private void InitializeQuoteHistory()
        {
            DisposeQuoteHistory();

            _historyClient               = new QuoteHistoryClient("QuoteHistoryCache");
            _historyClient.Connected    += HistoryClientOnConnected;
            _historyClient.ConnectError += HistoryClientOnConnectError;
            _historyClient.Disconnected += HistoryClientOnDisconnected;
            _historyClient.Connect(textAddress.Text);

            _historyCacheManager = new HistoryCacheManager(_historyClient);
            _historyCacheManager.Initialize();

            var symbols = _historyCacheManager.GetSymbols();

            foreach (var symbol in symbols)
            {
                comboboxSymbol.Items.Add(symbol);
            }
            comboboxSymbol.SelectedIndex = 0;

            var periodicities = _historyCacheManager.GetPeriodicities();

            foreach (var periodicity in periodicities)
            {
                comboboxPeriodicity.Items.Add(periodicity.ToString());
            }
            comboboxPeriodicity.SelectedIndex = 0;

            comboboxPriceType.Items.Add("Bid");
            comboboxPriceType.Items.Add("Ask");
            comboboxPriceType.Items.Add("Ticks");
            comboboxPriceType.Items.Add("Level2");
            comboboxPriceType.SelectedIndex = 0;
        }
Example #2
0
        public BarsHistoryCache(string symbol, Periodicity periodicity, FxPriceType priceType, QuoteHistoryClient historyClient) : base(symbol)
        {
            _historyClient = historyClient;

            Periodicity = periodicity;
            PriceType   = priceType;
        }
        private void DisposeQuoteHistory()
        {
            if (_historyCacheManager != null)
            {
                _historyCacheManager.Close();
                _historyCacheManager = null;
            }
            if (_historyClient != null)
            {
                _historyClient.Connected    -= HistoryClientOnConnected;
                _historyClient.ConnectError -= HistoryClientOnConnectError;
                _historyClient.Disconnected -= HistoryClientOnDisconnected;

                _historyClient.Dispose();
                _historyClient = null;
            }

            comboboxSymbol.Items.Clear();
            comboboxSymbol.SelectedIndex = -1;
            comboboxPeriodicity.Items.Clear();
            comboboxPeriodicity.SelectedIndex = -1;
            comboboxPriceType.Items.Clear();
            comboboxPriceType.SelectedIndex = -1;

            textHistory.Text   = "";
            textIntervals.Text = "";
        }
 private void HistoryClientOnDisconnected(QuoteHistoryClient client)
 {
     Application.Current?.Dispatcher.BeginInvoke(new Action(() =>
     {
         EnableQuoteHistoryControls(false);
         connect.Content = "Connect";
     }));
 }
Example #5
0
        static void RequestBars(QuoteHistoryClient client, DateTime timestamp, int count, string symbol, string periodicity, PriceType priceType, bool verbose)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            bool backward = count >= 0;

            count = Math.Abs(count);

            List <Bar> result;

            for (int i = 0; i < count / 5000; i++)
            {
                // Request for the bars history
                result = client.QueryQuoteHistoryBars(timestamp, backward ? 5000 : -5000, symbol, periodicity, priceType);
                if (result.Count > 0)
                {
                    timestamp = backward ? result[result.Count - 1].Time : result[0].Time;
                }
                if (verbose)
                {
                    foreach (var bar in result)
                    {
                        Console.WriteLine(bar);
                    }
                }
            }

            int remain = count % 5000;

            if (remain > 0)
            {
                result = client.QueryQuoteHistoryBars(timestamp, backward ? remain : -remain, symbol, periodicity, priceType);
                if (verbose)
                {
                    foreach (var bar in result)
                    {
                        Console.WriteLine(bar);
                    }
                }
            }

            long elapsed = sw.ElapsedMilliseconds;

            Console.WriteLine($"Elapsed = {elapsed}ms");
            Console.WriteLine($"Throughput = {((double)count/(double)elapsed)*1000.0:0.#####} bars per second");
        }
Example #6
0
        static void RequestTicks(QuoteHistoryClient client, DateTime timestamp, int count, string symbol, bool level2, bool verbose)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            bool backward = count >= 0;

            count = Math.Abs(count);

            List <Tick> result;

            for (int i = 0; i < count / 1000; i++)
            {
                // Request for the bars history
                result = client.QueryQuoteHistoryTicks(timestamp, backward ? 1000 : -1000, symbol, level2);
                if (result.Count > 0)
                {
                    timestamp = backward ? result[result.Count - 1].Id.Time : result[0].Id.Time;
                }
                if (verbose)
                {
                    foreach (var tick in result)
                    {
                        Console.WriteLine(tick);
                    }
                }
            }

            int remain = count % 1000;

            if (remain > 0)
            {
                result = client.QueryQuoteHistoryTicks(timestamp, backward ? remain : -remain, symbol, level2);
                if (verbose)
                {
                    foreach (var tick in result)
                    {
                        Console.WriteLine(tick);
                    }
                }
            }

            long elapsed = sw.ElapsedMilliseconds;

            Console.WriteLine($"Elapsed = {elapsed}ms");
            Console.WriteLine($"Throughput = {((double)count / (double)elapsed) * 1000.0:0.#####} ticks per second");
        }
Example #7
0
 public static int Connect(string name, string address, double port, string login, string password)
 {
     try
     {
         _client = new QuoteHistoryClient(name == "" ? DefaultName : name, (int)port);
         _client.Connect(address == "" ? DefaultAddress : address);
         _client.Login(login == "" ? DefaultLogin : login, password == "" ? DefaultPassword : password, "", "");
         return(0);
     }
     catch (TimeoutException ex)
     {
         return(-1);
     }
     catch (SoftFX.Net.Core.DisconnectException ex)
     {
         return(-2);
     }
 }
Example #8
0
        static void RequestBarsFiles(QuoteHistoryClient client, DateTime from, DateTime to, string symbol, string periodicity, PriceType priceType, bool verbose)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            int count = 0;

            foreach (var bar in client.QueryQuoteHistoryBarsRange(from, to, symbol, periodicity, priceType))
            {
                count++;
                if (verbose)
                {
                    Console.WriteLine(bar);
                }
            }

            long elapsed = sw.ElapsedMilliseconds;

            Console.WriteLine($"Elapsed = {elapsed}ms");
            Console.WriteLine($"Throughput = {((double)count/(double)elapsed)*1000.0:0.#####} bars per second");
        }
Example #9
0
        static void RequestTicksFiles(QuoteHistoryClient client, DateTime from, DateTime to, string symbol, bool level2, bool verbose)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            int count = 0;

            foreach (var tick in client.QueryQuoteHistoryTicksRange(from, to, symbol, level2))
            {
                count++;
                if (verbose)
                {
                    Console.WriteLine(tick);
                }
            }

            long elapsed = sw.ElapsedMilliseconds;

            Console.WriteLine($"Elapsed = {elapsed}ms");
            Console.WriteLine($"Throughput = {((double)count / (double)elapsed) * 1000.0:0.#####} ticks per second");
        }
Example #10
0
        static void WorkingThread(string address, string login, string password, int port, DateTime from, DateTime to, string symbol, string periodicity, PriceType priceType, bool bars, bool ticks, bool level2, bool verbose)
        {
            try
            {
                // Create an instance of Quote History client
                using (var client = new QuoteHistoryClient("QuoteHistoryCache", port, false))
                {
                    // Connect to the server
                    client.Connect(address);

                    // Login
                    client.Login(login, password, "", "");

                    if (level2)
                    {
                        RequestTicksFiles(client, from, to, symbol, true, verbose);
                    }

                    if (ticks)
                    {
                        RequestTicksFiles(client, from, to, symbol, false, verbose);
                    }

                    if (bars)
                    {
                        RequestBarsFiles(client, from, to, symbol, periodicity, priceType, verbose);
                    }

                    // Logout
                    client.Logout("");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error : " + ex.Message);
            }
        }
Example #11
0
        static void Main(string[] args)
        {
            try
            {
                bool help = false;

                string address  = "localhost";
                string login    = "******";
                string password = "******";
                int    port     = 5020;

                DateTime  timestamp   = DateTime.UtcNow;
                int       count       = -100;
                string    symbol      = "EURUSD";
                string    periodicity = "M1";
                PriceType priceType   = PriceType.Bid;
                bool      bars        = false;
                bool      ticks       = false;
                bool      level2      = false;
                int       threadCount = 10;

                var options = new OptionSet()
                {
                    { "address=", v => address = v },
                    { "login="******"password="******"port=", v => port = int.Parse(v) },
                    { "?|help", v => help = v != null },
                    { "timestamp=", v => timestamp = DateTime.Parse(v) },
                    { "count=", v => count = int.Parse(v) },
                    { "symobl=", v => symbol = v },
                    { "periodicity=", v => periodicity = v },
                    { "threads=", v => threadCount = int.Parse(v) },
                    { "request=", v =>
                      {
                          switch (v.ToLowerInvariant())
                          {
                          case "bids":
                              priceType = PriceType.Bid;
                              bars      = true;
                              break;

                          case "asks":
                              priceType = PriceType.Ask;
                              bars      = true;
                              break;

                          case "ticks":
                              ticks = true;
                              break;

                          case "level2":
                              level2 = true;
                              break;

                          default:
                              throw new Exception("Unknown request type: " + v);
                          }
                      } },
                };

                try
                {
                    options.Parse(args);
                }
                catch (OptionException e)
                {
                    Console.Write("TTQuoteHistoryClientStressTest: ");
                    Console.WriteLine(e.Message);
                    Console.WriteLine("Try `TTQuoteHistoryClientStressTest --help' for more information.");
                    return;
                }

                if (help)
                {
                    Console.WriteLine("TTQuoteHistoryClientStressTest usage:");
                    options.WriteOptionDescriptions(Console.Out);
                    return;
                }

                // Create an instance of Quote History client
                using (var client = new QuoteHistoryClient("QuoteHistoryCache", port))
                {
                    // Connect to the server
                    client.Connect(address);

                    // Login
                    client.Login(login, password, "", "");

                    ThreadParams threadParams = new ThreadParams();
                    threadParams.client      = client;
                    threadParams.timestamp   = timestamp;
                    threadParams.count       = count;
                    threadParams.symbol      = symbol;
                    threadParams.periodicity = periodicity;
                    threadParams.priceType   = priceType;
                    threadParams.bars        = bars;
                    threadParams.ticks       = ticks;
                    threadParams.level2      = level2;

                    Thread[] threads = new Thread[threadCount];

                    for (int i = 0; i < threads.Length; ++i)
                    {
                        threads[i] = new Thread(new ParameterizedThreadStart(Program.Thread));
                    }

                    stop_ = false;

                    for (int i = 0; i < threads.Length; ++i)
                    {
                        threads[i].Start(threadParams);
//                        System.Threading.Thread.Sleep(10);
                    }

                    Console.WriteLine("Press any key to stop");
                    Console.ReadKey();

                    stop_ = true;

                    for (int i = 0; i < threads.Length; ++i)
                    {
                        threads[i].Join();
                    }

                    // Logout
                    client.Logout("");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error : " + ex.Message);
            }
        }
 private void HistoryClientOnConnectError(QuoteHistoryClient client)
 {
     Application.Current?.Dispatcher.BeginInvoke(new Action(DisposeQuoteHistory));
 }
Example #13
0
 public HistoryCacheManager(QuoteHistoryClient historyClient)
 {
     _historyClient = historyClient;
 }
 public TicksHistoryCache(string symbol, bool level2, QuoteHistoryClient historyClient) : base(symbol)
 {
     _historyClient = historyClient;
     _level2        = level2;
 }