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 Type | Crypto | Crypto Futures |
---|---|---|
Market | ||
Limit | ||
Stop market | ||
Stop limit |
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:
Property | Data Type | Description | Default Value |
---|---|---|---|
TimeInForce time_in_force | TimeInForce |
A TimeInForce instruction to apply to the order. The following instructions are supported:
| TimeInForce.GoodTilCanceled TimeInForce.GOOD_TIL_CANCELED |
PostOnly post_only | bool | A 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. | |
ReduceOnly reduce_only | bool? bool/NoneType | A 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.New
OrderStatus.NEW
OrderStatus.PartiallyFilled
OrderStatus.PARTIALLY_FILLED
OrderStatus.Submitted
OrderStatus.SUBMITTED
OrderStatus.UpdateSubmitted
OrderStatus.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.
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 Class | Model |
---|---|
Crypto | CashBuyingPowerModel for cash accounts or SecurityMarginModel for margin accounts |
CryptoFuture | CryptoFutureMarginModel |
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.