Module: Bitfinex::RESTv2Orders

Included in:
RESTv2
Defined in:
lib/rest/v2/orders.rb

Instance Method Summary collapse

Instance Method Details

#cancel_multiObject

TODO - requires websocket implementation as well

Raises:

  • (Exception)


86
87
88
# File 'lib/rest/v2/orders.rb', line 86

def cancel_multi ()
  raise Exception, 'not implemented'
end

#cancel_order(order) ⇒ Array

Cancel an order by ID

Parameters:

  • order (Hash|Array|Order|number)
    • must contain or be ID

Returns:

  • (Array)

    Raw notification



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/rest/v2/orders.rb', line 70

def cancel_order (order)
  if order.is_a?(Numeric)
    id = order
  elsif order.is_a?(Array)
    id = order[0]
  elsif order.instance_of?(Models::Order)
    id = order.id
  elsif order.kind_of?(Hash)
    id = order[:id] || order['id']
  else
    raise Exception, 'tried to cancel order with invalid ID'
  end
  authenticated_post("auth/w/order/cancel", params: { :id => id }).body
end

#order_multiObject

TODO - requires websocket implementation as well

Raises:

  • (Exception)


91
92
93
# File 'lib/rest/v2/orders.rb', line 91

def order_multi ()
  raise Exception, 'not implemented'
end

#order_trades(order_id, symbol = "tBTCUSD") ⇒ Array

Get Trades generated by an Order

@example:

client.order_trades 10010, "tBTCUSD"

Parameters:

  • order_id (int32)

    Id of the order

  • symbol (string) (defaults to: "tBTCUSD")

    symbol used for the order

Returns:

  • (Array)


21
22
23
# File 'lib/rest/v2/orders.rb', line 21

def order_trades(order_id, symbol="tBTCUSD")
  authenticated_post("auth/r/order/#{symbol}:#{order_id}/trades").body
end

#ordersObject

Get active orders

example: client.orders



7
8
9
# File 'lib/rest/v2/orders.rb', line 7

def orders
  authenticated_post("auth/r/orders").body
end

#submit_order(order) ⇒ Array

Submit a new order

Parameters:

  • order (Hash|Order)

Returns:

  • (Array)

    Raw notification



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rest/v2/orders.rb', line 32

def submit_order(order)
  if order.instance_of?(Models::Order)
    packet = order.to_new_order_packet
  elsif order.kind_of?(Hash)
    packet = Models::Order.new(order).to_new_order_packet
  else
    raise Exception, 'tried to submit order of unkown type'
  end

  if !@aff_code.nil?
    unless packet[:meta]
      packet[:meta] = {}
    end

    packet[:meta][:aff_code] = @aff_code
  end

  authenticated_post("auth/w/order/submit", params: packet).body
end

#update_order(changes) ⇒ Array

Update an order with a changeset by ID

Parameters:

  • changes (Hash)
    • must contain ID

Returns:

  • (Array)

    Raw notification



59
60
61
# File 'lib/rest/v2/orders.rb', line 59

def update_order (changes)
  authenticated_post("auth/w/order/update", params: changes).body
end