Overall Statistics
Total Trades
2
Average Win
0.02%
Average Loss
0%
Compounding Annual Return
-2.885%
Drawdown
21.000%
Expectancy
0
Net Profit
-4.270%
Sharpe Ratio
-0.095
Probabilistic Sharpe Ratio
5.379%
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
0.003
Beta
0.192
Annual Standard Deviation
0.129
Annual Variance
0.017
Information Ratio
0.13
Tracking Error
0.513
Treynor Ratio
-0.064
Total Fees
$43.99
Estimated Strategy Capacity
$77000.00
Lowest Capacity Asset
BTCUSD 2S7
/*
 * 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.
*/

using System;
using QuantConnect.Brokerages;
using QuantConnect.Data;
using QuantConnect.Orders;

namespace QuantConnect.Algorithm.CSharp
{
    public class BinanceBrokerageExampleAlgorithm : QCAlgorithm
    {
        private Symbol _symbol;
        
        public override void Initialize()
        {
            SetStartDate(2021, 1, 1);
            SetCash(100000);
            
            SetBrokerageModel(BrokerageName.BinanceUS, AccountType.Cash);
            
            _symbol = AddCrypto("BTCUSD", Resolution.Minute).Symbol;

            // Set default order properties
            DefaultOrderProperties = new BinanceOrderProperties
            {
                TimeInForce = TimeInForce.GoodTilCanceled,
                PostOnly = false
            };
        }
        
        public override void OnData(Slice data)
        {
            if (Portfolio.Invested)
            {
                return;
            }
            
            // Place an order with the default order properties 
            MarketOrder(_symbol, 1);
            
            // Place an order with new order properties
            var orderProperties = new BinanceOrderProperties { 
                TimeInForce = TimeInForce.Day,
                PostOnly = true 
            };
            var ticket = LimitOrder(_symbol, -0.5, Math.Round(data[_symbol].Price + 1000, 2), orderProperties: orderProperties);
            
            // If we try to call `Update`, an exception is raised
            // ticket.Update(...)
            
            // Update the order
            ticket.Cancel();
            LimitOrder(_symbol, -0.5, Math.Round(data[_symbol].Price + 100, 2), orderProperties: orderProperties);
        }

    }
}