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
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
using System;
using RestSharp;
namespace QuantConnect.Algorithm.CSharp
{
    public class HorizontalQuantumRegulators : QCAlgorithm
    {
     private int counter = 0;
        private string symbol = "EURUSD";
        public override void Initialize()
        {
        	SetTimeZone("Europe/London");
        	//SetTimeZone(NodaTime.DateTimeZone.Utc);
            SetStartDate(2019, 4, 7);  //Set Start Date
            SetStartDate(2019, 4, 8);
            SetCash(100000);             //Set Strategy Cash

            AddSecurity(SecurityType.Forex, symbol, Resolution.Minute, Market.Oanda, true, 100, false);

        }
        private string _url = "https://api-fxtrade.oanda.com/v3/instruments/{0}/candles?price={1}&from={2}&count=1&granularity={3}";


        public void OnData(QuoteBars data)
        {
        	

            if(counter++>200)
            {
            	return;
            }
            string r = "M1";
            string filename = "";
            string _price = "BA";
            string s = symbol.Insert(symbol.Length - 3, "_");
            DateTime todate = data[symbol].Time.ToUniversalTime().AddDays(1d);
            DateTime fromdate = UtcTime; //.AddHours(-2l);
            //var url = string.Format(_url, s, _price, ToUnixTimestamp(data[symbol].Time.ToUniversalTime()), r); //ToUnixTimestamp(todate), r);
            var url = string.Format(_url, s, _price, ToUnixTimestamp(fromdate), r); //ToUnixTimestamp(todate), r);

string token = null;
if(token==null)
{
	
	Log("you must set the oanda token");

	return;
}
            RestClient client = new RestClient();
            var auth = "Bearer " + token;
            
            client.Timeout = 120000;

            client.BaseUrl = new Uri(url);

            var request = new RestRequest();
            request.AddHeader("content-type", "application/json");
            request.AddHeader("Authorization", auth);
            IRestResponse response = client.Execute(request);
            //Instrument.FromJson(response.Content);
            try
            {
            Instrument ins = Instrument.FromJson(response.Content);
            foreach (Candle candle in ins.Candles)
            {

                // = candle.Time.ConvertFromUtc(config.ExchangeTimeZone);
                // brokerVolume.Volume = candle.Volume; 
   				Log(string.Format("oanda {0} UTC {1} Exchange {2}", candle.Ask.C, candle.Time, candle.Time.ConvertFromUtc(Portfolio.Securities[symbol].Exchange.TimeZone)));
            }
            }
            catch(Exception)
            {
            	Log(response.Content);
            	counter = 1000000;
            }
            Log(string.Format("leandata {0} UTC {1} Exchange {2}", data[symbol].Ask.Close, data[symbol].Time.ConvertToUtc(Portfolio.Securities[symbol].Exchange.TimeZone), data[symbol].Time));
            Log(string.Format("time {0} Unix {1} FakeUTC {2} UTC {3}", Time, ToUnixTimestamp(Time), Time.ToUniversalTime(), UtcTime));
        System.Threading.Thread.Sleep(200);
            //Log(string.Format("data {0} {1}", data[symbol].Ask.Close, data[symbol].Time.ToUniversalTime()));
        }
        private int ToUnixTimestamp(DateTime dateTime)
        {
            return (int)(TimeZoneInfo.ConvertTimeToUtc(dateTime) -
                     new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc)).TotalSeconds;

        }
        
        
    }
}
namespace QuantConnect.Algorithm.CSharp
{
    using System;
    using System.Net;
    using System.Collections.Generic;

    using Newtonsoft.Json;

    public partial class Instrument
    {
        [JsonProperty("instrument")]
        public string PurpleInstrument { get; set; }

        [JsonProperty("granularity")]
        public string Granularity { get; set; }

        [JsonProperty("candles")]
        public Candle[] Candles { get; set; }
    }

    public partial class Candle
    {
        [JsonProperty("complete")]
        public bool Complete { get; set; }

        [JsonProperty("volume")]
        public long Volume { get; set; }

        [JsonProperty("time")]
        public DateTime Time { get; set; }

        [JsonProperty("bid")]
        public Ask Bid { get; set; }

        [JsonProperty("ask")]
        public Ask Ask { get; set; }
    }

    public partial class Ask
    {
        [JsonProperty("o")]
        public string O { get; set; }

        [JsonProperty("h")]
        public string H { get; set; }

        [JsonProperty("l")]
        public string L { get; set; }

        [JsonProperty("c")]
        public string C { get; set; }
    }

    public partial class Instrument
    {
        public static Instrument FromJson(string json) => JsonConvert.DeserializeObject<Instrument>(json, Converter.Settings);
    }

    public static class Serialize
    {
        public static string ToJson(this Instrument self) => JsonConvert.SerializeObject(self, Converter.Settings);
    }

    public class Converter
    {
        public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
        {
            MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
            DateParseHandling = DateParseHandling.None,
        };
    }
}