public void Add(string stockCode, KLineType kLineType, IStockKLine data) { using (var file = StockKLineFile.CreateOrOpen(stockCode, kLineType, data.Time)) { StockKLineDataItem dataItem = data.Convert(); file.Add(dataItem); } }
/// <summary> /// 添加新的数据 /// </summary> /// <param name="type"></param> /// <param name="kLine"></param> public void AddNewData(KLineType type, IStockKLine kLine) { if(!_history.ContainsKey(type)) { _history.Add(type, new List<IStockKLine>()); } _history[type].Add(kLine); }
/// <summary> /// 判断数据是否已经存在 /// </summary> /// <param name="type"></param> /// <param name="kLine"></param> /// <returns></returns> public bool ExistData(KLineType type, IStockKLine kLine) { if (_history.ContainsKey(type) && _history[type].Contains(kLine)) { return true; } else { return false; } }
public bool Exists(IStockKLine kLine) { bool bExists = false; string sql = string.Format("SELECT * FROM {0} WHERE {1}='{2}'", tableName, colTime, kLine.Time.ToString("yyyy-MM-dd HH:mm:ss")); using (SqlCeConnection conn = new SqlCeConnection(ConnectionString)) { conn.Open(); using (SqlCeCommand sqlCmd = new SqlCeCommand(sql, conn)) { Object o = sqlCmd.ExecuteScalar(); bExists = (o != null); } conn.Close(); } return bExists; }
/// <summary> /// 存储数据 /// </summary> /// <param name="stockCode"></param> /// <param name="data"></param> private void SaveData(string stockCode, IStockKLine data) { try { // 检查是否已经存在记录 if (!_saveDataService.Exists(KLineType.Day, stockCode, data)) { // 不存在就添加 _saveDataService.Add(KLineType.Day, stockCode, data); } } catch(Exception ex) { LogHelper.Logger.WriteLine(string.Format("Save stock[{0}] data error.", stockCode), this.ServiceName); LogHelper.Logger.WriteLine(ex.ToString(), this.ServiceName); } }
public void Delete(KLineType type, string stockCode, IStockKLine kLine) { Delete(type, stockCode, new List<IStockKLine> { kLine }); }
public void Add(KLineType type, string stockCode, IStockKLine kLine) { Add(type, stockCode, new List<IStockKLine> { kLine }); }
public bool Exists(KLineType type, string stockCode, IStockKLine kLine) { ThrowIfTypeNotSupport(type); // 获取数据文件路径 string dbFilePath = null; if(type == KLineType.Day) { dbFilePath = new Day1KLineFile(stockCode).GetFilePath(); } else if(type == KLineType.Min1) { dbFilePath = new Min1KLineFile(stockCode).GetFilePath(kLine.Time); } else if(type == KLineType.Min5) { dbFilePath = new Min5KLineFile(stockCode).GetFilePath(kLine.Time); } if (!string.IsNullOrEmpty(dbFilePath)) { KLineRepository repository = new KLineRepository(dbFilePath); return repository.Exists(kLine); } else { return false; } }