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:



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

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:



239
240
241
# File 'lib/binance/spot/trade.rb', line 239

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:



205
206
207
208
209
# File 'lib/binance/spot/trade.rb', line 205

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)
  • :stopPrice (Float)
  • :trailingDelta (Integer)
  • :icebergQty (Float)
  • :newOrderRespType (String)
  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/binance/spot/trade.rb', line 316

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

#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:



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

def get_order_rate_limit(**kwargs)
  @session.sign_request(:get, '/api/v3/rateLimit/order', params: kwargs)
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:



278
279
280
# File 'lib/binance/spot/trade.rb', line 278

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

#new_oco_order(symbol:, side:, quantity:, price:, stopPrice:, **kwargs) ⇒ Object

New OCO (TRADE)

POST /api/v3/order/oco

Send in a new OCO

Parameters:

  • symbol (String)

    the symbol

  • side (String)
  • quantity (Float)
  • price (Float)
  • stopPrice (Float)
  • kwargs (Hash)

Options Hash (**kwargs):

  • :listClientOrderId (String)
  • :limitClientOrderId (String)
  • :limitIcebergQty (Float)
  • :stopClientOrderId (String)
  • :stopLimitPrice (Float)
  • :stopIcebergQty (Float)
  • :stopLimitTimeInForce (Float)

    GTC/ FOK/ IOC

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

    The value cannot be greater than 60000

See Also:



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/binance/spot/trade.rb', line 178

def new_oco_order(symbol:, side:, quantity:, price:, stopPrice:, **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('price', price)
  Binance::Utils::Validation.require_param('stopPrice', stopPrice)

  @session.sign_request(:post, '/api/v3/order/oco', params: kwargs.merge(
    symbol: symbol,
    side: side,
    quantity: quantity,
    price: price,
    stopPrice: stopPrice
  ))
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:



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

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:



222
223
224
# File 'lib/binance/spot/trade.rb', line 222

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