private void LoadTradesFromFile(DateCollection newCol) { FileLib.WFile f = new FileLib.WFile(GetFilePath(newCol.Date)); if (!f.Exists()) { return; } var strings = f.ReadAllLines(); strings.ForEach <string>((s) => { if (s.Empty()) { return; } var dataTrade = s.Split('\t'); var trade = new Trade(); trade.Number = dataTrade[0].ToLong(); trade.Price = dataTrade[2].ToDecimal(); trade.Volume = dataTrade[3].ToInt32(); trade.Direction = dataTrade[4] == "B" ? OrderDirection.Buy : OrderDirection.Sell; trade.SecCode = dataTrade[5]; newCol.Trades.Add(trade); }); }
/// <summary> Чтение коллекции из файла в сериализованном виде. </summary> /// <param name="filename"></param> public void ReadCollectionFromFile(string filename) { this.TimeLastWrite = DateTime.Now; FileLib.WFile file = new FileLib.WFile(filename); if (!file.Exists()) { return; } if (file.Size() == 0) { return; } MutexCollection.WaitOne(); using (Stream stream = File.Open(filename, FileMode.Open)) { try { var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); this.Collection = (List <CandleData>)binaryFormatter.Deserialize(stream); } catch (Exception e) { string er = e.ToString(); } } MutexCollection.ReleaseMutex(); }
/// <summary> /// /// </summary> private int SaveCandleInfile(string filename, CandleLib.CandleData candle) { FileLib.WFile file = new FileLib.WFile(filename); char split = '\t'; string text = candle.Time.ToString() + split + candle.FirstId.ToString() + split + candle.Open.ToString().Replace(',', '.') + split + candle.Close.ToString().Replace(',', '.') + split + //3 candle.High.ToString().Replace(',', '.') + split + candle.Low.ToString().Replace(',', '.') + split + candle.LastId.ToString() + split + //6 candle.LastTime.ToString() + split; //7 if (candle.HorVolumes.HVolCollection.Count > 0) { candle.HorVolumes.HVolCollection.CollectionArray.ForEach <ChartVol>((vol) => { if (vol.VolBuy > 0) { text += "b:" + vol.Price.ToString().Replace(',', '.') + ":" + vol.VolBuy.ToString() + split; } if (vol.VolSell > 0) { text += "s:" + vol.Price.ToString().Replace(',', '.') + ":" + vol.VolSell.ToString() + split; } }); } LastSaveCandle = candle; if (file.Append(text) == -1) { return(-1); } return(0); }
private void AppendTradeFile(Trade trade) { FileLib.WFile f = new FileLib.WFile(GetFilePath(trade.DateTrade)); //if (!f.Exists()) f.Append(""); string text = trade.Number.ToString() + '\t' + trade.DateTrade.ToString() + '\t' + trade.Price.ToString() + '\t' + trade.Volume.ToString() + '\t' + (trade.Direction == OrderDirection.Buy ? 'B' : 'S') + '\t' + trade.Sec.Code + ':' + trade.Sec.Class.Code; f.Append(text); }