Exemplo n.º 1
0
        private void WriteLog()
        {
            //build log

            tradeEngineLog = new LogData
            {
                SystemTime  = DateTime.Now,
                BarTime     = instruments.GetBars(1, "M5").candles[0].time,
                BarOpen     = instruments.GetBars(1, "M5").candles[0].mid.o,
                BarComplete = instruments.GetBars(1, "M5").candles[0].complete,
                BarClose    = instruments.GetBars(1, "M5").candles[0].mid.c,
                BarHigh     = instruments.GetBars(1, "M5").candles[0].mid.h,
                BarLow      = instruments.GetBars(1, "M5").candles[0].mid.l,
                Volume      = instruments.GetBars(1, "M5").candles[0].volume,
                SMA50       = SMA50[SMA50.Count - 1].result,
                Trend       = trend
            };

            //write to csv file

            using (StreamWriter writer = new StreamWriter(outFile, append: true))
            {
                CsvWriter csvWriter = new CsvWriter(writer);
                csvWriter.WriteRecord(tradeEngineLog);
                csvWriter.NextRecord();
            }
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
0
        public void StoreData(string[] _timeFrame)
        {
            //shouldn't need to do this
            SqlConnection dbConnect = new SqlConnection(connectionString);

            dbConnect.Open();
            EUR_USDDataContext linqInterop = new EUR_USDDataContext(dbConnect);



            ProgressBarOptions progressBarOptions = new ProgressBarOptions {
                ProgressCharacter = '*'
            };
            ProgressBar progressBar = new ProgressBar(runLength * _timeFrame.Count() - 1, "Saving bar data to local storage", progressBarOptions);

            foreach (var tf in _timeFrame)
            {
                for (int i = 0; i < runLength - 1; i++)


                {
                    DateTime runDate = startDate.AddDays(i);

                    //can't trade on weekends and december 25th, Jan 1st
                    if (!(runDate.DayOfWeek == DayOfWeek.Saturday) && !(runDate.DayOfWeek == DayOfWeek.Sunday) && !(runDate.Date == new DateTime(runDate.Year, 12, 25)) && !(runDate.Date == new DateTime(runDate.Year, 1, 1)))
                    {
                        DateTime startTime = runDate.Add(new TimeSpan(00, 00, 00));
                        DateTime endTime   = runDate.Add(new TimeSpan(23, 59, 59));
                        bars = instruments.GetBars(startTime, endTime, tf);
                        for (int i2 = 0; i2 < bars.candles.Count - 1; i2++)
                        {
                            //write rows to db

                            BarData row = new BarData
                            {
                                SystemTime = DateTime.Now,
                                BarTime    = bars.candles[i2].time,
                                c          = bars.candles[i2].mid.c,
                                o          = bars.candles[i2].mid.o,
                                h          = bars.candles[i2].mid.h,
                                l          = bars.candles[i2].mid.l,
                                Volume     = bars.candles[i2].volume,
                                Timeframe  = tf
                            };
                            linqInterop.BarDatas.InsertOnSubmit(row);
                        }

                        linqInterop.SubmitChanges();
                    }

                    progressBar.Tick();
                }
            }

            //clean up
            linqInterop.Dispose();
            dbConnect.Close();
        }