public override IEnumerable <KeyValuePair <long, STS.General.Generators.Tick> > Read()
        {
            LargeList index = indexes[0];

            foreach (string value in index.Scan())
            {
                string[] str = value.Remove(0, 1).Remove(value.Length - 2, 1).Split(','); // remove '[' ']'

                long key = long.Parse(str[0]);
                str = str[1].Split(';');

                string   symbol   = str[0];
                DateTime time     = DateTime.Parse(str[1]);
                double   bid      = double.Parse(str[2]);
                double   ask      = double.Parse(str[3]);
                int      bidSize  = int.Parse(str[4]);
                int      askSize  = int.Parse(str[5]);
                string   provider = str[6];

                Tick tick = new Tick(symbol, time, bid, ask, bidSize, askSize, provider);

                yield return(new KeyValuePair <long, Tick>(key, tick));
            }
        }
Exemple #2
0
        public void DistinctBinsLargeList()
        {
            if (!args.ValidateLDT())
            {
                return;
            }
            Key key = new Key(args.ns, args.set, "accountId");

            // Delete record if it already exists.
            client.Delete(null, key);

            // Initialize large list operator.
            LargeList list = client.GetLargeList(null, key, "trades");

            // Write trades
            Dictionary <string, Value> map = new Dictionary <string, Value>();

            DateTime timestamp1 = new DateTime(2014, 6, 25, 12, 18, 43);

            map["key"]    = Value.Get(timestamp1.Ticks);
            map["ticker"] = Value.Get("IBM");
            map["qty"]    = Value.Get(100);
            map["price"]  = Value.Get(BitConverter.GetBytes(181.82));
            list.Add(Value.Get(map));

            DateTime timestamp2 = new DateTime(2014, 6, 26, 9, 33, 17);

            map["key"]    = Value.Get(timestamp2.Ticks);
            map["ticker"] = Value.Get("GE");
            map["qty"]    = Value.Get(500);
            map["price"]  = Value.Get(BitConverter.GetBytes(26.36));
            list.Add(Value.Get(map));

            DateTime timestamp3 = new DateTime(2014, 6, 27, 14, 40, 19);

            map["key"]    = Value.Get(timestamp3.Ticks);
            map["ticker"] = Value.Get("AAPL");
            map["qty"]    = Value.Get(75);
            map["price"]  = Value.Get(BitConverter.GetBytes(91.85));
            list.Add(Value.Get(map));

            // Verify list size
            int size = list.Size();

            Assert.AreEqual(3, size);

            // Filter on range of timestamps
            DateTime begin   = new DateTime(2014, 6, 26);
            DateTime end     = new DateTime(2014, 6, 28);
            IList    results = list.Range(Value.Get(begin.Ticks), Value.Get(end.Ticks));

            Assert.IsNotNull(results);
            Assert.AreEqual(2, results.Count);

            // Verify data.
            ValidateWithDistinctBins(results, 0, timestamp2, "GE", 500, 26.36);
            ValidateWithDistinctBins(results, 1, timestamp3, "AAPL", 75, 91.85);

            IList rows = list.Scan();

            foreach (IDictionary row in rows)
            {
                foreach (DictionaryEntry entry in row)
                {
                    //console.Info(entry.Key.ToString());
                    //console.Info(entry.Value.ToString());
                }
            }
        }