Board logo

标题: CTP穿透式监管怎么实现代码, 穿透测试API [打印本页]

作者: 龙听    时间: 2019-5-23 15:01     标题: CTP穿透式监管怎么实现代码, 穿透测试API

做量化交易的朋友都支持,2019年6月要开始实行穿透式监管了,
老的代码可能不再能够接入,那么如何将老的CTP程序实现升级到穿透式监管呢?本文就讲一下修改的方法。
(1)先替换为最新的CTP api
CTP API下载地址
http://www.simnow.com.cn/static/softwareDownload.action

Quicklib 下载地址
http://www.quicklib.cn/
期货行情数据下载地址
http://www.mdshare.cn
http://www.pythonpai.com/topic/4206/
免费商品期货股指期货跟单系统和资管系统
http://www.kucps.com/
参考代码打包下载
http://mdshare.cn/source.zip

期货低佣金开户步骤(交易所标准+1分,交反40%~90%)
http://www.qhlt.cn/thread-25049-1-1.html


主要涉及以下2个方法

///客户端认证响应virtual void OnRspAuthenticate(CThostFtdcRspAuthenticateField *pRspAuthenticateField, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};///客户端认证请求virtual int ReqAuthenticate(CThostFtdcReqAuthenticateField *pReqAuthenticateField, int nRequestID) = 0;

这2个方法分别是:客户端认证请求,客户端认证响应

(2)代码方面的修改:

之前大家做CTP都需要调用ReqUserLogin();这个登录请求,现在如果要接入穿透式监管的流程改变了,请将ReqUserLogin();替换为ReqAuthenticate(CThostFtdcReqAuthenticateField *pReqAuthenticateField, int nRequestID) 认证请求,然后在认证回调里添加ReqUserLogin();

简单的说代码修改流程即为:
先认证再登录
1.把以前登录请求替换为认证请求
2.就是把登录请求放到认证回调里

向期货公司申请获得信息
在认证请求的结构体定义如下:、

  1. ///客户端认证响应

  2. struct CThostFtdcRspAuthenticateField
  3. {
  4.         ///经纪公司代码
  5.         TThostFtdcBrokerIDType        BrokerID;
  6.         ///用户代码
  7.         TThostFtdcUserIDType        UserID;
  8.         ///用户端产品信息
  9.         TThostFtdcProductInfoType        UserProductInfo;
  10.         ///App代码
  11.         TThostFtdcAppIDType        AppID;
  12.         ///App类型
  13.         TThostFtdcAppTypeType        AppType;
  14. };
复制代码

(3)认证的函数定义

  1. ReqAuthenticate(UserProductInfo, AuthCode);

  2. void CTraderSpi::ReqAuthenticate(const char *UserProductInfo,const char *AuthCode)
  3. {                        
  4.             
  5.          if(pUserApi[accountid]   ==   NULL ){return;}
  6.         //认证码
  7.         CThostFtdcReqAuthenticateField  pReqAuthenticateField;
  8.         memset(&pReqAuthenticateField, 0, sizeof(CThostFtdcReqAuthenticateField));
  9.         strcpy(pReqAuthenticateField.BrokerID, BROKER_ID);
  10.         strcpy(pReqAuthenticateField.UserID, INVESTOR_ID);
  11.         strcpy(pReqAuthenticateField.UserProductInfo, UserProductInfo); //产品标识
  12.         strcpy(pReqAuthenticateField.AuthCode, AuthCode);  //认证码
  13.         int iResult = pUserApi[accountid]->ReqAuthenticate(&pReqAuthenticateField, ++iRequestID);
  14.          cerr << "--->>> 发送认证请求: " << ((iResult == 0) ? "成功" : "失败") << endl;
  15. }
复制代码


作者: 龙听    时间: 2020-2-29 07:27

欢迎加群交流:

加管理员微信备注:C++微信群  




欢迎光临 龙听期货论坛 (http://qhlt.club/) Powered by Discuz! 7.2