  
- UID
- 2
- 积分
- 2948830
- 威望
- 1424452 布
- 龙e币
- 1524378 刀
- 在线时间
- 13794 小时
- 注册时间
- 2009-12-3
- 最后登录
- 2025-5-1

|
核心策略模块,我做了一个注释:- if (bsfx == "0")//做价差扩大时价差是第一腿卖价减第二腿买价
- {
- jc = mapMd[dyt].AskPrice1 - mapMd[det].BidPrice1;//价差等于第一腿的卖价减第二腿的买价
- }
- else if (bsfx == "1")//做价差缩小时价差是第一腿的买价减第二腿的卖价
- {
- jc = mapMd[dyt].BidPrice1 - mapMd[det].AskPrice1;//价差等于第一腿的买价减第二腿的卖价
- }
- //条件价差方向是1(做多价差扩大),价差大于条件价差,第一腿的卖一量大于挂单量要求,第二腿的买单量大于挂单量要求,或者:条件价差方向是-1(做空价差缩小),价差小于等于条件价差,第一腿的买一单量大地挂单量要求,第二腿的卖单量大于挂单量【第一腿为买有两种情况:一是做价差扩大的建仓,二是做价差缩小后的平仓】
- if ((tjjcfx == "1" && jc >= tjjc && mapMd[dyt].AskVolume1 > gdl && mapMd[det].BidVolume1 > gdl) || (tjjcfx == "-1" && jc <= tjjc && mapMd[dyt].BidVolume1 > gdl && mapMd[det].AskVolume1 > gdl))
- {
- if (bsfx == "0") //第一腿是买(做价差扩大)【买有两种,一是做多开仓,二是做空平仓】
- {
- if (ocfx == "0") //建仓期(开仓买入)
- {
- dytcj = false; //第一腿没有成交
- detcj = false; //第二腿没有成交
- map<string, double>::iterator it;
- for (it = mapSub.begin(); it != mapSub.end(); it++)
- {
- int ss = (int)floor(it->second * sl);
- OrderInsert(it->first, dyt, '0', '0', ss, mapMd[dyt].AskPrice1 + hd * mapInstrument[det].PriceTick, "", "");//第一腿买单指令
- OrderInsert(it->first, det, '1', '0', ss, mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick, "", "");//第二腿卖单指令
- yfd = true;
- string s = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + it->first + " 达到套利价差交易条件买入开仓,第一腿价格 " + to_string(mapMd[dyt].AskPrice1 + hd * mapInstrument[det].PriceTick) + " 第二蹆价格 " + to_string(mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick) + " 对手价差 " + to_string(jc);
- maps[num] = s;
- num++;
- InsertLog(it->first + " 达到套利价差交易条件买入开仓,第一腿价格 " + to_string(mapMd[dyt].AskPrice1 + hd * mapInstrument[det].PriceTick) + " 第二蹆价格 " + to_string(mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick) + " 对手价差 " + to_string(jc));
- }
- }
- else if (ocfx == "1") //平仓期(平仓卖出)
- {
- dytcj = false; //第一腿没有成交
- detcj = false;//第二腿没有成交
- map<string, double>::iterator it;
- for (it = mapSub.begin(); it != mapSub.end(); it++)
- {
- int ss = (int)floor(it->second * sl);
- OrderInsert(it->first, dyt, '0', '1', ss, mapMd[dyt].AskPrice1 + hd * mapInstrument[det].PriceTick, "", "");
- OrderInsert(it->first, det, '1', '1', ss, mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick, "", "");
- yfd = true;
- string s = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + it->first + " 达到套利价差交易条件买入平仓,第一腿价格 " + to_string(mapMd[dyt].AskPrice1 + hd * mapInstrument[dyt].PriceTick) + " 第二蹆价格 " + to_string(mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick) + " 对手价差 " + to_string(jc);
- maps[num] = s;
- num++;
- InsertLog(it->first + " 达到套利价差交易条件买入平仓,第一腿价格 " + to_string(mapMd[dyt].AskPrice1 + hd * mapInstrument[dyt].PriceTick) + " 第二蹆价格 " + to_string(mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick) + " 对手价差 " + to_string(jc));
- }
- }
- else if (ocfx == "3")//平今
- {
- dytcj = false;
- detcj = false;
- map<string, double>::iterator it;
- for (it = mapSub.begin(); it != mapSub.end(); it++)
- {
- int ss = (int)floor(it->second * sl);
- OrderInsert(it->first, dyt, '0', '3', ss, mapMd[dyt].AskPrice1 + hd * mapInstrument[dyt].PriceTick, "", "");
- OrderInsert(it->first, det, '1', '3', ss, mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick, "", "");
- yfd = true;
- string s = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + it->first + " 达到套利价差交易条件买入平今,第一腿价格 " + to_string(mapMd[dyt].AskPrice1 + hd * mapInstrument[dyt].PriceTick) + " 第二蹆价格 " + to_string(mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick) + " 对手价差 " + to_string(jc);
- maps[num] = s;
- num++;
- InsertLog(it->first + " 达到套利价差交易条件买入平今,第一腿价格 " + to_string(mapMd[dyt].AskPrice1 + hd * mapInstrument[dyt].PriceTick) + " 第二蹆价格 " + to_string(mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick) + " 对手价差 " + to_string(jc));
- }
- }
- else if (ocfx == "4")//平昨
- {
- dytcj = false;
- detcj = false;
- map<string, double>::iterator it;
- for (it = mapSub.begin(); it != mapSub.end(); it++)
- {
- int ss = (int)floor(it->second * sl);
- OrderInsert(it->first, dyt, '0', '4', ss, mapMd[dyt].AskPrice1 + hd * mapInstrument[dyt].PriceTick, "", "");
- OrderInsert(it->first, det, '1', '4', ss, mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick, "", "");
- yfd = true;
- string s = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + it->first + " 达到套利价差交易条件买入平昨,第一腿价格 " + to_string(mapMd[dyt].AskPrice1 + hd * mapInstrument[dyt].PriceTick) + " 第二蹆价格 " + to_string(mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick) + " 对手价差 " + to_string(jc);
- maps[num] = s;
- num++;
- InsertLog(it->first + " 达到套利价差交易条件买入平昨,第一腿价格 " + to_string(mapMd[dyt].AskPrice1 + hd * mapInstrument[dyt].PriceTick) + " 第二蹆价格 " + to_string(mapMd[det].BidPrice1 - hd * mapInstrument[det].PriceTick) + " 对手价差 " + to_string(jc));
- }
- }
- }
- else if (bsfx == "1")//第一腿做卖出,有两种情况:一是做价差缩小的建仓,二是价差扩大后的平仓卖单
- {
- if (ocfx == "0") //建仓期(开仓卖出)
- {
- dytcj = false;
- detcj = false;
- map<string, double>::iterator it;
- for (it = mapSub.begin(); it != mapSub.end(); it++)
- {
- int ss = (int)floor(it->second * sl);
- OrderInsert(it->first, dyt, '1', '0', ss, mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick, "", "");
- OrderInsert(it->first, det, '0', '0', ss, mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick, "", "");
- yfd = true;
- string s = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + it->first + " 达到套利价差交易条件卖出开仓,第一腿价格 " + to_string(mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick) + " 第二蹆价格 " + to_string(mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick) + " 对手价差 " + to_string(jc);
- maps[num] = s;
- num++;
- InsertLog(it->first + " 达到套利价差交易条件卖出开仓,第一腿价格 " + to_string(mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick) + " 第二蹆价格 " + to_string(mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick) + " 对手价差 " + to_string(jc));
- }
- }
- else if (ocfx == "1")//平仓期(平仓卖出)
- {
- dytcj = false; detcj = false;
- map<string, double>::iterator it;
- for (it = mapSub.begin(); it != mapSub.end(); it++)
- {
- int ss = (int)floor(it->second * sl);
- OrderInsert(it->first, dyt, '1', '1', ss, mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick, "", "");
- OrderInsert(it->first, det, '0', '1', ss, mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick, "", "");
- yfd = true;
- string s = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + it->first + " 达到套利价差交易条件卖出平仓,第一腿价格 " + to_string(mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick) + " 第二蹆价格 " + to_string(mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick) + " 对手价差 " + to_string(jc);
- maps[num] = s;
- num++;
- InsertLog(it->first + " 达到套利价差交易条件卖出平仓,第一腿价格 " + to_string(mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick) + " 第二蹆价格 " + to_string(mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick) + " 对手价差 " + to_string(jc));
- }
- }
- else if (ocfx == "3")//平今
- {
- dytcj = false;
- detcj = false;
- map<string, double>::iterator it;
- for (it = mapSub.begin(); it != mapSub.end(); it++)
- {
- int ss = (int)floor(it->second * sl);
- OrderInsert(it->first, dyt, '1', '3', ss, mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick, "", "");
- OrderInsert(it->first, det, '0', '3', ss, mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick, "", "");
- yfd = true;
- string s = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + it->first + " 达到套利价差交易条件,第一腿价格卖出平今 " + to_string(mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick) + " 第二蹆价格 " + to_string(mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick) + " 对手价差 " + to_string(jc);
- maps[num] = s;
- num++;
- InsertLog(it->first + " 达到套利价差交易条件,第一腿价格卖出平今 " + to_string(mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick) + " 第二蹆价格 " + to_string(mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick) + " 对手价差 " + to_string(jc));
- }
- }
- else if (ocfx == "4")//平昨
- {
- dytcj = false;
- detcj = false;
- map<string, double>::iterator it;
- for (it = mapSub.begin(); it != mapSub.end(); it++)
- {
- int ss = (int)floor(it->second * sl);
- OrderInsert(it->first, dyt, '1', '4', ss, mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick, "", "");
- OrderInsert(it->first, det, '0', '4', ss, mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick, "", "");
- yfd = true;
- string s = t1 + ":" + t2 + ":" + t3 + ":" + t4 + " " + it->first + " 达到套利价差交易条件,第一腿价格卖出平昨 " + to_string(mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick) + " 第二蹆价格 " + to_string(mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick) + " 对手价差 " + to_string(jc);
- maps[num] = s;
- num++;
- InsertLog(it->first + " 达到套利价差交易条件,第一腿价格卖出平昨 " + to_string(mapMd[dyt].BidPrice1 - hd * mapInstrument[dyt].PriceTick) + " 第二蹆价格 " + to_string(mapMd[det].AskPrice1 + hd * mapInstrument[det].PriceTick) + " 对手价差 " + to_string(jc));
- }
- }
- }
- if (num != 0)shuchurizhi();
- tm = 0;
- }
复制代码 |
|