public StockTradeDetails LoadDetailDatas() { PrpTradeDetailParser parser = new PrpTradeDetailParser(Settings.Default.PrpDataFile); var std = parser.GetOneStockTradeDetail(shareId); return(std); }
private Stock LoadMinStock(string sId, bool isMa) { if (!File.Exists(Settings.Default.PrpDataFile)) { return(null); } PrpTradeDetailParser parser = new PrpTradeDetailParser(Settings.Default.PrpDataFile); Stock s = null; var std = parser.GetOneStockTradeDetail(sId); if (!StockTradeDetails.IsNullOrEmpty(std) && std.DataCount > 10) { if (!isMa) { s = TradeDetails2Stock.Convert(std, CandlePeriod.min1); } else { s = TradeDetails2Stock.ConvertMA(std, CandlePeriod.min1); } } return(s); }
private static void LoadAndConvertStock(List <string> ids, PrpTradeDetailParser parser, string outputFile) { List <CompleteShare> shares = new List <CompleteShare>(); foreach (var id in ids) { var tds = parser.GetOneStockTradeDetail(GetId(id)); if (!StockTradeDetails.IsNullOrEmpty(tds)) { var stock = TradeDetails2Stock.Convert(tds, CandlePeriod.min1); var share = FromStock(new Stock(tds.id, stock.Data)); shares.Add(share); var stockMa = TradeDetails2Stock.ConvertMA(tds, CandlePeriod.min1); var shareMa = FromStock(new Stock(tds.id + "average", stockMa.Data)); shares.Add(shareMa); } } if (shares.Any()) { JsonSerializer jSer = new JsonSerializer(); if (File.Exists(outputFile)) { using (JsonTextReader reader = new JsonTextReader(new StreamReader( new FileStream(outputFile, FileMode.Open, FileAccess.Read, FileShare.Read), Encoding.UTF8))) { var oldShares = jSer.Deserialize <CompleteShare[]>(reader); shares.InsertRange(0, oldShares); } } using (JsonTextWriter writer = new JsonTextWriter(new StreamWriter( new FileStream(outputFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None), Encoding.UTF8))) { jSer.Serialize(writer, shares); } } }