Class: TesoteSdk::V2::TransactionOrders

Inherits:
Object
  • Object
show all
Defined in:
lib/tesote_sdk/v2/transaction_orders.rb

Instance Method Summary collapse

Constructor Details

#initialize(transport) ⇒ TransactionOrders

Returns a new instance of TransactionOrders.



4
5
6
# File 'lib/tesote_sdk/v2/transaction_orders.rb', line 4

def initialize(transport)
  @transport = transport
end

Instance Method Details

#cancel(account_id, order_id, opts: {}) ⇒ Object

POST /v2/accounts/id/transaction_orders/order_id/cancel

Raises:

  • (ArgumentError)


59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/tesote_sdk/v2/transaction_orders.rb', line 59

def cancel(, order_id, opts: {})
  raise ArgumentError, 'account_id is required' if .nil? || .to_s.empty?
  raise ArgumentError, 'order_id is required' if order_id.nil? || order_id.to_s.empty?

  body = @transport.request(
    'POST',
    "accounts/#{}/transaction_orders/#{order_id}/cancel",
    body: {},
    opts: opts
  )
  Models::TransactionOrder.from_hash(body)
end

#create(account_id, order:, opts: {}) ⇒ Object

POST /v2/accounts/id/transaction_orders ‘order` is a hash matching the spec’s ‘transaction_order` body field.

Raises:

  • (ArgumentError)


34
35
36
37
38
39
40
41
# File 'lib/tesote_sdk/v2/transaction_orders.rb', line 34

def create(, order:, opts: {})
  raise ArgumentError, 'account_id is required' if .nil? || .to_s.empty?
  raise ArgumentError, 'order is required' if order.nil?

  payload = { transaction_order: order }
  body = @transport.request('POST', "accounts/#{}/transaction_orders", body: payload, opts: opts)
  Models::TransactionOrder.from_hash(body)
end

#get(account_id, order_id, opts: {}) ⇒ Object

GET /v2/accounts/id/transaction_orders/order_id

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
# File 'lib/tesote_sdk/v2/transaction_orders.rb', line 24

def get(, order_id, opts: {})
  raise ArgumentError, 'account_id is required' if .nil? || .to_s.empty?
  raise ArgumentError, 'order_id is required' if order_id.nil? || order_id.to_s.empty?

  body = @transport.request('GET', "accounts/#{}/transaction_orders/#{order_id}", opts: opts)
  Models::TransactionOrder.from_hash(body)
end

#list(account_id, query = {}, opts: {}) ⇒ Object

GET /v2/accounts/id/transaction_orders Returns OffsetPage with TransactionOrder items.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/tesote_sdk/v2/transaction_orders.rb', line 10

def list(, query = {}, opts: {})
  raise ArgumentError, 'account_id is required' if .nil? || .to_s.empty?

  body = @transport.request('GET', "accounts/#{}/transaction_orders", query: query, opts: opts)
  items_raw = (body && body['items']) || []
  Models::OffsetPage.new(
    items: Models::TransactionOrder.from_array(items_raw),
    limit: body && body['limit'],
    offset: body && body['offset'],
    has_more: body && body['has_more']
  )
end

#submit(account_id, order_id, token: nil, opts: {}) ⇒ Object

POST /v2/accounts/id/transaction_orders/order_id/submit

Raises:

  • (ArgumentError)


44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/tesote_sdk/v2/transaction_orders.rb', line 44

def submit(, order_id, token: nil, opts: {})
  raise ArgumentError, 'account_id is required' if .nil? || .to_s.empty?
  raise ArgumentError, 'order_id is required' if order_id.nil? || order_id.to_s.empty?

  payload = token.nil? ? {} : { token: token }
  body = @transport.request(
    'POST',
    "accounts/#{}/transaction_orders/#{order_id}/submit",
    body: payload,
    opts: opts
  )
  Models::TransactionOrder.from_hash(body)
end