Overall Statistics
Total Orders
2
Average Win
0.10%
Average Loss
0%
Compounding Annual Return
-0.800%
Drawdown
14.200%
Expectancy
0
Start Equity
100000
End Equity
97375.38
Net Profit
-2.625%
Sharpe Ratio
-0.409
Sortino Ratio
-0.547
Probabilistic Sharpe Ratio
2.667%
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
-0.015
Beta
-0.09
Annual Standard Deviation
0.079
Annual Variance
0.006
Information Ratio
-0.476
Tracking Error
0.462
Treynor Ratio
0.36
Total Fees
â‚®4.03
Estimated Strategy Capacity
â‚®20000000.00
Lowest Capacity Asset
BTCUSDT 2V3
Portfolio Turnover
0.01%
# region imports
from AlgorithmImports import *
# endregion

class BybitBrokerageExampleAlgorithm(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2021, 1, 1)
        self.set_account_currency("USDT", 100_000)
        
        self.set_brokerage_model(BrokerageName.BYBIT, AccountType.MARGIN)
        
        self._symbol = self.add_crypto_future("BTCUSDT", Resolution.MINUTE).symbol
        
        # Set default order properties
        self.default_order_properties = BybitOrderProperties()
        self.default_order_properties.time_in_force = TimeInForce.GOOD_TIL_CANCELED
        self.default_order_properties.post_only = False
        self.default_order_properties.reduce_only = False


    def on_data(self, data):
        if self.portfolio.invested:
            return
        
        # Place an order with the default order properties
        self.market_order(self._symbol, 0.1)
        
        # Place an order with new order properties
        order_properties = BybitOrderProperties()
        order_properties.time_in_force = TimeInForce.GOOD_TIL_CANCELED
        order_properties.post_only = True
        order_properties.reduce_only = False
        ticket = self.limit_order(self._symbol, -0.5, round(data[self._symbol].price + 5000, 1), order_properties = order_properties)
        
        
        # Update the order
        order_fields = UpdateOrderFields()
        order_fields.quantity = -0.4
        order_fields.limit_price = round(data[self._symbol].price + 1000, 1)
        order_fields.tag = "Informative order tag"
        response = ticket.update(order_fields)
        if not self.live_mode and response.is_success:
            self.debug("Order updated successfully")