- UID
- 2
- 积分
- 2892307
- 威望
- 1396185 布
- 龙e币
- 1496122 刀
- 在线时间
- 13313 小时
- 注册时间
- 2009-12-3
- 最后登录
- 2024-12-25
|
10、订单成交、撤单、重发委托等跟交易与委托相关模块:- void test::OnRsqBar(string sPeriod, string sInst, map<string, TKVALUE> mp)
- {
- if (state != "run")return;
- mapK[sPeriod][sInst] = mp;
- int n = mp.size();
- if (n < jxzq)InsertLog(sInst + " bar 数量不够 ");
- }
- /*
- ***********************************************************************委托与交易模块(开始)**********************************************************************************
- */
- void test::OnInstrument(CThostFtdcInstrumentField t)
- {
- mapInstrument[t.InstrumentID] = t;
- }
- void test::OnRspQryOrder(map<string, CThostFtdcOrderField>* m)
- {
- mapOrder = *m;
- }
- void test::OnRspQryTrade(map<string, CThostFtdcTradeField>* m)
- {
- mapTrade = *m;
- }
- void test::OnPosition(map<string, map<string, TPOSITION>>* m)
- {
- mapPos = *m;
- }
- void test::OnPositionDetail(map<string, TDETAIL>* m)
- {
- mapPosDeta = *m;
- /*map<string, TDETAIL>::iterator it;
- for (it = mapPosDeta.begin(); it != mapPosDeta.end(); it++)
- {
- string s1 = " 编号 " + it->first + " 账户 " + it->second.sAcc + " 合约 " + it->second.sInst + " 方向 " + it->second.sBuySell + " 数量 " + to_string(it->second.nVol) + " 平仓数量 " + to_string(it->second.nCloseVol) + " 价格 " + to_string(it->second.dOpenPrice) + " 时间 " + it->second.sOpenDate;
- if (it->second.nVol - it->second.nCloseVol != 0)InsertLog(s1);
- }*/
- }
- void test::OnCommissionRate(map<string, map<string, TCOMMISSION>>* m)
- {
- mapCom = *m;
- }
- void test::OnAccount(map<string, CThostFtdcTradingAccountField>* m)
- {
- mapAcc = *m;
- }
- void test::OnInstrumentStatus(CThostFtdcInstrumentStatusField* t)
- {
- }
- void test::OnInstrumentAll(map<string, CThostFtdcInstrumentField>* m)
- {
- mapInstrument = *m;
- }
- void test::chedan()
- {
- map<string, CThostFtdcOrderField>::iterator it;
- for (it = mapOrder.begin(); it != mapOrder.end(); it++)
- {
- if (it->second.MacAddress == sName)
- {
- if (it->second.OrderStatus == '3' || it->second.OrderStatus == '1')
- {
- string bs;
- string soc;
- if (it->second.Direction == '0')bs = "买入";
- if (it->second.Direction == '1')bs = "卖出";
- if (it->second.CombOffsetFlag == "0")soc = "开仓";
- if (it->second.CombOffsetFlag == "1")soc = "平仓";
- if (it->second.CombOffsetFlag == "3")soc = "平今仓";
- if (it->second.CombOffsetFlag == "4")soc = "平昨仓";
- OrderAction(it->second);
- string s1 = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + it->second.InvestorID + " 有未成交委托,委托买卖方向 " + bs + soc + " 未成交数量委托数量 " + to_string((it->second.VolumeTotal - it->second.VolumeTraded)) + " 委托价格 " + to_string(it->second.LimitPrice) + " " + it->second.InstrumentID;
- maps[num] = s1;
- num++;
- lstActionOrdrSysID.push_back(it->second.OrderSysID);
- }
- }
- }
- if (num != 0)shuchurizhi();
- }
- void test::shuchurizhi()
- {
- map<int, string>::iterator it;
- for (it = maps.begin(); it != maps.end(); it++)
- {
- InsertLog(it->second);
- }
- maps.clear();
- num = 0;
- }
- void test::xieruzhuangtai()
- {
- string s = "c:/" + sName + sInst + "均线出场.txt";
- fstream ofs;
- ofs.open(s, ios::out, ios::_Noreplace);
- if (ofs.is_open())
- {
- ofs << to_string(fx) << endl;
- ofs << to_string(ss) << endl;
- }
- ofs.close();
- }
- void test::chongfa(CThostFtdcOrderField t)
- {
- string bs;
- string soc;
- if (t.Direction == '0')bs = "买入";
- if (t.Direction == '1')bs = "卖出";
- if (t.CombOffsetFlag == "0")soc = "开仓";
- if (t.CombOffsetFlag == "1")soc = "平仓";
- if (t.CombOffsetFlag == "3")soc = "平今仓";
- if (t.CombOffsetFlag == "4")soc = "平昨仓";
- char oc = t.CombOffsetFlag[0];
- double dsj;
- if (t.Direction == '0')
- {
- dsj = mapMd[t.InstrumentID].AskPrice1;
- }
- else if (t.Direction == '1')
- {
- dsj = mapMd[t.InstrumentID].BidPrice1;
- }
- OrderInsert(t.InvestorID, t.InstrumentID, t.Direction, oc, (t.VolumeTotal - t.VolumeTraded), dsj, "", "");
- string s = t.InvestorID;
- string s1 = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + s + " 有撤单成功重发,重发委托买卖方向 " + bs + soc + " 未成交数量委托数量 " + to_string((t.VolumeTotal - t.VolumeTraded)) + " 重发价格 " + to_string(dsj) + " " + t.InstrumentID;
- InsertLog(s1);
- }
- // 卖出平仓 优先平昨仓
- void test::closesell1(string sInvestorID, string sName, int sl, double jg)
- {
- //if (mapInstrument[sName].ExchangeID != "SHFE")
- //{
- // OrderInsert(sInvestorID, sName, '1', '1', sl, jg, "", "");
- //}
- //else
- //{
- if (mapPos[sInvestorID][sName].nLongPosYd >= sl)
- {
- OrderInsert(sInvestorID, sName, '1', '4', sl, jg, "", "");
- string s1 = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + " 账户 " + sInvestorID + " 合约 " + sName + " 卖出平昨 " + to_string(sl) + " 手,账户持仓有多单今仓数量 " + to_string(mapPos[sInvestorID][sName].nLongPosTd) + " 手持有昨仓多单数量 " + to_string(mapPos[sInvestorID][sName].nLongPosYd);
- InsertLog(s1);
- }
- else if (mapPos[sInvestorID][sName].nLongPosYd > 0)
- {
- OrderInsert(sInvestorID, sName, '1', '4', mapPos[sInvestorID][sName].nLongPosYd, jg, "", "");
- int jys2 = min(mapPos[sInvestorID][sName].nLongPosTd, sl - mapPos[sInvestorID][sName].nLongPosYd);
- if (mapPos[sInvestorID][sName].nLongPosTd > 0)
- {
- OrderInsert(sInvestorID, sName, '1', '3', jys2, jg, "", "");
- }
- string s1 = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + " 账户 " + sInvestorID + " 合约 " + sName + " 卖出平昨 " + to_string(mapPos[sInvestorID][sName].nLongPosYd) + " 卖出平今仓 " + to_string(jys2) + " 手,账户持仓有多单今仓数量 " + to_string(mapPos[sInvestorID][sName].nLongPosTd) + " 手持有昨仓多单数量 " + to_string(mapPos[sInvestorID][sName].nLongPosYd);
- InsertLog(s1);
- }
- else if (mapPos[sInvestorID][sName].nLongPosTd > 0)
- {
- int jys3 = min(sl, mapPos[sInvestorID][sName].nLongPosTd);
- OrderInsert(sInvestorID, sName, '1', '3', jys3, jg, "", "");
- string s1 = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + " 账户 " + sInvestorID + " 合约 " + sName + " 卖出平今仓 " + to_string(jys3) + " 手,账户持仓有多单今仓数量 " + to_string(mapPos[sInvestorID][sName].nLongPosTd) + " 手持有昨仓多单数量 " + to_string(mapPos[sInvestorID][sName].nLongPosYd);
- InsertLog(s1);
- }
- else
- {
- string s1 = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + " 账户 " + sInvestorID + " 合约 " + sName + " 账户持仓有多单今仓数量 " + to_string(mapPos[sInvestorID][sName].nLongPosTd) + " 手持有昨仓多单数量 " + to_string(mapPos[sInvestorID][sName].nLongPosYd) + " 账户持仓有空单今仓数量 " + to_string(mapPos[sInvestorID][sName].nShortPosTd) + " 手持有昨仓空单数量 " + to_string(mapPos[sInvestorID][sName].nShortPosYd);;
- InsertLog(s1);
- }
- // }
- }
- // 买入平仓 优先平昨仓
- void test::closebuy1(string sInvestorID, string sName, int sl, double jg)
- {
- //if (mapInstrument[sName].ExchangeID != "SHFE")
- //{
- // OrderInsert(sInvestorID, sName, '0', '1', sl, jg, "", "");
- //}
- //else
- //{
- if (mapPos[sInvestorID][sName].nShortPosYd >= sl)
- {
- OrderInsert(sInvestorID, sName, '0', '4', sl, jg, "", "");
- string s1 = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + " 账户 " + sInvestorID + " 合约 " + sName + " 买入平昨 " + to_string(sl) + " 手,账户持仓有空单今仓数量 " + to_string(mapPos[sInvestorID][sName].nShortPosTd) + " 手持有昨仓空单数量 " + to_string(mapPos[sInvestorID][sName].nShortPosYd);
- InsertLog(s1);
- }
- else if (mapPos[sInvestorID][sName].nShortPosYd > 0)
- {
- OrderInsert(sInvestorID, sName, '0', '4', mapPos[sInvestorID][sName].nShortPosYd, jg, "", "");
- int jys2 = min(mapPos[sInvestorID][sName].nShortPosTd, sl - mapPos[sInvestorID][sName].nShortPosYd);
- if (mapPos[sInvestorID][sName].nShortPosTd > 0)
- {
- OrderInsert(sInvestorID, sName, '0', '3', jys2, jg, "", "");
- }
- string s1 = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + " 账户 " + sInvestorID + " 合约 " + sName + " 买入平昨 " + to_string(mapPos[sInvestorID][sName].nShortPosYd) + " 买入平今仓 " + to_string(jys2) + " 手,账户持仓有空单今仓数量 " + to_string(mapPos[sInvestorID][sName].nShortPosTd) + " 手持有昨仓空单数量 " + to_string(mapPos[sInvestorID][sName].nShortPosYd);
- InsertLog(s1);
- }
- else if (mapPos[sInvestorID][sName].nShortPosTd > 0)
- {
- int jys3 = min(mapPos[sInvestorID][sName].nShortPosTd, sl);
- OrderInsert(sInvestorID, sName, '0', '3', jys3, jg, "", "");
- string s1 = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + " 账户 " + sInvestorID + " 合约 " + sName + " 买入平昨仓 " + to_string(jys3) + " 手,账户持仓有空单今仓数量 " + to_string(mapPos[sInvestorID][sName].nShortPosTd) + " 手持有昨仓空单数量 " + to_string(mapPos[sInvestorID][sName].nShortPosYd);
- InsertLog(s1);
- }
- else
- {
- string s1 = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + " 账户 " + sInvestorID + " 合约 " + sName + " 账户持仓有多单今仓数量 " + to_string(mapPos[sInvestorID][sName].nLongPosTd) + " 手持有昨仓多单数量 " + to_string(mapPos[sInvestorID][sName].nLongPosYd) + " 账户持仓有空单今仓数量 " + to_string(mapPos[sInvestorID][sName].nShortPosTd) + " 手持有昨仓空单数量 " + to_string(mapPos[sInvestorID][sName].nShortPosYd);;
- InsertLog(s1);
- }
- // }
- }
- // 卖出平仓 优先平今仓
- void test::closesell2(string sInvestorID, string sName, int sl, double jg)
- {
- //if (mapInstrument[sName].ExchangeID != "SHFE")
- //{
- // OrderInsert(sInvestorID, sName, '1', '1', sl, jg, "", "");
- //}
- //else
- //{
- if (mapPos[sInvestorID][sName].nLongPosTd >= sl)
- {
- OrderInsert(sInvestorID, sName, '1', '3', sl, jg, "", "");
- string s1 = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + " 账户 " + sInvestorID + " 合约 " + sName + " 卖出平今 " + to_string(sl) + " 手,账户持仓有多单今仓数量 " + to_string(mapPos[sInvestorID][sName].nLongPosTd) + " 手持有昨仓多单数量 " + to_string(mapPos[sInvestorID][sName].nLongPosYd);
- InsertLog(s1);
- }
- else if (mapPos[sInvestorID][sName].nLongPosTd > 0)
- {
- OrderInsert(sInvestorID, sName, '1', '3', mapPos[sInvestorID][sName].nLongPosTd, jg, "", "");
- int jys2 = min(mapPos[sInvestorID][sName].nLongPosYd, sl - mapPos[sInvestorID][sName].nLongPosTd);
- if (mapPos[sInvestorID][sName].nLongPosYd > 0)
- {
- OrderInsert(sInvestorID, sName, '1', '4', jys2, jg, "", "");
- }
- string s1 = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + " 账户 " + sInvestorID + " 合约 " + sName + " 卖出平今 " + to_string(mapPos[sInvestorID][sName].nLongPosTd) + " 卖出平昨仓 " + to_string(jys2) + " 手,账户持仓有多单今仓数量 " + to_string(mapPos[sInvestorID][sName].nLongPosTd) + " 手持有昨仓多单数量 " + to_string(mapPos[sInvestorID][sName].nLongPosYd);
- InsertLog(s1);
- }
- else if (mapPos[sInvestorID][sName].nLongPosYd > 0)
- {
- int jys3 = min(mapPos[sInvestorID][sName].nLongPosYd, sl);
- OrderInsert(sInvestorID, sName, '1', '4', jys3, jg, "", "");
- string s1 = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + " 账户 " + sInvestorID + " 合约 " + sName + " 卖出平昨仓 " + to_string(jys3) + " 手,账户持仓有多单今仓数量 " + to_string(mapPos[sInvestorID][sName].nLongPosTd) + " 手持有昨仓多单数量 " + to_string(mapPos[sInvestorID][sName].nLongPosYd);
- InsertLog(s1);
- }
- else
- {
- string s1 = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + " 账户 " + sInvestorID + " 合约 " + sName + " 账户持仓有多单今仓数量 " + to_string(mapPos[sInvestorID][sName].nLongPosTd) + " 手持有昨仓多单数量 " + to_string(mapPos[sInvestorID][sName].nLongPosYd) + " 账户持仓有空单今仓数量 " + to_string(mapPos[sInvestorID][sName].nShortPosTd) + " 手持有昨仓空单数量 " + to_string(mapPos[sInvestorID][sName].nShortPosYd);;
- InsertLog(s1);
- }
- }
- //
- //}
- // 买入平仓 优先平今仓
- void test::closebuy2(string sInvestorID, string sName, int sl, double jg)
- {
- //if (mapInstrument[sName].ExchangeID != "SHFE")
- //{
- // OrderInsert(sInvestorID, sName, '0', '1', sl, jg, "", "");
- //}
- //else
- //{
- if (mapPos[sInvestorID][sName].nShortPosTd >= sl)
- {
- OrderInsert(sInvestorID, sName, '0', '3', sl, jg, "", "");
- string s1 = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + " 账户 " + sInvestorID + " 合约 " + sName + " 买入平今 " + to_string(sl) + " 手,账户持仓有空单今仓数量 " + to_string(mapPos[sInvestorID][sName].nShortPosTd) + " 手持有昨仓空单数量 " + to_string(mapPos[sInvestorID][sName].nShortPosYd);
- InsertLog(s1);
- }
- else if (mapPos[sInvestorID][sName].nShortPosTd > 0)
- {
- OrderInsert(sInvestorID, sName, '0', '3', mapPos[sInvestorID][sName].nShortPosTd, jg, "", "");
- int jys2 = min(mapPos[sInvestorID][sName].nShortPosYd, sl - mapPos[sInvestorID][sName].nShortPosTd);
- if (mapPos[sInvestorID][sName].nShortPosYd > 0)
- {
- OrderInsert(sInvestorID, sName, '0', '4', jys2, jg, "", "");
- }
- string s1 = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + " 账户 " + sInvestorID + " 合约 " + sName + " 买入平今 " + to_string(mapPos[sInvestorID][sName].nShortPosTd) + " 买入平昨仓 " + to_string(jys2) + " 手,账户持仓有空单今仓数量 " + to_string(mapPos[sInvestorID][sName].nShortPosTd) + " 手持有昨仓空单数量 " + to_string(mapPos[sInvestorID][sName].nShortPosYd);
- InsertLog(s1);
- }
- else if (mapPos[sInvestorID][sName].nShortPosYd > 0)
- {
- int jys2 = min(mapPos[sInvestorID][sName].nShortPosYd, sl);
- OrderInsert(sInvestorID, sName, '0', '4', jys2, jg, "", "");
- string s1 = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + " 账户 " + sInvestorID + " 合约 " + sName + " 买入平昨仓 " + to_string(jys2) + " 手,账户持仓有空单今仓数量 " + to_string(mapPos[sInvestorID][sName].nShortPosTd) + " 手持有昨仓空单数量 " + to_string(mapPos[sInvestorID][sName].nShortPosYd);
- InsertLog(s1);
- }
- else
- {
- string s1 = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + " 账户 " + sInvestorID + " 合约 " + sName + " 账户持仓有多单今仓数量 " + to_string(mapPos[sInvestorID][sName].nLongPosTd) + " 手持有昨仓多单数量 " + to_string(mapPos[sInvestorID][sName].nLongPosYd) + " 账户持仓有空单今仓数量 " + to_string(mapPos[sInvestorID][sName].nShortPosTd) + " 手持有昨仓空单数量 " + to_string(mapPos[sInvestorID][sName].nShortPosYd);;
- InsertLog(s1);
- }
- }
- /*
- ***********************************************************************委托与交易模块(结束)**********************************************************************************
- */
复制代码 |
|