예제 #1
0
        /// <summary>
        /// 获取数据表名。
        /// </summary>
        /// <param name="kLine"></param>
        /// <returns></returns>
        private string GetDBTableName(USeCycleType cycle, USeMarket market)
        {
            string tableName = string.Empty;

            if (cycle == USeCycleType.Day)
            {
                tableName = "day_kline";
            }
            else if (cycle == USeCycleType.Min1)
            {
                switch (market)
                {
                case USeMarket.CFFEX:
                case USeMarket.CZCE:
                case USeMarket.DCE:
                case USeMarket.SHFE:
                    tableName = string.Format("min1_kline_{0}", market.ToString().ToLower());
                    break;

                default:
                    Debug.Assert(false);
                    throw new Exception("Invalid market:" + market.ToString());
                }
            }
            else
            {
                throw new Exception("Invalid cycel:" + cycle.ToString());
            }
            return(tableName);
        }
예제 #2
0
        public KLineImporter(LogFileInfo fileInfo)
        {
            m_logFileInfo = fileInfo;

            m_filePath       = fileInfo.FileInfo.FullName;
            m_cycle          = fileInfo.Cycle;
            m_market         = fileInfo.Market;
            m_instrumentCode = fileInfo.InstrumentCode;
        }
예제 #3
0
        private TimeSpan m_logNoonTime    = new TimeSpan(11 + 3, 32, 00); //午盘时间 前推三个小时
        #endregion

        public ClosePrice2Importer(LogFileInfo fileInfo)
        {
            Debug.Assert(fileInfo.Cycle == USeCycleType.Min1);
            m_logFileInfo = fileInfo;

            m_filePath       = fileInfo.FileInfo.FullName;
            m_cycle          = fileInfo.Cycle;
            m_market         = fileInfo.Market;
            m_instrumentCode = fileInfo.InstrumentCode;
        }
예제 #4
0
        private DateTime GetLogTime(USeCycleType cycle, string dateValue, string timeValue)
        {
            string   value = dateValue.Replace(".", "-") + " " + timeValue + ":00";
            DateTime time;

            if (DateTime.TryParse(value, out time) == false)
            {
                Debug.Assert(false);
            }
            return(time);
        }
예제 #5
0
        private void SaveKLineData(USeMarket market, USeCycleType cycle, string instrumentCode,
                                   DateTime beginDate, DateTime endDate, List <USeKLine> klineList)
        {
            using (MySqlConnection connection = new MySqlConnection(m_dbConStr))
            {
                connection.Open();

                string tableName = GetDBTableName(cycle, market);
                string cmdText   = string.Format(@"delete from {0}.{1} where contract = '{2}' 
and date_time >= '{3:yyyy-MM-dd}' and date_time < '{4:yyyy-MM-dd}'",
                                                 m_alphaDBName, tableName, instrumentCode, beginDate, endDate.AddDays(1));
                MySqlCommand command = new MySqlCommand(cmdText, connection);
                command.ExecuteNonQuery();

                StringBuilder sb = new StringBuilder();
                foreach (USeKLine kLine in klineList)
                {
                    cmdText = CreateKLineInsertSql2(kLine);
                    sb.Append(cmdText);
                    //command = new MySqlCommand(cmdText, connection);
                    //command.Parameters.AddWithValue("@contract", kLine.InstrumentCode);
                    //command.Parameters.AddWithValue("@exchange", kLine.Market.ToString());
                    //command.Parameters.AddWithValue("@date_time", kLine.DateTime);
                    //command.Parameters.AddWithValue("@price_open", kLine.Open);
                    //command.Parameters.AddWithValue("@price_high", kLine.High);
                    //command.Parameters.AddWithValue("@price_low", kLine.Low);
                    //command.Parameters.AddWithValue("@price_close", kLine.Close);
                    //command.Parameters.AddWithValue("@volumn", kLine.Volumn);
                    //command.Parameters.AddWithValue("@turnover", kLine.Turnover);
                    //command.Parameters.AddWithValue("@openinterest", kLine.OpenInterest);

                    //if (kLine.Cycle == USeCycleType.Day)
                    //{
                    //    command.Parameters.AddWithValue("@pre_settlement_price", kLine.PreSettlementPrice);
                    //    command.Parameters.AddWithValue("@settlement_price", kLine.SettlementPrice);
                    //}
                    if (sb.Length > 6000)
                    {
                        command = new MySqlCommand(sb.ToString(), connection);
                        int result = command.ExecuteNonQuery();
                        sb.Clear();
                    }
                    //int result = command.ExecuteNonQuery();
                }

                if (sb.Length > 0)
                {
                    command = new MySqlCommand(sb.ToString(), connection);
                    int result = command.ExecuteNonQuery();
                    sb.Clear();
                }
            }
        }
예제 #6
0
        private DateTime GetActualTime(USeCycleType cycle, string dateValue, string timeValue)
        {
            string   value = dateValue.Replace(".", "-") + " " + timeValue + ":00";
            DateTime time;

            if (DateTime.TryParse(value, out time) == false)
            {
                Debug.Assert(false);
            }
            if (cycle == USeCycleType.Min1)
            {
                time = time.AddHours(-3).AddMinutes(-1);
            }
            return(time);
        }
예제 #7
0
        public static LogFileInfo ParseLogFile(FileInfo fileInfo, USeProductManager productManager)
        {
            string[] items = fileInfo.Name.Split(new char[] { '-', '.' });
            if (items.Length != 3 && items[2].ToLower() != "csv")
            {
                throw new Exception("Undistinguish fileName:" + fileInfo.Name);
            }

            USeCycleType cycle          = USeCycleType.Unknown;
            string       cycleValue     = items[0].ToLower();
            string       instrumentCode = items[1];

            if (cycleValue == "1min")
            {
                cycle = USeCycleType.Min1;
            }
            else if (cycleValue == "5min")
            {
                cycle = USeCycleType.Min5;
            }
            else if (cycleValue == "1day")
            {
                cycle = USeCycleType.Day;
            }
            else
            {
                throw new Exception("Undistinguish cycel:" + cycleValue);
            }

            string     productCode = USeTraderProtocol.GetVarieties(instrumentCode);
            USeProduct product     = productManager.GetPruduct(productCode);

            if (product == null)
            {
                throw new Exception("Undistinguish cycel:" + cycleValue);
            }

            LogFileInfo logInfo = new LogFileInfo();

            logInfo.InstrumentCode = GetOfficeInstrumentCode(instrumentCode, product.Market);
            logInfo.Market         = product.Market;
            logInfo.Cycle          = cycle;
            logInfo.FileInfo       = fileInfo;

            return(logInfo);
        }
예제 #8
0
        /// <summary>
        /// 构造方法。
        /// </summary>
        /// <param name="instrument">合约。</param>
        /// <param name="klinePublisher">发布者。</param>
        /// <param name="cycle">周期。</param>
        /// <param name="eventLogger">日志。</param>
        public MinKLineFactory(USeInstrument instrument, IKLinePublisher klinePublisher, DayTradeRange tradeRange, IAppLogger eventLogger, USeCycleType cycle, bool isMainContract)
            : base(instrument, klinePublisher, tradeRange, eventLogger)
        {
            if (cycle != USeCycleType.Min1)
            {
                throw new NotSupportedException(string.Format("Not support {0} ", cycle));
            }

            m_cycle          = cycle;
            m_isMainContract = isMainContract;

            if (isMainContract)
            {
                string varieties = USeTraderProtocol.GetVarieties(instrument.InstrumentCode);
                m_mainContract = USeTraderProtocol.GetMainContractCode(varieties, instrument.Market);
            }
        }
예제 #9
0
        /// <summary>
        /// 构造方法。
        /// </summary>
        /// <param name="indexInstrument">指数合约。</param>
        /// <param name="klinePublisher">发布者。</param>
        /// <param name="cycle">周期。</param>
        /// <param name="eventLogger">日志。</param>
        public IndexMinKLineFactory(USeProduct product, List <USeInstrument> instrumentList, USeCycleType cycle, IKLinePublisher klinePublisher, DayTradeRange tradeRange, IAppLogger eventLogger, USeTradingInstrumentManager instrumentManager)
            : base(USeTraderProtocol.GetVarietiesIndexCode(product),
                   klinePublisher, tradeRange, eventLogger)
        {
            if (cycle != USeCycleType.Min1)
            {
                throw new NotSupportedException(string.Format("Not support {0} ", cycle));
            }
            Debug.Assert(product.PriceTick > 0);
            Debug.Assert(instrumentList != null && instrumentList.Count > 0);

            m_cycle        = cycle;
            m_product      = product;
            m_componentDic = new Dictionary <string, USeMarketData>();
            foreach (USeInstrument instrument in instrumentList)
            {
                m_componentDic.Add(instrument.InstrumentCode, null);
            }

            //if (initKLine != null)
            //{
            //    Debug.Assert(initKLine.InstrumentCode == USeTraderProtocol.GetVarietiesIndexCode(product).InstrumentCode);
            //    m_kLine = initKLine;
            //}

            //获取该数据库下的合约详细信息
            try
            {
                Debug.Assert(instrumentManager != null);
                m_insDetailList = instrumentManager.GetAllInstrumentDetails();
            }
            catch (Exception ex)
            {
                throw new Exception("IndexDayKLineFactory 获取全部合约详细信息异常:" + ex.Message);
            }
        }
예제 #10
0
 public KLineImportServices(USeCycleType cycle, IAppLogger eventLogger)
     : base(eventLogger)
 {
     m_cycle = cycle;
 }