public static LotByGroupDictionary LoadFromFile(string path) { var dic = new LotByGroupDictionary { dictionary = new Dictionary<string, Dictionary<string, Cortege2<int, int>>>() }; if (!File.Exists(path)) return dic; try { using (var sr = new StreamReader(path, Encoding.UTF8)) { Dictionary<string, Cortege2<int, int>> curGroup = null; string curTicker = string.Empty; while (!sr.EndOfStream) { var line = sr.ReadLine(); if (string.IsNullOrEmpty(line)) continue; line = line.Trim(); // строка вида [DemoGroup] или GBPUSD 10000 5000 if (line.StartsWith("[")) { curTicker = line.Substring(1, line.Length - 2); curGroup = new Dictionary<string, Cortege2<int, int>>(); dic.dictionary.Add(curTicker, curGroup); continue; } if (curGroup == null) continue; var parts = line.Split(new [] {' '}, StringSplitOptions.RemoveEmptyEntries); if (parts.Length != 3) continue; var minVolm = parts[1].ToIntSafe(); if (!minVolm.HasValue) continue; var stepVolm = parts[2].ToIntSafe(); if (!stepVolm.HasValue) continue; curGroup.Add(parts[0], new Cortege2<int, int>(minVolm.Value, stepVolm.Value)); } } } catch (Exception ex) { Logger.Error("Ошибка в LotByGroupDictionary.LoadFromFile()", ex); } // посчитать хеш код dic.GetHashCodeForDic(); return dic; }
public void Setup() { lotDictionary = new LotByGroupDictionary { dictionary = new Dictionary<string, Dictionary<string, Cortege2<int, int>>> { { "Demo", new Dictionary<string, Cortege2<int, int>> { {"EURUSD", new Cortege2<int, int>(10000, 10000)}, {"GBPUSD", new Cortege2<int, int>(10000, 5000)} } }, { "Nano", new Dictionary<string, Cortege2<int, int>> { {"EURUSD", new Cortege2<int, int>(100, 100)}, {"GBPUSD", new Cortege2<int, int>(100, 100)}, {"USDJPY", new Cortege2<int, int>(100, 100)} } } } }; }
private void FillDictionaries(ITradeSharpDictionary dict) { // прочитать локальную копию настроек группа - лот dictionaryGroupLot = LotByGroupDictionary.LoadFromFile(lotDicPath); if (dict != null) try { long lotByGroupHashCode; tickers = dict.GetTickers(out lotByGroupHashCode).ToDictionary(t => t.Title, t => t); if (tickers.Count > 0) { // контракты прочитаны, проверить словарь группа - лот if (lotByGroupHashCode == 0) dictionaryGroupLot.Clear(); else { if (dictionaryGroupLot.calculatedHashCode != lotByGroupHashCode) { var newDictionaryGroupLot = dict.GetLotByGroup(); if (newDictionaryGroupLot != null) { dictionaryGroupLot = newDictionaryGroupLot; dictionaryGroupLot.SaveInFile(lotDicPath); } } } ConnectionWasEstablished = true; return; } else { Logger.ErrorFormat("DalSpot: тикеры не получены"); } } catch (Exception ex) { Logger.Error("Ошибка в DalSpot ctor (доступ к БД)", ex); } InitializeDefault(); }
public static LotByGroupDictionary LoadFromFile(string path) { var dic = new LotByGroupDictionary { dictionary = new Dictionary <string, Dictionary <string, Cortege2 <int, int> > >() }; if (!File.Exists(path)) { return(dic); } try { using (var sr = new StreamReader(path, Encoding.UTF8)) { Dictionary <string, Cortege2 <int, int> > curGroup = null; string curTicker = string.Empty; while (!sr.EndOfStream) { var line = sr.ReadLine(); if (string.IsNullOrEmpty(line)) { continue; } line = line.Trim(); // строка вида [DemoGroup] или GBPUSD 10000 5000 if (line.StartsWith("[")) { curTicker = line.Substring(1, line.Length - 2); curGroup = new Dictionary <string, Cortege2 <int, int> >(); dic.dictionary.Add(curTicker, curGroup); continue; } if (curGroup == null) { continue; } var parts = line.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length != 3) { continue; } var minVolm = parts[1].ToIntSafe(); if (!minVolm.HasValue) { continue; } var stepVolm = parts[2].ToIntSafe(); if (!stepVolm.HasValue) { continue; } curGroup.Add(parts[0], new Cortege2 <int, int>(minVolm.Value, stepVolm.Value)); } } } catch (Exception ex) { Logger.Error("Ошибка в LotByGroupDictionary.LoadFromFile()", ex); } // посчитать хеш код dic.GetHashCodeForDic(); return(dic); }