Supported Models

Coinbase

Introduction

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

SetBrokerageModel(BrokerageName.Coinbase, AccountType.Cash);
self.set_brokerage_model(BrokerageName.COINBASE, AccountType.CASH)

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

Asset Classes

The CoinbaseBrokerageModel supports trading Crypto.

Orders

The CoinbaseBrokerageModel supports several order types and order properties, but it doesn't support order updates.

Order Types

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

Order TypeCrypto
Marketgreen check
Limitgreen check
Stop marketgreen check
Supported after 2019-03-23 in backtests. For reference, see the Coinbase Market Structure Update on the Coinbase website.
Stop limitgreen check

Order Properties

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

PropertyData TypeDescriptionDefault Value
TimeInForcetime_in_forceTimeInForceA TimeInForce instruction to apply to the order. The GoodTilCanceledGOOD_TIL_CANCELED TimeInForce is supported.TimeInForce.GoodTilCanceledTimeInForce.GOOD_TIL_CANCELED
PostOnlypost_onlyboolA flag that signals 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.
SelfTradePreventionIdself_trade_prevention_idboolA flag that signals self-trade prevention is enabled for this order. Self-trade prevention helps prevent an order from crossing against the same user, reducing the risk of unintentional trades within the same account.
public override void Initialize()
{
    // Set the default order properties
    DefaultOrderProperties = new CoinbaseOrderProperties
    {
        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 CoinbaseOrderProperties
               { 
                   TimeInForce = TimeInForce.GoodTilCanceled,
                   PostOnly = true
               });
}
def initialize(self) -> None:
    # Set the default order properties
    self.default_order_properties = CoinbaseOrderProperties()
    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 = CoinbaseOrderProperties()
    order_properties.time_in_force = TimeInForce.GOOD_TIL_CANCELED
    order_properties.post_only = True
    self.limit_order(self._symbol, quantity, limit_price, order_properties=order_properties)

Updates

The CoinbaseBrokerageModel doesn'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 CoinbaseBrokerageModel uses the ImmediateFillModel.

Slippage

The CoinbaseBrokerageModel uses the NullSlippageModel.

Fees

The CoinbaseBrokerageModel uses the CoinbaseFeeModel.

Buying Power

The CoinbaseBrokerageModel uses the CashBuyingPowerModel. The brokerage model doesn't currently support margin trading.

Settlement

The CoinbaseBrokerageModel uses the ImmediateSettlementModel.

Margin Interest Rate

The CoinbaseBrokerageModel uses the NullMarginInterestRateModel.

Default Markets

The default market of the CoinbaseBrokerageModel is Market.CoinbaseMarket.COINBASE.

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: