/// <summary> /// 登录回调函数 /// </summary> /// <param name="pRspUserLogin"></param> /// <param name="pRspInfo"></param> /// <param name="nRequestID"></param> /// <param name="bIsLast"></param> public void OnRspUserLogin(SecurityFtdcRspUserLoginField pRspUserLogin, SecurityFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast) { if (bIsLast && !SysConst.IsErrorRspInfo(pRspInfo)) { ///获取当前交易日,说明登录成功了 String msg = "\n--->>> 获取当前交易日 = " + SysConst.TraderApi.GetTradingDay(); //Console.WriteLine(msg); Debug.WriteLine(msg); // 请求订阅行情 //SubscribeMarketData(); parent.asyncMsg.ShowMsg("交易账号登录成功!"); SecurityFtdcReqUserLoginField req = new SecurityFtdcReqUserLoginField(); req.BrokerID = SysConst.User.BrokerID; req.UserID = SysConst.User.UserID; req.Password = SysConst.User.Password; int iResult = SysConst.MarketDataApi.ReqUserLogin(req, SysConst.GetRequestID()); msg = "\n--->>> 发送用户登录请求: " + ((iResult == 0) ? "成功" : "失败"); parent.asyncMsg.AppendMsg(msg); Debug.WriteLine(msg); parent.QryInstrument(); ///留点行情处理时间 Thread.Sleep(1000); DialogResult = System.Windows.Forms.DialogResult.OK; } else { parent.asyncMsg.ShowMsg("登录失败:账号或者密码错误!"); Debug.WriteLine(pRspInfo.ErrorMsg); } }
public static bool IsErrorRspInfo(SecurityFtdcRspInfoField pRspInfo) { // 如果ErrorID != 0, 说明收到了错误的响应 bool bResult = ((pRspInfo != null) && (pRspInfo.ErrorID != 0)); if (bResult) { String msg = "\n--->>> ErrorID=" + pRspInfo.ErrorID + ", ErrorMsg=" + pRspInfo.ErrorMsg; Debug.WriteLine(msg); } return(bResult); }
void OnRspUserLogin(SecurityFtdcRspUserLoginField pRspUserLogin, SecurityFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast) { if (bIsLast && !IsErrorRspInfo(pRspInfo)) { ///获取当前交易日 String msg = "\n--->>> 获取当前交易日 = " + marketDataApi.GetTradingDay(); //Console.WriteLine(msg); asyncMsg.AppendMsg("用户登录成功!"); Debug.WriteLine(msg); // 请求订阅行情 SubscribeMarketData(); } else { asyncMsg.AppendMsg("登录失败:账号或者密码错误!"); Debug.WriteLine(pRspInfo.ErrorMsg); } }
/// <summary> /// 资金账号回调 /// </summary> /// <param name="pTradingAccount"></param> /// <param name="pRspInfo"></param> /// <param name="nRequestID"></param> /// <param name="bIsLast"></param> void OnRspQryTradingAccount(SecurityFtdcTradingAccountField pTradingAccount, SecurityFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast) { // if(SysConst.Accounts.ContainsKey(pTradingAccount.AccountID)) if (pTradingAccount != null) { SysConst.Accounts[pTradingAccount.AccountID] = pTradingAccount; if (bIsLast) { DataSet ds2 = GetFundInfo2Client(); if (this.FundDataGrid.InvokeRequired) { base.BeginInvoke(callbackUpdateFundDataGrid, ds2.Tables["Fund"]); } else { FillPositionDataGrid(ds2.Tables["Fund"]); } // asyncMsg.UpdateGrid(this.PositionDataGrid, ds2.Tables["Position"]); Debug.WriteLine("资金信息查询完毕!"); } } else { } }
/// <summary> /// 持仓信息回调 /// </summary> /// <param name="pInvestorPosition"></param> /// <param name="pRspInfo"></param> /// <param name="nRequestID"></param> /// <param name="bIsLast"></param> void OnRspQryInvestorPosition(SecurityFtdcInvestorPositionField pInvestorPosition, SecurityFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast) { if (pInvestorPosition != null) { SysConst.PositionDatas[pInvestorPosition.InstrumentID] = pInvestorPosition; if (bIsLast) { DataSet ds2 = GetPositionInfo2Client(); if (this.PositionDataGrid.InvokeRequired) { base.BeginInvoke(callbackUpdatePositionDataGrid, ds2.Tables["Position"]); } else { FillPositionDataGrid(ds2.Tables["Position"]); } // asyncMsg.UpdateGrid(this.PositionDataGrid, ds2.Tables["Position"]); Debug.WriteLine("持仓信息查询完毕!"); queryIsInit = true; } } else { queryIsInit = true; } }
void OnRspSubMarketData(SecurityFtdcSpecificInstrumentField pSpecificInstrument, SecurityFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast) { DebugPrintFunc(new StackTrace()); //asyncMsg.AppendMsg("行情订阅!"); }
void OnRspUnSubMarketData(SecurityFtdcSpecificInstrumentField pSpecificInstrument, SecurityFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast) { DebugPrintFunc(new StackTrace()); }
void OnRspUserLogin(SecurityFtdcRspUserLoginField pRspUserLogin, SecurityFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast) { if (bIsLast && !IsErrorRspInfo(pRspInfo)) { ///获取当前交易日 String msg = "\n--->>> 获取当前交易日 = " + SysConst.MarketDataApi.GetTradingDay(); //Console.WriteLine(msg); asyncMsg.AppendMsg("\n--->>> 行情登录成功!"); Debug.WriteLine(msg); // 请求订阅行情,获取合约之后再来订阅行情 //SubscribeMarketData(); } else { asyncMsg.AppendMsg("登录失败:账号或者密码错误!"); Debug.WriteLine(pRspInfo.ErrorMsg); } }
public static bool IsErrorRspInfo(SecurityFtdcRspInfoField pRspInfo) { // 如果ErrorID != 0, 说明收到了错误的响应 bool bResult = ((pRspInfo != null) && (pRspInfo.ErrorID != 0)); if (bResult) { String msg = "\n--->>> ErrorID=" + pRspInfo.ErrorID + ", ErrorMsg=" + pRspInfo.ErrorMsg; Debug.WriteLine(msg); } return bResult; }
void OnRspUserLogout(SecurityFtdcUserLogoutField pUserLogout, SecurityFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast) { DebugPrintFunc(new StackTrace()); asyncMsg.AppendMsg("--->>> 退出行情!"); Debug.WriteLine("--->>> 退出行情!"); }
/// <summary> /// 登录回调函数 /// </summary> /// <param name="pRspUserLogin"></param> /// <param name="pRspInfo"></param> /// <param name="nRequestID"></param> /// <param name="bIsLast"></param> public void OnRspUserLogin(SecurityFtdcRspUserLoginField pRspUserLogin, SecurityFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast) { if (bIsLast && !SysConst.IsErrorRspInfo(pRspInfo)) { ///获取当前交易日,说明登录成功了 String msg = "\n--->>> 获取当前交易日 = " + SysConst.TraderApi.GetTradingDay(); //Console.WriteLine(msg); Debug.WriteLine(msg); // 请求订阅行情 //SubscribeMarketData(); parent.asyncMsg.ShowMsg("交易账号登录成功!"); SecurityFtdcReqUserLoginField req = new SecurityFtdcReqUserLoginField(); req.BrokerID = SysConst.User.BrokerID; req.UserID = SysConst.User.UserID; req.Password = SysConst.User.Password; int iResult = SysConst.MarketDataApi.ReqUserLogin(req, SysConst.GetRequestID()); msg = "\n--->>> 发送用户登录请求: " + ((iResult == 0) ? "成功" : "失败"); parent.asyncMsg.AppendMsg(msg); Debug.WriteLine(msg); parent.QryInstrument(); ///留点行情处理时间 Thread.Sleep(1000); DialogResult = System.Windows.Forms.DialogResult.OK; } else { parent.asyncMsg.ShowMsg("登录失败:账号或者密码错误!"); Debug.WriteLine(pRspInfo.ErrorMsg); } }
void OnRspUserLogout(SecurityFtdcUserLogoutField pUserLogout, SecurityFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast) { DebugPrintFunc(new StackTrace()); asyncMsg.AppendMsg("--->>> 退出行情!"); Debug.WriteLine("--->>> 退出行情!"); }
void OnRspSubMarketData(SecurityFtdcSpecificInstrumentField pSpecificInstrument, SecurityFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast) { DebugPrintFunc(new StackTrace()); asyncMsg.AppendMsg("行情订阅!"); }
void OnRspUnSubMarketData(SecurityFtdcSpecificInstrumentField pSpecificInstrument, SecurityFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast) { DebugPrintFunc(new StackTrace()); }
/// <summary> /// 发生错误 /// </summary> /// <param name="pRspInfo"></param> /// <param name="nRequestID"></param> /// <param name="bIsLast"></param> void OnRspError(SecurityFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast) { DebugPrintFunc(new StackTrace()); IsErrorRspInfo(pRspInfo); asyncMsg.AppendMsg(pRspInfo.ErrorMsg); }
/// <summary> /// 合约查询回调 /// </summary> /// <param name="pInstrument"></param> /// <param name="pRspInfo"></param> /// <param name="nRequestID"></param> /// <param name="bIsLast"></param> void OnRspQryInstrument(SecurityFtdcInstrumentField pInstrument, SecurityFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast) { if (pInstrument != null) { SysConst.Instruments[pInstrument.InstrumentID.Trim()] = pInstrument; if (bIsLast) { InitQuery(); /// if (comboBoxInstrument.InvokeRequired) { base.Invoke(callbackUpdateComboboxInstrument); } else UpdateComboboxInstrument(); Debug.WriteLine("合约查询完毕!"); } } else { Debug.WriteLine("没有合约信息!"); } }
/// <summary> /// 报单回调 /// </summary> /// <param name="pInputOrder"></param> /// <param name="pRspInfo"></param> /// <param name="nRequestID"></param> /// <param name="bIsLast"></param> void OnRspOrderInsert(SecurityFtdcInputOrderField pInputOrder, SecurityFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast) { if (pInputOrder != null) { SysConst.SendOrders[pInputOrder] = pRspInfo; if (bIsLast) { UpdateDelegateDataGrid(); Debug.WriteLine(pRspInfo.ErrorMsg); } } }
/// <summary> /// 发生错误 /// </summary> /// <param name="pRspInfo"></param> /// <param name="nRequestID"></param> /// <param name="bIsLast"></param> void OnRspError(SecurityFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast) { DebugPrintFunc(new StackTrace()); //IsErrorRspInfo(pRspInfo); asyncMsg.AppendMsg(pRspInfo.ErrorMsg); }