Esempio n. 1
0
 public static int BarRequest(DateTime timestamp, double count, string symbol, string periodicity,
                              string priceType)
 {
     if (count < 0)
     {
         count *= -1;
         if (count <= 5000)
         {
             _barList =
                 _client.QueryQuoteHistoryBars(
                     new DateTime(timestamp.Ticks, DateTimeKind.Utc), -(int)count, symbol, periodicity,
                     priceType.Equals("Ask") ? PriceType.Ask : PriceType.Bid);
         }
         else
         {
             _barList = new List <Bar>();
             while (count >= 0)
             {
                 _barList.AddRange(_client.QueryQuoteHistoryBars(
                                       new DateTime(timestamp.Ticks, DateTimeKind.Utc), -(int)(count > 5000 ? 5000 : count), symbol, periodicity,
                                       priceType.Equals("Ask") ? PriceType.Ask : PriceType.Bid));
                 count    -= 5000;
                 timestamp = _barList.Last().Time;
             }
         }
     }
     else
     {
         if (count <= 5000)
         {
             _barList =
                 _client.QueryQuoteHistoryBars(
                     new DateTime(timestamp.Ticks, DateTimeKind.Utc), (int)count, symbol, periodicity,
                     priceType.Equals("Ask") ? PriceType.Ask : PriceType.Bid);
         }
         else
         {
             _barList = new List <Bar>();
             while (count >= 0)
             {
                 _barList.InsertRange(0, _client.QueryQuoteHistoryBars(
                                          new DateTime(timestamp.Ticks, DateTimeKind.Utc), (int)(count > 5000 ? 5000 : count), symbol, periodicity,
                                          priceType.Equals("Ask") ? PriceType.Ask : PriceType.Bid));
                 count    -= 5000;
                 timestamp = periodicity.Equals("M1") ? _barList.First().Time.AddMinutes(-1) :
                             _barList.First().Time.AddHours(-1);
             }
         }
     }
     return(0);
 }
Esempio n. 2
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");
        }
Esempio n. 3
0
        protected override List <HistoryBar> RequestHistory(DateTime timestamp, int count)
        {
            var result = new List <HistoryBar>(Math.Abs(count));

            if (count == 0)
            {
                return(result);
            }

            try
            {
                var report = _historyClient.QueryQuoteHistoryBars(timestamp, count, Symbol, Periodicity.ToString(), (PriceType.HasValue && (PriceType.Value == FxPriceType.Ask)) ? TTQuoteHistoryClient.PriceType.Ask : TTQuoteHistoryClient.PriceType.Bid);
                var bars   = report.Select(srcBar =>
                {
                    var dstBar = new HistoryBar
                    {
                        Time  = srcBar.Time,
                        Open  = srcBar.Open,
                        Hi    = srcBar.High,
                        Low   = srcBar.Low,
                        Close = srcBar.Close
                    };
                    return(dstBar);
                });
                result.AddRange(bars);
            }
            catch (Exception) {}

            return(result);
        }