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 Type | Crypto |
---|---|
Market | |
Limit | |
Stop market | Supported after 2019-03-23 in backtests. For reference, see the Coinbase Market Structure Update on the Coinbase website. |
Stop limit |
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:
Property | Data Type | Description | Default Value |
---|---|---|---|
TimeInForce time_in_force | TimeInForce | A TimeInForce instruction to apply to the order. The GoodTilCanceled GOOD_TIL_CANCELED TimeInForce is supported. | TimeInForce.GoodTilCanceled TimeInForce.GOOD_TIL_CANCELED |
PostOnly post_only | bool | A 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. | |
SelfTradePreventionId self_trade_prevention_id | bool | A 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.
Settlement
The CoinbaseBrokerageModel
uses the ImmediateSettlementModel.
Margin Interest Rate
The CoinbaseBrokerageModel
uses the NullMarginInterestRateModel.