初步完成了LTS API的行情MD和交易TD封装,以及MD的测试脚本,LTS API版本20150115
This commit is contained in:
parent
50dd809ec7
commit
a9ff04a808
25
.gitignore
vendored
Normal file
25
.gitignore
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
# C++源代码
|
||||
ipch/
|
||||
Release/
|
||||
|
||||
*.sdf
|
||||
*.sln
|
||||
*.suo
|
||||
*.exp
|
||||
*.pdb
|
||||
*.filters
|
||||
*.vcxproj
|
||||
*.cd
|
||||
|
||||
# Python编译文件
|
||||
*.pyc
|
||||
|
||||
# WingIDE文件
|
||||
*.wpr
|
||||
*.wpu
|
||||
|
||||
# 压缩文件
|
||||
*.zip
|
||||
|
||||
# API的.con文件
|
||||
*.con
|
135
vn.lts/ltsapi/SecurityFtdcMdApi.h
Normal file
135
vn.lts/ltsapi/SecurityFtdcMdApi.h
Normal file
@ -0,0 +1,135 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
///@company shanghai liber information Technology Co.,Ltd
|
||||
///@file SecurityFtdcMdApi.h
|
||||
///@brief 定义客户端接口
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(SECURITY_FTDCMDAPI_H)
|
||||
#define SECURITY_FTDCMDAPI_H
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "SecurityFtdcUserApiStruct.h"
|
||||
|
||||
#if defined(ISLIB) && defined(WIN32)
|
||||
#ifdef LIB_MD_API_EXPORT
|
||||
#define MD_API_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define MD_API_EXPORT __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define MD_API_EXPORT
|
||||
#endif
|
||||
|
||||
class CSecurityFtdcMdSpi
|
||||
{
|
||||
public:
|
||||
///当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
|
||||
virtual void OnFrontConnected(){};
|
||||
|
||||
///当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
|
||||
///@param nReason 错误原因
|
||||
/// 0x1001 网络读失败
|
||||
/// 0x1002 网络写失败
|
||||
/// 0x2001 接收心跳超时
|
||||
/// 0x2002 发送心跳失败
|
||||
/// 0x2003 收到错误报文
|
||||
virtual void OnFrontDisconnected(int nReason){};
|
||||
|
||||
///心跳超时警告。当长时间未收到报文时,该方法被调用。
|
||||
///@param nTimeLapse 距离上次接收报文的时间
|
||||
virtual void OnHeartBeatWarning(int nTimeLapse){};
|
||||
|
||||
|
||||
///错误应答
|
||||
virtual void OnRspError(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///登录请求响应
|
||||
virtual void OnRspUserLogin(CSecurityFtdcRspUserLoginField *pRspUserLogin, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///登出请求响应
|
||||
virtual void OnRspUserLogout(CSecurityFtdcUserLogoutField *pUserLogout, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///订阅行情应答
|
||||
virtual void OnRspSubMarketData(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///取消订阅行情应答
|
||||
virtual void OnRspUnSubMarketData(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///深度行情通知
|
||||
virtual void OnRtnDepthMarketData(CSecurityFtdcDepthMarketDataField *pDepthMarketData) {};
|
||||
};
|
||||
|
||||
#ifndef WINDOWS
|
||||
#if __GNUC__ >= 4
|
||||
#pragma GCC visibility push(default)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
class MD_API_EXPORT CSecurityFtdcMdApi
|
||||
{
|
||||
public:
|
||||
///创建MdApi
|
||||
///@param pszFlowPath 存贮订阅信息文件的目录,默认为当前目录
|
||||
///@return 创建出的UserApi
|
||||
///modify for udp marketdata
|
||||
static CSecurityFtdcMdApi *CreateFtdcMdApi(const char *pszFlowPath = "");
|
||||
|
||||
///删除接口对象本身
|
||||
///@remark 不再使用本接口对象时,调用该函数删除接口对象
|
||||
virtual void Release() = 0;
|
||||
|
||||
///初始化
|
||||
///@remark 初始化运行环境,只有调用后,接口才开始工作
|
||||
virtual void Init() = 0;
|
||||
|
||||
///等待接口线程结束运行
|
||||
///@return 线程退出代码
|
||||
virtual int Join() = 0;
|
||||
|
||||
///获取当前交易日
|
||||
///@retrun 获取到的交易日
|
||||
///@remark 只有登录成功后,才能得到正确的交易日
|
||||
virtual const char *GetTradingDay() = 0;
|
||||
|
||||
///注册前置机网络地址
|
||||
///@param pszFrontAddress:前置机网络地址。
|
||||
///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:17001”。
|
||||
///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”17001”代表服务器端口号。
|
||||
virtual void RegisterFront(char *pszFrontAddress) = 0;
|
||||
|
||||
///注册回调接口
|
||||
///@param pSpi 派生自回调接口类的实例
|
||||
virtual void RegisterSpi(CSecurityFtdcMdSpi *pSpi) = 0;
|
||||
|
||||
///订阅行情。
|
||||
///@param ppInstrumentID 合约ID
|
||||
///@param nCount 要订阅/退订行情的合约个数
|
||||
///@remark
|
||||
virtual int SubscribeMarketData(char *ppInstrumentID[], int nCount, char* pExchageID) = 0;
|
||||
|
||||
///退订行情。
|
||||
///@param ppInstrumentID 合约ID
|
||||
///@param nCount 要订阅/退订行情的合约个数
|
||||
///@remark
|
||||
virtual int UnSubscribeMarketData(char *ppInstrumentID[], int nCount, char* pExchageID) = 0;
|
||||
|
||||
///用户登录请求
|
||||
virtual int ReqUserLogin(CSecurityFtdcReqUserLoginField *pReqUserLoginField, int nRequestID) = 0;
|
||||
|
||||
|
||||
///登出请求
|
||||
virtual int ReqUserLogout(CSecurityFtdcUserLogoutField *pUserLogout, int nRequestID) = 0;
|
||||
protected:
|
||||
~CSecurityFtdcMdApi(){};
|
||||
};
|
||||
|
||||
#ifndef WINDOWS
|
||||
#if __GNUC__ >= 4
|
||||
#pragma GCC visibility pop
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
299
vn.lts/ltsapi/SecurityFtdcTraderApi.h
Normal file
299
vn.lts/ltsapi/SecurityFtdcTraderApi.h
Normal file
@ -0,0 +1,299 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
///@company shanghai liber information Technology Co.,Ltd
|
||||
///@file SecurityFtdcTraderApi.h
|
||||
///@brief 定义客户端接口
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(SECURITY_FTDCTRADERAPI_H)
|
||||
#define SECURITY_FTDCTRADERAPI_H
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "SecurityFtdcUserApiStruct.h"
|
||||
|
||||
#if defined(ISLIB) && defined(WIN32)
|
||||
#ifdef LIB_TRADER_API_EXPORT
|
||||
#define TRADER_API_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define TRADER_API_EXPORT __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define TRADER_API_EXPORT
|
||||
#endif
|
||||
|
||||
class CSecurityFtdcTraderSpi
|
||||
{
|
||||
public:
|
||||
///当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
|
||||
virtual void OnFrontConnected(){};
|
||||
|
||||
///当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
|
||||
///@param nReason 错误原因
|
||||
/// 0x1001 网络读失败
|
||||
/// 0x1002 网络写失败
|
||||
/// 0x2001 接收心跳超时
|
||||
/// 0x2002 发送心跳失败
|
||||
/// 0x2003 收到错误报文
|
||||
virtual void OnFrontDisconnected(int nReason){};
|
||||
|
||||
///心跳超时警告。当长时间未收到报文时,该方法被调用。
|
||||
///@param nTimeLapse 距离上次接收报文的时间
|
||||
virtual void OnHeartBeatWarning(int nTimeLapse){};
|
||||
|
||||
///错误应答
|
||||
virtual void OnRspError(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///登录请求响应
|
||||
virtual void OnRspUserLogin(CSecurityFtdcRspUserLoginField *pRspUserLogin, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///登出请求响应
|
||||
virtual void OnRspUserLogout(CSecurityFtdcUserLogoutField *pUserLogout, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///报单录入请求响应
|
||||
virtual void OnRspOrderInsert(CSecurityFtdcInputOrderField *pInputOrder, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///报单操作请求响应
|
||||
virtual void OnRspOrderAction(CSecurityFtdcInputOrderActionField *pInputOrderAction, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///用户口令更新请求响应
|
||||
virtual void OnRspUserPasswordUpdate(CSecurityFtdcUserPasswordUpdateField *pUserPasswordUpdate, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///资金账户口令更新请求响应
|
||||
virtual void OnRspTradingAccountPasswordUpdate(CSecurityFtdcTradingAccountPasswordUpdateField *pTradingAccountPasswordUpdate, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询交易所响应
|
||||
virtual void OnRspQryExchange(CSecurityFtdcExchangeField *pExchange, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询合约响应
|
||||
virtual void OnRspQryInstrument(CSecurityFtdcInstrumentField *pInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询投资者响应
|
||||
virtual void OnRspQryInvestor(CSecurityFtdcInvestorField *pInvestor, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询交易编码响应
|
||||
virtual void OnRspQryTradingCode(CSecurityFtdcTradingCodeField *pTradingCode, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询资金账户响应
|
||||
virtual void OnRspQryTradingAccount(CSecurityFtdcTradingAccountField *pTradingAccount, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询行情响应
|
||||
virtual void OnRspQryDepthMarketData(CSecurityFtdcDepthMarketDataField *pDepthMarketData, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询债券利息响应
|
||||
virtual void OnRspQryBondInterest(CSecurityFtdcBondInterestField *pBondInterest, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询市值配售信息响应
|
||||
virtual void OnRspQryMarketRationInfo(CSecurityFtdcMarketRationInfoField *pMarketRationInfo, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询合约手续费率响应
|
||||
virtual void OnRspQryInstrumentCommissionRate(CSecurityFtdcInstrumentCommissionRateField *pInstrumentCommissionRate, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询ETF合约响应
|
||||
virtual void OnRspQryETFInstrument(CSecurityFtdcETFInstrumentField *pETFInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询ETF股票篮响应
|
||||
virtual void OnRspQryETFBasket(CSecurityFtdcETFBasketField *pETFBasket, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询OF合约响应
|
||||
virtual void OnRspQryOFInstrument(CSecurityFtdcOFInstrumentField *pOFInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询SF合约响应
|
||||
virtual void OnRspQrySFInstrument(CSecurityFtdcSFInstrumentField *pSFInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询报单响应
|
||||
virtual void OnRspQryOrder(CSecurityFtdcOrderField *pOrder, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询成交响应
|
||||
virtual void OnRspQryTrade(CSecurityFtdcTradeField *pTrade, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询投资者持仓响应
|
||||
virtual void OnRspQryInvestorPosition(CSecurityFtdcInvestorPositionField *pInvestorPosition, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///报单通知
|
||||
virtual void OnRtnOrder(CSecurityFtdcOrderField *pOrder) {};
|
||||
|
||||
///成交通知
|
||||
virtual void OnRtnTrade(CSecurityFtdcTradeField *pTrade) {};
|
||||
|
||||
///报单录入错误回报
|
||||
virtual void OnErrRtnOrderInsert(CSecurityFtdcInputOrderField *pInputOrder, CSecurityFtdcRspInfoField *pRspInfo) {};
|
||||
|
||||
///报单操作错误回报
|
||||
virtual void OnErrRtnOrderAction(CSecurityFtdcOrderActionField *pOrderAction, CSecurityFtdcRspInfoField *pRspInfo) {};
|
||||
|
||||
///Liber发起出金应答
|
||||
virtual void OnRspFundOutByLiber(CSecurityFtdcInputFundTransferField *pInputFundTransfer, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///Liber发起出金通知
|
||||
virtual void OnRtnFundOutByLiber(CSecurityFtdcFundTransferField *pFundTransfer) {};
|
||||
|
||||
///Liber发起出金错误回报
|
||||
virtual void OnErrRtnFundOutByLiber(CSecurityFtdcInputFundTransferField *pInputFundTransfer, CSecurityFtdcRspInfoField *pRspInfo) {};
|
||||
|
||||
///银行发起入金通知
|
||||
virtual void OnRtnFundInByBank(CSecurityFtdcFundTransferField *pFundTransfer) {};
|
||||
|
||||
///资金转账查询应答
|
||||
virtual void OnRspQryFundTransferSerial(CSecurityFtdcFundTransferField *pFundTransfer, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///资金内转应答
|
||||
virtual void OnRspFundInterTransfer(CSecurityFtdcFundInterTransferField *pFundInterTransfer, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///资金内转流水查询应答
|
||||
virtual void OnRspQryFundInterTransferSerial(CSecurityFtdcFundInterTransferSerialField *pFundInterTransferSerial, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///资金内转流水通知
|
||||
virtual void OnRtnFundInterTransferSerial(CSecurityFtdcFundInterTransferSerialField *pFundInterTransferSerial) {};
|
||||
|
||||
///资金内转错误回报
|
||||
virtual void OnErrRtnFundInterTransfer(CSecurityFtdcFundInterTransferField *pFundInterTransfer, CSecurityFtdcRspInfoField *pRspInfo) {};
|
||||
};
|
||||
|
||||
#ifndef WINDOWS
|
||||
#if __GNUC__ >= 4
|
||||
#pragma GCC visibility push(default)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
class TRADER_API_EXPORT CSecurityFtdcTraderApi
|
||||
{
|
||||
public:
|
||||
///创建TraderApi
|
||||
///@param pszFlowPath 存贮订阅信息文件的目录,默认为当前目录
|
||||
///@return 创建出的UserApi
|
||||
static CSecurityFtdcTraderApi *CreateFtdcTraderApi(const char *pszFlowPath = "");
|
||||
|
||||
///删除接口对象本身
|
||||
///@remark 不再使用本接口对象时,调用该函数删除接口对象
|
||||
virtual void Release() = 0;
|
||||
|
||||
///初始化
|
||||
///@remark 初始化运行环境,只有调用后,接口才开始工作
|
||||
virtual void Init() = 0;
|
||||
|
||||
///等待接口线程结束运行
|
||||
///@return 线程退出代码
|
||||
virtual int Join() = 0;
|
||||
|
||||
///获取当前交易日
|
||||
///@retrun 获取到的交易日
|
||||
///@remark 只有登录成功后,才能得到正确的交易日
|
||||
virtual const char *GetTradingDay() = 0;
|
||||
|
||||
///注册前置机网络地址
|
||||
///@param pszFrontAddress:前置机网络地址。
|
||||
///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:17001”。
|
||||
///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”17001”代表服务器端口号。
|
||||
virtual void RegisterFront(char *pszFrontAddress) = 0;
|
||||
|
||||
///注册回调接口
|
||||
///@param pSpi 派生自回调接口类的实例
|
||||
virtual void RegisterSpi(CSecurityFtdcTraderSpi *pSpi) = 0;
|
||||
|
||||
///订阅私有流。
|
||||
///@param nResumeType 私有流重传方式
|
||||
/// SECURITY_TERT_RESTART:从本交易日开始重传
|
||||
/// SECURITY_TERT_RESUME:从上次收到的续传
|
||||
/// SECURITY_TERT_QUICK:只传送登录后私有流的内容
|
||||
///@remark 该方法要在Init方法前调用。若不调用则不会收到私有流的数据。
|
||||
virtual void SubscribePrivateTopic(SECURITY_TE_RESUME_TYPE nResumeType) = 0;
|
||||
|
||||
///订阅公共流。
|
||||
///@param nResumeType 公共流重传方式
|
||||
/// SECURITY_TERT_RESTART:从本交易日开始重传
|
||||
/// SECURITY_TERT_RESUME:从上次收到的续传
|
||||
/// SECURITY_TERT_QUICK:只传送登录后公共流的内容
|
||||
///@remark 该方法要在Init方法前调用。若不调用则不会收到公共流的数据。
|
||||
virtual void SubscribePublicTopic(SECURITY_TE_RESUME_TYPE nResumeType) = 0;
|
||||
|
||||
///用户登录请求
|
||||
virtual int ReqUserLogin(CSecurityFtdcReqUserLoginField *pReqUserLoginField, int nRequestID) = 0;
|
||||
|
||||
|
||||
///登出请求
|
||||
virtual int ReqUserLogout(CSecurityFtdcUserLogoutField *pUserLogout, int nRequestID) = 0;
|
||||
|
||||
///报单录入请求
|
||||
virtual int ReqOrderInsert(CSecurityFtdcInputOrderField *pInputOrder, int nRequestID) = 0;
|
||||
|
||||
///报单操作请求
|
||||
virtual int ReqOrderAction(CSecurityFtdcInputOrderActionField *pInputOrderAction, int nRequestID) = 0;
|
||||
|
||||
///用户口令更新请求
|
||||
virtual int ReqUserPasswordUpdate(CSecurityFtdcUserPasswordUpdateField *pUserPasswordUpdate, int nRequestID) = 0;
|
||||
|
||||
///资金账户口令更新请求
|
||||
virtual int ReqTradingAccountPasswordUpdate(CSecurityFtdcTradingAccountPasswordUpdateField *pTradingAccountPasswordUpdate, int nRequestID) = 0;
|
||||
|
||||
///请求查询交易所
|
||||
virtual int ReqQryExchange(CSecurityFtdcQryExchangeField *pQryExchange, int nRequestID) = 0;
|
||||
|
||||
///请求查询合约
|
||||
virtual int ReqQryInstrument(CSecurityFtdcQryInstrumentField *pQryInstrument, int nRequestID) = 0;
|
||||
|
||||
///请求查询投资者
|
||||
virtual int ReqQryInvestor(CSecurityFtdcQryInvestorField *pQryInvestor, int nRequestID) = 0;
|
||||
|
||||
///请求查询交易编码
|
||||
virtual int ReqQryTradingCode(CSecurityFtdcQryTradingCodeField *pQryTradingCode, int nRequestID) = 0;
|
||||
|
||||
///请求查询资金账户
|
||||
virtual int ReqQryTradingAccount(CSecurityFtdcQryTradingAccountField *pQryTradingAccount, int nRequestID) = 0;
|
||||
|
||||
///请求查询行情
|
||||
virtual int ReqQryDepthMarketData(CSecurityFtdcQryDepthMarketDataField *pQryDepthMarketData, int nRequestID) = 0;
|
||||
|
||||
///请求查询债券利息
|
||||
virtual int ReqQryBondInterest(CSecurityFtdcQryBondInterestField *pQryBondInterest, int nRequestID) = 0;
|
||||
|
||||
///请求查询市值配售信息
|
||||
virtual int ReqQryMarketRationInfo(CSecurityFtdcQryMarketRationInfoField *pQryMarketRationInfo, int nRequestID) = 0;
|
||||
|
||||
///请求查询合约手续费率
|
||||
virtual int ReqQryInstrumentCommissionRate(CSecurityFtdcQryInstrumentCommissionRateField *pQryInstrumentCommissionRate, int nRequestID) = 0;
|
||||
|
||||
///请求查询ETF合约
|
||||
virtual int ReqQryETFInstrument(CSecurityFtdcQryETFInstrumentField *pQryETFInstrument, int nRequestID) = 0;
|
||||
|
||||
///请求查询ETF股票篮
|
||||
virtual int ReqQryETFBasket(CSecurityFtdcQryETFBasketField *pQryETFBasket, int nRequestID) = 0;
|
||||
|
||||
///请求查询OF合约
|
||||
virtual int ReqQryOFInstrument(CSecurityFtdcQryOFInstrumentField *pQryOFInstrument, int nRequestID) = 0;
|
||||
|
||||
///请求查询SF合约
|
||||
virtual int ReqQrySFInstrument(CSecurityFtdcQrySFInstrumentField *pQrySFInstrument, int nRequestID) = 0;
|
||||
|
||||
///请求查询报单
|
||||
virtual int ReqQryOrder(CSecurityFtdcQryOrderField *pQryOrder, int nRequestID) = 0;
|
||||
|
||||
///请求查询成交
|
||||
virtual int ReqQryTrade(CSecurityFtdcQryTradeField *pQryTrade, int nRequestID) = 0;
|
||||
|
||||
///请求查询投资者持仓
|
||||
virtual int ReqQryInvestorPosition(CSecurityFtdcQryInvestorPositionField *pQryInvestorPosition, int nRequestID) = 0;
|
||||
|
||||
///Liber发起出金请求
|
||||
virtual int ReqFundOutByLiber(CSecurityFtdcInputFundTransferField *pInputFundTransfer, int nRequestID) = 0;
|
||||
|
||||
///资金转账查询请求
|
||||
virtual int ReqQryFundTransferSerial(CSecurityFtdcQryFundTransferSerialField *pQryFundTransferSerial, int nRequestID) = 0;
|
||||
|
||||
///资金内转请求
|
||||
virtual int ReqFundInterTransfer(CSecurityFtdcFundInterTransferField *pFundInterTransfer, int nRequestID) = 0;
|
||||
|
||||
///资金内转流水查询请求
|
||||
virtual int ReqQryFundInterTransferSerial(CSecurityFtdcQryFundInterTransferSerialField *pQryFundInterTransferSerial, int nRequestID) = 0;
|
||||
protected:
|
||||
~CSecurityFtdcTraderApi(){};
|
||||
};
|
||||
|
||||
#ifndef WINDOWS
|
||||
#if __GNUC__ >= 4
|
||||
#pragma GCC visibility pop
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
2080
vn.lts/ltsapi/SecurityFtdcUserApiDataType.h
Normal file
2080
vn.lts/ltsapi/SecurityFtdcUserApiDataType.h
Normal file
File diff suppressed because it is too large
Load Diff
2312
vn.lts/ltsapi/SecurityFtdcUserApiStruct.h
Normal file
2312
vn.lts/ltsapi/SecurityFtdcUserApiStruct.h
Normal file
File diff suppressed because it is too large
Load Diff
BIN
vn.lts/ltsapi/securitymduserapi.dll
Normal file
BIN
vn.lts/ltsapi/securitymduserapi.dll
Normal file
Binary file not shown.
BIN
vn.lts/ltsapi/securitymduserapi.lib
Normal file
BIN
vn.lts/ltsapi/securitymduserapi.lib
Normal file
Binary file not shown.
BIN
vn.lts/ltsapi/securitymduserapi.so
Normal file
BIN
vn.lts/ltsapi/securitymduserapi.so
Normal file
Binary file not shown.
BIN
vn.lts/ltsapi/securitytraderapi.dll
Normal file
BIN
vn.lts/ltsapi/securitytraderapi.dll
Normal file
Binary file not shown.
BIN
vn.lts/ltsapi/securitytraderapi.lib
Normal file
BIN
vn.lts/ltsapi/securitytraderapi.lib
Normal file
Binary file not shown.
BIN
vn.lts/ltsapi/securitytraderapi.so
Normal file
BIN
vn.lts/ltsapi/securitytraderapi.so
Normal file
Binary file not shown.
135
vn.lts/pyscript/SecurityFtdcMdApi.h
Normal file
135
vn.lts/pyscript/SecurityFtdcMdApi.h
Normal file
@ -0,0 +1,135 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
///@company shanghai liber information Technology Co.,Ltd
|
||||
///@file SecurityFtdcMdApi.h
|
||||
///@brief 定义客户端接口
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(SECURITY_FTDCMDAPI_H)
|
||||
#define SECURITY_FTDCMDAPI_H
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "SecurityFtdcUserApiStruct.h"
|
||||
|
||||
#if defined(ISLIB) && defined(WIN32)
|
||||
#ifdef LIB_MD_API_EXPORT
|
||||
#define MD_API_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define MD_API_EXPORT __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define MD_API_EXPORT
|
||||
#endif
|
||||
|
||||
class CSecurityFtdcMdSpi
|
||||
{
|
||||
public:
|
||||
///当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
|
||||
virtual void OnFrontConnected(){};
|
||||
|
||||
///当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
|
||||
///@param nReason 错误原因
|
||||
/// 0x1001 网络读失败
|
||||
/// 0x1002 网络写失败
|
||||
/// 0x2001 接收心跳超时
|
||||
/// 0x2002 发送心跳失败
|
||||
/// 0x2003 收到错误报文
|
||||
virtual void OnFrontDisconnected(int nReason){};
|
||||
|
||||
///心跳超时警告。当长时间未收到报文时,该方法被调用。
|
||||
///@param nTimeLapse 距离上次接收报文的时间
|
||||
virtual void OnHeartBeatWarning(int nTimeLapse){};
|
||||
|
||||
|
||||
///错误应答
|
||||
virtual void OnRspError(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///登录请求响应
|
||||
virtual void OnRspUserLogin(CSecurityFtdcRspUserLoginField *pRspUserLogin, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///登出请求响应
|
||||
virtual void OnRspUserLogout(CSecurityFtdcUserLogoutField *pUserLogout, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///订阅行情应答
|
||||
virtual void OnRspSubMarketData(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///取消订阅行情应答
|
||||
virtual void OnRspUnSubMarketData(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///深度行情通知
|
||||
virtual void OnRtnDepthMarketData(CSecurityFtdcDepthMarketDataField *pDepthMarketData) {};
|
||||
};
|
||||
|
||||
#ifndef WINDOWS
|
||||
#if __GNUC__ >= 4
|
||||
#pragma GCC visibility push(default)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
class MD_API_EXPORT CSecurityFtdcMdApi
|
||||
{
|
||||
public:
|
||||
///创建MdApi
|
||||
///@param pszFlowPath 存贮订阅信息文件的目录,默认为当前目录
|
||||
///@return 创建出的UserApi
|
||||
///modify for udp marketdata
|
||||
static CSecurityFtdcMdApi *CreateFtdcMdApi(const char *pszFlowPath = "");
|
||||
|
||||
///删除接口对象本身
|
||||
///@remark 不再使用本接口对象时,调用该函数删除接口对象
|
||||
virtual void Release() = 0;
|
||||
|
||||
///初始化
|
||||
///@remark 初始化运行环境,只有调用后,接口才开始工作
|
||||
virtual void Init() = 0;
|
||||
|
||||
///等待接口线程结束运行
|
||||
///@return 线程退出代码
|
||||
virtual int Join() = 0;
|
||||
|
||||
///获取当前交易日
|
||||
///@retrun 获取到的交易日
|
||||
///@remark 只有登录成功后,才能得到正确的交易日
|
||||
virtual const char *GetTradingDay() = 0;
|
||||
|
||||
///注册前置机网络地址
|
||||
///@param pszFrontAddress:前置机网络地址。
|
||||
///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:17001”。
|
||||
///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”17001”代表服务器端口号。
|
||||
virtual void RegisterFront(char *pszFrontAddress) = 0;
|
||||
|
||||
///注册回调接口
|
||||
///@param pSpi 派生自回调接口类的实例
|
||||
virtual void RegisterSpi(CSecurityFtdcMdSpi *pSpi) = 0;
|
||||
|
||||
///订阅行情。
|
||||
///@param ppInstrumentID 合约ID
|
||||
///@param nCount 要订阅/退订行情的合约个数
|
||||
///@remark
|
||||
virtual int SubscribeMarketData(char *ppInstrumentID[], int nCount, char* pExchageID) = 0;
|
||||
|
||||
///退订行情。
|
||||
///@param ppInstrumentID 合约ID
|
||||
///@param nCount 要订阅/退订行情的合约个数
|
||||
///@remark
|
||||
virtual int UnSubscribeMarketData(char *ppInstrumentID[], int nCount, char* pExchageID) = 0;
|
||||
|
||||
///用户登录请求
|
||||
virtual int ReqUserLogin(CSecurityFtdcReqUserLoginField *pReqUserLoginField, int nRequestID) = 0;
|
||||
|
||||
|
||||
///登出请求
|
||||
virtual int ReqUserLogout(CSecurityFtdcUserLogoutField *pUserLogout, int nRequestID) = 0;
|
||||
protected:
|
||||
~CSecurityFtdcMdApi(){};
|
||||
};
|
||||
|
||||
#ifndef WINDOWS
|
||||
#if __GNUC__ >= 4
|
||||
#pragma GCC visibility pop
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
299
vn.lts/pyscript/SecurityFtdcTraderApi.h
Normal file
299
vn.lts/pyscript/SecurityFtdcTraderApi.h
Normal file
@ -0,0 +1,299 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
///@company shanghai liber information Technology Co.,Ltd
|
||||
///@file SecurityFtdcTraderApi.h
|
||||
///@brief 定义客户端接口
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(SECURITY_FTDCTRADERAPI_H)
|
||||
#define SECURITY_FTDCTRADERAPI_H
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "SecurityFtdcUserApiStruct.h"
|
||||
|
||||
#if defined(ISLIB) && defined(WIN32)
|
||||
#ifdef LIB_TRADER_API_EXPORT
|
||||
#define TRADER_API_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define TRADER_API_EXPORT __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define TRADER_API_EXPORT
|
||||
#endif
|
||||
|
||||
class CSecurityFtdcTraderSpi
|
||||
{
|
||||
public:
|
||||
///当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
|
||||
virtual void OnFrontConnected(){};
|
||||
|
||||
///当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
|
||||
///@param nReason 错误原因
|
||||
/// 0x1001 网络读失败
|
||||
/// 0x1002 网络写失败
|
||||
/// 0x2001 接收心跳超时
|
||||
/// 0x2002 发送心跳失败
|
||||
/// 0x2003 收到错误报文
|
||||
virtual void OnFrontDisconnected(int nReason){};
|
||||
|
||||
///心跳超时警告。当长时间未收到报文时,该方法被调用。
|
||||
///@param nTimeLapse 距离上次接收报文的时间
|
||||
virtual void OnHeartBeatWarning(int nTimeLapse){};
|
||||
|
||||
///错误应答
|
||||
virtual void OnRspError(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///登录请求响应
|
||||
virtual void OnRspUserLogin(CSecurityFtdcRspUserLoginField *pRspUserLogin, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///登出请求响应
|
||||
virtual void OnRspUserLogout(CSecurityFtdcUserLogoutField *pUserLogout, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///报单录入请求响应
|
||||
virtual void OnRspOrderInsert(CSecurityFtdcInputOrderField *pInputOrder, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///报单操作请求响应
|
||||
virtual void OnRspOrderAction(CSecurityFtdcInputOrderActionField *pInputOrderAction, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///用户口令更新请求响应
|
||||
virtual void OnRspUserPasswordUpdate(CSecurityFtdcUserPasswordUpdateField *pUserPasswordUpdate, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///资金账户口令更新请求响应
|
||||
virtual void OnRspTradingAccountPasswordUpdate(CSecurityFtdcTradingAccountPasswordUpdateField *pTradingAccountPasswordUpdate, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询交易所响应
|
||||
virtual void OnRspQryExchange(CSecurityFtdcExchangeField *pExchange, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询合约响应
|
||||
virtual void OnRspQryInstrument(CSecurityFtdcInstrumentField *pInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询投资者响应
|
||||
virtual void OnRspQryInvestor(CSecurityFtdcInvestorField *pInvestor, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询交易编码响应
|
||||
virtual void OnRspQryTradingCode(CSecurityFtdcTradingCodeField *pTradingCode, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询资金账户响应
|
||||
virtual void OnRspQryTradingAccount(CSecurityFtdcTradingAccountField *pTradingAccount, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询行情响应
|
||||
virtual void OnRspQryDepthMarketData(CSecurityFtdcDepthMarketDataField *pDepthMarketData, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询债券利息响应
|
||||
virtual void OnRspQryBondInterest(CSecurityFtdcBondInterestField *pBondInterest, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询市值配售信息响应
|
||||
virtual void OnRspQryMarketRationInfo(CSecurityFtdcMarketRationInfoField *pMarketRationInfo, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询合约手续费率响应
|
||||
virtual void OnRspQryInstrumentCommissionRate(CSecurityFtdcInstrumentCommissionRateField *pInstrumentCommissionRate, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询ETF合约响应
|
||||
virtual void OnRspQryETFInstrument(CSecurityFtdcETFInstrumentField *pETFInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询ETF股票篮响应
|
||||
virtual void OnRspQryETFBasket(CSecurityFtdcETFBasketField *pETFBasket, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询OF合约响应
|
||||
virtual void OnRspQryOFInstrument(CSecurityFtdcOFInstrumentField *pOFInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询SF合约响应
|
||||
virtual void OnRspQrySFInstrument(CSecurityFtdcSFInstrumentField *pSFInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询报单响应
|
||||
virtual void OnRspQryOrder(CSecurityFtdcOrderField *pOrder, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询成交响应
|
||||
virtual void OnRspQryTrade(CSecurityFtdcTradeField *pTrade, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///请求查询投资者持仓响应
|
||||
virtual void OnRspQryInvestorPosition(CSecurityFtdcInvestorPositionField *pInvestorPosition, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///报单通知
|
||||
virtual void OnRtnOrder(CSecurityFtdcOrderField *pOrder) {};
|
||||
|
||||
///成交通知
|
||||
virtual void OnRtnTrade(CSecurityFtdcTradeField *pTrade) {};
|
||||
|
||||
///报单录入错误回报
|
||||
virtual void OnErrRtnOrderInsert(CSecurityFtdcInputOrderField *pInputOrder, CSecurityFtdcRspInfoField *pRspInfo) {};
|
||||
|
||||
///报单操作错误回报
|
||||
virtual void OnErrRtnOrderAction(CSecurityFtdcOrderActionField *pOrderAction, CSecurityFtdcRspInfoField *pRspInfo) {};
|
||||
|
||||
///Liber发起出金应答
|
||||
virtual void OnRspFundOutByLiber(CSecurityFtdcInputFundTransferField *pInputFundTransfer, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///Liber发起出金通知
|
||||
virtual void OnRtnFundOutByLiber(CSecurityFtdcFundTransferField *pFundTransfer) {};
|
||||
|
||||
///Liber发起出金错误回报
|
||||
virtual void OnErrRtnFundOutByLiber(CSecurityFtdcInputFundTransferField *pInputFundTransfer, CSecurityFtdcRspInfoField *pRspInfo) {};
|
||||
|
||||
///银行发起入金通知
|
||||
virtual void OnRtnFundInByBank(CSecurityFtdcFundTransferField *pFundTransfer) {};
|
||||
|
||||
///资金转账查询应答
|
||||
virtual void OnRspQryFundTransferSerial(CSecurityFtdcFundTransferField *pFundTransfer, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///资金内转应答
|
||||
virtual void OnRspFundInterTransfer(CSecurityFtdcFundInterTransferField *pFundInterTransfer, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///资金内转流水查询应答
|
||||
virtual void OnRspQryFundInterTransferSerial(CSecurityFtdcFundInterTransferSerialField *pFundInterTransferSerial, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {};
|
||||
|
||||
///资金内转流水通知
|
||||
virtual void OnRtnFundInterTransferSerial(CSecurityFtdcFundInterTransferSerialField *pFundInterTransferSerial) {};
|
||||
|
||||
///资金内转错误回报
|
||||
virtual void OnErrRtnFundInterTransfer(CSecurityFtdcFundInterTransferField *pFundInterTransfer, CSecurityFtdcRspInfoField *pRspInfo) {};
|
||||
};
|
||||
|
||||
#ifndef WINDOWS
|
||||
#if __GNUC__ >= 4
|
||||
#pragma GCC visibility push(default)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
class TRADER_API_EXPORT CSecurityFtdcTraderApi
|
||||
{
|
||||
public:
|
||||
///创建TraderApi
|
||||
///@param pszFlowPath 存贮订阅信息文件的目录,默认为当前目录
|
||||
///@return 创建出的UserApi
|
||||
static CSecurityFtdcTraderApi *CreateFtdcTraderApi(const char *pszFlowPath = "");
|
||||
|
||||
///删除接口对象本身
|
||||
///@remark 不再使用本接口对象时,调用该函数删除接口对象
|
||||
virtual void Release() = 0;
|
||||
|
||||
///初始化
|
||||
///@remark 初始化运行环境,只有调用后,接口才开始工作
|
||||
virtual void Init() = 0;
|
||||
|
||||
///等待接口线程结束运行
|
||||
///@return 线程退出代码
|
||||
virtual int Join() = 0;
|
||||
|
||||
///获取当前交易日
|
||||
///@retrun 获取到的交易日
|
||||
///@remark 只有登录成功后,才能得到正确的交易日
|
||||
virtual const char *GetTradingDay() = 0;
|
||||
|
||||
///注册前置机网络地址
|
||||
///@param pszFrontAddress:前置机网络地址。
|
||||
///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:17001”。
|
||||
///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”17001”代表服务器端口号。
|
||||
virtual void RegisterFront(char *pszFrontAddress) = 0;
|
||||
|
||||
///注册回调接口
|
||||
///@param pSpi 派生自回调接口类的实例
|
||||
virtual void RegisterSpi(CSecurityFtdcTraderSpi *pSpi) = 0;
|
||||
|
||||
///订阅私有流。
|
||||
///@param nResumeType 私有流重传方式
|
||||
/// SECURITY_TERT_RESTART:从本交易日开始重传
|
||||
/// SECURITY_TERT_RESUME:从上次收到的续传
|
||||
/// SECURITY_TERT_QUICK:只传送登录后私有流的内容
|
||||
///@remark 该方法要在Init方法前调用。若不调用则不会收到私有流的数据。
|
||||
virtual void SubscribePrivateTopic(SECURITY_TE_RESUME_TYPE nResumeType) = 0;
|
||||
|
||||
///订阅公共流。
|
||||
///@param nResumeType 公共流重传方式
|
||||
/// SECURITY_TERT_RESTART:从本交易日开始重传
|
||||
/// SECURITY_TERT_RESUME:从上次收到的续传
|
||||
/// SECURITY_TERT_QUICK:只传送登录后公共流的内容
|
||||
///@remark 该方法要在Init方法前调用。若不调用则不会收到公共流的数据。
|
||||
virtual void SubscribePublicTopic(SECURITY_TE_RESUME_TYPE nResumeType) = 0;
|
||||
|
||||
///用户登录请求
|
||||
virtual int ReqUserLogin(CSecurityFtdcReqUserLoginField *pReqUserLoginField, int nRequestID) = 0;
|
||||
|
||||
|
||||
///登出请求
|
||||
virtual int ReqUserLogout(CSecurityFtdcUserLogoutField *pUserLogout, int nRequestID) = 0;
|
||||
|
||||
///报单录入请求
|
||||
virtual int ReqOrderInsert(CSecurityFtdcInputOrderField *pInputOrder, int nRequestID) = 0;
|
||||
|
||||
///报单操作请求
|
||||
virtual int ReqOrderAction(CSecurityFtdcInputOrderActionField *pInputOrderAction, int nRequestID) = 0;
|
||||
|
||||
///用户口令更新请求
|
||||
virtual int ReqUserPasswordUpdate(CSecurityFtdcUserPasswordUpdateField *pUserPasswordUpdate, int nRequestID) = 0;
|
||||
|
||||
///资金账户口令更新请求
|
||||
virtual int ReqTradingAccountPasswordUpdate(CSecurityFtdcTradingAccountPasswordUpdateField *pTradingAccountPasswordUpdate, int nRequestID) = 0;
|
||||
|
||||
///请求查询交易所
|
||||
virtual int ReqQryExchange(CSecurityFtdcQryExchangeField *pQryExchange, int nRequestID) = 0;
|
||||
|
||||
///请求查询合约
|
||||
virtual int ReqQryInstrument(CSecurityFtdcQryInstrumentField *pQryInstrument, int nRequestID) = 0;
|
||||
|
||||
///请求查询投资者
|
||||
virtual int ReqQryInvestor(CSecurityFtdcQryInvestorField *pQryInvestor, int nRequestID) = 0;
|
||||
|
||||
///请求查询交易编码
|
||||
virtual int ReqQryTradingCode(CSecurityFtdcQryTradingCodeField *pQryTradingCode, int nRequestID) = 0;
|
||||
|
||||
///请求查询资金账户
|
||||
virtual int ReqQryTradingAccount(CSecurityFtdcQryTradingAccountField *pQryTradingAccount, int nRequestID) = 0;
|
||||
|
||||
///请求查询行情
|
||||
virtual int ReqQryDepthMarketData(CSecurityFtdcQryDepthMarketDataField *pQryDepthMarketData, int nRequestID) = 0;
|
||||
|
||||
///请求查询债券利息
|
||||
virtual int ReqQryBondInterest(CSecurityFtdcQryBondInterestField *pQryBondInterest, int nRequestID) = 0;
|
||||
|
||||
///请求查询市值配售信息
|
||||
virtual int ReqQryMarketRationInfo(CSecurityFtdcQryMarketRationInfoField *pQryMarketRationInfo, int nRequestID) = 0;
|
||||
|
||||
///请求查询合约手续费率
|
||||
virtual int ReqQryInstrumentCommissionRate(CSecurityFtdcQryInstrumentCommissionRateField *pQryInstrumentCommissionRate, int nRequestID) = 0;
|
||||
|
||||
///请求查询ETF合约
|
||||
virtual int ReqQryETFInstrument(CSecurityFtdcQryETFInstrumentField *pQryETFInstrument, int nRequestID) = 0;
|
||||
|
||||
///请求查询ETF股票篮
|
||||
virtual int ReqQryETFBasket(CSecurityFtdcQryETFBasketField *pQryETFBasket, int nRequestID) = 0;
|
||||
|
||||
///请求查询OF合约
|
||||
virtual int ReqQryOFInstrument(CSecurityFtdcQryOFInstrumentField *pQryOFInstrument, int nRequestID) = 0;
|
||||
|
||||
///请求查询SF合约
|
||||
virtual int ReqQrySFInstrument(CSecurityFtdcQrySFInstrumentField *pQrySFInstrument, int nRequestID) = 0;
|
||||
|
||||
///请求查询报单
|
||||
virtual int ReqQryOrder(CSecurityFtdcQryOrderField *pQryOrder, int nRequestID) = 0;
|
||||
|
||||
///请求查询成交
|
||||
virtual int ReqQryTrade(CSecurityFtdcQryTradeField *pQryTrade, int nRequestID) = 0;
|
||||
|
||||
///请求查询投资者持仓
|
||||
virtual int ReqQryInvestorPosition(CSecurityFtdcQryInvestorPositionField *pQryInvestorPosition, int nRequestID) = 0;
|
||||
|
||||
///Liber发起出金请求
|
||||
virtual int ReqFundOutByLiber(CSecurityFtdcInputFundTransferField *pInputFundTransfer, int nRequestID) = 0;
|
||||
|
||||
///资金转账查询请求
|
||||
virtual int ReqQryFundTransferSerial(CSecurityFtdcQryFundTransferSerialField *pQryFundTransferSerial, int nRequestID) = 0;
|
||||
|
||||
///资金内转请求
|
||||
virtual int ReqFundInterTransfer(CSecurityFtdcFundInterTransferField *pFundInterTransfer, int nRequestID) = 0;
|
||||
|
||||
///资金内转流水查询请求
|
||||
virtual int ReqQryFundInterTransferSerial(CSecurityFtdcQryFundInterTransferSerialField *pQryFundInterTransferSerial, int nRequestID) = 0;
|
||||
protected:
|
||||
~CSecurityFtdcTraderApi(){};
|
||||
};
|
||||
|
||||
#ifndef WINDOWS
|
||||
#if __GNUC__ >= 4
|
||||
#pragma GCC visibility pop
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
2080
vn.lts/pyscript/SecurityFtdcUserApiDataType.h
Normal file
2080
vn.lts/pyscript/SecurityFtdcUserApiDataType.h
Normal file
File diff suppressed because it is too large
Load Diff
2312
vn.lts/pyscript/SecurityFtdcUserApiStruct.h
Normal file
2312
vn.lts/pyscript/SecurityFtdcUserApiStruct.h
Normal file
File diff suppressed because it is too large
Load Diff
98
vn.lts/pyscript/generate_data_type.py
Normal file
98
vn.lts/pyscript/generate_data_type.py
Normal file
@ -0,0 +1,98 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
__author__ = 'CHENXY'
|
||||
|
||||
# C++和python类型的映射字典
|
||||
type_dict = {
|
||||
'int': 'int',
|
||||
'char': 'string',
|
||||
'double': 'float',
|
||||
'short': 'int'
|
||||
}
|
||||
|
||||
|
||||
def process_line(line):
|
||||
"""处理每行"""
|
||||
if '///' in line: # 注释
|
||||
py_line = process_comment(line)
|
||||
elif 'typedef' in line: # 类型申明
|
||||
py_line = process_typedef(line)
|
||||
elif '#define' in line: # 定义常量
|
||||
py_line = process_define(line)
|
||||
elif line == '\n': # 空行
|
||||
py_line = line
|
||||
else:
|
||||
py_line = ''
|
||||
|
||||
return py_line
|
||||
|
||||
|
||||
def process_comment(line):
|
||||
"""处理注释"""
|
||||
# if line[3] == '/':
|
||||
# py_line = ''
|
||||
# else:
|
||||
# py_line = '#' + line[3:]
|
||||
py_line = '#' + line[3:]
|
||||
return py_line
|
||||
|
||||
|
||||
def process_typedef(line):
|
||||
"""处理类型申明"""
|
||||
content = line.split(' ')
|
||||
type_ = type_dict[content[1]]
|
||||
|
||||
keyword = content[2]
|
||||
if '[' in keyword:
|
||||
i = keyword.index('[')
|
||||
keyword = keyword[:i]
|
||||
else:
|
||||
keyword = keyword.replace(';\n', '') # 删除行末分号
|
||||
|
||||
py_line = 'typedefDict["%s"] = "%s"\n' % (keyword, type_)
|
||||
|
||||
return py_line
|
||||
|
||||
|
||||
def process_define(line):
|
||||
"""处理定义常量"""
|
||||
content = line.split(' ')
|
||||
constant = content[1]
|
||||
|
||||
if len(content)>2:
|
||||
value = content[-1]
|
||||
py_line = 'defineDict["%s"] = %s' % (constant, value)
|
||||
else:
|
||||
py_line = ''
|
||||
|
||||
return py_line
|
||||
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
try:
|
||||
fcpp = open('SecurityFtdcUserApiDataType.h','r')
|
||||
fpy = open('lts_data_type.py', 'w')
|
||||
|
||||
fpy.write('# encoding: UTF-8\n')
|
||||
fpy.write('\n')
|
||||
fpy.write('defineDict = {}\n')
|
||||
fpy.write('typedefDict = {}\n')
|
||||
fpy.write('\n')
|
||||
|
||||
for line in fcpp:
|
||||
py_line = process_line(line)
|
||||
if py_line:
|
||||
fpy.write(py_line.decode('gbk').encode('utf-8'))
|
||||
|
||||
fcpp.close()
|
||||
fpy.close()
|
||||
|
||||
print u'data_type.py生成过程完成'
|
||||
except:
|
||||
print u'data_type.py生成过程出错'
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
207
vn.lts/pyscript/generate_md_functions.py
Normal file
207
vn.lts/pyscript/generate_md_functions.py
Normal file
@ -0,0 +1,207 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
__author__ = 'CHENXY'
|
||||
|
||||
from string import join
|
||||
from lts_struct import structDict
|
||||
|
||||
|
||||
|
||||
def processCallBack(line):
|
||||
orignalLine = line
|
||||
line = line.replace('\tvirtual void ', '') # 删除行首的无效内容
|
||||
line = line.replace('{};\n', '') # 删除行尾的无效内容
|
||||
|
||||
content = line.split('(')
|
||||
cbName = content[0] # 回调函数名称
|
||||
|
||||
cbArgs = content[1] # 回调函数参数
|
||||
if cbArgs[-1] == ' ':
|
||||
cbArgs = cbArgs.replace(') ', '')
|
||||
else:
|
||||
cbArgs = cbArgs.replace(')', '')
|
||||
|
||||
cbArgsList = cbArgs.split(', ') # 将每个参数转化为列表
|
||||
|
||||
cbArgsTypeList = []
|
||||
cbArgsValueList = []
|
||||
|
||||
for arg in cbArgsList: # 开始处理参数
|
||||
content = arg.split(' ')
|
||||
if len(content) > 1:
|
||||
cbArgsTypeList.append(content[0]) # 参数类型列表
|
||||
cbArgsValueList.append(content[1]) # 参数数据列表
|
||||
|
||||
createTask(cbName, cbArgsTypeList, cbArgsValueList, orignalLine)
|
||||
createProcess(cbName, cbArgsTypeList, cbArgsValueList)
|
||||
|
||||
|
||||
def createTask(cbName, cbArgsTypeList, cbArgsValueList, orignalLine):
|
||||
# 从回调函数生成任务对象,并放入队列
|
||||
funcline = orignalLine.replace('\tvirtual void ', 'void ' + apiName + '::')
|
||||
funcline = funcline.replace('{};', '')
|
||||
|
||||
ftask.write(funcline)
|
||||
ftask.write('{\n')
|
||||
ftask.write("\tTask task = Task();\n")
|
||||
|
||||
ftask.write("\ttask.task_name = " + cbName.upper() + ";\n")
|
||||
|
||||
# define常量
|
||||
global define_count
|
||||
fdefine.write("#define " + cbName.upper() + ' ' + str(define_count) + '\n')
|
||||
define_count = define_count + 1
|
||||
|
||||
# switch段代码
|
||||
fswitch.write("case " + cbName.upper() + ':\n')
|
||||
fswitch.write("{\n")
|
||||
fswitch.write("\tthis->" + cbName.replace('On', 'process') + '(task);\n')
|
||||
fswitch.write("\tbreak;\n")
|
||||
fswitch.write("}\n")
|
||||
fswitch.write("\n")
|
||||
|
||||
for i, type_ in enumerate(cbArgsTypeList):
|
||||
if type_ == 'int':
|
||||
ftask.write("\ttask.task_id = " + cbArgsValueList[i] + ";\n")
|
||||
elif type_ == 'bool':
|
||||
ftask.write("\ttask.task_last = " + cbArgsValueList[i] + ";\n")
|
||||
elif 'RspInfoField' in type_:
|
||||
ftask.write("\tif (pRspInfo)\n")
|
||||
ftask.write("\t{\n")
|
||||
ftask.write("\t\ttask.task_error = " + cbArgsValueList[i] + ";\n")
|
||||
ftask.write("\t}\n")
|
||||
ftask.write("\telse\n")
|
||||
ftask.write("\t{\n")
|
||||
ftask.write("\t\tCSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();\n")
|
||||
ftask.write("\t\tmemset(&empty_error, 0, sizeof(empty_error));\n")
|
||||
ftask.write("\t\ttask.task_error = empty_error;\n")
|
||||
ftask.write("\t}\n")
|
||||
else:
|
||||
ftask.write("\ttask.task_data = " + cbArgsValueList[i] + ";\n")
|
||||
|
||||
ftask.write("\tthis->task_queue.push(task);\n")
|
||||
ftask.write("};\n")
|
||||
ftask.write("\n")
|
||||
|
||||
|
||||
def createProcess(cbName, cbArgsTypeList, cbArgsValueList):
|
||||
# 从队列中提取任务,并转化为python字典
|
||||
fprocess.write("void " + apiName + '::' + cbName.replace('On', 'process') + '(Task task)' + "\n")
|
||||
fprocess.write("{\n")
|
||||
|
||||
onArgsList = []
|
||||
|
||||
for i, type_ in enumerate(cbArgsTypeList):
|
||||
if 'RspInfoField' in type_:
|
||||
fprocess.write("\t"+ type_ + ' task_error = any_cast<' + type_ + '>(task.task_error);\n')
|
||||
fprocess.write("\t"+ "dict error;\n")
|
||||
|
||||
struct = structDict[type_]
|
||||
for key in struct.keys():
|
||||
fprocess.write("\t"+ 'error["' + key + '"] = task_error.' + key + ';\n')
|
||||
|
||||
fprocess.write("\n")
|
||||
|
||||
onArgsList.append('error')
|
||||
|
||||
elif type_ in structDict:
|
||||
fprocess.write("\t"+ type_ + ' task_data = any_cast<' + type_ + '>(task.task_data);\n')
|
||||
fprocess.write("\t"+ "dict data;\n")
|
||||
|
||||
struct = structDict[type_]
|
||||
for key in struct.keys():
|
||||
fprocess.write("\t"+ 'data["' + key + '"] = task_data.' + key + ';\n')
|
||||
|
||||
fprocess.write("\n")
|
||||
|
||||
onArgsList.append('data')
|
||||
|
||||
elif type_ == 'bool':
|
||||
onArgsList.append('task.task_last')
|
||||
|
||||
elif type_ == 'int':
|
||||
onArgsList.append('task.task_id')
|
||||
|
||||
onArgs = join(onArgsList, ', ')
|
||||
fprocess.write('\tthis->' + cbName.replace('On', 'on') + '(' + onArgs +');\n')
|
||||
|
||||
fprocess.write("};\n")
|
||||
fprocess.write("\n")
|
||||
|
||||
|
||||
def processFunction(line):
|
||||
line = line.replace('\tvirtual int ', '') # 删除行首的无效内容
|
||||
line = line.replace(') = 0;\n', '') # 删除行尾的无效内容
|
||||
|
||||
content = line.split('(')
|
||||
fcName = content[0] # 回调函数名称
|
||||
|
||||
fcArgs = content[1] # 回调函数参数
|
||||
fcArgs = fcArgs.replace(')', '')
|
||||
|
||||
fcArgsList = fcArgs.split(', ') # 将每个参数转化为列表
|
||||
|
||||
fcArgsTypeList = []
|
||||
fcArgsValueList = []
|
||||
|
||||
for arg in fcArgsList: # 开始处理参数
|
||||
content = arg.split(' ')
|
||||
if len(content) > 1:
|
||||
fcArgsTypeList.append(content[0]) # 参数类型列表
|
||||
fcArgsValueList.append(content[1]) # 参数数据列表
|
||||
|
||||
if len(fcArgsTypeList)>0 and fcArgsTypeList[0] in structDict:
|
||||
createFunction(fcName, fcArgsTypeList, fcArgsValueList)
|
||||
|
||||
|
||||
def createFunction(fcName, fcArgsTypeList, fcArgsValueList):
|
||||
type_ = fcArgsTypeList[0]
|
||||
struct = structDict[type_]
|
||||
|
||||
ffunction.write(fcName + '\n')
|
||||
ffunction.write('{\n')
|
||||
ffunction.write('\t' + type_ +' myreq = ' + type_ + '();\n')
|
||||
ffunction.write('\tmemset(&myreq, 0, sizeof(myreq));\n')
|
||||
|
||||
for key, value in struct.items():
|
||||
if value == 'string':
|
||||
line = '\tgetChar(req, "' + key + '", myreq.' + key + ');\n'
|
||||
elif value == 'int':
|
||||
line = '\tgetInt(req, "' + key + '", &myreq.' + key + ');\n'
|
||||
elif value == 'double':
|
||||
line = '\tgetDouble(req, "' + key + '", &myreq.' + key + ');\n'
|
||||
ffunction.write(line)
|
||||
|
||||
ffunction.write('\tint i = this->api->' + fcName + '(&myreq, nRequestID);\n')
|
||||
ffunction.write('\treturn i;\n')
|
||||
|
||||
ffunction.write('};\n')
|
||||
ffunction.write('\n')
|
||||
|
||||
|
||||
|
||||
|
||||
#########################################################
|
||||
apiName = 'MdApi'
|
||||
|
||||
fcpp = open('SecurityFtdcMdApi.h', 'r')
|
||||
ftask = open('lts_md_task.cpp', 'w')
|
||||
fprocess = open('lts_md_process.cpp', 'w')
|
||||
ffunction = open('lts_md_function.cpp', 'w')
|
||||
fdefine = open('lts_md_define.cpp', 'w')
|
||||
fswitch = open('lts_md_switch.cpp', 'w')
|
||||
|
||||
define_count = 1
|
||||
|
||||
for line in fcpp:
|
||||
if "\tvirtual void On" in line:
|
||||
processCallBack(line)
|
||||
elif "\tvirtual int" in line:
|
||||
processFunction(line)
|
||||
|
||||
fcpp.close()
|
||||
ftask.close()
|
||||
fprocess.close()
|
||||
ffunction.close()
|
||||
fswitch.close()
|
||||
fdefine.close()
|
56
vn.lts/pyscript/generate_struct.py
Normal file
56
vn.lts/pyscript/generate_struct.py
Normal file
@ -0,0 +1,56 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
__author__ = 'CHENXY'
|
||||
|
||||
from lts_data_type import *
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
fcpp = open('SecurityFtdcUserApiStruct.h', 'r')
|
||||
fpy = open('lts_struct.py', 'w')
|
||||
|
||||
fpy.write('# encoding: UTF-8\n')
|
||||
fpy.write('\n')
|
||||
fpy.write('structDict = {}\n')
|
||||
fpy.write('\n')
|
||||
|
||||
for line in fcpp:
|
||||
# 结构体申明注释
|
||||
if '///' in line and '\t' not in line:
|
||||
py_line = '#' + line[3:]
|
||||
|
||||
# 结构体变量注释
|
||||
elif '\t///' in line:
|
||||
py_line = '#' + line[4:]
|
||||
|
||||
# 结构体申明
|
||||
elif 'struct' in line:
|
||||
content = line.split(' ')
|
||||
name = content[1].replace('\n','')
|
||||
py_line = '%s = {}\n' % name
|
||||
|
||||
# 结构体变量
|
||||
elif '\t' in line:
|
||||
content = line.split('\t')
|
||||
typedef = content[1]
|
||||
type_ = typedefDict[typedef]
|
||||
variable = content[2].replace(';\n', "")
|
||||
py_line = '%s["%s"] = "%s"\n' % (name, variable, type_)
|
||||
|
||||
# 结构体结束
|
||||
elif '}' in line:
|
||||
py_line = "structDict['%s'] = %s\n\n" % (name, name)
|
||||
|
||||
# 结构体开始
|
||||
elif '{' in line:
|
||||
py_line = ''
|
||||
|
||||
# 其他
|
||||
else:
|
||||
py_line = '\n'
|
||||
|
||||
fpy.write(py_line.decode('gbk').encode('utf-8'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
207
vn.lts/pyscript/generate_td_functions.py
Normal file
207
vn.lts/pyscript/generate_td_functions.py
Normal file
@ -0,0 +1,207 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
__author__ = 'CHENXY'
|
||||
|
||||
from string import join
|
||||
from lts_struct import structDict
|
||||
|
||||
|
||||
|
||||
def processCallBack(line):
|
||||
orignalLine = line
|
||||
line = line.replace('\tvirtual void ', '') # 删除行首的无效内容
|
||||
line = line.replace('{};\n', '') # 删除行尾的无效内容
|
||||
|
||||
content = line.split('(')
|
||||
cbName = content[0] # 回调函数名称
|
||||
|
||||
cbArgs = content[1] # 回调函数参数
|
||||
if cbArgs[-1] == ' ':
|
||||
cbArgs = cbArgs.replace(') ', '')
|
||||
else:
|
||||
cbArgs = cbArgs.replace(')', '')
|
||||
|
||||
cbArgsList = cbArgs.split(', ') # 将每个参数转化为列表
|
||||
|
||||
cbArgsTypeList = []
|
||||
cbArgsValueList = []
|
||||
|
||||
for arg in cbArgsList: # 开始处理参数
|
||||
content = arg.split(' ')
|
||||
if len(content) > 1:
|
||||
cbArgsTypeList.append(content[0]) # 参数类型列表
|
||||
cbArgsValueList.append(content[1]) # 参数数据列表
|
||||
|
||||
createTask(cbName, cbArgsTypeList, cbArgsValueList, orignalLine)
|
||||
createProcess(cbName, cbArgsTypeList, cbArgsValueList)
|
||||
|
||||
|
||||
def createTask(cbName, cbArgsTypeList, cbArgsValueList, orignalLine):
|
||||
# 从回调函数生成任务对象,并放入队列
|
||||
funcline = orignalLine.replace('\tvirtual void ', 'void ' + apiName + '::')
|
||||
funcline = funcline.replace('{};', '')
|
||||
|
||||
ftask.write(funcline)
|
||||
ftask.write('{\n')
|
||||
ftask.write("\tTask task = Task();\n")
|
||||
|
||||
ftask.write("\ttask.task_name = " + cbName.upper() + ";\n")
|
||||
|
||||
# define常量
|
||||
global define_count
|
||||
fdefine.write("#define " + cbName.upper() + ' ' + str(define_count) + '\n')
|
||||
define_count = define_count + 1
|
||||
|
||||
# switch段代码
|
||||
fswitch.write("case " + cbName.upper() + ':\n')
|
||||
fswitch.write("{\n")
|
||||
fswitch.write("\tthis->" + cbName.replace('On', 'process') + '(task);\n')
|
||||
fswitch.write("\tbreak;\n")
|
||||
fswitch.write("}\n")
|
||||
fswitch.write("\n")
|
||||
|
||||
for i, type_ in enumerate(cbArgsTypeList):
|
||||
if type_ == 'int':
|
||||
ftask.write("\ttask.task_id = " + cbArgsValueList[i] + ";\n")
|
||||
elif type_ == 'bool':
|
||||
ftask.write("\ttask.task_last = " + cbArgsValueList[i] + ";\n")
|
||||
elif 'RspInfoField' in type_:
|
||||
ftask.write("\tif (pRspInfo)\n")
|
||||
ftask.write("\t{\n")
|
||||
ftask.write("\t\ttask.task_error = " + cbArgsValueList[i] + ";\n")
|
||||
ftask.write("\t}\n")
|
||||
ftask.write("\telse\n")
|
||||
ftask.write("\t{\n")
|
||||
ftask.write("\t\tCSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();\n")
|
||||
ftask.write("\t\tmemset(&empty_error, 0, sizeof(empty_error));\n")
|
||||
ftask.write("\t\ttask.task_error = empty_error;\n")
|
||||
ftask.write("\t}\n")
|
||||
else:
|
||||
ftask.write("\ttask.task_data = " + cbArgsValueList[i] + ";\n")
|
||||
|
||||
ftask.write("\tthis->task_queue.push(task);\n")
|
||||
ftask.write("};\n")
|
||||
ftask.write("\n")
|
||||
|
||||
|
||||
def createProcess(cbName, cbArgsTypeList, cbArgsValueList):
|
||||
# 从队列中提取任务,并转化为python字典
|
||||
fprocess.write("void " + apiName + '::' + cbName.replace('On', 'process') + '(Task task)' + "\n")
|
||||
fprocess.write("{\n")
|
||||
|
||||
onArgsList = []
|
||||
|
||||
for i, type_ in enumerate(cbArgsTypeList):
|
||||
if 'RspInfoField' in type_:
|
||||
fprocess.write("\t"+ type_ + ' task_error = any_cast<' + type_ + '>(task.task_error);\n')
|
||||
fprocess.write("\t"+ "dict error;\n")
|
||||
|
||||
struct = structDict[type_]
|
||||
for key in struct.keys():
|
||||
fprocess.write("\t"+ 'error["' + key + '"] = task_error.' + key + ';\n')
|
||||
|
||||
fprocess.write("\n")
|
||||
|
||||
onArgsList.append('error')
|
||||
|
||||
elif type_ in structDict:
|
||||
fprocess.write("\t"+ type_ + ' task_data = any_cast<' + type_ + '>(task.task_data);\n')
|
||||
fprocess.write("\t"+ "dict data;\n")
|
||||
|
||||
struct = structDict[type_]
|
||||
for key in struct.keys():
|
||||
fprocess.write("\t"+ 'data["' + key + '"] = task_data.' + key + ';\n')
|
||||
|
||||
fprocess.write("\n")
|
||||
|
||||
onArgsList.append('data')
|
||||
|
||||
elif type_ == 'bool':
|
||||
onArgsList.append('task.task_last')
|
||||
|
||||
elif type_ == 'int':
|
||||
onArgsList.append('task.task_id')
|
||||
|
||||
onArgs = join(onArgsList, ', ')
|
||||
fprocess.write('\tthis->' + cbName.replace('On', 'on') + '(' + onArgs +');\n')
|
||||
|
||||
fprocess.write("};\n")
|
||||
fprocess.write("\n")
|
||||
|
||||
|
||||
def processFunction(line):
|
||||
line = line.replace('\tvirtual int ', '') # 删除行首的无效内容
|
||||
line = line.replace(') = 0;\n', '') # 删除行尾的无效内容
|
||||
|
||||
content = line.split('(')
|
||||
fcName = content[0] # 回调函数名称
|
||||
|
||||
fcArgs = content[1] # 回调函数参数
|
||||
fcArgs = fcArgs.replace(')', '')
|
||||
|
||||
fcArgsList = fcArgs.split(', ') # 将每个参数转化为列表
|
||||
|
||||
fcArgsTypeList = []
|
||||
fcArgsValueList = []
|
||||
|
||||
for arg in fcArgsList: # 开始处理参数
|
||||
content = arg.split(' ')
|
||||
if len(content) > 1:
|
||||
fcArgsTypeList.append(content[0]) # 参数类型列表
|
||||
fcArgsValueList.append(content[1]) # 参数数据列表
|
||||
|
||||
if len(fcArgsTypeList)>0 and fcArgsTypeList[0] in structDict:
|
||||
createFunction(fcName, fcArgsTypeList, fcArgsValueList)
|
||||
|
||||
|
||||
def createFunction(fcName, fcArgsTypeList, fcArgsValueList):
|
||||
type_ = fcArgsTypeList[0]
|
||||
struct = structDict[type_]
|
||||
|
||||
ffunction.write(fcName + '\n')
|
||||
ffunction.write('{\n')
|
||||
ffunction.write('\t' + type_ +' myreq = ' + type_ + '();\n')
|
||||
ffunction.write('\tmemset(&myreq, 0, sizeof(myreq));\n')
|
||||
|
||||
for key, value in struct.items():
|
||||
if value == 'string':
|
||||
line = '\tgetChar(req, "' + key + '", myreq.' + key + ');\n'
|
||||
elif value == 'int':
|
||||
line = '\tgetInt(req, "' + key + '", &myreq.' + key + ');\n'
|
||||
elif value == 'double':
|
||||
line = '\tgetDouble(req, "' + key + '", &myreq.' + key + ');\n'
|
||||
ffunction.write(line)
|
||||
|
||||
ffunction.write('\tint i = this->api->' + fcName + '(&myreq, nRequestID);\n')
|
||||
ffunction.write('\treturn i;\n')
|
||||
|
||||
ffunction.write('};\n')
|
||||
ffunction.write('\n')
|
||||
|
||||
|
||||
|
||||
|
||||
#########################################################
|
||||
apiName = 'TdApi'
|
||||
|
||||
fcpp = open('SecurityFtdcTraderApi.h', 'r')
|
||||
ftask = open('lts_td_task.cpp', 'w')
|
||||
fprocess = open('lts_td_process.cpp', 'w')
|
||||
ffunction = open('lts_td_function.cpp', 'w')
|
||||
fdefine = open('lts_td_define.cpp', 'w')
|
||||
fswitch = open('lts_td_switch.cpp', 'w')
|
||||
|
||||
define_count = 1
|
||||
|
||||
for line in fcpp:
|
||||
if "\tvirtual void On" in line:
|
||||
processCallBack(line)
|
||||
elif "\tvirtual int" in line:
|
||||
processFunction(line)
|
||||
|
||||
fcpp.close()
|
||||
ftask.close()
|
||||
fprocess.close()
|
||||
ffunction.close()
|
||||
fswitch.close()
|
||||
fdefine.close()
|
2076
vn.lts/pyscript/lts_data_type.py
Normal file
2076
vn.lts/pyscript/lts_data_type.py
Normal file
File diff suppressed because it is too large
Load Diff
9
vn.lts/pyscript/lts_md_define.cpp
Normal file
9
vn.lts/pyscript/lts_md_define.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#define ONFRONTCONNECTED 1
|
||||
#define ONFRONTDISCONNECTED 2
|
||||
#define ONHEARTBEATWARNING 3
|
||||
#define ONRSPERROR 4
|
||||
#define ONRSPUSERLOGIN 5
|
||||
#define ONRSPUSERLOGOUT 6
|
||||
#define ONRSPSUBMARKETDATA 7
|
||||
#define ONRSPUNSUBMARKETDATA 8
|
||||
#define ONRTNDEPTHMARKETDATA 9
|
29
vn.lts/pyscript/lts_md_function.cpp
Normal file
29
vn.lts/pyscript/lts_md_function.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
ReqUserLogin
|
||||
{
|
||||
CSecurityFtdcReqUserLoginField myreq = CSecurityFtdcReqUserLoginField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "MacAddress", myreq.MacAddress);
|
||||
getChar(req, "UserProductInfo", myreq.UserProductInfo);
|
||||
getChar(req, "UserID", myreq.UserID);
|
||||
getChar(req, "AuthCode", myreq.AuthCode);
|
||||
getChar(req, "TradingDay", myreq.TradingDay);
|
||||
getChar(req, "InterfaceProductInfo", myreq.InterfaceProductInfo);
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
getChar(req, "ClientIPAddress", myreq.ClientIPAddress);
|
||||
getChar(req, "OneTimePassword", myreq.OneTimePassword);
|
||||
getChar(req, "ProtocolInfo", myreq.ProtocolInfo);
|
||||
getChar(req, "Password", myreq.Password);
|
||||
int i = this->api->ReqUserLogin(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqUserLogout
|
||||
{
|
||||
CSecurityFtdcUserLogoutField myreq = CSecurityFtdcUserLogoutField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "UserID", myreq.UserID);
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
int i = this->api->ReqUserLogout(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
143
vn.lts/pyscript/lts_md_process.cpp
Normal file
143
vn.lts/pyscript/lts_md_process.cpp
Normal file
@ -0,0 +1,143 @@
|
||||
void MdApi::processFrontConnected(Task task)
|
||||
{
|
||||
this->onFrontConnected();
|
||||
};
|
||||
|
||||
void MdApi::processFrontDisconnected(Task task)
|
||||
{
|
||||
this->onFrontDisconnected(task.task_id);
|
||||
};
|
||||
|
||||
void MdApi::processHeartBeatWarning(Task task)
|
||||
{
|
||||
this->onHeartBeatWarning(task.task_id);
|
||||
};
|
||||
|
||||
void MdApi::processRspError(Task task)
|
||||
{
|
||||
CSecurityFtdcRspInfoField task_error = any_cast<CSecurityFtdcRspInfoField>(task.task_error);
|
||||
dict error;
|
||||
error["ErrorMsg"] = task_error.ErrorMsg;
|
||||
error["ErrorID"] = task_error.ErrorID;
|
||||
|
||||
this->onRspError(error, task.task_id, task.task_last);
|
||||
};
|
||||
|
||||
void MdApi::processRspUserLogin(Task task)
|
||||
{
|
||||
CSecurityFtdcRspUserLoginField task_data = any_cast<CSecurityFtdcRspUserLoginField>(task.task_data);
|
||||
dict data;
|
||||
data["MaxOrderRef"] = task_data.MaxOrderRef;
|
||||
data["UserID"] = task_data.UserID;
|
||||
data["TradingDay"] = task_data.TradingDay;
|
||||
data["SessionID"] = task_data.SessionID;
|
||||
data["SystemName"] = task_data.SystemName;
|
||||
data["FrontID"] = task_data.FrontID;
|
||||
data["BrokerID"] = task_data.BrokerID;
|
||||
data["LoginTime"] = task_data.LoginTime;
|
||||
|
||||
CSecurityFtdcRspInfoField task_error = any_cast<CSecurityFtdcRspInfoField>(task.task_error);
|
||||
dict error;
|
||||
error["ErrorMsg"] = task_error.ErrorMsg;
|
||||
error["ErrorID"] = task_error.ErrorID;
|
||||
|
||||
this->onRspUserLogin(data, error, task.task_id, task.task_last);
|
||||
};
|
||||
|
||||
void MdApi::processRspUserLogout(Task task)
|
||||
{
|
||||
CSecurityFtdcUserLogoutField task_data = any_cast<CSecurityFtdcUserLogoutField>(task.task_data);
|
||||
dict data;
|
||||
data["UserID"] = task_data.UserID;
|
||||
data["BrokerID"] = task_data.BrokerID;
|
||||
|
||||
CSecurityFtdcRspInfoField task_error = any_cast<CSecurityFtdcRspInfoField>(task.task_error);
|
||||
dict error;
|
||||
error["ErrorMsg"] = task_error.ErrorMsg;
|
||||
error["ErrorID"] = task_error.ErrorID;
|
||||
|
||||
this->onRspUserLogout(data, error, task.task_id, task.task_last);
|
||||
};
|
||||
|
||||
void MdApi::processRspSubMarketData(Task task)
|
||||
{
|
||||
CSecurityFtdcSpecificInstrumentField task_data = any_cast<CSecurityFtdcSpecificInstrumentField>(task.task_data);
|
||||
dict data;
|
||||
data["InstrumentID"] = task_data.InstrumentID;
|
||||
data["ExchangeID"] = task_data.ExchangeID;
|
||||
|
||||
CSecurityFtdcRspInfoField task_error = any_cast<CSecurityFtdcRspInfoField>(task.task_error);
|
||||
dict error;
|
||||
error["ErrorMsg"] = task_error.ErrorMsg;
|
||||
error["ErrorID"] = task_error.ErrorID;
|
||||
|
||||
this->onRspSubMarketData(data, error, task.task_id, task.task_last);
|
||||
};
|
||||
|
||||
void MdApi::processRspUnSubMarketData(Task task)
|
||||
{
|
||||
CSecurityFtdcSpecificInstrumentField task_data = any_cast<CSecurityFtdcSpecificInstrumentField>(task.task_data);
|
||||
dict data;
|
||||
data["InstrumentID"] = task_data.InstrumentID;
|
||||
data["ExchangeID"] = task_data.ExchangeID;
|
||||
|
||||
CSecurityFtdcRspInfoField task_error = any_cast<CSecurityFtdcRspInfoField>(task.task_error);
|
||||
dict error;
|
||||
error["ErrorMsg"] = task_error.ErrorMsg;
|
||||
error["ErrorID"] = task_error.ErrorID;
|
||||
|
||||
this->onRspUnSubMarketData(data, error, task.task_id, task.task_last);
|
||||
};
|
||||
|
||||
void MdApi::processRtnDepthMarketData(Task task)
|
||||
{
|
||||
CSecurityFtdcDepthMarketDataField task_data = any_cast<CSecurityFtdcDepthMarketDataField>(task.task_data);
|
||||
dict data;
|
||||
data["HighestPrice"] = task_data.HighestPrice;
|
||||
data["BidPrice5"] = task_data.BidPrice5;
|
||||
data["BidPrice4"] = task_data.BidPrice4;
|
||||
data["BidPrice1"] = task_data.BidPrice1;
|
||||
data["BidPrice3"] = task_data.BidPrice3;
|
||||
data["BidPrice2"] = task_data.BidPrice2;
|
||||
data["LowerLimitPrice"] = task_data.LowerLimitPrice;
|
||||
data["OpenPrice"] = task_data.OpenPrice;
|
||||
data["AskPrice5"] = task_data.AskPrice5;
|
||||
data["AskPrice4"] = task_data.AskPrice4;
|
||||
data["AskPrice3"] = task_data.AskPrice3;
|
||||
data["PreClosePrice"] = task_data.PreClosePrice;
|
||||
data["AskPrice1"] = task_data.AskPrice1;
|
||||
data["PreSettlementPrice"] = task_data.PreSettlementPrice;
|
||||
data["AskVolume1"] = task_data.AskVolume1;
|
||||
data["UpdateTime"] = task_data.UpdateTime;
|
||||
data["UpdateMillisec"] = task_data.UpdateMillisec;
|
||||
data["AveragePrice"] = task_data.AveragePrice;
|
||||
data["BidVolume5"] = task_data.BidVolume5;
|
||||
data["BidVolume4"] = task_data.BidVolume4;
|
||||
data["BidVolume3"] = task_data.BidVolume3;
|
||||
data["BidVolume2"] = task_data.BidVolume2;
|
||||
data["PreOpenInterest"] = task_data.PreOpenInterest;
|
||||
data["AskPrice2"] = task_data.AskPrice2;
|
||||
data["Volume"] = task_data.Volume;
|
||||
data["AskVolume3"] = task_data.AskVolume3;
|
||||
data["AskVolume2"] = task_data.AskVolume2;
|
||||
data["AskVolume5"] = task_data.AskVolume5;
|
||||
data["AskVolume4"] = task_data.AskVolume4;
|
||||
data["UpperLimitPrice"] = task_data.UpperLimitPrice;
|
||||
data["BidVolume1"] = task_data.BidVolume1;
|
||||
data["InstrumentID"] = task_data.InstrumentID;
|
||||
data["ClosePrice"] = task_data.ClosePrice;
|
||||
data["ExchangeID"] = task_data.ExchangeID;
|
||||
data["TradingDay"] = task_data.TradingDay;
|
||||
data["PreDelta"] = task_data.PreDelta;
|
||||
data["OpenInterest"] = task_data.OpenInterest;
|
||||
data["CurrDelta"] = task_data.CurrDelta;
|
||||
data["Turnover"] = task_data.Turnover;
|
||||
data["LastPrice"] = task_data.LastPrice;
|
||||
data["SettlementPrice"] = task_data.SettlementPrice;
|
||||
data["ExchangeInstID"] = task_data.ExchangeInstID;
|
||||
data["LowestPrice"] = task_data.LowestPrice;
|
||||
data["ActionDay"] = task_data.ActionDay;
|
||||
|
||||
this->onRtnDepthMarketData(data);
|
||||
};
|
||||
|
54
vn.lts/pyscript/lts_md_switch.cpp
Normal file
54
vn.lts/pyscript/lts_md_switch.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
case ONFRONTCONNECTED:
|
||||
{
|
||||
this->processFrontConnected(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONFRONTDISCONNECTED:
|
||||
{
|
||||
this->processFrontDisconnected(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONHEARTBEATWARNING:
|
||||
{
|
||||
this->processHeartBeatWarning(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPERROR:
|
||||
{
|
||||
this->processRspError(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPUSERLOGIN:
|
||||
{
|
||||
this->processRspUserLogin(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPUSERLOGOUT:
|
||||
{
|
||||
this->processRspUserLogout(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPSUBMARKETDATA:
|
||||
{
|
||||
this->processRspSubMarketData(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPUNSUBMARKETDATA:
|
||||
{
|
||||
this->processRspUnSubMarketData(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRTNDEPTHMARKETDATA:
|
||||
{
|
||||
this->processRtnDepthMarketData(task);
|
||||
break;
|
||||
}
|
||||
|
130
vn.lts/pyscript/lts_md_task.cpp
Normal file
130
vn.lts/pyscript/lts_md_task.cpp
Normal file
@ -0,0 +1,130 @@
|
||||
void MdApi::OnFrontConnected()
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONFRONTCONNECTED;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void MdApi::OnFrontDisconnected(int nReason)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONFRONTDISCONNECTED;
|
||||
task.task_id = nReason;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void MdApi::OnHeartBeatWarning(int nTimeLapse)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONHEARTBEATWARNING;
|
||||
task.task_id = nTimeLapse;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void MdApi::OnRspError(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPERROR;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void MdApi::OnRspUserLogin(CSecurityFtdcRspUserLoginField *pRspUserLogin, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPUSERLOGIN;
|
||||
task.task_data = *pRspUserLogin;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void MdApi::OnRspUserLogout(CSecurityFtdcUserLogoutField *pUserLogout, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPUSERLOGOUT;
|
||||
task.task_data = *pUserLogout;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void MdApi::OnRspSubMarketData(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPSUBMARKETDATA;
|
||||
task.task_data = *pSpecificInstrument;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void MdApi::OnRspUnSubMarketData(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPUNSUBMARKETDATA;
|
||||
task.task_data = *pSpecificInstrument;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void MdApi::OnRtnDepthMarketData(CSecurityFtdcDepthMarketDataField *pDepthMarketData)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRTNDEPTHMARKETDATA;
|
||||
task.task_data = *pDepthMarketData;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
2316
vn.lts/pyscript/lts_struct.py
Normal file
2316
vn.lts/pyscript/lts_struct.py
Normal file
File diff suppressed because it is too large
Load Diff
39
vn.lts/pyscript/lts_td_define.cpp
Normal file
39
vn.lts/pyscript/lts_td_define.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#define ONFRONTCONNECTED 1
|
||||
#define ONFRONTDISCONNECTED 2
|
||||
#define ONHEARTBEATWARNING 3
|
||||
#define ONRSPERROR 4
|
||||
#define ONRSPUSERLOGIN 5
|
||||
#define ONRSPUSERLOGOUT 6
|
||||
#define ONRSPORDERINSERT 7
|
||||
#define ONRSPORDERACTION 8
|
||||
#define ONRSPUSERPASSWORDUPDATE 9
|
||||
#define ONRSPTRADINGACCOUNTPASSWORDUPDATE 10
|
||||
#define ONRSPQRYEXCHANGE 11
|
||||
#define ONRSPQRYINSTRUMENT 12
|
||||
#define ONRSPQRYINVESTOR 13
|
||||
#define ONRSPQRYTRADINGCODE 14
|
||||
#define ONRSPQRYTRADINGACCOUNT 15
|
||||
#define ONRSPQRYDEPTHMARKETDATA 16
|
||||
#define ONRSPQRYBONDINTEREST 17
|
||||
#define ONRSPQRYMARKETRATIONINFO 18
|
||||
#define ONRSPQRYINSTRUMENTCOMMISSIONRATE 19
|
||||
#define ONRSPQRYETFINSTRUMENT 20
|
||||
#define ONRSPQRYETFBASKET 21
|
||||
#define ONRSPQRYOFINSTRUMENT 22
|
||||
#define ONRSPQRYSFINSTRUMENT 23
|
||||
#define ONRSPQRYORDER 24
|
||||
#define ONRSPQRYTRADE 25
|
||||
#define ONRSPQRYINVESTORPOSITION 26
|
||||
#define ONRTNORDER 27
|
||||
#define ONRTNTRADE 28
|
||||
#define ONERRRTNORDERINSERT 29
|
||||
#define ONERRRTNORDERACTION 30
|
||||
#define ONRSPFUNDOUTBYLIBER 31
|
||||
#define ONRTNFUNDOUTBYLIBER 32
|
||||
#define ONERRRTNFUNDOUTBYLIBER 33
|
||||
#define ONRTNFUNDINBYBANK 34
|
||||
#define ONRSPQRYFUNDTRANSFERSERIAL 35
|
||||
#define ONRSPFUNDINTERTRANSFER 36
|
||||
#define ONRSPQRYFUNDINTERTRANSFERSERIAL 37
|
||||
#define ONRTNFUNDINTERTRANSFERSERIAL 38
|
||||
#define ONERRRTNFUNDINTERTRANSFER 39
|
338
vn.lts/pyscript/lts_td_function.cpp
Normal file
338
vn.lts/pyscript/lts_td_function.cpp
Normal file
@ -0,0 +1,338 @@
|
||||
ReqUserLogin
|
||||
{
|
||||
CSecurityFtdcReqUserLoginField myreq = CSecurityFtdcReqUserLoginField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "MacAddress", myreq.MacAddress);
|
||||
getChar(req, "UserProductInfo", myreq.UserProductInfo);
|
||||
getChar(req, "UserID", myreq.UserID);
|
||||
getChar(req, "AuthCode", myreq.AuthCode);
|
||||
getChar(req, "TradingDay", myreq.TradingDay);
|
||||
getChar(req, "InterfaceProductInfo", myreq.InterfaceProductInfo);
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
getChar(req, "ClientIPAddress", myreq.ClientIPAddress);
|
||||
getChar(req, "OneTimePassword", myreq.OneTimePassword);
|
||||
getChar(req, "ProtocolInfo", myreq.ProtocolInfo);
|
||||
getChar(req, "Password", myreq.Password);
|
||||
int i = this->api->ReqUserLogin(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqUserLogout
|
||||
{
|
||||
CSecurityFtdcUserLogoutField myreq = CSecurityFtdcUserLogoutField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "UserID", myreq.UserID);
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
int i = this->api->ReqUserLogout(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqOrderInsert
|
||||
{
|
||||
CSecurityFtdcInputOrderField myreq = CSecurityFtdcInputOrderField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "ContingentCondition", myreq.ContingentCondition);
|
||||
getChar(req, "CombOffsetFlag", myreq.CombOffsetFlag);
|
||||
getChar(req, "UserID", myreq.UserID);
|
||||
getChar(req, "LimitPrice", myreq.LimitPrice);
|
||||
getInt(req, "UserForceClose", &myreq.UserForceClose);
|
||||
getChar(req, "Direction", myreq.Direction);
|
||||
getInt(req, "VolumeTotalOriginal", &myreq.VolumeTotalOriginal);
|
||||
getChar(req, "OrderPriceType", myreq.OrderPriceType);
|
||||
getChar(req, "TimeCondition", myreq.TimeCondition);
|
||||
getInt(req, "IsAutoSuspend", &myreq.IsAutoSuspend);
|
||||
getInt(req, "IsAutoSuspend", &myreq.IsAutoSuspend);
|
||||
getChar(req, "InstrumentID", myreq.InstrumentID);
|
||||
getChar(req, "ExchangeID", myreq.ExchangeID);
|
||||
getInt(req, "MinVolume", &myreq.MinVolume);
|
||||
getChar(req, "ForceCloseReason", myreq.ForceCloseReason);
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
getChar(req, "CombHedgeFlag", myreq.CombHedgeFlag);
|
||||
getChar(req, "GTDDate", myreq.GTDDate);
|
||||
getChar(req, "BusinessUnit", myreq.BusinessUnit);
|
||||
getChar(req, "OrderRef", myreq.OrderRef);
|
||||
getChar(req, "InvestorID", myreq.InvestorID);
|
||||
getChar(req, "VolumeCondition", myreq.VolumeCondition);
|
||||
getInt(req, "RequestID", &myreq.RequestID);
|
||||
int i = this->api->ReqOrderInsert(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqOrderAction
|
||||
{
|
||||
CSecurityFtdcInputOrderActionField myreq = CSecurityFtdcInputOrderActionField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "InstrumentID", myreq.InstrumentID);
|
||||
getChar(req, "ExchangeID", myreq.ExchangeID);
|
||||
getChar(req, "OrderLocalID", myreq.OrderLocalID);
|
||||
getInt(req, "OrderActionRef", &myreq.OrderActionRef);
|
||||
getChar(req, "UserID", myreq.UserID);
|
||||
getChar(req, "UserID", myreq.UserID);
|
||||
getChar(req, "OrderRef", myreq.OrderRef);
|
||||
getChar(req, "InvestorID", myreq.InvestorID);
|
||||
getInt(req, "SessionID", &myreq.SessionID);
|
||||
getInt(req, "VolumeChange", &myreq.VolumeChange);
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
getInt(req, "RequestID", &myreq.RequestID);
|
||||
getChar(req, "ActionFlag", myreq.ActionFlag);
|
||||
getInt(req, "FrontID", &myreq.FrontID);
|
||||
getChar(req, "BranchPBU", myreq.BranchPBU);
|
||||
int i = this->api->ReqOrderAction(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqUserPasswordUpdate
|
||||
{
|
||||
CSecurityFtdcUserPasswordUpdateField myreq = CSecurityFtdcUserPasswordUpdateField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "UserID", myreq.UserID);
|
||||
getChar(req, "NewPassword", myreq.NewPassword);
|
||||
getChar(req, "OldPassword", myreq.OldPassword);
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
int i = this->api->ReqUserPasswordUpdate(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqTradingAccountPasswordUpdate
|
||||
{
|
||||
CSecurityFtdcTradingAccountPasswordUpdateField myreq = CSecurityFtdcTradingAccountPasswordUpdateField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "NewPassword", myreq.NewPassword);
|
||||
getChar(req, "OldPassword", myreq.OldPassword);
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
getChar(req, "AccountID", myreq.AccountID);
|
||||
int i = this->api->ReqTradingAccountPasswordUpdate(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqQryExchange
|
||||
{
|
||||
CSecurityFtdcQryExchangeField myreq = CSecurityFtdcQryExchangeField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "ExchangeID", myreq.ExchangeID);
|
||||
int i = this->api->ReqQryExchange(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqQryInstrument
|
||||
{
|
||||
CSecurityFtdcQryInstrumentField myreq = CSecurityFtdcQryInstrumentField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "InstrumentID", myreq.InstrumentID);
|
||||
getChar(req, "ExchangeID", myreq.ExchangeID);
|
||||
getChar(req, "ExchangeInstID", myreq.ExchangeInstID);
|
||||
getChar(req, "ProductID", myreq.ProductID);
|
||||
int i = this->api->ReqQryInstrument(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqQryInvestor
|
||||
{
|
||||
CSecurityFtdcQryInvestorField myreq = CSecurityFtdcQryInvestorField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "InvestorID", myreq.InvestorID);
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
int i = this->api->ReqQryInvestor(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqQryTradingCode
|
||||
{
|
||||
CSecurityFtdcQryTradingCodeField myreq = CSecurityFtdcQryTradingCodeField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "InvestorID", myreq.InvestorID);
|
||||
getChar(req, "ExchangeID", myreq.ExchangeID);
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
getChar(req, "ClientID", myreq.ClientID);
|
||||
int i = this->api->ReqQryTradingCode(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqQryTradingAccount
|
||||
{
|
||||
CSecurityFtdcQryTradingAccountField myreq = CSecurityFtdcQryTradingAccountField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "InvestorID", myreq.InvestorID);
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
int i = this->api->ReqQryTradingAccount(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqQryDepthMarketData
|
||||
{
|
||||
CSecurityFtdcQryDepthMarketDataField myreq = CSecurityFtdcQryDepthMarketDataField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "InstrumentID", myreq.InstrumentID);
|
||||
int i = this->api->ReqQryDepthMarketData(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqQryBondInterest
|
||||
{
|
||||
CSecurityFtdcQryBondInterestField myreq = CSecurityFtdcQryBondInterestField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "InstrumentID", myreq.InstrumentID);
|
||||
getChar(req, "ExchangeID", myreq.ExchangeID);
|
||||
int i = this->api->ReqQryBondInterest(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqQryMarketRationInfo
|
||||
{
|
||||
CSecurityFtdcQryMarketRationInfoField myreq = CSecurityFtdcQryMarketRationInfoField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "InvestorID", myreq.InvestorID);
|
||||
getChar(req, "ExchangeID", myreq.ExchangeID);
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
int i = this->api->ReqQryMarketRationInfo(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqQryInstrumentCommissionRate
|
||||
{
|
||||
CSecurityFtdcQryInstrumentCommissionRateField myreq = CSecurityFtdcQryInstrumentCommissionRateField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "InstrumentID", myreq.InstrumentID);
|
||||
getChar(req, "ExchangeID", myreq.ExchangeID);
|
||||
getChar(req, "OffsetFlag", myreq.OffsetFlag);
|
||||
getChar(req, "Direction", myreq.Direction);
|
||||
getChar(req, "InvestorID", myreq.InvestorID);
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
int i = this->api->ReqQryInstrumentCommissionRate(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqQryETFInstrument
|
||||
{
|
||||
CSecurityFtdcQryETFInstrumentField myreq = CSecurityFtdcQryETFInstrumentField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "ETFInstrumentID", myreq.ETFInstrumentID);
|
||||
getChar(req, "ExchangeID", myreq.ExchangeID);
|
||||
int i = this->api->ReqQryETFInstrument(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqQryETFBasket
|
||||
{
|
||||
CSecurityFtdcQryETFBasketField myreq = CSecurityFtdcQryETFBasketField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "ETFInstrumentID", myreq.ETFInstrumentID);
|
||||
getChar(req, "ExchangeID", myreq.ExchangeID);
|
||||
int i = this->api->ReqQryETFBasket(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqQryOFInstrument
|
||||
{
|
||||
CSecurityFtdcQryOFInstrumentField myreq = CSecurityFtdcQryOFInstrumentField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "ExchangeID", myreq.ExchangeID);
|
||||
getChar(req, "OFInstrumentID", myreq.OFInstrumentID);
|
||||
int i = this->api->ReqQryOFInstrument(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqQrySFInstrument
|
||||
{
|
||||
CSecurityFtdcQrySFInstrumentField myreq = CSecurityFtdcQrySFInstrumentField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "SFInstrumentID", myreq.SFInstrumentID);
|
||||
getChar(req, "ExchangeID", myreq.ExchangeID);
|
||||
int i = this->api->ReqQrySFInstrument(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqQryOrder
|
||||
{
|
||||
CSecurityFtdcQryOrderField myreq = CSecurityFtdcQryOrderField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "InstrumentID", myreq.InstrumentID);
|
||||
getChar(req, "ExchangeID", myreq.ExchangeID);
|
||||
getChar(req, "InsertTimeStart", myreq.InsertTimeStart);
|
||||
getChar(req, "InvestorID", myreq.InvestorID);
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
getChar(req, "OrderSysID", myreq.OrderSysID);
|
||||
getChar(req, "InsertTimeEnd", myreq.InsertTimeEnd);
|
||||
int i = this->api->ReqQryOrder(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqQryTrade
|
||||
{
|
||||
CSecurityFtdcQryTradeField myreq = CSecurityFtdcQryTradeField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "InstrumentID", myreq.InstrumentID);
|
||||
getChar(req, "TradeTimeStart", myreq.TradeTimeStart);
|
||||
getChar(req, "ExchangeID", myreq.ExchangeID);
|
||||
getChar(req, "TradeID", myreq.TradeID);
|
||||
getChar(req, "InvestorID", myreq.InvestorID);
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
getChar(req, "TradeTimeEnd", myreq.TradeTimeEnd);
|
||||
int i = this->api->ReqQryTrade(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqQryInvestorPosition
|
||||
{
|
||||
CSecurityFtdcQryInvestorPositionField myreq = CSecurityFtdcQryInvestorPositionField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "InstrumentID", myreq.InstrumentID);
|
||||
getChar(req, "InvestorID", myreq.InvestorID);
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
int i = this->api->ReqQryInvestorPosition(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqFundOutByLiber
|
||||
{
|
||||
CSecurityFtdcInputFundTransferField myreq = CSecurityFtdcInputFundTransferField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "UserID", myreq.UserID);
|
||||
getChar(req, "InvestorID", myreq.InvestorID);
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
getChar(req, "AccountType", myreq.AccountType);
|
||||
getChar(req, "Password", myreq.Password);
|
||||
getChar(req, "Password", myreq.Password);
|
||||
getChar(req, "Digest", myreq.Digest);
|
||||
getChar(req, "AccountID", myreq.AccountID);
|
||||
int i = this->api->ReqFundOutByLiber(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqQryFundTransferSerial
|
||||
{
|
||||
CSecurityFtdcQryFundTransferSerialField myreq = CSecurityFtdcQryFundTransferSerialField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
getChar(req, "AccountType", myreq.AccountType);
|
||||
getChar(req, "AccountID", myreq.AccountID);
|
||||
int i = this->api->ReqQryFundTransferSerial(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqFundInterTransfer
|
||||
{
|
||||
CSecurityFtdcFundInterTransferField myreq = CSecurityFtdcFundInterTransferField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getInt(req, "SerialID", &myreq.SerialID);
|
||||
getChar(req, "TransferType", myreq.TransferType);
|
||||
getChar(req, "UserID", myreq.UserID);
|
||||
getChar(req, "InvestorID", myreq.InvestorID);
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
getChar(req, "Password", myreq.Password);
|
||||
getChar(req, "Password", myreq.Password);
|
||||
getChar(req, "AccountID", myreq.AccountID);
|
||||
int i = this->api->ReqFundInterTransfer(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
ReqQryFundInterTransferSerial
|
||||
{
|
||||
CSecurityFtdcQryFundInterTransferSerialField myreq = CSecurityFtdcQryFundInterTransferSerialField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "InvestorID", myreq.InvestorID);
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
int i = this->api->ReqQryFundInterTransferSerial(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
1092
vn.lts/pyscript/lts_td_process.cpp
Normal file
1092
vn.lts/pyscript/lts_td_process.cpp
Normal file
File diff suppressed because it is too large
Load Diff
234
vn.lts/pyscript/lts_td_switch.cpp
Normal file
234
vn.lts/pyscript/lts_td_switch.cpp
Normal file
@ -0,0 +1,234 @@
|
||||
case ONFRONTCONNECTED:
|
||||
{
|
||||
this->processFrontConnected(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONFRONTDISCONNECTED:
|
||||
{
|
||||
this->processFrontDisconnected(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONHEARTBEATWARNING:
|
||||
{
|
||||
this->processHeartBeatWarning(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPERROR:
|
||||
{
|
||||
this->processRspError(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPUSERLOGIN:
|
||||
{
|
||||
this->processRspUserLogin(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPUSERLOGOUT:
|
||||
{
|
||||
this->processRspUserLogout(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPORDERINSERT:
|
||||
{
|
||||
this->processRspOrderInsert(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPORDERACTION:
|
||||
{
|
||||
this->processRspOrderAction(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPUSERPASSWORDUPDATE:
|
||||
{
|
||||
this->processRspUserPasswordUpdate(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPTRADINGACCOUNTPASSWORDUPDATE:
|
||||
{
|
||||
this->processRspTradingAccountPasswordUpdate(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPQRYEXCHANGE:
|
||||
{
|
||||
this->processRspQryExchange(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPQRYINSTRUMENT:
|
||||
{
|
||||
this->processRspQryInstrument(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPQRYINVESTOR:
|
||||
{
|
||||
this->processRspQryInvestor(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPQRYTRADINGCODE:
|
||||
{
|
||||
this->processRspQryTradingCode(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPQRYTRADINGACCOUNT:
|
||||
{
|
||||
this->processRspQryTradingAccount(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPQRYDEPTHMARKETDATA:
|
||||
{
|
||||
this->processRspQryDepthMarketData(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPQRYBONDINTEREST:
|
||||
{
|
||||
this->processRspQryBondInterest(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPQRYMARKETRATIONINFO:
|
||||
{
|
||||
this->processRspQryMarketRationInfo(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPQRYINSTRUMENTCOMMISSIONRATE:
|
||||
{
|
||||
this->processRspQryInstrumentCommissionRate(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPQRYETFINSTRUMENT:
|
||||
{
|
||||
this->processRspQryETFInstrument(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPQRYETFBASKET:
|
||||
{
|
||||
this->processRspQryETFBasket(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPQRYOFINSTRUMENT:
|
||||
{
|
||||
this->processRspQryOFInstrument(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPQRYSFINSTRUMENT:
|
||||
{
|
||||
this->processRspQrySFInstrument(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPQRYORDER:
|
||||
{
|
||||
this->processRspQryOrder(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPQRYTRADE:
|
||||
{
|
||||
this->processRspQryTrade(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPQRYINVESTORPOSITION:
|
||||
{
|
||||
this->processRspQryInvestorPosition(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRTNORDER:
|
||||
{
|
||||
this->processRtnOrder(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRTNTRADE:
|
||||
{
|
||||
this->processRtnTrade(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONERRRTNORDERINSERT:
|
||||
{
|
||||
this->processErrRtnOrderInsert(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONERRRTNORDERACTION:
|
||||
{
|
||||
this->processErrRtnOrderAction(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPFUNDOUTBYLIBER:
|
||||
{
|
||||
this->processRspFundOutByLiber(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRTNFUNDOUTBYLIBER:
|
||||
{
|
||||
this->processRtnFundOutByLiber(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONERRRTNFUNDOUTBYLIBER:
|
||||
{
|
||||
this->processErrRtnFundOutByLiber(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRTNFUNDINBYBANK:
|
||||
{
|
||||
this->processRtnFundInByBank(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPQRYFUNDTRANSFERSERIAL:
|
||||
{
|
||||
this->processRspQryFundTransferSerial(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPFUNDINTERTRANSFER:
|
||||
{
|
||||
this->processRspFundInterTransfer(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPQRYFUNDINTERTRANSFERSERIAL:
|
||||
{
|
||||
this->processRspQryFundInterTransferSerial(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRTNFUNDINTERTRANSFERSERIAL:
|
||||
{
|
||||
this->processRtnFundInterTransferSerial(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONERRRTNFUNDINTERTRANSFER:
|
||||
{
|
||||
this->processErrRtnFundInterTransfer(task);
|
||||
break;
|
||||
}
|
||||
|
675
vn.lts/pyscript/lts_td_task.cpp
Normal file
675
vn.lts/pyscript/lts_td_task.cpp
Normal file
@ -0,0 +1,675 @@
|
||||
void TdApi::OnFrontConnected()
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONFRONTCONNECTED;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnFrontDisconnected(int nReason)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONFRONTDISCONNECTED;
|
||||
task.task_id = nReason;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnHeartBeatWarning(int nTimeLapse)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONHEARTBEATWARNING;
|
||||
task.task_id = nTimeLapse{};
|
||||
;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspError(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPERROR;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspUserLogin(CSecurityFtdcRspUserLoginField *pRspUserLogin, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPUSERLOGIN;
|
||||
task.task_data = *pRspUserLogin;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspUserLogout(CSecurityFtdcUserLogoutField *pUserLogout, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPUSERLOGOUT;
|
||||
task.task_data = *pUserLogout;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspOrderInsert(CSecurityFtdcInputOrderField *pInputOrder, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPORDERINSERT;
|
||||
task.task_data = *pInputOrder;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspOrderAction(CSecurityFtdcInputOrderActionField *pInputOrderAction, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPORDERACTION;
|
||||
task.task_data = *pInputOrderAction;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspUserPasswordUpdate(CSecurityFtdcUserPasswordUpdateField *pUserPasswordUpdate, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPUSERPASSWORDUPDATE;
|
||||
task.task_data = *pUserPasswordUpdate;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspTradingAccountPasswordUpdate(CSecurityFtdcTradingAccountPasswordUpdateField *pTradingAccountPasswordUpdate, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPTRADINGACCOUNTPASSWORDUPDATE;
|
||||
task.task_data = *pTradingAccountPasswordUpdate;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspQryExchange(CSecurityFtdcExchangeField *pExchange, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPQRYEXCHANGE;
|
||||
task.task_data = *pExchange;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspQryInstrument(CSecurityFtdcInstrumentField *pInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPQRYINSTRUMENT;
|
||||
task.task_data = *pInstrument;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspQryInvestor(CSecurityFtdcInvestorField *pInvestor, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPQRYINVESTOR;
|
||||
task.task_data = *pInvestor;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspQryTradingCode(CSecurityFtdcTradingCodeField *pTradingCode, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPQRYTRADINGCODE;
|
||||
task.task_data = *pTradingCode;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspQryTradingAccount(CSecurityFtdcTradingAccountField *pTradingAccount, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPQRYTRADINGACCOUNT;
|
||||
task.task_data = *pTradingAccount;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspQryDepthMarketData(CSecurityFtdcDepthMarketDataField *pDepthMarketData, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPQRYDEPTHMARKETDATA;
|
||||
task.task_data = *pDepthMarketData;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspQryBondInterest(CSecurityFtdcBondInterestField *pBondInterest, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPQRYBONDINTEREST;
|
||||
task.task_data = *pBondInterest;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspQryMarketRationInfo(CSecurityFtdcMarketRationInfoField *pMarketRationInfo, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPQRYMARKETRATIONINFO;
|
||||
task.task_data = *pMarketRationInfo;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspQryInstrumentCommissionRate(CSecurityFtdcInstrumentCommissionRateField *pInstrumentCommissionRate, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPQRYINSTRUMENTCOMMISSIONRATE;
|
||||
task.task_data = *pInstrumentCommissionRate;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspQryETFInstrument(CSecurityFtdcETFInstrumentField *pETFInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPQRYETFINSTRUMENT;
|
||||
task.task_data = *pETFInstrument;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspQryETFBasket(CSecurityFtdcETFBasketField *pETFBasket, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPQRYETFBASKET;
|
||||
task.task_data = *pETFBasket;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspQryOFInstrument(CSecurityFtdcOFInstrumentField *pOFInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPQRYOFINSTRUMENT;
|
||||
task.task_data = *pOFInstrument;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspQrySFInstrument(CSecurityFtdcSFInstrumentField *pSFInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPQRYSFINSTRUMENT;
|
||||
task.task_data = *pSFInstrument;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspQryOrder(CSecurityFtdcOrderField *pOrder, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPQRYORDER;
|
||||
task.task_data = *pOrder;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspQryTrade(CSecurityFtdcTradeField *pTrade, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPQRYTRADE;
|
||||
task.task_data = *pTrade;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspQryInvestorPosition(CSecurityFtdcInvestorPositionField *pInvestorPosition, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPQRYINVESTORPOSITION;
|
||||
task.task_data = *pInvestorPosition;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRtnOrder(CSecurityFtdcOrderField *pOrder)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRTNORDER;
|
||||
task.task_data = *pOrder;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRtnTrade(CSecurityFtdcTradeField *pTrade)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRTNTRADE;
|
||||
task.task_data = *pTrade;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnErrRtnOrderInsert(CSecurityFtdcInputOrderField *pInputOrder, CSecurityFtdcRspInfoField *pRspInfo)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONERRRTNORDERINSERT;
|
||||
task.task_data = *pInputOrder;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnErrRtnOrderAction(CSecurityFtdcOrderActionField *pOrderAction, CSecurityFtdcRspInfoField *pRspInfo)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONERRRTNORDERACTION;
|
||||
task.task_data = *pOrderAction;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspFundOutByLiber(CSecurityFtdcInputFundTransferField *pInputFundTransfer, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPFUNDOUTBYLIBER;
|
||||
task.task_data = *pInputFundTransfer;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRtnFundOutByLiber(CSecurityFtdcFundTransferField *pFundTransfer)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRTNFUNDOUTBYLIBER;
|
||||
task.task_data = *pFundTransfer;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnErrRtnFundOutByLiber(CSecurityFtdcInputFundTransferField *pInputFundTransfer, CSecurityFtdcRspInfoField *pRspInfo)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONERRRTNFUNDOUTBYLIBER;
|
||||
task.task_data = *pInputFundTransfer;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRtnFundInByBank(CSecurityFtdcFundTransferField *pFundTransfer)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRTNFUNDINBYBANK;
|
||||
task.task_data = *pFundTransfer;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspQryFundTransferSerial(CSecurityFtdcFundTransferField *pFundTransfer, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPQRYFUNDTRANSFERSERIAL;
|
||||
task.task_data = *pFundTransfer;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspFundInterTransfer(CSecurityFtdcFundInterTransferField *pFundInterTransfer, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPFUNDINTERTRANSFER;
|
||||
task.task_data = *pFundInterTransfer;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRspQryFundInterTransferSerial(CSecurityFtdcFundInterTransferSerialField *pFundInterTransferSerial, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPQRYFUNDINTERTRANSFERSERIAL;
|
||||
task.task_data = *pFundInterTransferSerial;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnRtnFundInterTransferSerial(CSecurityFtdcFundInterTransferSerialField *pFundInterTransferSerial)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRTNFUNDINTERTRANSFERSERIAL;
|
||||
task.task_data = *pFundInterTransferSerial;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void TdApi::OnErrRtnFundInterTransfer(CSecurityFtdcFundInterTransferField *pFundInterTransfer, CSecurityFtdcRspInfoField *pRspInfo)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONERRRTNFUNDINTERTRANSFER;
|
||||
task.task_data = *pFundInterTransfer;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
32
vn.lts/vnltsmd/pyltsmd/ReadMe.txt
Normal file
32
vn.lts/vnltsmd/pyltsmd/ReadMe.txt
Normal file
@ -0,0 +1,32 @@
|
||||
========================================================================
|
||||
动态链接库:pyltsmd 项目概述
|
||||
========================================================================
|
||||
|
||||
应用程序向导已为您创建了此 pyltsmd DLL。
|
||||
|
||||
本文件概要介绍组成 pyltsmd 应用程序的每个文件的内容。
|
||||
|
||||
|
||||
pyltsmd.vcxproj
|
||||
这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。
|
||||
|
||||
pyltsmd.vcxproj.filters
|
||||
这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。
|
||||
|
||||
pyltsmd.cpp
|
||||
这是主 DLL 源文件。
|
||||
|
||||
此 DLL 在创建时不导出任何符号。因此,生成时不会产生 .lib 文件。如果希望此项目成为其他某个项目的项目依赖项,则需要添加代码以从 DLL 导出某些符号,以便产生一个导出库,或者,也可以在项目“属性页”对话框中的“链接器”文件夹中,将“常规”属性页上的“忽略输入库”属性设置为“是”。
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
其他标准文件:
|
||||
|
||||
StdAfx.h, StdAfx.cpp
|
||||
这些文件用于生成名为 pyltsmd.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
其他注释:
|
||||
|
||||
应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
19
vn.lts/vnltsmd/pyltsmd/dllmain.cpp
Normal file
19
vn.lts/vnltsmd/pyltsmd/dllmain.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
// dllmain.cpp : 定义 DLL 应用程序的入口点。
|
||||
#include "stdafx.h"
|
||||
|
||||
BOOL APIENTRY DllMain( HMODULE hModule,
|
||||
DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved
|
||||
)
|
||||
{
|
||||
switch (ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
case DLL_THREAD_ATTACH:
|
||||
case DLL_THREAD_DETACH:
|
||||
case DLL_PROCESS_DETACH:
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
8
vn.lts/vnltsmd/pyltsmd/stdafx.cpp
Normal file
8
vn.lts/vnltsmd/pyltsmd/stdafx.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
// stdafx.cpp : 只包括标准包含文件的源文件
|
||||
// pyltsmd.pch 将作为预编译头
|
||||
// stdafx.obj 将包含预编译类型信息
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: 在 STDAFX.H 中
|
||||
// 引用任何所需的附加头文件,而不是在此文件中引用
|
16
vn.lts/vnltsmd/pyltsmd/stdafx.h
Normal file
16
vn.lts/vnltsmd/pyltsmd/stdafx.h
Normal file
@ -0,0 +1,16 @@
|
||||
// stdafx.h : 标准系统包含文件的包含文件,
|
||||
// 或是经常使用但不常更改的
|
||||
// 特定于项目的包含文件
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "targetver.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的信息
|
||||
// Windows 头文件:
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
|
||||
// TODO: 在此处引用程序需要的其他头文件
|
8
vn.lts/vnltsmd/pyltsmd/targetver.h
Normal file
8
vn.lts/vnltsmd/pyltsmd/targetver.h
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
// 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。
|
||||
|
||||
// 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将
|
||||
// WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。
|
||||
|
||||
#include <SDKDDKVer.h>
|
588
vn.lts/vnltsmd/pyltsmd/vnltsmd.cpp
Normal file
588
vn.lts/vnltsmd/pyltsmd/vnltsmd.cpp
Normal file
@ -0,0 +1,588 @@
|
||||
// MdApi.cpp : 定义 DLL 应用程序的导出函数。
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "vnltsmd.h"
|
||||
|
||||
|
||||
|
||||
///-------------------------------------------------------------------------------------
|
||||
///从Python对象到C++类型转换用的函数
|
||||
///-------------------------------------------------------------------------------------
|
||||
|
||||
void getInt(dict d, string key, int *value)
|
||||
{
|
||||
if (d.has_key(key)) //检查字典中是否存在该键值
|
||||
{
|
||||
object o = d[key]; //获取该键值
|
||||
extract<int> x(o); //创建提取器
|
||||
if (x.check()) //如果可以提取
|
||||
{
|
||||
*value = x(); //对目标整数指针赋值
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void getDouble(dict d, string key, double *value)
|
||||
{
|
||||
if (d.has_key(key))
|
||||
{
|
||||
object o = d[key];
|
||||
extract<double> x(o);
|
||||
if (x.check())
|
||||
{
|
||||
*value = x();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void getChar(dict d, string key, char *value)
|
||||
{
|
||||
if (d.has_key(key))
|
||||
{
|
||||
object o = d[key];
|
||||
extract<string> x(o);
|
||||
if (x.check())
|
||||
{
|
||||
string s = x();
|
||||
const char *buffer = s.c_str();
|
||||
//对字符串指针赋值必须使用strcpy_s, vs2013使用strcpy编译通不过
|
||||
//+1应该是因为C++字符串的结尾符号?不是特别确定,不加这个1会出错
|
||||
strcpy_s(value, strlen(buffer) + 1, buffer);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
///-------------------------------------------------------------------------------------
|
||||
///C++的回调函数将数据保存到队列中
|
||||
///-------------------------------------------------------------------------------------
|
||||
|
||||
void MdApi::OnFrontConnected()
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONFRONTCONNECTED;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void MdApi::OnFrontDisconnected(int nReason)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONFRONTDISCONNECTED;
|
||||
task.task_id = nReason;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void MdApi::OnHeartBeatWarning(int nTimeLapse)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONHEARTBEATWARNING;
|
||||
task.task_id = nTimeLapse;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void MdApi::OnRspError(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPERROR;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void MdApi::OnRspUserLogin(CSecurityFtdcRspUserLoginField *pRspUserLogin, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPUSERLOGIN;
|
||||
task.task_data = *pRspUserLogin;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void MdApi::OnRspUserLogout(CSecurityFtdcUserLogoutField *pUserLogout, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPUSERLOGOUT;
|
||||
task.task_data = *pUserLogout;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void MdApi::OnRspSubMarketData(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPSUBMARKETDATA;
|
||||
task.task_data = *pSpecificInstrument;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void MdApi::OnRspUnSubMarketData(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRSPUNSUBMARKETDATA;
|
||||
task.task_data = *pSpecificInstrument;
|
||||
if (pRspInfo)
|
||||
{
|
||||
task.task_error = *pRspInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
CSecurityFtdcRspInfoField empty_error = CSecurityFtdcRspInfoField();
|
||||
memset(&empty_error, 0, sizeof(empty_error));
|
||||
task.task_error = empty_error;
|
||||
}
|
||||
task.task_id = nRequestID;
|
||||
task.task_last = bIsLast;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
void MdApi::OnRtnDepthMarketData(CSecurityFtdcDepthMarketDataField *pDepthMarketData)
|
||||
{
|
||||
Task task = Task();
|
||||
task.task_name = ONRTNDEPTHMARKETDATA;
|
||||
task.task_data = *pDepthMarketData;
|
||||
this->task_queue.push(task);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///-------------------------------------------------------------------------------------
|
||||
///工作线程从队列中取出数据,转化为python对象后,进行推送
|
||||
///-------------------------------------------------------------------------------------
|
||||
|
||||
void MdApi::processTask()
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
Task task = this->task_queue.wait_and_pop();
|
||||
|
||||
switch (task.task_name)
|
||||
{
|
||||
case ONFRONTCONNECTED:
|
||||
{
|
||||
this->processFrontConnected(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONFRONTDISCONNECTED:
|
||||
{
|
||||
this->processFrontDisconnected(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONHEARTBEATWARNING:
|
||||
{
|
||||
this->processHeartBeatWarning(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPERROR:
|
||||
{
|
||||
this->processRspError(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPUSERLOGIN:
|
||||
{
|
||||
this->processRspUserLogin(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPUSERLOGOUT:
|
||||
{
|
||||
this->processRspUserLogout(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPSUBMARKETDATA:
|
||||
{
|
||||
this->processRspSubMarketData(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRSPUNSUBMARKETDATA:
|
||||
{
|
||||
this->processRspUnSubMarketData(task);
|
||||
break;
|
||||
}
|
||||
|
||||
case ONRTNDEPTHMARKETDATA:
|
||||
{
|
||||
this->processRtnDepthMarketData(task);
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
void MdApi::processFrontConnected(Task task)
|
||||
{
|
||||
this->onFrontConnected();
|
||||
};
|
||||
|
||||
void MdApi::processFrontDisconnected(Task task)
|
||||
{
|
||||
this->onFrontDisconnected(task.task_id);
|
||||
};
|
||||
|
||||
void MdApi::processHeartBeatWarning(Task task)
|
||||
{
|
||||
this->onHeartBeatWarning(task.task_id);
|
||||
};
|
||||
|
||||
void MdApi::processRspError(Task task)
|
||||
{
|
||||
CSecurityFtdcRspInfoField task_error = any_cast<CSecurityFtdcRspInfoField>(task.task_error);
|
||||
dict error;
|
||||
error["ErrorMsg"] = task_error.ErrorMsg;
|
||||
error["ErrorID"] = task_error.ErrorID;
|
||||
|
||||
this->onRspError(error, task.task_id, task.task_last);
|
||||
};
|
||||
|
||||
void MdApi::processRspUserLogin(Task task)
|
||||
{
|
||||
CSecurityFtdcRspUserLoginField task_data = any_cast<CSecurityFtdcRspUserLoginField>(task.task_data);
|
||||
dict data;
|
||||
data["MaxOrderRef"] = task_data.MaxOrderRef;
|
||||
data["UserID"] = task_data.UserID;
|
||||
data["TradingDay"] = task_data.TradingDay;
|
||||
data["SessionID"] = task_data.SessionID;
|
||||
data["SystemName"] = task_data.SystemName;
|
||||
data["FrontID"] = task_data.FrontID;
|
||||
data["BrokerID"] = task_data.BrokerID;
|
||||
data["LoginTime"] = task_data.LoginTime;
|
||||
|
||||
CSecurityFtdcRspInfoField task_error = any_cast<CSecurityFtdcRspInfoField>(task.task_error);
|
||||
dict error;
|
||||
error["ErrorMsg"] = task_error.ErrorMsg;
|
||||
error["ErrorID"] = task_error.ErrorID;
|
||||
|
||||
this->onRspUserLogin(data, error, task.task_id, task.task_last);
|
||||
};
|
||||
|
||||
void MdApi::processRspUserLogout(Task task)
|
||||
{
|
||||
CSecurityFtdcUserLogoutField task_data = any_cast<CSecurityFtdcUserLogoutField>(task.task_data);
|
||||
dict data;
|
||||
data["UserID"] = task_data.UserID;
|
||||
data["BrokerID"] = task_data.BrokerID;
|
||||
|
||||
CSecurityFtdcRspInfoField task_error = any_cast<CSecurityFtdcRspInfoField>(task.task_error);
|
||||
dict error;
|
||||
error["ErrorMsg"] = task_error.ErrorMsg;
|
||||
error["ErrorID"] = task_error.ErrorID;
|
||||
|
||||
this->onRspUserLogout(data, error, task.task_id, task.task_last);
|
||||
};
|
||||
|
||||
void MdApi::processRspSubMarketData(Task task)
|
||||
{
|
||||
CSecurityFtdcSpecificInstrumentField task_data = any_cast<CSecurityFtdcSpecificInstrumentField>(task.task_data);
|
||||
dict data;
|
||||
data["InstrumentID"] = task_data.InstrumentID;
|
||||
data["ExchangeID"] = task_data.ExchangeID;
|
||||
|
||||
CSecurityFtdcRspInfoField task_error = any_cast<CSecurityFtdcRspInfoField>(task.task_error);
|
||||
dict error;
|
||||
error["ErrorMsg"] = task_error.ErrorMsg;
|
||||
error["ErrorID"] = task_error.ErrorID;
|
||||
|
||||
this->onRspSubMarketData(data, error, task.task_id, task.task_last);
|
||||
};
|
||||
|
||||
void MdApi::processRspUnSubMarketData(Task task)
|
||||
{
|
||||
CSecurityFtdcSpecificInstrumentField task_data = any_cast<CSecurityFtdcSpecificInstrumentField>(task.task_data);
|
||||
dict data;
|
||||
data["InstrumentID"] = task_data.InstrumentID;
|
||||
data["ExchangeID"] = task_data.ExchangeID;
|
||||
|
||||
CSecurityFtdcRspInfoField task_error = any_cast<CSecurityFtdcRspInfoField>(task.task_error);
|
||||
dict error;
|
||||
error["ErrorMsg"] = task_error.ErrorMsg;
|
||||
error["ErrorID"] = task_error.ErrorID;
|
||||
|
||||
this->onRspUnSubMarketData(data, error, task.task_id, task.task_last);
|
||||
};
|
||||
|
||||
void MdApi::processRtnDepthMarketData(Task task)
|
||||
{
|
||||
CSecurityFtdcDepthMarketDataField task_data = any_cast<CSecurityFtdcDepthMarketDataField>(task.task_data);
|
||||
dict data;
|
||||
data["HighestPrice"] = task_data.HighestPrice;
|
||||
data["BidPrice5"] = task_data.BidPrice5;
|
||||
data["BidPrice4"] = task_data.BidPrice4;
|
||||
data["BidPrice1"] = task_data.BidPrice1;
|
||||
data["BidPrice3"] = task_data.BidPrice3;
|
||||
data["BidPrice2"] = task_data.BidPrice2;
|
||||
data["LowerLimitPrice"] = task_data.LowerLimitPrice;
|
||||
data["OpenPrice"] = task_data.OpenPrice;
|
||||
data["AskPrice5"] = task_data.AskPrice5;
|
||||
data["AskPrice4"] = task_data.AskPrice4;
|
||||
data["AskPrice3"] = task_data.AskPrice3;
|
||||
data["PreClosePrice"] = task_data.PreClosePrice;
|
||||
data["AskPrice1"] = task_data.AskPrice1;
|
||||
data["PreSettlementPrice"] = task_data.PreSettlementPrice;
|
||||
data["AskVolume1"] = task_data.AskVolume1;
|
||||
data["UpdateTime"] = task_data.UpdateTime;
|
||||
data["UpdateMillisec"] = task_data.UpdateMillisec;
|
||||
data["AveragePrice"] = task_data.AveragePrice;
|
||||
data["BidVolume5"] = task_data.BidVolume5;
|
||||
data["BidVolume4"] = task_data.BidVolume4;
|
||||
data["BidVolume3"] = task_data.BidVolume3;
|
||||
data["BidVolume2"] = task_data.BidVolume2;
|
||||
data["PreOpenInterest"] = task_data.PreOpenInterest;
|
||||
data["AskPrice2"] = task_data.AskPrice2;
|
||||
data["Volume"] = task_data.Volume;
|
||||
data["AskVolume3"] = task_data.AskVolume3;
|
||||
data["AskVolume2"] = task_data.AskVolume2;
|
||||
data["AskVolume5"] = task_data.AskVolume5;
|
||||
data["AskVolume4"] = task_data.AskVolume4;
|
||||
data["UpperLimitPrice"] = task_data.UpperLimitPrice;
|
||||
data["BidVolume1"] = task_data.BidVolume1;
|
||||
data["InstrumentID"] = task_data.InstrumentID;
|
||||
data["ClosePrice"] = task_data.ClosePrice;
|
||||
data["ExchangeID"] = task_data.ExchangeID;
|
||||
data["TradingDay"] = task_data.TradingDay;
|
||||
data["PreDelta"] = task_data.PreDelta;
|
||||
data["OpenInterest"] = task_data.OpenInterest;
|
||||
data["CurrDelta"] = task_data.CurrDelta;
|
||||
data["Turnover"] = task_data.Turnover;
|
||||
data["LastPrice"] = task_data.LastPrice;
|
||||
data["SettlementPrice"] = task_data.SettlementPrice;
|
||||
data["ExchangeInstID"] = task_data.ExchangeInstID;
|
||||
data["LowestPrice"] = task_data.LowestPrice;
|
||||
data["ActionDay"] = task_data.ActionDay;
|
||||
|
||||
this->onRtnDepthMarketData(data);
|
||||
};
|
||||
|
||||
|
||||
|
||||
///-------------------------------------------------------------------------------------
|
||||
///主动函数
|
||||
///-------------------------------------------------------------------------------------
|
||||
|
||||
void MdApi::createFtdcMdApi(string pszFlowPath)
|
||||
{
|
||||
this->api = CSecurityFtdcMdApi::CreateFtdcMdApi(pszFlowPath.c_str());
|
||||
this->api->RegisterSpi(this);
|
||||
};
|
||||
|
||||
void MdApi::release()
|
||||
{
|
||||
this->api->Release();
|
||||
};
|
||||
|
||||
void MdApi::init()
|
||||
{
|
||||
this->api->Init();
|
||||
};
|
||||
|
||||
int MdApi::join()
|
||||
{
|
||||
int i = this->api->Join();
|
||||
return i;
|
||||
};
|
||||
|
||||
string MdApi::getTradingDay()
|
||||
{
|
||||
string day = this->api->GetTradingDay();
|
||||
return day;
|
||||
};
|
||||
|
||||
void MdApi::registerFront(string pszFrontAddress)
|
||||
{
|
||||
this->api->RegisterFront((char*)pszFrontAddress.c_str());
|
||||
};
|
||||
|
||||
int MdApi::subscribeMarketData(dict req)
|
||||
{
|
||||
char instrumentID[256];
|
||||
char exchangeID[256];
|
||||
getChar(req, "InstrumentID", instrumentID);
|
||||
getChar(req, "ExchangeID", exchangeID);
|
||||
char* myreq[1] = { instrumentID };
|
||||
int i = this->api->SubscribeMarketData(myreq, 1, exchangeID);
|
||||
return i;
|
||||
};
|
||||
|
||||
int MdApi::unSubscribeMarketData(dict req)
|
||||
{
|
||||
char instrumentID[256];
|
||||
char exchangeID[256];
|
||||
getChar(req, "InstrumentID", instrumentID);
|
||||
getChar(req, "ExchangeID", exchangeID);
|
||||
char* myreq[1] = { instrumentID };
|
||||
int i = this->api->UnSubscribeMarketData(myreq, 1, exchangeID);
|
||||
return i;
|
||||
};
|
||||
|
||||
int MdApi::reqUserLogin(dict req, int nRequestID)
|
||||
{
|
||||
CSecurityFtdcReqUserLoginField myreq = CSecurityFtdcReqUserLoginField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "MacAddress", myreq.MacAddress);
|
||||
getChar(req, "UserProductInfo", myreq.UserProductInfo);
|
||||
getChar(req, "UserID", myreq.UserID);
|
||||
getChar(req, "AuthCode", myreq.AuthCode);
|
||||
getChar(req, "TradingDay", myreq.TradingDay);
|
||||
getChar(req, "InterfaceProductInfo", myreq.InterfaceProductInfo);
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
getChar(req, "ClientIPAddress", myreq.ClientIPAddress);
|
||||
getChar(req, "OneTimePassword", myreq.OneTimePassword);
|
||||
getChar(req, "ProtocolInfo", myreq.ProtocolInfo);
|
||||
getChar(req, "Password", myreq.Password);
|
||||
int i = this->api->ReqUserLogin(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
int MdApi::reqUserLogout(dict req, int nRequestID)
|
||||
{
|
||||
CSecurityFtdcUserLogoutField myreq = CSecurityFtdcUserLogoutField();
|
||||
memset(&myreq, 0, sizeof(myreq));
|
||||
getChar(req, "UserID", myreq.UserID);
|
||||
getChar(req, "BrokerID", myreq.BrokerID);
|
||||
int i = this->api->ReqUserLogout(&myreq, nRequestID);
|
||||
return i;
|
||||
};
|
||||
|
||||
|
||||
|
||||
///-------------------------------------------------------------------------------------
|
||||
///Boost.Python封装
|
||||
///-------------------------------------------------------------------------------------
|
||||
|
||||
struct MdApiWrap : MdApi, wrapper < MdApi >
|
||||
{
|
||||
virtual void onFrontConnected()
|
||||
{
|
||||
PyLock lock;
|
||||
this->get_override("onFrontConnected")();
|
||||
};
|
||||
|
||||
virtual void onFrontDisconnected(int i)
|
||||
{
|
||||
PyLock lock;
|
||||
this->get_override("onFrontDisconnected")(i);
|
||||
};
|
||||
|
||||
virtual void onHeartBeatWarning(int i)
|
||||
{
|
||||
PyLock lock;
|
||||
this->get_override("onHeartBeatWarning")(i);
|
||||
};
|
||||
|
||||
virtual void onRspError(dict data, int id, bool last)
|
||||
{
|
||||
PyLock lock;
|
||||
this->get_override("onRspError")(data, id, last);
|
||||
};
|
||||
|
||||
virtual void onRspUserLogin(dict data, dict error, int id, bool last)
|
||||
{
|
||||
PyLock lock;
|
||||
this->get_override("onRspUserLogin")(data, error, id, last);
|
||||
};
|
||||
|
||||
virtual void onRspUserLogout(dict data, dict error, int id, bool last)
|
||||
{
|
||||
PyLock lock;
|
||||
this->get_override("onRspUserLogout")(data, error, id, last);
|
||||
};
|
||||
|
||||
virtual void onRspSubMarketData(dict data, dict error, int id, bool last)
|
||||
{
|
||||
PyLock lock;
|
||||
this->get_override("onRspSubMarketData")(data, error, id, last);
|
||||
};
|
||||
|
||||
virtual void onRspUnSubMarketData(dict data, dict error, int id, bool last)
|
||||
{
|
||||
PyLock lock;
|
||||
this->get_override("onRspUnSubMarketData")(data, error, id, last);
|
||||
};
|
||||
|
||||
virtual void onRtnDepthMarketData(dict data)
|
||||
{
|
||||
PyLock lock;
|
||||
this->get_override("onRtnDepthMarketData")(data);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
BOOST_PYTHON_MODULE(vnltsmd)
|
||||
{
|
||||
PyEval_InitThreads(); //导入时运行,保证先创建GIL
|
||||
|
||||
class_<MdApiWrap, boost::noncopyable>("MdApi")
|
||||
.def("createFtdcMdApi", &MdApiWrap::createFtdcMdApi)
|
||||
.def("release", &MdApiWrap::release)
|
||||
.def("init", &MdApiWrap::init)
|
||||
.def("join", &MdApiWrap::join)
|
||||
.def("getTradingDay", &MdApiWrap::getTradingDay)
|
||||
.def("registerFront", &MdApiWrap::registerFront)
|
||||
.def("subscribeMarketData", &MdApiWrap::subscribeMarketData)
|
||||
.def("unSubscribeMarketData", &MdApiWrap::unSubscribeMarketData)
|
||||
.def("reqUserLogin", &MdApiWrap::reqUserLogin)
|
||||
.def("reqUserLogout", &MdApiWrap::reqUserLogout)
|
||||
|
||||
.def("onFrontConnected", pure_virtual(&MdApiWrap::onFrontConnected))
|
||||
.def("onFrontDisconnected", pure_virtual(&MdApiWrap::onFrontDisconnected))
|
||||
.def("onHeartBeatWarning", pure_virtual(&MdApiWrap::onHeartBeatWarning))
|
||||
.def("onRspError", pure_virtual(&MdApiWrap::onRspError))
|
||||
.def("onRspUserLogin", pure_virtual(&MdApiWrap::onRspUserLogin))
|
||||
.def("onRspUserLogout", pure_virtual(&MdApiWrap::onRspUserLogout))
|
||||
.def("onRspSubMarketData", pure_virtual(&MdApiWrap::onRspSubMarketData))
|
||||
.def("onRspUnSubMarketData", pure_virtual(&MdApiWrap::onRspUnSubMarketData))
|
||||
.def("onRtnDepthMarketData", pure_virtual(&MdApiWrap::onRtnDepthMarketData))
|
||||
;
|
||||
};
|
272
vn.lts/vnltsmd/pyltsmd/vnltsmd.h
Normal file
272
vn.lts/vnltsmd/pyltsmd/vnltsmd.h
Normal file
@ -0,0 +1,272 @@
|
||||
//说明部分
|
||||
|
||||
//系统
|
||||
#include "stdafx.h"
|
||||
#include <string>
|
||||
#include <queue>
|
||||
|
||||
//Boost
|
||||
#define BOOST_PYTHON_STATIC_LIB
|
||||
#include <boost/python/module.hpp> //python封装
|
||||
#include <boost/python/def.hpp> //python封装
|
||||
#include <boost/python/dict.hpp> //python封装
|
||||
#include <boost/python/object.hpp> //python封装
|
||||
#include <boost/python.hpp> //python封装
|
||||
#include <boost/thread.hpp> //任务队列的线程功能
|
||||
#include <boost/bind.hpp> //任务队列的线程功能
|
||||
#include <boost/any.hpp> //任务队列的任务实现
|
||||
|
||||
//API
|
||||
#include "SecurityFtdcMdApi.h"
|
||||
|
||||
//命名空间
|
||||
using namespace std;
|
||||
using namespace boost::python;
|
||||
using namespace boost;
|
||||
|
||||
//常量
|
||||
#define ONFRONTCONNECTED 0
|
||||
#define ONFRONTDISCONNECTED 1
|
||||
#define ONHEARTBEATWARNING 2
|
||||
#define ONRSPERROR 3
|
||||
#define ONRSPUSERLOGIN 4
|
||||
#define ONRSPUSERLOGOUT 5
|
||||
#define ONRSPSUBMARKETDATA 6
|
||||
#define ONRSPUNSUBMARKETDATA 7
|
||||
#define ONRTNDEPTHMARKETDATA 8
|
||||
#define EXIT 0
|
||||
|
||||
|
||||
///-------------------------------------------------------------------------------------
|
||||
///API中的部分组件
|
||||
///-------------------------------------------------------------------------------------
|
||||
|
||||
//GIL全局锁简化获取用,
|
||||
//用于帮助C++线程获得GIL锁,从而防止python崩溃
|
||||
class PyLock
|
||||
{
|
||||
private:
|
||||
PyGILState_STATE gil_state;
|
||||
|
||||
public:
|
||||
//在某个函数方法中创建该对象时,获得GIL锁
|
||||
PyLock()
|
||||
{
|
||||
gil_state = PyGILState_Ensure();
|
||||
}
|
||||
|
||||
//在某个函数完成后销毁该对象时,解放GIL锁
|
||||
~PyLock()
|
||||
{
|
||||
PyGILState_Release(gil_state);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//任务结构体
|
||||
struct Task
|
||||
{
|
||||
int task_name; //回调函数名称对应的常量
|
||||
any task_data; //数据结构体
|
||||
any task_error; //错误结构体
|
||||
int task_id; //请求id
|
||||
bool task_last; //是否为最后返回
|
||||
};
|
||||
|
||||
|
||||
///线程安全的队列
|
||||
template<typename Data>
|
||||
|
||||
class ConcurrentQueue
|
||||
{
|
||||
private:
|
||||
queue<Data> the_queue; //标准库队列
|
||||
mutable mutex the_mutex; //boost互斥锁
|
||||
condition_variable the_condition_variable; //boost条件变量
|
||||
|
||||
public:
|
||||
|
||||
//存入新的任务
|
||||
void push(Data const& data)
|
||||
{
|
||||
mutex::scoped_lock lock(the_mutex); //获取互斥锁
|
||||
the_queue.push(data); //向队列中存入数据
|
||||
lock.unlock(); //释放锁
|
||||
the_condition_variable.notify_one(); //通知正在阻塞等待的线程
|
||||
}
|
||||
|
||||
//检查队列是否为空
|
||||
bool empty() const
|
||||
{
|
||||
mutex::scoped_lock lock(the_mutex);
|
||||
return the_queue.empty();
|
||||
}
|
||||
|
||||
//取出
|
||||
Data wait_and_pop()
|
||||
{
|
||||
mutex::scoped_lock lock(the_mutex);
|
||||
|
||||
while (the_queue.empty()) //当队列为空时
|
||||
{
|
||||
the_condition_variable.wait(lock); //等待条件变量通知
|
||||
}
|
||||
|
||||
Data popped_value = the_queue.front(); //获取队列中的最后一个任务
|
||||
the_queue.pop(); //删除该任务
|
||||
return popped_value; //返回该任务
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
//从字典中获取某个建值对应的整数,并赋值到请求结构体对象的值上
|
||||
void getInt(dict d, string key, int* value);
|
||||
|
||||
|
||||
//从字典中获取某个建值对应的浮点数,并赋值到请求结构体对象的值上
|
||||
void getDouble(dict d, string key, double* value);
|
||||
|
||||
|
||||
//从字典中获取某个建值对应的字符串,并赋值到请求结构体对象的值上
|
||||
void getChar(dict d, string key, char* value);
|
||||
|
||||
|
||||
|
||||
///-------------------------------------------------------------------------------------
|
||||
///C++ SPI的回调函数方法实现
|
||||
///-------------------------------------------------------------------------------------
|
||||
|
||||
//API的继承实现
|
||||
class MdApi : public CSecurityFtdcMdSpi
|
||||
{
|
||||
private:
|
||||
CSecurityFtdcMdApi* api; //API对象
|
||||
thread *task_thread; //工作线程指针(向python中推送数据)
|
||||
ConcurrentQueue<Task> task_queue; //任务队列
|
||||
|
||||
public:
|
||||
MdApi()
|
||||
{
|
||||
function0<void> f = boost::bind(&MdApi::processTask, this);
|
||||
thread t(f);
|
||||
this->task_thread = &t;
|
||||
};
|
||||
|
||||
~MdApi()
|
||||
{
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//API回调函数
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
//当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
|
||||
virtual void OnFrontConnected();
|
||||
|
||||
//当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
|
||||
//@param nReason 错误原因
|
||||
// 0x1001 网络读失败
|
||||
// 0x1002 网络写失败
|
||||
// 0x2001 接收心跳超时
|
||||
// 0x2002 发送心跳失败
|
||||
// 0x2003 收到错误报文
|
||||
virtual void OnFrontDisconnected(int nReason);
|
||||
|
||||
//心跳超时警告。当长时间未收到报文时,该方法被调用。
|
||||
//@param nTimeLapse 距离上次接收报文的时间
|
||||
virtual void OnHeartBeatWarning(int nTimeLapse);
|
||||
|
||||
//错误应答
|
||||
virtual void OnRspError(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
//登录请求响应
|
||||
virtual void OnRspUserLogin(CSecurityFtdcRspUserLoginField *pRspUserLogin, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
//登出请求响应
|
||||
virtual void OnRspUserLogout(CSecurityFtdcUserLogoutField *pUserLogout, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
//订阅行情应答
|
||||
virtual void OnRspSubMarketData(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
//取消订阅行情应答
|
||||
virtual void OnRspUnSubMarketData(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
//深度行情通知
|
||||
virtual void OnRtnDepthMarketData(CSecurityFtdcDepthMarketDataField *pDepthMarketData);
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//task:任务
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
void processTask();
|
||||
|
||||
void processFrontConnected(Task task);
|
||||
|
||||
void processFrontDisconnected(Task task);
|
||||
|
||||
void processHeartBeatWarning(Task task);
|
||||
|
||||
void processRspError(Task task);
|
||||
|
||||
void processRspUserLogin(Task task);
|
||||
|
||||
void processRspUserLogout(Task task);
|
||||
|
||||
void processRspSubMarketData(Task task);
|
||||
|
||||
void processRspUnSubMarketData(Task task);
|
||||
|
||||
void processRtnDepthMarketData(Task task);
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//data:回调函数的数据字典
|
||||
//error:回调函数的错误字典
|
||||
//id:请求id
|
||||
//last:是否为最后返回
|
||||
//i:整数
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
virtual void onFrontConnected(){};
|
||||
|
||||
virtual void onFrontDisconnected(int i){};
|
||||
|
||||
virtual void onHeartBeatWarning(int i){};
|
||||
|
||||
virtual void onRspError(dict data, int id, bool last) {};
|
||||
|
||||
virtual void onRspUserLogin(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspUserLogout(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspSubMarketData(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspUnSubMarketData(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRtnDepthMarketData(dict data) {};
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//req:主动函数的请求字典
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
void createFtdcMdApi(string pszFlowPath = "");
|
||||
|
||||
void release();
|
||||
|
||||
void init();
|
||||
|
||||
int join();
|
||||
|
||||
string getTradingDay();
|
||||
|
||||
void registerFront(string pszFrontAddress);
|
||||
|
||||
int subscribeMarketData(dict req);
|
||||
|
||||
int unSubscribeMarketData(dict req);
|
||||
|
||||
int reqUserLogin(dict req, int nRequestID);
|
||||
|
||||
int reqUserLogout(dict req, int nRequestID);
|
||||
};
|
151
vn.lts/vnltsmd/test/mdtest.py
Normal file
151
vn.lts/vnltsmd/test/mdtest.py
Normal file
@ -0,0 +1,151 @@
|
||||
# encoding = UTF-8
|
||||
|
||||
import sys
|
||||
from time import sleep
|
||||
|
||||
from PyQt4 import QtGui
|
||||
|
||||
from vnltsmd import *
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def print_dict(d):
|
||||
"""按照键值打印一个字典"""
|
||||
for key,value in d.items():
|
||||
print key + ':' + str(value)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def simple_log(func):
|
||||
"""简单装饰器用于输出函数名"""
|
||||
def wrapper(*args, **kw):
|
||||
print ""
|
||||
print str(func.__name__)
|
||||
return func(*args, **kw)
|
||||
return wrapper
|
||||
|
||||
|
||||
########################################################################
|
||||
class TestMdApi(MdApi):
|
||||
"""测试用实例"""
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def __init__(self):
|
||||
"""Constructor"""
|
||||
super(TestMdApi, self).__init__()
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@simple_log
|
||||
def onFrontConnected(self):
|
||||
"""服务器连接"""
|
||||
pass
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@simple_log
|
||||
def onFrontDisconnected(self, n):
|
||||
"""服务器断开"""
|
||||
print n
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@simple_log
|
||||
def onHeartBeatWarning(self, n):
|
||||
"""心跳报警"""
|
||||
print n
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@simple_log
|
||||
def onRspError(self, error, n, last):
|
||||
"""错误"""
|
||||
print_dict(error)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def onRspUserLogin(self, data, error, n, last):
|
||||
"""登陆回报"""
|
||||
print_dict(data)
|
||||
print_dict(error)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@simple_log
|
||||
def onRspUserLogout(self, data, error, n, last):
|
||||
"""登出回报"""
|
||||
print_dict(data)
|
||||
print_dict(error)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@simple_log
|
||||
def onRspSubMarketData(self, data, error, n, last):
|
||||
"""订阅合约回报"""
|
||||
print_dict(data)
|
||||
print_dict(error)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@simple_log
|
||||
def onRspUnSubMarketData(self, data, error, n, last):
|
||||
"""退订合约回报"""
|
||||
print_dict(data)
|
||||
print_dict(error)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@simple_log
|
||||
def onRtnDepthMarketData(self, data):
|
||||
"""行情推送"""
|
||||
print_dict(data)
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def main():
|
||||
"""主测试函数,出现堵塞时可以考虑使用sleep"""
|
||||
reqid = 0
|
||||
|
||||
# 创建Qt应用对象,用于事件循环
|
||||
app = QtGui.QApplication(sys.argv)
|
||||
|
||||
# 创建API对象
|
||||
api = TestMdApi()
|
||||
|
||||
# 在C++环境中创建MdApi对象,传入参数是希望用来保存.con文件的地址
|
||||
api.createFtdcMdApi('')
|
||||
|
||||
# 注册前置机地址
|
||||
api.registerFront("tcp://101.231.210.1:24513")
|
||||
|
||||
# 初始化api,连接前置机
|
||||
api.init()
|
||||
sleep(0.5)
|
||||
|
||||
# 登陆
|
||||
loginReq = {} # 创建一个空字典
|
||||
loginReq['UserID'] = '' # 参数作为字典键值的方式传入
|
||||
loginReq['Password'] = '' # 键名和C++中的结构体成员名对应
|
||||
loginReq['BrokerID'] = '2011'
|
||||
reqid = reqid + 1 # 请求数必须保持唯一性
|
||||
i = api.reqUserLogin(loginReq, 1)
|
||||
sleep(0.5)
|
||||
|
||||
## 登出
|
||||
#reqid = reqid + 1
|
||||
#i = api.reqUserLogout({}, 1)
|
||||
#sleep(0.5)
|
||||
|
||||
# 获取交易日,目前输出为空
|
||||
#day = api.getTradingDay()
|
||||
#print 'Trading Day is:' + str(day)
|
||||
#sleep(0.5)
|
||||
|
||||
# 订阅合约
|
||||
subReq = {}
|
||||
subReq['InstrumentID'] = '600600'
|
||||
subReq['ExchangeID'] = 'SSE'
|
||||
i = api.subscribeMarketData(subReq)
|
||||
|
||||
## 退订合约
|
||||
#i = api.unSubscribeMarketData(subReq)
|
||||
|
||||
# 连续运行,用于输出行情
|
||||
app.exec_()
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
BIN
vn.lts/vnltsmd/test/securitymduserapi.dll
Normal file
BIN
vn.lts/vnltsmd/test/securitymduserapi.dll
Normal file
Binary file not shown.
BIN
vn.lts/vnltsmd/test/vnltsmd.pyd
Normal file
BIN
vn.lts/vnltsmd/test/vnltsmd.pyd
Normal file
Binary file not shown.
BIN
vn.lts/vnltstd/PythonTest/securitytraderapi.dll
Normal file
BIN
vn.lts/vnltstd/PythonTest/securitytraderapi.dll
Normal file
Binary file not shown.
83
vn.lts/vnltstd/PythonTest/test.py
Normal file
83
vn.lts/vnltstd/PythonTest/test.py
Normal file
@ -0,0 +1,83 @@
|
||||
# encoding = UTF-8
|
||||
|
||||
from PyQt4 import QtGui
|
||||
import sys
|
||||
from time import sleep
|
||||
|
||||
from vnltstd import *
|
||||
|
||||
def printdict(error):
|
||||
for key, value in error.items():
|
||||
print key + ':' + str(value)
|
||||
|
||||
class MyTdApi(TdApi):
|
||||
def __init__(self):
|
||||
super(MyTdApi, self).__init__()
|
||||
|
||||
def onFrontConnected(self):
|
||||
print 'connected'
|
||||
|
||||
def onFrontDisconnected(self, i):
|
||||
print 'disconnected'
|
||||
|
||||
def onHeartBeatWarning(self, i):
|
||||
print 'heartbeat'
|
||||
|
||||
def onRspError(self, data, id_, last):
|
||||
print 'error'
|
||||
print data
|
||||
|
||||
def onRspUserLogin(self, data, error, id_, last) :
|
||||
print 'login'
|
||||
printdict(data)
|
||||
printdict(error)
|
||||
|
||||
|
||||
def onRspUserLogout(self, data, error, id_, last):
|
||||
print 'logout'
|
||||
printdict(data)
|
||||
printdict(error)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def onRspQryInstrument(self, data, error, id_, last):
|
||||
""""""
|
||||
printdict(data)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def onRspQryInvestor(self, data, error, id_, last):
|
||||
""""""
|
||||
printdict(data)
|
||||
|
||||
def main():
|
||||
|
||||
app = QtGui.QApplication(sys.argv)
|
||||
|
||||
api = MyTdApi()
|
||||
api.createFtdcTraderApi('')
|
||||
|
||||
api.registerFront("tcp://101.231.210.1:24505")
|
||||
api.init()
|
||||
sleep(1.0)
|
||||
|
||||
lgreq = {}
|
||||
lgreq['UserID'] = '010000058678'
|
||||
lgreq['Password'] = '0656032'
|
||||
lgreq['BrokerID'] = '2011'
|
||||
i = api.reqUserLogin(lgreq, 1)
|
||||
print i
|
||||
sleep(1.0)
|
||||
|
||||
#req2 = {}
|
||||
#req2['InstrumentID'] = '600600'
|
||||
#req2['ExchangeID'] = 'SSE'
|
||||
#api.subscribeMarketData(req2)
|
||||
|
||||
ireq = {}
|
||||
#a = api.reqQryInstrument(ireq, 3)
|
||||
b = api.reqQryInvestor(ireq, 3)
|
||||
#print 'a is:'+ str(a)
|
||||
|
||||
app.exec_()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
BIN
vn.lts/vnltstd/PythonTest/vnltstd.pyd
Normal file
BIN
vn.lts/vnltstd/PythonTest/vnltstd.pyd
Normal file
Binary file not shown.
BIN
vn.lts/vnltstd/pyltstd.opensdf
Normal file
BIN
vn.lts/vnltstd/pyltstd.opensdf
Normal file
Binary file not shown.
32
vn.lts/vnltstd/pyltstd/ReadMe.txt
Normal file
32
vn.lts/vnltstd/pyltstd/ReadMe.txt
Normal file
@ -0,0 +1,32 @@
|
||||
========================================================================
|
||||
动态链接库:pyltstd 项目概述
|
||||
========================================================================
|
||||
|
||||
应用程序向导已为您创建了此 pyltstd DLL。
|
||||
|
||||
本文件概要介绍组成 pyltstd 应用程序的每个文件的内容。
|
||||
|
||||
|
||||
pyltstd.vcxproj
|
||||
这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。
|
||||
|
||||
pyltstd.vcxproj.filters
|
||||
这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。
|
||||
|
||||
pyltstd.cpp
|
||||
这是主 DLL 源文件。
|
||||
|
||||
此 DLL 在创建时不导出任何符号。因此,生成时不会产生 .lib 文件。如果希望此项目成为其他某个项目的项目依赖项,则需要添加代码以从 DLL 导出某些符号,以便产生一个导出库,或者,也可以在项目“属性页”对话框中的“链接器”文件夹中,将“常规”属性页上的“忽略输入库”属性设置为“是”。
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
其他标准文件:
|
||||
|
||||
StdAfx.h, StdAfx.cpp
|
||||
这些文件用于生成名为 pyltstd.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
其他注释:
|
||||
|
||||
应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
19
vn.lts/vnltstd/pyltstd/dllmain.cpp
Normal file
19
vn.lts/vnltstd/pyltstd/dllmain.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
// dllmain.cpp : 定义 DLL 应用程序的入口点。
|
||||
#include "stdafx.h"
|
||||
|
||||
BOOL APIENTRY DllMain( HMODULE hModule,
|
||||
DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved
|
||||
)
|
||||
{
|
||||
switch (ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
case DLL_THREAD_ATTACH:
|
||||
case DLL_THREAD_DETACH:
|
||||
case DLL_PROCESS_DETACH:
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
8
vn.lts/vnltstd/pyltstd/stdafx.cpp
Normal file
8
vn.lts/vnltstd/pyltstd/stdafx.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
// stdafx.cpp : 只包括标准包含文件的源文件
|
||||
// pyltstd.pch 将作为预编译头
|
||||
// stdafx.obj 将包含预编译类型信息
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: 在 STDAFX.H 中
|
||||
// 引用任何所需的附加头文件,而不是在此文件中引用
|
16
vn.lts/vnltstd/pyltstd/stdafx.h
Normal file
16
vn.lts/vnltstd/pyltstd/stdafx.h
Normal file
@ -0,0 +1,16 @@
|
||||
// stdafx.h : 标准系统包含文件的包含文件,
|
||||
// 或是经常使用但不常更改的
|
||||
// 特定于项目的包含文件
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "targetver.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的信息
|
||||
// Windows 头文件:
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
|
||||
// TODO: 在此处引用程序需要的其他头文件
|
8
vn.lts/vnltstd/pyltstd/targetver.h
Normal file
8
vn.lts/vnltstd/pyltstd/targetver.h
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
// 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。
|
||||
|
||||
// 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将
|
||||
// WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。
|
||||
|
||||
#include <SDKDDKVer.h>
|
2841
vn.lts/vnltstd/pyltstd/vnltstd.cpp
Normal file
2841
vn.lts/vnltstd/pyltstd/vnltstd.cpp
Normal file
File diff suppressed because it is too large
Load Diff
558
vn.lts/vnltstd/pyltstd/vnltstd.h
Normal file
558
vn.lts/vnltstd/pyltstd/vnltstd.h
Normal file
@ -0,0 +1,558 @@
|
||||
//说明部分
|
||||
|
||||
//系统
|
||||
#include "stdafx.h"
|
||||
#include <string>
|
||||
#include <queue>
|
||||
|
||||
//Boost
|
||||
#define BOOST_PYTHON_STATIC_LIB
|
||||
#include <boost/python/module.hpp> //python封装
|
||||
#include <boost/python/def.hpp> //python封装
|
||||
#include <boost/python/dict.hpp> //python封装
|
||||
#include <boost/python/object.hpp> //python封装
|
||||
#include <boost/python.hpp> //python封装
|
||||
#include <boost/thread.hpp> //任务队列的线程功能
|
||||
#include <boost/bind.hpp> //任务队列的线程功能
|
||||
#include <boost/any.hpp> //任务队列的任务实现
|
||||
|
||||
//API
|
||||
#include "SecurityFtdcTraderApi.h"
|
||||
|
||||
//命名空间
|
||||
using namespace std;
|
||||
using namespace boost::python;
|
||||
using namespace boost;
|
||||
|
||||
//常量
|
||||
#define ONFRONTCONNECTED 1
|
||||
#define ONFRONTDISCONNECTED 2
|
||||
#define ONHEARTBEATWARNING 3
|
||||
#define ONRSPERROR 4
|
||||
#define ONRSPUSERLOGIN 5
|
||||
#define ONRSPUSERLOGOUT 6
|
||||
#define ONRSPORDERINSERT 7
|
||||
#define ONRSPORDERACTION 8
|
||||
#define ONRSPUSERPASSWORDUPDATE 9
|
||||
#define ONRSPTRADINGACCOUNTPASSWORDUPDATE 10
|
||||
#define ONRSPQRYEXCHANGE 11
|
||||
#define ONRSPQRYINSTRUMENT 12
|
||||
#define ONRSPQRYINVESTOR 13
|
||||
#define ONRSPQRYTRADINGCODE 14
|
||||
#define ONRSPQRYTRADINGACCOUNT 15
|
||||
#define ONRSPQRYDEPTHMARKETDATA 16
|
||||
#define ONRSPQRYBONDINTEREST 17
|
||||
#define ONRSPQRYMARKETRATIONINFO 18
|
||||
#define ONRSPQRYINSTRUMENTCOMMISSIONRATE 19
|
||||
#define ONRSPQRYETFINSTRUMENT 20
|
||||
#define ONRSPQRYETFBASKET 21
|
||||
#define ONRSPQRYOFINSTRUMENT 22
|
||||
#define ONRSPQRYSFINSTRUMENT 23
|
||||
#define ONRSPQRYORDER 24
|
||||
#define ONRSPQRYTRADE 25
|
||||
#define ONRSPQRYINVESTORPOSITION 26
|
||||
#define ONRTNORDER 27
|
||||
#define ONRTNTRADE 28
|
||||
#define ONERRRTNORDERINSERT 29
|
||||
#define ONERRRTNORDERACTION 30
|
||||
#define ONRSPFUNDOUTBYLIBER 31
|
||||
#define ONRTNFUNDOUTBYLIBER 32
|
||||
#define ONERRRTNFUNDOUTBYLIBER 33
|
||||
#define ONRTNFUNDINBYBANK 34
|
||||
#define ONRSPQRYFUNDTRANSFERSERIAL 35
|
||||
#define ONRSPFUNDINTERTRANSFER 36
|
||||
#define ONRSPQRYFUNDINTERTRANSFERSERIAL 37
|
||||
#define ONRTNFUNDINTERTRANSFERSERIAL 38
|
||||
#define ONERRRTNFUNDINTERTRANSFER 39
|
||||
|
||||
|
||||
///-------------------------------------------------------------------------------------
|
||||
///API中的部分组件
|
||||
///-------------------------------------------------------------------------------------
|
||||
|
||||
//GIL全局锁简化获取用,
|
||||
//用于帮助C++线程获得GIL锁,从而防止python崩溃
|
||||
class PyLock
|
||||
{
|
||||
private:
|
||||
PyGILState_STATE gil_state;
|
||||
|
||||
public:
|
||||
//在某个函数方法中创建该对象时,获得GIL锁
|
||||
PyLock()
|
||||
{
|
||||
gil_state = PyGILState_Ensure();
|
||||
}
|
||||
|
||||
//在某个函数完成后销毁该对象时,解放GIL锁
|
||||
~PyLock()
|
||||
{
|
||||
PyGILState_Release(gil_state);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//任务结构体
|
||||
struct Task
|
||||
{
|
||||
int task_name; //回调函数名称对应的常量
|
||||
any task_data; //数据结构体
|
||||
any task_error; //错误结构体
|
||||
int task_id; //请求id
|
||||
bool task_last; //是否为最后返回
|
||||
};
|
||||
|
||||
|
||||
///线程安全的队列
|
||||
template<typename Data>
|
||||
|
||||
class ConcurrentQueue
|
||||
{
|
||||
private:
|
||||
queue<Data> the_queue; //标准库队列
|
||||
mutable mutex the_mutex; //boost互斥锁
|
||||
condition_variable the_condition_variable; //boost条件变量
|
||||
|
||||
public:
|
||||
|
||||
//存入新的任务
|
||||
void push(Data const& data)
|
||||
{
|
||||
mutex::scoped_lock lock(the_mutex); //获取互斥锁
|
||||
the_queue.push(data); //向队列中存入数据
|
||||
lock.unlock(); //释放锁
|
||||
the_condition_variable.notify_one(); //通知正在阻塞等待的线程
|
||||
}
|
||||
|
||||
//检查队列是否为空
|
||||
bool empty() const
|
||||
{
|
||||
mutex::scoped_lock lock(the_mutex);
|
||||
return the_queue.empty();
|
||||
}
|
||||
|
||||
//取出
|
||||
Data wait_and_pop()
|
||||
{
|
||||
mutex::scoped_lock lock(the_mutex);
|
||||
|
||||
while (the_queue.empty()) //当队列为空时
|
||||
{
|
||||
the_condition_variable.wait(lock); //等待条件变量通知
|
||||
}
|
||||
|
||||
Data popped_value = the_queue.front(); //获取队列中的最后一个任务
|
||||
the_queue.pop(); //删除该任务
|
||||
return popped_value; //返回该任务
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
//从字典中获取某个建值对应的整数,并赋值到请求结构体对象的值上
|
||||
void getInt(dict d, string key, int* value);
|
||||
|
||||
|
||||
//从字典中获取某个建值对应的浮点数,并赋值到请求结构体对象的值上
|
||||
void getDouble(dict d, string key, double* value);
|
||||
|
||||
|
||||
//从字典中获取某个建值对应的字符串,并赋值到请求结构体对象的值上
|
||||
void getChar(dict d, string key, char* value);
|
||||
|
||||
|
||||
|
||||
///-------------------------------------------------------------------------------------
|
||||
///C++ SPI的回调函数方法实现
|
||||
///-------------------------------------------------------------------------------------
|
||||
|
||||
//API的继承实现
|
||||
class TdApi : public CSecurityFtdcTraderSpi
|
||||
{
|
||||
private:
|
||||
CSecurityFtdcTraderApi* api; //API对象
|
||||
thread *task_thread; //工作线程指针(向python中推送数据)
|
||||
ConcurrentQueue<Task> task_queue; //任务队列
|
||||
|
||||
public:
|
||||
TdApi()
|
||||
{
|
||||
function0<void> f = boost::bind(&TdApi::processTask, this);
|
||||
thread t(f);
|
||||
this->task_thread = &t;
|
||||
};
|
||||
|
||||
~TdApi()
|
||||
{
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//API回调函数
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
///当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
|
||||
virtual void OnFrontConnected();
|
||||
|
||||
///当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
|
||||
///@param nReason 错误原因
|
||||
/// 0x1001 网络读失败
|
||||
/// 0x1002 网络写失败
|
||||
/// 0x2001 接收心跳超时
|
||||
/// 0x2002 发送心跳失败
|
||||
/// 0x2003 收到错误报文
|
||||
virtual void OnFrontDisconnected(int nReason);
|
||||
|
||||
///心跳超时警告。当长时间未收到报文时,该方法被调用。
|
||||
///@param nTimeLapse 距离上次接收报文的时间
|
||||
virtual void OnHeartBeatWarning(int nTimeLapse);
|
||||
|
||||
///错误应答
|
||||
virtual void OnRspError(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///登录请求响应
|
||||
virtual void OnRspUserLogin(CSecurityFtdcRspUserLoginField *pRspUserLogin, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///登出请求响应
|
||||
virtual void OnRspUserLogout(CSecurityFtdcUserLogoutField *pUserLogout, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///报单录入请求响应
|
||||
virtual void OnRspOrderInsert(CSecurityFtdcInputOrderField *pInputOrder, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///报单操作请求响应
|
||||
virtual void OnRspOrderAction(CSecurityFtdcInputOrderActionField *pInputOrderAction, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///用户口令更新请求响应
|
||||
virtual void OnRspUserPasswordUpdate(CSecurityFtdcUserPasswordUpdateField *pUserPasswordUpdate, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///资金账户口令更新请求响应
|
||||
virtual void OnRspTradingAccountPasswordUpdate(CSecurityFtdcTradingAccountPasswordUpdateField *pTradingAccountPasswordUpdate, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///请求查询交易所响应
|
||||
virtual void OnRspQryExchange(CSecurityFtdcExchangeField *pExchange, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///请求查询合约响应
|
||||
virtual void OnRspQryInstrument(CSecurityFtdcInstrumentField *pInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///请求查询投资者响应
|
||||
virtual void OnRspQryInvestor(CSecurityFtdcInvestorField *pInvestor, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///请求查询交易编码响应
|
||||
virtual void OnRspQryTradingCode(CSecurityFtdcTradingCodeField *pTradingCode, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///请求查询资金账户响应
|
||||
virtual void OnRspQryTradingAccount(CSecurityFtdcTradingAccountField *pTradingAccount, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///请求查询行情响应
|
||||
virtual void OnRspQryDepthMarketData(CSecurityFtdcDepthMarketDataField *pDepthMarketData, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///请求查询债券利息响应
|
||||
virtual void OnRspQryBondInterest(CSecurityFtdcBondInterestField *pBondInterest, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///请求查询市值配售信息响应
|
||||
virtual void OnRspQryMarketRationInfo(CSecurityFtdcMarketRationInfoField *pMarketRationInfo, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///请求查询合约手续费率响应
|
||||
virtual void OnRspQryInstrumentCommissionRate(CSecurityFtdcInstrumentCommissionRateField *pInstrumentCommissionRate, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///请求查询ETF合约响应
|
||||
virtual void OnRspQryETFInstrument(CSecurityFtdcETFInstrumentField *pETFInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///请求查询ETF股票篮响应
|
||||
virtual void OnRspQryETFBasket(CSecurityFtdcETFBasketField *pETFBasket, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///请求查询OF合约响应
|
||||
virtual void OnRspQryOFInstrument(CSecurityFtdcOFInstrumentField *pOFInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///请求查询SF合约响应
|
||||
virtual void OnRspQrySFInstrument(CSecurityFtdcSFInstrumentField *pSFInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///请求查询报单响应
|
||||
virtual void OnRspQryOrder(CSecurityFtdcOrderField *pOrder, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///请求查询成交响应
|
||||
virtual void OnRspQryTrade(CSecurityFtdcTradeField *pTrade, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///请求查询投资者持仓响应
|
||||
virtual void OnRspQryInvestorPosition(CSecurityFtdcInvestorPositionField *pInvestorPosition, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///报单通知
|
||||
virtual void OnRtnOrder(CSecurityFtdcOrderField *pOrder);
|
||||
|
||||
///成交通知
|
||||
virtual void OnRtnTrade(CSecurityFtdcTradeField *pTrade);
|
||||
|
||||
///报单录入错误回报
|
||||
virtual void OnErrRtnOrderInsert(CSecurityFtdcInputOrderField *pInputOrder, CSecurityFtdcRspInfoField *pRspInfo);
|
||||
|
||||
///报单操作错误回报
|
||||
virtual void OnErrRtnOrderAction(CSecurityFtdcOrderActionField *pOrderAction, CSecurityFtdcRspInfoField *pRspInfo);
|
||||
|
||||
///Liber发起出金应答
|
||||
virtual void OnRspFundOutByLiber(CSecurityFtdcInputFundTransferField *pInputFundTransfer, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///Liber发起出金通知
|
||||
virtual void OnRtnFundOutByLiber(CSecurityFtdcFundTransferField *pFundTransfer);
|
||||
|
||||
///Liber发起出金错误回报
|
||||
virtual void OnErrRtnFundOutByLiber(CSecurityFtdcInputFundTransferField *pInputFundTransfer, CSecurityFtdcRspInfoField *pRspInfo);
|
||||
|
||||
///银行发起入金通知
|
||||
virtual void OnRtnFundInByBank(CSecurityFtdcFundTransferField *pFundTransfer);
|
||||
|
||||
///资金转账查询应答
|
||||
virtual void OnRspQryFundTransferSerial(CSecurityFtdcFundTransferField *pFundTransfer, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///资金内转应答
|
||||
virtual void OnRspFundInterTransfer(CSecurityFtdcFundInterTransferField *pFundInterTransfer, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///资金内转流水查询应答
|
||||
virtual void OnRspQryFundInterTransferSerial(CSecurityFtdcFundInterTransferSerialField *pFundInterTransferSerial, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
|
||||
|
||||
///资金内转流水通知
|
||||
virtual void OnRtnFundInterTransferSerial(CSecurityFtdcFundInterTransferSerialField *pFundInterTransferSerial);
|
||||
|
||||
///资金内转错误回报
|
||||
virtual void OnErrRtnFundInterTransfer(CSecurityFtdcFundInterTransferField *pFundInterTransfer, CSecurityFtdcRspInfoField *pRspInfo);
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//task:任务
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
void processTask();
|
||||
|
||||
void processFrontConnected(Task task);
|
||||
|
||||
void processFrontDisconnected(Task task);
|
||||
|
||||
void processHeartBeatWarning(Task task);
|
||||
|
||||
void processRspError(Task task);
|
||||
|
||||
void processRspUserLogin(Task task);
|
||||
|
||||
void processRspUserLogout(Task task);
|
||||
|
||||
void processRspOrderInsert(Task task);
|
||||
|
||||
void processRspOrderAction(Task task);
|
||||
|
||||
void processRspUserPasswordUpdate(Task task);
|
||||
|
||||
void processRspTradingAccountPasswordUpdate(Task task);
|
||||
|
||||
void processRspQryExchange(Task task);
|
||||
|
||||
void processRspQryInstrument(Task task);
|
||||
|
||||
void processRspQryInvestor(Task task);
|
||||
|
||||
void processRspQryTradingCode(Task task);
|
||||
|
||||
void processRspQryTradingAccount(Task task);
|
||||
|
||||
void processRspQryDepthMarketData(Task task);
|
||||
|
||||
void processRspQryBondInterest(Task task);
|
||||
|
||||
void processRspQryMarketRationInfo(Task task);
|
||||
|
||||
void processRspQryInstrumentCommissionRate(Task task);
|
||||
|
||||
void processRspQryETFInstrument(Task task);
|
||||
|
||||
void processRspQryETFBasket(Task task);
|
||||
|
||||
void processRspQryOFInstrument(Task task);
|
||||
|
||||
void processRspQrySFInstrument(Task task);
|
||||
|
||||
void processRspQryOrder(Task task);
|
||||
|
||||
void processRspQryTrade(Task task);
|
||||
|
||||
void processRspQryInvestorPosition(Task task);
|
||||
|
||||
void processRtnOrder(Task task);
|
||||
|
||||
void processRtnTrade(Task task);
|
||||
|
||||
void processErrRtnOrderInsert(Task task);
|
||||
|
||||
void processErrRtnOrderAction(Task task);
|
||||
|
||||
void processRspFundOutByLiber(Task task);
|
||||
|
||||
void processRtnFundOutByLiber(Task task);
|
||||
|
||||
void processErrRtnFundOutByLiber(Task task);
|
||||
|
||||
void processRtnFundInByBank(Task task);
|
||||
|
||||
void processRspQryFundTransferSerial(Task task);
|
||||
|
||||
void processRspFundInterTransfer(Task task);
|
||||
|
||||
void processRspQryFundInterTransferSerial(Task task);
|
||||
|
||||
void processRtnFundInterTransferSerial(Task task);
|
||||
|
||||
void processErrRtnFundInterTransfer(Task task);
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//data:回调函数的数据字典
|
||||
//error:回调函数的错误字典
|
||||
//id:请求id
|
||||
//last:是否为最后返回
|
||||
//i:整数
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
virtual void onFrontConnected(){};
|
||||
|
||||
virtual void onFrontDisconnected(int i){};
|
||||
|
||||
virtual void onHeartBeatWarning(int i){};
|
||||
|
||||
virtual void onRspError(dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspUserLogin(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspUserLogout(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspOrderInsert(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspOrderAction(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspUserPasswordUpdate(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspTradingAccountPasswordUpdate(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspQryExchange(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspQryInstrument(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspQryInvestor(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspQryTradingCode(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspQryTradingAccount(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspQryDepthMarketData(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspQryBondInterest(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspQryMarketRationInfo(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspQryInstrumentCommissionRate(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspQryETFInstrument(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspQryETFBasket(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspQryOFInstrument(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspQrySFInstrument(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspQryOrder(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspQryTrade(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspQryInvestorPosition(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRtnOrder(dict data) {};
|
||||
|
||||
virtual void onRtnTrade(dict data) {};
|
||||
|
||||
virtual void onErrRtnOrderInsert(dict data, dict error) {};
|
||||
|
||||
virtual void onErrRtnOrderAction(dict data, dict error) {};
|
||||
|
||||
virtual void onRspFundOutByLiber(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRtnFundOutByLiber(dict data) {};
|
||||
|
||||
virtual void onErrRtnFundOutByLiber(dict data, dict error) {};
|
||||
|
||||
virtual void onRtnFundInByBank(dict data) {};
|
||||
|
||||
virtual void onRspQryFundTransferSerial(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspFundInterTransfer(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRspQryFundInterTransferSerial(dict data, dict error, int id, bool last) {};
|
||||
|
||||
virtual void onRtnFundInterTransferSerial(dict data) {};
|
||||
|
||||
virtual void onErrRtnFundInterTransfer(dict data, dict error) {};
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//req:主动函数的请求字典
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
void createFtdcTraderApi(string pszFlowPath = "");
|
||||
|
||||
void release();
|
||||
|
||||
void init();
|
||||
|
||||
int join();
|
||||
|
||||
string getTradingDay();
|
||||
|
||||
void registerFront(string pszFrontAddress);
|
||||
|
||||
void subscribePrivateTopic(int nType);
|
||||
|
||||
void subscribePublicTopic(int nType);
|
||||
|
||||
int reqUserLogin(dict req, int nRequestID);
|
||||
|
||||
int reqUserLogout(dict req, int nRequestID);
|
||||
|
||||
int reqOrderInsert(dict req, int nRequestID);
|
||||
|
||||
int reqOrderAction(dict req, int nRequestID);
|
||||
|
||||
int reqUserPasswordUpdate(dict req, int nRequestID);
|
||||
|
||||
int reqTradingAccountPasswordUpdate(dict req, int nRequestID);
|
||||
|
||||
int reqQryExchange(dict req, int nRequestID);
|
||||
|
||||
int reqQryInstrument(dict req, int nRequestID);
|
||||
|
||||
int reqQryInvestor(dict req, int nRequestID);
|
||||
|
||||
int reqQryTradingCode(dict req, int nRequestID);
|
||||
|
||||
int reqQryTradingAccount(dict req, int nRequestID);
|
||||
|
||||
int reqQryDepthMarketData(dict req, int nRequestID);
|
||||
|
||||
int reqQryBondInterest(dict req, int nRequestID);
|
||||
|
||||
int reqQryMarketRationInfo(dict req, int nRequestID);
|
||||
|
||||
int reqQryInstrumentCommissionRate(dict req, int nRequestID);
|
||||
|
||||
int reqQryETFInstrument(dict req, int nRequestID);
|
||||
|
||||
int reqQryETFBasket(dict req, int nRequestID);
|
||||
|
||||
int reqQryOFInstrument(dict req, int nRequestID);
|
||||
|
||||
int reqQrySFInstrument(dict req, int nRequestID);
|
||||
|
||||
int reqQryOrder(dict req, int nRequestID);
|
||||
|
||||
int reqQryTrade(dict req, int nRequestID);
|
||||
|
||||
int reqQryInvestorPosition(dict req, int nRequestID);
|
||||
|
||||
int reqFundOutByLiber(dict req, int nRequestID);
|
||||
|
||||
int reqQryFundTransferSerial(dict req, int nRequestID);
|
||||
|
||||
int reqFundInterTransfer(dict req, int nRequestID);
|
||||
|
||||
int reqQryFundInterTransferSerial(dict req, int nRequestID);
|
||||
};
|
Loading…
Reference in New Issue
Block a user