Supported Models

Binance

Introduction

This page explains the Binance brokerage models, including the asset classes they supports, their default security-level models, and their default markets.

// Binance Spot
SetBrokerageModel(BrokerageName.Binance, AccountType.Cash);
SetBrokerageModel(BrokerageName.Binance, AccountType.Margin);

// Binance Futures
SetBrokerageModel(BrokerageName.BinanceFutures, AccountType.Margin);
SetBrokerageModel(BrokerageName.BinanceCoinFutures, AccountType.Margin);

// Binance US Spot
SetBrokerageModel(BrokerageName.BinanceUS, AccountType.Cash);
# Binance Spot
self.set_brokerage_model(BrokerageName.BINANCE, AccountType.CASH)
self.set_brokerage_model(BrokerageName.BINANCE, AccountType.MARGIN)

# Binance Futures
self.set_brokerage_model(BrokerageName.BINANCE_FUTURES, AccountType.MARGIN)
self.set_brokerage_model(BrokerageName.BINANCE_COIN_FUTURES, AccountType.MARGIN)

# Binance US Spot
self.set_brokerage_model(BrokerageName.BINANCE_US, AccountType.CASH)

To view the implementation of these models, see the following pages in the LEAN GitHub repository:

Asset Classes

The Binance brokerage models support trading Crypto and Crypto Futures.

The Binance US brokerage model supports trading Crypto.

Orders

The Binance and Binance US brokerage models support several order types and order properties, but don't support order updates.

Order Types

The following table describes the available order types for each asset class that the Binance and Binance US brokerage models support:

Order TypeCryptoCrypto Futures
Marketgreen checkgreen check
Limitgreen checkgreen check
Stop limitgreen check

Order Properties

The Binance and Binance US brokerage models supports custom order properties. The following table describes the members of the BinanceOrderProperties object that you can set to customize order execution:

PropertyData TypeDescriptionDefault Value
TimeInForcetime_in_forceTimeInForce A TimeInForce instruction to apply to the order. The following instructions are supported:
  • DayDAY
  • GoodTilCanceledGOOD_TIL_CANCELED
  • GoodTilDategood_til_date
TimeInForce.GoodTilCanceledTimeInForce.GOOD_TIL_CANCELED
PostOnlypost_onlyboolA flag to signal that the order must only add liquidity to the order book and not take liquidity from the order book. If part of the order results in taking liquidity rather than providing liquidity, the order is rejected without any part of it being filled.
public override void Initialize()
{
    // Set the default order properties
    DefaultOrderProperties = new BinanceOrderProperties
    {
        TimeInForce = TimeInForce.GoodTilCanceled,
        PostOnly = false
    };
}

public override void OnData(Slice slice)
{
    // Use default order order properties
    LimitOrder(_symbol, quantity, limitPrice);
    
    // Override the default order properties
    LimitOrder(_symbol, quantity, limitPrice, 
               orderProperties: new BinanceOrderProperties
               { 
                   TimeInForce = TimeInForce.Day,
                   PostOnly = false
               });
    LimitOrder(_symbol, quantity, limitPrice, 
               orderProperties: new BinanceOrderProperties
               { 
                   TimeInForce = TimeInForce.GoodTilDate(new DateTime(year, month, day)),
                   PostOnly = true
               });
}
def initialize(self) -> None:
    # Set the default order properties
    self.default_order_properties = BinanceOrderProperties()
    self.default_order_properties.time_in_force = TimeInForce.GOOD_TIL_CANCELED
    self.default_order_properties.post_only = False

def on_data(self, slice: Slice) -> None:
    # Use default order order properties
    self.limit_order(self._symbol, quantity, limit_price)
    
    # Override the default order properties
    order_properties = BinanceOrderProperties()
    order_properties.time_in_force = TimeInForce.DAY
    order_properties.post_only = True
    self.limit_order(self._symbol, quantity, limit_price, order_properties=order_properties)

    order_properties.time_in_force = TimeInForce.good_til_date(datetime(year, month, day))
    self.limit_order(self._symbol, quantity, limit_price, order_properties=order_properties)

Updates

The Binance and Binance US brokerage models don't support order updates, but you can cancel an existing order and then create a new order with the desired arguments. For more information about this workaround, see the Workaround for Brokerages That Don’t Support Updates.

Fills

The Binance brokerage models use the ImmediateFillModel.

Slippage

The Binance brokerage models use the NullSlippageModel.

security.set_slippage_model(NullSlippageModel.instance);
security.set_slippage_model(NullSlippageModel.instance)

Fees

The following table shows the fee model that each Binance brokerage model uses:

Brokerage ModelFee Model
BinanceBrokerageModelBinanceFeeModel
BinanceFuturesBrokerageModelBinanceFuturesFeeModel
BinanceCoinFuturesBrokerageModelBinanceCoinFuturesFeeModel
BinanceUSBrokerageModelBinanceFeeModel

The Binance brokerage models use the default argument values for each fee model so that it models the current Binance fee schedule.

Buying Power

The Binance brokerage models use the CashBuyingPowerModel for cash accounts and the SecurityMarginModel for margin accounts.

The following table shows the maximum leverage each brokerage model allows for margin accounts:

Brokerage ModelMaximum Leverage
BinanceBrokerageModel3
BinanceFuturesBrokerageModel25
BinanceCoinFuturesBrokerageModel25

The BinanceUSBrokerageModel doesn't currently support margin trading.

Settlement

The Binance brokerage models use the ImmediateSettlementModel.

Margin Interest Rate

The following table shows the margin interest rate model that the Binance brokerages use:

Brokerage ModelMargin Interest Rate Model
BinanceBrokerageModelNullMarginInterestRateModel
BinanceFuturesBrokerageModelBinanceFutureMarginInterestRateModel for Crypto Perpetual Futures and NullMarginInterestRateModel for other assets
BinanceCoinFuturesBrokerageModelBinanceFutureMarginInterestRateModel for Crypto Perpetual Futures and NullMarginInterestRateModel for other assets
BinanceUSBrokerageModelNullMarginInterestRateModel

Default Markets

The following table shows the default market of the Binance brokerage models:

Brokerage ModelMarket
BinanceBrokerageModelMarket.BinanceMarket.BINANCE
BinanceFuturesBrokerageModelMarket.BinanceMarket.BINANCE
BinanceCoinFuturesBrokerageModelMarket.BinanceMarket.BINANCE
BinanceUSBrokerageModelMarket.BinanceUSMarket.BINANCE_US

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: