/// <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); }
/// <summary> /// 保存合约结算价数据。 /// </summary> /// <param name="DepthMarketDataFieldinstrumentList"></param> /// <returns></returns> private void SaveInstumentsSettlementPriceToDB(DepthMarketDataField item, string instrumentID, USeMarket market, DateTime settlementDate, double settlementPrice) { try { using (MySqlConnection connection = new MySqlConnection(m_dbConStr)) { connection.Open(); string cmdText = string.Format(@"update {0}.day_kline set settlement_price = @settlement_price where contract = @contract AND exchange = @exchange AND date_time = @date_time;", m_alphaDBName); // string cmdText = string.Format(@"update {0}.day_kline set settlement_price ={1} //where contract = '{2}' AND exchange = '{3}' AND date_time = '{4:yyyy-MM-dd}';", m_alphaDBName,settlementPrice,instrumentID,mar); MySqlCommand command = new MySqlCommand(cmdText, connection); command.Parameters.AddWithValue("@contract", instrumentID); command.Parameters.AddWithValue("@exchange", market.ToString()); command.Parameters.AddWithValue("@date_time", settlementDate); command.Parameters.AddWithValue("@settlement_price", settlementPrice); int result = command.ExecuteNonQuery(); //Debug.Assert(result == 1); } } catch (Exception ex) { string text = "保存结算价失败:" + ex.Message; WriteConsoleLog(text); } }
/// <summary> /// 保存合约结算价数据。 /// </summary> /// <param name="DepthMarketDataFieldinstrumentList"></param> /// <returns></returns> private void SaveClosePriceToDB(DepthMarketDataField item, string instrumentID, USeMarket market, DateTime dateTime, double priceClose) { try { using (MySqlConnection connection = new MySqlConnection(m_dbConStr)) { connection.Open(); string cmdText = string.Empty; cmdText = CreateClosePrice2UpdateSql(); MySqlCommand command = new MySqlCommand(cmdText, connection); command.Parameters.AddWithValue("@contract", instrumentID); command.Parameters.AddWithValue("@exchange", market.ToString()); command.Parameters.AddWithValue("@date_time", dateTime); command.Parameters.AddWithValue("@price_close2", (decimal)priceClose); int result = command.ExecuteNonQuery(); //Debug.Assert(result == 1); } } catch (Exception ex) { throw new Exception(ex.Message); } }
/// <summary> /// 获取一分钟K线表名。 /// </summary> /// <param name="market"></param> /// <returns></returns> private string GetMin1KLineTableName(USeMarket market) { string tableName = string.Empty; 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()); } return(tableName); }
private void RefreashSendimentaryMoney(DepthMarketDataField item, string instrumentID, USeMarket market, DateTime settlementDate, double settlementPrice) { //计算资金沉淀用结算价 decimal sendimentaryMoney = 0m; foreach (USeInstrumentDetail insDetail in m_insDetailList) { if (instrumentID == insDetail.Instrument.InstrumentCode) { int perSharesContract = insDetail.VolumeMultiple; //合约规模 decimal exchangeLongMarginRatio = insDetail.ExchangeLongMarginRatio; //保证金 sendimentaryMoney = Convert.ToDecimal(item.OpenInterest) * Convert.ToDecimal(settlementPrice) * perSharesContract * exchangeLongMarginRatio; //资金沉淀 break; } } Debug.Assert(sendimentaryMoney != 0m); try { using (MySqlConnection connection = new MySqlConnection(m_dbConStr)) { connection.Open(); string cmdText = string.Format(@"update {0}.day_kline set sendimentary_money = @sendimentary_money where contract = @contract AND exchange = @exchange AND date_time = @date_time;", m_alphaDBName); MySqlCommand command = new MySqlCommand(cmdText, connection); command.Parameters.AddWithValue("@contract", instrumentID); command.Parameters.AddWithValue("@exchange", market.ToString()); command.Parameters.AddWithValue("@date_time", settlementDate); command.Parameters.AddWithValue("@sendimentary_money", sendimentaryMoney); int result = command.ExecuteNonQuery(); Debug.Assert(result == 1); string text = string.Format("用结算价更新资金沉淀成功,合约:{0} 结算价:{1}", item.InstrumentID, settlementPrice); WriteConsoleLog(text); m_eventLogger.WriteInformation(text); } } catch (Exception ex) { string text = "用结算价更新资金沉淀失败:" + ex.Message; WriteConsoleLog(text); } }