Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
#region imports using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Globalization; using System.Drawing; using QuantConnect; using QuantConnect.Algorithm.Framework; using QuantConnect.Algorithm.Framework.Selection; using QuantConnect.Algorithm.Framework.Alphas; using QuantConnect.Algorithm.Framework.Portfolio; using QuantConnect.Algorithm.Framework.Execution; using QuantConnect.Algorithm.Framework.Risk; using QuantConnect.Parameters; using QuantConnect.Benchmarks; using QuantConnect.Brokerages; using QuantConnect.Util; using QuantConnect.Interfaces; using QuantConnect.Algorithm; using QuantConnect.Indicators; using QuantConnect.Data; using QuantConnect.Data.Consolidators; using QuantConnect.Data.Custom; using QuantConnect.DataSource; using QuantConnect.Data.Fundamental; using QuantConnect.Data.Market; using QuantConnect.Data.UniverseSelection; using QuantConnect.Notifications; using QuantConnect.Orders; using QuantConnect.Orders.Fees; using QuantConnect.Orders.Fills; using QuantConnect.Orders.Slippage; using QuantConnect.Scheduling; using QuantConnect.Securities; using QuantConnect.Securities.Equity; using QuantConnect.Securities.Future; using QuantConnect.Securities.Option; using QuantConnect.Securities.Forex; using QuantConnect.Securities.Crypto; using QuantConnect.Securities.Interfaces; using QuantConnect.Storage; using QuantConnect.Data.Custom.AlphaStreams; using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm; using QCAlgorithmFrameworkBridge = QuantConnect.Algorithm.QCAlgorithm; using QuantConnect.Indicators.CandlestickPatterns; using Newtonsoft.Json; #endregion namespace QuantConnect.Algorithm.CSharp { public partial class TestAlgo : QCAlgorithm { // PROGRAM VARIABLES public string base_symbol; private Symbol funding_symbol; private int i = 0; // INITIALIASE public override void Initialize() { SetStartDate(2022, 7, 22); SetEndDate(2022, 7, 24); SetAccountCurrency("USD"); SetCash(10000); var crypto = AddCrypto("BTCUSD", Resolution.Daily, Market.FTX); base_symbol = crypto.BaseCurrencySymbol; var fundingRate = AddData<FundingRates>("BTC_FR", Resolution.Daily); funding_symbol = fundingRate.Symbol; SetWarmUp(TimeSpan.FromDays(5)); SetBrokerageModel(BrokerageName.FTX, AccountType.Margin); } // ONDATA public override void OnData(Slice data) { if(IsWarmingUp) { return; } if(data.ContainsKey(funding_symbol)) { Debug($"Acctual Time {Time} | FR Time {data[funding_symbol].timestamp} | FR Symbol {data[funding_symbol].FTXsymbol} | FR Value {data[funding_symbol].Rate}"); } try { if(i < 3) { Debug($"Acctual Time {Time} | FR Time {data[funding_symbol].timestamp} | FR Symbol {data[funding_symbol].FTXsymbol} | FR Value {data[funding_symbol].Rate}"); i++; } } catch (Exception e) { Debug($"Error: {e.Message}"); } } } //CUSTOM DATA class public class FundingRates : BaseData { [JsonProperty("time")] public DateTime timestamp; [JsonProperty("future")] public string FTXsymbol; [JsonProperty("rate")] public decimal Rate; //DEFAULT CONSTRUCTOR: Custom data types need a default constructor. public FundingRates() { Symbol = "BTC_FR"; } // Get data source and stream into algorithm public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLive) { var source = "https://ftx.com/api/funding_rates?future=BTC-PERP"; return new SubscriptionDataSource(source, SubscriptionTransportMedium.Streaming); } //Configure CalendarEvent object with streamed data and then return the CalendarEvent object public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLive) { // Check if string is not empty if (string.IsNullOrWhiteSpace(line)) // Return null object return null; //Example Line Format: //{"future":"BTC-PERP","rate":-1e-6,"time":"2022-07-25T14:00:00+00:00"} FundingRates f = new FundingRates(); try { f = JsonConvert.DeserializeObject<FundingRates>(line); f.EndTime = DateTime.UtcNow.ConvertFromUtc(config.ExchangeTimeZone); f.Value = f.Rate; } catch { /* Do nothing, possible error in json decoding */ } return f; } } }
#region imports using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Globalization; using System.Drawing; using QuantConnect; using QuantConnect.Algorithm.Framework; using QuantConnect.Algorithm.Framework.Selection; using QuantConnect.Algorithm.Framework.Alphas; using QuantConnect.Algorithm.Framework.Portfolio; using QuantConnect.Algorithm.Framework.Execution; using QuantConnect.Algorithm.Framework.Risk; using QuantConnect.Parameters; using QuantConnect.Benchmarks; using QuantConnect.Brokerages; using QuantConnect.Util; using QuantConnect.Interfaces; using QuantConnect.Algorithm; using QuantConnect.Indicators; using QuantConnect.Data; using QuantConnect.Data.Consolidators; using QuantConnect.Data.Custom; using QuantConnect.DataSource; using QuantConnect.Data.Fundamental; using QuantConnect.Data.Market; using QuantConnect.Data.UniverseSelection; using QuantConnect.Notifications; using QuantConnect.Orders; using QuantConnect.Orders.Fees; using QuantConnect.Orders.Fills; using QuantConnect.Orders.Slippage; using QuantConnect.Scheduling; using QuantConnect.Securities; using QuantConnect.Securities.Equity; using QuantConnect.Securities.Future; using QuantConnect.Securities.Option; using QuantConnect.Securities.Forex; using QuantConnect.Securities.Crypto; using QuantConnect.Securities.Interfaces; using QuantConnect.Storage; using QuantConnect.Data.Custom.AlphaStreams; using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm; using QCAlgorithmFrameworkBridge = QuantConnect.Algorithm.QCAlgorithm; #endregion namespace QuantConnect.Algorithm.CSharp { public partial class TestAlgo : QCAlgorithm { //**************************************************************************************************************************************** //USER VARIABLES //**************************************************************************************************************************************** private static string _AccountCurrency = "USD"; private static decimal _StartingCash = 100000m; Resolution _Res = Resolution.Daily; // Reference resolution for our custom TradeBar private static int barPerTimeSpan = 1; private int _WarmUpPeriod = 200; public decimal _PctRisk = 0.10m; private decimal _StopLossPct = 0.05m; public TimeSpan HighVolatiltyEventHourStop = new TimeSpan(38, 0, 0); //***Symbol List*** List <string> _MySymbolList = new List <string> { "BTCUSD", "ETHUSD", }; //***Indicators*** public static int _ROCperiod = 5; } }