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
MarketOrdergreen check
LimitOrdergreen check
StopMarketOrdergreen check
Supported after 2019-03-23 in backtests. For reference, see the Coinbase Market Structure Update on the Coinbase website.
StopLimitOrdergreen 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:

PropertyDescription
TimeInForceA TimeInForce instruction to apply to the order. The GoodTilCanceled TimeInForce is supported.
PostOnlyA 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.
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.

security.set_slippage_model(NullSlippageModel.instance);
security.set_slippage_model(NullSlippageModel.instance)

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.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: