public Boolean InsertDataIntoDB(DateTime lastExistDataDate) { DBManager dbManager = new DBManager(); MySqlConnection con = null; try { String ip = Config.DB_SERVER_IP; con = dbManager.CreateConnection(ip, Config.DATABASE_CORREL); con.Open(); foreach (Tuple<DateTime, double> row in _data) { InsertDataIntoDB_Raw(con, row, lastExistDataDate); } return true; } catch (System.Exception e) { logger.Error(e.ToString()); } finally { dbManager.Close(con); } return false; }
public Boolean DeletePrevDataInDB() { DBManager dbManager = new DBManager(); MySqlConnection con = null; try { String ip = Config.DB_SERVER_IP; con = dbManager.CreateConnection(ip, Config.DATABASE_CORREL); con.Open(); String query = String.Format("delete from raw_price_data where Ticker = '{0}'", kBokRateTicker); MySqlCommand cmd = new MySqlCommand(query, con); int ret = cmd.ExecuteNonQuery(); if (ret < 0) { throw new Exception(); } return true; } catch (System.Exception e) { logger.Error(e.ToString()); } finally { dbManager.Close(con); } return false; }
public static DateTime GetLastExistDataDate(String ticker) { DBManager dbManager = new DBManager(); MySqlConnection con = null; try { String ip = Config.DB_SERVER_IP; con = dbManager.CreateConnection(ip, Config.DATABASE_CORREL); con.Open(); String query = String.Format("select * from raw_price_data where Ticker = '{0}' order by DateTime desc", ticker); MySqlCommand cmd = new MySqlCommand(query, con); MySqlDataAdapter dataAdapter = new MySqlDataAdapter(cmd); DataSet ds = new DataSet("raw_price_data"); dataAdapter.Fill(ds, "raw_price_data"); DataRowCollection drc = ds.Tables["raw_price_data"].Rows; if (drc.Count > 0) { DataRow dr = drc[0]; DateTime curDate = Convert.ToDateTime(dr["DateTime"]); return curDate; } } catch (System.Exception e) { logger.Error(e.ToString()); } finally { dbManager.Close(con); } return new DateTime(1800, 1, 1); }
void LoadPrevSessionCountInfo() { DBManager dbManager = new DBManager(); MySqlConnection con = null; try { String ip = Config.DB_SERVER_IP; con = dbManager.CreateConnection(ip, Config.DATABASE_CORREL); con.Open(); String query = String.Format("select * from adre_trading_board order by inserted desc"); MySqlCommand cmd = new MySqlCommand(query, con); MySqlDataAdapter dataAdapter = new MySqlDataAdapter(cmd); DataSet ds = new DataSet("data"); dataAdapter.Fill(ds, "data"); DataRowCollection drc = ds.Tables["data"].Rows; if (drc.Count == 0) { logger.Warn("PrevSessionCountInfo is not exist."); return; } DataRow dr = drc[0]; String sessionName = dr["session_name"].ToString(); String description = dr["description"].ToString(); int kospiTargetCount = Convert.ToInt32(MathUtil.RemoveComma(dr["k_target_count"].ToString())); int bondTargetCount = Convert.ToInt32(MathUtil.RemoveComma(dr["b_target_count"].ToString())); int dollarTargetCount = Convert.ToInt32(MathUtil.RemoveComma(dr["d_target_count"].ToString())); textBox15.Text = kospiTargetCount.ToString("n0"); textBox14.Text = bondTargetCount.ToString("n0"); textBox13.Text = dollarTargetCount.ToString("n0"); ds.Clear(); } catch (System.Exception e) { logger.Error(e.ToString()); } finally { dbManager.Close(con); } }
void DBOut() { String sessionName = _sessionData.SessionKey; String description = _sessionData.Description; long notional = _sessionData.InputData.InitInvestAmount; double kospiAdjRate = Convert.ToDouble(textBox3.Text); double bondAdjRate = Convert.ToDouble(textBox4.Text); double dollarAdjRate = Convert.ToDouble(textBox5.Text); int kospiCount = Convert.ToInt32(MathUtil.RemoveComma(textBox11.Text)); int bondCount = Convert.ToInt32(MathUtil.RemoveComma(textBox10.Text)); int dollarCount = Convert.ToInt32(MathUtil.RemoveComma(textBox9.Text)); DBManager dbManager = new DBManager(); MySqlConnection con = null; try { String ip = Config.DB_SERVER_IP; con = dbManager.CreateConnection(ip, Config.DATABASE_CORREL); con.Open(); String template = "(session_name, description, investment_amount, k_adj, b_adj, d_adj," + " k_target_count, b_target_count, d_target_count, inserted)"; String query = String.Format( "insert into adre_trading_board {0} values ('{1}', '{2}', {3}, {4}, {5}, {6}, {7}, {8}, {9}, '{10}')", template, sessionName, description, notional, kospiAdjRate, bondAdjRate, dollarAdjRate, kospiCount, bondCount, dollarCount, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); MySqlCommand cmd = new MySqlCommand(query, con); int ret = cmd.ExecuteNonQuery(); if (ret != 1) { logger.Warn(query); throw new Exception(); } else { logger.Info(query); } } catch (System.Exception e) { logger.Error(e.ToString()); } finally { dbManager.Close(con); } }
public void LoadDataFromDB() { DBManager dbManager = new DBManager(); MySqlConnection con = null; try { String ip = Config.DB_SERVER_IP; con = dbManager.CreateConnection(ip, Config.DATABASE_CORREL); con.Open(); String query = String.Format( "select * from raw_price_data where Ticker = '{0}' and datetime >= '{1}' and datetime <= '{2}' order by DateTime", this.Ticker, this.StartDate.ToString("yyyy-MM-dd"), this.EndDate.ToString("yyyy-MM-dd")); MySqlCommand cmd = new MySqlCommand(query, con); MySqlDataAdapter dataAdapter = new MySqlDataAdapter(cmd); DataSet ds = new DataSet("raw_price_data"); dataAdapter.Fill(ds, "raw_price_data"); DataRowCollection drc = ds.Tables["raw_price_data"].Rows; double prevOpen = 0; double prevHigh = 0; double prevLow = 0; double prevClose = 0; for (int i = 0; i < drc.Count; ++i) { DataRow dr = drc[i]; String ticker = dr["Ticker"].ToString(); DateTime curDate = Convert.ToDateTime(dr["DateTime"]); double open = Convert.ToDouble(dr["Open"]); double high = Convert.ToDouble(dr["High"]); double low = Convert.ToDouble(dr["Low"]); double close = Convert.ToDouble(dr["LastPrice"]); // 주말 데이터가 들어오면 이상 데이터로 간주. 제외한다. if (curDate.DayOfWeek == DayOfWeek.Saturday || curDate.DayOfWeek == DayOfWeek.Sunday) { continue; } // 임시: 코스피 선물 데이터의 경우시고저종 값이 모두 같으면 이상 데이터로 간주. 제외한다. if ("KM1 R:00_0_R Index".CompareTo(ticker) == 0 && open == prevOpen && high == prevHigh && low == prevLow && close == prevClose) { continue; } OHLC ohlc = new OHLC(open, high, low, close); DOHLC dolhc = new DOHLC(curDate, ohlc); this._data.Add(dolhc); this._dateDict.Add(curDate, dolhc); prevOpen = open; prevHigh = high; prevLow = low; prevClose = close; } ds.Clear(); logger.Debug("{0} data load complete.", this.Ticker); } catch (System.Exception e) { logger.Error(e.ToString()); } finally { dbManager.Close(con); } }