Module: Binance::Spot::Margin

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

Overview

Margin endpoints

Instance Method Summary collapse

Instance Method Details

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

Disable Isolated Margin Account (TRADE)

DELETE /sapi/v1/margin/isolated/account

Parameters:

  • symbol (String)
  • kwargs (Hash)

Options Hash (**kwargs):

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



390
391
392
393
394
# File 'lib/binance/spot/margin.rb', line 390

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

  @session.sign_request(:delete, '/sapi/v1/margin/isolated/account', params: kwargs.merge(symbol: symbol))
end

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

Enable Isolated Margin Account (TRADE)

POST /sapi/v1/margin/isolated/account

Parameters:

  • symbol (String)
  • kwargs (Hash)

Options Hash (**kwargs):

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



404
405
406
407
408
# File 'lib/binance/spot/margin.rb', line 404

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

  @session.sign_request(:post, '/sapi/v1/margin/isolated/account', params: kwargs.merge(symbol: symbol))
end

#get_all_isolated_margin_pairs(**kwargs) ⇒ Object

Get All Isolated Margin Symbol(USER_DATA)

GET /sapi/v1/margin/isolated/allPairs

Parameters:

  • kwargs (Hash)

Options Hash (**kwargs):

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



428
429
430
# File 'lib/binance/spot/margin.rb', line 428

def get_all_isolated_margin_pairs(**kwargs)
  @session.sign_request(:get, '/sapi/v1/margin/isolated/allPairs', params: kwargs)
end

#get_bnb_burn(**kwargs) ⇒ Object

Get BNB Burn Status (USER_DATA)

GET /sapi/v1/bnbBurn

Parameters:

  • kwargs (Hash)

Options Hash (**kwargs):

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



454
455
456
# File 'lib/binance/spot/margin.rb', line 454

def get_bnb_burn(**kwargs)
  @session.sign_request(:get, '/sapi/v1/bnbBurn', params: kwargs)
end

#get_cross_margin_data(**kwargs) ⇒ Object

Query Cross Margin Fee Data (USER_DATA)

GET /sapi/v1/margin/crossMarginData

Parameters:

  • kwargs (Hash)
  • vipLevel (Hash)

    a customizable set of options

  • coin (Hash)

    a customizable set of options

Options Hash (**kwargs):

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



485
486
487
# File 'lib/binance/spot/margin.rb', line 485

def get_cross_margin_data(**kwargs)
  @session.sign_request(:get, '/sapi/v1/margin/crossMarginData', params: kwargs)
end

#get_isolated_margin_account(**kwargs) ⇒ Object

Query Isolated Margin Account Info (USER_DATA)

GET /sapi/v1/margin/isolated/account

Parameters:

  • kwargs (Hash)

Options Hash (**kwargs):

  • :symbols (String)

    Max 5 symbols can be sent; separated by “,”. e.g. “BTCUSDT,BNBUSDT,ADAUSDT”

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



378
379
380
# File 'lib/binance/spot/margin.rb', line 378

def (**kwargs)
  @session.sign_request(:get, '/sapi/v1/margin/isolated/account', params: kwargs)
end

#get_isolated_margin_account_limit(**kwargs) ⇒ Object

Query Enabled Isolated Margin Account Limit (USER_DATA)

GET /sapi/v1/margin/isolated/accountLimit

Parameters:

  • kwargs (Hash)

Options Hash (**kwargs):

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



417
418
419
# File 'lib/binance/spot/margin.rb', line 417

def (**kwargs)
  @session.sign_request(:get, '/sapi/v1/margin/isolated/accountLimit', params: kwargs)
end

#get_isolated_margin_data(**kwargs) ⇒ Object

Query Isolated Margin Fee Data (USER_DATA)

GET /sapi/v1/margin/isolatedMarginData

Parameters:

  • kwargs (Hash)
  • vipLevel (Hash)

    a customizable set of options

  • symbol (Hash)

    a customizable set of options

Options Hash (**kwargs):

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



498
499
500
# File 'lib/binance/spot/margin.rb', line 498

def get_isolated_margin_data(**kwargs)
  @session.sign_request(:get, '/sapi/v1/margin/isolatedMarginData', params: kwargs)
end

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

Query Isolated Margin Tier Data (USER_DATA)

GET /sapi/v1/margin/isolatedMarginTier

Parameters:

  • symbol (String)
  • kwargs (Hash)
  • tier (Hash)

    a customizable set of options

Options Hash (**kwargs):

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



511
512
513
514
515
# File 'lib/binance/spot/margin.rb', line 511

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

  @session.sign_request(:get, '/sapi/v1/margin/isolatedMarginTier', params: kwargs.merge(symbol: symbol))
end

#get_margin_interest_rate_history(asset:, **kwargs) ⇒ Object

Query Margin Interest Rate History (USER_DATA)

GET /sapi/v1/margin/interestRateHistory

Parameters:

  • asset (String)
  • kwargs (Hash)
  • vipLevel (Hash)

    a customizable set of options

  • startTime (Hash)

    a customizable set of options

  • endTime (Hash)

    a customizable set of options

  • limit (Hash)

    a customizable set of options

Options Hash (**kwargs):

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



470
471
472
473
474
# File 'lib/binance/spot/margin.rb', line 470

def get_margin_interest_rate_history(asset:, **kwargs)
  Binance::Utils::Validation.require_param('asset', asset)

  @session.sign_request(:get, '/sapi/v1/margin/interestRateHistory', params: kwargs.merge(asset: asset))
end

#get_margin_order_usage(**kwargs) ⇒ Object

Query Current Margin Order Count Usage (TRADE)

GET /sapi/v1/margin/rateLimit/order

Parameters:

  • kwargs (Hash)
  • isIsolated (Hash)

    a customizable set of options

  • symbol (Hash)

    a customizable set of options

Options Hash (**kwargs):

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



526
527
528
# File 'lib/binance/spot/margin.rb', line 526

def get_margin_order_usage(**kwargs)
  @session.sign_request(:get, '/sapi/v1/margin/rateLimit/order', params: kwargs)
end

#margin_account(**kwargs) ⇒ Object

Query Cross Margin Account Details (USER_DATA)

GET /sapi/v1/margin/account

Parameters:

  • kwargs (Hash)

Options Hash (**kwargs):

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



164
165
166
# File 'lib/binance/spot/margin.rb', line 164

def (**kwargs)
  @session.sign_request(:get, '/sapi/v1/margin/account', params: kwargs)
end

#margin_all_assetsObject

Get All Margin Assets (MARKET_DATA)

GET /sapi/v1/margin/allAssets



13
14
15
# File 'lib/binance/spot/margin.rb', line 13

def margin_all_assets
  @session.limit_request(path: '/sapi/v1/margin/allAssets')
end

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

Query Margin Account’s All Order (USER_DATA)

GET /sapi/v1/margin/allOrders

Parameters:

  • symbol (String)
  • kwargs (Hash)

Options Hash (**kwargs):

  • :isIsolated (String)

    for isolated margin or not, “TRUE”, “FALSE”, default “FALSE”

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

    Default 500; max 1000.

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



211
212
213
214
215
# File 'lib/binance/spot/margin.rb', line 211

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

  @session.sign_request(:get, '/sapi/v1/margin/allOrders', params: kwargs.merge(symbol: symbol))
end

#margin_all_pairsObject

Get All Margin Pairs (MARKET_DATA)

GET /sapi/v1/margin/allPairs



22
23
24
# File 'lib/binance/spot/margin.rb', line 22

def margin_all_pairs
  @session.limit_request(path: '/sapi/v1/margin/allPairs')
end

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

Margin Account Cancel all Open Orders on a Symbol (TRADE)

DELETE /sapi/v1/margin/openOrders

Parameters:

  • symbol (String)
  • kwargs (Hash)

Options Hash (**kwargs):

  • :isIsolated (String)

    for isolated margin or not, “TRUE”, “FALSE”, default “FALSE”

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



97
98
99
100
101
102
103
# File 'lib/binance/spot/margin.rb', line 97

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

  @session.sign_request(:delete, '/sapi/v1/margin/openOrders', params: kwargs.merge(
    symbol: symbol
  ))
end

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

Margin Account Cancel OCO (TRADE)

DELETE /sapi/v1/margin/orderList

Canceling an individual leg will cancel the entire OCO

Parameters:

  • symbol (String)
  • kwargs (Hash)

Options Hash (**kwargs):

  • :isIsolated (String)
  • :orderListId (Integer)

    Either orderListId or listClientOrderId must be provided

  • :listClientOrderId (String)

    Either orderListId or listClientOrderId must be provided

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

    The value cannot be greater than 60000

See Also:



269
270
271
272
273
274
275
# File 'lib/binance/spot/margin.rb', line 269

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

  @session.sign_request(:delete, '/sapi/v1/margin/orderList', params: kwargs.merge(
    symbol: symbol
  ))
end

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

Margin Account Cancel Order (TRADE)

DELETE /sapi/v1/margin/order

Parameters:

  • symbol (String)
  • kwargs (Hash)

Options Hash (**kwargs):

  • :isIsolated (String)

    for isolated margin or not, “TRUE”, “FALSE”, default “FALSE”

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

    The value cannot be greater than 60000

See Also:



80
81
82
83
84
85
86
# File 'lib/binance/spot/margin.rb', line 80

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

  @session.sign_request(:delete, '/sapi/v1/margin/order', params: kwargs.merge(
    symbol: symbol
  ))
end

#margin_force_liquidation_record(**kwargs) ⇒ Object

Get Force Liquidation Record (USER_DATA)

GET /sapi/v1/margin/forceLiquidationRec

Parameters:

  • kwargs (Hash)

Options Hash (**kwargs):

  • :isolatedSymbol (String)
  • :startTime (Integer)
  • :endTime (Integer)
  • :current (Integer)

    Currently querying page. Start from 1. Default:1

  • :size (Integer)

    Default:10 Max:100

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



153
154
155
# File 'lib/binance/spot/margin.rb', line 153

def margin_force_liquidation_record(**kwargs)
  @session.sign_request(:get, '/sapi/v1/margin/forceLiquidationRec', params: kwargs)
end

#margin_get_all_oco(**kwargs) ⇒ Object

Query Margin Account’s all OCO (USER_DATA)

GET /sapi/v1/margin/allOrderList

Parameters:

  • kwargs (Hash)

Options Hash (**kwargs):

  • :symbol (String)
  • :isIsolated (String)
  • :fromId (Integer)

    If supplied, neither startTime nor endTime can be provided

  • :startTime (Integer)
  • :endTime (Integer)
  • :limit (Integer)
  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



305
306
307
# File 'lib/binance/spot/margin.rb', line 305

def margin_get_all_oco(**kwargs)
  @session.sign_request(:get, '/sapi/v1/margin/allOrderList', params: kwargs)
end

#margin_get_oco(**kwargs) ⇒ Object

Query Margin Account’s OCO (USER_DATA)

GET /sapi/v1/margin/orderList

Parameters:

  • kwargs (Hash)

Options Hash (**kwargs):

  • :symbol (String)
  • :isIsolated (String)
  • :orderListId (Integer)

    Either orderListId or origClientOrderId must be provided

  • :origClientOrderId (String)

    Either orderListId or origClientOrderId must be provided

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



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

def margin_get_oco(**kwargs)
  @session.sign_request(:get, '/sapi/v1/margin/orderList', params: kwargs)
end

#margin_get_open_oco(**kwargs) ⇒ Object

Query Margin Account’s Open OCO (USER_DATA)

GET /sapi/v1/margin/openOrderList

Parameters:

  • kwargs (Hash)

Options Hash (**kwargs):

  • :symbol (String)
  • :isIsolated (String)
  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



318
319
320
# File 'lib/binance/spot/margin.rb', line 318

def margin_get_open_oco(**kwargs)
  @session.sign_request(:get, '/sapi/v1/margin/openOrderList', params: kwargs)
end

#margin_interest_history(**kwargs) ⇒ Object

Get Interest History (USER_DATA)

GET /sapi/v1/margin/interestHistory

Parameters:

  • kwargs (Hash)

Options Hash (**kwargs):

  • :asset (String)
  • :isolatedSymbol (String)
  • :startTime (Integer)
  • :endTime (Integer)
  • :current (Integer)

    Currently querying page. Start from 1. Default:1

  • :size (Integer)

    Default:10 Max:100

  • :archived (String)

    Default: false. Set to true for archived data from 6 months ago

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



137
138
139
# File 'lib/binance/spot/margin.rb', line 137

def margin_interest_history(**kwargs)
  @session.sign_request(:get, '/sapi/v1/margin/interestHistory', params: kwargs)
end

#margin_max_borrowable(asset:, **kwargs) ⇒ Object

Query Max Borrow (USER_DATA)

GET /sapi/v1/margin/maxBorrowable

Parameters:

  • asset (String)
  • kwargs (Hash)

Options Hash (**kwargs):

  • :isolatedSymbol (String)
  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



349
350
351
352
353
# File 'lib/binance/spot/margin.rb', line 349

def margin_max_borrowable(asset:, **kwargs)
  Binance::Utils::Validation.require_param('asset', asset)

  @session.sign_request(:get, '/sapi/v1/margin/maxBorrowable', params: kwargs.merge(asset: asset))
end

#margin_max_transferable(asset:, **kwargs) ⇒ Object

Query Max Transfer-Out Amount (USER_DATA)

GET /sapi/v1/margin/maxTransferable

Parameters:

  • asset (String)
  • kwargs (Hash)

Options Hash (**kwargs):

  • :isolatedSymbol (String)
  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



364
365
366
367
368
# File 'lib/binance/spot/margin.rb', line 364

def margin_max_transferable(asset:, **kwargs)
  Binance::Utils::Validation.require_param('asset', asset)

  @session.sign_request(:get, '/sapi/v1/margin/maxTransferable', params: kwargs.merge(asset: asset))
end

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

Query Margin Account’s Trade List (USER_DATA)

GET /sapi/v1/margin/myTrades

Parameters:

  • symbol (String)
  • kwargs (Hash)

Options Hash (**kwargs):

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

    Default 500; max 1000.

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



334
335
336
337
338
# File 'lib/binance/spot/margin.rb', line 334

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

  @session.sign_request(:get, '/sapi/v1/margin/myTrades', params: kwargs.merge(symbol: symbol))
end

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

Margin Account New Order (TRADE)

POST /sapi/v1/margin/order

Parameters:

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

Options Hash (**kwargs):

  • :isIsolated (String)

    for isolated margin or not, “TRUE”, “FALSE”, default “FALSE”

  • :quantity (Float)
  • :quoteOrderQty (Float)
  • :price (Float)
  • :stopPrice (Float)

    Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.

  • :newClientOrderId (String)
  • :icebergQty (Float)

    Used with LIMIT, STOP_LOSS_LIMIT, and TAKE_PROFIT_LIMIT to create an iceberg order.

  • :newOrderRespType (String)
  • :sideEffectType (String)

    NO_SIDE_EFFECT, MARGIN_BUY, AUTO_REPAY; default NO_SIDE_EFFECT.

  • :timeInForce (String)

    GTC,IOC,FOK

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/binance/spot/margin.rb', line 56

def margin_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, '/sapi/v1/margin/order', params: kwargs.merge(
    symbol: symbol,
    side: side,
    type: type
  ))
end

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

Margin Account New OCO (TRADE)

POST /sapi/v1/margin/order/oco

Parameters:

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

Options Hash (**kwargs):

  • :isIsolated (String)

    for isolated margin or not, “TRUE”, “FALSE”, default “FALSE”

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

    If provided, stopLimitTimeInForce is required.

  • :stopIcebergQty (Float)
  • :stopLimitTimeInForce (String)

    Valid values are GTC/FOK/IOC

  • :newOrderRespType (String)
  • :sideEffectType (String)

    NO_SIDE_EFFECT, MARGIN_BUY, AUTO_REPAY; default NO_SIDE_EFFECT.

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/binance/spot/margin.rb', line 239

def margin_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, '/sapi/v1/margin/order/oco', params: kwargs.merge(
    symbol: symbol,
    side: side,
    quantity: quantity,
    price: price,
    stopPrice: stopPrice
  ))
end

#margin_open_orders(**kwargs) ⇒ Object

Query Margin Account’s Open Order (USER_DATA)

GET /sapi/v1/margin/openOrders

Parameters:

  • kwargs (Hash)

Options Hash (**kwargs):

  • :symbol (String)
  • :isIsolated (String)

    for isolated margin or not, “TRUE”, “FALSE”, default “FALSE”

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



194
195
196
# File 'lib/binance/spot/margin.rb', line 194

def margin_open_orders(**kwargs)
  @session.sign_request(:get, '/sapi/v1/margin/openOrders', params: kwargs)
end

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

Query Margin Account’s Order (USER_DATA)

GET /sapi/v1/margin/order

Parameters:

  • symbol (String)
  • kwargs (Hash)

Options Hash (**kwargs):

  • :isIsolated (String)

    for isolated margin or not, “TRUE”, “FALSE”, default “FALSE”

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

    The value cannot be greater than 60000

See Also:



179
180
181
182
183
# File 'lib/binance/spot/margin.rb', line 179

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

  @session.sign_request(:get, '/sapi/v1/margin/order', params: kwargs.merge(symbol: symbol))
end

#margin_price_index(symbol:) ⇒ Object

Query Margin PriceIndex (MARKET_DATA)

GET /sapi/v1/margin/priceIndex



31
32
33
34
# File 'lib/binance/spot/margin.rb', line 31

def margin_price_index(symbol:)
  Binance::Utils::Validation.require_param('symbol', symbol)
  @session.limit_request(path: '/sapi/v1/margin/priceIndex', params: { symbol: symbol })
end

#margin_transfer_history(**kwargs) ⇒ Object

Get Cross Margin Transfer History (USER_DATA)

GET /sapi/v1/margin/transfer

Parameters:

  • kwargs (Hash)

Options Hash (**kwargs):

  • :asset (String)
  • :type (String)
  • :startTime (Integer)
  • :endTime (Integer)
  • :current (Integer)

    Currently querying page. Start from 1. Default:1

  • :size (Integer)

    Default:10 Max:100

  • :archived (String)

    Default: false. Set to true for archived data from 6 months ago

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



119
120
121
# File 'lib/binance/spot/margin.rb', line 119

def margin_transfer_history(**kwargs)
  @session.sign_request(:get, '/sapi/v1/margin/transfer', params: kwargs)
end

#toggle_bnb_burn(**kwargs) ⇒ Object

Toggle BNB Burn On Spot Trade And Margin Interest (USER_DATA)

POST /sapi/v1/bnbBurn

“spotBNBBurn” and “interestBNBBurn” should be sent at least one.

Parameters:

  • kwargs (Hash)

Options Hash (**kwargs):

  • :spotBNBBurn (String)

    “true” or “false”; Determines whether to use BNB to pay for trading fees on SPOT

  • :interestBNBBurn (String)

    “true” or “false”; Determines whether to use BNB to pay for margin loan’s interest

  • :recvWindow (Integer)

    The value cannot be greater than 60000

See Also:



443
444
445
# File 'lib/binance/spot/margin.rb', line 443

def toggle_bnb_burn(**kwargs)
  @session.sign_request(:post, '/sapi/v1/bnbBurn', params: kwargs)
end