Ejemplo n.º 1
0
        // futureSeriesOffset : 0 근월물, 1 원월물
        public KospiFutureInfo GetKospiFutureInfoFromCP(short futureSeriesOffset)
        {
            CPUTILLib.CpFutureCode futureCodeInfo = new CPUTILLib.CpFutureCode();
            DSCBO1Lib.FutureWideClass futureWide = new DSCBO1Lib.FutureWideClass();
            DSCBO1Lib.FutureMst futureMst = new DSCBO1Lib.FutureMst();

            // 상한가, 하한가, 전일 종가 등의 정보를 저장해 둔다.
            String futureCode = Convert.ToString(futureCodeInfo.GetData(0, futureSeriesOffset));

            futureWide.SetInputValue(0, futureCode);
            futureWide.BlockRequest();

            double yesterdayLastPrice = Convert.ToDouble(futureWide.GetHeaderValue(1));
            double upLimitPrice = Convert.ToDouble(futureWide.GetHeaderValue(2));
            double downLimitPrice = Convert.ToDouble(futureWide.GetHeaderValue(3));

            futureMst.SetInputValue(0, futureCode);
            futureMst.BlockRequest();

            long maturity = Convert.ToInt64(futureMst.GetHeaderValue(9));
            String strMaturity = "" + maturity;
            DateTime dtMaturityCP = DateTime.ParseExact(strMaturity, "yyyyMMdd", null);

            if (futureCode.Length == 5)
            {
                futureCode = futureCode + "000";
                logger.Info("future code is {0}({1}, [0: nearest 1: second])", futureCode, futureSeriesOffset);
            }
            else
            {
                logger.Error("Code problem {0}", futureCode);
                Util.KillWithNotice("Code problem");
            }

            KospiFutureInfo kfi = new KospiFutureInfo();

            kfi.Code = futureCode;
            kfi.UpLimit = upLimitPrice;
            kfi.DownLimit = downLimitPrice;
            kfi.YesterdayLastPrice = yesterdayLastPrice;
            kfi.Maturity = dtMaturityCP;

            logger.Info("Future info is loaded from CP");

            return kfi;
        }
        KospiFutureInfo GetKospiFutureInfoFromDB(short futureSeriesOffset)
        {
            DBManager dbManager = new DBManager();
            MySqlConnection con = null;

            try
            {
                String ip = ConfigManager.Ins().Config.GetValue(ConfigKeyConst.DB_SERVER_IP);
                con = dbManager.CreateConnection(ip, CommonConst.DATABASE_MADVIPER);
                con.Open();

                String query = "select * from kospi_future_info order by maturity";

                MySqlCommand cmd = new MySqlCommand(query, con);
                MySqlDataAdapter dataAdapter = new MySqlDataAdapter(cmd);

                DataSet ds = new DataSet("query_result");

                dataAdapter.Fill(ds, "query_result");
                DataRowCollection drc = ds.Tables["query_result"].Rows;

                if (drc.Count != 2)
                {
                    logger.Error("DB에 kospi future 정보가 두개가 아닙니다.");
                    Util.KillWithNotice("DB에 kospi future 정보가 두개가 아닙니다.");
                }

                Trace.Assert(futureSeriesOffset == 0 || futureSeriesOffset == 1);

                DataRow dr = drc[futureSeriesOffset];

                String code = dr["code"].ToString();
                double upLimit = Convert.ToDouble(dr["up_limit"]);
                double downLimit = Convert.ToDouble(dr["down_limit"]);
                long maturity = Convert.ToInt64(dr["maturity"]);

                KospiFutureInfo kfi = new KospiFutureInfo();
                kfi.Code = code;
                kfi.DownLimit = downLimit;
                kfi.UpLimit = upLimit;
                kfi.Maturity = DateTime.ParseExact("" + maturity, "yyyyMMdd", null);

                ds.Clear();

                return kfi;
            }
            catch (System.Exception ex)
            {
                logger.Warn(ex.ToString());
            }
            finally
            {
                dbManager.Close(con);
            }
            return null;
        }
 KospiFutureInfo GetKospiFutureInfo2_Raw()
 {
     if (_kfi2 == null)
     {
         _kfi2 = GetKospiFutureInfoFromDB(1);
     }
     return _kfi2;
 }
 KospiFutureInfo GetKospiFutureInfo_Raw()
 {
     if (_kfi1 == null)
     {
         _kfi1 = GetKospiFutureInfoFromDB(0);
     }
     return _kfi1;
 }
Ejemplo n.º 5
0
 public void SetFutureInfo_1(KospiFutureInfo kfi)
 {
     this.KFI = kfi;
 }
Ejemplo n.º 6
0
 public void SetFutureInfo_2(KospiFutureInfo kfi2)
 {
     this.KFI2 = kfi2;
 }
Ejemplo n.º 7
0
        void InsertFutureInfo(KospiFutureInfo data)
        {
            DBManager dbManager = new DBManager();
            MySqlConnection con = null;

            try
            {
                String ip = IP;
                con = dbManager.CreateConnection(ip, CommonConst.DATABASE_MADVIPER);
                con.Open();

                String query_template = String.Format("insert into kospi_future_info ({0}) values ({1})",
                    "code, up_limit, down_limit, yes_price, maturity",
                    "'{0}', {1}, {2}, {3}, {4}");

                String query = String.Format(
                    query_template,
                    data.Code,
                    data.UpLimit,
                    data.DownLimit,
                    data.YesterdayLastPrice,
                    data.Maturity.ToString("yyyyMMdd"));

                logger.Debug(query);

                MySqlCommand cmd = new MySqlCommand(query, con);
                int ret = cmd.ExecuteNonQuery();
                if (ret <= 0)
                {
                    logger.Warn(String.Format("Query: ({0})", query));
                }

                logger.Info("Delete kospi future spread info complete...");
            }
            catch (System.Exception ex)
            {
                logger.Warn(ex.ToString());
            }
            finally
            {
                dbManager.Close(con);
            }
        }