Module: Binance::Spot::Trade

Included in:
Binance::Spot
Defined in:
lib/binance/spot/trade.rb

Overview

This module includes all spot trading methods, including:

  • place orders (spot and oco)

  • query orders (spot and oco)

  • cancel orders (spot and oco)

  • account information

  • my trades

Instance Method Summary collapse

Instance Method Details

#account(**kwargs) ⇒ Object

Account Information (USER_DATA)

GET /api/v3/account

Parameters:

  • kwargs (Hash)

Options Hash (**kwargs):

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



271
272
273
# File 'lib/binance/spot/trade.rb', line 271

def (**kwargs)
  @session.sign_request(:get, '/api/v3/account', params: kwargs)
end

#all_order_list(**kwargs) ⇒ Object

Query all OCO (USER_DATA)

GET /api/v3/allOrderList

Retrieves all OCO based on provided optional parameters

Parameters:

  • kwargs (Hash)

Options Hash (**kwargs):

  • :fromId (Integer)
  • :startTime (String)
  • :endTime (String)
  • :limit (String)

    Default 500; max 1000.

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



249
250
251
# File 'lib/binance/spot/trade.rb', line 249

def all_order_list(**kwargs)
  @session.sign_request(:get, '/api/v3/allOrderList', params: kwargs)
end

#all_orders(symbol:, **kwargs) ⇒ Object

All Orders (USER_DATA)

GET /api/v3/allOrders

Get all account orders; active, canceled, or filled.

Parameters:

  • symbol (String)

    the symbol

  • kwargs (Hash)

Options Hash (**kwargs):

  • :orderId (String)
  • :startTime (String)
  • :endTime (String)
  • :limit (String)

    Default 500; max 1000.

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



150
151
152
153
154
# File 'lib/binance/spot/trade.rb', line 150

def all_orders(symbol:, **kwargs)
  Binance::Utils::Validation.require_param('symbol', symbol)

  @session.sign_request(:get, '/api/v3/allOrders', params: kwargs.merge(symbol: symbol))
end

#cancel_open_orders(symbol:, **kwargs) ⇒ Object

Cancel all Open Orders on a Symbol (TRADE)

DELETE /api/v3/openOrders

Parameters:

  • symbol (String)

    the symbol

  • kwargs (Hash)

Options Hash (**kwargs):

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



102
103
104
105
106
# File 'lib/binance/spot/trade.rb', line 102

def cancel_open_orders(symbol:, **kwargs)
  Binance::Utils::Validation.require_param('symbol', symbol)

  @session.sign_request(:delete, '/api/v3/openOrders', params: kwargs.merge(symbol: symbol))
end

#cancel_order(symbol:, **kwargs) ⇒ Object

Cancel Order (TRADE)

DELETE /api/v3/order

Parameters:

  • symbol (String)

    the symbol

  • kwargs (Hash)

Options Hash (**kwargs):

  • :orderId (Integer)
  • :origClientOrderId (String)
  • :newClientOrderId (String)
  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



88
89
90
91
92
# File 'lib/binance/spot/trade.rb', line 88

def cancel_order(symbol:, **kwargs)
  Binance::Utils::Validation.require_param('symbol', symbol)

  @session.sign_request(:delete, '/api/v3/order', params: kwargs.merge(symbol: symbol))
end

#cancel_order_list(symbol:, **kwargs) ⇒ Object

Cancel OCO (TRADE)

DELETE /api/v3/orderList

Parameters:

  • symbol (String)

    the symbol

  • kwargs (Hash)

Options Hash (**kwargs):

  • :orderListId (Integer)
  • :listClientOrderId (String)
  • :newClientOrderId (String)
  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



215
216
217
218
219
# File 'lib/binance/spot/trade.rb', line 215

def cancel_order_list(symbol:, **kwargs)
  Binance::Utils::Validation.require_param('symbol', symbol)

  @session.sign_request(:delete, '/api/v3/orderList', params: kwargs.merge(symbol: symbol))
end

#cancel_replace(symbol:, side:, type:, cancelReplaceMode:, **kwargs) ⇒ Object

Cancel an Existing Order and Send a New Order (TRADE)

POST /api/v3/order/cancelReplace

Parameters:

  • symbol (String)

    the symbol

  • side (String)
  • type (String)
  • cancelReplaceMode (String)

    STOP_ON_FAILURE or ALLOW_FAILURE

  • kwargs (Hash)

Options Hash (**kwargs):

  • :timeInForce (String)
  • :quantity (Float)
  • :quoteOrderQty (Float)
  • :price (Float)
  • :cancelNewClientOrderId (String)
  • :cancelOrigClientOrderId (String)
  • :cancelOrderId (Integer)
  • :newClientOrderId (String)
  • :strategyId (Integer)
  • :strategyType (Integer)

    The value cannot be less than 1000000

  • :stopPrice (Float)
  • :trailingDelta (Integer)
  • :icebergQty (Float)
  • :newOrderRespType (String)
  • :selfTradePreventionMode (String)

    The allowed enums is dependent on what is configured on the symbo

  • :cancelRestrictions (String)

    ONLY_NEW - Cancel will succeed if the order status is NEW. ONLY_PARTIALLY_FILLED - Cancel will succeed if order status is PARTIALLY_FILLED

  • :orderRateLimitExceededMode (String)

    DO_NOTHING (default)- will only attempt to cancel the order if account has not exceeded the unfilled order rate limit CANCEL_ONLY - will always cancel the order

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



380
381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/binance/spot/trade.rb', line 380

def cancel_replace(symbol:, side:, type:, cancelReplaceMode:, **kwargs)
  Binance::Utils::Validation.require_param('symbol', symbol)
  Binance::Utils::Validation.require_param('side', side)
  Binance::Utils::Validation.require_param('type', type)
  Binance::Utils::Validation.require_param('cancelReplaceMode', cancelReplaceMode)

  @session.sign_request(:post, '/api/v3/order/cancelReplace',
                        params: kwargs.merge(
                          symbol: symbol,
                          side: side,
                          type: type,
                          cancelReplaceMode: cancelReplaceMode
                        ))
end

#commission_rate(symbol:) ⇒ Object

Query Commission Rates (USER_DATA)

GET /api/v3/account/commission



345
346
347
348
349
# File 'lib/binance/spot/trade.rb', line 345

def commission_rate(symbol:)
  Binance::Utils::Validation.require_param('symbol', symbol)

  @session.sign_request(:get, '/api/v3/account/commission', params: { symbol: symbol })
end

#get_order(symbol:, **kwargs) ⇒ Object

Query Order (USER_DATA)

GET /api/v3/order

Parameters:

  • symbol (String)

    the symbol

  • kwargs (Hash)

Options Hash (**kwargs):

  • :orderId (Integer)
  • :origClientOrderId (String)
  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



118
119
120
121
122
# File 'lib/binance/spot/trade.rb', line 118

def get_order(symbol:, **kwargs)
  Binance::Utils::Validation.require_param('symbol', symbol)

  @session.sign_request(:get, '/api/v3/order', params: kwargs.merge(symbol: symbol))
end

#get_order_rate_limit(**kwargs) ⇒ Object

Query Current Order Count Usage (TRADE)

GET /api/v3/rateLimit/order

Parameters:

  • kwargs (Hash)

Options Hash (**kwargs):

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



299
300
301
# File 'lib/binance/spot/trade.rb', line 299

def get_order_rate_limit(**kwargs)
  @session.sign_request(:get, '/api/v3/rateLimit/order', params: kwargs)
end

#my_allocations(symbol:, **kwargs) ⇒ Object

Query Allocations (USER_DATA)

GET /api/v3/myAllocations

Parameters:

  • symbol (String)
  • kwargs (Hash)
  • kwargs (Integer)

    :startTime

  • kwargs (Integer)

    :endTime

  • kwargs (Integer)

    :fromAllocationId

  • kwargs (Integer)

    :limit Default 500;Max 1000

  • kwargs (Integer)

    :orderId

See Also:



333
334
335
336
337
# File 'lib/binance/spot/trade.rb', line 333

def my_allocations(symbol:, **kwargs)
  Binance::Utils::Validation.require_param('symbol', symbol)

  @session.sign_request(:get, '/api/v3/myAllocations', params: kwargs.merge(symbol: symbol))
end

#my_prevented_matches(symbol:, **kwargs) ⇒ Object

Query Prevented Matches (USER_DATA)

GET /api/v3/myPreventedMatches

Parameters:

  • symbol (String)
  • kwargs (Hash)
  • kwargs (Integer)

    :preventedMatchId

  • kwargs (Integer)

    :orderId

  • kwargs (Integer)

    :fromPreventedMatchId

  • kwargs (Integer)

    :limit Default: 500; Max: 1000

  • kwargs (Integer)

    :recvWindow The value cannot be greater than 60000

See Also:



315
316
317
318
319
# File 'lib/binance/spot/trade.rb', line 315

def my_prevented_matches(symbol:, **kwargs)
  Binance::Utils::Validation.require_param('symbol', symbol)

  @session.sign_request(:get, '/api/v3/myPreventedMatches', params: kwargs.merge(symbol: symbol))
end

#my_trades(symbol:, **kwargs) ⇒ Object

Account Trade List (USER_DATA)

GET /api/v3/myTrades

Parameters:

  • symbol (String)

    the symbol

  • kwargs (Hash)

Options Hash (**kwargs):

  • :orderId (Integer)
  • :startTime (Integer)
  • :endTime (Integer)
  • :fromId (Integer)

    TradeId to fetch from. Default gets most recent trades.

  • :limit (Integer)

    Default 500; max 1000.

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



288
289
290
# File 'lib/binance/spot/trade.rb', line 288

def my_trades(symbol:, **kwargs)
  @session.sign_request(:get, '/api/v3/myTrades', params: kwargs.merge(symbol: symbol))
end

#new_oco_order(symbol:, side:, quantity:, aboveType:, belowType:, **kwargs) ⇒ Object

New OCO (TRADE)

POST /api/v3/order/oco

Send in a new OCO

Parameters:

  • symbol (String)

    the symbol

  • side (String)
  • quantity (Float)
  • aboveType (String)
  • belowType (String)
  • kwargs (Hash)

Options Hash (**kwargs):

  • :listClientOrderId (String)
  • :aboveClientOrderId (String)

    Arbitrary unique ID among open orders for the above order. Automatically generated if not sent

  • :aboveIcebergQty (Integer)

    Note that this can only be used if aboveTimeInForce is GTC

  • :abovePrice (Float)
  • :aboveStopPriceCan (Float)

    be used if aboveType is STOP_LOSS or STOP_LOSS_LIMIT. Either aboveStopPrice or aboveTrailingDelta or both, must be specified.

  • :aboveTrailingDelta (Integer)
  • :aboveTimeInForce (Float)

    Required if the aboveType is STOP_LOSS_LIMIT.

  • :aboveStrategyId (Integer)

    Arbitrary numeric value identifying the above order within an order strategy.

  • :aboveStrategyType (Integer)

    Arbitrary numeric value identifying the above order strategy. Values smaller than 1000000 are reserved and cannot be used.

  • :belowClientOrderId (String)

    Arbitrary unique ID among open orders for the below order. Automatically generated if not sent

  • :belowIcebergQty (Integer)

    Note that this can only be used if belowTimeInForce is GTC

  • :belowPrice (Float)

    Can be used if belowType is STOP_LOSS_LIMIT or LIMIT_MAKER to specify the limit price.

  • :belowStopPrice (Float)

    Can be used if belowType is STOP_LOSS or STOP_LOSS_LIMIT. Either belowStopPrice or belowTrailingDelta or both, must be specified.

  • :belowTrailingDelta (Integer)
  • :belowTimeInForce (String)

    Required if the belowType is STOP_LOSS_LIMIT

  • :belowStrategyId (Integer)

    Arbitrary numeric value identifying the below order within an order strategy

  • :belowStrategyType (String)

    Arbitrary numeric value identifying the below order strategy. Values smaller than 1000000 are reserved and cannot be used.

  • :newOrderRespType (String)
  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/binance/spot/trade.rb', line 188

def new_oco_order(symbol:, side:, quantity:, aboveType:, belowType:, **kwargs)
  Binance::Utils::Validation.require_param('symbol', symbol)
  Binance::Utils::Validation.require_param('side', side)
  Binance::Utils::Validation.require_param('quantity', quantity)
  Binance::Utils::Validation.require_param('aboveType', aboveType)
  Binance::Utils::Validation.require_param('belowType', belowType)

  @session.sign_request(:post, '/api/v3/order/oco', params: kwargs.merge(
    symbol: symbol,
    side: side,
    quantity: quantity,
    aboveType: aboveType,
    belowType: belowType
  ))
end

#new_order(symbol:, side:, type:, **kwargs) ⇒ Object

New Order

POST /api/v3/order

send in a new order

Parameters:

  • symbol (String)

    the symbol

  • side (String)
  • type (String)
  • kwargs (Hash)

Options Hash (**kwargs):

  • :timeInForce (String)
  • :quantity (Float)
  • :quoteOrderQty (Float)
  • :price (Float)
  • :newClientOrderId (String)
  • :stopPrice (Float)
  • :icebergeQty (Float)
  • :newOrderRespType (String)

    Set the response JSON. ACK, RESULT, or FULL.

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/binance/spot/trade.rb', line 65

def new_order(symbol:, side:, type:, **kwargs)
  Binance::Utils::Validation.require_param('symbol', symbol)
  Binance::Utils::Validation.require_param('side', side)
  Binance::Utils::Validation.require_param('type', type)

  @session.sign_request(:post, '/api/v3/order', params: kwargs.merge(
    symbol: symbol,
    side: side,
    type: type
  ))
end

#new_order_test(symbol:, side:, type:, **kwargs) ⇒ Object

TestNew Order

POST /api/v3/order/test

send in a new order to test the request, no order is really generated.

Parameters:

  • symbol (String)

    the symbol

  • side (String)
  • type (String)
  • kwargs (Hash)

Options Hash (**kwargs):

  • :timeInForce (String)
  • :quantity (Float)
  • :quoteOrderQty (Float)
  • :price (Float)
  • :newClientOrderId (String)
  • :stopPrice (Float)
  • :icebergeQty (Float)
  • :newOrderRespType (String)

    Set the response JSON. ACK, RESULT, or FULL.

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/binance/spot/trade.rb', line 33

def new_order_test(symbol:, side:, type:, **kwargs)
  Binance::Utils::Validation.require_param('symbol', symbol)
  Binance::Utils::Validation.require_param('side', side)
  Binance::Utils::Validation.require_param('type', type)

  @session.sign_request(:post, '/api/v3/order/test', params: kwargs.merge(
    symbol: symbol,
    side: side,
    type: type
  ))
end

#open_order_list(**kwargs) ⇒ Object

Query Open OCO (USER_DATA)

GET /api/v3/openOrderList

Parameters:

  • kwargs (Hash)

Options Hash (**kwargs):

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



260
261
262
# File 'lib/binance/spot/trade.rb', line 260

def open_order_list(**kwargs)
  @session.sign_request(:get, '/api/v3/openOrderList', params: kwargs)
end

#open_orders(**kwargs) ⇒ Object

Current Open Orders (USER_DATA)

GET /api/v3/openOrders

Parameters:

  • kwargs (Hash)

Options Hash (**kwargs):

  • :symbol (String)

    the symbol

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



132
133
134
# File 'lib/binance/spot/trade.rb', line 132

def open_orders(**kwargs)
  @session.sign_request(:get, '/api/v3/openOrders', params: kwargs)
end

#order_list(**kwargs) ⇒ Object

Query OCO (USER_DATA)

GET /api/v3/orderList

Retrieves a specific OCO based on provided optional parameters

Parameters:

  • kwargs (Hash)

Options Hash (**kwargs):

  • :orderListId (Integer)
  • :orgClientOrderId (String)
  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



232
233
234
# File 'lib/binance/spot/trade.rb', line 232

def order_list(**kwargs)
  @session.sign_request(:get, '/api/v3/orderList', params: kwargs)
end