Overall Statistics
Total Orders
3
Average Win
0%
Average Loss
0%
Compounding Annual Return
18.443%
Drawdown
59.000%
Expectancy
0
Start Equity
100000
End Equity
175179.37
Net Profit
75.179%
Sharpe Ratio
0.633
Sortino Ratio
0.903
Probabilistic Sharpe Ratio
24.264%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.079
Beta
0.613
Annual Standard Deviation
0.402
Annual Variance
0.162
Information Ratio
-1.114
Tracking Error
0.26
Treynor Ratio
0.416
Total Fees
$122.73
Estimated Strategy Capacity
$83000.00
Lowest Capacity Asset
BTCUSD 10B
Portfolio Turnover
0.05%
# region imports
from AlgorithmImports import *
# endregion

class KrakenBrokerageExampleAlgorithm(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2021, 1, 1)
        self.set_cash(100000)
        
        self.set_brokerage_model(BrokerageName.KRAKEN, AccountType.CASH)
        
        self._symbol = self.add_crypto("BTCUSD", Resolution.MINUTE).symbol
        
        # Set default order properites
        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 = False
        self.default_order_properties.fee_in_quote = True
        self.default_order_properties.no_market_price_protection = True


    def on_data(self, data):
        if self.portfolio.invested:
            return
        
        # Place an order with the default order properties
        self.limit_order(self._symbol, 1, round(data[self._symbol].price + 100, 1))
        
        # Place an order and with new order properties
        order_properties = KrakenOrderProperties()
        order_properties.post_only = True
        order_properties.fee_in_base = True
        order_properties.fee_in_quote = False
        order_properties.no_market_price_protection = False
        ticket = self.limit_order(self._symbol, 1, round(data[self._symbol].price * .9, 1), order_properties = order_properties)
        
        # If we try to call `Update`, an exception is raised
        # ticket.update()
        
        # Update the order
        ticket.cancel()
        order_properties.conditional_order = MarketOrder(self._symbol, -1, self.time)
        self.limit_order(self._symbol, 1, round(data[self._symbol].price * .99, 1), order_properties = order_properties)
        
        
    def on_order_event(self, order_event):
        if order_event.status == OrderStatus.FILLED:
            self.debug(f"Order fee: {order_event.order_fee}") # The fees are paid in different currencies if we flip FeeInBase and FeeInQuote