Supported Models

Bitfinex

Introduction

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

SetBrokerageModel(BrokerageName.Bitfinex, AccountType.Cash);
SetBrokerageModel(BrokerageName.Bitfinex, AccountType.Margin);
self.set_brokerage_model(BrokerageName.BITFINEX, AccountType.CASH)
self.set_brokerage_model(BrokerageName.BITFINEX, AccountType.MARGIN)

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

Asset Classes

The BitfinexBrokerageModel supports trading Crypto.

Orders

The BitfinexBrokerageModel 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 BitfinexBrokerageModel supports:

Order TypeCrypto
Marketgreen check
Limitgreen check
Limit if touchedgreen check
Stop marketgreen check
Stop limitgreen check
Market on opengreen check
Market on closegreen check

Order Properties

The BitfinexBrokerageModel supports custom order properties. The following table describes the members of the BitfinexOrderProperties 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
HiddenhiddenboolA flag to signal that the order should be hidden. Hidden orders do not appear in the order book, so they do not influence other market participants. Hidden orders incur the taker fee.
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 BitfinexOrderProperties
    {
        TimeInForce = TimeInForce.GoodTilCanceled,
        Hidden = false,
        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 BitfinexOrderProperties
               { 
                   TimeInForce = TimeInForce.Day,
                   Hidden = true,
                   PostOnly = false
               });
    LimitOrder(_symbol, quantity, limitPrice, 
               orderProperties: new BitfinexOrderProperties
               { 
                   TimeInForce = TimeInForce.GoodTilDate(new DateTime(year, month, day)),
                   Hidden = false,
                   PostOnly = true
               });
}
def initialize(self) -> None:
    # Set the default order properties
    self.default_order_properties = BitfinexOrderProperties()
    self.default_order_properties.time_in_force = TimeInForce.GOOD_TIL_CANCELED
    self.default_order_properties.hidden = False
    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 = BitfinexOrderProperties()
    order_properties.time_in_force = TimeInForce.DAY
    order_properties.hidden = True
    order_properties.post_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.hidden = False
    order_properties.post_only = True
    self.limit_order(self._symbol, quantity, limit_price, order_properties=order_properties)

Updates

The BitfinexBrokerageModel supports order updates.

Fills

The BitfinexBrokerageModel uses the ImmediateFillModel.

Slippage

The BitfinexBrokerageModel uses the NullSlippageModel.

Fees

The BitfinexBrokerageModel uses the BitfinexFeeModel with the default argument values that models the current Bitfinex fee schedule.

Buying Power

The BitfinexBrokerageModel uses the CashBuyingPowerModel for cash accounts and the SecurityMarginModel for margin accounts.

If you have a margin account, the BitfinexBrokerageModel allows 3.3x leverage.

Settlement

The BitfinexBrokerageModel uses the ImmediateSettlementModel.

Margin Interest Rate

The BitfinexBrokerageModel uses the NullMarginInterestRateModel.

Default Markets

The default market of the BitfinexBrokerageModel is Market.BitfinexMarket.BITFINEX.

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: