做量化交易的朋友都支持,2019年6月要开始实行穿透式监管了,
老的代码可能不再能够接入,那么如何将老的CTP程序实现升级到穿透式监管呢?本文就讲一下修改的方法。
一、先替换为最新的CTP api
CTP API下载地址
http://www.simnow.com.cn/static/softwareDownload.action
期货低佣金开户
http://www.kaihucn.cn/
期货低佣金开户步骤(交易所标准+1分,交反40%~90%)
http://www.kaihucn.cn/comm/topic/1882/
期货行情数据下载地址
http://www.mdshare.cn
http://www.pythonpai.com/topic/4206/
免费商品期货股指期货跟单系统和资管系统
http://www.kucps.com/
参考代码打包下载
http://mdshare.cn/source.zip
同时免费提供期货APP下单掌上宏源https://mp.weixin.qq.com/s/j_xLax6qM74dcUlM2jZCww
可以看到新的API里的认证,主要涉及以下2个方法
///客户端认证响应
virtual void OnRspAuthenticate(CThostFtdcRspAuthenticateField *pRspAuthenticateField,
CThostFtdcRspInfoField *pRspInfo,
int nRequestID, bool bIsLast) {};
///客户端认证请求
virtual int ReqAuthenticate(CThostFtdcReqAuthenticateField *pReqAuthenticateField,
int nRequestID) = 0;
这2个方法分别是:客户端认证响应和客户端认证请求。
二、代码方面的修改:
之前大家做CTP都需要调用ReqUserLogin();这个登录请求,现在如果要接入穿透式监管的流程改变了,请将ReqUserLogin();替换为ReqAuthenticate(CThostFtdcReqAuthenticateField *pReqAuthenticateField, int nRequestID) 认证请求,然后在认证回调里添加ReqUserLogin();
简单的说代码修改流程即为:
1.把以前登录请求替换为认证请求
2.就是把登录请求放到认证回调里
即先认证再登录
向期货公司申请获得信息
在认证请求的结构体定义如下:
///客户端认证响应
struct CThostFtdcRspAuthenticateField
{
///经纪公司代码
TThostFtdcBrokerIDType BrokerID;
///用户代码
TThostFtdcUserIDType UserID;
///用户端产品信息
TThostFtdcProductInfoType UserProductInfo;
///App代码
TThostFtdcAppIDType AppID;
///App类型
TThostFtdcAppTypeType AppType;
};
三、认证的函数ReqAuthenticate的定义赋值
void CTraderSpi::ReqAuthenticate(const char *UserProductInfo,const char *AuthCode)
{
if(pUserApi[accountid] == NULL ){return;}
//认证码
CThostFtdcReqAuthenticateField pReqAuthenticateField;
memset(&pReqAuthenticateField, 0, sizeof(CThostFtdcReqAuthenticateField));
strcpy(pReqAuthenticateField.BrokerID, BROKER_ID);
strcpy(pReqAuthenticateField.UserID, INVESTOR_ID);
strcpy(pReqAuthenticateField.UserProductInfo, UserProductInfo); //产品标识
strcpy(pReqAuthenticateField.AuthCode, AuthCode); //认证码
int iResult = pUserApi[accountid]->ReqAuthenticate(&pReqAuthenticateField, ++iRequestID);
cerr << "--->>> 发送认证请求: " << ((iResult == 0) ? "成功" : "失败") << endl;
}
其中产品信息UserProductInfo、AppID、AppType
需要通过咨询期货公司获得。
http://www.mdshare.cn/comm/topic/2750/
《优秀量化资源导航》
《TradeApi A股程序化交易接口》
《酷操盘手期货跟单软件》
《开户中国期货低佣金开户》
《mdshare财经数据接口包》
《期货跟单软件视频教学4集》
python量化交易