Exemple #1
0
 private void SaveToDB(Dictionary <string, double> dict, int initBarsCount)
 {
     using (var storage = new LevelDbStorage(_dbPath))
     {
         foreach (var lp in dict)
         {
             using (var collection = storage.GetBinaryCollection(lp.Key, _keySerializer))
             {
                 collection.Write(Bars[Bars.Count - initBarsCount].OpenTime, GetSegment(lp.Value));
             }
         }
     }
 }
Exemple #2
0
        private void ProcessPreviousBars()
        {
            using (var storage = new LevelDbStorage(_dbPath))
            {
                var savedLps       = new List <LiquidityProvider>();
                var bidCollections = new Dictionary <LiquidityProvider, IBinaryStorageCollection <DateTime> >();
                var askCollections = new Dictionary <LiquidityProvider, IBinaryStorageCollection <DateTime> >();

                try
                {
                    foreach (var lp in _requiredLP)
                    {
                        if (storage.Collections.Contains(lp.ToString() + "Bid") && storage.Collections.Contains(lp.ToString() + "Ask"))
                        {
                            savedLps.Add(lp);
                            bidCollections[lp] = storage.GetBinaryCollection(lp.ToString() + "Bid", _keySerializer);
                            askCollections[lp] = storage.GetBinaryCollection(lp.ToString() + "Ask", _keySerializer);
                        }
                    }


                    for (int pos = Bars.Count - 1; pos > 0; pos--)
                    {
                        foreach (var lp in savedLps)
                        {
                            if (bidCollections[lp].Read(Bars[pos].OpenTime, out var x))
                            {
                                Math.Abs(-1);
                            }
                            var bid      = bidCollections[lp].Read(Bars[pos].OpenTime, out var bidSeg) ? BitConverter.ToDouble(bidSeg.Array, 0) : double.NaN;
                            var ask      = askCollections[lp].Read(Bars[pos].OpenTime, out var askSeg) ? BitConverter.ToDouble(askSeg.Array, 0) : double.NaN;
                            var localLp  = lp;
                            var localPos = pos;
                            OnMainThreadAsync(() => AddToIndicatorOutput(localLp, bid, ask, localPos));
                        }
                    }
                }
                finally
                {
                    foreach (var lp in savedLps)
                    {
                        bidCollections[lp].Dispose();
                        askCollections[lp].Dispose();
                    }
                }
            }

            _isPreviousBarsProccessed = true;
        }