Supported Models

Bybit

Introduction

This page explains BybitBrokerageModel, including the asset classes it supports, its default security-level models, and it's default markets.

SetBrokerageModel(BrokerageName.Bybit, AccountType.Cash);
SetBrokerageModel(BrokerageName.Bybit, AccountType.Margin);
self.SetBrokerageModel(BrokerageName.Bybit, AccountType.Cash)
self.SetBrokerageModel(BrokerageName.Bybit, AccountType.Margin)

To view the implementation of this model, see the LEAN GitHub repository.

Asset Classes

The BybitBrokerageModel supports trading Crypto and Crypto Futures.

Orders

The BybitBrokerageModel supports several order types, order properties, and order updates.

Order Types

The following table describes the available order types for each asset class that the BybitBrokerageModel supports:

Order TypeCryptoCrypto Futures
MarketOrdergreen checkgreen check
LimitOrdergreen checkgreen check
StopMarketOrdergreen checkgreen check
StopLimitOrdergreen checkgreen check

Order Properties

The BybitBrokerageModel supports custom order properties. The following table describes the members of the BybitBrokerageModel object that you can set to customize order execution:

PropertyDescription
TimeInForce A TimeInForce instruction to apply to the order. The following instructions are supported:
  • Day
  • GoodTilCanceled
  • GoodTilDate
PostOnlyA 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. This order property is only available for limit orders.
ReduceOnlyA flag to signal that the order must only reduce your current position size. For more information about this order property, see Reduce-Only Order on the Bybit website.
public override void Initialize()
{
    // Set the default order properties
    DefaultOrderProperties = new BybitOrderProperties
    {
        TimeInForce = TimeInForce.GoodTilCanceled,
        PostOnly = false,
        ReduceOnly = 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 BybitOrderProperties
               { 
                   TimeInForce = TimeInForce.Day,
                   PostOnly = true,
                   ReduceOnly = false
               });
    LimitOrder(_symbol, quantity, limitPrice, 
               orderProperties: new BybitOrderProperties
               { 
                   TimeInForce = TimeInForce.GoodTilDate(new DateTime(year, month, day)),
                   PostOnly = false,
                   ReduceOnly = true
               });
}
def Initialize(self) -> None:
    # Set the default order properties
    self.DefaultOrderProperties = BybitOrderProperties()
    self.DefaultOrderProperties.TimeInForce = TimeInForce.GoodTilCanceled
    self.DefaultOrderProperties.PostOnly = False
    self.DefaultOrderProperties.ReduceOnly = False

def OnData(self, slice: Slice) -> None:
    # Use default order order properties
    self.LimitOrder(self.symbol, quantity, limit_price)
    
    # Override the default order properties
    order_properties = BybitOrderProperties()
    order_properties.TimeInForce = TimeInForce.Day
    order_properties.PostOnly = True
    self.DefaultOrderProperties.ReduceOnly = False
    self.LimitOrder(self.symbol, quantity, limit_price, orderProperties=order_properties)

    order_properties.TimeInForce = TimeInForce.GoodTilDate(datetime(year, month, day))
    order_properties.PostOnly = False
    self.DefaultOrderProperties.ReduceOnly = True
    self.LimitOrder(self.symbol, quantity, limit_price, orderProperties=order_properties)

Updates

The BybitBrokerageModel supports order updates for Crypto Future assets that have one of the following order states:

  • OrderStatus.New
  • OrderStatus.PartiallyFilled
  • OrderStatus.Submitted
  • OrderStatus.UpdateSubmitted

In cases where you can't update an order, you can cancel the 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 BybitBrokerageModel uses the ImmediateFillModel.

Slippage

The BybitBrokerageModel uses the NullSlippageModel.

security.SetSlippageModel(NullSlippageModel.Instance);
security.SetSlippageModel(NullSlippageModel.Instance)

Fees

The BybitBrokerageModel uses the BybitFeeModel for Crypto trades and the BybitFuturesFeeModel for Crypto Future trades. In both cases, the brokerage model uses the default argument values that models the Bybit fee schedule for VIP Level 0.

Buying Power

The BybitBrokerageModel sets the buying power model based on the asset class of the security. The following table shows the default buying power model of each asset class:

Asset ClassModel
CryptoCashBuyingPowerModel for cash accounts or SecurityMarginModel for margin accounts
CryptoFutureCryptoFutureMarginModel

If you have a margin account, the BybitBrokerageModel allows 10x leverage.

Settlement

The BybitBrokerageModel uses the ImmediateSettlementModel.

Margin Interest Rate

The BybitBrokerageModel uses the BybitFutureMarginInterestRateModel for perpetual Futures and the NullMarginInterestRateModel for every other asset.

Default Markets

The default market of the BybitBrokerageModel is Market.Bybit.

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: