Overall Statistics
Total Trades
2
Average Win
0.10%
Average Loss
0%
Compounding Annual Return
1.607%
Drawdown
10.200%
Expectancy
0
Net Profit
4.724%
Sharpe Ratio
-0.159
Probabilistic Sharpe Ratio
5.131%
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
-0.012
Beta
-0.07
Annual Standard Deviation
0.064
Annual Variance
0.004
Information Ratio
0.03
Tracking Error
0.362
Treynor Ratio
0.144
Total Fees
₮4.03
Estimated Strategy Capacity
₮39000000.00
Lowest Capacity Asset
BTCUSDT 2V3
Portfolio Turnover
0.01%
# region imports
from AlgorithmImports import *
# endregion

class BybitBrokerageExampleAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 1, 1)
        self.SetAccountCurrency("USDT", 100_000)
        
        self.SetBrokerageModel(BrokerageName.Bybit, AccountType.Margin)
        
        self.symbol = self.AddCryptoFuture("BTCUSDT", Resolution.Minute).Symbol
        
        # Set default order properties
        self.DefaultOrderProperties = BybitOrderProperties()
        self.DefaultOrderProperties.TimeInForce = TimeInForce.GoodTilCanceled
        self.DefaultOrderProperties.PostOnly = False
        self.DefaultOrderProperties.ReduceOnly = False


    def OnData(self, data):
        if self.Portfolio.Invested:
            return
        
        # Place an order with the default order properties
        self.MarketOrder(self.symbol, 0.1)
        
        # Place an order with new order properties
        order_properties = BybitOrderProperties()
        order_properties.TimeInForce = TimeInForce.GoodTilCanceled
        order_properties.PostOnly = True
        order_properties.ReduceOnly = False
        ticket = self.LimitOrder(self.symbol, -0.5, round(data[self.symbol].Price + 5000, 1), orderProperties = order_properties)
        
        
        # Update the order
        order_fields = UpdateOrderFields()
        order_fields.Quantity = -0.4
        order_fields.LimitPrice = round(data[self.symbol].Price + 1000, 1)
        order_fields.Tag = "Informative order tag"
        response = ticket.Update(order_fields)
        if not self.LiveMode and response.IsSuccess:
            self.Debug("Order updated successfully")