Supported Models

Kraken

Introduction

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

SetBrokerageModel(BrokerageName.Kraken, AccountType.Cash);
SetBrokerageModel(BrokerageName.Kraken, AccountType.Margin);
self.set_brokerage_model(BrokerageName.KRAKEN, AccountType.CASH)
self.set_brokerage_model(BrokerageName.KRAKEN, AccountType.MARGIN)

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

Asset Classes

The KrakenBrokerageModel supports trading Crypto.

Orders

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

Order TypeCrypto
Marketgreen check
Limitgreen check
Limit if touchedgreen check
Stop marketgreen check
Stop limitgreen check

Order Properties

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

PropertyData TypeDescriptionDefault Value
TimeInForcetime_in_forceTimeInForceA TimeInForce instruction to apply to the order. The following instructions are supported:
  • DayDAY
  • GoodTilCanceledGOOD_TIL_CANCELED
  • GoodTilDategood_til_date
TimeInForce.GoodTilCanceledTimeInForce.GOOD_TIL_CANCELED
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.
FeeInBasefee_in_baseboolA flag to signal that the order fees should be paid in the base currency, which is the default behavior when selling. This flag must be the opposite of the FeeInQuotefee_in_quote flag.
FeeInQuotefee_in_quoteboolA flag to signal that the order fees should be paid in the quote currency, which is the default behavior when buying. This flag must be the opposite of the FeeInBasefee_in_base flag.
NoMarketPriceProtectionno_market_price_protectionboolA flag to signal that no Market Price Protection should be used.
ConditionalOrderconditional_orderOrderAn Order that's submitted when the primary order is executed. The ConditionalOrderconditional_order quantity must match the primary order quantity and the ConditionalOrderconditional_order direction must be the opposite of the primary order direction. This order property is only available for live algorithms.
public override void Initialize()
{
    // Set the default order properties
    DefaultOrderProperties = new KrakenOrderProperties
    {
        TimeInForce = TimeInForce.GoodTilCanceled,
        PostOnly = false,
        FeeInBase = true,
        FeeInQuote = false,
        NoMarketPriceProtection = true
    };
}

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 KrakenOrderProperties
               { 
                   TimeInForce = TimeInForce.Day,
                   PostOnly = true,
                   FeeInBase = false,
                   FeeInQuote = true,
                   NoMarketPriceProtection = true
               });
    LimitOrder(_symbol, quantity, limitPrice, 
               orderProperties: new KrakenOrderProperties
               { 
                   TimeInForce = TimeInForce.GoodTilDate(new DateTime(year, month, day)),
                   PostOnly = false,
                   FeeInBase = true,
                   FeeInQuote = false,
                   NoMarketPriceProtection = false,
                   ConditionalOrder = StopLimitOrder(_symbol, -quantity, stopLimitPrice, stopPrice)
               });
}
def initialize(self) -> None:
    # Set the default order properties
    self.default_order_properties = KrakenOrderProperties()
    self.default_order_properties.time_in_force = TimeInForce.GOOD_TIL_CANCELED
    self.default_order_properties.post_only = False
    self.default_order_properties.fee_in_base = True
    self.default_order_properties.fee_in_quote = False
    self.default_order_properties.no_market_price_protection = True

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 = KrakenOrderProperties()
    order_properties.time_in_force = TimeInForce.DAY
    order_properties.post_only = True
    order_properties.fee_in_base = False
    order_properties.fee_in_quote = True
    order_properties.no_market_price_protection = True
    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
    order_properties.fee_in_base = True
    order_properties.fee_in_quote = False
    order_properties.no_market_price_protection = False
    order_properties.conditional_order = StopLimitOrder(self._symbol, -quantity, stop_limit_price, stop_price)
    self.limit_order(self._symbol, quantity, limit_price, order_properties=order_properties)

Updates

The KrakenBrokerageModel 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 KrakenBrokerageModel uses the ImmediateFillModel.

Slippage

The KrakenBrokerageModel uses the NullSlippageModel.

Fees

The KrakenBrokerageModel uses the KrakenFeeModel.

Buying Power

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

If you have a margin account, the KrakenBrokerageModel allows 1x leverage for most Crypto pairs. The following table shows pairs that have additional leverage available:

Quote CurrencyBase CurrenciesLeverage
ADABTC, ETH, USD, EUR3
BCHBTC, USD, EUR2
BTCUSD, EUR
5
DASHBTC, USD, EUR3
EOSBTC, ETH, USD, EUR3
ETHBTC, USD, EUR5
LINKBTC, ETH, USD, EUR3
LTCBTC, USD, EUR3
REPBTC, ETH, USD, EUR2
TRXBTC, ETH, USD, EUR3
USDCUSD, EUR3
USDTUSD, EUR2
XMRBTC, USD, EUR2
XRPBTC, USD, EUR3
XTZBTC, ETH, USD, EUR2

Settlement

The KrakenBrokerageModel uses the ImmediateSettlementModel.

Margin Interest Rate

The KrakenBrokerageModel uses the NullMarginInterestRateModel.

Default Markets

The default market of the KrakenBrokerageModel is Market.KrakenMarket.KRAKEN.

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: