Esempio n. 1
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");
        }
        protected override List <TickValue> RequestHistory(DateTime timestamp, int count)
        {
            var result = new List <TickValue>(Math.Abs(count));

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

            try
            {
                var report = _historyClient.QueryQuoteHistoryTicks(timestamp, count, Symbol, _level2);
                var ticks  = report.Select(srcTick =>
                {
                    var bids    = srcTick.Level2.Bids.Select(bid => new TickTrader.BusinessObjects.Level2Value(new Price(bid.Price), (double)bid.Volume));
                    var asks    = srcTick.Level2.Asks.Select(ask => new TickTrader.BusinessObjects.Level2Value(new Price(ask.Price), (double)ask.Volume));
                    var level2  = new TickTrader.BusinessObjects.Level2Collection(bids, asks);
                    var dstTick = new TickValue(new FeedTickId(srcTick.Id.Time, srcTick.Id.Index), level2);
                    return(dstTick);
                });
                result.AddRange(ticks);
            }
            catch (Exception) {}

            return(result);
        }
Esempio n. 3
0
 public static int TickRequest(DateTime timestamp, double count, string symbol, bool level2)
 {
     if (count < 0)
     {
         count *= -1;
         if (count <= 1000)
         {
             _tickList = _client.QueryQuoteHistoryTicks(timestamp, -(int)count, symbol, level2);
         }
         else
         {
             _tickList = new List <Tick>();
             while (count >= 0)
             {
                 _tickList.AddRange(_client.QueryQuoteHistoryTicks(timestamp, -(int)(count > 1000 ? 1000 : count), symbol, level2));
                 count    -= 1000;
                 timestamp = _tickList.Last().Id.Time.AddMilliseconds(1);
             }
         }
     }
     else
     {
         if (count <= 1000)
         {
             _tickList = _client.QueryQuoteHistoryTicks(timestamp, (int)count, symbol, level2);
         }
         else
         {
             _tickList = new List <Tick>();
             while (count >= 0)
             {
                 _tickList.InsertRange(0, _client.QueryQuoteHistoryTicks(timestamp, (int)(count > 1000 ? 1000 : count), symbol, level2));
                 count    -= 1000;
                 timestamp = _tickList.First().Id.Time.AddMilliseconds(-1);
             }
         }
     }
     return(0);
 }