diff --git a/vn.lts/ltsl2/L2mduserapi.dll b/vn.lts/ltsl2/L2mduserapi.dll new file mode 100644 index 00000000..d401bf1f Binary files /dev/null and b/vn.lts/ltsl2/L2mduserapi.dll differ diff --git a/vn.lts/ltsl2/L2mduserapi.lib b/vn.lts/ltsl2/L2mduserapi.lib new file mode 100644 index 00000000..7aded7db Binary files /dev/null and b/vn.lts/ltsl2/L2mduserapi.lib differ diff --git a/vn.lts/ltsl2/L2mduserapi.so b/vn.lts/ltsl2/L2mduserapi.so new file mode 100644 index 00000000..6e818ed7 Binary files /dev/null and b/vn.lts/ltsl2/L2mduserapi.so differ diff --git a/vn.lts/ltsl2/LTS_ns.h b/vn.lts/ltsl2/LTS_ns.h new file mode 100644 index 00000000..f825f233 --- /dev/null +++ b/vn.lts/ltsl2/LTS_ns.h @@ -0,0 +1,9 @@ +#ifndef _LTS_NAMESPACE_H +#define _LTS_NAMESPACE_H + +#define _LTS_NS_ _LTS_ +#define _LTS_NS_BEGIN_ namespace _LTS_{ +#define _LTS_NS_END_ } +#define _USING_LTS_NS_ using namespace _LTS_; + +#endif diff --git a/vn.lts/ltsl2/SecurityFtdcL2MDUserApi.h b/vn.lts/ltsl2/SecurityFtdcL2MDUserApi.h new file mode 100644 index 00000000..d86dd1dc --- /dev/null +++ b/vn.lts/ltsl2/SecurityFtdcL2MDUserApi.h @@ -0,0 +1,150 @@ +///////////////////////////////////////////////////////////////////////// +///@company shanghai liber information Technology Co.,Ltd +///@file SecurityFtdcL2MDUserApi.h +///@brief 定义客户端接口 +///////////////////////////////////////////////////////////////////////// + +#if !defined(SECURITY_L2MD_FTDCUSERAPI_H) +#define SECURITY_L2MD_FTDCUSERAPI_H + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#include "SecurityFtdcL2MDUserApiStruct.h" + +_LTS_NS_BEGIN_ +#if defined(L2MD_USERAPI_IS_LIB) && defined(WINDOWS) +#ifdef LIB_L2MD_USER_API_EXPORT +#define L2MD_USER_API_EXPORT __declspec(dllexport) +#else +#define L2MD_USER_API_EXPORT __declspec(dllimport) +#endif +#else +#define L2MD_USER_API_EXPORT +#endif + +class CSecurityFtdcL2MDUserSpi +{ +public: + ///当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。 + virtual void OnFrontConnected(){}; + + ///当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。 + ///@param nReason 错误原因 + /// 0x1001 网络读失败 + /// 0x1002 网络写失败 + /// 0x2001 接收心跳超时 + /// 0x2002 发送心跳失败 + /// 0x2003 收到错误报文 + virtual void OnFrontDisconnected(int nReason){}; + + ///心跳超时警告 + virtual void OnHeartBeatWarning(int nTimeLapse){}; + + ///错误应答 + virtual void OnRspError(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; + + ///登录请求响应 + virtual void OnRspUserLogin(CSecurityFtdcUserLoginField *pUserLogin, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; + + ///登出请求响应 + virtual void OnRspUserLogout(CSecurityFtdcUserLogoutField *pUserLogout, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; + + ///订阅Level2行情应答 + virtual void OnRspSubL2MarketData(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; + + ///取消订阅Level2行情应答 + virtual void OnRspUnSubL2MarketData(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; + + ///订阅Level2指数行情应答 + virtual void OnRspSubL2Index(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; + + ///取消订阅Level2指数行情应答 + virtual void OnRspUnSubL2Index(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; + + ///Level2行情通知 + virtual void OnRtnL2MarketData(CSecurityFtdcL2MarketDataField *pL2MarketData) {}; + + ///Level2指数行情通知 + virtual void OnRtnL2Index(CSecurityFtdcL2IndexField *pL2Index) {}; + + ///订阅逐笔委托及成交应答 + virtual void OnRspSubL2OrderAndTrade(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; + + ///取消订阅逐笔委托及成交应答 + virtual void OnRspUnSubL2OrderAndTrade(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; + + ///Level2委托通知 + virtual void OnRtnL2Order(CSecurityFtdcL2OrderField *pL2Order) {}; + + ///Level2成交通知 + virtual void OnRtnL2Trade(CSecurityFtdcL2TradeField *pL2Trade) {}; + + ///通知清理SSE买卖一队列中数量为0的报单 + virtual void OnNtfCheckOrderList(TSecurityFtdcInstrumentIDType InstrumentID, TSecurityFtdcFunctionCodeType FunctionCode) {}; +}; + +#ifndef WINDOWS + #if __GNUC__ >= 4 + #pragma GCC visibility push(default) + #endif +#endif +class L2MD_USER_API_EXPORT CSecurityFtdcL2MDUserApi +{ +public: + ///创建UserApi + static CSecurityFtdcL2MDUserApi *CreateFtdcL2MDUserApi(const bool bIsMulticast=false); + + ///删除接口对象本身 + ///@remark 不再使用本接口对象时,调用该函数删除接口对象 + virtual void Release() = 0; + + ///初始化 + ///@remark 初始化运行环境,只有调用后,接口才开始工作 + virtual void Init() = 0; + + ///等待接口线程结束运行 + virtual int Join() = 0; + + ///获取当前交易日 + ///@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(CSecurityFtdcL2MDUserSpi *pSpi) = 0; + + virtual int SubscribeL2MarketData(char *ppInstrumentID[], int nCount, char* pExchageID) = 0; + + virtual int UnSubscribeL2MarketData(char *ppInstrumentID[], int nCount, char* pExchageID) = 0; + + virtual int SubscribeL2Index(char *ppInstrumentID[], int nCount, char* pExchageID) = 0; + + virtual int UnSubscribeL2Index(char *ppInstrumentID[], int nCount, char* pExchageID) = 0; + + virtual int SubscribeL2OrderAndTrade() = 0; + + virtual int UnSubscribeL2OrderAndTrade() = 0; + + ///登录请求 + virtual int ReqUserLogin(CSecurityFtdcUserLoginField *pUserLogin, int nRequestID) = 0; + + ///登出请求 + virtual int ReqUserLogout(CSecurityFtdcUserLogoutField *pUserLogout, int nRequestID) = 0; +protected: + ~CSecurityFtdcL2MDUserApi(){}; +}; +#ifndef WINDOWS + #if __GNUC__ >= 4 + #pragma GCC visibility pop + #endif +#endif +_LTS_NS_END_ +#endif diff --git a/vn.lts/ltsl2/SecurityFtdcL2MDUserApiDataType.h b/vn.lts/ltsl2/SecurityFtdcL2MDUserApiDataType.h new file mode 100644 index 00000000..c2c6eb08 --- /dev/null +++ b/vn.lts/ltsl2/SecurityFtdcL2MDUserApiDataType.h @@ -0,0 +1,213 @@ +///////////////////////////////////////////////////////////////////////// +///@company shanghai liber information Technology Co.,Ltd +///@file SecurityFtdcL2MDUserApiDataType.h +///@brief 定义业务数据类型 +///////////////////////////////////////////////////////////////////////// + +#ifndef SECURITY_L2MD_FTDCDATATYPE_H +#define SECURITY_L2MD_FTDCDATATYPE_H + +#include "LTS_ns.h" + +_LTS_NS_BEGIN_ + +///////////////////////////////////////////////////////////////////////// +///TFtdcErrorIDType是一个错误代码类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcErrorIDType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcErrorMsgType是一个错误信息类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcErrorMsgType[81]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcBrokerIDType是一个经纪公司代码类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcBrokerIDType[11]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcUserIDType是一个用户代码类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcUserIDType[16]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcUserNameType是一个用户名称类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcUserNameType[81]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcPasswordType是一个密码类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcPasswordType[41]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcExchangeIDType是一个交易所代码类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcExchangeIDType[9]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcInstrumentIDType是一个合约代码类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcInstrumentIDType[31]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcDateType是一个日期类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcDateType[9]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcTimeType是一个时间类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcTimeType[9]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcPriceType是一个价格类型 +///////////////////////////////////////////////////////////////////////// +typedef double TSecurityFtdcPriceType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcVolumeType是一个数量类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcVolumeType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcLargeVolumeType是一个大额数量类型 +///////////////////////////////////////////////////////////////////////// +typedef double TSecurityFtdcLargeVolumeType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcRatioType是一个比率类型 +///////////////////////////////////////////////////////////////////////// +typedef double TSecurityFtdcRatioType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcMoneyType是一个资金类型 +///////////////////////////////////////////////////////////////////////// +typedef double TSecurityFtdcMoneyType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcPriceLevelType是一个价格深度类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcPriceLevelType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcBoolType是一个布尔型类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcBoolType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcIndexType是一个指数类型 +///////////////////////////////////////////////////////////////////////// +typedef double TSecurityFtdcIndexType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcDataLevelType是一个行情数据等级类型 +///////////////////////////////////////////////////////////////////////// +///全量行情 +#define SECURITY_FTDC_DL_FULL '0' +///L10行情 +#define SECURITY_FTDC_DL_L10 '1' +///L5行情 +#define SECURITY_FTDC_DL_L5 '2' + +typedef char TSecurityFtdcDataLevelType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcIPAddressType是一个IP地址类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcIPAddressType[16]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcIPPortType是一个IP端口类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcIPPortType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcBeginStringType是一个step起始串类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcBeginStringType[17]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcBodyLengthType是一个消息体长度类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcBodyLengthType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcMsgTypeType是一个消息类型类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcMsgTypeType[9]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcSenderCompIDType是一个发送方代码类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcSenderCompIDType[33]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcTargetCompIDType是一个接收方代码类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcTargetCompIDType[33]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcMsgSeqNumType是一个头消息序号标签34类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcMsgSeqNumType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcSendingTimeType是一个发送时间类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcSendingTimeType[21]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcMessageEncodingType是一个消息中Encoded域的字符编码类型类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcMessageEncodingType[21]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcCheckSumType是一个校验和类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcCheckSumType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcEncryptMethodType是一个加密方法类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcEncryptMethodType[9]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcHeartBtIntType是一个心跳间隔类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcHeartBtIntType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcInterfaceVersionType是一个行情数据接口版本号类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcInterfaceVersionType[9]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcMsgSeqIDType是一个消息序号标签10072类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcMsgSeqIDType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcGroupIDType是一个组号类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcGroupIDType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcGroupNoType是一个组序类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcGroupNoType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcOrderKindType是一个报单类型类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcOrderKindType[2]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcFunctionCodeType是一个功能码类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcFunctionCodeType[2]; + +_LTS_NS_END_ + +#endif diff --git a/vn.lts/ltsl2/SecurityFtdcL2MDUserApiStruct.h b/vn.lts/ltsl2/SecurityFtdcL2MDUserApiStruct.h new file mode 100644 index 00000000..99330028 --- /dev/null +++ b/vn.lts/ltsl2/SecurityFtdcL2MDUserApiStruct.h @@ -0,0 +1,786 @@ +///////////////////////////////////////////////////////////////////////// +///@company shanghai liber information Technology Co.,Ltd +///@file SecurityFtdcL2MDUserApiStruct.h +///@brief 定义业务数据结构 +///////////////////////////////////////////////////////////////////////// + +#if !defined(SECURITY_L2MD_FTDCSTRUCT_H) +#define SECURITY_L2MD_FTDCSTRUCT_H + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#include "SecurityFtdcL2MDUserApiDataType.h" + +_LTS_NS_BEGIN_ + +///响应信息 +struct CSecurityFtdcRspInfoField +{ + ///错误代码 + TSecurityFtdcErrorIDType ErrorID; + ///错误信息 + TSecurityFtdcErrorMsgType ErrorMsg; +}; + +///用户登录信息 +struct CSecurityFtdcUserLoginField +{ + ///交易日 + TSecurityFtdcDateType TradingDay; + ///经纪公司代码 + TSecurityFtdcBrokerIDType BrokerID; + ///用户代码 + TSecurityFtdcUserIDType UserID; + ///密码 + TSecurityFtdcPasswordType Password; + ///行情数据等级 + TSecurityFtdcDataLevelType DataLevel; +}; + +///用户登出信息 +struct CSecurityFtdcUserLogoutField +{ + ///经纪公司代码 + TSecurityFtdcBrokerIDType BrokerID; + ///用户代码 + TSecurityFtdcUserIDType UserID; +}; + +///指定的合约 +struct CSecurityFtdcSpecificInstrumentField +{ + ///合约代码 + TSecurityFtdcInstrumentIDType InstrumentID; + ///交易所代码 + TSecurityFtdcExchangeIDType ExchangeID; +}; + +///Level2行情 +struct CSecurityFtdcL2MarketDataField +{ + ///交易日 + TSecurityFtdcDateType TradingDay; + ///时间戳 + TSecurityFtdcTimeType TimeStamp; + ///交易所代码 + TSecurityFtdcExchangeIDType ExchangeID; + ///合约代码 + TSecurityFtdcInstrumentIDType InstrumentID; + ///昨收盘价 + TSecurityFtdcPriceType PreClosePrice; + ///今开盘价 + TSecurityFtdcPriceType OpenPrice; + ///收盘价 + TSecurityFtdcPriceType ClosePrice; + ///净值估值 + TSecurityFtdcPriceType IOPV; + ///到期收益率 + TSecurityFtdcRatioType YieldToMaturity; + ///最高价 + TSecurityFtdcPriceType HighPrice; + ///最低价 + TSecurityFtdcPriceType LowPrice; + ///最新价 + TSecurityFtdcPriceType LastPrice; + ///成交笔数 + TSecurityFtdcVolumeType TradeCount; + ///成交总量 + TSecurityFtdcLargeVolumeType TotalTradeVolume; + ///成交总金额 + TSecurityFtdcMoneyType TotalTradeValue; + ///委托买入总量 + TSecurityFtdcLargeVolumeType TotalBidVolume; + ///加权平均委买价 + TSecurityFtdcPriceType WeightedAvgBidPrice; + ///债券加权平均委买价 + TSecurityFtdcPriceType AltWeightedAvgBidPrice; + ///委托卖出总量 + TSecurityFtdcLargeVolumeType TotalOfferVolume; + ///加权平均委卖价 + TSecurityFtdcPriceType WeightedAvgOfferPrice; + ///债券加权平均委卖价格 + TSecurityFtdcPriceType AltWeightedAvgOfferPrice; + ///买价深度 + TSecurityFtdcPriceLevelType BidPriceLevel; + ///卖价深度 + TSecurityFtdcPriceLevelType OfferPriceLevel; + ///申买价一 + TSecurityFtdcPriceType BidPrice1; + ///申买量一 + TSecurityFtdcVolumeType BidVolume1; + ///实际买总委托笔数一 + TSecurityFtdcVolumeType BidCount1; + ///申买价二 + TSecurityFtdcPriceType BidPrice2; + ///申买量二 + TSecurityFtdcVolumeType BidVolume2; + ///实际买总委托笔数二 + TSecurityFtdcVolumeType BidCount2; + ///申买价三 + TSecurityFtdcPriceType BidPrice3; + ///申买量三 + TSecurityFtdcVolumeType BidVolume3; + ///实际买总委托笔数三 + TSecurityFtdcVolumeType BidCount3; + ///申买价四 + TSecurityFtdcPriceType BidPrice4; + ///申买量四 + TSecurityFtdcVolumeType BidVolume4; + ///实际买总委托笔数四 + TSecurityFtdcVolumeType BidCount4; + ///申买价五 + TSecurityFtdcPriceType BidPrice5; + ///申买量五 + TSecurityFtdcVolumeType BidVolume5; + ///实际买总委托笔数五 + TSecurityFtdcVolumeType BidCount5; + ///申买价六 + TSecurityFtdcPriceType BidPrice6; + ///申买量六 + TSecurityFtdcVolumeType BidVolume6; + ///实际买总委托笔数六 + TSecurityFtdcVolumeType BidCount6; + ///申买价七 + TSecurityFtdcPriceType BidPrice7; + ///申买量七 + TSecurityFtdcVolumeType BidVolume7; + ///实际买总委托笔数七 + TSecurityFtdcVolumeType BidCount7; + ///申买价八 + TSecurityFtdcPriceType BidPrice8; + ///申买量八 + TSecurityFtdcVolumeType BidVolume8; + ///实际买总委托笔数八 + TSecurityFtdcVolumeType BidCount8; + ///申买价九 + TSecurityFtdcPriceType BidPrice9; + ///申买量九 + TSecurityFtdcVolumeType BidVolume9; + ///实际买总委托笔数九 + TSecurityFtdcVolumeType BidCount9; + ///申买价十 + TSecurityFtdcPriceType BidPriceA; + ///申买量十 + TSecurityFtdcVolumeType BidVolumeA; + ///实际买总委托笔数十 + TSecurityFtdcVolumeType BidCountA; + ///申卖价一 + TSecurityFtdcPriceType OfferPrice1; + ///申卖量一 + TSecurityFtdcVolumeType OfferVolume1; + ///实际卖总委托笔数一 + TSecurityFtdcVolumeType OfferCount1; + ///申卖价二 + TSecurityFtdcPriceType OfferPrice2; + ///申卖量二 + TSecurityFtdcVolumeType OfferVolume2; + ///实际卖总委托笔数二 + TSecurityFtdcVolumeType OfferCount2; + ///申卖价三 + TSecurityFtdcPriceType OfferPrice3; + ///申卖量三 + TSecurityFtdcVolumeType OfferVolume3; + ///实际卖总委托笔数三 + TSecurityFtdcVolumeType OfferCount3; + ///申卖价四 + TSecurityFtdcPriceType OfferPrice4; + ///申卖量四 + TSecurityFtdcVolumeType OfferVolume4; + ///实际卖总委托笔数四 + TSecurityFtdcVolumeType OfferCount4; + ///申卖价五 + TSecurityFtdcPriceType OfferPrice5; + ///申卖量五 + TSecurityFtdcVolumeType OfferVolume5; + ///实际卖总委托笔数五 + TSecurityFtdcVolumeType OfferCount5; + ///申卖价六 + TSecurityFtdcPriceType OfferPrice6; + ///申卖量六 + TSecurityFtdcVolumeType OfferVolume6; + ///实际卖总委托笔数六 + TSecurityFtdcVolumeType OfferCount6; + ///申卖价七 + TSecurityFtdcPriceType OfferPrice7; + ///申卖量七 + TSecurityFtdcVolumeType OfferVolume7; + ///实际卖总委托笔数七 + TSecurityFtdcVolumeType OfferCount7; + ///申卖价八 + TSecurityFtdcPriceType OfferPrice8; + ///申卖量八 + TSecurityFtdcVolumeType OfferVolume8; + ///实际卖总委托笔数八 + TSecurityFtdcVolumeType OfferCount8; + ///申卖价九 + TSecurityFtdcPriceType OfferPrice9; + ///申卖量九 + TSecurityFtdcVolumeType OfferVolume9; + ///实际卖总委托笔数九 + TSecurityFtdcVolumeType OfferCount9; + ///申卖价十 + TSecurityFtdcPriceType OfferPriceA; + ///申卖量十 + TSecurityFtdcVolumeType OfferVolumeA; + ///实际卖总委托笔数十 + TSecurityFtdcVolumeType OfferCountA; +}; + +///Level2行情更新时间属性 +struct CSecurityFtdcL2UpdateTimeField +{ + ///交易日 + TSecurityFtdcDateType TradingDay; + ///时间戳 + TSecurityFtdcTimeType TimeStamp; + ///交易所代码 + TSecurityFtdcExchangeIDType ExchangeID; + ///合约代码 + TSecurityFtdcInstrumentIDType InstrumentID; +}; + +///Level2行情静态属性 +struct CSecurityFtdcL2StaticField +{ + ///昨收盘价 + TSecurityFtdcPriceType PreClosePrice; + ///今开盘价 + TSecurityFtdcPriceType OpenPrice; + ///收盘价 + TSecurityFtdcPriceType ClosePrice; + ///净值估值 + TSecurityFtdcPriceType IOPV; + ///到期收益率 + TSecurityFtdcRatioType YieldToMaturity; +}; + +///Level2行情价格区间属性 +struct CSecurityFtdcL2PriceIntervalField +{ + ///最高价 + TSecurityFtdcPriceType HighPrice; + ///最低价 + TSecurityFtdcPriceType LowPrice; +}; + +///Level2行情基本信息 +struct CSecurityFtdcL2BaseField +{ + ///最新价 + TSecurityFtdcPriceType LastPrice; +}; + +///Level2成交信息 +struct CSecurityFtdcL2TradedField +{ + ///成交笔数 + TSecurityFtdcVolumeType TradeCount; + ///成交总量 + TSecurityFtdcLargeVolumeType TotalTradeVolume; + ///成交总金额 + TSecurityFtdcMoneyType TotalTradeValue; +}; + +///Level2行情数据属性 +struct CSecurityFtdcL2DataLevelField +{ + ///价格 + TSecurityFtdcPriceType Price; + ///数量 + TSecurityFtdcVolumeType Volume; + ///实际总委托笔数 + TSecurityFtdcVolumeType Count; +}; + +///Level2委买信息 +struct CSecurityFtdcL2BidOrderField +{ + ///委托买入总量 + TSecurityFtdcLargeVolumeType TotalBidVolume; + ///加权平均委买价 + TSecurityFtdcPriceType WeightedAvgBidPrice; + ///债券加权平均委买价 + TSecurityFtdcPriceType AltWeightedAvgBidPrice; +}; + +///Level2委卖信息 +struct CSecurityFtdcL2OfferOrderField +{ + ///委托卖出总量 + TSecurityFtdcLargeVolumeType TotalOfferVolume; + ///加权平均委卖价 + TSecurityFtdcPriceType WeightedAvgOfferPrice; + ///债券加权平均委卖价格 + TSecurityFtdcPriceType AltWeightedAvgOfferPrice; +}; + +///Level2价格深度属性 +struct CSecurityFtdcL2PriceLevelField +{ + ///买价深度 + TSecurityFtdcPriceLevelType BidPriceLevel; + ///卖价深度 + TSecurityFtdcPriceLevelType OfferPriceLevel; +}; + +///Level2行情申买一属性 +struct CSecurityFtdcL2Bid1Field +{ + ///申买价一 + TSecurityFtdcPriceType BidPrice1; + ///申买量一 + TSecurityFtdcVolumeType BidVolume1; + ///实际买总委托笔数一 + TSecurityFtdcVolumeType BidCount1; +}; + +///Level2行情申卖一属性 +struct CSecurityFtdcL2Offer1Field +{ + ///申卖价一 + TSecurityFtdcPriceType OfferPrice1; + ///申卖量一 + TSecurityFtdcVolumeType OfferVolume1; + ///实际卖总委托笔数一 + TSecurityFtdcVolumeType OfferCount1; +}; + +///Level2行情申买二属性 +struct CSecurityFtdcL2Bid2Field +{ + ///申买价二 + TSecurityFtdcPriceType BidPrice2; + ///申买量二 + TSecurityFtdcVolumeType BidVolume2; + ///实际买总委托笔数二 + TSecurityFtdcVolumeType BidCount2; +}; + +///Level2行情申卖二属性 +struct CSecurityFtdcL2Offer2Field +{ + ///申卖价二 + TSecurityFtdcPriceType OfferPrice2; + ///申卖量二 + TSecurityFtdcVolumeType OfferVolume2; + ///实际卖总委托笔数二 + TSecurityFtdcVolumeType OfferCount2; +}; + +///Level2行情申买三属性 +struct CSecurityFtdcL2Bid3Field +{ + ///申买价三 + TSecurityFtdcPriceType BidPrice3; + ///申买量三 + TSecurityFtdcVolumeType BidVolume3; + ///实际买总委托笔数三 + TSecurityFtdcVolumeType BidCount3; +}; + +///Level2行情申卖三属性 +struct CSecurityFtdcL2Offer3Field +{ + ///申卖价三 + TSecurityFtdcPriceType OfferPrice3; + ///申卖量三 + TSecurityFtdcVolumeType OfferVolume3; + ///实际卖总委托笔数三 + TSecurityFtdcVolumeType OfferCount3; +}; + +///Level2行情申买四属性 +struct CSecurityFtdcL2Bid4Field +{ + ///申买价四 + TSecurityFtdcPriceType BidPrice4; + ///申买量四 + TSecurityFtdcVolumeType BidVolume4; + ///实际买总委托笔数四 + TSecurityFtdcVolumeType BidCount4; +}; + +///Level2行情申卖四属性 +struct CSecurityFtdcL2Offer4Field +{ + ///申卖价四 + TSecurityFtdcPriceType OfferPrice4; + ///申卖量四 + TSecurityFtdcVolumeType OfferVolume4; + ///实际卖总委托笔数四 + TSecurityFtdcVolumeType OfferCount4; +}; + +///Level2行情申买五属性 +struct CSecurityFtdcL2Bid5Field +{ + ///申买价五 + TSecurityFtdcPriceType BidPrice5; + ///申买量五 + TSecurityFtdcVolumeType BidVolume5; + ///实际买总委托笔数五 + TSecurityFtdcVolumeType BidCount5; +}; + +///Level2行情申卖五属性 +struct CSecurityFtdcL2Offer5Field +{ + ///申卖价五 + TSecurityFtdcPriceType OfferPrice5; + ///申卖量五 + TSecurityFtdcVolumeType OfferVolume5; + ///实际卖总委托笔数五 + TSecurityFtdcVolumeType OfferCount5; +}; + +///Level2行情申买六属性 +struct CSecurityFtdcL2Bid6Field +{ + ///申买价六 + TSecurityFtdcPriceType BidPrice6; + ///申买量六 + TSecurityFtdcVolumeType BidVolume6; + ///实际买总委托笔数六 + TSecurityFtdcVolumeType BidCount6; +}; + +///Level2行情申卖六属性 +struct CSecurityFtdcL2Offer6Field +{ + ///申卖价六 + TSecurityFtdcPriceType OfferPrice6; + ///申卖量六 + TSecurityFtdcVolumeType OfferVolume6; + ///实际卖总委托笔数六 + TSecurityFtdcVolumeType OfferCount6; +}; + +///Level2行情申买七属性 +struct CSecurityFtdcL2Bid7Field +{ + ///申买价七 + TSecurityFtdcPriceType BidPrice7; + ///申买量七 + TSecurityFtdcVolumeType BidVolume7; + ///实际买总委托笔数七 + TSecurityFtdcVolumeType BidCount7; +}; + +///Level2行情申卖七属性 +struct CSecurityFtdcL2Offer7Field +{ + ///申卖价七 + TSecurityFtdcPriceType OfferPrice7; + ///申卖量七 + TSecurityFtdcVolumeType OfferVolume7; + ///实际卖总委托笔数七 + TSecurityFtdcVolumeType OfferCount7; +}; + +///Level2行情申买八属性 +struct CSecurityFtdcL2Bid8Field +{ + ///申买价八 + TSecurityFtdcPriceType BidPrice8; + ///申买量八 + TSecurityFtdcVolumeType BidVolume8; + ///实际买总委托笔数八 + TSecurityFtdcVolumeType BidCount8; +}; + +///Level2行情申卖八属性 +struct CSecurityFtdcL2Offer8Field +{ + ///申卖价八 + TSecurityFtdcPriceType OfferPrice8; + ///申卖量八 + TSecurityFtdcVolumeType OfferVolume8; + ///实际卖总委托笔数八 + TSecurityFtdcVolumeType OfferCount8; +}; + +///Level2行情申买九属性 +struct CSecurityFtdcL2Bid9Field +{ + ///申买价九 + TSecurityFtdcPriceType BidPrice9; + ///申买量九 + TSecurityFtdcVolumeType BidVolume9; + ///实际买总委托笔数九 + TSecurityFtdcVolumeType BidCount9; +}; + +///Level2行情申卖九属性 +struct CSecurityFtdcL2Offer9Field +{ + ///申卖价九 + TSecurityFtdcPriceType OfferPrice9; + ///申卖量九 + TSecurityFtdcVolumeType OfferVolume9; + ///实际卖总委托笔数九 + TSecurityFtdcVolumeType OfferCount9; +}; + +///Level2行情申买十属性 +struct CSecurityFtdcL2BidAField +{ + ///申买价十 + TSecurityFtdcPriceType BidPriceA; + ///申买量十 + TSecurityFtdcVolumeType BidVolumeA; + ///实际买总委托笔数十 + TSecurityFtdcVolumeType BidCountA; +}; + +///Level2行情申卖十属性 +struct CSecurityFtdcL2OfferAField +{ + ///申卖价十 + TSecurityFtdcPriceType OfferPriceA; + ///申卖量十 + TSecurityFtdcVolumeType OfferVolumeA; + ///实际卖总委托笔数十 + TSecurityFtdcVolumeType OfferCountA; +}; + +///Level2行情申买属性 +struct CSecurityFtdcL2BidField +{ + ///申买价一 + TSecurityFtdcPriceType BidPrice1; + ///申买量一 + TSecurityFtdcVolumeType BidVolume1; + ///实际买总委托笔数一 + TSecurityFtdcVolumeType BidCount1; + ///申买价二 + TSecurityFtdcPriceType BidPrice2; + ///申买量二 + TSecurityFtdcVolumeType BidVolume2; + ///实际买总委托笔数二 + TSecurityFtdcVolumeType BidCount2; + ///申买价三 + TSecurityFtdcPriceType BidPrice3; + ///申买量三 + TSecurityFtdcVolumeType BidVolume3; + ///实际买总委托笔数三 + TSecurityFtdcVolumeType BidCount3; + ///申买价四 + TSecurityFtdcPriceType BidPrice4; + ///申买量四 + TSecurityFtdcVolumeType BidVolume4; + ///实际买总委托笔数四 + TSecurityFtdcVolumeType BidCount4; + ///申买价五 + TSecurityFtdcPriceType BidPrice5; + ///申买量五 + TSecurityFtdcVolumeType BidVolume5; + ///实际买总委托笔数五 + TSecurityFtdcVolumeType BidCount5; + ///申买价六 + TSecurityFtdcPriceType BidPrice6; + ///申买量六 + TSecurityFtdcVolumeType BidVolume6; + ///实际买总委托笔数六 + TSecurityFtdcVolumeType BidCount6; + ///申买价七 + TSecurityFtdcPriceType BidPrice7; + ///申买量七 + TSecurityFtdcVolumeType BidVolume7; + ///实际买总委托笔数七 + TSecurityFtdcVolumeType BidCount7; + ///申买价八 + TSecurityFtdcPriceType BidPrice8; + ///申买量八 + TSecurityFtdcVolumeType BidVolume8; + ///实际买总委托笔数八 + TSecurityFtdcVolumeType BidCount8; + ///申买价九 + TSecurityFtdcPriceType BidPrice9; + ///申买量九 + TSecurityFtdcVolumeType BidVolume9; + ///实际买总委托笔数九 + TSecurityFtdcVolumeType BidCount9; + ///申买价十 + TSecurityFtdcPriceType BidPriceA; + ///申买量十 + TSecurityFtdcVolumeType BidVolumeA; + ///实际买总委托笔数十 + TSecurityFtdcVolumeType BidCountA; +}; + +///Level2行情申卖属性 +struct CSecurityFtdcL2OfferField +{ + ///申卖价一 + TSecurityFtdcPriceType OfferPrice1; + ///申卖量一 + TSecurityFtdcVolumeType OfferVolume1; + ///实际卖总委托笔数一 + TSecurityFtdcVolumeType OfferCount1; + ///申卖价二 + TSecurityFtdcPriceType OfferPrice2; + ///申卖量二 + TSecurityFtdcVolumeType OfferVolume2; + ///实际卖总委托笔数二 + TSecurityFtdcVolumeType OfferCount2; + ///申卖价三 + TSecurityFtdcPriceType OfferPrice3; + ///申卖量三 + TSecurityFtdcVolumeType OfferVolume3; + ///实际卖总委托笔数三 + TSecurityFtdcVolumeType OfferCount3; + ///申卖价四 + TSecurityFtdcPriceType OfferPrice4; + ///申卖量四 + TSecurityFtdcVolumeType OfferVolume4; + ///实际卖总委托笔数四 + TSecurityFtdcVolumeType OfferCount4; + ///申卖价五 + TSecurityFtdcPriceType OfferPrice5; + ///申卖量五 + TSecurityFtdcVolumeType OfferVolume5; + ///实际卖总委托笔数五 + TSecurityFtdcVolumeType OfferCount5; + ///申卖价六 + TSecurityFtdcPriceType OfferPrice6; + ///申卖量六 + TSecurityFtdcVolumeType OfferVolume6; + ///实际卖总委托笔数六 + TSecurityFtdcVolumeType OfferCount6; + ///申卖价七 + TSecurityFtdcPriceType OfferPrice7; + ///申卖量七 + TSecurityFtdcVolumeType OfferVolume7; + ///实际卖总委托笔数七 + TSecurityFtdcVolumeType OfferCount7; + ///申卖价八 + TSecurityFtdcPriceType OfferPrice8; + ///申卖量八 + TSecurityFtdcVolumeType OfferVolume8; + ///实际卖总委托笔数八 + TSecurityFtdcVolumeType OfferCount8; + ///申卖价九 + TSecurityFtdcPriceType OfferPrice9; + ///申卖量九 + TSecurityFtdcVolumeType OfferVolume9; + ///实际卖总委托笔数九 + TSecurityFtdcVolumeType OfferCount9; + ///申卖价十 + TSecurityFtdcPriceType OfferPriceA; + ///申卖量十 + TSecurityFtdcVolumeType OfferVolumeA; + ///实际卖总委托笔数十 + TSecurityFtdcVolumeType OfferCountA; +}; + +///Level2指数行情 +struct CSecurityFtdcL2IndexField +{ + ///交易日 + TSecurityFtdcDateType TradingDay; + ///行情时间(秒) + TSecurityFtdcTimeType TimeStamp; + ///交易所代码 + TSecurityFtdcExchangeIDType ExchangeID; + ///指数代码 + TSecurityFtdcInstrumentIDType InstrumentID; + ///前收盘指数 + TSecurityFtdcIndexType PreCloseIndex; + ///今开盘指数 + TSecurityFtdcIndexType OpenIndex; + ///今日收盘指数 + TSecurityFtdcIndexType CloseIndex; + ///最高指数 + TSecurityFtdcIndexType HighIndex; + ///最低指数 + TSecurityFtdcIndexType LowIndex; + ///最新指数 + TSecurityFtdcIndexType LastIndex; + ///参与计算相应指数的成交金额(元) + TSecurityFtdcMoneyType TurnOver; + ///参与计算相应指数的交易数量(手) + TSecurityFtdcLargeVolumeType TotalVolume; +}; + +///Level2行情用户信息 +struct CSecurityFtdcL2UserInfoField +{ + ///经纪公司代码 + TSecurityFtdcBrokerIDType BrokerID; + ///用户代码 + TSecurityFtdcUserIDType UserID; + ///用户名称 + TSecurityFtdcUserNameType UserName; + ///密码 + TSecurityFtdcPasswordType Password; + ///行情数据等级 + TSecurityFtdcDataLevelType DataLevel; +}; + +///UDP组播组信息 +struct CSecurityFtdcMulticastGroupInfoField +{ + ///组播组IP地址 + TSecurityFtdcIPAddressType GroupIP; + ///组播组IP端口 + TSecurityFtdcIPPortType GroupPort; + ///源地址 + TSecurityFtdcIPAddressType SourceIP; +}; + +///Level2逐笔委托 +struct CSecurityFtdcL2OrderField +{ + ///委托组 + TSecurityFtdcGroupIDType OrderGroupID; + ///委托序号 + TSecurityFtdcGroupNoType OrderIndex; + ///委托时间(秒) + TSecurityFtdcTimeType OrderTime; + ///交易所代码 + TSecurityFtdcExchangeIDType ExchangeID; + ///合约代码 + TSecurityFtdcInstrumentIDType InstrumentID; + ///委托价格 + TSecurityFtdcPriceType Price; + ///委托数量 + TSecurityFtdcVolumeType Volume; + ///报单类型 + TSecurityFtdcOrderKindType OrderKind; + ///功能码 + TSecurityFtdcFunctionCodeType FunctionCode; +}; + +///Level2逐笔成交 +struct CSecurityFtdcL2TradeField +{ + ///成交组 + TSecurityFtdcGroupIDType TradeGroupID; + ///成交序号 + TSecurityFtdcGroupNoType TradeIndex; + ///买方委托序号 + TSecurityFtdcGroupNoType BuyIndex; + ///卖方委托序号 + TSecurityFtdcGroupNoType SellIndex; + ///成交时间(秒) + TSecurityFtdcTimeType TradeTime; + ///交易所代码 + TSecurityFtdcExchangeIDType ExchangeID; + ///合约代码 + TSecurityFtdcInstrumentIDType InstrumentID; + ///成交价格 + TSecurityFtdcPriceType Price; + ///成交数量 + TSecurityFtdcVolumeType Volume; + ///报单类型 + TSecurityFtdcOrderKindType OrderKind; + ///功能码 + TSecurityFtdcFunctionCodeType FunctionCode; +}; + + +_LTS_NS_END_ + +#endif diff --git a/vn.lts/pyscript/l2/SecurityFtdcL2MDUserApi.h b/vn.lts/pyscript/l2/SecurityFtdcL2MDUserApi.h new file mode 100644 index 00000000..d86dd1dc --- /dev/null +++ b/vn.lts/pyscript/l2/SecurityFtdcL2MDUserApi.h @@ -0,0 +1,150 @@ +///////////////////////////////////////////////////////////////////////// +///@company shanghai liber information Technology Co.,Ltd +///@file SecurityFtdcL2MDUserApi.h +///@brief 定义客户端接口 +///////////////////////////////////////////////////////////////////////// + +#if !defined(SECURITY_L2MD_FTDCUSERAPI_H) +#define SECURITY_L2MD_FTDCUSERAPI_H + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#include "SecurityFtdcL2MDUserApiStruct.h" + +_LTS_NS_BEGIN_ +#if defined(L2MD_USERAPI_IS_LIB) && defined(WINDOWS) +#ifdef LIB_L2MD_USER_API_EXPORT +#define L2MD_USER_API_EXPORT __declspec(dllexport) +#else +#define L2MD_USER_API_EXPORT __declspec(dllimport) +#endif +#else +#define L2MD_USER_API_EXPORT +#endif + +class CSecurityFtdcL2MDUserSpi +{ +public: + ///当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。 + virtual void OnFrontConnected(){}; + + ///当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。 + ///@param nReason 错误原因 + /// 0x1001 网络读失败 + /// 0x1002 网络写失败 + /// 0x2001 接收心跳超时 + /// 0x2002 发送心跳失败 + /// 0x2003 收到错误报文 + virtual void OnFrontDisconnected(int nReason){}; + + ///心跳超时警告 + virtual void OnHeartBeatWarning(int nTimeLapse){}; + + ///错误应答 + virtual void OnRspError(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; + + ///登录请求响应 + virtual void OnRspUserLogin(CSecurityFtdcUserLoginField *pUserLogin, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; + + ///登出请求响应 + virtual void OnRspUserLogout(CSecurityFtdcUserLogoutField *pUserLogout, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; + + ///订阅Level2行情应答 + virtual void OnRspSubL2MarketData(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; + + ///取消订阅Level2行情应答 + virtual void OnRspUnSubL2MarketData(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; + + ///订阅Level2指数行情应答 + virtual void OnRspSubL2Index(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; + + ///取消订阅Level2指数行情应答 + virtual void OnRspUnSubL2Index(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; + + ///Level2行情通知 + virtual void OnRtnL2MarketData(CSecurityFtdcL2MarketDataField *pL2MarketData) {}; + + ///Level2指数行情通知 + virtual void OnRtnL2Index(CSecurityFtdcL2IndexField *pL2Index) {}; + + ///订阅逐笔委托及成交应答 + virtual void OnRspSubL2OrderAndTrade(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; + + ///取消订阅逐笔委托及成交应答 + virtual void OnRspUnSubL2OrderAndTrade(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) {}; + + ///Level2委托通知 + virtual void OnRtnL2Order(CSecurityFtdcL2OrderField *pL2Order) {}; + + ///Level2成交通知 + virtual void OnRtnL2Trade(CSecurityFtdcL2TradeField *pL2Trade) {}; + + ///通知清理SSE买卖一队列中数量为0的报单 + virtual void OnNtfCheckOrderList(TSecurityFtdcInstrumentIDType InstrumentID, TSecurityFtdcFunctionCodeType FunctionCode) {}; +}; + +#ifndef WINDOWS + #if __GNUC__ >= 4 + #pragma GCC visibility push(default) + #endif +#endif +class L2MD_USER_API_EXPORT CSecurityFtdcL2MDUserApi +{ +public: + ///创建UserApi + static CSecurityFtdcL2MDUserApi *CreateFtdcL2MDUserApi(const bool bIsMulticast=false); + + ///删除接口对象本身 + ///@remark 不再使用本接口对象时,调用该函数删除接口对象 + virtual void Release() = 0; + + ///初始化 + ///@remark 初始化运行环境,只有调用后,接口才开始工作 + virtual void Init() = 0; + + ///等待接口线程结束运行 + virtual int Join() = 0; + + ///获取当前交易日 + ///@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(CSecurityFtdcL2MDUserSpi *pSpi) = 0; + + virtual int SubscribeL2MarketData(char *ppInstrumentID[], int nCount, char* pExchageID) = 0; + + virtual int UnSubscribeL2MarketData(char *ppInstrumentID[], int nCount, char* pExchageID) = 0; + + virtual int SubscribeL2Index(char *ppInstrumentID[], int nCount, char* pExchageID) = 0; + + virtual int UnSubscribeL2Index(char *ppInstrumentID[], int nCount, char* pExchageID) = 0; + + virtual int SubscribeL2OrderAndTrade() = 0; + + virtual int UnSubscribeL2OrderAndTrade() = 0; + + ///登录请求 + virtual int ReqUserLogin(CSecurityFtdcUserLoginField *pUserLogin, int nRequestID) = 0; + + ///登出请求 + virtual int ReqUserLogout(CSecurityFtdcUserLogoutField *pUserLogout, int nRequestID) = 0; +protected: + ~CSecurityFtdcL2MDUserApi(){}; +}; +#ifndef WINDOWS + #if __GNUC__ >= 4 + #pragma GCC visibility pop + #endif +#endif +_LTS_NS_END_ +#endif diff --git a/vn.lts/pyscript/l2/SecurityFtdcL2MDUserApiDataType.h b/vn.lts/pyscript/l2/SecurityFtdcL2MDUserApiDataType.h new file mode 100644 index 00000000..c2c6eb08 --- /dev/null +++ b/vn.lts/pyscript/l2/SecurityFtdcL2MDUserApiDataType.h @@ -0,0 +1,213 @@ +///////////////////////////////////////////////////////////////////////// +///@company shanghai liber information Technology Co.,Ltd +///@file SecurityFtdcL2MDUserApiDataType.h +///@brief 定义业务数据类型 +///////////////////////////////////////////////////////////////////////// + +#ifndef SECURITY_L2MD_FTDCDATATYPE_H +#define SECURITY_L2MD_FTDCDATATYPE_H + +#include "LTS_ns.h" + +_LTS_NS_BEGIN_ + +///////////////////////////////////////////////////////////////////////// +///TFtdcErrorIDType是一个错误代码类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcErrorIDType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcErrorMsgType是一个错误信息类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcErrorMsgType[81]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcBrokerIDType是一个经纪公司代码类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcBrokerIDType[11]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcUserIDType是一个用户代码类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcUserIDType[16]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcUserNameType是一个用户名称类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcUserNameType[81]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcPasswordType是一个密码类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcPasswordType[41]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcExchangeIDType是一个交易所代码类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcExchangeIDType[9]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcInstrumentIDType是一个合约代码类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcInstrumentIDType[31]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcDateType是一个日期类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcDateType[9]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcTimeType是一个时间类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcTimeType[9]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcPriceType是一个价格类型 +///////////////////////////////////////////////////////////////////////// +typedef double TSecurityFtdcPriceType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcVolumeType是一个数量类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcVolumeType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcLargeVolumeType是一个大额数量类型 +///////////////////////////////////////////////////////////////////////// +typedef double TSecurityFtdcLargeVolumeType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcRatioType是一个比率类型 +///////////////////////////////////////////////////////////////////////// +typedef double TSecurityFtdcRatioType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcMoneyType是一个资金类型 +///////////////////////////////////////////////////////////////////////// +typedef double TSecurityFtdcMoneyType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcPriceLevelType是一个价格深度类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcPriceLevelType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcBoolType是一个布尔型类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcBoolType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcIndexType是一个指数类型 +///////////////////////////////////////////////////////////////////////// +typedef double TSecurityFtdcIndexType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcDataLevelType是一个行情数据等级类型 +///////////////////////////////////////////////////////////////////////// +///全量行情 +#define SECURITY_FTDC_DL_FULL '0' +///L10行情 +#define SECURITY_FTDC_DL_L10 '1' +///L5行情 +#define SECURITY_FTDC_DL_L5 '2' + +typedef char TSecurityFtdcDataLevelType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcIPAddressType是一个IP地址类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcIPAddressType[16]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcIPPortType是一个IP端口类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcIPPortType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcBeginStringType是一个step起始串类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcBeginStringType[17]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcBodyLengthType是一个消息体长度类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcBodyLengthType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcMsgTypeType是一个消息类型类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcMsgTypeType[9]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcSenderCompIDType是一个发送方代码类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcSenderCompIDType[33]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcTargetCompIDType是一个接收方代码类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcTargetCompIDType[33]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcMsgSeqNumType是一个头消息序号标签34类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcMsgSeqNumType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcSendingTimeType是一个发送时间类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcSendingTimeType[21]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcMessageEncodingType是一个消息中Encoded域的字符编码类型类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcMessageEncodingType[21]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcCheckSumType是一个校验和类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcCheckSumType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcEncryptMethodType是一个加密方法类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcEncryptMethodType[9]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcHeartBtIntType是一个心跳间隔类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcHeartBtIntType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcInterfaceVersionType是一个行情数据接口版本号类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcInterfaceVersionType[9]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcMsgSeqIDType是一个消息序号标签10072类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcMsgSeqIDType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcGroupIDType是一个组号类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcGroupIDType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcGroupNoType是一个组序类型 +///////////////////////////////////////////////////////////////////////// +typedef int TSecurityFtdcGroupNoType; + +///////////////////////////////////////////////////////////////////////// +///TFtdcOrderKindType是一个报单类型类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcOrderKindType[2]; + +///////////////////////////////////////////////////////////////////////// +///TFtdcFunctionCodeType是一个功能码类型 +///////////////////////////////////////////////////////////////////////// +typedef char TSecurityFtdcFunctionCodeType[2]; + +_LTS_NS_END_ + +#endif diff --git a/vn.lts/pyscript/l2/SecurityFtdcL2MDUserApiStruct.h b/vn.lts/pyscript/l2/SecurityFtdcL2MDUserApiStruct.h new file mode 100644 index 00000000..99330028 --- /dev/null +++ b/vn.lts/pyscript/l2/SecurityFtdcL2MDUserApiStruct.h @@ -0,0 +1,786 @@ +///////////////////////////////////////////////////////////////////////// +///@company shanghai liber information Technology Co.,Ltd +///@file SecurityFtdcL2MDUserApiStruct.h +///@brief 定义业务数据结构 +///////////////////////////////////////////////////////////////////////// + +#if !defined(SECURITY_L2MD_FTDCSTRUCT_H) +#define SECURITY_L2MD_FTDCSTRUCT_H + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#include "SecurityFtdcL2MDUserApiDataType.h" + +_LTS_NS_BEGIN_ + +///响应信息 +struct CSecurityFtdcRspInfoField +{ + ///错误代码 + TSecurityFtdcErrorIDType ErrorID; + ///错误信息 + TSecurityFtdcErrorMsgType ErrorMsg; +}; + +///用户登录信息 +struct CSecurityFtdcUserLoginField +{ + ///交易日 + TSecurityFtdcDateType TradingDay; + ///经纪公司代码 + TSecurityFtdcBrokerIDType BrokerID; + ///用户代码 + TSecurityFtdcUserIDType UserID; + ///密码 + TSecurityFtdcPasswordType Password; + ///行情数据等级 + TSecurityFtdcDataLevelType DataLevel; +}; + +///用户登出信息 +struct CSecurityFtdcUserLogoutField +{ + ///经纪公司代码 + TSecurityFtdcBrokerIDType BrokerID; + ///用户代码 + TSecurityFtdcUserIDType UserID; +}; + +///指定的合约 +struct CSecurityFtdcSpecificInstrumentField +{ + ///合约代码 + TSecurityFtdcInstrumentIDType InstrumentID; + ///交易所代码 + TSecurityFtdcExchangeIDType ExchangeID; +}; + +///Level2行情 +struct CSecurityFtdcL2MarketDataField +{ + ///交易日 + TSecurityFtdcDateType TradingDay; + ///时间戳 + TSecurityFtdcTimeType TimeStamp; + ///交易所代码 + TSecurityFtdcExchangeIDType ExchangeID; + ///合约代码 + TSecurityFtdcInstrumentIDType InstrumentID; + ///昨收盘价 + TSecurityFtdcPriceType PreClosePrice; + ///今开盘价 + TSecurityFtdcPriceType OpenPrice; + ///收盘价 + TSecurityFtdcPriceType ClosePrice; + ///净值估值 + TSecurityFtdcPriceType IOPV; + ///到期收益率 + TSecurityFtdcRatioType YieldToMaturity; + ///最高价 + TSecurityFtdcPriceType HighPrice; + ///最低价 + TSecurityFtdcPriceType LowPrice; + ///最新价 + TSecurityFtdcPriceType LastPrice; + ///成交笔数 + TSecurityFtdcVolumeType TradeCount; + ///成交总量 + TSecurityFtdcLargeVolumeType TotalTradeVolume; + ///成交总金额 + TSecurityFtdcMoneyType TotalTradeValue; + ///委托买入总量 + TSecurityFtdcLargeVolumeType TotalBidVolume; + ///加权平均委买价 + TSecurityFtdcPriceType WeightedAvgBidPrice; + ///债券加权平均委买价 + TSecurityFtdcPriceType AltWeightedAvgBidPrice; + ///委托卖出总量 + TSecurityFtdcLargeVolumeType TotalOfferVolume; + ///加权平均委卖价 + TSecurityFtdcPriceType WeightedAvgOfferPrice; + ///债券加权平均委卖价格 + TSecurityFtdcPriceType AltWeightedAvgOfferPrice; + ///买价深度 + TSecurityFtdcPriceLevelType BidPriceLevel; + ///卖价深度 + TSecurityFtdcPriceLevelType OfferPriceLevel; + ///申买价一 + TSecurityFtdcPriceType BidPrice1; + ///申买量一 + TSecurityFtdcVolumeType BidVolume1; + ///实际买总委托笔数一 + TSecurityFtdcVolumeType BidCount1; + ///申买价二 + TSecurityFtdcPriceType BidPrice2; + ///申买量二 + TSecurityFtdcVolumeType BidVolume2; + ///实际买总委托笔数二 + TSecurityFtdcVolumeType BidCount2; + ///申买价三 + TSecurityFtdcPriceType BidPrice3; + ///申买量三 + TSecurityFtdcVolumeType BidVolume3; + ///实际买总委托笔数三 + TSecurityFtdcVolumeType BidCount3; + ///申买价四 + TSecurityFtdcPriceType BidPrice4; + ///申买量四 + TSecurityFtdcVolumeType BidVolume4; + ///实际买总委托笔数四 + TSecurityFtdcVolumeType BidCount4; + ///申买价五 + TSecurityFtdcPriceType BidPrice5; + ///申买量五 + TSecurityFtdcVolumeType BidVolume5; + ///实际买总委托笔数五 + TSecurityFtdcVolumeType BidCount5; + ///申买价六 + TSecurityFtdcPriceType BidPrice6; + ///申买量六 + TSecurityFtdcVolumeType BidVolume6; + ///实际买总委托笔数六 + TSecurityFtdcVolumeType BidCount6; + ///申买价七 + TSecurityFtdcPriceType BidPrice7; + ///申买量七 + TSecurityFtdcVolumeType BidVolume7; + ///实际买总委托笔数七 + TSecurityFtdcVolumeType BidCount7; + ///申买价八 + TSecurityFtdcPriceType BidPrice8; + ///申买量八 + TSecurityFtdcVolumeType BidVolume8; + ///实际买总委托笔数八 + TSecurityFtdcVolumeType BidCount8; + ///申买价九 + TSecurityFtdcPriceType BidPrice9; + ///申买量九 + TSecurityFtdcVolumeType BidVolume9; + ///实际买总委托笔数九 + TSecurityFtdcVolumeType BidCount9; + ///申买价十 + TSecurityFtdcPriceType BidPriceA; + ///申买量十 + TSecurityFtdcVolumeType BidVolumeA; + ///实际买总委托笔数十 + TSecurityFtdcVolumeType BidCountA; + ///申卖价一 + TSecurityFtdcPriceType OfferPrice1; + ///申卖量一 + TSecurityFtdcVolumeType OfferVolume1; + ///实际卖总委托笔数一 + TSecurityFtdcVolumeType OfferCount1; + ///申卖价二 + TSecurityFtdcPriceType OfferPrice2; + ///申卖量二 + TSecurityFtdcVolumeType OfferVolume2; + ///实际卖总委托笔数二 + TSecurityFtdcVolumeType OfferCount2; + ///申卖价三 + TSecurityFtdcPriceType OfferPrice3; + ///申卖量三 + TSecurityFtdcVolumeType OfferVolume3; + ///实际卖总委托笔数三 + TSecurityFtdcVolumeType OfferCount3; + ///申卖价四 + TSecurityFtdcPriceType OfferPrice4; + ///申卖量四 + TSecurityFtdcVolumeType OfferVolume4; + ///实际卖总委托笔数四 + TSecurityFtdcVolumeType OfferCount4; + ///申卖价五 + TSecurityFtdcPriceType OfferPrice5; + ///申卖量五 + TSecurityFtdcVolumeType OfferVolume5; + ///实际卖总委托笔数五 + TSecurityFtdcVolumeType OfferCount5; + ///申卖价六 + TSecurityFtdcPriceType OfferPrice6; + ///申卖量六 + TSecurityFtdcVolumeType OfferVolume6; + ///实际卖总委托笔数六 + TSecurityFtdcVolumeType OfferCount6; + ///申卖价七 + TSecurityFtdcPriceType OfferPrice7; + ///申卖量七 + TSecurityFtdcVolumeType OfferVolume7; + ///实际卖总委托笔数七 + TSecurityFtdcVolumeType OfferCount7; + ///申卖价八 + TSecurityFtdcPriceType OfferPrice8; + ///申卖量八 + TSecurityFtdcVolumeType OfferVolume8; + ///实际卖总委托笔数八 + TSecurityFtdcVolumeType OfferCount8; + ///申卖价九 + TSecurityFtdcPriceType OfferPrice9; + ///申卖量九 + TSecurityFtdcVolumeType OfferVolume9; + ///实际卖总委托笔数九 + TSecurityFtdcVolumeType OfferCount9; + ///申卖价十 + TSecurityFtdcPriceType OfferPriceA; + ///申卖量十 + TSecurityFtdcVolumeType OfferVolumeA; + ///实际卖总委托笔数十 + TSecurityFtdcVolumeType OfferCountA; +}; + +///Level2行情更新时间属性 +struct CSecurityFtdcL2UpdateTimeField +{ + ///交易日 + TSecurityFtdcDateType TradingDay; + ///时间戳 + TSecurityFtdcTimeType TimeStamp; + ///交易所代码 + TSecurityFtdcExchangeIDType ExchangeID; + ///合约代码 + TSecurityFtdcInstrumentIDType InstrumentID; +}; + +///Level2行情静态属性 +struct CSecurityFtdcL2StaticField +{ + ///昨收盘价 + TSecurityFtdcPriceType PreClosePrice; + ///今开盘价 + TSecurityFtdcPriceType OpenPrice; + ///收盘价 + TSecurityFtdcPriceType ClosePrice; + ///净值估值 + TSecurityFtdcPriceType IOPV; + ///到期收益率 + TSecurityFtdcRatioType YieldToMaturity; +}; + +///Level2行情价格区间属性 +struct CSecurityFtdcL2PriceIntervalField +{ + ///最高价 + TSecurityFtdcPriceType HighPrice; + ///最低价 + TSecurityFtdcPriceType LowPrice; +}; + +///Level2行情基本信息 +struct CSecurityFtdcL2BaseField +{ + ///最新价 + TSecurityFtdcPriceType LastPrice; +}; + +///Level2成交信息 +struct CSecurityFtdcL2TradedField +{ + ///成交笔数 + TSecurityFtdcVolumeType TradeCount; + ///成交总量 + TSecurityFtdcLargeVolumeType TotalTradeVolume; + ///成交总金额 + TSecurityFtdcMoneyType TotalTradeValue; +}; + +///Level2行情数据属性 +struct CSecurityFtdcL2DataLevelField +{ + ///价格 + TSecurityFtdcPriceType Price; + ///数量 + TSecurityFtdcVolumeType Volume; + ///实际总委托笔数 + TSecurityFtdcVolumeType Count; +}; + +///Level2委买信息 +struct CSecurityFtdcL2BidOrderField +{ + ///委托买入总量 + TSecurityFtdcLargeVolumeType TotalBidVolume; + ///加权平均委买价 + TSecurityFtdcPriceType WeightedAvgBidPrice; + ///债券加权平均委买价 + TSecurityFtdcPriceType AltWeightedAvgBidPrice; +}; + +///Level2委卖信息 +struct CSecurityFtdcL2OfferOrderField +{ + ///委托卖出总量 + TSecurityFtdcLargeVolumeType TotalOfferVolume; + ///加权平均委卖价 + TSecurityFtdcPriceType WeightedAvgOfferPrice; + ///债券加权平均委卖价格 + TSecurityFtdcPriceType AltWeightedAvgOfferPrice; +}; + +///Level2价格深度属性 +struct CSecurityFtdcL2PriceLevelField +{ + ///买价深度 + TSecurityFtdcPriceLevelType BidPriceLevel; + ///卖价深度 + TSecurityFtdcPriceLevelType OfferPriceLevel; +}; + +///Level2行情申买一属性 +struct CSecurityFtdcL2Bid1Field +{ + ///申买价一 + TSecurityFtdcPriceType BidPrice1; + ///申买量一 + TSecurityFtdcVolumeType BidVolume1; + ///实际买总委托笔数一 + TSecurityFtdcVolumeType BidCount1; +}; + +///Level2行情申卖一属性 +struct CSecurityFtdcL2Offer1Field +{ + ///申卖价一 + TSecurityFtdcPriceType OfferPrice1; + ///申卖量一 + TSecurityFtdcVolumeType OfferVolume1; + ///实际卖总委托笔数一 + TSecurityFtdcVolumeType OfferCount1; +}; + +///Level2行情申买二属性 +struct CSecurityFtdcL2Bid2Field +{ + ///申买价二 + TSecurityFtdcPriceType BidPrice2; + ///申买量二 + TSecurityFtdcVolumeType BidVolume2; + ///实际买总委托笔数二 + TSecurityFtdcVolumeType BidCount2; +}; + +///Level2行情申卖二属性 +struct CSecurityFtdcL2Offer2Field +{ + ///申卖价二 + TSecurityFtdcPriceType OfferPrice2; + ///申卖量二 + TSecurityFtdcVolumeType OfferVolume2; + ///实际卖总委托笔数二 + TSecurityFtdcVolumeType OfferCount2; +}; + +///Level2行情申买三属性 +struct CSecurityFtdcL2Bid3Field +{ + ///申买价三 + TSecurityFtdcPriceType BidPrice3; + ///申买量三 + TSecurityFtdcVolumeType BidVolume3; + ///实际买总委托笔数三 + TSecurityFtdcVolumeType BidCount3; +}; + +///Level2行情申卖三属性 +struct CSecurityFtdcL2Offer3Field +{ + ///申卖价三 + TSecurityFtdcPriceType OfferPrice3; + ///申卖量三 + TSecurityFtdcVolumeType OfferVolume3; + ///实际卖总委托笔数三 + TSecurityFtdcVolumeType OfferCount3; +}; + +///Level2行情申买四属性 +struct CSecurityFtdcL2Bid4Field +{ + ///申买价四 + TSecurityFtdcPriceType BidPrice4; + ///申买量四 + TSecurityFtdcVolumeType BidVolume4; + ///实际买总委托笔数四 + TSecurityFtdcVolumeType BidCount4; +}; + +///Level2行情申卖四属性 +struct CSecurityFtdcL2Offer4Field +{ + ///申卖价四 + TSecurityFtdcPriceType OfferPrice4; + ///申卖量四 + TSecurityFtdcVolumeType OfferVolume4; + ///实际卖总委托笔数四 + TSecurityFtdcVolumeType OfferCount4; +}; + +///Level2行情申买五属性 +struct CSecurityFtdcL2Bid5Field +{ + ///申买价五 + TSecurityFtdcPriceType BidPrice5; + ///申买量五 + TSecurityFtdcVolumeType BidVolume5; + ///实际买总委托笔数五 + TSecurityFtdcVolumeType BidCount5; +}; + +///Level2行情申卖五属性 +struct CSecurityFtdcL2Offer5Field +{ + ///申卖价五 + TSecurityFtdcPriceType OfferPrice5; + ///申卖量五 + TSecurityFtdcVolumeType OfferVolume5; + ///实际卖总委托笔数五 + TSecurityFtdcVolumeType OfferCount5; +}; + +///Level2行情申买六属性 +struct CSecurityFtdcL2Bid6Field +{ + ///申买价六 + TSecurityFtdcPriceType BidPrice6; + ///申买量六 + TSecurityFtdcVolumeType BidVolume6; + ///实际买总委托笔数六 + TSecurityFtdcVolumeType BidCount6; +}; + +///Level2行情申卖六属性 +struct CSecurityFtdcL2Offer6Field +{ + ///申卖价六 + TSecurityFtdcPriceType OfferPrice6; + ///申卖量六 + TSecurityFtdcVolumeType OfferVolume6; + ///实际卖总委托笔数六 + TSecurityFtdcVolumeType OfferCount6; +}; + +///Level2行情申买七属性 +struct CSecurityFtdcL2Bid7Field +{ + ///申买价七 + TSecurityFtdcPriceType BidPrice7; + ///申买量七 + TSecurityFtdcVolumeType BidVolume7; + ///实际买总委托笔数七 + TSecurityFtdcVolumeType BidCount7; +}; + +///Level2行情申卖七属性 +struct CSecurityFtdcL2Offer7Field +{ + ///申卖价七 + TSecurityFtdcPriceType OfferPrice7; + ///申卖量七 + TSecurityFtdcVolumeType OfferVolume7; + ///实际卖总委托笔数七 + TSecurityFtdcVolumeType OfferCount7; +}; + +///Level2行情申买八属性 +struct CSecurityFtdcL2Bid8Field +{ + ///申买价八 + TSecurityFtdcPriceType BidPrice8; + ///申买量八 + TSecurityFtdcVolumeType BidVolume8; + ///实际买总委托笔数八 + TSecurityFtdcVolumeType BidCount8; +}; + +///Level2行情申卖八属性 +struct CSecurityFtdcL2Offer8Field +{ + ///申卖价八 + TSecurityFtdcPriceType OfferPrice8; + ///申卖量八 + TSecurityFtdcVolumeType OfferVolume8; + ///实际卖总委托笔数八 + TSecurityFtdcVolumeType OfferCount8; +}; + +///Level2行情申买九属性 +struct CSecurityFtdcL2Bid9Field +{ + ///申买价九 + TSecurityFtdcPriceType BidPrice9; + ///申买量九 + TSecurityFtdcVolumeType BidVolume9; + ///实际买总委托笔数九 + TSecurityFtdcVolumeType BidCount9; +}; + +///Level2行情申卖九属性 +struct CSecurityFtdcL2Offer9Field +{ + ///申卖价九 + TSecurityFtdcPriceType OfferPrice9; + ///申卖量九 + TSecurityFtdcVolumeType OfferVolume9; + ///实际卖总委托笔数九 + TSecurityFtdcVolumeType OfferCount9; +}; + +///Level2行情申买十属性 +struct CSecurityFtdcL2BidAField +{ + ///申买价十 + TSecurityFtdcPriceType BidPriceA; + ///申买量十 + TSecurityFtdcVolumeType BidVolumeA; + ///实际买总委托笔数十 + TSecurityFtdcVolumeType BidCountA; +}; + +///Level2行情申卖十属性 +struct CSecurityFtdcL2OfferAField +{ + ///申卖价十 + TSecurityFtdcPriceType OfferPriceA; + ///申卖量十 + TSecurityFtdcVolumeType OfferVolumeA; + ///实际卖总委托笔数十 + TSecurityFtdcVolumeType OfferCountA; +}; + +///Level2行情申买属性 +struct CSecurityFtdcL2BidField +{ + ///申买价一 + TSecurityFtdcPriceType BidPrice1; + ///申买量一 + TSecurityFtdcVolumeType BidVolume1; + ///实际买总委托笔数一 + TSecurityFtdcVolumeType BidCount1; + ///申买价二 + TSecurityFtdcPriceType BidPrice2; + ///申买量二 + TSecurityFtdcVolumeType BidVolume2; + ///实际买总委托笔数二 + TSecurityFtdcVolumeType BidCount2; + ///申买价三 + TSecurityFtdcPriceType BidPrice3; + ///申买量三 + TSecurityFtdcVolumeType BidVolume3; + ///实际买总委托笔数三 + TSecurityFtdcVolumeType BidCount3; + ///申买价四 + TSecurityFtdcPriceType BidPrice4; + ///申买量四 + TSecurityFtdcVolumeType BidVolume4; + ///实际买总委托笔数四 + TSecurityFtdcVolumeType BidCount4; + ///申买价五 + TSecurityFtdcPriceType BidPrice5; + ///申买量五 + TSecurityFtdcVolumeType BidVolume5; + ///实际买总委托笔数五 + TSecurityFtdcVolumeType BidCount5; + ///申买价六 + TSecurityFtdcPriceType BidPrice6; + ///申买量六 + TSecurityFtdcVolumeType BidVolume6; + ///实际买总委托笔数六 + TSecurityFtdcVolumeType BidCount6; + ///申买价七 + TSecurityFtdcPriceType BidPrice7; + ///申买量七 + TSecurityFtdcVolumeType BidVolume7; + ///实际买总委托笔数七 + TSecurityFtdcVolumeType BidCount7; + ///申买价八 + TSecurityFtdcPriceType BidPrice8; + ///申买量八 + TSecurityFtdcVolumeType BidVolume8; + ///实际买总委托笔数八 + TSecurityFtdcVolumeType BidCount8; + ///申买价九 + TSecurityFtdcPriceType BidPrice9; + ///申买量九 + TSecurityFtdcVolumeType BidVolume9; + ///实际买总委托笔数九 + TSecurityFtdcVolumeType BidCount9; + ///申买价十 + TSecurityFtdcPriceType BidPriceA; + ///申买量十 + TSecurityFtdcVolumeType BidVolumeA; + ///实际买总委托笔数十 + TSecurityFtdcVolumeType BidCountA; +}; + +///Level2行情申卖属性 +struct CSecurityFtdcL2OfferField +{ + ///申卖价一 + TSecurityFtdcPriceType OfferPrice1; + ///申卖量一 + TSecurityFtdcVolumeType OfferVolume1; + ///实际卖总委托笔数一 + TSecurityFtdcVolumeType OfferCount1; + ///申卖价二 + TSecurityFtdcPriceType OfferPrice2; + ///申卖量二 + TSecurityFtdcVolumeType OfferVolume2; + ///实际卖总委托笔数二 + TSecurityFtdcVolumeType OfferCount2; + ///申卖价三 + TSecurityFtdcPriceType OfferPrice3; + ///申卖量三 + TSecurityFtdcVolumeType OfferVolume3; + ///实际卖总委托笔数三 + TSecurityFtdcVolumeType OfferCount3; + ///申卖价四 + TSecurityFtdcPriceType OfferPrice4; + ///申卖量四 + TSecurityFtdcVolumeType OfferVolume4; + ///实际卖总委托笔数四 + TSecurityFtdcVolumeType OfferCount4; + ///申卖价五 + TSecurityFtdcPriceType OfferPrice5; + ///申卖量五 + TSecurityFtdcVolumeType OfferVolume5; + ///实际卖总委托笔数五 + TSecurityFtdcVolumeType OfferCount5; + ///申卖价六 + TSecurityFtdcPriceType OfferPrice6; + ///申卖量六 + TSecurityFtdcVolumeType OfferVolume6; + ///实际卖总委托笔数六 + TSecurityFtdcVolumeType OfferCount6; + ///申卖价七 + TSecurityFtdcPriceType OfferPrice7; + ///申卖量七 + TSecurityFtdcVolumeType OfferVolume7; + ///实际卖总委托笔数七 + TSecurityFtdcVolumeType OfferCount7; + ///申卖价八 + TSecurityFtdcPriceType OfferPrice8; + ///申卖量八 + TSecurityFtdcVolumeType OfferVolume8; + ///实际卖总委托笔数八 + TSecurityFtdcVolumeType OfferCount8; + ///申卖价九 + TSecurityFtdcPriceType OfferPrice9; + ///申卖量九 + TSecurityFtdcVolumeType OfferVolume9; + ///实际卖总委托笔数九 + TSecurityFtdcVolumeType OfferCount9; + ///申卖价十 + TSecurityFtdcPriceType OfferPriceA; + ///申卖量十 + TSecurityFtdcVolumeType OfferVolumeA; + ///实际卖总委托笔数十 + TSecurityFtdcVolumeType OfferCountA; +}; + +///Level2指数行情 +struct CSecurityFtdcL2IndexField +{ + ///交易日 + TSecurityFtdcDateType TradingDay; + ///行情时间(秒) + TSecurityFtdcTimeType TimeStamp; + ///交易所代码 + TSecurityFtdcExchangeIDType ExchangeID; + ///指数代码 + TSecurityFtdcInstrumentIDType InstrumentID; + ///前收盘指数 + TSecurityFtdcIndexType PreCloseIndex; + ///今开盘指数 + TSecurityFtdcIndexType OpenIndex; + ///今日收盘指数 + TSecurityFtdcIndexType CloseIndex; + ///最高指数 + TSecurityFtdcIndexType HighIndex; + ///最低指数 + TSecurityFtdcIndexType LowIndex; + ///最新指数 + TSecurityFtdcIndexType LastIndex; + ///参与计算相应指数的成交金额(元) + TSecurityFtdcMoneyType TurnOver; + ///参与计算相应指数的交易数量(手) + TSecurityFtdcLargeVolumeType TotalVolume; +}; + +///Level2行情用户信息 +struct CSecurityFtdcL2UserInfoField +{ + ///经纪公司代码 + TSecurityFtdcBrokerIDType BrokerID; + ///用户代码 + TSecurityFtdcUserIDType UserID; + ///用户名称 + TSecurityFtdcUserNameType UserName; + ///密码 + TSecurityFtdcPasswordType Password; + ///行情数据等级 + TSecurityFtdcDataLevelType DataLevel; +}; + +///UDP组播组信息 +struct CSecurityFtdcMulticastGroupInfoField +{ + ///组播组IP地址 + TSecurityFtdcIPAddressType GroupIP; + ///组播组IP端口 + TSecurityFtdcIPPortType GroupPort; + ///源地址 + TSecurityFtdcIPAddressType SourceIP; +}; + +///Level2逐笔委托 +struct CSecurityFtdcL2OrderField +{ + ///委托组 + TSecurityFtdcGroupIDType OrderGroupID; + ///委托序号 + TSecurityFtdcGroupNoType OrderIndex; + ///委托时间(秒) + TSecurityFtdcTimeType OrderTime; + ///交易所代码 + TSecurityFtdcExchangeIDType ExchangeID; + ///合约代码 + TSecurityFtdcInstrumentIDType InstrumentID; + ///委托价格 + TSecurityFtdcPriceType Price; + ///委托数量 + TSecurityFtdcVolumeType Volume; + ///报单类型 + TSecurityFtdcOrderKindType OrderKind; + ///功能码 + TSecurityFtdcFunctionCodeType FunctionCode; +}; + +///Level2逐笔成交 +struct CSecurityFtdcL2TradeField +{ + ///成交组 + TSecurityFtdcGroupIDType TradeGroupID; + ///成交序号 + TSecurityFtdcGroupNoType TradeIndex; + ///买方委托序号 + TSecurityFtdcGroupNoType BuyIndex; + ///卖方委托序号 + TSecurityFtdcGroupNoType SellIndex; + ///成交时间(秒) + TSecurityFtdcTimeType TradeTime; + ///交易所代码 + TSecurityFtdcExchangeIDType ExchangeID; + ///合约代码 + TSecurityFtdcInstrumentIDType InstrumentID; + ///成交价格 + TSecurityFtdcPriceType Price; + ///成交数量 + TSecurityFtdcVolumeType Volume; + ///报单类型 + TSecurityFtdcOrderKindType OrderKind; + ///功能码 + TSecurityFtdcFunctionCodeType FunctionCode; +}; + + +_LTS_NS_END_ + +#endif diff --git a/vn.lts/pyscript/l2/generate_data_type.py b/vn.lts/pyscript/l2/generate_data_type.py new file mode 100644 index 00000000..64374ff3 --- /dev/null +++ b/vn.lts/pyscript/l2/generate_data_type.py @@ -0,0 +1,98 @@ +# encoding: UTF-8 + +__author__ = 'CHENXY' + +# C++鍜宲ython绫诲瀷鐨勬槧灏勫瓧鍏 +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('SecurityFtdcL2MDUserApiDataType.h','r') + fpy = open('l2_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() + diff --git a/vn.lts/pyscript/l2/generate_l2_functions.py b/vn.lts/pyscript/l2/generate_l2_functions.py new file mode 100644 index 00000000..f1506d80 --- /dev/null +++ b/vn.lts/pyscript/l2/generate_l2_functions.py @@ -0,0 +1,291 @@ +# encoding: UTF-8 + +__author__ = 'CHENXY' + +from string import join +from l2_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) + + # 鐢熸垚.h鏂囦欢涓殑process閮ㄥ垎 + process_line = 'void process' + cbName[2:] + '(Task task);\n' + fheaderprocess.write(process_line) + fheaderprocess.write('\n') + + # 鐢熸垚.h鏂囦欢涓殑on閮ㄥ垎 + if 'OnRspError' in cbName: + on_line = 'virtual void on' + cbName[2:] + '(dict error, int id, bool last) {};\n' + elif 'OnRsp' in cbName: + on_line = 'virtual void on' + cbName[2:] + '(dict data, dict error, int id, bool last) {};\n' + elif 'OnRtn' in cbName: + on_line = 'virtual void on' + cbName[2:] + '(dict data) {};\n' + elif 'OnErrRtn' in cbName: + on_line = 'virtual void on' + cbName[2:] + '(dict data, dict error) {};\n' + else: + on_line = '' + fheaderon.write(on_line) + fheaderon.write('\n') + + # 鐢熸垚灏佽閮ㄥ垎 + createWrap(cbName) + + +#---------------------------------------------------------------------- +def createWrap(cbName): + """鍦≒ython灏佽娈典唬鐮佷腑杩涜澶勭悊""" + # 鐢熸垚.h鏂囦欢涓殑on閮ㄥ垎 + if 'OnRspError' in cbName: + on_line = 'virtual void on' + cbName[2:] + '(dict error, int id, bool last)\n' + override_line = '("on' + cbName[2:] + '")(error, id, last);\n' + elif 'OnRsp' in cbName: + on_line = 'virtual void on' + cbName[2:] + '(dict data, dict error, int id, bool last)\n' + override_line = '("on' + cbName[2:] + '")(data, error, id, last);\n' + elif 'OnRtn' in cbName: + on_line = 'virtual void on' + cbName[2:] + '(dict data)\n' + override_line = '("on' + cbName[2:] + '")(data);\n' + elif 'OnErrRtn' in cbName: + on_line = 'virtual void on' + cbName[2:] + '(dict data, dict error)\n' + override_line = '("on' + cbName[2:] + '")(data, error);\n' + else: + on_line = '' + + if on_line is not '': + fwrap.write(on_line) + fwrap.write('{\n') + fwrap.write('\t PyLock lock;\n') + fwrap.write('\n') + fwrap.write('\ttry\n') + fwrap.write('\t{\n') + fwrap.write('\t\tthis->get_override'+override_line) + fwrap.write('\t}\n') + fwrap.write('\tcatch (error_already_set const &)\n') + fwrap.write('\t{\n') + fwrap.write('\t\tPyErr_Print();\n') + fwrap.write('\t}\n') + fwrap.write('};\n') + fwrap.write('\n') + + + +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("\n") + 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("\n") + ftask.write("\tif (" + cbArgsValueList[i][1:] + ")\n") + ftask.write("\t{\n") + ftask.write("\t\ttask.task_data = " + cbArgsValueList[i] + ";\n") + ftask.write("\t}\n") + ftask.write("\telse\n") + ftask.write("\t{\n") + ftask.write("\t\t" + type_ + " empty_data = " + type_ + "();\n") + ftask.write("\t\tmemset(&empty_data, 0, sizeof(empty_data));\n") + ftask.write("\t\ttask.task_data = empty_data;\n") + ftask.write("\t}\n") + + ftask.write("\tthis->task_queue.push(task);\n") + ftask.write("};\n") + ftask.write("\n") + + +def createProcess(cbName, cbArgsTypeList, cbArgsValueList): + # 浠庨槦鍒椾腑鎻愬彇浠诲姟锛屽苟杞寲涓簆ython瀛楀吀 + 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) + + # 鐢熸垚.h鏂囦欢涓殑涓诲姩鍑芥暟閮ㄥ垎 + if 'Req' in fcName: + req_line = 'int req' + fcName[3:] + '(dict req, int nRequestID);\n' + fheaderfunction.write(req_line) + fheaderfunction.write('\n') + + +def createFunction(fcName, fcArgsTypeList, fcArgsValueList): + type_ = fcArgsTypeList[0] + struct = structDict[type_] + + ffunction.write('int TdApi::req' + fcName[3:] + '(dict req, int nRequestID)\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('SecurityFtdcL2MDUserApi.h', 'r') +ftask = open('lts_l2_task.cpp', 'w') +fprocess = open('lts_l2_process.cpp', 'w') +ffunction = open('lts_l2_function.cpp', 'w') +fdefine = open('lts_l2_define.cpp', 'w') +fswitch = open('lts_l2_switch.cpp', 'w') +fheaderprocess = open('lts_l2_header_process.h', 'w') +fheaderon = open('lts_l2_header_on.h', 'w') +fheaderfunction = open('lts_l2_header_function.h', 'w') +fwrap = open('lts_l2_wrap.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() +fheaderprocess.close() +fheaderon.close() +fheaderfunction.close() +fwrap.close() \ No newline at end of file diff --git a/vn.lts/pyscript/l2/generate_struct.py b/vn.lts/pyscript/l2/generate_struct.py new file mode 100644 index 00000000..070f41f4 --- /dev/null +++ b/vn.lts/pyscript/l2/generate_struct.py @@ -0,0 +1,56 @@ +# encoding: UTF-8 + +__author__ = 'CHENXY' + +from l2_data_type import * + +def main(): + """涓诲嚱鏁""" + fcpp = open('SecurityFtdcL2MDUserApiStruct.h', 'r') + fpy = open('l2_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() \ No newline at end of file diff --git a/vn.lts/pyscript/l2/l2_data_type.py b/vn.lts/pyscript/l2/l2_data_type.py new file mode 100644 index 00000000..e7542ffc --- /dev/null +++ b/vn.lts/pyscript/l2/l2_data_type.py @@ -0,0 +1,212 @@ +# encoding: UTF-8 + +defineDict = {} +typedefDict = {} + +#////////////////////////////////////////////////////////////////////// +#@company shanghai liber information Technology Co.,Ltd +#@file SecurityFtdcL2MDUserApiDataType.h +#@brief 瀹氫箟涓氬姟鏁版嵁绫诲瀷 +#////////////////////////////////////////////////////////////////////// + + + + +#////////////////////////////////////////////////////////////////////// +#TFtdcErrorIDType鏄竴涓敊璇唬鐮佺被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcErrorIDType"] = "int" + +#////////////////////////////////////////////////////////////////////// +#TFtdcErrorMsgType鏄竴涓敊璇俊鎭被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcErrorMsgType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcBrokerIDType鏄竴涓粡绾叕鍙镐唬鐮佺被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcBrokerIDType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcUserIDType鏄竴涓敤鎴蜂唬鐮佺被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcUserIDType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcUserNameType鏄竴涓敤鎴峰悕绉扮被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcUserNameType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcPasswordType鏄竴涓瘑鐮佺被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcPasswordType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcExchangeIDType鏄竴涓氦鏄撴墍浠g爜绫诲瀷 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcExchangeIDType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcInstrumentIDType鏄竴涓悎绾︿唬鐮佺被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcInstrumentIDType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcDateType鏄竴涓棩鏈熺被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcDateType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcTimeType鏄竴涓椂闂寸被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcTimeType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcPriceType鏄竴涓环鏍肩被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcPriceType"] = "float" + +#////////////////////////////////////////////////////////////////////// +#TFtdcVolumeType鏄竴涓暟閲忕被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcVolumeType"] = "int" + +#////////////////////////////////////////////////////////////////////// +#TFtdcLargeVolumeType鏄竴涓ぇ棰濇暟閲忕被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcLargeVolumeType"] = "float" + +#////////////////////////////////////////////////////////////////////// +#TFtdcRatioType鏄竴涓瘮鐜囩被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcRatioType"] = "float" + +#////////////////////////////////////////////////////////////////////// +#TFtdcMoneyType鏄竴涓祫閲戠被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcMoneyType"] = "float" + +#////////////////////////////////////////////////////////////////////// +#TFtdcPriceLevelType鏄竴涓环鏍兼繁搴︾被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcPriceLevelType"] = "int" + +#////////////////////////////////////////////////////////////////////// +#TFtdcBoolType鏄竴涓竷灏斿瀷绫诲瀷 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcBoolType"] = "int" + +#////////////////////////////////////////////////////////////////////// +#TFtdcIndexType鏄竴涓寚鏁扮被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcIndexType"] = "float" + +#////////////////////////////////////////////////////////////////////// +#TFtdcDataLevelType鏄竴涓鎯呮暟鎹瓑绾х被鍨 +#////////////////////////////////////////////////////////////////////// +#鍏ㄩ噺琛屾儏 +defineDict["SECURITY_FTDC_DL_FULL"] = '0' +#L10琛屾儏 +defineDict["SECURITY_FTDC_DL_L10"] = '1' +#L5琛屾儏 +defineDict["SECURITY_FTDC_DL_L5"] = '2' + +typedefDict["TSecurityFtdcDataLevelType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcIPAddressType鏄竴涓狪P鍦板潃绫诲瀷 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcIPAddressType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcIPPortType鏄竴涓狪P绔彛绫诲瀷 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcIPPortType"] = "int" + +#////////////////////////////////////////////////////////////////////// +#TFtdcBeginStringType鏄竴涓猻tep璧峰涓茬被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcBeginStringType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcBodyLengthType鏄竴涓秷鎭綋闀垮害绫诲瀷 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcBodyLengthType"] = "int" + +#////////////////////////////////////////////////////////////////////// +#TFtdcMsgTypeType鏄竴涓秷鎭被鍨嬬被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcMsgTypeType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcSenderCompIDType鏄竴涓彂閫佹柟浠g爜绫诲瀷 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcSenderCompIDType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcTargetCompIDType鏄竴涓帴鏀舵柟浠g爜绫诲瀷 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcTargetCompIDType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcMsgSeqNumType鏄竴涓ご娑堟伅搴忓彿鏍囩34绫诲瀷 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcMsgSeqNumType"] = "int" + +#////////////////////////////////////////////////////////////////////// +#TFtdcSendingTimeType鏄竴涓彂閫佹椂闂寸被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcSendingTimeType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcMessageEncodingType鏄竴涓秷鎭腑Encoded鍩熺殑瀛楃缂栫爜绫诲瀷绫诲瀷 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcMessageEncodingType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcCheckSumType鏄竴涓牎楠屽拰绫诲瀷 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcCheckSumType"] = "int" + +#////////////////////////////////////////////////////////////////////// +#TFtdcEncryptMethodType鏄竴涓姞瀵嗘柟娉曠被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcEncryptMethodType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcHeartBtIntType鏄竴涓績璺抽棿闅旂被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcHeartBtIntType"] = "int" + +#////////////////////////////////////////////////////////////////////// +#TFtdcInterfaceVersionType鏄竴涓鎯呮暟鎹帴鍙g増鏈彿绫诲瀷 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcInterfaceVersionType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcMsgSeqIDType鏄竴涓秷鎭簭鍙锋爣绛10072绫诲瀷 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcMsgSeqIDType"] = "int" + +#////////////////////////////////////////////////////////////////////// +#TFtdcGroupIDType鏄竴涓粍鍙风被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcGroupIDType"] = "int" + +#////////////////////////////////////////////////////////////////////// +#TFtdcGroupNoType鏄竴涓粍搴忕被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcGroupNoType"] = "int" + +#////////////////////////////////////////////////////////////////////// +#TFtdcOrderKindType鏄竴涓姤鍗曠被鍨嬬被鍨 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcOrderKindType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcFunctionCodeType鏄竴涓姛鑳界爜绫诲瀷 +#////////////////////////////////////////////////////////////////////// +typedefDict["TSecurityFtdcFunctionCodeType"] = "string" + + diff --git a/vn.lts/pyscript/l2/l2_struct.py b/vn.lts/pyscript/l2/l2_struct.py new file mode 100644 index 00000000..602164f0 --- /dev/null +++ b/vn.lts/pyscript/l2/l2_struct.py @@ -0,0 +1,790 @@ +# encoding: UTF-8 + +structDict = {} + +#////////////////////////////////////////////////////////////////////// +#@company shanghai liber information Technology Co.,Ltd +#@file SecurityFtdcL2MDUserApiStruct.h +#@brief 瀹氫箟涓氬姟鏁版嵁缁撴瀯 +#////////////////////////////////////////////////////////////////////// + + + + + + + + + + + + +#鍝嶅簲淇℃伅 +CSecurityFtdcRspInfoField = {} +#閿欒浠g爜 +CSecurityFtdcRspInfoField["ErrorID"] = "int" +#閿欒淇℃伅 +CSecurityFtdcRspInfoField["ErrorMsg"] = "string" +structDict['CSecurityFtdcRspInfoField'] = CSecurityFtdcRspInfoField + + +#鐢ㄦ埛鐧诲綍淇℃伅 +CSecurityFtdcUserLoginField = {} +#浜ゆ槗鏃 +CSecurityFtdcUserLoginField["TradingDay"] = "string" +#缁忕邯鍏徃浠g爜 +CSecurityFtdcUserLoginField["BrokerID"] = "string" +#鐢ㄦ埛浠g爜 +CSecurityFtdcUserLoginField["UserID"] = "string" +#瀵嗙爜 +CSecurityFtdcUserLoginField["Password"] = "string" +#琛屾儏鏁版嵁绛夌骇 +CSecurityFtdcUserLoginField["DataLevel"] = "string" +structDict['CSecurityFtdcUserLoginField'] = CSecurityFtdcUserLoginField + + +#鐢ㄦ埛鐧诲嚭淇℃伅 +CSecurityFtdcUserLogoutField = {} +#缁忕邯鍏徃浠g爜 +CSecurityFtdcUserLogoutField["BrokerID"] = "string" +#鐢ㄦ埛浠g爜 +CSecurityFtdcUserLogoutField["UserID"] = "string" +structDict['CSecurityFtdcUserLogoutField'] = CSecurityFtdcUserLogoutField + + +#鎸囧畾鐨勫悎绾 +CSecurityFtdcSpecificInstrumentField = {} +#鍚堢害浠g爜 +CSecurityFtdcSpecificInstrumentField["InstrumentID"] = "string" +#浜ゆ槗鎵浠g爜 +CSecurityFtdcSpecificInstrumentField["ExchangeID"] = "string" +structDict['CSecurityFtdcSpecificInstrumentField'] = CSecurityFtdcSpecificInstrumentField + + +#Level2琛屾儏 +CSecurityFtdcL2MarketDataField = {} +#浜ゆ槗鏃 +CSecurityFtdcL2MarketDataField["TradingDay"] = "string" +#鏃堕棿鎴 +CSecurityFtdcL2MarketDataField["TimeStamp"] = "string" +#浜ゆ槗鎵浠g爜 +CSecurityFtdcL2MarketDataField["ExchangeID"] = "string" +#鍚堢害浠g爜 +CSecurityFtdcL2MarketDataField["InstrumentID"] = "string" +#鏄ㄦ敹鐩樹环 +CSecurityFtdcL2MarketDataField["PreClosePrice"] = "float" +#浠婂紑鐩樹环 +CSecurityFtdcL2MarketDataField["OpenPrice"] = "float" +#鏀剁洏浠 +CSecurityFtdcL2MarketDataField["ClosePrice"] = "float" +#鍑鍊间及鍊 +CSecurityFtdcL2MarketDataField["IOPV"] = "float" +#鍒版湡鏀剁泭鐜 +CSecurityFtdcL2MarketDataField["YieldToMaturity"] = "float" +#鏈楂樹环 +CSecurityFtdcL2MarketDataField["HighPrice"] = "float" +#鏈浣庝环 +CSecurityFtdcL2MarketDataField["LowPrice"] = "float" +#鏈鏂颁环 +CSecurityFtdcL2MarketDataField["LastPrice"] = "float" +#鎴愪氦绗旀暟 +CSecurityFtdcL2MarketDataField["TradeCount"] = "int" +#鎴愪氦鎬婚噺 +CSecurityFtdcL2MarketDataField["TotalTradeVolume"] = "float" +#鎴愪氦鎬婚噾棰 +CSecurityFtdcL2MarketDataField["TotalTradeValue"] = "float" +#濮旀墭涔板叆鎬婚噺 +CSecurityFtdcL2MarketDataField["TotalBidVolume"] = "float" +#鍔犳潈骞冲潎濮斾拱浠 +CSecurityFtdcL2MarketDataField["WeightedAvgBidPrice"] = "float" +#鍊哄埜鍔犳潈骞冲潎濮斾拱浠 +CSecurityFtdcL2MarketDataField["AltWeightedAvgBidPrice"] = "float" +#濮旀墭鍗栧嚭鎬婚噺 +CSecurityFtdcL2MarketDataField["TotalOfferVolume"] = "float" +#鍔犳潈骞冲潎濮斿崠浠 +CSecurityFtdcL2MarketDataField["WeightedAvgOfferPrice"] = "float" +#鍊哄埜鍔犳潈骞冲潎濮斿崠浠锋牸 +CSecurityFtdcL2MarketDataField["AltWeightedAvgOfferPrice"] = "float" +#涔颁环娣卞害 +CSecurityFtdcL2MarketDataField["BidPriceLevel"] = "int" +#鍗栦环娣卞害 +CSecurityFtdcL2MarketDataField["OfferPriceLevel"] = "int" +#鐢充拱浠蜂竴 +CSecurityFtdcL2MarketDataField["BidPrice1"] = "float" +#鐢充拱閲忎竴 +CSecurityFtdcL2MarketDataField["BidVolume1"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁颁竴 +CSecurityFtdcL2MarketDataField["BidCount1"] = "int" +#鐢充拱浠蜂簩 +CSecurityFtdcL2MarketDataField["BidPrice2"] = "float" +#鐢充拱閲忎簩 +CSecurityFtdcL2MarketDataField["BidVolume2"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁颁簩 +CSecurityFtdcL2MarketDataField["BidCount2"] = "int" +#鐢充拱浠蜂笁 +CSecurityFtdcL2MarketDataField["BidPrice3"] = "float" +#鐢充拱閲忎笁 +CSecurityFtdcL2MarketDataField["BidVolume3"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁颁笁 +CSecurityFtdcL2MarketDataField["BidCount3"] = "int" +#鐢充拱浠峰洓 +CSecurityFtdcL2MarketDataField["BidPrice4"] = "float" +#鐢充拱閲忓洓 +CSecurityFtdcL2MarketDataField["BidVolume4"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁板洓 +CSecurityFtdcL2MarketDataField["BidCount4"] = "int" +#鐢充拱浠蜂簲 +CSecurityFtdcL2MarketDataField["BidPrice5"] = "float" +#鐢充拱閲忎簲 +CSecurityFtdcL2MarketDataField["BidVolume5"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁颁簲 +CSecurityFtdcL2MarketDataField["BidCount5"] = "int" +#鐢充拱浠峰叚 +CSecurityFtdcL2MarketDataField["BidPrice6"] = "float" +#鐢充拱閲忓叚 +CSecurityFtdcL2MarketDataField["BidVolume6"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁板叚 +CSecurityFtdcL2MarketDataField["BidCount6"] = "int" +#鐢充拱浠蜂竷 +CSecurityFtdcL2MarketDataField["BidPrice7"] = "float" +#鐢充拱閲忎竷 +CSecurityFtdcL2MarketDataField["BidVolume7"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁颁竷 +CSecurityFtdcL2MarketDataField["BidCount7"] = "int" +#鐢充拱浠峰叓 +CSecurityFtdcL2MarketDataField["BidPrice8"] = "float" +#鐢充拱閲忓叓 +CSecurityFtdcL2MarketDataField["BidVolume8"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁板叓 +CSecurityFtdcL2MarketDataField["BidCount8"] = "int" +#鐢充拱浠蜂節 +CSecurityFtdcL2MarketDataField["BidPrice9"] = "float" +#鐢充拱閲忎節 +CSecurityFtdcL2MarketDataField["BidVolume9"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁颁節 +CSecurityFtdcL2MarketDataField["BidCount9"] = "int" +#鐢充拱浠峰崄 +CSecurityFtdcL2MarketDataField["BidPriceA"] = "float" +#鐢充拱閲忓崄 +CSecurityFtdcL2MarketDataField["BidVolumeA"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁板崄 +CSecurityFtdcL2MarketDataField["BidCountA"] = "int" +#鐢冲崠浠蜂竴 +CSecurityFtdcL2MarketDataField["OfferPrice1"] = "float" +#鐢冲崠閲忎竴 +CSecurityFtdcL2MarketDataField["OfferVolume1"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁颁竴 +CSecurityFtdcL2MarketDataField["OfferCount1"] = "int" +#鐢冲崠浠蜂簩 +CSecurityFtdcL2MarketDataField["OfferPrice2"] = "float" +#鐢冲崠閲忎簩 +CSecurityFtdcL2MarketDataField["OfferVolume2"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁颁簩 +CSecurityFtdcL2MarketDataField["OfferCount2"] = "int" +#鐢冲崠浠蜂笁 +CSecurityFtdcL2MarketDataField["OfferPrice3"] = "float" +#鐢冲崠閲忎笁 +CSecurityFtdcL2MarketDataField["OfferVolume3"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁颁笁 +CSecurityFtdcL2MarketDataField["OfferCount3"] = "int" +#鐢冲崠浠峰洓 +CSecurityFtdcL2MarketDataField["OfferPrice4"] = "float" +#鐢冲崠閲忓洓 +CSecurityFtdcL2MarketDataField["OfferVolume4"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁板洓 +CSecurityFtdcL2MarketDataField["OfferCount4"] = "int" +#鐢冲崠浠蜂簲 +CSecurityFtdcL2MarketDataField["OfferPrice5"] = "float" +#鐢冲崠閲忎簲 +CSecurityFtdcL2MarketDataField["OfferVolume5"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁颁簲 +CSecurityFtdcL2MarketDataField["OfferCount5"] = "int" +#鐢冲崠浠峰叚 +CSecurityFtdcL2MarketDataField["OfferPrice6"] = "float" +#鐢冲崠閲忓叚 +CSecurityFtdcL2MarketDataField["OfferVolume6"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁板叚 +CSecurityFtdcL2MarketDataField["OfferCount6"] = "int" +#鐢冲崠浠蜂竷 +CSecurityFtdcL2MarketDataField["OfferPrice7"] = "float" +#鐢冲崠閲忎竷 +CSecurityFtdcL2MarketDataField["OfferVolume7"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁颁竷 +CSecurityFtdcL2MarketDataField["OfferCount7"] = "int" +#鐢冲崠浠峰叓 +CSecurityFtdcL2MarketDataField["OfferPrice8"] = "float" +#鐢冲崠閲忓叓 +CSecurityFtdcL2MarketDataField["OfferVolume8"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁板叓 +CSecurityFtdcL2MarketDataField["OfferCount8"] = "int" +#鐢冲崠浠蜂節 +CSecurityFtdcL2MarketDataField["OfferPrice9"] = "float" +#鐢冲崠閲忎節 +CSecurityFtdcL2MarketDataField["OfferVolume9"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁颁節 +CSecurityFtdcL2MarketDataField["OfferCount9"] = "int" +#鐢冲崠浠峰崄 +CSecurityFtdcL2MarketDataField["OfferPriceA"] = "float" +#鐢冲崠閲忓崄 +CSecurityFtdcL2MarketDataField["OfferVolumeA"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁板崄 +CSecurityFtdcL2MarketDataField["OfferCountA"] = "int" +structDict['CSecurityFtdcL2MarketDataField'] = CSecurityFtdcL2MarketDataField + + +#Level2琛屾儏鏇存柊鏃堕棿灞炴 +CSecurityFtdcL2UpdateTimeField = {} +#浜ゆ槗鏃 +CSecurityFtdcL2UpdateTimeField["TradingDay"] = "string" +#鏃堕棿鎴 +CSecurityFtdcL2UpdateTimeField["TimeStamp"] = "string" +#浜ゆ槗鎵浠g爜 +CSecurityFtdcL2UpdateTimeField["ExchangeID"] = "string" +#鍚堢害浠g爜 +CSecurityFtdcL2UpdateTimeField["InstrumentID"] = "string" +structDict['CSecurityFtdcL2UpdateTimeField'] = CSecurityFtdcL2UpdateTimeField + + +#Level2琛屾儏闈欐佸睘鎬 +CSecurityFtdcL2StaticField = {} +#鏄ㄦ敹鐩樹环 +CSecurityFtdcL2StaticField["PreClosePrice"] = "float" +#浠婂紑鐩樹环 +CSecurityFtdcL2StaticField["OpenPrice"] = "float" +#鏀剁洏浠 +CSecurityFtdcL2StaticField["ClosePrice"] = "float" +#鍑鍊间及鍊 +CSecurityFtdcL2StaticField["IOPV"] = "float" +#鍒版湡鏀剁泭鐜 +CSecurityFtdcL2StaticField["YieldToMaturity"] = "float" +structDict['CSecurityFtdcL2StaticField'] = CSecurityFtdcL2StaticField + + +#Level2琛屾儏浠锋牸鍖洪棿灞炴 +CSecurityFtdcL2PriceIntervalField = {} +#鏈楂樹环 +CSecurityFtdcL2PriceIntervalField["HighPrice"] = "float" +#鏈浣庝环 +CSecurityFtdcL2PriceIntervalField["LowPrice"] = "float" +structDict['CSecurityFtdcL2PriceIntervalField'] = CSecurityFtdcL2PriceIntervalField + + +#Level2琛屾儏鍩烘湰淇℃伅 +CSecurityFtdcL2BaseField = {} +#鏈鏂颁环 +CSecurityFtdcL2BaseField["LastPrice"] = "float" +structDict['CSecurityFtdcL2BaseField'] = CSecurityFtdcL2BaseField + + +#Level2鎴愪氦淇℃伅 +CSecurityFtdcL2TradedField = {} +#鎴愪氦绗旀暟 +CSecurityFtdcL2TradedField["TradeCount"] = "int" +#鎴愪氦鎬婚噺 +CSecurityFtdcL2TradedField["TotalTradeVolume"] = "float" +#鎴愪氦鎬婚噾棰 +CSecurityFtdcL2TradedField["TotalTradeValue"] = "float" +structDict['CSecurityFtdcL2TradedField'] = CSecurityFtdcL2TradedField + + +#Level2琛屾儏鏁版嵁灞炴 +CSecurityFtdcL2DataLevelField = {} +#浠锋牸 +CSecurityFtdcL2DataLevelField["Price"] = "float" +#鏁伴噺 +CSecurityFtdcL2DataLevelField["Volume"] = "int" +#瀹為檯鎬诲鎵樼瑪鏁 +CSecurityFtdcL2DataLevelField["Count"] = "int" +structDict['CSecurityFtdcL2DataLevelField'] = CSecurityFtdcL2DataLevelField + + +#Level2濮斾拱淇℃伅 +CSecurityFtdcL2BidOrderField = {} +#濮旀墭涔板叆鎬婚噺 +CSecurityFtdcL2BidOrderField["TotalBidVolume"] = "float" +#鍔犳潈骞冲潎濮斾拱浠 +CSecurityFtdcL2BidOrderField["WeightedAvgBidPrice"] = "float" +#鍊哄埜鍔犳潈骞冲潎濮斾拱浠 +CSecurityFtdcL2BidOrderField["AltWeightedAvgBidPrice"] = "float" +structDict['CSecurityFtdcL2BidOrderField'] = CSecurityFtdcL2BidOrderField + + +#Level2濮斿崠淇℃伅 +CSecurityFtdcL2OfferOrderField = {} +#濮旀墭鍗栧嚭鎬婚噺 +CSecurityFtdcL2OfferOrderField["TotalOfferVolume"] = "float" +#鍔犳潈骞冲潎濮斿崠浠 +CSecurityFtdcL2OfferOrderField["WeightedAvgOfferPrice"] = "float" +#鍊哄埜鍔犳潈骞冲潎濮斿崠浠锋牸 +CSecurityFtdcL2OfferOrderField["AltWeightedAvgOfferPrice"] = "float" +structDict['CSecurityFtdcL2OfferOrderField'] = CSecurityFtdcL2OfferOrderField + + +#Level2浠锋牸娣卞害灞炴 +CSecurityFtdcL2PriceLevelField = {} +#涔颁环娣卞害 +CSecurityFtdcL2PriceLevelField["BidPriceLevel"] = "int" +#鍗栦环娣卞害 +CSecurityFtdcL2PriceLevelField["OfferPriceLevel"] = "int" +structDict['CSecurityFtdcL2PriceLevelField'] = CSecurityFtdcL2PriceLevelField + + +#Level2琛屾儏鐢充拱涓灞炴 +CSecurityFtdcL2Bid1Field = {} +#鐢充拱浠蜂竴 +CSecurityFtdcL2Bid1Field["BidPrice1"] = "float" +#鐢充拱閲忎竴 +CSecurityFtdcL2Bid1Field["BidVolume1"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁颁竴 +CSecurityFtdcL2Bid1Field["BidCount1"] = "int" +structDict['CSecurityFtdcL2Bid1Field'] = CSecurityFtdcL2Bid1Field + + +#Level2琛屾儏鐢冲崠涓灞炴 +CSecurityFtdcL2Offer1Field = {} +#鐢冲崠浠蜂竴 +CSecurityFtdcL2Offer1Field["OfferPrice1"] = "float" +#鐢冲崠閲忎竴 +CSecurityFtdcL2Offer1Field["OfferVolume1"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁颁竴 +CSecurityFtdcL2Offer1Field["OfferCount1"] = "int" +structDict['CSecurityFtdcL2Offer1Field'] = CSecurityFtdcL2Offer1Field + + +#Level2琛屾儏鐢充拱浜屽睘鎬 +CSecurityFtdcL2Bid2Field = {} +#鐢充拱浠蜂簩 +CSecurityFtdcL2Bid2Field["BidPrice2"] = "float" +#鐢充拱閲忎簩 +CSecurityFtdcL2Bid2Field["BidVolume2"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁颁簩 +CSecurityFtdcL2Bid2Field["BidCount2"] = "int" +structDict['CSecurityFtdcL2Bid2Field'] = CSecurityFtdcL2Bid2Field + + +#Level2琛屾儏鐢冲崠浜屽睘鎬 +CSecurityFtdcL2Offer2Field = {} +#鐢冲崠浠蜂簩 +CSecurityFtdcL2Offer2Field["OfferPrice2"] = "float" +#鐢冲崠閲忎簩 +CSecurityFtdcL2Offer2Field["OfferVolume2"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁颁簩 +CSecurityFtdcL2Offer2Field["OfferCount2"] = "int" +structDict['CSecurityFtdcL2Offer2Field'] = CSecurityFtdcL2Offer2Field + + +#Level2琛屾儏鐢充拱涓夊睘鎬 +CSecurityFtdcL2Bid3Field = {} +#鐢充拱浠蜂笁 +CSecurityFtdcL2Bid3Field["BidPrice3"] = "float" +#鐢充拱閲忎笁 +CSecurityFtdcL2Bid3Field["BidVolume3"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁颁笁 +CSecurityFtdcL2Bid3Field["BidCount3"] = "int" +structDict['CSecurityFtdcL2Bid3Field'] = CSecurityFtdcL2Bid3Field + + +#Level2琛屾儏鐢冲崠涓夊睘鎬 +CSecurityFtdcL2Offer3Field = {} +#鐢冲崠浠蜂笁 +CSecurityFtdcL2Offer3Field["OfferPrice3"] = "float" +#鐢冲崠閲忎笁 +CSecurityFtdcL2Offer3Field["OfferVolume3"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁颁笁 +CSecurityFtdcL2Offer3Field["OfferCount3"] = "int" +structDict['CSecurityFtdcL2Offer3Field'] = CSecurityFtdcL2Offer3Field + + +#Level2琛屾儏鐢充拱鍥涘睘鎬 +CSecurityFtdcL2Bid4Field = {} +#鐢充拱浠峰洓 +CSecurityFtdcL2Bid4Field["BidPrice4"] = "float" +#鐢充拱閲忓洓 +CSecurityFtdcL2Bid4Field["BidVolume4"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁板洓 +CSecurityFtdcL2Bid4Field["BidCount4"] = "int" +structDict['CSecurityFtdcL2Bid4Field'] = CSecurityFtdcL2Bid4Field + + +#Level2琛屾儏鐢冲崠鍥涘睘鎬 +CSecurityFtdcL2Offer4Field = {} +#鐢冲崠浠峰洓 +CSecurityFtdcL2Offer4Field["OfferPrice4"] = "float" +#鐢冲崠閲忓洓 +CSecurityFtdcL2Offer4Field["OfferVolume4"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁板洓 +CSecurityFtdcL2Offer4Field["OfferCount4"] = "int" +structDict['CSecurityFtdcL2Offer4Field'] = CSecurityFtdcL2Offer4Field + + +#Level2琛屾儏鐢充拱浜斿睘鎬 +CSecurityFtdcL2Bid5Field = {} +#鐢充拱浠蜂簲 +CSecurityFtdcL2Bid5Field["BidPrice5"] = "float" +#鐢充拱閲忎簲 +CSecurityFtdcL2Bid5Field["BidVolume5"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁颁簲 +CSecurityFtdcL2Bid5Field["BidCount5"] = "int" +structDict['CSecurityFtdcL2Bid5Field'] = CSecurityFtdcL2Bid5Field + + +#Level2琛屾儏鐢冲崠浜斿睘鎬 +CSecurityFtdcL2Offer5Field = {} +#鐢冲崠浠蜂簲 +CSecurityFtdcL2Offer5Field["OfferPrice5"] = "float" +#鐢冲崠閲忎簲 +CSecurityFtdcL2Offer5Field["OfferVolume5"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁颁簲 +CSecurityFtdcL2Offer5Field["OfferCount5"] = "int" +structDict['CSecurityFtdcL2Offer5Field'] = CSecurityFtdcL2Offer5Field + + +#Level2琛屾儏鐢充拱鍏睘鎬 +CSecurityFtdcL2Bid6Field = {} +#鐢充拱浠峰叚 +CSecurityFtdcL2Bid6Field["BidPrice6"] = "float" +#鐢充拱閲忓叚 +CSecurityFtdcL2Bid6Field["BidVolume6"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁板叚 +CSecurityFtdcL2Bid6Field["BidCount6"] = "int" +structDict['CSecurityFtdcL2Bid6Field'] = CSecurityFtdcL2Bid6Field + + +#Level2琛屾儏鐢冲崠鍏睘鎬 +CSecurityFtdcL2Offer6Field = {} +#鐢冲崠浠峰叚 +CSecurityFtdcL2Offer6Field["OfferPrice6"] = "float" +#鐢冲崠閲忓叚 +CSecurityFtdcL2Offer6Field["OfferVolume6"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁板叚 +CSecurityFtdcL2Offer6Field["OfferCount6"] = "int" +structDict['CSecurityFtdcL2Offer6Field'] = CSecurityFtdcL2Offer6Field + + +#Level2琛屾儏鐢充拱涓冨睘鎬 +CSecurityFtdcL2Bid7Field = {} +#鐢充拱浠蜂竷 +CSecurityFtdcL2Bid7Field["BidPrice7"] = "float" +#鐢充拱閲忎竷 +CSecurityFtdcL2Bid7Field["BidVolume7"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁颁竷 +CSecurityFtdcL2Bid7Field["BidCount7"] = "int" +structDict['CSecurityFtdcL2Bid7Field'] = CSecurityFtdcL2Bid7Field + + +#Level2琛屾儏鐢冲崠涓冨睘鎬 +CSecurityFtdcL2Offer7Field = {} +#鐢冲崠浠蜂竷 +CSecurityFtdcL2Offer7Field["OfferPrice7"] = "float" +#鐢冲崠閲忎竷 +CSecurityFtdcL2Offer7Field["OfferVolume7"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁颁竷 +CSecurityFtdcL2Offer7Field["OfferCount7"] = "int" +structDict['CSecurityFtdcL2Offer7Field'] = CSecurityFtdcL2Offer7Field + + +#Level2琛屾儏鐢充拱鍏睘鎬 +CSecurityFtdcL2Bid8Field = {} +#鐢充拱浠峰叓 +CSecurityFtdcL2Bid8Field["BidPrice8"] = "float" +#鐢充拱閲忓叓 +CSecurityFtdcL2Bid8Field["BidVolume8"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁板叓 +CSecurityFtdcL2Bid8Field["BidCount8"] = "int" +structDict['CSecurityFtdcL2Bid8Field'] = CSecurityFtdcL2Bid8Field + + +#Level2琛屾儏鐢冲崠鍏睘鎬 +CSecurityFtdcL2Offer8Field = {} +#鐢冲崠浠峰叓 +CSecurityFtdcL2Offer8Field["OfferPrice8"] = "float" +#鐢冲崠閲忓叓 +CSecurityFtdcL2Offer8Field["OfferVolume8"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁板叓 +CSecurityFtdcL2Offer8Field["OfferCount8"] = "int" +structDict['CSecurityFtdcL2Offer8Field'] = CSecurityFtdcL2Offer8Field + + +#Level2琛屾儏鐢充拱涔濆睘鎬 +CSecurityFtdcL2Bid9Field = {} +#鐢充拱浠蜂節 +CSecurityFtdcL2Bid9Field["BidPrice9"] = "float" +#鐢充拱閲忎節 +CSecurityFtdcL2Bid9Field["BidVolume9"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁颁節 +CSecurityFtdcL2Bid9Field["BidCount9"] = "int" +structDict['CSecurityFtdcL2Bid9Field'] = CSecurityFtdcL2Bid9Field + + +#Level2琛屾儏鐢冲崠涔濆睘鎬 +CSecurityFtdcL2Offer9Field = {} +#鐢冲崠浠蜂節 +CSecurityFtdcL2Offer9Field["OfferPrice9"] = "float" +#鐢冲崠閲忎節 +CSecurityFtdcL2Offer9Field["OfferVolume9"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁颁節 +CSecurityFtdcL2Offer9Field["OfferCount9"] = "int" +structDict['CSecurityFtdcL2Offer9Field'] = CSecurityFtdcL2Offer9Field + + +#Level2琛屾儏鐢充拱鍗佸睘鎬 +CSecurityFtdcL2BidAField = {} +#鐢充拱浠峰崄 +CSecurityFtdcL2BidAField["BidPriceA"] = "float" +#鐢充拱閲忓崄 +CSecurityFtdcL2BidAField["BidVolumeA"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁板崄 +CSecurityFtdcL2BidAField["BidCountA"] = "int" +structDict['CSecurityFtdcL2BidAField'] = CSecurityFtdcL2BidAField + + +#Level2琛屾儏鐢冲崠鍗佸睘鎬 +CSecurityFtdcL2OfferAField = {} +#鐢冲崠浠峰崄 +CSecurityFtdcL2OfferAField["OfferPriceA"] = "float" +#鐢冲崠閲忓崄 +CSecurityFtdcL2OfferAField["OfferVolumeA"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁板崄 +CSecurityFtdcL2OfferAField["OfferCountA"] = "int" +structDict['CSecurityFtdcL2OfferAField'] = CSecurityFtdcL2OfferAField + + +#Level2琛屾儏鐢充拱灞炴 +CSecurityFtdcL2BidField = {} +#鐢充拱浠蜂竴 +CSecurityFtdcL2BidField["BidPrice1"] = "float" +#鐢充拱閲忎竴 +CSecurityFtdcL2BidField["BidVolume1"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁颁竴 +CSecurityFtdcL2BidField["BidCount1"] = "int" +#鐢充拱浠蜂簩 +CSecurityFtdcL2BidField["BidPrice2"] = "float" +#鐢充拱閲忎簩 +CSecurityFtdcL2BidField["BidVolume2"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁颁簩 +CSecurityFtdcL2BidField["BidCount2"] = "int" +#鐢充拱浠蜂笁 +CSecurityFtdcL2BidField["BidPrice3"] = "float" +#鐢充拱閲忎笁 +CSecurityFtdcL2BidField["BidVolume3"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁颁笁 +CSecurityFtdcL2BidField["BidCount3"] = "int" +#鐢充拱浠峰洓 +CSecurityFtdcL2BidField["BidPrice4"] = "float" +#鐢充拱閲忓洓 +CSecurityFtdcL2BidField["BidVolume4"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁板洓 +CSecurityFtdcL2BidField["BidCount4"] = "int" +#鐢充拱浠蜂簲 +CSecurityFtdcL2BidField["BidPrice5"] = "float" +#鐢充拱閲忎簲 +CSecurityFtdcL2BidField["BidVolume5"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁颁簲 +CSecurityFtdcL2BidField["BidCount5"] = "int" +#鐢充拱浠峰叚 +CSecurityFtdcL2BidField["BidPrice6"] = "float" +#鐢充拱閲忓叚 +CSecurityFtdcL2BidField["BidVolume6"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁板叚 +CSecurityFtdcL2BidField["BidCount6"] = "int" +#鐢充拱浠蜂竷 +CSecurityFtdcL2BidField["BidPrice7"] = "float" +#鐢充拱閲忎竷 +CSecurityFtdcL2BidField["BidVolume7"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁颁竷 +CSecurityFtdcL2BidField["BidCount7"] = "int" +#鐢充拱浠峰叓 +CSecurityFtdcL2BidField["BidPrice8"] = "float" +#鐢充拱閲忓叓 +CSecurityFtdcL2BidField["BidVolume8"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁板叓 +CSecurityFtdcL2BidField["BidCount8"] = "int" +#鐢充拱浠蜂節 +CSecurityFtdcL2BidField["BidPrice9"] = "float" +#鐢充拱閲忎節 +CSecurityFtdcL2BidField["BidVolume9"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁颁節 +CSecurityFtdcL2BidField["BidCount9"] = "int" +#鐢充拱浠峰崄 +CSecurityFtdcL2BidField["BidPriceA"] = "float" +#鐢充拱閲忓崄 +CSecurityFtdcL2BidField["BidVolumeA"] = "int" +#瀹為檯涔版诲鎵樼瑪鏁板崄 +CSecurityFtdcL2BidField["BidCountA"] = "int" +structDict['CSecurityFtdcL2BidField'] = CSecurityFtdcL2BidField + + +#Level2琛屾儏鐢冲崠灞炴 +CSecurityFtdcL2OfferField = {} +#鐢冲崠浠蜂竴 +CSecurityFtdcL2OfferField["OfferPrice1"] = "float" +#鐢冲崠閲忎竴 +CSecurityFtdcL2OfferField["OfferVolume1"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁颁竴 +CSecurityFtdcL2OfferField["OfferCount1"] = "int" +#鐢冲崠浠蜂簩 +CSecurityFtdcL2OfferField["OfferPrice2"] = "float" +#鐢冲崠閲忎簩 +CSecurityFtdcL2OfferField["OfferVolume2"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁颁簩 +CSecurityFtdcL2OfferField["OfferCount2"] = "int" +#鐢冲崠浠蜂笁 +CSecurityFtdcL2OfferField["OfferPrice3"] = "float" +#鐢冲崠閲忎笁 +CSecurityFtdcL2OfferField["OfferVolume3"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁颁笁 +CSecurityFtdcL2OfferField["OfferCount3"] = "int" +#鐢冲崠浠峰洓 +CSecurityFtdcL2OfferField["OfferPrice4"] = "float" +#鐢冲崠閲忓洓 +CSecurityFtdcL2OfferField["OfferVolume4"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁板洓 +CSecurityFtdcL2OfferField["OfferCount4"] = "int" +#鐢冲崠浠蜂簲 +CSecurityFtdcL2OfferField["OfferPrice5"] = "float" +#鐢冲崠閲忎簲 +CSecurityFtdcL2OfferField["OfferVolume5"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁颁簲 +CSecurityFtdcL2OfferField["OfferCount5"] = "int" +#鐢冲崠浠峰叚 +CSecurityFtdcL2OfferField["OfferPrice6"] = "float" +#鐢冲崠閲忓叚 +CSecurityFtdcL2OfferField["OfferVolume6"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁板叚 +CSecurityFtdcL2OfferField["OfferCount6"] = "int" +#鐢冲崠浠蜂竷 +CSecurityFtdcL2OfferField["OfferPrice7"] = "float" +#鐢冲崠閲忎竷 +CSecurityFtdcL2OfferField["OfferVolume7"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁颁竷 +CSecurityFtdcL2OfferField["OfferCount7"] = "int" +#鐢冲崠浠峰叓 +CSecurityFtdcL2OfferField["OfferPrice8"] = "float" +#鐢冲崠閲忓叓 +CSecurityFtdcL2OfferField["OfferVolume8"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁板叓 +CSecurityFtdcL2OfferField["OfferCount8"] = "int" +#鐢冲崠浠蜂節 +CSecurityFtdcL2OfferField["OfferPrice9"] = "float" +#鐢冲崠閲忎節 +CSecurityFtdcL2OfferField["OfferVolume9"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁颁節 +CSecurityFtdcL2OfferField["OfferCount9"] = "int" +#鐢冲崠浠峰崄 +CSecurityFtdcL2OfferField["OfferPriceA"] = "float" +#鐢冲崠閲忓崄 +CSecurityFtdcL2OfferField["OfferVolumeA"] = "int" +#瀹為檯鍗栨诲鎵樼瑪鏁板崄 +CSecurityFtdcL2OfferField["OfferCountA"] = "int" +structDict['CSecurityFtdcL2OfferField'] = CSecurityFtdcL2OfferField + + +#Level2鎸囨暟琛屾儏 +CSecurityFtdcL2IndexField = {} +#浜ゆ槗鏃 +CSecurityFtdcL2IndexField["TradingDay"] = "string" +#琛屾儏鏃堕棿锛堢锛 +CSecurityFtdcL2IndexField["TimeStamp"] = "string" +#浜ゆ槗鎵浠g爜 +CSecurityFtdcL2IndexField["ExchangeID"] = "string" +#鎸囨暟浠g爜 +CSecurityFtdcL2IndexField["InstrumentID"] = "string" +#鍓嶆敹鐩樻寚鏁 +CSecurityFtdcL2IndexField["PreCloseIndex"] = "float" +#浠婂紑鐩樻寚鏁 +CSecurityFtdcL2IndexField["OpenIndex"] = "float" +#浠婃棩鏀剁洏鎸囨暟 +CSecurityFtdcL2IndexField["CloseIndex"] = "float" +#鏈楂樻寚鏁 +CSecurityFtdcL2IndexField["HighIndex"] = "float" +#鏈浣庢寚鏁 +CSecurityFtdcL2IndexField["LowIndex"] = "float" +#鏈鏂版寚鏁 +CSecurityFtdcL2IndexField["LastIndex"] = "float" +#鍙備笌璁$畻鐩稿簲鎸囨暟鐨勬垚浜ら噾棰濓紙鍏冿級 +CSecurityFtdcL2IndexField["TurnOver"] = "float" +#鍙備笌璁$畻鐩稿簲鎸囨暟鐨勪氦鏄撴暟閲忥紙鎵嬶級 +CSecurityFtdcL2IndexField["TotalVolume"] = "float" +structDict['CSecurityFtdcL2IndexField'] = CSecurityFtdcL2IndexField + + +#Level2琛屾儏鐢ㄦ埛淇℃伅 +CSecurityFtdcL2UserInfoField = {} +#缁忕邯鍏徃浠g爜 +CSecurityFtdcL2UserInfoField["BrokerID"] = "string" +#鐢ㄦ埛浠g爜 +CSecurityFtdcL2UserInfoField["UserID"] = "string" +#鐢ㄦ埛鍚嶇О +CSecurityFtdcL2UserInfoField["UserName"] = "string" +#瀵嗙爜 +CSecurityFtdcL2UserInfoField["Password"] = "string" +#琛屾儏鏁版嵁绛夌骇 +CSecurityFtdcL2UserInfoField["DataLevel"] = "string" +structDict['CSecurityFtdcL2UserInfoField'] = CSecurityFtdcL2UserInfoField + + +#UDP缁勬挱缁勪俊鎭 +CSecurityFtdcMulticastGroupInfoField = {} +#缁勬挱缁処P鍦板潃 +CSecurityFtdcMulticastGroupInfoField["GroupIP"] = "string" +#缁勬挱缁処P绔彛 +CSecurityFtdcMulticastGroupInfoField["GroupPort"] = "int" +#婧愬湴鍧 +CSecurityFtdcMulticastGroupInfoField["SourceIP"] = "string" +structDict['CSecurityFtdcMulticastGroupInfoField'] = CSecurityFtdcMulticastGroupInfoField + + +#Level2閫愮瑪濮旀墭 +CSecurityFtdcL2OrderField = {} +#濮旀墭缁 +CSecurityFtdcL2OrderField["OrderGroupID"] = "int" +#濮旀墭搴忓彿 +CSecurityFtdcL2OrderField["OrderIndex"] = "int" +#濮旀墭鏃堕棿锛堢锛 +CSecurityFtdcL2OrderField["OrderTime"] = "string" +#浜ゆ槗鎵浠g爜 +CSecurityFtdcL2OrderField["ExchangeID"] = "string" +#鍚堢害浠g爜 +CSecurityFtdcL2OrderField["InstrumentID"] = "string" +#濮旀墭浠锋牸 +CSecurityFtdcL2OrderField["Price"] = "float" +#濮旀墭鏁伴噺 +CSecurityFtdcL2OrderField["Volume"] = "int" +#鎶ュ崟绫诲瀷 +CSecurityFtdcL2OrderField["OrderKind"] = "string" +#鍔熻兘鐮 +CSecurityFtdcL2OrderField["FunctionCode"] = "string" +structDict['CSecurityFtdcL2OrderField'] = CSecurityFtdcL2OrderField + + +#Level2閫愮瑪鎴愪氦 +CSecurityFtdcL2TradeField = {} +#鎴愪氦缁 +CSecurityFtdcL2TradeField["TradeGroupID"] = "int" +#鎴愪氦搴忓彿 +CSecurityFtdcL2TradeField["TradeIndex"] = "int" +#涔版柟濮旀墭搴忓彿 +CSecurityFtdcL2TradeField["BuyIndex"] = "int" +#鍗栨柟濮旀墭搴忓彿 +CSecurityFtdcL2TradeField["SellIndex"] = "int" +#鎴愪氦鏃堕棿锛堢锛 +CSecurityFtdcL2TradeField["TradeTime"] = "string" +#浜ゆ槗鎵浠g爜 +CSecurityFtdcL2TradeField["ExchangeID"] = "string" +#鍚堢害浠g爜 +CSecurityFtdcL2TradeField["InstrumentID"] = "string" +#鎴愪氦浠锋牸 +CSecurityFtdcL2TradeField["Price"] = "float" +#鎴愪氦鏁伴噺 +CSecurityFtdcL2TradeField["Volume"] = "int" +#鎶ュ崟绫诲瀷 +CSecurityFtdcL2TradeField["OrderKind"] = "string" +#鍔熻兘鐮 +CSecurityFtdcL2TradeField["FunctionCode"] = "string" +structDict['CSecurityFtdcL2TradeField'] = CSecurityFtdcL2TradeField + + + + + + diff --git a/vn.lts/pyscript/l2/lts_l2_define.cpp b/vn.lts/pyscript/l2/lts_l2_define.cpp new file mode 100644 index 00000000..3bd0f5af --- /dev/null +++ b/vn.lts/pyscript/l2/lts_l2_define.cpp @@ -0,0 +1,17 @@ +#define ONFRONTCONNECTED 1 +#define ONFRONTDISCONNECTED 2 +#define ONHEARTBEATWARNING 3 +#define ONRSPERROR 4 +#define ONRSPUSERLOGIN 5 +#define ONRSPUSERLOGOUT 6 +#define ONRSPSUBL2MARKETDATA 7 +#define ONRSPUNSUBL2MARKETDATA 8 +#define ONRSPSUBL2INDEX 9 +#define ONRSPUNSUBL2INDEX 10 +#define ONRTNL2MARKETDATA 11 +#define ONRTNL2INDEX 12 +#define ONRSPSUBL2ORDERANDTRADE 13 +#define ONRSPUNSUBL2ORDERANDTRADE 14 +#define ONRTNL2ORDER 15 +#define ONRTNL2TRADE 16 +#define ONNTFCHECKORDERLIST 17 diff --git a/vn.lts/pyscript/l2/lts_l2_function.cpp b/vn.lts/pyscript/l2/lts_l2_function.cpp new file mode 100644 index 00000000..e12bcb1d --- /dev/null +++ b/vn.lts/pyscript/l2/lts_l2_function.cpp @@ -0,0 +1,23 @@ +int TdApi::reqUserLogin(dict req, int nRequestID) +{ + CSecurityFtdcUserLoginField myreq = CSecurityFtdcUserLoginField(); + memset(&myreq, 0, sizeof(myreq)); + getChar(req, "TradingDay", myreq.TradingDay); + getChar(req, "Password", myreq.Password); + getChar(req, "BrokerID", myreq.BrokerID); + getChar(req, "DataLevel", myreq.DataLevel); + getChar(req, "UserID", myreq.UserID); + int i = this->api->ReqUserLogin(&myreq, nRequestID); + return i; +}; + +int TdApi::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; +}; + diff --git a/vn.lts/pyscript/l2/lts_l2_header_function.h b/vn.lts/pyscript/l2/lts_l2_header_function.h new file mode 100644 index 00000000..26a1f4fe --- /dev/null +++ b/vn.lts/pyscript/l2/lts_l2_header_function.h @@ -0,0 +1,4 @@ +int reqUserLogin(dict req, int nRequestID); + +int reqUserLogout(dict req, int nRequestID); + diff --git a/vn.lts/pyscript/l2/lts_l2_header_on.h b/vn.lts/pyscript/l2/lts_l2_header_on.h new file mode 100644 index 00000000..96d2796d --- /dev/null +++ b/vn.lts/pyscript/l2/lts_l2_header_on.h @@ -0,0 +1,30 @@ + + + +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 onRspSubL2MarketData(dict data, dict error, int id, bool last) {}; + +virtual void onRspUnSubL2MarketData(dict data, dict error, int id, bool last) {}; + +virtual void onRspSubL2Index(dict data, dict error, int id, bool last) {}; + +virtual void onRspUnSubL2Index(dict data, dict error, int id, bool last) {}; + +virtual void onRtnL2MarketData(dict data) {}; + +virtual void onRtnL2Index(dict data) {}; + +virtual void onRspSubL2OrderAndTrade(dict data, dict error, int id, bool last) {}; + +virtual void onRspUnSubL2OrderAndTrade(dict data, dict error, int id, bool last) {}; + +virtual void onRtnL2Order(dict data) {}; + +virtual void onRtnL2Trade(dict data) {}; + + diff --git a/vn.lts/pyscript/l2/lts_l2_header_process.h b/vn.lts/pyscript/l2/lts_l2_header_process.h new file mode 100644 index 00000000..f11c1959 --- /dev/null +++ b/vn.lts/pyscript/l2/lts_l2_header_process.h @@ -0,0 +1,34 @@ +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 processRspSubL2MarketData(Task task); + +void processRspUnSubL2MarketData(Task task); + +void processRspSubL2Index(Task task); + +void processRspUnSubL2Index(Task task); + +void processRtnL2MarketData(Task task); + +void processRtnL2Index(Task task); + +void processRspSubL2OrderAndTrade(Task task); + +void processRspUnSubL2OrderAndTrade(Task task); + +void processRtnL2Order(Task task); + +void processRtnL2Trade(Task task); + +void processNtfCheckOrderList(Task task); + diff --git a/vn.lts/pyscript/l2/lts_l2_process.cpp b/vn.lts/pyscript/l2/lts_l2_process.cpp new file mode 100644 index 00000000..0a174280 --- /dev/null +++ b/vn.lts/pyscript/l2/lts_l2_process.cpp @@ -0,0 +1,290 @@ +void TdApi::processFrontConnected(Task task) +{ + this->onFrontConnected(); +}; + +void TdApi::processFrontDisconnected(Task task) +{ + this->onFrontDisconnected(task.task_id); +}; + +void TdApi::processHeartBeatWarning(Task task) +{ + this->onHeartBeatWarning(task.task_id); +}; + +void TdApi::processRspError(Task task) +{ + CSecurityFtdcRspInfoField task_error = any_cast(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 TdApi::processRspUserLogin(Task task) +{ + CSecurityFtdcUserLoginField task_data = any_cast(task.task_data); + dict data; + data["TradingDay"] = task_data.TradingDay; + data["Password"] = task_data.Password; + data["BrokerID"] = task_data.BrokerID; + data["DataLevel"] = task_data.DataLevel; + data["UserID"] = task_data.UserID; + + CSecurityFtdcRspInfoField task_error = any_cast(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 TdApi::processRspUserLogout(Task task) +{ + CSecurityFtdcUserLogoutField task_data = any_cast(task.task_data); + dict data; + data["UserID"] = task_data.UserID; + data["BrokerID"] = task_data.BrokerID; + + CSecurityFtdcRspInfoField task_error = any_cast(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 TdApi::processRspSubL2MarketData(Task task) +{ + CSecurityFtdcSpecificInstrumentField task_data = any_cast(task.task_data); + dict data; + data["InstrumentID"] = task_data.InstrumentID; + data["ExchangeID"] = task_data.ExchangeID; + + CSecurityFtdcRspInfoField task_error = any_cast(task.task_error); + dict error; + error["ErrorMsg"] = task_error.ErrorMsg; + error["ErrorID"] = task_error.ErrorID; + + this->onRspSubL2MarketData(data, error, task.task_id, task.task_last); +}; + +void TdApi::processRspUnSubL2MarketData(Task task) +{ + CSecurityFtdcSpecificInstrumentField task_data = any_cast(task.task_data); + dict data; + data["InstrumentID"] = task_data.InstrumentID; + data["ExchangeID"] = task_data.ExchangeID; + + CSecurityFtdcRspInfoField task_error = any_cast(task.task_error); + dict error; + error["ErrorMsg"] = task_error.ErrorMsg; + error["ErrorID"] = task_error.ErrorID; + + this->onRspUnSubL2MarketData(data, error, task.task_id, task.task_last); +}; + +void TdApi::processRspSubL2Index(Task task) +{ + CSecurityFtdcSpecificInstrumentField task_data = any_cast(task.task_data); + dict data; + data["InstrumentID"] = task_data.InstrumentID; + data["ExchangeID"] = task_data.ExchangeID; + + CSecurityFtdcRspInfoField task_error = any_cast(task.task_error); + dict error; + error["ErrorMsg"] = task_error.ErrorMsg; + error["ErrorID"] = task_error.ErrorID; + + this->onRspSubL2Index(data, error, task.task_id, task.task_last); +}; + +void TdApi::processRspUnSubL2Index(Task task) +{ + CSecurityFtdcSpecificInstrumentField task_data = any_cast(task.task_data); + dict data; + data["InstrumentID"] = task_data.InstrumentID; + data["ExchangeID"] = task_data.ExchangeID; + + CSecurityFtdcRspInfoField task_error = any_cast(task.task_error); + dict error; + error["ErrorMsg"] = task_error.ErrorMsg; + error["ErrorID"] = task_error.ErrorID; + + this->onRspUnSubL2Index(data, error, task.task_id, task.task_last); +}; + +void TdApi::processRtnL2MarketData(Task task) +{ + CSecurityFtdcL2MarketDataField task_data = any_cast(task.task_data); + dict data; + data["BidCount8"] = task_data.BidCount8; + data["BidVolume4"] = task_data.BidVolume4; + data["BidPrice9"] = task_data.BidPrice9; + data["BidPrice8"] = task_data.BidPrice8; + data["OfferVolume8"] = task_data.OfferVolume8; + data["OfferCount9"] = task_data.OfferCount9; + data["BidPrice5"] = task_data.BidPrice5; + data["LowPrice"] = task_data.LowPrice; + data["BidPrice7"] = task_data.BidPrice7; + data["AltWeightedAvgOfferPrice"] = task_data.AltWeightedAvgOfferPrice; + data["BidPrice1"] = task_data.BidPrice1; + data["OfferCount3"] = task_data.OfferCount3; + data["TotalTradeVolume"] = task_data.TotalTradeVolume; + data["BidPrice2"] = task_data.BidPrice2; + data["BidVolume1"] = task_data.BidVolume1; + data["OfferVolume3"] = task_data.OfferVolume3; + data["PreClosePrice"] = task_data.PreClosePrice; + data["OfferVolumeA"] = task_data.OfferVolumeA; + data["BidCount3"] = task_data.BidCount3; + data["BidCount2"] = task_data.BidCount2; + data["BidCount1"] = task_data.BidCount1; + data["BidPriceLevel"] = task_data.BidPriceLevel; + data["BidCount7"] = task_data.BidCount7; + data["BidCount6"] = task_data.BidCount6; + data["BidCount5"] = task_data.BidCount5; + data["BidCount4"] = task_data.BidCount4; + data["BidVolume7"] = task_data.BidVolume7; + data["BidVolume6"] = task_data.BidVolume6; + data["TotalOfferVolume"] = task_data.TotalOfferVolume; + data["TotalBidVolume"] = task_data.TotalBidVolume; + data["BidVolume3"] = task_data.BidVolume3; + data["BidVolume2"] = task_data.BidVolume2; + data["OpenPrice"] = task_data.OpenPrice; + data["OfferPriceA"] = task_data.OfferPriceA; + data["OfferCount7"] = task_data.OfferCount7; + data["OfferCount6"] = task_data.OfferCount6; + data["TradeCount"] = task_data.TradeCount; + data["BidPrice4"] = task_data.BidPrice4; + data["WeightedAvgOfferPrice"] = task_data.WeightedAvgOfferPrice; + data["OfferVolume6"] = task_data.OfferVolume6; + data["HighPrice"] = task_data.HighPrice; + data["OfferVolume9"] = task_data.OfferVolume9; + data["InstrumentID"] = task_data.InstrumentID; + data["ClosePrice"] = task_data.ClosePrice; + data["ExchangeID"] = task_data.ExchangeID; + data["BidPrice6"] = task_data.BidPrice6; + data["OfferPrice7"] = task_data.OfferPrice7; + data["AltWeightedAvgBidPrice"] = task_data.AltWeightedAvgBidPrice; + data["TimeStamp"] = task_data.TimeStamp; + data["WeightedAvgBidPrice"] = task_data.WeightedAvgBidPrice; + data["BidVolume9"] = task_data.BidVolume9; + data["TotalTradeValue"] = task_data.TotalTradeValue; + data["OfferCount4"] = task_data.OfferCount4; + data["TradingDay"] = task_data.TradingDay; + data["BidCountA"] = task_data.BidCountA; + data["BidPrice3"] = task_data.BidPrice3; + data["IOPV"] = task_data.IOPV; + data["OfferCount1"] = task_data.OfferCount1; + data["BidVolumeA"] = task_data.BidVolumeA; + data["OfferPrice9"] = task_data.OfferPrice9; + data["BidCount9"] = task_data.BidCount9; + data["OfferPrice8"] = task_data.OfferPrice8; + data["YieldToMaturity"] = task_data.YieldToMaturity; + data["LastPrice"] = task_data.LastPrice; + data["OfferCount8"] = task_data.OfferCount8; + data["OfferPrice4"] = task_data.OfferPrice4; + data["OfferPrice5"] = task_data.OfferPrice5; + data["OfferPrice6"] = task_data.OfferPrice6; + data["BidVolume8"] = task_data.BidVolume8; + data["OfferCount5"] = task_data.OfferCount5; + data["OfferPrice1"] = task_data.OfferPrice1; + data["OfferPrice2"] = task_data.OfferPrice2; + data["OfferPrice3"] = task_data.OfferPrice3; + data["OfferVolume4"] = task_data.OfferVolume4; + data["OfferVolume5"] = task_data.OfferVolume5; + data["OfferPriceLevel"] = task_data.OfferPriceLevel; + data["OfferVolume7"] = task_data.OfferVolume7; + data["OfferVolume1"] = task_data.OfferVolume1; + data["OfferVolume2"] = task_data.OfferVolume2; + data["OfferCount2"] = task_data.OfferCount2; + data["BidPriceA"] = task_data.BidPriceA; + data["BidVolume5"] = task_data.BidVolume5; + data["OfferCountA"] = task_data.OfferCountA; + + this->onRtnL2MarketData(data); +}; + +void TdApi::processRtnL2Index(Task task) +{ + CSecurityFtdcL2IndexField task_data = any_cast(task.task_data); + dict data; + data["InstrumentID"] = task_data.InstrumentID; + data["ExchangeID"] = task_data.ExchangeID; + data["HighIndex"] = task_data.HighIndex; + data["TimeStamp"] = task_data.TimeStamp; + data["CloseIndex"] = task_data.CloseIndex; + data["PreCloseIndex"] = task_data.PreCloseIndex; + data["LastIndex"] = task_data.LastIndex; + data["TradingDay"] = task_data.TradingDay; + data["OpenIndex"] = task_data.OpenIndex; + data["TotalVolume"] = task_data.TotalVolume; + data["LowIndex"] = task_data.LowIndex; + data["TurnOver"] = task_data.TurnOver; + + this->onRtnL2Index(data); +}; + +void TdApi::processRspSubL2OrderAndTrade(Task task) +{ + CSecurityFtdcRspInfoField task_error = any_cast(task.task_error); + dict error; + error["ErrorMsg"] = task_error.ErrorMsg; + error["ErrorID"] = task_error.ErrorID; + + this->onRspSubL2OrderAndTrade(error, task.task_id, task.task_last); +}; + +void TdApi::processRspUnSubL2OrderAndTrade(Task task) +{ + CSecurityFtdcRspInfoField task_error = any_cast(task.task_error); + dict error; + error["ErrorMsg"] = task_error.ErrorMsg; + error["ErrorID"] = task_error.ErrorID; + + this->onRspUnSubL2OrderAndTrade(error, task.task_id, task.task_last); +}; + +void TdApi::processRtnL2Order(Task task) +{ + CSecurityFtdcL2OrderField task_data = any_cast(task.task_data); + dict data; + data["InstrumentID"] = task_data.InstrumentID; + data["OrderTime"] = task_data.OrderTime; + data["OrderKind"] = task_data.OrderKind; + data["Price"] = task_data.Price; + data["ExchangeID"] = task_data.ExchangeID; + data["OrderGroupID"] = task_data.OrderGroupID; + data["Volume"] = task_data.Volume; + data["FunctionCode"] = task_data.FunctionCode; + data["OrderIndex"] = task_data.OrderIndex; + + this->onRtnL2Order(data); +}; + +void TdApi::processRtnL2Trade(Task task) +{ + CSecurityFtdcL2TradeField task_data = any_cast(task.task_data); + dict data; + data["TradeGroupID"] = task_data.TradeGroupID; + data["SellIndex"] = task_data.SellIndex; + data["ExchangeID"] = task_data.ExchangeID; + data["OrderKind"] = task_data.OrderKind; + data["TradeIndex"] = task_data.TradeIndex; + data["Price"] = task_data.Price; + data["InstrumentID"] = task_data.InstrumentID; + data["BuyIndex"] = task_data.BuyIndex; + data["Volume"] = task_data.Volume; + data["FunctionCode"] = task_data.FunctionCode; + data["TradeTime"] = task_data.TradeTime; + + this->onRtnL2Trade(data); +}; + +void TdApi::processNtfCheckOrderList(Task task) +{ + this->onNtfCheckOrderList(); +}; + diff --git a/vn.lts/pyscript/l2/lts_l2_switch.cpp b/vn.lts/pyscript/l2/lts_l2_switch.cpp new file mode 100644 index 00000000..fab9039c --- /dev/null +++ b/vn.lts/pyscript/l2/lts_l2_switch.cpp @@ -0,0 +1,102 @@ +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 ONRSPSUBL2MARKETDATA: +{ + this->processRspSubL2MarketData(task); + break; +} + +case ONRSPUNSUBL2MARKETDATA: +{ + this->processRspUnSubL2MarketData(task); + break; +} + +case ONRSPSUBL2INDEX: +{ + this->processRspSubL2Index(task); + break; +} + +case ONRSPUNSUBL2INDEX: +{ + this->processRspUnSubL2Index(task); + break; +} + +case ONRTNL2MARKETDATA: +{ + this->processRtnL2MarketData(task); + break; +} + +case ONRTNL2INDEX: +{ + this->processRtnL2Index(task); + break; +} + +case ONRSPSUBL2ORDERANDTRADE: +{ + this->processRspSubL2OrderAndTrade(task); + break; +} + +case ONRSPUNSUBL2ORDERANDTRADE: +{ + this->processRspUnSubL2OrderAndTrade(task); + break; +} + +case ONRTNL2ORDER: +{ + this->processRtnL2Order(task); + break; +} + +case ONRTNL2TRADE: +{ + this->processRtnL2Trade(task); + break; +} + +case ONNTFCHECKORDERLIST: +{ + this->processNtfCheckOrderList(task); + break; +} + diff --git a/vn.lts/pyscript/l2/lts_l2_task.cpp b/vn.lts/pyscript/l2/lts_l2_task.cpp new file mode 100644 index 00000000..b74f6d69 --- /dev/null +++ b/vn.lts/pyscript/l2/lts_l2_task.cpp @@ -0,0 +1,370 @@ +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(CSecurityFtdcUserLoginField *pUserLogin, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) +{ + Task task = Task(); + task.task_name = ONRSPUSERLOGIN; + + if (pUserLogin) + { + task.task_data = *pUserLogin; + } + else + { + CSecurityFtdcUserLoginField empty_data = CSecurityFtdcUserLoginField(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + + 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; + + if (pUserLogout) + { + task.task_data = *pUserLogout; + } + else + { + CSecurityFtdcUserLogoutField empty_data = CSecurityFtdcUserLogoutField(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + + 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::OnRspSubL2MarketData(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) +{ + Task task = Task(); + task.task_name = ONRSPSUBL2MARKETDATA; + + if (pSpecificInstrument) + { + task.task_data = *pSpecificInstrument; + } + else + { + CSecurityFtdcSpecificInstrumentField empty_data = CSecurityFtdcSpecificInstrumentField(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + + 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::OnRspUnSubL2MarketData(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) +{ + Task task = Task(); + task.task_name = ONRSPUNSUBL2MARKETDATA; + + if (pSpecificInstrument) + { + task.task_data = *pSpecificInstrument; + } + else + { + CSecurityFtdcSpecificInstrumentField empty_data = CSecurityFtdcSpecificInstrumentField(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + + 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::OnRspSubL2Index(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) +{ + Task task = Task(); + task.task_name = ONRSPSUBL2INDEX; + + if (pSpecificInstrument) + { + task.task_data = *pSpecificInstrument; + } + else + { + CSecurityFtdcSpecificInstrumentField empty_data = CSecurityFtdcSpecificInstrumentField(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + + 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::OnRspUnSubL2Index(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) +{ + Task task = Task(); + task.task_name = ONRSPUNSUBL2INDEX; + + if (pSpecificInstrument) + { + task.task_data = *pSpecificInstrument; + } + else + { + CSecurityFtdcSpecificInstrumentField empty_data = CSecurityFtdcSpecificInstrumentField(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + + 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::OnRtnL2MarketData(CSecurityFtdcL2MarketDataField *pL2MarketData) +{ + Task task = Task(); + task.task_name = ONRTNL2MARKETDATA; + + if (pL2MarketData) + { + task.task_data = *pL2MarketData; + } + else + { + CSecurityFtdcL2MarketDataField empty_data = CSecurityFtdcL2MarketDataField(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + this->task_queue.push(task); +}; + +void TdApi::OnRtnL2Index(CSecurityFtdcL2IndexField *pL2Index) +{ + Task task = Task(); + task.task_name = ONRTNL2INDEX; + + if (pL2Index) + { + task.task_data = *pL2Index; + } + else + { + CSecurityFtdcL2IndexField empty_data = CSecurityFtdcL2IndexField(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + this->task_queue.push(task); +}; + +void TdApi::OnRspSubL2OrderAndTrade(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) +{ + Task task = Task(); + task.task_name = ONRSPSUBL2ORDERANDTRADE; + + 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::OnRspUnSubL2OrderAndTrade(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) +{ + Task task = Task(); + task.task_name = ONRSPUNSUBL2ORDERANDTRADE; + + 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::OnRtnL2Order(CSecurityFtdcL2OrderField *pL2Order) +{ + Task task = Task(); + task.task_name = ONRTNL2ORDER; + + if (pL2Order) + { + task.task_data = *pL2Order; + } + else + { + CSecurityFtdcL2OrderField empty_data = CSecurityFtdcL2OrderField(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + this->task_queue.push(task); +}; + +void TdApi::OnRtnL2Trade(CSecurityFtdcL2TradeField *pL2Trade) +{ + Task task = Task(); + task.task_name = ONRTNL2TRADE; + + if (pL2Trade) + { + task.task_data = *pL2Trade; + } + else + { + CSecurityFtdcL2TradeField empty_data = CSecurityFtdcL2TradeField(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + this->task_queue.push(task); +}; + +void TdApi::OnNtfCheckOrderList(TSecurityFtdcInstrumentIDType InstrumentID, TSecurityFtdcFunctionCodeType FunctionCode) +{ + Task task = Task(); + task.task_name = ONNTFCHECKORDERLIST; + + if (nstrumentID) + { + task.task_data = InstrumentID; + } + else + { + TSecurityFtdcInstrumentIDType empty_data = TSecurityFtdcInstrumentIDType(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + + if (unctionCode) + { + task.task_data = FunctionCode; + } + else + { + TSecurityFtdcFunctionCodeType empty_data = TSecurityFtdcFunctionCodeType(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + this->task_queue.push(task); +}; + diff --git a/vn.lts/pyscript/l2/lts_l2_wrap.cpp b/vn.lts/pyscript/l2/lts_l2_wrap.cpp new file mode 100644 index 00000000..e24fef76 --- /dev/null +++ b/vn.lts/pyscript/l2/lts_l2_wrap.cpp @@ -0,0 +1,182 @@ +virtual void onRspError(dict error, int id, bool last) +{ + PyLock lock; + + try + { + this->get_override("onRspError")(error, id, last); + } + catch (error_already_set const &) + { + PyErr_Print(); + } +}; + +virtual void onRspUserLogin(dict data, dict error, int id, bool last) +{ + PyLock lock; + + try + { + this->get_override("onRspUserLogin")(data, error, id, last); + } + catch (error_already_set const &) + { + PyErr_Print(); + } +}; + +virtual void onRspUserLogout(dict data, dict error, int id, bool last) +{ + PyLock lock; + + try + { + this->get_override("onRspUserLogout")(data, error, id, last); + } + catch (error_already_set const &) + { + PyErr_Print(); + } +}; + +virtual void onRspSubL2MarketData(dict data, dict error, int id, bool last) +{ + PyLock lock; + + try + { + this->get_override("onRspSubL2MarketData")(data, error, id, last); + } + catch (error_already_set const &) + { + PyErr_Print(); + } +}; + +virtual void onRspUnSubL2MarketData(dict data, dict error, int id, bool last) +{ + PyLock lock; + + try + { + this->get_override("onRspUnSubL2MarketData")(data, error, id, last); + } + catch (error_already_set const &) + { + PyErr_Print(); + } +}; + +virtual void onRspSubL2Index(dict data, dict error, int id, bool last) +{ + PyLock lock; + + try + { + this->get_override("onRspSubL2Index")(data, error, id, last); + } + catch (error_already_set const &) + { + PyErr_Print(); + } +}; + +virtual void onRspUnSubL2Index(dict data, dict error, int id, bool last) +{ + PyLock lock; + + try + { + this->get_override("onRspUnSubL2Index")(data, error, id, last); + } + catch (error_already_set const &) + { + PyErr_Print(); + } +}; + +virtual void onRtnL2MarketData(dict data) +{ + PyLock lock; + + try + { + this->get_override("onRtnL2MarketData")(data); + } + catch (error_already_set const &) + { + PyErr_Print(); + } +}; + +virtual void onRtnL2Index(dict data) +{ + PyLock lock; + + try + { + this->get_override("onRtnL2Index")(data); + } + catch (error_already_set const &) + { + PyErr_Print(); + } +}; + +virtual void onRspSubL2OrderAndTrade(dict data, dict error, int id, bool last) +{ + PyLock lock; + + try + { + this->get_override("onRspSubL2OrderAndTrade")(data, error, id, last); + } + catch (error_already_set const &) + { + PyErr_Print(); + } +}; + +virtual void onRspUnSubL2OrderAndTrade(dict data, dict error, int id, bool last) +{ + PyLock lock; + + try + { + this->get_override("onRspUnSubL2OrderAndTrade")(data, error, id, last); + } + catch (error_already_set const &) + { + PyErr_Print(); + } +}; + +virtual void onRtnL2Order(dict data) +{ + PyLock lock; + + try + { + this->get_override("onRtnL2Order")(data); + } + catch (error_already_set const &) + { + PyErr_Print(); + } +}; + +virtual void onRtnL2Trade(dict data) +{ + PyLock lock; + + try + { + this->get_override("onRtnL2Trade")(data); + } + catch (error_already_set const &) + { + PyErr_Print(); + } +}; + diff --git a/vn.lts/vnltsl2/test/L2mduserapi.dll b/vn.lts/vnltsl2/test/L2mduserapi.dll new file mode 100644 index 00000000..d401bf1f Binary files /dev/null and b/vn.lts/vnltsl2/test/L2mduserapi.dll differ diff --git a/vn.lts/vnltsl2/test/l2test.py b/vn.lts/vnltsl2/test/l2test.py new file mode 100644 index 00000000..3faa5b42 --- /dev/null +++ b/vn.lts/vnltsl2/test/l2test.py @@ -0,0 +1,226 @@ +# encoding: UTF-8 + +import sys +from time import sleep + +from PyQt4 import QtGui + +from vnltsl2 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 TestL2MdApi(L2MdApi): + """娴嬭瘯鐢ㄥ疄渚""" + + #---------------------------------------------------------------------- + def __init__(self): + """Constructor""" + super(TestL2MdApi, self).__init__() + self.brokerID = None + self.userID = None + + #---------------------------------------------------------------------- + @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): + """鐧婚檰鍥炴姤""" + self.brokerID = data['BrokerID'] + self.userID = data['UserID'] + print_dict(data) + print_dict(error) + + #---------------------------------------------------------------------- + @simple_log + def onRspUserLogout(self, data, error, n, last): + """鐧诲嚭鍥炴姤""" + print_dict(data) + print_dict(error) + + #---------------------------------------------------------------------- + @simple_log + def onRspSubL2MarketData(self, data, error, n, last): + """璁㈤槄L2鍚堢害鍥炴姤""" + print_dict(data) + print_dict(error) + + #---------------------------------------------------------------------- + @simple_log + def onRspUnSubL2MarketData(self, data, error, n, last): + """閫璁2鍚堢害鍥炴姤""" + print_dict(data) + print_dict(error) + + #---------------------------------------------------------------------- + @simple_log + def onRspSubL2Index(self, data, error, n, last): + """璁㈤槄L2鎸囨暟鍥炴姤""" + print_dict(data) + print_dict(error) + + #---------------------------------------------------------------------- + @simple_log + def onRspUnSubL2Index(self, data, error, n, last): + """閫璁2鎸囨暟鍥炴姤""" + print_dict(data) + print_dict(error) + + #---------------------------------------------------------------------- + @simple_log + def onRtnL2MarketData(self, data): + """L2琛屾儏鎺ㄩ""" + print_dict(data) + + #---------------------------------------------------------------------- + @simple_log + def onRtnL2Index(self, data): + """L2鎸囨暟琛屾儏鎺ㄩ""" + print_dict(data) + + #---------------------------------------------------------------------- + @simple_log + def onRtnL2Order(self, data): + """L2璁㈠崟鎺ㄩ""" + print_dict(data) + + #---------------------------------------------------------------------- + @simple_log + def onRtnL2Trade(self, data): + """L2鎴愪氦鎺ㄩ""" + print_dict(data) + + #---------------------------------------------------------------------- + @simple_log + def onRspSubL2OrderAndTrade(self, error, n, last): + """璁㈤槄L2璁㈠崟銆佹垚浜ゅ洖鎶""" + print_dict(error) + + #---------------------------------------------------------------------- + @simple_log + def onRspUnSubL2OrderAndTrade(self, error, n, last): + """閫璁2璁㈠崟銆佹垚浜ゅ洖鎶""" + print_dict(error) + + #---------------------------------------------------------------------- + @simple_log + def onNtfCheckOrderList(self, instrumentID, functionID): + """閫氱煡娓呯悊SSE涔板崠涓闃熷垪涓暟閲忎负0鐨勬姤鍗""" + print 'instrumentID: %s' % instrumentID + print 'functionID: %s' % functionID + +#---------------------------------------------------------------------- +def main(): + """涓绘祴璇曞嚱鏁帮紝鍑虹幇鍫靛鏃跺彲浠ヨ冭檻浣跨敤sleep""" + reqid = 0 + + # 鍒涘缓Qt搴旂敤瀵硅薄锛岀敤浜庝簨浠跺惊鐜 + app = QtGui.QApplication(sys.argv) + + # 鍒涘缓API瀵硅薄 + api = TestL2MdApi() + + # 鍦–++鐜涓垱寤篗dApi瀵硅薄锛屼紶鍏ュ弬鏁版槸甯屾湜鐢ㄦ潵淇濆瓨.con鏂囦欢鐨勫湴鍧 + api.createFtdcL2MDUserApi('') + + # 娉ㄥ唽鍓嶇疆鏈哄湴鍧 + api.registerFront("tcp://101.231.210.2:8900") # 鍙︿竴涓湴鍧tcp://222.66.55.171:8900 + + # 鍒濆鍖朼pi锛岃繛鎺ュ墠缃満 + api.init() + sleep(0.5) + + # 鐧婚檰锛屾祴璇曢氳繃 + loginReq = {} # 鍒涘缓涓涓┖瀛楀吀 + loginReq['UserID'] = '' # 鍙傛暟浣滀负瀛楀吀閿肩殑鏂瑰紡浼犲叆 + loginReq['Password'] = '' # 閿悕鍜孋++涓殑缁撴瀯浣撴垚鍛樺悕瀵瑰簲 + loginReq['BrokerID'] = '2011' + loginReq['DataLevel'] = '1' # '0'鍏ㄩ噺琛屾儏 '1'10妗 '2'5妗 + reqid = reqid + 1 # 璇锋眰鏁板繀椤讳繚鎸佸敮涓鎬 + i = api.reqUserLogin(loginReq, 1) + sleep(0.5) + + ## 鐧诲嚭锛屾祴璇曞け璐 + #reqid = reqid + 1 + #logoutReq = {} + #logoutReq['UserID'] = api.userID + #loginReq['BrokerID'] = api.brokerID + #i = api.reqUserLogout(logoutReq, 1) + #sleep(0.5) + + ## 瀹夊叏閫鍑猴紝娴嬭瘯閫氳繃 + #i = api.exit() + + # 鑾峰彇浜ゆ槗鏃ワ紝娴嬭瘯閫氳繃 + #day = api.getTradingDay() + #print 'Trading Day is:' + str(day) + #sleep(0.5) + + # 璁㈤槄L2鍚堢害锛屾祴璇曢氳繃 + subReq = {} + subReq['InstrumentID'] = '510050' + subReq['ExchangeID'] = 'SSE' + i = api.subscribeL2MarketData(subReq) + + ## 閫璁2鍚堢害锛屾祴璇曢氳繃 + #i = api.unSubscribeL2MarketData(subReq) + + ## 璁㈤槄L2鎸囨暟锛屾祴璇曢氳繃 + #subReq = {} + #subReq['InstrumentID'] = '000300' + #subReq['ExchangeID'] = 'SSE' + #i = api.subscribeL2Index(subReq) + + ## 閫璁2鍚堢害锛屾祴璇曢氳繃 + #i = api.unSubscribeL2Index(subReq) + + # 璁㈤槄L2鎶ュ崟鍜屾垚浜わ紝娴嬭瘯鎻愮ず鏃犳鏉冮檺 + i = api.subscribeL2OrderAndTrade() + + # 閫璁2鎶ュ崟鍜屾垚浜わ紝娴嬭瘯閫氳繃 + i = api.unSubscribeL2OrderAndTrade() + + # 杩炵画杩愯锛岀敤浜庤緭鍑鸿鎯 + app.exec_() + + + +if __name__ == '__main__': + main() diff --git a/vn.lts/vnltsl2/test/vnltsl2.pyd b/vn.lts/vnltsl2/test/vnltsl2.pyd new file mode 100644 index 00000000..2703437c Binary files /dev/null and b/vn.lts/vnltsl2/test/vnltsl2.pyd differ diff --git a/vn.lts/vnltsl2/vnltsl2/ReadMe.txt b/vn.lts/vnltsl2/vnltsl2/ReadMe.txt new file mode 100644 index 00000000..f67e3fb3 --- /dev/null +++ b/vn.lts/vnltsl2/vnltsl2/ReadMe.txt @@ -0,0 +1,32 @@ +锘======================================================================== + 鍔ㄦ侀摼鎺ュ簱锛歷nltsl2 椤圭洰姒傝堪 +======================================================================== + +搴旂敤绋嬪簭鍚戝宸蹭负鎮ㄥ垱寤轰簡姝 vnltsl2 DLL銆 + +鏈枃浠舵瑕佷粙缁嶇粍鎴 vnltsl2 搴旂敤绋嬪簭鐨勬瘡涓枃浠剁殑鍐呭銆 + + +vnltsl2.vcxproj + 杩欐槸浣跨敤搴旂敤绋嬪簭鍚戝鐢熸垚鐨 VC++ 椤圭洰鐨勪富椤圭洰鏂囦欢锛屽叾涓寘鍚敓鎴愯鏂囦欢鐨 Visual C++ 鐨勭増鏈俊鎭紝浠ュ強鏈夊叧浣跨敤搴旂敤绋嬪簭鍚戝閫夋嫨鐨勫钩鍙般侀厤缃拰椤圭洰鍔熻兘鐨勪俊鎭 + +vnltsl2.vcxproj.filters + 杩欐槸浣跨敤鈥滃簲鐢ㄧ▼搴忓悜瀵尖濈敓鎴愮殑 VC++ 椤圭洰绛涢夊櫒鏂囦欢銆傚畠鍖呭惈鏈夊叧椤圭洰鏂囦欢涓庣瓫閫夊櫒涔嬮棿鐨勫叧鑱斾俊鎭傚湪 IDE 涓紝閫氳繃杩欑鍏宠仈锛屽湪鐗瑰畾鑺傜偣涓嬩互鍒嗙粍褰㈠紡鏄剧ず鍏锋湁鐩镐技鎵╁睍鍚嶇殑鏂囦欢銆備緥濡傦紝鈥.cpp鈥濇枃浠朵笌鈥滄簮鏂囦欢鈥濈瓫閫夊櫒鍏宠仈銆 + +vnltsl2.cpp + 杩欐槸涓 DLL 婧愭枃浠躲 + + 姝 DLL 鍦ㄥ垱寤烘椂涓嶅鍑轰换浣曠鍙枫傚洜姝わ紝鐢熸垚鏃朵笉浼氫骇鐢 .lib 鏂囦欢銆傚鏋滃笇鏈涙椤圭洰鎴愪负鍏朵粬鏌愪釜椤圭洰鐨勯」鐩緷璧栭」锛屽垯闇瑕佹坊鍔犱唬鐮佷互浠 DLL 瀵煎嚭鏌愪簺绗﹀彿锛屼互渚夸骇鐢熶竴涓鍑哄簱锛屾垨鑰咃紝涔熷彲浠ュ湪椤圭洰鈥滃睘鎬ч〉鈥濆璇濇涓殑鈥滈摼鎺ュ櫒鈥濇枃浠跺す涓紝灏嗏滃父瑙勨濆睘鎬ч〉涓婄殑鈥滃拷鐣ヨ緭鍏ュ簱鈥濆睘鎬ц缃负鈥滄槸鈥濄 + +///////////////////////////////////////////////////////////////////////////// +鍏朵粬鏍囧噯鏂囦欢: + +StdAfx.h, StdAfx.cpp + 杩欎簺鏂囦欢鐢ㄤ簬鐢熸垚鍚嶄负 vnltsl2.pch 鐨勯缂栬瘧澶 (PCH) 鏂囦欢鍜屽悕涓 StdAfx.obj 鐨勯缂栬瘧绫诲瀷鏂囦欢銆 + +///////////////////////////////////////////////////////////////////////////// +鍏朵粬娉ㄩ噴: + +搴旂敤绋嬪簭鍚戝浣跨敤鈥淭ODO:鈥濇敞閲婃潵鎸囩ず搴旀坊鍔犳垨鑷畾涔夌殑婧愪唬鐮侀儴鍒嗐 + +///////////////////////////////////////////////////////////////////////////// diff --git a/vn.lts/vnltsl2/vnltsl2/dllmain.cpp b/vn.lts/vnltsl2/vnltsl2/dllmain.cpp new file mode 100644 index 00000000..260abc6d --- /dev/null +++ b/vn.lts/vnltsl2/vnltsl2/dllmain.cpp @@ -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; +} + diff --git a/vn.lts/vnltsl2/vnltsl2/stdafx.cpp b/vn.lts/vnltsl2/vnltsl2/stdafx.cpp new file mode 100644 index 00000000..bf416b64 --- /dev/null +++ b/vn.lts/vnltsl2/vnltsl2/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : 只包括标准包含文件的源文件 +// vnltsl2.pch 将作为预编译头 +// stdafx.obj 将包含预编译类型信息 + +#include "stdafx.h" + +// TODO: 在 STDAFX.H 中 +// 引用任何所需的附加头文件,而不是在此文件中引用 diff --git a/vn.lts/vnltsl2/vnltsl2/stdafx.h b/vn.lts/vnltsl2/vnltsl2/stdafx.h new file mode 100644 index 00000000..2ec1caa0 --- /dev/null +++ b/vn.lts/vnltsl2/vnltsl2/stdafx.h @@ -0,0 +1,16 @@ +// stdafx.h : 标准系统包含文件的包含文件, +// 或是经常使用但不常更改的 +// 特定于项目的包含文件 +// + +#pragma once + +#include "targetver.h" + +#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的信息 +// Windows 头文件: +#include + + + +// TODO: 在此处引用程序需要的其他头文件 diff --git a/vn.lts/vnltsl2/vnltsl2/targetver.h b/vn.lts/vnltsl2/vnltsl2/targetver.h new file mode 100644 index 00000000..7a7d2c83 --- /dev/null +++ b/vn.lts/vnltsl2/vnltsl2/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。 + +// 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将 +// WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。 + +#include diff --git a/vn.lts/vnltsl2/vnltsl2/vnltsl2.cpp b/vn.lts/vnltsl2/vnltsl2/vnltsl2.cpp new file mode 100644 index 00000000..193fd309 --- /dev/null +++ b/vn.lts/vnltsl2/vnltsl2/vnltsl2.cpp @@ -0,0 +1,1249 @@ +// vnltsl2.cpp : 定义 DLL 应用程序的导出函数。 +// + +#include "stdafx.h" +#include "vnltsl2.h" + + + +///------------------------------------------------------------------------------------- +///从Python对象到C++类型转换用的函数 +///------------------------------------------------------------------------------------- + +void getInt(dict d, string key, int *value) +{ + if (d.has_key(key)) //检查字典中是否存在该键值 + { + object o = d[key]; //获取该键值 + extract 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 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 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 L2MdApi::OnFrontConnected() +{ + Task task = Task(); + task.task_name = ONFRONTCONNECTED; + this->task_queue.push(task); +}; + +void L2MdApi::OnFrontDisconnected(int nReason) +{ + Task task = Task(); + task.task_name = ONFRONTDISCONNECTED; + task.task_id = nReason; + this->task_queue.push(task); +}; + +void L2MdApi::OnHeartBeatWarning(int nTimeLapse) +{ + Task task = Task(); + task.task_name = ONHEARTBEATWARNING; + task.task_id = nTimeLapse; + this->task_queue.push(task); +}; + +void L2MdApi::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 L2MdApi::OnRspUserLogin(CSecurityFtdcUserLoginField *pUserLogin, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) +{ + Task task = Task(); + task.task_name = ONRSPUSERLOGIN; + + if (pUserLogin) + { + task.task_data = *pUserLogin; + } + else + { + CSecurityFtdcUserLoginField empty_data = CSecurityFtdcUserLoginField(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + + 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 L2MdApi::OnRspUserLogout(CSecurityFtdcUserLogoutField *pUserLogout, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) +{ + Task task = Task(); + task.task_name = ONRSPUSERLOGOUT; + + if (pUserLogout) + { + task.task_data = *pUserLogout; + } + else + { + CSecurityFtdcUserLogoutField empty_data = CSecurityFtdcUserLogoutField(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + + 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 L2MdApi::OnRspSubL2MarketData(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) +{ + Task task = Task(); + task.task_name = ONRSPSUBL2MARKETDATA; + + if (pSpecificInstrument) + { + task.task_data = *pSpecificInstrument; + } + else + { + CSecurityFtdcSpecificInstrumentField empty_data = CSecurityFtdcSpecificInstrumentField(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + + 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 L2MdApi::OnRspUnSubL2MarketData(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) +{ + Task task = Task(); + task.task_name = ONRSPUNSUBL2MARKETDATA; + + if (pSpecificInstrument) + { + task.task_data = *pSpecificInstrument; + } + else + { + CSecurityFtdcSpecificInstrumentField empty_data = CSecurityFtdcSpecificInstrumentField(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + + 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 L2MdApi::OnRspSubL2Index(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) +{ + Task task = Task(); + task.task_name = ONRSPSUBL2INDEX; + + if (pSpecificInstrument) + { + task.task_data = *pSpecificInstrument; + } + else + { + CSecurityFtdcSpecificInstrumentField empty_data = CSecurityFtdcSpecificInstrumentField(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + + 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 L2MdApi::OnRspUnSubL2Index(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) +{ + Task task = Task(); + task.task_name = ONRSPUNSUBL2INDEX; + + if (pSpecificInstrument) + { + task.task_data = *pSpecificInstrument; + } + else + { + CSecurityFtdcSpecificInstrumentField empty_data = CSecurityFtdcSpecificInstrumentField(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + + 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 L2MdApi::OnRtnL2MarketData(CSecurityFtdcL2MarketDataField *pL2MarketData) +{ + Task task = Task(); + task.task_name = ONRTNL2MARKETDATA; + + if (pL2MarketData) + { + task.task_data = *pL2MarketData; + } + else + { + CSecurityFtdcL2MarketDataField empty_data = CSecurityFtdcL2MarketDataField(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + this->task_queue.push(task); +}; + +void L2MdApi::OnRtnL2Index(CSecurityFtdcL2IndexField *pL2Index) +{ + Task task = Task(); + task.task_name = ONRTNL2INDEX; + + if (pL2Index) + { + task.task_data = *pL2Index; + } + else + { + CSecurityFtdcL2IndexField empty_data = CSecurityFtdcL2IndexField(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + this->task_queue.push(task); +}; + +void L2MdApi::OnRspSubL2OrderAndTrade(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) +{ + Task task = Task(); + task.task_name = ONRSPSUBL2ORDERANDTRADE; + + 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 L2MdApi::OnRspUnSubL2OrderAndTrade(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) +{ + Task task = Task(); + task.task_name = ONRSPUNSUBL2ORDERANDTRADE; + + 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 L2MdApi::OnRtnL2Order(CSecurityFtdcL2OrderField *pL2Order) +{ + Task task = Task(); + task.task_name = ONRTNL2ORDER; + + if (pL2Order) + { + task.task_data = *pL2Order; + } + else + { + CSecurityFtdcL2OrderField empty_data = CSecurityFtdcL2OrderField(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + this->task_queue.push(task); +}; + +void L2MdApi::OnRtnL2Trade(CSecurityFtdcL2TradeField *pL2Trade) +{ + Task task = Task(); + task.task_name = ONRTNL2TRADE; + + if (pL2Trade) + { + task.task_data = *pL2Trade; + } + else + { + CSecurityFtdcL2TradeField empty_data = CSecurityFtdcL2TradeField(); + memset(&empty_data, 0, sizeof(empty_data)); + task.task_data = empty_data; + } + this->task_queue.push(task); +}; + +void L2MdApi::OnNtfCheckOrderList(TSecurityFtdcInstrumentIDType InstrumentID, TSecurityFtdcFunctionCodeType FunctionCode) +{ + //该函数为手动实现 + Task task = Task(); + task.task_name = ONNTFCHECKORDERLIST; + + //先转换为string类型 + string instrumentID = InstrumentID; + string functionCode = FunctionCode; + + task.task_data = instrumentID; + task.task_error = functionCode; + + this->task_queue.push(task); +}; + + +///------------------------------------------------------------------------------------- +///工作线程从队列中取出数据,转化为python对象后,进行推送 +///------------------------------------------------------------------------------------- + +void L2MdApi::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 ONRSPSUBL2MARKETDATA: + { + this->processRspSubL2MarketData(task); + break; + } + + case ONRSPUNSUBL2MARKETDATA: + { + this->processRspUnSubL2MarketData(task); + break; + } + + case ONRSPSUBL2INDEX: + { + this->processRspSubL2Index(task); + break; + } + + case ONRSPUNSUBL2INDEX: + { + this->processRspUnSubL2Index(task); + break; + } + + case ONRTNL2MARKETDATA: + { + this->processRtnL2MarketData(task); + break; + } + + case ONRTNL2INDEX: + { + this->processRtnL2Index(task); + break; + } + + case ONRSPSUBL2ORDERANDTRADE: + { + this->processRspSubL2OrderAndTrade(task); + break; + } + + case ONRSPUNSUBL2ORDERANDTRADE: + { + this->processRspUnSubL2OrderAndTrade(task); + break; + } + + case ONRTNL2ORDER: + { + this->processRtnL2Order(task); + break; + } + + case ONRTNL2TRADE: + { + this->processRtnL2Trade(task); + break; + } + + case ONNTFCHECKORDERLIST: + { + this->processNtfCheckOrderList(task); + break; + } + } + } +}; + +void L2MdApi::processFrontConnected(Task task) +{ + this->onFrontConnected(); +}; + +void L2MdApi::processFrontDisconnected(Task task) +{ + this->onFrontDisconnected(task.task_id); +}; + +void L2MdApi::processHeartBeatWarning(Task task) +{ + this->onHeartBeatWarning(task.task_id); +}; + +void L2MdApi::processRspError(Task task) +{ + CSecurityFtdcRspInfoField task_error = any_cast(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 L2MdApi::processRspUserLogin(Task task) +{ + CSecurityFtdcUserLoginField task_data = any_cast(task.task_data); + dict data; + data["TradingDay"] = task_data.TradingDay; + data["Password"] = task_data.Password; + data["BrokerID"] = task_data.BrokerID; + data["DataLevel"] = task_data.DataLevel; + data["UserID"] = task_data.UserID; + + CSecurityFtdcRspInfoField task_error = any_cast(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 L2MdApi::processRspUserLogout(Task task) +{ + CSecurityFtdcUserLogoutField task_data = any_cast(task.task_data); + dict data; + data["UserID"] = task_data.UserID; + data["BrokerID"] = task_data.BrokerID; + + CSecurityFtdcRspInfoField task_error = any_cast(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 L2MdApi::processRspSubL2MarketData(Task task) +{ + CSecurityFtdcSpecificInstrumentField task_data = any_cast(task.task_data); + dict data; + data["InstrumentID"] = task_data.InstrumentID; + data["ExchangeID"] = task_data.ExchangeID; + + CSecurityFtdcRspInfoField task_error = any_cast(task.task_error); + dict error; + error["ErrorMsg"] = task_error.ErrorMsg; + error["ErrorID"] = task_error.ErrorID; + + this->onRspSubL2MarketData(data, error, task.task_id, task.task_last); +}; + +void L2MdApi::processRspUnSubL2MarketData(Task task) +{ + CSecurityFtdcSpecificInstrumentField task_data = any_cast(task.task_data); + dict data; + data["InstrumentID"] = task_data.InstrumentID; + data["ExchangeID"] = task_data.ExchangeID; + + CSecurityFtdcRspInfoField task_error = any_cast(task.task_error); + dict error; + error["ErrorMsg"] = task_error.ErrorMsg; + error["ErrorID"] = task_error.ErrorID; + + this->onRspUnSubL2MarketData(data, error, task.task_id, task.task_last); +}; + +void L2MdApi::processRspSubL2Index(Task task) +{ + CSecurityFtdcSpecificInstrumentField task_data = any_cast(task.task_data); + dict data; + data["InstrumentID"] = task_data.InstrumentID; + data["ExchangeID"] = task_data.ExchangeID; + + CSecurityFtdcRspInfoField task_error = any_cast(task.task_error); + dict error; + error["ErrorMsg"] = task_error.ErrorMsg; + error["ErrorID"] = task_error.ErrorID; + + this->onRspSubL2Index(data, error, task.task_id, task.task_last); +}; + +void L2MdApi::processRspUnSubL2Index(Task task) +{ + CSecurityFtdcSpecificInstrumentField task_data = any_cast(task.task_data); + dict data; + data["InstrumentID"] = task_data.InstrumentID; + data["ExchangeID"] = task_data.ExchangeID; + + CSecurityFtdcRspInfoField task_error = any_cast(task.task_error); + dict error; + error["ErrorMsg"] = task_error.ErrorMsg; + error["ErrorID"] = task_error.ErrorID; + + this->onRspUnSubL2Index(data, error, task.task_id, task.task_last); +}; + +void L2MdApi::processRtnL2MarketData(Task task) +{ + CSecurityFtdcL2MarketDataField task_data = any_cast(task.task_data); + dict data; + data["BidCount8"] = task_data.BidCount8; + data["BidVolume4"] = task_data.BidVolume4; + data["BidPrice9"] = task_data.BidPrice9; + data["BidPrice8"] = task_data.BidPrice8; + data["OfferVolume8"] = task_data.OfferVolume8; + data["OfferCount9"] = task_data.OfferCount9; + data["BidPrice5"] = task_data.BidPrice5; + data["LowPrice"] = task_data.LowPrice; + data["BidPrice7"] = task_data.BidPrice7; + data["AltWeightedAvgOfferPrice"] = task_data.AltWeightedAvgOfferPrice; + data["BidPrice1"] = task_data.BidPrice1; + data["OfferCount3"] = task_data.OfferCount3; + data["TotalTradeVolume"] = task_data.TotalTradeVolume; + data["BidPrice2"] = task_data.BidPrice2; + data["BidVolume1"] = task_data.BidVolume1; + data["OfferVolume3"] = task_data.OfferVolume3; + data["PreClosePrice"] = task_data.PreClosePrice; + data["OfferVolumeA"] = task_data.OfferVolumeA; + data["BidCount3"] = task_data.BidCount3; + data["BidCount2"] = task_data.BidCount2; + data["BidCount1"] = task_data.BidCount1; + data["BidPriceLevel"] = task_data.BidPriceLevel; + data["BidCount7"] = task_data.BidCount7; + data["BidCount6"] = task_data.BidCount6; + data["BidCount5"] = task_data.BidCount5; + data["BidCount4"] = task_data.BidCount4; + data["BidVolume7"] = task_data.BidVolume7; + data["BidVolume6"] = task_data.BidVolume6; + data["TotalOfferVolume"] = task_data.TotalOfferVolume; + data["TotalBidVolume"] = task_data.TotalBidVolume; + data["BidVolume3"] = task_data.BidVolume3; + data["BidVolume2"] = task_data.BidVolume2; + data["OpenPrice"] = task_data.OpenPrice; + data["OfferPriceA"] = task_data.OfferPriceA; + data["OfferCount7"] = task_data.OfferCount7; + data["OfferCount6"] = task_data.OfferCount6; + data["TradeCount"] = task_data.TradeCount; + data["BidPrice4"] = task_data.BidPrice4; + data["WeightedAvgOfferPrice"] = task_data.WeightedAvgOfferPrice; + data["OfferVolume6"] = task_data.OfferVolume6; + data["HighPrice"] = task_data.HighPrice; + data["OfferVolume9"] = task_data.OfferVolume9; + data["InstrumentID"] = task_data.InstrumentID; + data["ClosePrice"] = task_data.ClosePrice; + data["ExchangeID"] = task_data.ExchangeID; + data["BidPrice6"] = task_data.BidPrice6; + data["OfferPrice7"] = task_data.OfferPrice7; + data["AltWeightedAvgBidPrice"] = task_data.AltWeightedAvgBidPrice; + data["TimeStamp"] = task_data.TimeStamp; + data["WeightedAvgBidPrice"] = task_data.WeightedAvgBidPrice; + data["BidVolume9"] = task_data.BidVolume9; + data["TotalTradeValue"] = task_data.TotalTradeValue; + data["OfferCount4"] = task_data.OfferCount4; + data["TradingDay"] = task_data.TradingDay; + data["BidCountA"] = task_data.BidCountA; + data["BidPrice3"] = task_data.BidPrice3; + data["IOPV"] = task_data.IOPV; + data["OfferCount1"] = task_data.OfferCount1; + data["BidVolumeA"] = task_data.BidVolumeA; + data["OfferPrice9"] = task_data.OfferPrice9; + data["BidCount9"] = task_data.BidCount9; + data["OfferPrice8"] = task_data.OfferPrice8; + data["YieldToMaturity"] = task_data.YieldToMaturity; + data["LastPrice"] = task_data.LastPrice; + data["OfferCount8"] = task_data.OfferCount8; + data["OfferPrice4"] = task_data.OfferPrice4; + data["OfferPrice5"] = task_data.OfferPrice5; + data["OfferPrice6"] = task_data.OfferPrice6; + data["BidVolume8"] = task_data.BidVolume8; + data["OfferCount5"] = task_data.OfferCount5; + data["OfferPrice1"] = task_data.OfferPrice1; + data["OfferPrice2"] = task_data.OfferPrice2; + data["OfferPrice3"] = task_data.OfferPrice3; + data["OfferVolume4"] = task_data.OfferVolume4; + data["OfferVolume5"] = task_data.OfferVolume5; + data["OfferPriceLevel"] = task_data.OfferPriceLevel; + data["OfferVolume7"] = task_data.OfferVolume7; + data["OfferVolume1"] = task_data.OfferVolume1; + data["OfferVolume2"] = task_data.OfferVolume2; + data["OfferCount2"] = task_data.OfferCount2; + data["BidPriceA"] = task_data.BidPriceA; + data["BidVolume5"] = task_data.BidVolume5; + data["OfferCountA"] = task_data.OfferCountA; + + this->onRtnL2MarketData(data); +}; + +void L2MdApi::processRtnL2Index(Task task) +{ + CSecurityFtdcL2IndexField task_data = any_cast(task.task_data); + dict data; + data["InstrumentID"] = task_data.InstrumentID; + data["ExchangeID"] = task_data.ExchangeID; + data["HighIndex"] = task_data.HighIndex; + data["TimeStamp"] = task_data.TimeStamp; + data["CloseIndex"] = task_data.CloseIndex; + data["PreCloseIndex"] = task_data.PreCloseIndex; + data["LastIndex"] = task_data.LastIndex; + data["TradingDay"] = task_data.TradingDay; + data["OpenIndex"] = task_data.OpenIndex; + data["TotalVolume"] = task_data.TotalVolume; + data["LowIndex"] = task_data.LowIndex; + data["TurnOver"] = task_data.TurnOver; + + this->onRtnL2Index(data); +}; + +void L2MdApi::processRspSubL2OrderAndTrade(Task task) +{ + CSecurityFtdcRspInfoField task_error = any_cast(task.task_error); + dict error; + error["ErrorMsg"] = task_error.ErrorMsg; + error["ErrorID"] = task_error.ErrorID; + + this->onRspSubL2OrderAndTrade(error, task.task_id, task.task_last); +}; + +void L2MdApi::processRspUnSubL2OrderAndTrade(Task task) +{ + CSecurityFtdcRspInfoField task_error = any_cast(task.task_error); + dict error; + error["ErrorMsg"] = task_error.ErrorMsg; + error["ErrorID"] = task_error.ErrorID; + + this->onRspUnSubL2OrderAndTrade(error, task.task_id, task.task_last); +}; + +void L2MdApi::processRtnL2Order(Task task) +{ + CSecurityFtdcL2OrderField task_data = any_cast(task.task_data); + dict data; + data["InstrumentID"] = task_data.InstrumentID; + data["OrderTime"] = task_data.OrderTime; + data["OrderKind"] = task_data.OrderKind; + data["Price"] = task_data.Price; + data["ExchangeID"] = task_data.ExchangeID; + data["OrderGroupID"] = task_data.OrderGroupID; + data["Volume"] = task_data.Volume; + data["FunctionCode"] = task_data.FunctionCode; + data["OrderIndex"] = task_data.OrderIndex; + + this->onRtnL2Order(data); +}; + +void L2MdApi::processRtnL2Trade(Task task) +{ + CSecurityFtdcL2TradeField task_data = any_cast(task.task_data); + dict data; + data["TradeGroupID"] = task_data.TradeGroupID; + data["SellIndex"] = task_data.SellIndex; + data["ExchangeID"] = task_data.ExchangeID; + data["OrderKind"] = task_data.OrderKind; + data["TradeIndex"] = task_data.TradeIndex; + data["Price"] = task_data.Price; + data["InstrumentID"] = task_data.InstrumentID; + data["BuyIndex"] = task_data.BuyIndex; + data["Volume"] = task_data.Volume; + data["FunctionCode"] = task_data.FunctionCode; + data["TradeTime"] = task_data.TradeTime; + + this->onRtnL2Trade(data); +}; + +void L2MdApi::processNtfCheckOrderList(Task task) +{ + //该函数为手动实现 + string instrumentID = any_cast(task.task_data); + string functionCode = any_cast(task.task_data); + + this->onNtfCheckOrderList(instrumentID, functionCode); +}; + + + +///------------------------------------------------------------------------------------- +///主动函数 +///------------------------------------------------------------------------------------- + +void L2MdApi::createFtdcL2MDUserApi(string pszFlowPath) +{ + this->api = CSecurityFtdcL2MDUserApi::CreateFtdcL2MDUserApi(pszFlowPath.c_str()); + this->api->RegisterSpi(this); +}; + +void L2MdApi::release() +{ + this->api->Release(); +}; + +void L2MdApi::init() +{ + this->api->Init(); +}; + +int L2MdApi::join() +{ + int i = this->api->Join(); + return i; +}; + +int L2MdApi::exit() +{ + //该函数在原生API里没有,用于安全退出API用,原生的join似乎不太稳定 + this->api->RegisterSpi(NULL); + this->api->Release(); + this->api = NULL; + return 1; +}; + +string L2MdApi::getTradingDay() +{ + string day = this->api->GetTradingDay(); + return day; +}; + +void L2MdApi::registerFront(string pszFrontAddress) +{ + this->api->RegisterFront((char*)pszFrontAddress.c_str()); +}; + +int L2MdApi::reqUserLogin(dict req, int nRequestID) +{ + CSecurityFtdcUserLoginField myreq = CSecurityFtdcUserLoginField(); + memset(&myreq, 0, sizeof(myreq)); + getChar(req, "TradingDay", myreq.TradingDay); + getChar(req, "Password", myreq.Password); + getChar(req, "BrokerID", myreq.BrokerID); + getChar(req, "DataLevel", &myreq.DataLevel); + getChar(req, "UserID", myreq.UserID); + int i = this->api->ReqUserLogin(&myreq, nRequestID); + + return i; +}; + +int L2MdApi::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; +}; + +int L2MdApi::subscribeL2MarketData(dict req) +{ + char instrumentID[256]; + char exchangeID[256]; + getChar(req, "InstrumentID", instrumentID); + getChar(req, "ExchangeID", exchangeID); + char* myreq[1] = { instrumentID }; + int i = this->api->SubscribeL2MarketData(myreq, 1, exchangeID); + return i; +}; + +int L2MdApi::unSubscribeL2MarketData(dict req) +{ + char instrumentID[256]; + char exchangeID[256]; + getChar(req, "InstrumentID", instrumentID); + getChar(req, "ExchangeID", exchangeID); + char* myreq[1] = { instrumentID }; + int i = this->api->UnSubscribeL2MarketData(myreq, 1, exchangeID); + return i; +}; + +int L2MdApi::subscribeL2Index(dict req) +{ + char instrumentID[256]; + char exchangeID[256]; + getChar(req, "InstrumentID", instrumentID); + getChar(req, "ExchangeID", exchangeID); + char* myreq[1] = { instrumentID }; + int i = this->api->SubscribeL2Index(myreq, 1, exchangeID); + return i; +}; + +int L2MdApi::unSubscribeL2Index(dict req) +{ + char instrumentID[256]; + char exchangeID[256]; + getChar(req, "InstrumentID", instrumentID); + getChar(req, "ExchangeID", exchangeID); + char* myreq[1] = { instrumentID }; + int i = this->api->UnSubscribeL2Index(myreq, 1, exchangeID); + return i; +}; + +int L2MdApi::subscribeL2OrderAndTrade() +{ + int i = this->api->SubscribeL2OrderAndTrade(); + return i; +}; + +int L2MdApi::unSubscribeL2OrderAndTrade() +{ + int i = this->api->UnSubscribeL2OrderAndTrade(); + return i; +}; + + + + +///------------------------------------------------------------------------------------- +///Boost.Python封装 +///------------------------------------------------------------------------------------- + +struct L2MdApiWrap : L2MdApi, wrapper < L2MdApi > +{ + virtual void onFrontConnected() + { + //在向python环境中调用回调函数推送数据前,需要先获取全局锁GIL,防止解释器崩溃 + PyLock lock; + + //以下的try...catch...可以实现捕捉python环境中错误的功能,防止C++直接出现原因未知的崩溃 + try + { + this->get_override("onFrontConnected")(); + } + catch (error_already_set const &) + { + PyErr_Print(); + } + }; + + virtual void onFrontDisconnected(int i) + { + PyLock lock; + + try + { + this->get_override("onFrontDisconnected")(i); + } + catch (error_already_set const &) + { + PyErr_Print(); + } + }; + + virtual void onHeartBeatWarning(int i) + { + PyLock lock; + + try + { + this->get_override("onHeartBeatWarning")(i); + } + catch (error_already_set const &) + { + PyErr_Print(); + } + }; + + virtual void onRspError(dict error, int id, bool last) + { + PyLock lock; + + try + { + this->get_override("onRspError")(error, id, last); + } + catch (error_already_set const &) + { + PyErr_Print(); + } + }; + + virtual void onRspUserLogin(dict data, dict error, int id, bool last) + { + PyLock lock; + + try + { + this->get_override("onRspUserLogin")(data, error, id, last); + } + catch (error_already_set const &) + { + PyErr_Print(); + } + }; + + virtual void onRspUserLogout(dict data, dict error, int id, bool last) + { + PyLock lock; + + try + { + this->get_override("onRspUserLogout")(data, error, id, last); + } + catch (error_already_set const &) + { + PyErr_Print(); + } + }; + + virtual void onRspSubL2MarketData(dict data, dict error, int id, bool last) + { + PyLock lock; + + try + { + this->get_override("onRspSubL2MarketData")(data, error, id, last); + } + catch (error_already_set const &) + { + PyErr_Print(); + } + }; + + virtual void onRspUnSubL2MarketData(dict data, dict error, int id, bool last) + { + PyLock lock; + + try + { + this->get_override("onRspUnSubL2MarketData")(data, error, id, last); + } + catch (error_already_set const &) + { + PyErr_Print(); + } + }; + + virtual void onRspSubL2Index(dict data, dict error, int id, bool last) + { + PyLock lock; + + try + { + this->get_override("onRspSubL2Index")(data, error, id, last); + } + catch (error_already_set const &) + { + PyErr_Print(); + } + }; + + virtual void onRspUnSubL2Index(dict data, dict error, int id, bool last) + { + PyLock lock; + + try + { + this->get_override("onRspUnSubL2Index")(data, error, id, last); + } + catch (error_already_set const &) + { + PyErr_Print(); + } + }; + + virtual void onRtnL2MarketData(dict data) + { + PyLock lock; + + try + { + this->get_override("onRtnL2MarketData")(data); + } + catch (error_already_set const &) + { + PyErr_Print(); + } + }; + + virtual void onRtnL2Index(dict data) + { + PyLock lock; + + try + { + this->get_override("onRtnL2Index")(data); + } + catch (error_already_set const &) + { + PyErr_Print(); + } + }; + + virtual void onRspSubL2OrderAndTrade(dict error, int id, bool last) + { + PyLock lock; + + try + { + this->get_override("onRspSubL2OrderAndTrade")(error, id, last); + } + catch (error_already_set const &) + { + PyErr_Print(); + } + }; + + virtual void onRspUnSubL2OrderAndTrade(dict error, int id, bool last) + { + PyLock lock; + + try + { + this->get_override("onRspUnSubL2OrderAndTrade")(error, id, last); + } + catch (error_already_set const &) + { + PyErr_Print(); + } + }; + + virtual void onRtnL2Order(dict data) + { + PyLock lock; + + try + { + this->get_override("onRtnL2Order")(data); + } + catch (error_already_set const &) + { + PyErr_Print(); + } + }; + + virtual void onRtnL2Trade(dict data) + { + PyLock lock; + + try + { + this->get_override("onRtnL2Trade")(data); + } + catch (error_already_set const &) + { + PyErr_Print(); + } + }; + + virtual void onNtfCheckOrderList(string instrumentID, string functionCode) + { + PyLock lock; + + try + { + this->get_override("onNtfCheckOrderList")(instrumentID, functionCode); + } + catch (error_already_set const &) + { + PyErr_Print(); + } + }; +}; + + +BOOST_PYTHON_MODULE(vnltsl2) +{ + PyEval_InitThreads(); //导入时运行,保证先创建GIL + + class_("L2MdApi") + .def("createFtdcL2MDUserApi", &L2MdApiWrap::createFtdcL2MDUserApi) + .def("release", &L2MdApiWrap::release) + .def("init", &L2MdApiWrap::init) + .def("join", &L2MdApiWrap::join) + .def("exit", &L2MdApiWrap::exit) + .def("getTradingDay", &L2MdApiWrap::getTradingDay) + .def("registerFront", &L2MdApiWrap::registerFront) + .def("subscribeL2MarketData", &L2MdApiWrap::subscribeL2MarketData) + .def("unSubscribeL2MarketData", &L2MdApiWrap::unSubscribeL2MarketData) + .def("subscribeL2Index", &L2MdApiWrap::subscribeL2Index) + .def("unSubscribeL2Index", &L2MdApiWrap::unSubscribeL2Index) + .def("subscribeL2OrderAndTrade", &L2MdApiWrap::subscribeL2OrderAndTrade) + .def("unSubscribeL2OrderAndTrade", &L2MdApiWrap::unSubscribeL2OrderAndTrade) + .def("reqUserLogin", &L2MdApiWrap::reqUserLogin) + .def("reqUserLogout", &L2MdApiWrap::reqUserLogout) + + .def("onFrontConnected", pure_virtual(&L2MdApiWrap::onFrontConnected)) + .def("onFrontDisconnected", pure_virtual(&L2MdApiWrap::onFrontDisconnected)) + .def("onHeartBeatWarning", pure_virtual(&L2MdApiWrap::onHeartBeatWarning)) + .def("onRspError", pure_virtual(&L2MdApiWrap::onRspError)) + .def("onRspUserLogin", pure_virtual(&L2MdApiWrap::onRspUserLogin)) + .def("onRspUserLogout", pure_virtual(&L2MdApiWrap::onRspUserLogout)) + .def("onRspSubL2MarketData", pure_virtual(&L2MdApiWrap::onRspSubL2MarketData)) + .def("onRspUnSubL2MarketData", pure_virtual(&L2MdApiWrap::onRspUnSubL2MarketData)) + .def("onRspSubL2Index", pure_virtual(&L2MdApiWrap::onRspSubL2Index)) + .def("onRspUnSubL2Index", pure_virtual(&L2MdApiWrap::onRspUnSubL2Index)) + .def("onRtnL2MarketData", pure_virtual(&L2MdApiWrap::onRtnL2MarketData)) + .def("onRtnL2Index", pure_virtual(&L2MdApiWrap::onRtnL2Index)) + .def("onRspSubL2OrderAndTrade", pure_virtual(&L2MdApiWrap::onRspSubL2OrderAndTrade)) + .def("onRspUnSubL2OrderAndTrade", pure_virtual(&L2MdApiWrap::onRspUnSubL2OrderAndTrade)) + .def("onRtnL2Order", pure_virtual(&L2MdApiWrap::onRtnL2Order)) + .def("onRtnL2Trade", pure_virtual(&L2MdApiWrap::onRtnL2Trade)) + .def("onNtfCheckOrderList", pure_virtual(&L2MdApiWrap::onNtfCheckOrderList)) + ; +}; \ No newline at end of file diff --git a/vn.lts/vnltsl2/vnltsl2/vnltsl2.h b/vn.lts/vnltsl2/vnltsl2/vnltsl2.h new file mode 100644 index 00000000..827c2102 --- /dev/null +++ b/vn.lts/vnltsl2/vnltsl2/vnltsl2.h @@ -0,0 +1,347 @@ +//说明部分 + +//系统 +#include "stdafx.h" +#include +#include + +//Boost +#define BOOST_PYTHON_STATIC_LIB +#include //python封装 +#include //python封装 +#include //python封装 +#include //python封装 +#include //python封装 +#include //任务队列的线程功能 +#include //任务队列的线程功能 +#include //任务队列的任务实现 + +//API +#include "SecurityFtdcL2MDUserApi.h" +_USING_LTS_NS_ + +//命名空间 +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 ONRSPSUBL2MARKETDATA 7 +#define ONRSPUNSUBL2MARKETDATA 8 +#define ONRSPSUBL2INDEX 9 +#define ONRSPUNSUBL2INDEX 10 +#define ONRTNL2MARKETDATA 11 +#define ONRTNL2INDEX 12 +#define ONRSPSUBL2ORDERANDTRADE 13 +#define ONRSPUNSUBL2ORDERANDTRADE 14 +#define ONRTNL2ORDER 15 +#define ONRTNL2TRADE 16 +#define ONNTFCHECKORDERLIST 17 + + + +///------------------------------------------------------------------------------------- +///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 + +class ConcurrentQueue +{ +private: + queue 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 L2MdApi : public CSecurityFtdcL2MDUserSpi +{ +private: + CSecurityFtdcL2MDUserApi* api; //API对象 + thread *task_thread; //工作线程指针(向python中推送数据) + ConcurrentQueue task_queue; //任务队列 + +public: + L2MdApi() + { + function0 f = boost::bind(&L2MdApi::processTask, this); + thread t(f); + this->task_thread = &t; + }; + + ~L2MdApi() + { + }; + + //------------------------------------------------------------------------------------- + //API回调函数 + //------------------------------------------------------------------------------------- + + ///当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。 + virtual void OnFrontConnected(); + + ///当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。 + ///@param nReason 错误原因 + /// 0x1001 网络读失败 + /// 0x1002 网络写失败 + /// 0x2001 接收心跳超时 + /// 0x2002 发送心跳失败 + /// 0x2003 收到错误报文 + virtual void OnFrontDisconnected(int nReason); + + ///心跳超时警告 + virtual void OnHeartBeatWarning(int nTimeLapse); + + ///错误应答 + virtual void OnRspError(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) ; + + ///登录请求响应 + virtual void OnRspUserLogin(CSecurityFtdcUserLoginField *pUserLogin, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) ; + + ///登出请求响应 + virtual void OnRspUserLogout(CSecurityFtdcUserLogoutField *pUserLogout, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) ; + + ///订阅Level2行情应答 + virtual void OnRspSubL2MarketData(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) ; + + ///取消订阅Level2行情应答 + virtual void OnRspUnSubL2MarketData(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) ; + + ///订阅Level2指数行情应答 + virtual void OnRspSubL2Index(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) ; + + ///取消订阅Level2指数行情应答 + virtual void OnRspUnSubL2Index(CSecurityFtdcSpecificInstrumentField *pSpecificInstrument, CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) ; + + ///Level2行情通知 + virtual void OnRtnL2MarketData(CSecurityFtdcL2MarketDataField *pL2MarketData) ; + + ///Level2指数行情通知 + virtual void OnRtnL2Index(CSecurityFtdcL2IndexField *pL2Index) ; + + ///订阅逐笔委托及成交应答 + virtual void OnRspSubL2OrderAndTrade(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) ; + + ///取消订阅逐笔委托及成交应答 + virtual void OnRspUnSubL2OrderAndTrade(CSecurityFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) ; + + ///Level2委托通知 + virtual void OnRtnL2Order(CSecurityFtdcL2OrderField *pL2Order) ; + + ///Level2成交通知 + virtual void OnRtnL2Trade(CSecurityFtdcL2TradeField *pL2Trade) ; + + ///通知清理SSE买卖一队列中数量为0的报单 + virtual void OnNtfCheckOrderList(TSecurityFtdcInstrumentIDType InstrumentID, TSecurityFtdcFunctionCodeType FunctionCode) ; + + + //------------------------------------------------------------------------------------- + //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 processRspSubL2MarketData(Task task); + + void processRspUnSubL2MarketData(Task task); + + void processRspSubL2Index(Task task); + + void processRspUnSubL2Index(Task task); + + void processRtnL2MarketData(Task task); + + void processRtnL2Index(Task task); + + void processRspSubL2OrderAndTrade(Task task); + + void processRspUnSubL2OrderAndTrade(Task task); + + void processRtnL2Order(Task task); + + void processRtnL2Trade(Task task); + + void processNtfCheckOrderList(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 onRspSubL2MarketData(dict data, dict error, int id, bool last) {}; + + virtual void onRspUnSubL2MarketData(dict data, dict error, int id, bool last) {}; + + virtual void onRspSubL2Index(dict data, dict error, int id, bool last) {}; + + virtual void onRspUnSubL2Index(dict data, dict error, int id, bool last) {}; + + virtual void onRtnL2MarketData(dict data) {}; + + virtual void onRtnL2Index(dict data) {}; + + virtual void onRspSubL2OrderAndTrade(dict error, int id, bool last) {}; + + virtual void onRspUnSubL2OrderAndTrade(dict error, int id, bool last) {}; + + virtual void onRtnL2Order(dict data) {}; + + virtual void onRtnL2Trade(dict data) {}; + + virtual void onNtfCheckOrderList(string instrumentID, string functionCode) {}; + + + //------------------------------------------------------------------------------------- + //req:主动函数的请求字典 + //------------------------------------------------------------------------------------- + + void createFtdcL2MDUserApi(string pszFlowPath = ""); + + void release(); + + void init(); + + int join(); + + int exit(); + + string getTradingDay(); + + void registerFront(string pszFrontAddress); + + int subscribeL2MarketData(dict req); + + int unSubscribeL2MarketData(dict req); + + int subscribeL2Index(dict req); + + int unSubscribeL2Index(dict req); + + int subscribeL2OrderAndTrade(); + + int unSubscribeL2OrderAndTrade(); + + int reqUserLogin(dict req, int nRequestID); + + int reqUserLogout(dict req, int nRequestID); +}; +