Supported Models

Bybit

Introduction

This page explains the 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.set_brokerage_model(BrokerageName.BYBIT, AccountType.CASH)
self.set_brokerage_model(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
Marketgreen checkgreen check
Limitgreen checkgreen check
Stop marketgreen checkgreen check
Stop limitgreen 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:

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. This order property is only available for limit orders.
ReduceOnlyreduce_onlybool?bool/NoneTypeA 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.default_order_properties = BybitOrderProperties()
    self.default_order_properties.time_in_force = TimeInForce.GOOD_TIL_CANCELED
    self.default_order_properties.post_only = False
    self.default_order_properties.reduce_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 = BybitOrderProperties()
    order_properties.time_in_force = TimeInForce.DAY
    order_properties.post_only = True
    self.default_order_properties.reduce_only = False
    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))
    order_properties.post_only = False
    self.default_order_properties.reduce_only = True
    self.limit_order(self._symbol, quantity, limit_price, order_properties=order_properties)

Updates

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

  • OrderStatus.NewOrderStatus.NEW
  • OrderStatus.PartiallyFilledOrderStatus.PARTIALLY_FILLED
  • OrderStatus.SubmittedOrderStatus.SUBMITTED
  • OrderStatus.UpdateSubmittedOrderStatus.FILLED

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.set_slippage_model(NullSlippageModel.instance);
security.set_slippage_model(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.BybitMarket.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: