Module: Bitfinex::RESTv1Orders
- Included in:
- RESTv1
- Defined in:
- lib/rest/v1/orders.rb
Instance Method Summary collapse
-
#cancel_orders(ids = nil) ⇒ Hash
Cancel an order.
-
#multiple_orders(orders) ⇒ Hash
Submit several new orders at once.
-
#new_order(symbol, amount, type, side, price = nil, params = {}) ⇒ Hash
Submit a new order @example: client.new_order(“usdbtc”, 100, “market”, “sell”, 0).
-
#order_status(id) ⇒ Hash
Get the status of an order.
-
#orders ⇒ Hash
View your active orders.
-
#replace_order(id, symbol, amount, type, side, price, is_hidden = false, use_remaining = false) ⇒ Hash
Replace an orders with a new one.
Instance Method Details
#cancel_orders(ids = nil) ⇒ Hash
Cancel an order
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rest/v1/orders.rb', line 58 def cancel_orders(ids=nil) case ids when Array authenticated_post("order/cancel/multi", params: {order_ids: ids.map(&:to_i)}).body when Numeric, String authenticated_post("order/cancel", params: {order_id: ids.to_i}).body when NilClass authenticated_post("order/cancel/all").body else raise ParamsError end end |
#multiple_orders(orders) ⇒ Hash
Submit several new orders at once
@example:
client.multiple_orders([{symbol: "usdbtc", amount: 10, price: 0, exchange: "bitfinex", side: "buy", type: "market"}])
45 46 47 |
# File 'lib/rest/v1/orders.rb', line 45 def multiple_orders(orders) authenticated_post("order/new/multi", params: {orders: orders}).body end |
#new_order(symbol, amount, type, side, price = nil, params = {}) ⇒ Hash
Submit a new order @example:
client.new_order("usdbtc", 100, "market", "sell", 0)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rest/v1/orders.rb', line 16 def new_order(symbol, amount, type, side, price = nil, params = {}) check_params(params, %i{is_hidden is_postonly ocoorder buy_price_oco use_all_available}) # for 'market' order, we need to pass a random positive price, not nil price ||= 0.001 if type == "market" || type == "exchange market" params.merge!({ symbol: symbol, amount: amount.to_s, type: type, side: side, exchange: 'bitfinex', price: "%.10f" % price.to_f.round(10) # Decimalize float price (necessary for small numbers) }) authenticated_post("order/new", params: params).body end |
#order_status(id) ⇒ Hash
Get the status of an order. Is it active? Was it cancelled? To what extent has it been executed? etc.
@exmaple:
client.order_status(100)
105 106 107 |
# File 'lib/rest/v1/orders.rb', line 105 def order_status(id) authenticated_post("order/status", params: {order_id: id.to_i}).body end |
#orders ⇒ Hash
View your active orders.
@example:
client.orders
115 116 117 |
# File 'lib/rest/v1/orders.rb', line 115 def orders authenticated_post("orders").body end |
#replace_order(id, symbol, amount, type, side, price, is_hidden = false, use_remaining = false) ⇒ Hash
Replace an orders with a new one
@example:
client.replace_order(100,"usdbtc", 10, "market", "buy", 0)
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rest/v1/orders.rb', line 84 def replace_order(id, symbol, amount, type, side, price, is_hidden=false, use_remaining=false) params = { order_id: id.to_i, symbol: symbol, amount: amount.to_s, type: type, side: side, exchange: 'bitfinex', is_hidden: is_hidden, use_remaining: use_remaining, price: price.to_s } authenticated_post("order/cancel/replace", params: params).body end |