public List <DailyTradingModel> selectAllStockTrading() { List <DailyTradingModel> modelList = new List <DailyTradingModel>(); NpgsqlCommand command = connection.CreateCommand(); command.CommandText = DatabaseConst.SELECT_ALL_DAILY_TRADING; NpgsqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { DailyTradingModel model = new DailyTradingModel((String)reader["code"], (String)reader["name"], (int)reader["start_price"], (int)reader["end_price"], (int)reader["high_price"], (int)reader["low_price"], (int)reader["volume"], (int)reader["trading_value"], DateUtil.convertStringToDateTime((String)reader["trading_date"]), DateUtil.convertStringToDateTime((String)reader["created_date"]), DateUtil.convertStringToDateTime((String)reader["modified_date"]) ); modelList.Add(model); } reader.Close(); return(modelList); }
private bool isNewData(DailyTradingModel model) { if ("FIRST".Equals(this.lastUpdate)) { return(true); } DateTime last = DateUtil.convertStringToDateTime(this.lastUpdate); int result = DateTime.Compare(last, model.TradingDate); return((result < 0) ? true : false); }
private void onReceiveKiwoomApiEvent(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) { if (e.sRQName == "일봉조회") { StockDataCollector.isLockApi = true; int cnt = kiWoomApi.GetRepeatCnt(e.sTrCode, e.sRQName); if (cnt == 0) { LogUtil.logConsole(" count zero!! "); } else { String code = getReceiveDataCode(e); List <DailyTradingModel> list = new List <DailyTradingModel>(); // if most recent data is inserted then skip logic DailyTradingModel recentModel = makeDailyTradingModel(e, 0, code); if (!checkIsInsertedData(code, recentModel)) { DateTime recentDate = dbController.selectRecentTradingDate(code); DailyTradingModel firstModel = makeDailyTradingModel(e, cnt - 1, code); DailyTradingModel lastModel = makeDailyTradingModel(e, 0, code); bool isFirstInserted = compareRecentDateAndModelDate(recentDate, firstModel.TradingDate); bool isLastInserted = compareRecentDateAndModelDate(recentDate, lastModel.TradingDate); for (int idx = 0; idx < cnt; idx++) { DailyTradingModel model = makeDailyTradingModel(e, (cnt - 1) - idx, code); bool isInserted = compareRecentDateAndModelDate(recentDate, model.TradingDate); if (!isInserted) { list.Add(model); } else if (isFirstInserted && isLastInserted) { break; } } } else { LogUtil.logConsole("SKIP : " + code); } if (list.Count != 0) { dbController.insertDailyBatchData(list); LogUtil.logConsole(" db inserteds "); } } StockDataCollector.isLockApi = false; } }
public int insertDailyBatchData(List <DailyTradingModel> list) { int result = 0; Stopwatch watch = new Stopwatch(); watch.Start(); ThreadPoolChecker checker = new ThreadPoolChecker(list.Count); Parallel.For(0, list.Count, i => { using (NpgsqlConnection connectionParallel = new NpgsqlConnection(this.DATABASE_CONNECTION_INFO)) { connectionParallel.Open(); using (NpgsqlCommand commandParallel = new NpgsqlCommand(DatabaseConst.INSERT_DAILY_TRADING, connectionParallel)) { DailyTradingModel model = list.ElementAt <DailyTradingModel>(i); commandParallel.Parameters.Add("code", NpgsqlTypes.NpgsqlDbType.Varchar).Value = model.Code; commandParallel.Parameters.Add("name", NpgsqlTypes.NpgsqlDbType.Varchar).Value = model.Name; commandParallel.Parameters.Add("startPrice", NpgsqlTypes.NpgsqlDbType.Integer).Value = model.StartPrice; commandParallel.Parameters.Add("endPrice", NpgsqlTypes.NpgsqlDbType.Integer).Value = model.EndPrice; commandParallel.Parameters.Add("highPrice", NpgsqlTypes.NpgsqlDbType.Integer).Value = model.HighPrice; commandParallel.Parameters.Add("lowPrice", NpgsqlTypes.NpgsqlDbType.Integer).Value = model.LowPrice; commandParallel.Parameters.Add("volume", NpgsqlTypes.NpgsqlDbType.Integer).Value = model.Volume; commandParallel.Parameters.Add("tradingValue", NpgsqlTypes.NpgsqlDbType.Integer).Value = model.TradingValue; commandParallel.Parameters.Add("tradingDate", NpgsqlTypes.NpgsqlDbType.Date).Value = model.TradingDate; commandParallel.Parameters.Add("createdDate", NpgsqlTypes.NpgsqlDbType.Date).Value = model.CreatedDate; commandParallel.Parameters.Add("modifiedDate", NpgsqlTypes.NpgsqlDbType.Date).Value = model.ModifiedDate; try { commandParallel.ExecuteScalar(); } catch (Exception e) { LogUtil.logConsole(e.Message); } } } }); watch.Stop(); LogUtil.logConsole(" insert " + result + " items take " + watch.ElapsedMilliseconds / 1000 + "seconds"); return(result); }
public void insertDailyBatchDataForTest(List <DailyTradingModel> list) { //TODO: Insert Logic DailyTradingModel model = list.ElementAt(0); NpgsqlCommand command = connection.CreateCommand(); command.CommandText = DatabaseConst.INSERT_DAILY_TRADING; command.Parameters.Add("code", NpgsqlTypes.NpgsqlDbType.Varchar).Value = model.Code; command.Parameters.Add("name", NpgsqlTypes.NpgsqlDbType.Varchar).Value = model.Name; command.Parameters.Add("startPrice", NpgsqlTypes.NpgsqlDbType.Integer).Value = model.StartPrice; command.Parameters.Add("endPrice", NpgsqlTypes.NpgsqlDbType.Integer).Value = model.EndPrice; command.Parameters.Add("highPrice", NpgsqlTypes.NpgsqlDbType.Integer).Value = model.HighPrice; command.Parameters.Add("lowPrice", NpgsqlTypes.NpgsqlDbType.Integer).Value = model.LowPrice; command.Parameters.Add("volume", NpgsqlTypes.NpgsqlDbType.Integer).Value = model.Volume; command.Parameters.Add("tradingValue", NpgsqlTypes.NpgsqlDbType.Integer).Value = model.TradingValue; command.Parameters.Add("tradingDate", NpgsqlTypes.NpgsqlDbType.Date).Value = model.TradingDate; command.Parameters.Add("createdDate", NpgsqlTypes.NpgsqlDbType.Date).Value = model.CreatedDate; command.Parameters.Add("modifiedDate", NpgsqlTypes.NpgsqlDbType.Date).Value = model.ModifiedDate; command.ExecuteNonQuery(); }
private bool checkIsInsertedData(String code, DailyTradingModel model) { DateTime recentDate = getRecentTradingDateByCode(code); return(compareRecentDateAndModelDate(recentDate, model.TradingDate)); }
public TradingDateInsertJob(NpgsqlConnection connection, DailyTradingModel model) { this.connection = connection; this.model = model; }