Esempio n. 1
0
        public TradeEngine()
        {
            //create main timer for polling
            mainTimer           = new System.Timers.Timer();
            mainTimer.Interval  = 150000;        //launch polling event every 2.5 minutes
            mainTimer.AutoReset = true;
            mainTimer.Enabled   = true;

            myAccountSettings = new AccountSettings {
                BASEURI = BASEURI, APIKEY = APIKEY, ID = ID
            };

            //initialize default variables
            myAccount = new AccountAccessor(myAccountSettings);
            myAccount.RegisterTimer(mainTimer);

            instruments = new InstrumentAccessor(myAccountSettings, "EUR_USD");
            instruments.RegisterTimer(mainTimer);

            orders = new OrderAccessor(myAccountSettings);

            //OMG, initialize  first object in collection
            SMA50 = new List <IndicatorOverTime>();
            SMA50.Add(new IndicatorOverTime {
                result = Indicators.SMA((instruments.GetBars(50, "M5"))), time = instruments.GetBars(1, "M5").candles[0].time
            });


            trend = new TrendDirection();

            //set because log file is written before trend is actually calculated, so should be sideways until there is enough data to actually determine the trend
            trend = TrendDirection.Sideways;

            tradeEngineLog = new  LogData();

            //write headers to csv
            using (StreamWriter writer = new StreamWriter(outFile))
            {
                CsvWriter csvWriter = new CsvWriter(writer);
                csvWriter.WriteHeader <LogData>();
                csvWriter.NextRecord();
            }



            WriteLog();
            mainTimer.Elapsed += OnUpdate;
        }
Esempio n. 2
0
        public OrderAccessor(AccountSettings _settings)
        {
            this.accountSettings = _settings;
            var         client  = new RestClient(string.Format("{0}{1}", accountSettings.BASEURI, EndPoints.order(accountSettings.ID)));
            RestRequest request = new RestRequest()
            {
                Method = Method.GET
            };

            request.AddHeader("Authorization", string.Format("Bearer {0}", accountSettings.APIKEY));
            request.RequestFormat = DataFormat.Json;
            IRestResponse _response = client.Execute(request);

            /*
             * Console.ForegroundColor = ConsoleColor.Green;
             * Console.WriteLine("Order Status:{0}", _response.StatusCode);
             * Console.ResetColor();
             */
        }
Esempio n. 3
0
        public InstrumentAccessor(AccountSettings _accountSettings, string _currencyPair)
        {
            this.currencyPair    = _currencyPair;
            this.accountSettings = _accountSettings;
            var         client  = new RestClient(string.Format("{0}{1}/{2}/candles", accountSettings.BASEURI, EndPoints.instruments(), this.currencyPair));
            RestRequest request = new RestRequest()
            {
                Method = Method.GET
            };

            request.AddHeader("Authorization", string.Format("Bearer {0}", accountSettings.APIKEY));
            request.AddParameter("count", this.period);
            request.AddParameter("granularity", this.timeFrame);  //5 minute chart
            request.RequestFormat = DataFormat.Json;
            IRestResponse <OandaRootInstrumentObject> _response = client.Execute <OandaRootInstrumentObject>(request);

            //this.data = _response.Data;  //set public field to deserialized data
            this.bar     = _response.Data;
            this.allBars = new List <OandaRootInstrumentObject>();
            this.allBars.Add(new OandaRootInstrumentObject {
                instrument = this.currencyPair, granularity = this.timeFrame, candles = new List <Candle>()
            });
            this.allBars[0].candles.Add(this.bar.candles[0]);

            this.response = _response;


            //Program.mainTimer.Elapsed += this.OnUpdate;  //add Onupdate method to timer invocation list

            /*
             * Console.ForegroundColor = ConsoleColor.Green;
             * Console.WriteLine("Instrument Status:{0}", _response.StatusCode);
             * Console.WriteLine("Using {0} currency pair", this.currencyPair);
             * Console.ResetColor();
             */
        }