Overall Statistics
Total Orders
3
Average Win
0.02%
Average Loss
0%
Compounding Annual Return
-0.645%
Drawdown
22.000%
Expectancy
0
Start Equity
100000.00
End Equity
97880.43
Net Profit
-2.120%
Sharpe Ratio
-0.257
Sortino Ratio
-0.301
Probabilistic Sharpe Ratio
3.352%
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
-0.077
Beta
0.15
Annual Standard Deviation
0.109
Annual Variance
0.012
Information Ratio
-0.658
Tracking Error
0.538
Treynor Ratio
-0.186
Total Fees
$43.99
Estimated Strategy Capacity
$30000.00
Lowest Capacity Asset
BTCUSD 2S7
Portfolio Turnover
0.04%
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from AlgorithmImports import *

class BinanceUSBrokerageExampleAlgorithm(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2021, 1, 1)
        self.set_cash(100000)
        
        self.set_brokerage_model(BrokerageName.BINANCE_US, AccountType.CASH)
        
        self._symbol = self.add_crypto("BTCUSD", Resolution.MINUTE).symbol
        
        # Set default order properties
        self.default_order_properties = BinanceOrderProperties()
        self.default_order_properties.time_in_force = TimeInForce.GOOD_TIL_CANCELED
        self.default_order_properties.post_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, 1)
        
        # Place an order with new order properties
        order_properties = BinanceOrderProperties()
        order_properties.time_in_force = TimeInForce.DAY
        order_properties.post_only = True
        ticket = self.limit_order(self._symbol, -0.5, round(data[self._symbol].price + 1000, 2), order_properties = order_properties)
        
        # If we try to call `Update`, an exception is raised
        # ticket.update()
        
        # Update the order
        ticket.cancel()
        ticket = self.limit_order(self._symbol, -0.5, round(data[self._symbol].price + 100, 2), order_properties = order_properties)