Beispiel #1
0
 public LiveTradeEngine()
 {
     _session        = new FXSession();
     _opEngine       = new OrderPlacementEngine(_session);
     _priceEngine    = new HistoricPriceEngine(_session);
     _accountManager = new LiveAccountManager(_opEngine);
 }
Beispiel #2
0
        public static Quantum QuantumFromLiveData(string symbol, string timeframe, int ticks)
        {
            FXSession session = new FXSession();

            session.InitializeSession();
            HistoricPriceEngine h = new HistoricPriceEngine(session);

            h.GetLongHistoricPrices(symbol, timeframe, ticks);
            while (!h.Complete)
            {
                Thread.Sleep(100);
            }

            return(h.Data);
        }
Beispiel #3
0
        public void LoadData()
        {
            FXSession session = new FXSession();

            session.InitializeSession();

            foreach (string s in sList)
            {
                HistoricPriceEngine h = new HistoricPriceEngine(session);
                h.GetLongHistoricPrices(symbol, s, ticks);
                while (!h.Complete)
                {
                    Thread.Sleep(100);
                }
                mData.Add(h.Data);
            }
        }
Beispiel #4
0
        public void LoadDataLive(string symbol, string timeframe, int ticks)
        {
            var session = new FXSession();

            session.InitializeSession();
            while (!session.LoggedIn)
            {
                Thread.Sleep(100);
            }
            var price = new HistoricPriceEngine(session);

            price.GetLongHistoricPrices(symbol, timeframe, ticks);

            while (!price.Complete)
            {
                Thread.Sleep(100);
            }

            _dataSet.Add(price.Data);

            session.EndSession();
        }
Beispiel #5
0
        public static void Process(FXSession session, string symbol1, string symbol2, string timeframe, int length)
        {


            HistoricPriceEngine h1 = new HistoricPriceEngine(session);
            h1.GetLongHistoricPrices(symbol1, timeframe, length);

            while (!h1.Complete)
            {
                Thread.Sleep(100);
            }

            HistoricPriceEngine h2 = new HistoricPriceEngine(session);
            h2.GetLongHistoricPrices(symbol2, timeframe, length);

            while (!h2.Complete)
            {
                Thread.Sleep(100);
            }
            //-----------------------

            var dateTimeList = new SortedList<DateTime, int>();

            Quantum q1 = h1.Data;
            Quantum q2 = h2.Data;


            var priceData = new DenseMatrix(2, q1.Data.Count);

            for (int j = 0; j < ((q1.Data.Count <= q2.Data.Count)?q1.Data.Count:q2.Data.Count); j++ )
            {
                dateTimeList.Add(q1.Data.Values[j].Time, 1);
                priceData[0, j] = q1.Data.Values[j].BidClose;
                priceData[1, j] = q2.Data.Values[j].BidClose;
            }

            Vector<double> price1 = priceData.Row(0);
            Vector<double> price2 = priceData.Row(1);
            //Statistics.ApplyFunction((DenseVector)price1, Math.Log);
            //Statistics.ApplyFunction((DenseVector)price2, Math.Log);

            DenseVector norm1 = price1.ToArray().NormalizeZScore();
            DenseVector norm2 = price2.ToArray().NormalizeZScore();

            var newsym = new string[] {symbol1, symbol2, "spread"};

            var m = new DenseMatrix(6, norm1.Count);
            m.SetRow(0, norm1);
            m.SetRow(1, norm2);
            m.SetRow(2, (norm1 - norm2).ToArray().NormalizeZScore());

            string filename = symbol1.Replace('/', '_') + "-" + symbol2.Replace('/', '_') + ".html";


            Visualize.GenerateMultiPaneGraph(newsym, dateTimeList.Keys.ToArray(), m, QSConstants.DEFAULT_DATA_FILEPATH + filename,
                new ChartOption[]{new ChartOption(), new ChartOption(){Layover = true, YPosition = 0}, new ChartOption(){YPosition = 1} }, null, filename + ".json");

            FileUpload.UploadFileToFTP(QSConstants.DEFAULT_DATA_FILEPATH + filename, filename);
            FileUpload.UploadFileToFTP(QSConstants.DEFAULT_DATA_FILEPATH + filename + ".json", filename + ".json");

            double Spread = m[2, m.ColumnCount - 1];

            if (Spread > 2.0 && m[2, m.ColumnCount - 2] <= 2.0)
                Emailer.SendEmail(symbol1 + "-" + symbol2 + " Spread Above 2.0", "Test");

            if (Spread < -2.0 && m[2, m.ColumnCount - 2] >= -2.0)
                Emailer.SendEmail(symbol1 + "-" + symbol2 + " Spread Below -2.0", "Test");

        }
Beispiel #6
0
        public static void TestChannelLive(this AbstractChannel ind, string symbol, string timeframe, int length)
        {
            //------------grab data
            FXSession session = new FXSession();

            session.InitializeSession();
            while (!session.LoggedIn)
            {
                Thread.Sleep(100);
            }

            HistoricPriceEngine h = new HistoricPriceEngine(session);

            h.GetLongHistoricPrices(symbol, timeframe, length);

            while (!h.Complete)
            {
                Thread.Sleep(100);
            }
            //-----------------------

            var highList = new List <double>();
            var medList  = new List <double>();
            var lowList  = new List <double>();

            var dataList     = new List <double>();
            var dateTimeList = new SortedList <DateTime, int>();

            Quantum q = h.Data;

            int count = 0;

            foreach (Tick t in q)
            {
                try{
                    ind.HandleNextTick(t);
                    highList.Add(ind.HI(0));
                    medList.Add(ind.MID(0));
                    lowList.Add(ind.LOW(0));

                    dataList.Add(t.BidClose);
                    dateTimeList.Add(t.Time, 1);
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
                if (count++ > length)
                {
                    break;
                }
            }

            var dz = new DenseMatrix(4, medList.Count);

            dz.SetRow(0, new DenseVector(dataList.ToArray()));
            dz.SetRow(1, new DenseVector(highList.ToArray()));
            dz.SetRow(2, new DenseVector(medList.ToArray()));
            dz.SetRow(3, new DenseVector(lowList.ToArray()));

            Visualize.GenerateMultiPaneGraph(new[] { "data", "high", ind.ToString(), "low" }, dateTimeList.Keys.ToArray(), dz, QSConstants.DEFAULT_DATA_FILEPATH + @"results.html"
                                             , new ChartOption[]
            {
                new ChartOption()
                {
                    Height = 500
                },
                new ChartOption()
                {
                    Height = 0, Layover = true, YPosition = 0
                },
                new ChartOption()
                {
                    Height = 0, Layover = true, YPosition = 0
                },
                new ChartOption()
                {
                    Height = 0, Layover = true, YPosition = 0
                }
            });

            Console.WriteLine("Done Generating Graph for " + ind.ToString());
        }
Beispiel #7
0
        public static void TestGraphLive(this AbstractIndicator ind, string timeframe, string symbol, int length)
        {
            //------------grab data
            FXSession session = new FXSession();

            session.InitializeSession();

            HistoricPriceEngine h = new HistoricPriceEngine(session);

            h.GetLongHistoricPrices(symbol, timeframe, length);

            while (!h.Complete)
            {
                Thread.Sleep(100);
            }
            //-----------------------

            Quantum       q     = h.Data;
            var           dz    = new DenseMatrix(4 + 1 + ind.SubIndicatorSize, q.Data.Count);
            List <string> names = new List <string>();

            names.Add("symbol");
            names.Add(ind.ToString());
            foreach (var indicator in ind.SubIndicators)
            {
                names.Add(indicator.Key);
            }

            //chartoptions
            ChartOption[] chartOptions = new ChartOption[names.Count];
            chartOptions[0] = new ChartOption()
            {
                Height = 400, YPosition = 0
            };
            chartOptions[1] = new ChartOption()
            {
                Height = 200, YPosition = 1
            };
            for (int i = 2; i < chartOptions.Length; i++)
            {
                chartOptions[i] = new ChartOption()
                {
                    Height = 0, YPosition = 1, Layover = true
                }
            }
            ;

            int counter = 0;

            foreach (Tick tick in q)
            {
                dz[0, counter] = tick.BidOpen;
                dz[1, counter] = tick.BidHigh;
                dz[2, counter] = tick.BidLow;
                dz[3, counter] = tick.BidClose;

                dz[4, counter] = ind.HandleNextTick(tick);

                int icounter = 5;
                foreach (var subind in ind.SubIndicators.Values)
                {
                    dz[icounter, counter] = subind[0];
                    icounter++;
                }

                counter++;
            }


            Visualize.GenerateMultiPaneGraph(names.ToArray(), q.Data.Keys.ToArray(), dz, QSConstants.DEFAULT_DATA_FILEPATH + @"results.html",
                                             chartOptions);

            Console.WriteLine("Done Generating Graph for " + ind.ToString());
        }
Beispiel #8
0
        public static void Process(FXSession session, string symbol1, string symbol2, string timeframe, int length)
        {
            HistoricPriceEngine h1 = new HistoricPriceEngine(session);

            h1.GetLongHistoricPrices(symbol1, timeframe, length);

            while (!h1.Complete)
            {
                Thread.Sleep(100);
            }

            HistoricPriceEngine h2 = new HistoricPriceEngine(session);

            h2.GetLongHistoricPrices(symbol2, timeframe, length);

            while (!h2.Complete)
            {
                Thread.Sleep(100);
            }
            //-----------------------

            var dateTimeList = new SortedList <DateTime, int>();

            Quantum q1 = h1.Data;
            Quantum q2 = h2.Data;


            var priceData = new DenseMatrix(2, q1.Data.Count);

            for (int j = 0; j < ((q1.Data.Count <= q2.Data.Count)?q1.Data.Count:q2.Data.Count); j++)
            {
                dateTimeList.Add(q1.Data.Values[j].Time, 1);
                priceData[0, j] = q1.Data.Values[j].BidClose;
                priceData[1, j] = q2.Data.Values[j].BidClose;
            }

            Vector <double> price1 = priceData.Row(0);
            Vector <double> price2 = priceData.Row(1);
            //Statistics.ApplyFunction((DenseVector)price1, Math.Log);
            //Statistics.ApplyFunction((DenseVector)price2, Math.Log);

            DenseVector norm1 = price1.ToArray().NormalizeZScore();
            DenseVector norm2 = price2.ToArray().NormalizeZScore();

            var newsym = new string[] { symbol1, symbol2, "spread" };

            var m = new DenseMatrix(6, norm1.Count);

            m.SetRow(0, norm1);
            m.SetRow(1, norm2);
            m.SetRow(2, (norm1 - norm2).ToArray().NormalizeZScore());

            string filename = symbol1.Replace('/', '_') + "-" + symbol2.Replace('/', '_') + ".html";


            Visualize.GenerateMultiPaneGraph(newsym, dateTimeList.Keys.ToArray(), m, QSConstants.DEFAULT_DATA_FILEPATH + filename,
                                             new ChartOption[] { new ChartOption(), new ChartOption()
                                                                 {
                                                                     Layover = true, YPosition = 0
                                                                 }, new ChartOption()
                                                                 {
                                                                     YPosition = 1
                                                                 } }, null, filename + ".json");

            FileUpload.UploadFileToFTP(QSConstants.DEFAULT_DATA_FILEPATH + filename, filename);
            FileUpload.UploadFileToFTP(QSConstants.DEFAULT_DATA_FILEPATH + filename + ".json", filename + ".json");

            double Spread = m[2, m.ColumnCount - 1];

            if (Spread > 2.0 && m[2, m.ColumnCount - 2] <= 2.0)
            {
                Emailer.SendEmail(symbol1 + "-" + symbol2 + " Spread Above 2.0", "Test");
            }

            if (Spread < -2.0 && m[2, m.ColumnCount - 2] >= -2.0)
            {
                Emailer.SendEmail(symbol1 + "-" + symbol2 + " Spread Below -2.0", "Test");
            }
        }