/// <summary> /// 未捕获异常。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e) { Exception ex = (Exception)e.ExceptionObject; USeConsole.WriteLine(string.Format("observed unhandled exception:\r\n{0}", ex.ToString())); if (AppLogger.SingleInstance != null) { AppLogger.SingleInstance.WriteError("[MainContractMarginCalculater] catched unhandled exception:\r\n" + ex.ToString()); } }
public override bool Run() { USeProductManager varietiesManager = CreateVarietiesManager(); List <LogFileInfo> logFileList = GetLogFiles(varietiesManager); if (logFileList.Count < 0) { string text = "无可导入文件"; m_eventLogger.WriteInformation(text); USeConsole.WriteLine(text); return(true); } int index = 0; foreach (LogFileInfo file in logFileList) { index++; try { KLineImporter importer = new KLineImporter(file); if (importer.Cycel != USeCycleType.Min1 && importer.Cycel != USeCycleType.Day) { continue; } DateTime beginDate; DateTime endDate; List <USeKLine> klineList = importer.ParseKLine(out beginDate, out endDate); string text = string.Format("解析{0}.{1}@{2}数据完成,共计{3}条", importer.InstrumentCode, importer.Market, importer.Cycel, klineList.Count); USeConsole.WriteLine(text); Stopwatch stopWathch = new Stopwatch(); stopWathch.Start(); SaveKLineData(importer.Market, importer.Cycel, importer.InstrumentCode, beginDate, endDate, klineList); stopWathch.Stop(); long useSecondes = stopWathch.ElapsedMilliseconds / 1000; USeConsole.WriteLine(string.Format("导入{0}.{1}@{2}完成,共计{3}条,耗时{4}秒,平均速度{7}/秒,Finish{5}/{6}", importer.InstrumentCode, importer.Market, importer.Cycel, klineList.Count, useSecondes, index, logFileList.Count, useSecondes > 0 ? klineList.Count / useSecondes : 0)); } catch (Exception ex) { string text = string.Format("导入数据失败,文件路径:{0},错误:{1}", file.FileInfo.FullName, ex.Message); m_eventLogger.WriteInformation(text); USeConsole.WriteLine(text); } } return(true); }
/// <summary> /// 计算指定日主力合约。 /// </summary> /// <param name="settlementDate"></param> /// <returns></returns> private bool CalculateSerialContract(SettlementDayType settlementDayType, DateTime settlementDate, List <ErrorVarieties> errorList) { string text = string.Empty; if (!m_tradingDateManager.IsTradingDate(settlementDate)) { text = string.Format("{0:yyyy-MM-dd}为非交易日,无需计算", settlementDate); USeConsole.WriteLine(text); return(true); } Debug.Assert(m_varietiesList != null && m_varietiesList.Count > 0); foreach (USeProduct varieties in m_varietiesList) { try { List <string> serialContractList = null; if (settlementDayType == SettlementDayType.Today) { serialContractList = GetTodaySerialInstrument(varieties, settlementDate); } else { Debug.Assert(settlementDayType == SettlementDayType.SpecialDay); serialContractList = GetHistorySerialInstrument(varieties, settlementDate); //连续合约 } SaveSerialContract(varieties, settlementDate, serialContractList); text = string.Format("{0}@{1:yyyy-MM-dd}连续合约计算完成,共{2}个合约", varieties.ProductCode, settlementDate, serialContractList.Count); m_logger.WriteInformation(text); USeConsole.WriteLine(text); } catch (Exception ex) { text = string.Format("{0}@{1:yyyy-MM-dd}连续合约计算失败,{2}", varieties.ProductCode, settlementDate, ex.Message); m_logger.WriteInformation(text); USeConsole.WriteLine(text); errorList.Add(new ErrorVarieties() { Varieties = varieties.ProductCode, SettlementDate = settlementDate, ErrorMessage = ex.Message }); } } return(true); }
/// <summary> /// /// </summary> /// <returns></returns> public override bool Run() { List <MainContractEntity> mainContractList = GetMainContractList(); if (mainContractList.Count < 0) { string text = "无可导入主力合约"; m_eventLogger.WriteInformation(text); USeConsole.WriteLine(text); return(true); } int index = 0; foreach (MainContractEntity mainContract in mainContractList) { index++; try { string cmdDeleteText = GetMainContractMin1KLineDeleteSql(mainContract); string cmdInsertText = GetMainContractMin1KLineInsertSql(mainContract); string cmdText = cmdDeleteText + cmdInsertText; Stopwatch stopWathch = new Stopwatch(); stopWathch.Start(); using (MySqlConnection connection = new MySqlConnection(m_dbConStr)) { connection.Open(); MySqlCommand command = new MySqlCommand(cmdText, connection); command.ExecuteNonQuery(); } stopWathch.Stop(); long useSecondes = stopWathch.ElapsedMilliseconds / 1000; USeConsole.WriteLine(string.Format("导入{0}主力合约K线完成,耗时{1}秒,Finish{2}/{3}", mainContract, useSecondes, index, mainContractList.Count)); } catch (Exception ex) { string text = string.Format("导入{0}主力合约K线失败,错误:{1}", mainContract, ex.Message); m_eventLogger.WriteInformation(text); USeConsole.WriteLine(text); } } return(true); }
public override bool Initialize() { if (base.Initialize() == false) { return(false); } string klinFolder = ConfigurationManager.AppSettings["KLineFolder"]; if (string.IsNullOrEmpty(klinFolder)) { string text = "Not found KLineFolder"; m_eventLogger.WriteError(text); USeConsole.WriteLine(text); return(false); } m_kLineFolder = klinFolder; return(true); }
/// <summary> /// 初始化。 /// </summary> /// <returns></returns> public override bool Initialize() { if (base.Initialize() == false) { return(false); } try { string beginDateValue = ConfigurationManager.AppSettings["MainContractBeginDate"]; if (string.IsNullOrEmpty(beginDateValue)) { string text = "Not found MainContractBeginDate"; m_eventLogger.WriteError(text); USeConsole.WriteLine(text); return(false); } string endDateValue = ConfigurationManager.AppSettings["MainContractEndDate"]; if (string.IsNullOrEmpty(endDateValue)) { string text = "Not found MainContractEndDate"; m_eventLogger.WriteError(text); USeConsole.WriteLine(text); return(false); } m_beginDate = Convert.ToDateTime(beginDateValue); m_endDate = Convert.ToDateTime(endDateValue); } catch (Exception ex) { string text = "初始化主力合约K线导入服务失败," + ex.Message; m_eventLogger.WriteError(text); USeConsole.WriteLine(text); return(false); } return(true); }
/// <summary> /// 计算指定时段主力合约。 /// </summary> /// <param name="beginDate">起始日。</param> /// <param name="endDate">结束日。</param> /// <returns></returns> private bool CalculateMainContract(DateTime beginDate, DateTime endDate, List <ErrorVarieties> errorList) { string text = string.Empty; DateTime settlementDate = beginDate; while (settlementDate <= endDate) { try { CalculateMainContract(settlementDate, errorList); } catch (Exception ex) { text = string.Format("{0:yyyy-MM-dd}计算失败,错误:{1}", settlementDate, ex.Message); m_logger.WriteError(text); USeConsole.WriteLine(text); } settlementDate = settlementDate.AddDays(1); } return(true); }
/// <summary> /// 检查当日基础数据是否准备就绪。 /// </summary> /// <returns></returns> private bool CheckTodayBaseDataIsReady() { string text = string.Empty; int tryCount = 0; while (tryCount <= m_tryCount) { tryCount++; bool verifyResult = false; try { verifyResult = CheckBaseDataIsReady(DateTime.Today); } catch (Exception ex) { text = string.Format("基础数据第{0}次检查失败,错误:{1}", tryCount, ex.Message); m_logger.WriteError(text); USeConsole.WriteLine(text); } if (verifyResult == false) { text = string.Format("基础数据第{0}次检查未就绪,等待{1}继续尝试", tryCount, m_tryInterval); m_logger.WriteInformation(text); USeConsole.WriteLine(text); Thread.Sleep(m_tryInterval); continue; } else { return(true); } } return(false); }
/// <summary> /// 运行程序。 /// </summary> /// <returns></returns> private int Run() { int exitCode = 0; IAppLogger logger = AppLogger.SingleInstance; Debug.Assert(logger != null); SerialContractCalcServies m_serialContractServer = null; string message = string.Empty; // 消息。 USeConsole.WriteLine(); try { m_serialContractServer = new SerialContractCalcServies(logger); m_serialContractServer.Initialize(); } catch (Exception ex) { message = String.Format("连续合约计算服务初始化失败,错误:{0}", ex.Message); logger.WriteError(message); USeConsole.WriteLine(message); return(-1); } try { exitCode = m_serialContractServer.Run(); } catch (Exception ex) { message = String.Format("连续合约计算服务启动失败,错误:{0}", ex.Message); logger.WriteError(message); USeConsole.WriteLine(message); } return(exitCode); }
/// <summary> /// 读取配置信息。 /// </summary> /// <returns></returns> private bool ReadConfig() { try { string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; Debug.Assert(!string.IsNullOrEmpty(exePath)); Configuration config = ConfigurationManager.OpenExeConfiguration(exePath); if (!config.HasFile) { throw new ApplicationException("Not found the specific configuration file."); } CtpOrderDriverSection ctpSection = config.GetSection("CtpOrderDriver") as CtpOrderDriverSection; m_ctpDriverConfig = ctpSection.CtpOrderDriver; m_ctpAccountConfig = ctpSection.CtpAccount; m_dbConStr = ConfigurationManager.ConnectionStrings["MarketDataDB"].ConnectionString; m_alphaDBName = ConfigurationManager.AppSettings["AlphaDBName"]; //配置的查询参数 QuerySettingsSection settingsSection = config.GetSection("QuerySettlementSettings") as QuerySettingsSection; m_queryFrequence = settingsSection.QuerySettings.QueryFrequence; m_noonExchangeEndTime = settingsSection.QuerySettings.ExchangeNoonEndTime; m_noonExchangeBeginTime = settingsSection.QuerySettings.ExchangeNoonBeginTime; } catch (Exception ex) { string error = "Not found the specific configuration file," + ex.Message; USeConsole.WriteLine(error); m_eventLogger.WriteError(error); return(false); } return(true); }
/// <summary> /// 计算指定日主力合约。 /// </summary> /// <param name="settlementDate"></param> /// <returns></returns> private bool CalculateMainContract(DateTime settlementDate, List <ErrorVarieties> errorList) { string text = string.Empty; TradeCalendar tradeCalendar = m_tradingDateManager.GetTradeCalendar(settlementDate); if (tradeCalendar.IsTradeDay == false) { text = string.Format("{0:yyyy-MM-dd}为非交易日,无需计算", settlementDate); USeConsole.WriteLine(text); return(true); } //[yangming]历史数据未维护暂不校验 //if (CheckBaseDataIsReady(settlementDate) == false) //{ // text = string.Format("{0:yyyy-MM-dd}结算数据未就绪,无法计算", settlementDate); // m_logger.WriteWarning(text); // USeConsole.WriteLine(text); // errorList.Add(new ErrorVarieties() { // Varieties = "All", // SettlementDate = settlementDate, // ErrorMessage = text // }); // return false; //} Debug.Assert(m_varietiesList != null && m_varietiesList.Count > 0); foreach (USeProduct varieties in m_varietiesList) { //if (varieties.ProductCode != "CF") continue; try { string mainContract = GetMaxVolumeInstrument(varieties, settlementDate); //mainContract = "CF709"; List <string> hisMainContractList = GetHistoryMainContract(varieties, settlementDate); if (hisMainContractList != null && hisMainContractList.Count > 0) { string lastMainContract = hisMainContractList[0]; if (mainContract != lastMainContract) { //主力合约不同于昨日,且曾经为主力合约,则主力合约不切换 if (hisMainContractList.Contains(mainContract)) { mainContract = lastMainContract; } } } SaveMainContract(varieties, tradeCalendar.NextTradeDay, mainContract); text = string.Format("{0}@{1:yyyy-MM-dd}主力合约计算完成,主力合约:{2}", varieties.ProductCode, settlementDate, mainContract); m_logger.WriteInformation(text); USeConsole.WriteLine(text); } catch (Exception ex) { text = string.Format("{0}@{1:yyyy-MM-dd}主力合约计算失败,{2}", varieties.ProductCode, settlementDate, ex.Message); m_logger.WriteInformation(text); USeConsole.WriteLine(text); errorList.Add(new ErrorVarieties() { Varieties = varieties.ProductCode, SettlementDate = settlementDate, ErrorMessage = ex.Message }); } } return(true); }
/// <summary> /// 启动计算主力合约方法。 /// </summary> /// <returns></returns> public int Run() { string text = string.Empty; try { TradeCalendarManager tradeCalendarManager = new TradeCalendarManager(m_dbConnStr, m_alpahDBName); tradeCalendarManager.Initialize(); m_tradingDateManager = tradeCalendarManager; text = "初始化交易日历成功"; m_logger.WriteInformation(text); USeConsole.WriteLine(text); } catch (Exception ex) { text = string.Format("初始化交易日历失败,错误:{0}.", ex.Message); m_logger.WriteError(text); USeConsole.WriteLine(text); return(-1); } try { m_varietiesList = GetAllVarieties(); text = "加载品种信息成功"; m_logger.WriteInformation(text); USeConsole.WriteLine(text); } catch (Exception ex) { text = "加载品种信息失败," + ex.Message; m_logger.WriteError(text); USeConsole.WriteLine(text); return(-1); } if (m_dayType == SettlementDayType.Today) { //当日主力合约计算先检查基础数据状态,基础数据就绪后在计算主力合约 if (CheckTodayBaseDataIsReady() == false) { text = string.Format("{0:yyyy-MM-dd}基础数据未就绪,无法计算", m_beginDate); m_logger.WriteError(text); USeConsole.WriteLine(text); return(-2); } text = string.Format("{0:yyyy-MM-dd}基础数据已就绪,开始计算主力合约", m_beginDate); m_logger.WriteInformation(text); USeConsole.WriteLine(text); } List <ErrorVarieties> errorList = new List <ErrorVarieties>(); CalculateMainContract(m_beginDate, m_endDate, errorList); if (errorList.Count > 0) { foreach (ErrorVarieties errorItem in errorList) { text = errorItem.ToString(); m_logger.WriteInformation(text); USeConsole.WriteLine(text); } return(-2); } return(0); }
private TimeSpan m_nextDayRange = new TimeSpan(18, 0, 0); // 下一交易日的时间分界点 #endregion // member #region methods /// <summary> /// 启动结算价下载。 /// </summary> public int Start() { //确定更新结算价成功之后,需要再次计算资金沉淀,盘中的时候用的是最新价计算,有结算价之后,就改为结算价重新刷新一遍计算 //计算公式:资金沉淀=品种持仓量*结算价*合约规模*交易所多头保证金比例 //计算资金总沉淀(盘中就用最新价计算资金沉淀,待下午结算价出来之后,按照结算价再更新一次) //int perSharesContract = GetInstrumentPerSharesContract(marketData.Instrument.InstrumentCode);//合约规模 //decimal exchangeLongMarginRatio = GetExchangeLongMarginRatio(marketData.Instrument.InstrumentCode);//保证金 //m_kLine.SendimentaryMoney = marketData.OpenInterest * marketData.LastPrice * perSharesContract * exchangeLongMarginRatio;//资金沉淀 //取出UseinstrumentDetail品种合约信息取出合约规模和保证金额比例,再次执行SQL语句 try { m_eventLogger = AppLogger.InitInstance(); } catch { m_eventLogger = new NullLogger("DownloadProcessor_DefaultLogger"); } m_eventLogger.LineFeed(); string text = "开始下载结算价服务"; m_eventLogger.WriteInformation(text); WriteConsoleLog(text); if (ReadConfig() == false) { return(-1); } //下载所有合约详情,失败直接退出因为后面需要基础数据 try { USeTradingInstrumentManager tradingInsManager = CreateInstrumentManager(); m_insDetailList = tradingInsManager.GetAllInstrumentDetails(); Debug.Assert(m_insDetailList != null); } catch (Exception ex) { text = "下载数据库所有合约详情InstrumentDetail失败," + ex.Message; WriteConsoleLog(text); m_eventLogger.WriteError(text); return(-1); } CtpOrderQuerier ctpApp = new CtpOrderQuerier(); try { ctpApp.Connect(m_ctpDriverConfig.Address, m_ctpDriverConfig.Port, m_ctpDriverConfig.LoginTimeOut, m_ctpDriverConfig.QueryTimeOut); text = "连接CTP交易服务器成功"; WriteConsoleLog(text); m_eventLogger.WriteInformation(text); } catch (Exception ex) { text = "连接CTP交易服务器失败," + ex.Message; WriteConsoleLog(text); m_eventLogger.WriteError(text); ctpApp.Disconnect(); return(-1); } try { ctpApp.Login(m_ctpAccountConfig.ID, m_ctpAccountConfig.Password, m_ctpAccountConfig.BrokerID); text = "登陆CTP交易服务器成功"; WriteConsoleLog(text); m_eventLogger.WriteInformation(text); } catch (Exception ex) { text = "登陆CTP交易服务器失败," + ex.Message; WriteConsoleLog(text); m_eventLogger.WriteError(text); ctpApp.Disconnect(); return(-1); } try { List <InstrumentField> instrumentList = ctpApp.QueryInstument(); foreach (InstrumentField item in instrumentList) { if (item.ProductClass != ProductClass.Futures) { continue; } USeInstrumentDetail entity = InsturmentFiledToUSeInstrumentDetail(item); instrumentDic.Add(entity.Instrument.InstrumentCode, entity); } text = string.Format("查询期货合约数据完成,共计{0}个合约", instrumentDic.Count); WriteConsoleLog(text); m_eventLogger.WriteInformation(text); } catch (Exception ex) { text = "查询期货合约数据失败," + ex.Message; WriteConsoleLog(text); m_eventLogger.WriteError(text); ctpApp.Disconnect(); return(-1); } DateTime tradingDate = GetTradingDay(); if (m_refrashDate == QueryDay.Today) { int queryNum = m_queryNum; while (queryNum > 0) { try { List <DepthMarketDataField> tempDepthMarketDataFieldList = ctpApp.QueryDepthMarketData(); Debug.Assert(tempDepthMarketDataFieldList != null); foreach (DepthMarketDataField marketData in tempDepthMarketDataFieldList) { if (marketData.SettlementPrice <= 0d || marketData.SettlementPrice == double.MaxValue) { continue; } if (instrumentDic.ContainsKey(marketData.InstrumentID)) { //[hanyu]未防返回的MarketData没有ExchangeID,改用查询回来的合约交易所信息 USeMarket market = instrumentDic[marketData.InstrumentID].Instrument.Market; SaveInstumentsSettlementPriceToDB(marketData, marketData.InstrumentID, market, tradingDate, marketData.SettlementPrice); //保存完一笔的同时刷新一次资金沉淀[暂时不在这里处理,改用直接在特定时间执行SQL语句,因为涉及到8888指数和9999主力合约也需要刷新资金沉淀的问题] //RefreashSendimentaryMoney(marketData, marketData.InstrumentID, market, tradingDate,marketData.SettlementPrice); instrumentDic.Remove(marketData.InstrumentID); USeConsole.WriteLine(string.Format("保存{0}成功", marketData.InstrumentID)); } } if (instrumentDic.Count <= 0) { //所有合约存储完毕,退出 break; } queryNum--; if (queryNum > 0) { Thread.Sleep(m_queryFrequence); } } catch (Exception ex) { text = string.Format("查询,保存当日结算价异常:{0}", ex.Message); WriteConsoleLog(text); m_eventLogger.WriteInformation(text); ctpApp.Disconnect(); return(-1); } } } else { try { List <DepthMarketDataField> tempDepthMarketDataFieldList = ctpApp.QueryDepthMarketData(); Debug.Assert(tempDepthMarketDataFieldList != null); foreach (DepthMarketDataField marketData in tempDepthMarketDataFieldList) { if (marketData.PreSettlementPrice <= 0d || marketData.PreSettlementPrice == double.MaxValue) { continue; } if (instrumentDic.ContainsKey(marketData.InstrumentID)) { //[hanyu]未防返回的MarketData没有ExchangeID,改用查询回来的合约交易所信息 USeMarket market = instrumentDic[marketData.InstrumentID].Instrument.Market; //保存结算价 SaveInstumentsSettlementPriceToDB(marketData, marketData.InstrumentID, market, tradingDate, marketData.PreSettlementPrice); //RefreashSendimentaryMoney(marketData, marketData.InstrumentID, market, tradingDate,marketData.PreSettlementPrice); instrumentDic.Remove(marketData.InstrumentID); USeConsole.WriteLine(string.Format("保存{0}成功", marketData.InstrumentID)); } } } catch (Exception ex) { text = string.Format("保存昨日结算价异常:{0}", ex.Message); WriteConsoleLog(text); m_eventLogger.WriteInformation(text); ctpApp.Disconnect(); return(-1); } } if (ctpApp != null) { ctpApp.Disconnect(); } if (instrumentDic.Count > 0) { //未查询到的合约写入文件 foreach (USeInstrumentDetail field in instrumentDic.Values) { text = string.Format("[{0}]结算价查询失败", field.Instrument.InstrumentCode); WriteConsoleLog(text); m_eventLogger.WriteInformation(text); } } else { try { #if DEBUG bool iDownLoadResult = VerifyDBSettlementPrice(tradingDate); Debug.Assert(iDownLoadResult == true); #endif RefreshDBSettlementDownLoad(tradingDate, true); } catch (Exception ex) { text = string.Format("更新结算状态失败,错误:{0}", ex.Message); WriteConsoleLog(text); m_eventLogger.WriteInformation(text); } } return(0); }
/// <summary> /// 启动午盘休盘价下载。 /// </summary> public int Start() { try { m_eventLogger = AppLogger.InitInstance(); } catch { m_eventLogger = new NullLogger("DownloadProcessor_DefaultLogger"); } m_eventLogger.LineFeed(); string text = "开始下载午盘收盘价服务"; m_eventLogger.WriteInformation(text); USeConsole.WriteLine(text); if (ReadConfig() == false) { return(-1); } CtpOrderQuerier ctpApp = new CtpOrderQuerier(); try { ctpApp.Connect(m_ctpDriverConfig.Address, m_ctpDriverConfig.Port, m_ctpDriverConfig.LoginTimeOut, m_ctpDriverConfig.QueryTimeOut); text = "连接CTP交易服务器成功"; USeConsole.WriteLine(text); m_eventLogger.WriteInformation(text); } catch (Exception ex) { text = "连接CTP交易服务器失败," + ex.Message; USeConsole.WriteLine(text); m_eventLogger.WriteError(text); ctpApp.Disconnect(); return(-1); } try { ctpApp.Login(m_ctpAccountConfig.ID, m_ctpAccountConfig.Password, m_ctpAccountConfig.BrokerID); text = "登陆CTP交易服务器成功"; USeConsole.WriteLine(text); m_eventLogger.WriteInformation(text); } catch (Exception ex) { text = "登陆CTP交易服务器失败," + ex.Message; USeConsole.WriteLine(text); m_eventLogger.WriteError(text); ctpApp.Disconnect(); return(-1); } try { List <InstrumentField> instrumentList = ctpApp.QueryInstument(); foreach (InstrumentField item in instrumentList) { if (item.ProductClass != ProductClass.Futures) { continue; } USeInstrumentDetail entity = InsturmentFiledToUSeInstrumentDetail(item); instrumentDic.Add(entity.Instrument.InstrumentCode, entity); } text = string.Format("查询期货合约数据完成,共计{0}个合约", instrumentDic.Count); USeConsole.WriteLine(text); m_eventLogger.WriteInformation(text); } catch (Exception ex) { text = "查询期货合约数据失败," + ex.Message; USeConsole.WriteLine(text); m_eventLogger.WriteError(text); ctpApp.Disconnect(); return(-1); } List <DepthMarketDataField> depthMarketDataFieldList = new List <DepthMarketDataField>(); depthMarketDataFieldList = ctpApp.QueryDepthMarketData(); //while (true) //{ // depthMarketDataFieldList = ctpApp.QueryDepthMarketData(); // //返回大于下午开盘的行情时间 // if (VerfiyIsNoonBeginTime(depthMarketDataFieldList) == true) // { // text = string.Format("[{0}]行情已经进入下午开盘时间不在午盘时间内", DateTime.Now); // USeConsole.WriteLine(text); // m_eventLogger.WriteError(text); // ctpApp.Disconnect(); // return -1; // } // //未找到大于11:30:00。 // if (VerfiyIsNoonEndTime(depthMarketDataFieldList) == false) // { // Thread.Sleep(m_queryFrequence); // continue; // } // else // { // break; // } //} ctpApp.Disconnect(); try { foreach (DepthMarketDataField marketData in depthMarketDataFieldList) { if (instrumentDic.ContainsKey(marketData.InstrumentID)) { USeMarket market = instrumentDic[marketData.InstrumentID].Instrument.Market; //保存收盘价 SaveClosePriceToDB(marketData, marketData.InstrumentID, market, DateTime.Today, marketData.LastPrice); instrumentDic.Remove(marketData.InstrumentID); USeConsole.WriteLine(string.Format("保存{0}成功", marketData.InstrumentID)); } } RefrashPriceCloseDownLoad(DateTime.Today, 1); } catch (Exception ex) { text = string.Format("查询,保存当日午盘数据异常:{0}", ex.Message); USeConsole.WriteLine(text); m_eventLogger.WriteInformation(text); return(-1); } return(0); }
/// <summary> /// 运行程序。 /// </summary> /// <returns></returns> private int Run() { int exitCode = 0; IAppLogger logger = AppLogger.SingleInstance; Debug.Assert(logger != null); string text = string.Empty; string importDataTypeValue = ConfigurationManager.AppSettings["ImportDataType"]; if (string.IsNullOrEmpty(importDataTypeValue)) { text = String.Format("导入数据类型为空"); logger.WriteError(text); USeConsole.WriteLine(text); return(-1); } ImportDataType importDataType = (ImportDataType)Enum.Parse(typeof(ImportDataType), importDataTypeValue); ImportServices importServices = null; switch (importDataType) { case ImportDataType.DayKLine: importServices = new KLineImportServices(USeCycleType.Day, logger); break; case ImportDataType.Min1KLine: importServices = new KLineImportServices(USeCycleType.Min1, logger); break; case ImportDataType.ClosePrice2: importServices = new ClosePrice2ImportServices(logger); break; case ImportDataType.ContractIndex: importServices = new ContractIndexImportServices(logger); break; case ImportDataType.MainContractKLine: importServices = new MainContractKLineImportServices(logger); break; default: { string error = string.Format("未知的数据导入类型:{0}", importDataType); logger.WriteError(error); USeConsole.WriteLine(text); return(-1); } } try { if (importServices.Initialize() == false) { return(-1); } importServices.Run(); } catch (Exception ex) { text = String.Format("导入数据失败,错误:{0}", ex.Message); logger.WriteError(text); USeConsole.WriteLine(text); return(-1); } return(exitCode); }