Example #1
0
        static void SaveAndSendTicks(ITicksContainer containerTicks, IHistoricalTicksRepository repository)
        {
            long start = DateTime.Now.Ticks;
            //ITicksContainer _containerTicks = containerTicks;

            Dictionary <string, LatestSymbolTick> dictToSend = new Dictionary <string, LatestSymbolTick>();

            ITicksContainer containerLatestTicks = new TicksDataTableContainer();

            foreach (KeyValuePair <string, MessageTick> tick in symbolsCacheBid)
            {
                containerLatestTicks.AddEntry(tick.Value.Symbol, (int)tick.Value.Value, tick.Value.DecimalValue, tick.Value.DateTime, (byte)tick.Value.TickType, tick.Value.Provider);

                LatestSymbolTick latestSymbolTick = new LatestSymbolTick {
                    Symbol = tick.Value.Symbol, BidValue = tick.Value.DecimalValue, Timestamp = tick.Value.DateTime
                };
                dictToSend.Add(latestSymbolTick.Symbol, latestSymbolTick);
            }

            foreach (KeyValuePair <string, MessageTick> tick in symbolsCacheAsc)
            {
                containerLatestTicks.AddEntry(tick.Value.Symbol, (int)tick.Value.Value, tick.Value.DecimalValue, tick.Value.DateTime, (byte)tick.Value.TickType, tick.Value.Provider);
            }

            symbolsCacheBid.Clear();
            symbolsCacheAsc.Clear();

            double msPrepare = TimeSpan.FromTicks(DateTime.Now.Ticks - start).TotalMilliseconds;

            start = DateTime.Now.Ticks;

            Int32 totalTickCount = containerTicks.Count();

            repository.TicksInsert(containerLatestTicks, containerTicks);
            double msInsert = TimeSpan.FromTicks(DateTime.Now.Ticks - start).TotalMilliseconds;

            containerLatestTicks = null;

            if (HSTickWriter.provider != null)
            {
                HSTickWriter.provider.ProvideLatestSymbols(dictToSend);
            }

            Console.WriteLine("Saved in " + DateTime.Now.Date.ToShortDateString() + ", " + DateTime.Now.ToLongTimeString() + "; prepare: " + msPrepare.ToString() + "; ïnsert:" + msInsert.ToString() + "; count: " + totalTickCount.ToString());
        }
        private void AddReverseSymbols()
        {
            List <string> symbols = dictLatestTicks.Keys.ToList();

            foreach (string symbol in symbols)
            {
                string curr1         = symbol.Substring(0, 3);
                string curr2         = symbol.Substring(3, 3);
                string reverseSymbol = curr2 + curr1;

                dictLatestTicks[reverseSymbol] = new LatestSymbolTick
                {
                    Symbol    = reverseSymbol,
                    BidValue  = 1 / dictLatestTicks[symbol].BidValue,
                    Timestamp = dictLatestTicks[symbol].Timestamp
                };
            }
        }