Esempio n. 1
0
 public static string GetKey(this ArchiveEntriesJson json)
 {
     if (json == null)
     {
         return(null);
     }
     return(json.PairName + (int)json.Interval);
 }
Esempio n. 2
0
        public void LoadEntries(string[] pairs, OHLC.Interval[] intervals)
        {
            if (pairs == null || intervals == null || pairs.Length <= 0 || intervals.Length <= 0)
            {
                return;
            }

            foreach (OHLC.Interval interval in intervals)
            {
                foreach (string pair in pairs)
                {
                    string key     = this.GetKey(pair, interval);
                    var    entries = Entries.Get(key);

                    TickTime last    = new TickTime(0);
                    int      minutes = (int)interval;
                    if (entries != null)
                    {
                        if (entries.Last.AddMinutes(minutes) > TickTime.Now)
                        {
                            continue;
                        }

                        last = entries.Last;
                    }
                    else
                    {
                        entries          = new ArchiveEntriesJson();
                        entries.PairName = pair;
                        entries.Interval = interval;
                        entries.Last     = last;
                        entries.Entries  = new OHLCEntry[0];
                    }

                    if (last > new TickTime(0).AddMinutes(minutes))
                    {
                        last = last.AddMinutes(-minutes);
                    }

                    OHLC ohlc = null;
                    try
                    {
                        ohlc = Manager.GetOHLC(pair, interval, last);
                    }
                    catch
                    {
                        continue;
                    }

                    if (ohlc == null)
                    {
                        continue;
                    }


                    var _old = entries.Entries.ToDistinctKeyDictionary(x => x.Time, x => x);
                    var _new = ohlc.Entries.ToDistinctKeyDictionary(x => x.Time, x => x);
                    _old.AddOrUpdate(_new);

                    List <OHLCEntry> list = _old.Values.ToList();

                    if (list == null || list.Count <= 0)
                    {
                        continue;
                    }

                    entries.Entries = list.ToArray();
                    entries.Last    = list.Last().Time;
                    Entries.Set(key, entries, true);
                }
            }
        }