第六节 代码的编写(7)
几个不可见的按钮,这些按钮在运行时是不可见,由程序在运行到特定的时候直接调用
- 界面初始化:
这个按钮就是把界面美化一下,比如,把数据显示栏的字段头显示出来,把默认的参数赋值等,这里不列出代码了,没有什么重要的内容,读者可以根据自己的方式进行初始化,或不进行初始化。
- 登出释放:我们在退出程序的时候,需要把创建的对象释放掉,代码如下:
void CMyCtpDlg::OnBnClickedButton11()
{
// TODO: 在此添加控件通知处理程序代码
if (!LOGIN_MD_FLAG && !LOGIN_TR_FLAG) { return; }
CThostFtdcUserLogoutField req;
memset(&req, 0, sizeof(req));
strcpy_s(req.BrokerID, BROKER_ID);
strcpy_s(req.UserID, INVESTOR_ID);
// 释放 UserApi
if (pUserTrApi)
{
pUserTrApi->ReqUserLogout(&req, ++iRequestTRID);
pUserTrApi->RegisterSpi(NULL);
pUserTrApi->Release(); //@remark 不再使用本接口对象时,调用该函数删除接口对象
pUserTrApi = NULL;
}
// 释放 UserSpi 实例
if (pUserMdApi)
{
pUserMdApi->ReqUserLogout(&req, ++iRequestMDID);
pUserMdApi->RegisterSpi(NULL);
pUserMdApi->Release(); //@remark 不再使用本接口对象时,调用该函数删除接口对象
pUserMdApi = NULL;
}
LOGIN_MD_FLAG = false;
LOGIN_TR_FLAG = false;
}
///
这个也比较简单,不需要讲解,读者直接复制粘贴就可,就是程序退出前的时候调用一下。
- 接收行情数据:
//接收行情数据
void CMyCtpDlg::OnBnClickedButtonMddata()
{
CMyCtpDlg::OnBnClickedButton3(); //策略执行过程
CString md_DISPLAYSTR = _T(""); ///显示行情专用变量
CString md_InstId = _T("");
///先查找,没查到则插入
int nCount = -1;
int nIndex;
LVFINDINFO info;
MarketData m_Market_Data;
m_Market_Data = mm_Market_Data;
info.flags = LVFI_STRING;
md_DISPLAYSTR = m_Market_Data.InstrumentID.c_str();
if (Prc_Auto)
{
GetDlgItem(IDC_EDIT_INSTid)->GetWindowTextW(md_InstId);
if (md_InstId == md_DISPLAYSTR)
{
if (DIRECTION == THOST_FTDC_D_Buy)
{
md_InstId.Format(_T("%g"), m_Market_Data.AskPrice1);///申卖价一15
}
else
{
md_InstId.Format(_T("%g"), m_Market_Data.BidPrice1);///申买价一13
}
GetDlgItem(IDC_EDIT_prc)->SetWindowTextW(md_InstId);
}
}
info.psz = md_DISPLAYSTR;
while ((nIndex = m_IDC_LIST_MD.FindItem(&info)) == -1)
{
nCount = 0;
md_DISPLAYSTR = m_Market_Data.InstrumentID.c_str(); ///合约代码0
m_IDC_LIST_MD.InsertItem(nCount, md_DISPLAYSTR);
}
if (nCount == -1) { nCount = nIndex; }
md_DISPLAYSTR = m_Market_Data.TradingDay.c_str(); ///交易日 1
m_IDC_LIST_MD.SetItemText(nCount, 1, md_DISPLAYSTR);
md_DISPLAYSTR.Format(_T("%g"), m_Market_Data.LastPrice); ///最新价10
m_IDC_LIST_MD.SetItemText(nCount, 2, md_DISPLAYSTR);
md_DISPLAYSTR.Format(_T("%d"), m_Market_Data.Volume); ///数量8
m_IDC_LIST_MD.SetItemText(nCount, 3, md_DISPLAYSTR);
md_DISPLAYSTR.Format(_T("%g"), m_Market_Data.OpenInterest); 持仓量
m_IDC_LIST_MD.SetItemText(nCount, 4, md_DISPLAYSTR);
md_DISPLAYSTR = m_Market_Data.UpdateTime.c_str();///最后修改时间11
m_IDC_LIST_MD.SetItemText(nCount, 5, md_DISPLAYSTR);
md_DISPLAYSTR.Format(_T("%d"), m_Market_Data.UpdateMillisec);//最后修改毫秒12
m_IDC_LIST_MD.SetItemText(nCount, 6, md_DISPLAYSTR);
md_DISPLAYSTR.Format(_T("%g"), m_Market_Data.BidPrice1);///申买价一13
m_IDC_LIST_MD.SetItemText(nCount, 7, md_DISPLAYSTR);
md_DISPLAYSTR.Format(_T("%d"), m_Market_Data.BidVolume1); ///申买量一14
m_IDC_LIST_MD.SetItemText(nCount, 8, md_DISPLAYSTR);
md_DISPLAYSTR.Format(_T("%g"), m_Market_Data.AskPrice1);///申卖价一15
m_IDC_LIST_MD.SetItemText(nCount, 9, md_DISPLAYSTR);
md_DISPLAYSTR.Format(_T("%d"), m_Market_Data.AskVolume1);///申卖量一16
m_IDC_LIST_MD.SetItemText(nCount, 10, md_DISPLAYSTR);
md_DISPLAYSTR.Format(_T("%g"), m_Market_Data.HighestPrice);///最高价6
m_IDC_LIST_MD.SetItemText(nCount, 11, md_DISPLAYSTR);
md_DISPLAYSTR.Format(_T("%g"), m_Market_Data.LowestPrice); ///最低价7
m_IDC_LIST_MD.SetItemText(nCount, 12, md_DISPLAYSTR);
md_DISPLAYSTR.Format(_T("%g"), m_Market_Data.PreClosePrice); ///昨收盘价4
m_IDC_LIST_MD.SetItemText(nCount, 13, md_DISPLAYSTR);
md_DISPLAYSTR.Format(_T("%g"), m_Market_Data.OpenPrice); ///今天开盘价5
m_IDC_LIST_MD.SetItemText(nCount, 14, md_DISPLAYSTR);
md_DISPLAYSTR.Format(_T("%g"), m_Market_Data.ClosePrice); ///今收盘9
m_IDC_LIST_MD.SetItemText(nCount, 15, md_DISPLAYSTR);
}
//
说明:这个是轻量级的程序,所以,这里在接收行情数据的时候,直接用了行情数据变量赋值给局部变量,再显示到 List Control 控件上去,如果订阅的行情比较多,可以采用其它的方式接收数据。
我们收到数据后,首先在 List Control 中查找,如果有数据,则更新,如果没有,则插入一个新数据,这样就不像 控制台 程序那样,把数据一个一个的列示出来,屏上不停的有数据在滚动,人根本就没法看。
我们收到行情数据的第一时间,就是进入到策略判断过程中去,策略经过判断,如果需要进行开仓,平仓,撤单,锁仓等等操作,就直接先下达策略执行动作,然后才把数据显示在数据栏中。
- 接收成交数据:这个就是持仓数据,成交之后,就变成了我们的持仓,或平仓,等等,不管是什么,只要是有成交,都需要更新 一下持仓数据。
void CMyCtpDlg::OnBnClickedButton7()
{
int nCount = 0;
CString DISPLAYSTR = _T(""); ///为了显示到表格上方便
//m_IDC_LIST_POS.SetRedraw(FALSE); ///禁止窗口重绘,提高速度 m_IDC_LISTPOS.SetRedraw(TRUE); //恢复窗口重绘
m_IDC_LIST_POS.DeleteAllItems(); ///清屏
nCount = m_IDC_LIST_POS.GetItemCount(); //获取当前已插入的行数
size_t len = all_PosDatas.size();
for (size_t i = 0; i < len; i++)
{
{
//if (F_POS_W[0]>0) ///这个是必须要显示出来的,是增加一条,否则后面不能执行
{DISPLAYSTR = all_PosDatas[i].InstrumentID.c_str();
m_IDC_LIST_POS.InsertItem(nCount, DISPLAYSTR); }
if (F_POS_W[1] > 0)
{
DISPLAYSTR = all_PosDatas[i].BrokerID.c_str();
m_IDC_LIST_POS.SetItemText(nCount, 1, DISPLAYSTR);
}
if (F_POS_W[2] > 0)
{
DISPLAYSTR = all_PosDatas[i].InvestorID.c_str();
m_IDC_LIST_POS.SetItemText(nCount, 2, DISPLAYSTR);
}
if (F_POS_W[3] > 0)
{
DISPLAYSTR = all_PosDatas[i].HedgeFlag;///投机套保标志
m_IDC_LIST_POS.SetItemText(nCount, 3, DISPLAYSTR);
}
{
if (all_PosDatas[i].Direction == '0')
{
DISPLAYSTR = _T("买多");
}
else
{
DISPLAYSTR = _T(" 卖空");
}
m_IDC_LIST_POS.SetItemText(nCount, 4, DISPLAYSTR);
}
if (F_POS_W[5] > 0)
{
DISPLAYSTR = all_PosDatas[i].OpenDate.c_str();///开仓日期
m_IDC_LIST_POS.SetItemText(nCount, 5, DISPLAYSTR);
}
if (F_POS_W[6] > 0)
{
DISPLAYSTR = all_PosDatas[i].TradeID.c_str();///成交编号
m_IDC_LIST_POS.SetItemText(nCount, 6, DISPLAYSTR);
}
//if (F_POS_W[7]>0)
{DISPLAYSTR.Format(_T("%d"), all_PosDatas[i].Volume); ///数量
m_IDC_LIST_POS.SetItemText(nCount, 7, DISPLAYSTR);
}
//if (F_POS_W[8]>0)
{DISPLAYSTR.Format(_T("%g"), all_PosDatas[i].OpenPrice);///开仓价
m_IDC_LIST_POS.SetItemText(nCount, 8, DISPLAYSTR);
}
if (F_POS_W[9] > 0)
{
DISPLAYSTR = all_PosDatas[i].TradingDay.c_str();///交易日
m_IDC_LIST_POS.SetItemText(nCount, 9, DISPLAYSTR);
}
if (F_POS_W[10] > 0)
{
DISPLAYSTR.Format(_T("%d"), all_PosDatas[i].SettlementID);///结算编号
m_IDC_LIST_POS.SetItemText(nCount, 10, DISPLAYSTR);
}
if (F_POS_W[11] > 0)
{
if (all_PosDatas[i].TradeType == THOST_FTDC_TRDT_Common) //0) //成交类型
{
DISPLAYSTR = _T("普通成交");
}
else { DISPLAYSTR = _T("其它成交"); }
m_IDC_LIST_POS.SetItemText(nCount, 11, DISPLAYSTR);
}
if (F_POS_W[12] > 0)
{
DISPLAYSTR = all_PosDatas[i].CombInstrumentID.c_str();///组合合约代码
m_IDC_LIST_POS.SetItemText(nCount, 12, DISPLAYSTR);
}
if (F_POS_W[13] > 0)
{
DISPLAYSTR = all_PosDatas[i].ExchangeID.c_str();///交易所代码
m_IDC_LIST_POS.SetItemText(nCount, 13, DISPLAYSTR);
}
if (F_POS_W[14] > 0)
{
DISPLAYSTR.Format(_T("%g"), all_PosDatas[i].CloseProfitByDate);///逐日盯市平仓盈亏
m_IDC_LIST_POS.SetItemText(nCount, 14, DISPLAYSTR);
}
if (F_POS_W[15] > 0)
{
DISPLAYSTR.Format(_T("%g"), all_PosDatas[i].CloseProfitByTrade);///逐笔对冲平仓盈亏
m_IDC_LIST_POS.SetItemText(nCount, 15, DISPLAYSTR);
}
if (F_POS_W[16] > 0)
{
DISPLAYSTR.Format(_T("%g"), all_PosDatas[i].PositionProfitByDate);///逐日盯市持仓盈亏
m_IDC_LIST_POS.SetItemText(nCount, 16, DISPLAYSTR);
}
if (F_POS_W[17] > 0)
{
DISPLAYSTR.Format(_T("%g"), all_PosDatas[i].PositionProfitByTrade);///逐笔对冲持仓盈亏
m_IDC_LIST_POS.SetItemText(nCount, 17, DISPLAYSTR);
}
if (F_POS_W[18] > 0)
{
DISPLAYSTR.Format(_T("%.2f"), all_PosDatas[i].Margin);///投资者保证金 用g 会出现科学计数,要用 .2f
m_IDC_LIST_POS.SetItemText(nCount, 18, DISPLAYSTR);
}
if (F_POS_W[19] > 0)
{
DISPLAYSTR.Format(_T("%.2f"), all_PosDatas[i].ExchMargin);///交易所保证金
m_IDC_LIST_POS.SetItemText(nCount, 19, DISPLAYSTR);
}
if (F_POS_W[20] > 0)
{
DISPLAYSTR.Format(_T("%g"), all_PosDatas[i].MarginRateByMoney);///保证金率
m_IDC_LIST_POS.SetItemText(nCount, 20, DISPLAYSTR);
}
if (F_POS_W[21] > 0)
{
DISPLAYSTR.Format(_T("%g"), all_PosDatas[i].MarginRateByVolume);///保证金率(按手数)
m_IDC_LIST_POS.SetItemText(nCount, 21, DISPLAYSTR);
}
if (F_POS_W[22] > 0)
{
DISPLAYSTR.Format(_T("%g"), all_PosDatas[i].LastSettlementPrice);///昨结算价
m_IDC_LIST_POS.SetItemText(nCount, 22, DISPLAYSTR);
}
if (F_POS_W[23] > 0)
{
DISPLAYSTR.Format(_T("%g"), all_PosDatas[i].SettlementPrice);///结算价
m_IDC_LIST_POS.SetItemText(nCount, 23, DISPLAYSTR);
}
if (F_POS_W[24] > 0)
{
DISPLAYSTR.Format(_T("%d"), all_PosDatas[i].CloseVolume);///平仓量
m_IDC_LIST_POS.SetItemText(nCount, 24, DISPLAYSTR);
}
if (F_POS_W[25] > 0)
{
DISPLAYSTR.Format(_T("%g"), all_PosDatas[i].CloseAmount);///平仓金额
m_IDC_LIST_POS.SetItemText(nCount, 25, DISPLAYSTR);
}
}
}
m_IDC_LIST_POS.SetRedraw(TRUE);
}
/
因为持仓数据的字段比较多,有些不需要的字段,我们没必要显示出来,所以,我在这里定义了一个是否需要显示出来的数组F_POS_W[25],如果相应的字段在数组里为0,则不显示。
重点说明:这个和行情数据不一样,我们需要一个容器接收持仓数据,接收完之后,再把容器里的数据显示在界面上。
- 接收报单数据:这段代码因为字段比较多,也是很长,同上,不需要的内容也不显示了,用了同样的方法进行处理。
void CMyCtpDlg::OnBnClickedButton8()
{
//m_IDC_LISTORDER.SetRedraw(FALSE); ///禁止窗口重绘,提高速度 m_IDC_LISTPOS.SetRedraw(TRUE); //恢复窗口重绘
m_IDC_LISTORDER.DeleteAllItems(); ///清屏
GuaDan_Volume = 0;
size_t len = all_OrderDatas.size();
if (len <= 0) {return;}
int nCount = 0; m_IDC_LISTORDER.GetItemCount();
CString DISPLAYSTR = _T(""); ///为了显示到表格上方便
for (size_t i = 0; i < len; i++)
{
if ((all_OrderDatas[i].OrderStatus != THOST_FTDC_OST_AllTraded) && (all_OrderDatas[i].OrderStatus != THOST_FTDC_OST_Canceled)) //只对不正常单 已经成交或已经撤单的不
{
/挂单信息============================================================
GuaDan_OrderRef = all_OrderDatas[i].OrderRef; ///报单引用 这些信息与撤单相关,需要记录下来
Gua_Dan_ExchangeID = all_OrderDatas[i].ExchangeID; /// 这些信息与撤单相关,需要记录下来
Gua_Dan_OrderSysID = all_OrderDatas[i].OrderSysID; /// 这些信息与撤单相关,需要记录下来
GuaDan_Volume = all_OrderDatas[i].VolumeTotal; //VolumeTotal; ///剩数量 ///挂单数量
GuaDan_InstrumentID = all_OrderDatas[i].InstrumentID;
====================================================================
}
{
//if (F_ORDER_W[0] > 0){
if (1 == 1) {
DISPLAYSTR = all_OrderDatas[i].BrokerID.c_str(); ///经纪公司代码
m_IDC_LISTORDER.InsertItem(nCount, DISPLAYSTR);
}
if (F_ORDER_W[1] > 0)
{
DISPLAYSTR = all_OrderDatas[i].InvestorID.c_str(); ///投资者代码
m_IDC_LISTORDER.SetItemText(nCount, 1, DISPLAYSTR);
}
if (F_ORDER_W[2] > 0)
{
DISPLAYSTR = all_OrderDatas[i].InstrumentID.c_str(); ///合约代码
m_IDC_LISTORDER.SetItemText(nCount, 1, DISPLAYSTR);
}
if (F_ORDER_W[3] > 0)
{
DISPLAYSTR = all_OrderDatas[i].OrderRef.c_str(); ///报单引用
m_IDC_LISTORDER.SetItemText(nCount, 2, DISPLAYSTR);
}
if (F_ORDER_W[4] > 0)
{
DISPLAYSTR = all_OrderDatas[i].UserID.c_str(); ///用户代码
m_IDC_LISTORDER.SetItemText(nCount, 4, DISPLAYSTR);
}
if (F_ORDER_W[5] > 0)
{
DISPLAYSTR = all_OrderDatas[i].OrderPriceType; ///报单价格条件
m_IDC_LISTORDER.SetItemText(nCount, 5, DISPLAYSTR);
}
if (F_ORDER_W[6] > 0)
{
if (all_OrderDatas[i].Direction == '0')
{
DISPLAYSTR = _T("买多");
}
else
{
DISPLAYSTR = _T(" 卖空");
}
//DISPLAYSTR = all_OrderDatas[i].Direction;
m_IDC_LISTORDER.SetItemText(nCount, 3, DISPLAYSTR);
} ///买卖方向
if (F_ORDER_W[7] > 0)
{
if (all_OrderDatas[i].CombOffsetFlag == "0")
{
DISPLAYSTR = _T("开");
}
else
{
DISPLAYSTR = _T(" 平");
}
//DISPLAYSTR = all_OrderDatas[i].CombOffsetFlag.c_str();
m_IDC_LISTORDER.SetItemText(nCount, 4, DISPLAYSTR);
} ///组合开平标志
if (F_ORDER_W[8] > 0)
{
DISPLAYSTR = all_OrderDatas[i].CombHedgeFlag.c_str(); ///组合投机套保标志
m_IDC_LISTORDER.SetItemText(nCount, 8, DISPLAYSTR);
}
if (F_ORDER_W[9] > 0)
{
DISPLAYSTR.Format(_T("%g"), all_OrderDatas[i].LimitPrice); ///价格
m_IDC_LISTORDER.SetItemText(nCount, 5, DISPLAYSTR);
}
if (F_ORDER_W[10] > 0)
{
DISPLAYSTR.Format(_T("%d"), all_OrderDatas[i].VolumeTotalOriginal); ///数量
m_IDC_LISTORDER.SetItemText(nCount, 6, DISPLAYSTR);
}
if (F_ORDER_W[11] > 0)
{
DISPLAYSTR = all_OrderDatas[i].TimeCondition; ///有效期类型
m_IDC_LISTORDER.SetItemText(nCount, 11, DISPLAYSTR);
}
if (F_ORDER_W[12] > 0)
{
DISPLAYSTR = all_OrderDatas[i].GTDDate.c_str(); ///GTD日期
m_IDC_LISTORDER.SetItemText(nCount, 12, DISPLAYSTR);
}
if (F_ORDER_W[13] > 0)
{
DISPLAYSTR = all_OrderDatas[i].VolumeCondition; ///成交量类型
m_IDC_LISTORDER.SetItemText(nCount, 13, DISPLAYSTR);
}
if (F_ORDER_W[14] > 0)
{
DISPLAYSTR.Format(_T("%d"), all_OrderDatas[i].MinVolume); ///最小成交量
m_IDC_LISTORDER.SetItemText(nCount, 14, DISPLAYSTR);
}
if (F_ORDER_W[15] > 0)
{
DISPLAYSTR = all_OrderDatas[i].ContingentCondition; ///触发条件
m_IDC_LISTORDER.SetItemText(nCount, 15, DISPLAYSTR);
}
if (F_ORDER_W[16] > 0)
{
DISPLAYSTR.Format(_T("%g"), all_OrderDatas[i].StopPrice); ///止损价
m_IDC_LISTORDER.SetItemText(nCount, 16, DISPLAYSTR);
}
if (F_ORDER_W[17] > 0)
{
DISPLAYSTR = all_OrderDatas[i].ForceCloseReason; ///强平原因
m_IDC_LISTORDER.SetItemText(nCount, 17, DISPLAYSTR);
}
if (F_ORDER_W[18] > 0)
{
DISPLAYSTR.Format(_T("%d"), all_OrderDatas[i].IsAutoSuspend); ///自动挂起标志
m_IDC_LISTORDER.SetItemText(nCount, 18, DISPLAYSTR);
}
if (F_ORDER_W[19] > 0)
{
DISPLAYSTR = all_OrderDatas[i].BusinessUnit.c_str(); ///业务单元
m_IDC_LISTORDER.SetItemText(nCount, 19, DISPLAYSTR);
}
if (F_ORDER_W[20] > 0)
{
DISPLAYSTR.Format(_T("%d"), all_OrderDatas[i].RequestID); ///请求编号
m_IDC_LISTORDER.SetItemText(nCount, 20, DISPLAYSTR);
}
if (F_ORDER_W[21] > 0)
{
DISPLAYSTR = all_OrderDatas[i].OrderLocalID.c_str(); ///本地报单编号
m_IDC_LISTORDER.SetItemText(nCount, 21, DISPLAYSTR);
}
if (F_ORDER_W[22] > 0)
{
DISPLAYSTR = all_OrderDatas[i].ExchangeID.c_str(); ///交易所代码
m_IDC_LISTORDER.SetItemText(nCount, 7, DISPLAYSTR);
}
if (F_ORDER_W[23] > 0)
{
DISPLAYSTR = all_OrderDatas[i].ParticipantID.c_str(); ///会员代码
m_IDC_LISTORDER.SetItemText(nCount, 23, DISPLAYSTR);
}
if (F_ORDER_W[24] > 0)
{
DISPLAYSTR = all_OrderDatas[i].ClientID.c_str();
m_IDC_LISTORDER.SetItemText(nCount, 24, DISPLAYSTR);
}
if (F_ORDER_W[25] > 0)
{
DISPLAYSTR = all_OrderDatas[i].ExchangeInstID.c_str();
m_IDC_LISTORDER.SetItemText(nCount, 25, DISPLAYSTR);
}
if (F_ORDER_W[26] > 0)
{
DISPLAYSTR = all_OrderDatas[i].TraderID.c_str();
m_IDC_LISTORDER.SetItemText(nCount, 26, DISPLAYSTR);
}
if (F_ORDER_W[27] > 0)
{
DISPLAYSTR.Format(_T("%d"), all_OrderDatas[i].InstallID);
m_IDC_LISTORDER.SetItemText(nCount, 27, DISPLAYSTR);
}
if (F_ORDER_W[28] > 0)
{
DISPLAYSTR = all_OrderDatas[i].OrderSubmitStatus;
m_IDC_LISTORDER.SetItemText(nCount, 8, DISPLAYSTR);
}
if (F_ORDER_W[29] > 0)
{
DISPLAYSTR.Format(_T("%d"), all_OrderDatas[i].NotifySequence);
m_IDC_LISTORDER.SetItemText(nCount, 29, DISPLAYSTR);
}
if (F_ORDER_W[30] > 0)
{
DISPLAYSTR = all_OrderDatas[i].TradingDay.c_str();
m_IDC_LISTORDER.SetItemText(nCount, 30, DISPLAYSTR);
}
if (F_ORDER_W[31] > 0)
{
DISPLAYSTR.Format(_T("%d"), all_OrderDatas[i].SettlementID);
m_IDC_LISTORDER.SetItemText(nCount, 31, DISPLAYSTR);
}
if (F_ORDER_W[32] > 0)
{
DISPLAYSTR = all_OrderDatas[i].OrderSysID.c_str();
m_IDC_LISTORDER.SetItemText(nCount, 9, DISPLAYSTR);
}
if (F_ORDER_W[33] > 0)
{
DISPLAYSTR = all_OrderDatas[i].OrderSource;
m_IDC_LISTORDER.SetItemText(nCount, 33, DISPLAYSTR);
}
if (F_ORDER_W[34] > 0)
{
DISPLAYSTR = all_OrderDatas[i].OrderStatus; /报单状态,是否是区分成交撤单,挂起的标志?
m_IDC_LISTORDER.SetItemText(nCount, 10, DISPLAYSTR);
}
if (F_ORDER_W[35] > 0)
{
DISPLAYSTR = all_OrderDatas[i].OrderType;
m_IDC_LISTORDER.SetItemText(nCount, 35, DISPLAYSTR);
}
if (F_ORDER_W[36] > 0)
{
DISPLAYSTR.Format(_T("%d"), all_OrderDatas[i].VolumeTraded);
m_IDC_LISTORDER.SetItemText(nCount, 11, DISPLAYSTR);
}
if (F_ORDER_W[37] > 0)
{
DISPLAYSTR.Format(_T("%d"), all_OrderDatas[i].VolumeTotal);
m_IDC_LISTORDER.SetItemText(nCount, 12, DISPLAYSTR);
}
if (F_ORDER_W[38] > 0)
{
DISPLAYSTR = all_OrderDatas[i].InsertDate.c_str();
m_IDC_LISTORDER.SetItemText(nCount, 13, DISPLAYSTR);
}
if (F_ORDER_W[39] > 0)
{
DISPLAYSTR = all_OrderDatas[i].InsertTime.c_str();
m_IDC_LISTORDER.SetItemText(nCount, 14, DISPLAYSTR);
}
if (F_ORDER_W[40] > 0)
{
DISPLAYSTR = all_OrderDatas[i].ActiveTime.c_str();
m_IDC_LISTORDER.SetItemText(nCount, 40, DISPLAYSTR);
}
if (F_ORDER_W[41] > 0)
{
DISPLAYSTR = all_OrderDatas[i].SuspendTime.c_str();
m_IDC_LISTORDER.SetItemText(nCount, 41, DISPLAYSTR);
}
if (F_ORDER_W[42] > 0)
{
DISPLAYSTR = all_OrderDatas[i].UpdateTime.c_str();
m_IDC_LISTORDER.SetItemText(nCount, 42, DISPLAYSTR);
}
if (F_ORDER_W[43] > 0)
{
DISPLAYSTR = all_OrderDatas[i].CancelTime.c_str();
m_IDC_LISTORDER.SetItemText(nCount, 43, DISPLAYSTR);
}
if (F_ORDER_W[44] > 0)
{
DISPLAYSTR = all_OrderDatas[i].ActiveTraderID.c_str();
m_IDC_LISTORDER.SetItemText(nCount, 44, DISPLAYSTR);
}
if (F_ORDER_W[45] > 0)
{
DISPLAYSTR = all_OrderDatas[i].ClearingPartID.c_str();
m_IDC_LISTORDER.SetItemText(nCount, 45, DISPLAYSTR);
}
if (F_ORDER_W[46] > 0)
{
DISPLAYSTR.Format(_T("%d"), all_OrderDatas[i].SequenceNo);
m_IDC_LISTORDER.SetItemText(nCount, 46, DISPLAYSTR);
}
if (F_ORDER_W[47] > 0)
{
DISPLAYSTR.Format(_T("%d"), all_OrderDatas[i].FrontID);
m_IDC_LISTORDER.SetItemText(nCount, 47, DISPLAYSTR);
}
if (F_ORDER_W[48] > 0)
{
DISPLAYSTR.Format(_T("%d"), all_OrderDatas[i].SessionID);
m_IDC_LISTORDER.SetItemText(nCount, 48, DISPLAYSTR);
}
if (F_ORDER_W[49] > 0)
{
DISPLAYSTR = all_OrderDatas[i].UserProductInfo.c_str();
m_IDC_LISTORDER.SetItemText(nCount, 49, DISPLAYSTR);
}
if (F_ORDER_W[50] > 0)
{
DISPLAYSTR = all_OrderDatas[i].StatusMsg.c_str();
m_IDC_LISTORDER.SetItemText(nCount, 15, DISPLAYSTR);
}
if (F_ORDER_W[51] > 0)
{
DISPLAYSTR.Format(_T("%d"), all_OrderDatas[i].UserForceClose);
m_IDC_LISTORDER.SetItemText(nCount, 51, DISPLAYSTR);
}
if (F_ORDER_W[52] > 0)
{
DISPLAYSTR = all_OrderDatas[i].ActiveUserID.c_str();
m_IDC_LISTORDER.SetItemText(nCount, 52, DISPLAYSTR);
}
if (F_ORDER_W[53] > 0)
{
DISPLAYSTR.Format(_T("%d"), all_OrderDatas[i].BrokerOrderSeq);
m_IDC_LISTORDER.SetItemText(nCount, 53, DISPLAYSTR);
}
}
}
m_IDC_LISTORDER.SetRedraw(TRUE);
}
//
这段代码与持仓数据的差不多,都是一样的方式进行处理的。
至止,界面上的代码就讲解完了,为了让读者能看得懂,我们特意重新写了这么一个轻量级的小程序,在写的过程中,尽量用最简单的方式,没有采用各种的数据结构,各种的函数,各种的绕来绕去,全部在一个界面上,从上到下,一目了然,就是为了让读者能看懂,能有所帮助。
这个小程序的诞生,源于…………,想一下,可能还有更多的人需要这样的可读性强的代码用来参考等等,特别是新了解CTP的读者,CTP系统不仅仅是一套代码,想开发好CTP期货程序化交易程序,除了会写代码外,还要对CTP期货交易系统有所了解,才能写出好的程序。
需要查看原文件的读者,欢迎前往 :https://ipacel.cc/ctp
先到这里吧,看看反响怎么样,如果反响比较多,我就再把后面的内容写出来。如有需要的读者,可以联系作者索取源码 或 演示用可执行文件,作者平时要上课,回复信息不及时,请读者直接加,作者看到了会第一时间回复,读者也可以在以下网址找到相关的内容,或联系方式。