1. 完成了金仕达黄金接口的封装

2. 将金仕达黄金接口对接上了vn.trader
3. 将vn.trader中的gateway放到独立文件夹下,程序结构更加清晰
This commit is contained in:
WOLF 2015-12-23 14:15:41 +08:00
parent e05fd91545
commit a5ac08cb2d
93 changed files with 6214 additions and 775 deletions

10
vn.ksgold/README.md Normal file
View File

@ -0,0 +1,10 @@
# vn.ksgold
金仕达黄金T+D接口浦发银行的Python封装需要把SLEdll文件夹复制到python.exe所在的文件夹下才可以使用。
本接口看起来和CTP类似很简单其实坑相当多
1. 有每秒最多5笔操作的流控作者测试似乎3笔就会触发流控同时似乎底层采用的是同步模式意味着如果用户调用委托函数遭遇流控限制则在委托等待的过程中当前线程会阻塞导致程序出现界面卡死的情况因为主线程被卡住了
2. OnRtnOrder返回的数据字段极少仅包括委托号和当前状态且仅在委托下达和委托撤销时会推送委托成交时没有推送需要用户自己结合OnRtnTrade的数据还原当前委托的最新状态
3. 登录后不提供当日历史成交和委托的主动推送需要用户自行查询查询还有流控1秒/次)
如果打算自己开发建议参考vn.trader里的ksgoldGateway可以少踩点坑。

View File

@ -40,6 +40,32 @@
#define BUY '0' //Âò
#define SELL '1' //Âô
//委托类型
#define SPOT_ENTRUST '0' //现货
#define TN_ENTRUST '4' //现货T+N
#define DEFER_ENTRUST '1' //现货延期
#define DELIVERY_ENTRUST '2' //交割
#define MIDDLE_ENTRUST '3' //中立仓
//渠道类型
#define COUNTER_CHANNEL '1' //柜台
#define TEL_CHANNEL '2' //电话银行
#define NET_CHANNEL '3' //网银
#define TRADER_CHANNEL '4' //交易员
#define SELF_CHANNEL '5' //自助终端
#define PHONE_CHANNEL '6' //手机银行
#define TRADEAPI_CHANNEL '7' //交易API
//客户类别
#define CLIENT_SPOT '0' //现货
#define CLIENT_FUTURE '1' //期货
#define CLIENT_GENERAL '2' //通用
//登录类型
#define BANKACC_TYPE "1" //银行账号登录
#define TRADECODE_TYPE "2" //交易编码登录
//活跃标志
#define ACTIVITY_ON '1' //询价合约
#endif _NEWCONSTANT_H

View File

@ -18,6 +18,7 @@
class CGoldTradeSpi //回调接口
{
public:
virtual ~CGoldTradeSpi(){};
//连接建立通知
virtual void OnFrontConnected(){};
@ -48,10 +49,10 @@ class CGoldTradeSpi //
virtual void OnErrRtnOrderInsert(CThostFtdcInputOrderField *pInputOrder, CThostFtdcRspInfoField *pRspInfo) {};
///报单通知
virtual void OnRtnOrder(CThostFtdcOrderField *pOrder) {};
virtual void OnRtnOrder(CThostFtdcOrderRtnField *pOrder) {};
//强退通知
virtual void OnForceLogout(CThostFtdcUserLogoutField *pLogout) {};
virtual void OnForceLogout(CThostFtdcUserLogoutField *pLogout) {};
//撤单应答
///报单操作请求响应(二级系统返回包含了错误编码和错误消息)

Binary file not shown.

Binary file not shown.

View File

@ -20,68 +20,26 @@ struct CThostFtdcReqUserLoginField
TThostFtdcMemberIDType memberID; //会员代码
TThostFtdcPasswordType password; //密码
TThostFtdcDateType tradeDate; //交易日期
TThostFtdcIPAddressType ipGatewayAddress; //连接网关所在的IP
TThostFtdcServerPortType portGateway; //连接网关所用端口
TThostFtdcOrderRefType localOrderNo; //最大本地报单号
TThostFtdcMachineIDType machineID; //前置机编号
TThostFtdcLoginBatchType loginbatch; //登录批次
TThostFtdcCSRCInvestorNameType clientName; //客户名称
TThostFtdcIPAddressType lastLoginIp; //上次登录IP地址
TThostFtdcDateType lastLoginDate; //上次登录日期
TThostFtdcTimeType lastLoginTime; //上次登录时间
TThostFtdcGateWayCurLinkNumType gateWayCurLinkNum; //网关当前的连接数量
TThostFtdcGateWayYYBDBType gateWayYYBDB; //网关的营业部代码
TThostFtdcObligateType obligate; //预留字段
TThostFtdcMSGType msg; //消息
};
///用户登录应答
struct CThostFtdcRspUserLoginField
{
TThostFtdcTraderIDType traderID; //交易员代码
TThostFtdcMemberIDType memberID; //会员代码
TThostFtdcPasswordType password; //密码
TThostFtdcDateType tradeDate; //交易日期
TThostFtdcIPAddressType ipAddress; //IP地址
TThostFtdcOrderRefType localOrderNo; //最大本地报单号
TThostFtdcMachineIDType machineID; //前置机编号
TThostFtdcLoginBatchType loginbatch; //登录批次
TThostFtdcCSRCInvestorNameType clientName; //客户名称
TThostFtdcOrderRefType localOrderNo; //最大本地报单号
TThostFtdcLoginBatchType loginbatch; //登录批次
TThostFtdcClientIDType tradeCode; //交易编码
TThostFtdcClientIDType clientID; //客户号
TThostFtdcSeatIDType SeatNo ; //席位号
TThostFtdcCSRCInvestorNameType clientName; //客户名称
TThostFtdcIPAddressType lastLoginIp; //上次登录IP地址
TThostFtdcDateType lastLoginDate; //上次登录日期
TThostFtdcTimeType lastLoginTime; //上次登录时间
TThostFtdcGateWayCurLinkNumType gateWayCurLinkNum; //网关当前的连接数量
TThostFtdcGateWayYYBDBType gateWayYYBDB; //网关的营业部代码
TThostFtdcObligateType obligate; //预留字段
TThostFtdcMSGType msg; //消息
TThostFtdcSeatIDType SeatNo ; //席位号
TThostFtdcClientIDType tradeCode; //交易编码 是
TThostFtdcClientIDType clientID; //客户号 是
};
///用户登出请求
struct CThostFtdcUserLogoutField
{
TThostFtdcTraderIDType traderID; //交易员代码
TThostFtdcMemberIDType memberID; //会员代码
TThostFtdcPasswordType password; //密码
TThostFtdcDateType tradeDate; //交易日期
TThostFtdcIPAddressType ipAddress; //IP地址
TThostFtdcOrderRefType localOrderNo; //最大本地报单号
TThostFtdcMachineIDType machineID; //前置机编号
TThostFtdcLoginBatchType loginbatch; //登录批次
TThostFtdcCSRCInvestorNameType clientName; //客户名称
TThostFtdcIPAddressType lastLoginIp; //上次登录IP地址
TThostFtdcDateType lastLoginDate; //上次登录日期
TThostFtdcTimeType lastLoginTime; //上次登录时间
TThostFtdcGateWayCurLinkNumType gateWayCurLinkNum; //网关当前的连接数量
TThostFtdcGateWayYYBDBType gateWayYYBDB; //网关的营业部代码
TThostFtdcObligateType obligate; //预留字段
TThostFtdcMSGType msg; //消息
TThostFtdcTraderIDType traderID; //客户号
};
@ -111,13 +69,7 @@ struct CThostFtdcInstrumentField
//查询资金账户
struct CThostFtdcQryTradingAccountField
{
TThostFtdcMemberIDType memberID; //会员代码
TThostFtdcAccountType accountType; //帐户类型
TThostFtdcTraderIDType traderID; //交易员代码
TThostFtdcClientIDType clientID; //客户代码
TThostFtdcMarketIDType marketID; //市场代码
TThostFtdcMSGType remian; //保留字段
};
///资金账户
@ -146,9 +98,6 @@ struct CThostFtdcTradingAccountField
///投资者持仓
struct CThostFtdcInvestorPositionField
{
TThostFtdcClientIDType clientID; //1 客户号 是
//2 预留位 是
//3 预留位 是
TThostFtdcInstrumentIDType instID; //4 合约代码 是
TThostFtdcVolumeType longPosi; //5 可用买持仓量 是
TThostFtdcPriceType longPosiAvgPrice; //6 买持均价 是
@ -205,14 +154,14 @@ struct CThostFtdcDepthMarketDataField
TThostFtdcVolumeType BidLot3 ; /**<最高买量三 */
TThostFtdcPriceType Ask3 ; /**<最低卖价三 */
TThostFtdcVolumeType AskLot3 ; /**<最低卖量三 */
TThostFtdcPriceType Bid4 ; /**<最高买价 */
TThostFtdcVolumeType BidLot4 ; /**<最高买量 */
TThostFtdcPriceType Ask4 ; /**<最低卖价 */
TThostFtdcVolumeType AskLot4 ; /**<最低卖量 */
TThostFtdcPriceType Bid5 ; /**<最高买价 */
TThostFtdcVolumeType BidLot5 ; /**<最高买量 */
TThostFtdcPriceType Ask5 ; /**<最低卖价 */
TThostFtdcVolumeType AskLot5 ; /**<最低卖量 */
TThostFtdcPriceType Bid4 ; /**<最高买价 */
TThostFtdcVolumeType BidLot4 ; /**<最高买量 */
TThostFtdcPriceType Ask4 ; /**<最低卖价 */
TThostFtdcVolumeType AskLot4 ; /**<最低卖量 */
TThostFtdcPriceType Bid5 ; /**<最高买价 */
TThostFtdcVolumeType BidLot5 ; /**<最高买量 */
TThostFtdcPriceType Ask5 ; /**<最低卖价 */
TThostFtdcVolumeType AskLot5 ; /**<最低卖量 */
TThostFtdcVolumeType Volume ; /**<成交量(双边) */
TThostFtdcVolumeType OpenInt ; /**<持仓量(双边) */
TThostFtdcPriceType UpDown ; /**<涨跌 */
@ -234,39 +183,23 @@ struct CThostFtdcDepthMarketDataField
struct CThostFtdcInputOrderField
{
TThostFtdcSeatIDType seatID; //2 席位号 是
TThostFtdcClientIDType clientID; //3 交易编码 是
TThostFtdcExchangeIDType exchangeID; //4 交易所代码 是
TThostFtdcClientIDType tradeCode; //3 交易编码 是
TThostFtdcInstrumentIDType instID; //5 品种代码 是
TThostFtdcBsFlagType buyOrSell; //6 买卖方向 是
TThostFtdcBsFlagType buyOrSell; //6 买卖方向 是
TThostFtdcOffsetFlagType offsetFlag; //7 开平标志 是
TThostFtdcVolumeType amount; //8 委托数量 是
TThostFtdcWeightType weight; //10 委托重量 是 常量为0
TThostFtdcByteType middleFlag; //9 中立仓标志 是 常量为0
TThostFtdcByteType orderFlag; //10 委托标志 是
TThostFtdcByteType middleFlag; //9 中立仓标志 是 常量为0
TThostFtdcByteType priceFlag; //11 条件委托价格类型 是
TThostFtdcPriceType price; //12 预委托价格 是
TThostFtdcPriceType trigPrice; //13 预委托触发价格 是
TThostFtdcMarketIDType marketID; //14 市场代码 是
TThostFtdcDateType validDate; //15 有效日期 是
TThostFtdcOrderNoType orderNo; //1 系统报单号 是
TThostFtdcOrderRefType LocalOrderNo;//本地报单号
TThostFtdcVolumeType matchQty; //12 成交手数 是
TThostFtdcWeightType matchWeight; //13 成交重量 是
TThostFtdcOrderStatusType status; //14 委托状态 是
TThostFtdcTimeType entrustTime; //15 委托时间 是
TThostFtdcByteType forceoffset_flag; //16 强平标志 是
TThostFtdcVolumeType cancelQty; //17 撤单手数 是
TThostFtdcTimeType cancelTime; //18撤单时间
TThostFtdcVolumnCheck volumnCheck; //数量检查标志
TThostFtdcTradeWayType tradeWay; //19 交易渠道 是
TThostFtdcOrderRefType LocalOrderNo; // 本地报单号
TThostFtdcTradeWayType tradeWay; //19 交易渠道 是
};
///报单
struct CThostFtdcOrderField
{
TThostFtdcOrderNoType orderNo; //1 系统报单号 是
TThostFtdcOrderRefType localOrderNo;; //2 本地报单号 是
TThostFtdcMarketIDType marketID; //4 市场代码 是
@ -284,19 +217,24 @@ struct CThostFtdcOrderField
TThostFtdcVolumeType cancelQty; //17 撤单手数 是
TThostFtdcTimeType cancelTime; //18撤单时间
TThostFtdcTradeWayType tradeWay; //19 交易渠道 是
};
///报单撤单回报
struct CThostFtdcOrderRtnField
{
TThostFtdcOrderNoType orderNo; //1 系统报单号 是
TThostFtdcOrderRefType localOrderNo;; //2 本地报单号 是
TThostFtdcOrderStatusType status; //14 委托状态 是
TThostFtdcVolumeType cancelQty; //17 撤单手数 是
};
///输入报单操作(cancel order)
struct CThostFtdcInputOrderActionField
{
TThostFtdcOrderRefType localOrderNo; //1 本地报单号 是
TThostFtdcByteType orderFlag; //2 委托标志 是
TThostFtdcMarketIDType marketID; //3 市场代码 是
TThostFtdcTraderIDType traderID; //6 撤单操作员 是
TThostFtdcTradeWayType tradeWay; //7 委托渠道 是 写死"5"
TThostFtdcOrderRefType localOrderNo; //1 本地报单号 是
TThostFtdcMarketIDType marketID; //2 市场代码 是
TThostFtdcOrderStatusType status; //14 委托状态
};
///报单操作
@ -313,7 +251,6 @@ struct CThostFtdcOrderActionField
///成交
struct CThostFtdcTradeField
{
TThostFtdcOrderNoType orderNo; //1 系统报单号 是
TThostFtdcMatchNoType matchNo; //2 成交单编号 是
TThostFtdcInstrumentIDType instID; //3 合约代码 是
@ -330,10 +267,8 @@ struct CThostFtdcTradeField
TThostFtdcMarketIDType marketID; //15 市场代码 是
TThostFtdcMoneyType trade_fee; //16 手续费 是
TThostFtdcByteType forceoffset_flag; //17 强平标志 是
TThostFtdcVolumeType forcebatchnum ; //18 强平批次号 是
TThostFtdcTradeWayType tradeWay; //19 渠道标志 是
TThostFtdcVolumeType forcebatchnum ; //18 强平批次号 是
TThostFtdcTradeWayType tradeWay; //渠道标志
};
///查询合约
@ -349,17 +284,10 @@ struct CThostFtdcQryInstrumentField
///查询成交
struct CThostFtdcQryTradeField
{
TThostFtdcMatchNoType matchNo; //成交编号
TThostFtdcInstrumentIDType instID; //合约代码
TThostFtdcMarketIDType marketID; //市场代码
TThostFtdcOrderNoType orderNo; //报单号
TThostFtdcClientIDType clientID; //客户代码
TThostFtdcMemberIDType memberID; //会员代码
TThostFtdcMatchNoType matchNo; //成交编号
TThostFtdcExchangeIDType exchangeID; //交易所代码(wph)
TThostFtdcOrderRefType localOrderNo; //本地报单编号
TThostFtdcTraderIDType traderID; //交易员代码(wph)
TThostFtdcOrderRefType localOrderNo; //本地报单编号
};
@ -368,16 +296,7 @@ struct CThostFtdcQryOrderField
{
TThostFtdcInstrumentIDType instID; //合约代码
TThostFtdcMarketIDType marketID; //市场代码
TThostFtdcOrderNoType orderNo; //报单号
TThostFtdcClientIDType clientID; //客户代码
TThostFtdcMemberIDType memberID; //会员代码
TThostFtdcOffsetFlagType offsetFlag; //开平标志
TThostFtdcTraderIDType traderID; //交易员代码(wph)
TThostFtdcOrderStatusType status; //状态
TThostFtdcExchangeIDType exchangeID; //交易所代码(wph)
TThostFtdcOrderRefType localOrderNo; //本地报单编号
TThostFtdcOrderRefType localOrderNo; //本地报单编号
};
@ -386,21 +305,15 @@ struct CThostFtdcQryOrderField
///查询投资者持仓
struct CThostFtdcQryInvestorPositionField
{
TThostFtdcClientIDType clientID; //客户代码
TThostFtdcMemberIDType memberID; //会员代码
TThostFtdcMarketIDType marketID; //市场代码
TThostFtdcInstrumentIDType instID; //合约代码
TThostFtdcTraderIDType traderID; //交易员代码(wph)
TThostFtdcMarketIDType marketID; //市场代码
TThostFtdcInstrumentIDType instID; //合约代码
};
///查询库存
struct CThostFtdcQryStorageField
{
TThostFtdcClientIDType clientID; //客户代码
TThostFtdcMemberIDType memberID; //会员代码
TThostFtdcTraderIDType traderID; //交易员代码(wph)
TThostFtdcVarietyIDType varietyID; //交割品种代码
};
//库存应答
@ -422,20 +335,18 @@ struct CThostFtdcStorageField
TThostFtdcWeightType lawFrozen; //17 法律冻结库存 是
TThostFtdcWeightType bankFrozen; //18 银行冻结库存 是
TThostFtdcByteType customType; //19 客户类别 是
TThostFtdcWeightType storageCost; //20 库存成本 是
TThostFtdcWeightType storageCost; //20 库存成本 是
TThostFtdcWeightType impawnFrozen ; //22 质押冻结库存 是
};
//市场状态
//市场状态
struct CThostFtdcMarketStatusField
{
TThostFtdcMktStatusType MktStatus; /*市场状态*/
TThostFtdcMarketIDType marketID ; /*市场代码*/
TThostFtdcExchCodeType ExchCode; /*交易所代码*/
TThostFtdcMktChgTimeType MktChgTime; /*状态触发时间*/
//TThostFtdcExchCodeType ExchCode; /*交易所代码*/
//TThostFtdcMktChgTimeType MktChgTime; /*状态触发时间*/
};
///指定的合约

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -18,6 +18,7 @@
class CGoldTradeSpi //回调接口
{
public:
virtual ~CGoldTradeSpi(){};
//连接建立通知
virtual void OnFrontConnected(){};
@ -48,7 +49,7 @@ class CGoldTradeSpi //
virtual void OnErrRtnOrderInsert(CThostFtdcInputOrderField *pInputOrder, CThostFtdcRspInfoField *pRspInfo) {};
///报单通知
virtual void OnRtnOrder(CThostFtdcOrderField *pOrder) {};
virtual void OnRtnOrder(CThostFtdcOrderRtnField *pOrder) {};
//强退通知
virtual void OnForceLogout(CThostFtdcUserLogoutField *pLogout) {};

View File

@ -20,63 +20,26 @@ struct CThostFtdcReqUserLoginField
TThostFtdcMemberIDType memberID; //会员代码
TThostFtdcPasswordType password; //密码
TThostFtdcDateType tradeDate; //交易日期
TThostFtdcIPAddressType ipGatewayAddress; //连接网关所在的IP
TThostFtdcServerPortType portGateway; //连接网关所用端口
TThostFtdcOrderRefType localOrderNo; //最大本地报单号
TThostFtdcMachineIDType machineID; //前置机编号
TThostFtdcLoginBatchType loginbatch; //登录批次
TThostFtdcCSRCInvestorNameType clientName; //客户名称
TThostFtdcIPAddressType lastLoginIp; //上次登录IP地址
TThostFtdcDateType lastLoginDate; //上次登录日期
TThostFtdcTimeType lastLoginTime; //上次登录时间
TThostFtdcGateWayCurLinkNumType gateWayCurLinkNum; //网关当前的连接数量
TThostFtdcGateWayYYBDBType gateWayYYBDB; //网关的营业部代码
TThostFtdcObligateType obligate; //预留字段
TThostFtdcMSGType msg; //消息
};
///用户登录应答
struct CThostFtdcRspUserLoginField
{
TThostFtdcTraderIDType traderID; //交易员代码
TThostFtdcMemberIDType memberID; //会员代码
TThostFtdcPasswordType password; //密码
TThostFtdcDateType tradeDate; //交易日期
TThostFtdcIPAddressType ipAddress; //IP地址
TThostFtdcOrderRefType localOrderNo; //最大本地报单号
TThostFtdcMachineIDType machineID; //前置机编号
TThostFtdcLoginBatchType loginbatch; //登录批次
TThostFtdcCSRCInvestorNameType clientName; //客户名称
TThostFtdcOrderRefType localOrderNo; //最大本地报单号
TThostFtdcLoginBatchType loginbatch; //登录批次
TThostFtdcClientIDType tradeCode; //交易编码
TThostFtdcClientIDType clientID; //客户号
TThostFtdcSeatIDType SeatNo ; //席位号
TThostFtdcCSRCInvestorNameType clientName; //客户名称
TThostFtdcIPAddressType lastLoginIp; //上次登录IP地址
TThostFtdcDateType lastLoginDate; //上次登录日期
TThostFtdcTimeType lastLoginTime; //上次登录时间
TThostFtdcGateWayCurLinkNumType gateWayCurLinkNum; //网关当前的连接数量
TThostFtdcGateWayYYBDBType gateWayYYBDB; //网关的营业部代码
TThostFtdcObligateType obligate; //预留字段
TThostFtdcMSGType msg; //消息
TThostFtdcSeatIDType SeatNo ; //席位号
TThostFtdcClientIDType tradeCode; //交易编码 是
TThostFtdcClientIDType clientID; //客户号 是
};
///用户登出请求
struct CThostFtdcUserLogoutField
{
TThostFtdcTraderIDType traderID; //交易员代码
TThostFtdcMemberIDType memberID; //会员代码
TThostFtdcPasswordType password; //密码
TThostFtdcDateType tradeDate; //交易日期
TThostFtdcIPAddressType ipAddress; //IP地址
TThostFtdcOrderRefType localOrderNo; //最大本地报单号
TThostFtdcMachineIDType machineID; //前置机编号
TThostFtdcLoginBatchType loginbatch; //登录批次
TThostFtdcCSRCInvestorNameType clientName; //客户名称
TThostFtdcIPAddressType lastLoginIp; //上次登录IP地址
TThostFtdcDateType lastLoginDate; //上次登录日期
TThostFtdcTimeType lastLoginTime; //上次登录时间
TThostFtdcGateWayCurLinkNumType gateWayCurLinkNum; //网关当前的连接数量
TThostFtdcGateWayYYBDBType gateWayYYBDB; //网关的营业部代码
TThostFtdcObligateType obligate; //预留字段
TThostFtdcMSGType msg; //消息
TThostFtdcTraderIDType traderID; //客户号
};
@ -105,11 +68,7 @@ struct CThostFtdcInstrumentField
//查询资金账户
struct CThostFtdcQryTradingAccountField
{
TThostFtdcMemberIDType memberID; //会员代码
TThostFtdcAccountType accountType; //帐户类型
TThostFtdcTraderIDType traderID; //交易员代码
TThostFtdcClientIDType clientID; //客户代码
TThostFtdcMarketIDType marketID; //市场代码
TThostFtdcMSGType remian; //保留字段
};
///资金账户
@ -136,7 +95,6 @@ struct CThostFtdcTradingAccountField
///投资者持仓
struct CThostFtdcInvestorPositionField
{
TThostFtdcClientIDType clientID; //1 客户号 是
TThostFtdcInstrumentIDType instID; //4 合约代码 是
TThostFtdcVolumeType longPosi; //5 可用买持仓量 是
TThostFtdcPriceType longPosiAvgPrice; //6 买持均价 是
@ -191,14 +149,14 @@ struct CThostFtdcDepthMarketDataField
TThostFtdcVolumeType BidLot3 ; /**<最高买量三 */
TThostFtdcPriceType Ask3 ; /**<最低卖价三 */
TThostFtdcVolumeType AskLot3 ; /**<最低卖量三 */
TThostFtdcPriceType Bid4 ; /**<最高买价 */
TThostFtdcVolumeType BidLot4 ; /**<最高买量 */
TThostFtdcPriceType Ask4 ; /**<最低卖价 */
TThostFtdcVolumeType AskLot4 ; /**<最低卖量 */
TThostFtdcPriceType Bid5 ; /**<最高买价 */
TThostFtdcVolumeType BidLot5 ; /**<最高买量 */
TThostFtdcPriceType Ask5 ; /**<最低卖价 */
TThostFtdcVolumeType AskLot5 ; /**<最低卖量 */
TThostFtdcPriceType Bid4 ; /**<最高买价 */
TThostFtdcVolumeType BidLot4 ; /**<最高买量 */
TThostFtdcPriceType Ask4 ; /**<最低卖价 */
TThostFtdcVolumeType AskLot4 ; /**<最低卖量 */
TThostFtdcPriceType Bid5 ; /**<最高买价 */
TThostFtdcVolumeType BidLot5 ; /**<最高买量 */
TThostFtdcPriceType Ask5 ; /**<最低卖价 */
TThostFtdcVolumeType AskLot5 ; /**<最低卖量 */
TThostFtdcVolumeType Volume ; /**<成交量(双边) */
TThostFtdcVolumeType OpenInt ; /**<持仓量(双边) */
TThostFtdcPriceType UpDown ; /**<涨跌 */
@ -218,37 +176,23 @@ struct CThostFtdcDepthMarketDataField
struct CThostFtdcInputOrderField
{
TThostFtdcSeatIDType seatID; //2 席位号 是
TThostFtdcClientIDType clientID; //3 交易编码 是
TThostFtdcExchangeIDType exchangeID; //4 交易所代码 是
TThostFtdcClientIDType tradeCode; //3 交易编码 是
TThostFtdcInstrumentIDType instID; //5 品种代码 是
TThostFtdcBsFlagType buyOrSell; //6 买卖方向 是
TThostFtdcBsFlagType buyOrSell; //6 买卖方向 是
TThostFtdcOffsetFlagType offsetFlag; //7 开平标志 是
TThostFtdcVolumeType amount; //8 委托数量 是
TThostFtdcWeightType weight; //10 委托重量 是 常量为0
TThostFtdcByteType middleFlag; //9 中立仓标志 是 常量为0
TThostFtdcByteType orderFlag; //10 委托标志 是
TThostFtdcByteType middleFlag; //9 中立仓标志 是 常量为0
TThostFtdcByteType priceFlag; //11 条件委托价格类型 是
TThostFtdcPriceType price; //12 预委托价格 是
TThostFtdcPriceType trigPrice; //13 预委托触发价格 是
TThostFtdcMarketIDType marketID; //14 市场代码 是
TThostFtdcDateType validDate; //15 有效日期 是
TThostFtdcOrderNoType orderNo; //1 系统报单号 是
TThostFtdcOrderRefType LocalOrderNo;//本地报单号
TThostFtdcVolumeType matchQty; //12 成交手数 是
TThostFtdcWeightType matchWeight; //13 成交重量 是
TThostFtdcOrderStatusType status; //14 委托状态 是
TThostFtdcTimeType entrustTime; //15 委托时间 是
TThostFtdcByteType forceoffset_flag; //16 强平标志 是
TThostFtdcVolumeType cancelQty; //17 撤单手数 是
TThostFtdcTimeType cancelTime; //18撤单时间
TThostFtdcVolumnCheck volumnCheck; //数量检查标志
TThostFtdcTradeWayType tradeWay; //19 交易渠道 是
TThostFtdcOrderRefType LocalOrderNo; // 本地报单号
TThostFtdcTradeWayType tradeWay; //19 交易渠道 是
};
///报单
struct CThostFtdcOrderField
{
TThostFtdcOrderNoType orderNo; //1 系统报单号 是
TThostFtdcOrderRefType localOrderNo;; //2 本地报单号 是
TThostFtdcMarketIDType marketID; //4 市场代码 是
@ -268,15 +212,22 @@ struct CThostFtdcOrderField
TThostFtdcTradeWayType tradeWay; //19 交易渠道 是
};
///报单撤单回报
struct CThostFtdcOrderRtnField
{
TThostFtdcOrderNoType orderNo; //1 系统报单号 是
TThostFtdcOrderRefType localOrderNo;; //2 本地报单号 是
TThostFtdcOrderStatusType status; //14 委托状态 是
TThostFtdcVolumeType cancelQty; //17 撤单手数 是
};
///输入报单操作(cancel order)
struct CThostFtdcInputOrderActionField
{
TThostFtdcOrderRefType localOrderNo; //1 本地报单号 是
TThostFtdcByteType orderFlag; //2 委托标志 是
TThostFtdcMarketIDType marketID; //3 市场代码 是
TThostFtdcTraderIDType traderID; //6 撤单操作员 是
TThostFtdcTradeWayType tradeWay; //7 委托渠道 是 写死"5"
TThostFtdcOrderRefType localOrderNo; //1 本地报单号 是
TThostFtdcMarketIDType marketID; //2 市场代码 是
TThostFtdcOrderStatusType status; //14 委托状态
};
///报单操作
@ -291,7 +242,6 @@ struct CThostFtdcOrderActionField
///成交
struct CThostFtdcTradeField
{
TThostFtdcOrderNoType orderNo; //1 系统报单号 是
TThostFtdcMatchNoType matchNo; //2 成交单编号 是
TThostFtdcInstrumentIDType instID; //3 合约代码 是
@ -308,8 +258,8 @@ struct CThostFtdcTradeField
TThostFtdcMarketIDType marketID; //15 市场代码 是
TThostFtdcMoneyType trade_fee; //16 手续费 是
TThostFtdcByteType forceoffset_flag; //17 强平标志 是
TThostFtdcVolumeType forcebatchnum ; //18 强平批次号 是
TThostFtdcTradeWayType tradeWay; //19 渠道标志
TThostFtdcVolumeType forcebatchnum ; //18 强平批次号 是
TThostFtdcTradeWayType tradeWay; //渠道标志
};
///查询合约
@ -323,15 +273,10 @@ struct CThostFtdcQryInstrumentField
///查询成交
struct CThostFtdcQryTradeField
{
TThostFtdcMatchNoType matchNo; //成交编号
TThostFtdcInstrumentIDType instID; //合约代码
TThostFtdcMarketIDType marketID; //市场代码
TThostFtdcOrderNoType orderNo; //报单号
TThostFtdcClientIDType clientID; //客户代码
TThostFtdcMemberIDType memberID; //会员代码
TThostFtdcMatchNoType matchNo; //成交编号
TThostFtdcExchangeIDType exchangeID; //交易所代码(wph)
TThostFtdcOrderRefType localOrderNo; //本地报单编号
TThostFtdcTraderIDType traderID; //交易员代码(wph)
TThostFtdcOrderRefType localOrderNo; //本地报单编号
};
@ -340,14 +285,7 @@ struct CThostFtdcQryOrderField
{
TThostFtdcInstrumentIDType instID; //合约代码
TThostFtdcMarketIDType marketID; //市场代码
TThostFtdcOrderNoType orderNo; //报单号
TThostFtdcClientIDType clientID; //客户代码
TThostFtdcMemberIDType memberID; //会员代码
TThostFtdcOffsetFlagType offsetFlag; //开平标志
TThostFtdcTraderIDType traderID; //交易员代码(wph)
TThostFtdcOrderStatusType status; //状态
TThostFtdcExchangeIDType exchangeID; //交易所代码(wph)
TThostFtdcOrderRefType localOrderNo; //本地报单编号
TThostFtdcOrderRefType localOrderNo; //本地报单编号
};
@ -356,20 +294,15 @@ struct CThostFtdcQryOrderField
///查询投资者持仓
struct CThostFtdcQryInvestorPositionField
{
TThostFtdcClientIDType clientID; //客户代码
TThostFtdcMemberIDType memberID; //会员代码
TThostFtdcMarketIDType marketID; //市场代码
TThostFtdcInstrumentIDType instID; //合约代码
TThostFtdcTraderIDType traderID; //交易员代码(wph)
TThostFtdcMarketIDType marketID; //市场代码
TThostFtdcInstrumentIDType instID; //合约代码
};
///查询库存
struct CThostFtdcQryStorageField
{
TThostFtdcClientIDType clientID; //客户代码
TThostFtdcMemberIDType memberID; //会员代码
TThostFtdcTraderIDType traderID; //交易员代码(wph)
TThostFtdcVarietyIDType varietyID; //交割品种代码
};
//库存应答
@ -391,19 +324,15 @@ struct CThostFtdcStorageField
TThostFtdcWeightType lawFrozen; //17 法律冻结库存 是
TThostFtdcWeightType bankFrozen; //18 银行冻结库存 是
TThostFtdcByteType customType; //19 客户类别 是
TThostFtdcWeightType storageCost; //20 库存成本 是
TThostFtdcWeightType impawnFrozen ; //22 质押冻结库存 是
TThostFtdcWeightType storageCost; //20 库存成本 是
TThostFtdcWeightType impawnFrozen; //22 质押冻结库存 是
};
//市场状态
//市场状态
struct CThostFtdcMarketStatusField
{
TThostFtdcMktStatusType MktStatus; /*市场状态*/
TThostFtdcMarketIDType marketID ; /*市场代码*/
TThostFtdcExchCodeType ExchCode; /*交易所代码*/
TThostFtdcMktChgTimeType MktChgTime; /*状态触发时间*/
TThostFtdcMarketIDType marketID; /*市场代码*/
};
///指定的合约
struct CThostFtdcSpecificInstrumentField

View File

@ -22,63 +22,26 @@ CThostFtdcReqUserLoginField["loginType"] = "int"
CThostFtdcReqUserLoginField["memberID"] = "string"
CThostFtdcReqUserLoginField["password"] = "string"
CThostFtdcReqUserLoginField["tradeDate"] = "string"
CThostFtdcReqUserLoginField["ipGatewayAddress"] = "string"
CThostFtdcReqUserLoginField["portGateway"] = "int"
CThostFtdcReqUserLoginField["localOrderNo"] = "string"
CThostFtdcReqUserLoginField["machineID"] = "int"
CThostFtdcReqUserLoginField["loginbatch"] = "int"
CThostFtdcReqUserLoginField["clientName"] = "string"
CThostFtdcReqUserLoginField["lastLoginIp"] = "string"
CThostFtdcReqUserLoginField["lastLoginDate"] = "string"
CThostFtdcReqUserLoginField["lastLoginTime"] = "string"
CThostFtdcReqUserLoginField["gateWayCurLinkNum"] = "int"
CThostFtdcReqUserLoginField["gateWayYYBDB"] = "string"
CThostFtdcReqUserLoginField["obligate"] = "string"
CThostFtdcReqUserLoginField["msg"] = "string"
structDict['CThostFtdcReqUserLoginField'] = CThostFtdcReqUserLoginField
#用户登录应答
CThostFtdcRspUserLoginField = {}
CThostFtdcRspUserLoginField["traderID"] = "string"
CThostFtdcRspUserLoginField["memberID"] = "string"
CThostFtdcRspUserLoginField["password"] = "string"
CThostFtdcRspUserLoginField["tradeDate"] = "string"
CThostFtdcRspUserLoginField["ipAddress"] = "string"
CThostFtdcRspUserLoginField["localOrderNo"] = "string"
CThostFtdcRspUserLoginField["machineID"] = "int"
CThostFtdcRspUserLoginField["loginbatch"] = "int"
CThostFtdcRspUserLoginField["tradeCode"] = "string"
CThostFtdcRspUserLoginField["clientID"] = "string"
CThostFtdcRspUserLoginField["SeatNo"] = "string"
CThostFtdcRspUserLoginField["clientName"] = "string"
CThostFtdcRspUserLoginField["lastLoginIp"] = "string"
CThostFtdcRspUserLoginField["lastLoginDate"] = "string"
CThostFtdcRspUserLoginField["lastLoginTime"] = "string"
CThostFtdcRspUserLoginField["gateWayCurLinkNum"] = "int"
CThostFtdcRspUserLoginField["gateWayYYBDB"] = "string"
CThostFtdcRspUserLoginField["obligate"] = "string"
CThostFtdcRspUserLoginField["msg"] = "string"
CThostFtdcRspUserLoginField["SeatNo"] = "string"
CThostFtdcRspUserLoginField["tradeCode"] = "string"
CThostFtdcRspUserLoginField["clientID"] = "string"
structDict['CThostFtdcRspUserLoginField'] = CThostFtdcRspUserLoginField
#用户登出请求
CThostFtdcUserLogoutField = {}
CThostFtdcUserLogoutField["traderID"] = "string"
CThostFtdcUserLogoutField["memberID"] = "string"
CThostFtdcUserLogoutField["password"] = "string"
CThostFtdcUserLogoutField["tradeDate"] = "string"
CThostFtdcUserLogoutField["ipAddress"] = "string"
CThostFtdcUserLogoutField["localOrderNo"] = "string"
CThostFtdcUserLogoutField["machineID"] = "int"
CThostFtdcUserLogoutField["loginbatch"] = "int"
CThostFtdcUserLogoutField["clientName"] = "string"
CThostFtdcUserLogoutField["lastLoginIp"] = "string"
CThostFtdcUserLogoutField["lastLoginDate"] = "string"
CThostFtdcUserLogoutField["lastLoginTime"] = "string"
CThostFtdcUserLogoutField["gateWayCurLinkNum"] = "int"
CThostFtdcUserLogoutField["gateWayYYBDB"] = "string"
CThostFtdcUserLogoutField["obligate"] = "string"
CThostFtdcUserLogoutField["msg"] = "string"
structDict['CThostFtdcUserLogoutField'] = CThostFtdcUserLogoutField
@ -107,11 +70,7 @@ structDict['CThostFtdcInstrumentField'] = CThostFtdcInstrumentField
CThostFtdcQryTradingAccountField = {}
CThostFtdcQryTradingAccountField["memberID"] = "string"
CThostFtdcQryTradingAccountField["accountType"] = "string"
CThostFtdcQryTradingAccountField["traderID"] = "string"
CThostFtdcQryTradingAccountField["clientID"] = "string"
CThostFtdcQryTradingAccountField["marketID"] = "string"
CThostFtdcQryTradingAccountField["remian"] = "string"
structDict['CThostFtdcQryTradingAccountField'] = CThostFtdcQryTradingAccountField
@ -138,7 +97,6 @@ structDict['CThostFtdcTradingAccountField'] = CThostFtdcTradingAccountField
#投资者持仓
CThostFtdcInvestorPositionField = {}
CThostFtdcInvestorPositionField["clientID"] = "string"
CThostFtdcInvestorPositionField["instID"] = "string"
CThostFtdcInvestorPositionField["longPosi"] = "int"
CThostFtdcInvestorPositionField["longPosiAvgPrice"] = "float"
@ -220,37 +178,23 @@ structDict['CThostFtdcDepthMarketDataField'] = CThostFtdcDepthMarketDataField
#输入报单
CThostFtdcInputOrderField = {}
CThostFtdcInputOrderField["seatID"] = "string"
CThostFtdcInputOrderField["clientID"] = "string"
CThostFtdcInputOrderField["exchangeID"] = "string"
CThostFtdcInputOrderField["tradeCode"] = "string"
CThostFtdcInputOrderField["instID"] = "string"
CThostFtdcInputOrderField["buyOrSell"] = "string"
CThostFtdcInputOrderField["offsetFlag"] = "string"
CThostFtdcInputOrderField["amount"] = "int"
CThostFtdcInputOrderField["weight"] = "float"
CThostFtdcInputOrderField["middleFlag"] = "string"
CThostFtdcInputOrderField["orderFlag"] = "string"
CThostFtdcInputOrderField["priceFlag"] = "string"
CThostFtdcInputOrderField["price"] = "float"
CThostFtdcInputOrderField["trigPrice"] = "float"
CThostFtdcInputOrderField["marketID"] = "string"
CThostFtdcInputOrderField["validDate"] = "string"
CThostFtdcInputOrderField["orderNo"] = "string"
CThostFtdcInputOrderField["LocalOrderNo"] = "string"
CThostFtdcInputOrderField["matchQty"] = "int"
CThostFtdcInputOrderField["matchWeight"] = "float"
CThostFtdcInputOrderField["status"] = "string"
CThostFtdcInputOrderField["entrustTime"] = "string"
CThostFtdcInputOrderField["forceoffset_flag"] = "string"
CThostFtdcInputOrderField["cancelQty"] = "int"
CThostFtdcInputOrderField["cancelTime"] = "string"
CThostFtdcInputOrderField["volumnCheck"] = "int"
CThostFtdcInputOrderField["tradeWay"] = "string"
structDict['CThostFtdcInputOrderField'] = CThostFtdcInputOrderField
#报单
CThostFtdcOrderField = {}
CThostFtdcOrderField["orderNo"] = "string"
CThostFtdcOrderField["localOrderNo"] = "string"
CThostFtdcOrderField["marketID"] = "string"
@ -271,14 +215,21 @@ CThostFtdcOrderField["tradeWay"] = "string"
structDict['CThostFtdcOrderField'] = CThostFtdcOrderField
#报单撤单回报
CThostFtdcOrderRtnField = {}
CThostFtdcOrderRtnField["orderNo"] = "string"
CThostFtdcOrderRtnField["localOrderNo"] = "string"
CThostFtdcOrderRtnField["status"] = "string"
CThostFtdcOrderRtnField["cancelQty"] = "int"
structDict['CThostFtdcOrderRtnField'] = CThostFtdcOrderRtnField
#输入报单操作(cancel order)
CThostFtdcInputOrderActionField = {}
CThostFtdcInputOrderActionField["localOrderNo"] = "string"
CThostFtdcInputOrderActionField["orderFlag"] = "string"
CThostFtdcInputOrderActionField["marketID"] = "string"
CThostFtdcInputOrderActionField["traderID"] = "string"
CThostFtdcInputOrderActionField["tradeWay"] = "string"
CThostFtdcInputOrderActionField["status"] = "string"
structDict['CThostFtdcInputOrderActionField'] = CThostFtdcInputOrderActionField
@ -293,7 +244,6 @@ structDict['CThostFtdcOrderActionField'] = CThostFtdcOrderActionField
#成交
CThostFtdcTradeField = {}
CThostFtdcTradeField["orderNo"] = "string"
CThostFtdcTradeField["matchNo"] = "string"
CThostFtdcTradeField["instID"] = "string"
@ -325,15 +275,10 @@ structDict['CThostFtdcQryInstrumentField'] = CThostFtdcQryInstrumentField
#查询成交
CThostFtdcQryTradeField = {}
CThostFtdcQryTradeField["matchNo"] = "string"
CThostFtdcQryTradeField["instID"] = "string"
CThostFtdcQryTradeField["marketID"] = "string"
CThostFtdcQryTradeField["orderNo"] = "string"
CThostFtdcQryTradeField["clientID"] = "string"
CThostFtdcQryTradeField["memberID"] = "string"
CThostFtdcQryTradeField["matchNo"] = "string"
CThostFtdcQryTradeField["exchangeID"] = "string"
CThostFtdcQryTradeField["localOrderNo"] = "string"
CThostFtdcQryTradeField["traderID"] = "string"
structDict['CThostFtdcQryTradeField'] = CThostFtdcQryTradeField
@ -342,13 +287,6 @@ structDict['CThostFtdcQryTradeField'] = CThostFtdcQryTradeField
CThostFtdcQryOrderField = {}
CThostFtdcQryOrderField["instID"] = "string"
CThostFtdcQryOrderField["marketID"] = "string"
CThostFtdcQryOrderField["orderNo"] = "string"
CThostFtdcQryOrderField["clientID"] = "string"
CThostFtdcQryOrderField["memberID"] = "string"
CThostFtdcQryOrderField["offsetFlag"] = "string"
CThostFtdcQryOrderField["traderID"] = "string"
CThostFtdcQryOrderField["status"] = "string"
CThostFtdcQryOrderField["exchangeID"] = "string"
CThostFtdcQryOrderField["localOrderNo"] = "string"
structDict['CThostFtdcQryOrderField'] = CThostFtdcQryOrderField
@ -358,20 +296,15 @@ structDict['CThostFtdcQryOrderField'] = CThostFtdcQryOrderField
#查询投资者持仓
CThostFtdcQryInvestorPositionField = {}
CThostFtdcQryInvestorPositionField["clientID"] = "string"
CThostFtdcQryInvestorPositionField["memberID"] = "string"
CThostFtdcQryInvestorPositionField["marketID"] = "string"
CThostFtdcQryInvestorPositionField["instID"] = "string"
CThostFtdcQryInvestorPositionField["traderID"] = "string"
structDict['CThostFtdcQryInvestorPositionField'] = CThostFtdcQryInvestorPositionField
#查询库存
CThostFtdcQryStorageField = {}
CThostFtdcQryStorageField["clientID"] = "string"
CThostFtdcQryStorageField["memberID"] = "string"
CThostFtdcQryStorageField["traderID"] = "string"
CThostFtdcQryStorageField["varietyID"] = "string"
structDict['CThostFtdcQryStorageField'] = CThostFtdcQryStorageField
@ -399,13 +332,9 @@ structDict['CThostFtdcStorageField'] = CThostFtdcStorageField
CThostFtdcMarketStatusField = {}
CThostFtdcMarketStatusField["MktStatus"] = "string"
CThostFtdcMarketStatusField["marketID"] = "string"
CThostFtdcMarketStatusField["ExchCode"] = "string"
CThostFtdcMarketStatusField["MktChgTime"] = "string"
structDict['CThostFtdcMarketStatusField'] = CThostFtdcMarketStatusField
#指定的合约

View File

@ -2,23 +2,10 @@ int TdApi::reqUserLogin(dict req, int nRequestID)
{
CThostFtdcReqUserLoginField myreq = CThostFtdcReqUserLoginField();
memset(&myreq, 0, sizeof(myreq));
getChar(req, "lastLoginTime", myreq.lastLoginTime);
getChar(req, "password", myreq.password);
getChar(req, "tradeDate", myreq.tradeDate);
getChar(req, "ipGatewayAddress", myreq.ipGatewayAddress);
getChar(req, "localOrderNo", myreq.localOrderNo);
getInt(req, "loginbatch", &myreq.loginbatch);
getChar(req, "memberID", myreq.memberID);
getInt(req, "loginType", &myreq.loginType);
getInt(req, "portGateway", &myreq.portGateway);
getChar(req, "obligate", myreq.obligate);
getInt(req, "gateWayCurLinkNum", &myreq.gateWayCurLinkNum);
getChar(req, "lastLoginDate", myreq.lastLoginDate);
getInt(req, "machineID", &myreq.machineID);
getChar(req, "msg", myreq.msg);
getChar(req, "lastLoginIp", myreq.lastLoginIp);
getChar(req, "password", myreq.password);
getChar(req, "gateWayYYBDB", myreq.gateWayYYBDB);
getChar(req, "clientName", myreq.clientName);
getChar(req, "accountID", myreq.accountID);
int i = this->api->ReqUserLogin(&myreq, nRequestID);
return i;
@ -28,22 +15,7 @@ int TdApi::reqUserLogout(dict req, int nRequestID)
{
CThostFtdcUserLogoutField myreq = CThostFtdcUserLogoutField();
memset(&myreq, 0, sizeof(myreq));
getInt(req, "loginbatch", &myreq.loginbatch);
getChar(req, "gateWayYYBDB", myreq.gateWayYYBDB);
getChar(req, "tradeDate", myreq.tradeDate);
getInt(req, "machineID", &myreq.machineID);
getChar(req, "localOrderNo", myreq.localOrderNo);
getChar(req, "traderID", myreq.traderID);
getChar(req, "memberID", myreq.memberID);
getChar(req, "obligate", myreq.obligate);
getInt(req, "gateWayCurLinkNum", &myreq.gateWayCurLinkNum);
getChar(req, "lastLoginDate", myreq.lastLoginDate);
getChar(req, "lastLoginTime", myreq.lastLoginTime);
getChar(req, "msg", myreq.msg);
getChar(req, "lastLoginIp", myreq.lastLoginIp);
getChar(req, "password", myreq.password);
getChar(req, "ipAddress", myreq.ipAddress);
getChar(req, "clientName", myreq.clientName);
int i = this->api->ReqUserLogout(&myreq, nRequestID);
return i;
};
@ -63,31 +35,18 @@ int TdApi::reqOrderInsert(dict req, int nRequestID)
CThostFtdcInputOrderField myreq = CThostFtdcInputOrderField();
memset(&myreq, 0, sizeof(myreq));
getChar(req, "offsetFlag", myreq.offsetFlag);
getChar(req, "offsetFlag", myreq.offsetFlag);
getChar(req, "entrustTime", myreq.entrustTime);
getChar(req, "LocalOrderNo", myreq.LocalOrderNo);
getChar(req, "marketID", myreq.marketID);
getChar(req, "orderNo", myreq.orderNo);
getChar(req, "tradeWay", myreq.tradeWay);
getChar(req, "buyOrSell", myreq.buyOrSell);
getChar(req, "middleFlag", myreq.middleFlag);
getChar(req, "tradeCode", myreq.tradeCode);
getChar(req, "instID", myreq.instID);
getChar(req, "instID", myreq.instID);
getChar(req, "marketID", myreq.marketID);
getChar(req, "marketID", myreq.marketID);
getInt(req, "amount", &myreq.amount);
getChar(req, "seatID", myreq.seatID);
getChar(req, "status", myreq.status);
getChar(req, "cancelTime", myreq.cancelTime);
getChar(req, "middleFlag", myreq.middleFlag);
getChar(req, "middleFlag", myreq.middleFlag);
getChar(req, "validDate", myreq.validDate);
getInt(req, "matchQty", &myreq.matchQty);
getChar(req, "clientID", myreq.clientID);
getChar(req, "clientID", myreq.clientID);
getChar(req, "forceoffset_flag", myreq.forceoffset_flag);
getChar(req, "orderFlag", myreq.orderFlag);
getInt(req, "volumnCheck", &myreq.volumnCheck);
getInt(req, "cancelQty", &myreq.cancelQty);
getChar(req, "priceFlag", myreq.priceFlag);
getChar(req, "exchangeID", myreq.exchangeID);
getInt(req, "amount", &myreq.amount);
getInt(req, "amount", &myreq.amount);
getChar(req, "LocalOrderNo", myreq.LocalOrderNo);
getChar(req, "tradeWay", myreq.tradeWay);
int i = this->api->ReqOrderInsert(&myreq, nRequestID);
return i;
};
@ -96,11 +55,9 @@ int TdApi::reqOrderAction(dict req, int nRequestID)
{
CThostFtdcInputOrderActionField myreq = CThostFtdcInputOrderActionField();
memset(&myreq, 0, sizeof(myreq));
getChar(req, "tradeWay", myreq.tradeWay);
getChar(req, "status", myreq.status);
getChar(req, "localOrderNo", myreq.localOrderNo);
getChar(req, "marketID", myreq.marketID);
getChar(req, "traderID", myreq.traderID);
getChar(req, "orderFlag", myreq.orderFlag);
int i = this->api->ReqOrderAction(&myreq, nRequestID);
return i;
};
@ -110,9 +67,6 @@ int TdApi::reqQryInvestorPosition(dict req, int nRequestID)
CThostFtdcQryInvestorPositionField myreq = CThostFtdcQryInvestorPositionField();
memset(&myreq, 0, sizeof(myreq));
getChar(req, "instID", myreq.instID);
getChar(req, "traderID", myreq.traderID);
getChar(req, "memberID", myreq.memberID);
getChar(req, "clientID", myreq.clientID);
getChar(req, "marketID", myreq.marketID);
int i = this->api->ReqQryInvestorPosition(&myreq, nRequestID);
return i;
@ -122,11 +76,7 @@ int TdApi::reqQryTradingAccount(dict req, int nRequestID)
{
CThostFtdcQryTradingAccountField myreq = CThostFtdcQryTradingAccountField();
memset(&myreq, 0, sizeof(myreq));
getChar(req, "clientID", myreq.clientID);
getChar(req, "traderID", myreq.traderID);
getChar(req, "memberID", myreq.memberID);
getChar(req, "accountType", myreq.accountType);
getChar(req, "marketID", myreq.marketID);
getChar(req, "remian", myreq.remian);
int i = this->api->ReqQryTradingAccount(&myreq, nRequestID);
return i;
};
@ -135,15 +85,10 @@ int TdApi::reqQryTrade(dict req, int nRequestID)
{
CThostFtdcQryTradeField myreq = CThostFtdcQryTradeField();
memset(&myreq, 0, sizeof(myreq));
getChar(req, "exchangeID", myreq.exchangeID);
getChar(req, "instID", myreq.instID);
getChar(req, "localOrderNo", myreq.localOrderNo);
getChar(req, "traderID", myreq.traderID);
getChar(req, "memberID", myreq.memberID);
getChar(req, "clientID", myreq.clientID);
getChar(req, "marketID", myreq.marketID);
getChar(req, "matchNo", myreq.matchNo);
getChar(req, "orderNo", myreq.orderNo);
getChar(req, "marketID", myreq.marketID);
int i = this->api->ReqQryTrade(&myreq, nRequestID);
return i;
};
@ -152,16 +97,9 @@ int TdApi::reqQryOrder(dict req, int nRequestID)
{
CThostFtdcQryOrderField myreq = CThostFtdcQryOrderField();
memset(&myreq, 0, sizeof(myreq));
getChar(req, "status", myreq.status);
getChar(req, "exchangeID", myreq.exchangeID);
getChar(req, "offsetFlag", myreq.offsetFlag);
getChar(req, "instID", myreq.instID);
getChar(req, "localOrderNo", myreq.localOrderNo);
getChar(req, "traderID", myreq.traderID);
getChar(req, "memberID", myreq.memberID);
getChar(req, "clientID", myreq.clientID);
getChar(req, "marketID", myreq.marketID);
getChar(req, "orderNo", myreq.orderNo);
int i = this->api->ReqQryOrder(&myreq, nRequestID);
return i;
};
@ -170,9 +108,7 @@ int TdApi::reqQryStorage(dict req, int nRequestID)
{
CThostFtdcQryStorageField myreq = CThostFtdcQryStorageField();
memset(&myreq, 0, sizeof(myreq));
getChar(req, "traderID", myreq.traderID);
getChar(req, "memberID", myreq.memberID);
getChar(req, "clientID", myreq.clientID);
getChar(req, "varietyID", myreq.varietyID);
int i = this->api->ReqQryStorage(&myreq, nRequestID);
return i;
};

View File

@ -15,24 +15,15 @@ void TdApi::processRspUserLogin(Task task)
PyLock lock;
CThostFtdcRspUserLoginField task_data = any_cast<CThostFtdcRspUserLoginField>(task.task_data);
dict data;
data["loginbatch"] = task_data.loginbatch;
data["SeatNo"] = task_data.SeatNo;
data["gateWayYYBDB"] = task_data.gateWayYYBDB;
data["tradeDate"] = task_data.tradeDate;
data["tradeCode"] = task_data.tradeCode;
data["machineID"] = task_data.machineID;
data["localOrderNo"] = task_data.localOrderNo;
data["traderID"] = task_data.traderID;
data["memberID"] = task_data.memberID;
data["loginbatch"] = task_data.loginbatch;
data["clientID"] = task_data.clientID;
data["obligate"] = task_data.obligate;
data["gateWayCurLinkNum"] = task_data.gateWayCurLinkNum;
data["lastLoginDate"] = task_data.lastLoginDate;
data["lastLoginTime"] = task_data.lastLoginTime;
data["msg"] = task_data.msg;
data["lastLoginIp"] = task_data.lastLoginIp;
data["password"] = task_data.password;
data["ipAddress"] = task_data.ipAddress;
data["clientName"] = task_data.clientName;
CThostFtdcRspInfoField task_error = any_cast<CThostFtdcRspInfoField>(task.task_error);
@ -48,22 +39,7 @@ void TdApi::processRspUserLogout(Task task)
PyLock lock;
CThostFtdcUserLogoutField task_data = any_cast<CThostFtdcUserLogoutField>(task.task_data);
dict data;
data["loginbatch"] = task_data.loginbatch;
data["gateWayYYBDB"] = task_data.gateWayYYBDB;
data["tradeDate"] = task_data.tradeDate;
data["machineID"] = task_data.machineID;
data["localOrderNo"] = task_data.localOrderNo;
data["traderID"] = task_data.traderID;
data["memberID"] = task_data.memberID;
data["obligate"] = task_data.obligate;
data["gateWayCurLinkNum"] = task_data.gateWayCurLinkNum;
data["lastLoginDate"] = task_data.lastLoginDate;
data["lastLoginTime"] = task_data.lastLoginTime;
data["msg"] = task_data.msg;
data["lastLoginIp"] = task_data.lastLoginIp;
data["password"] = task_data.password;
data["ipAddress"] = task_data.ipAddress;
data["clientName"] = task_data.clientName;
CThostFtdcRspInfoField task_error = any_cast<CThostFtdcRspInfoField>(task.task_error);
dict error;
@ -165,31 +141,18 @@ void TdApi::processRspOrderInsert(Task task)
CThostFtdcInputOrderField task_data = any_cast<CThostFtdcInputOrderField>(task.task_data);
dict data;
data["offsetFlag"] = task_data.offsetFlag;
data["weight"] = task_data.weight;
data["entrustTime"] = task_data.entrustTime;
data["LocalOrderNo"] = task_data.LocalOrderNo;
data["marketID"] = task_data.marketID;
data["orderNo"] = task_data.orderNo;
data["tradeWay"] = task_data.tradeWay;
data["buyOrSell"] = task_data.buyOrSell;
data["instID"] = task_data.instID;
data["seatID"] = task_data.seatID;
data["status"] = task_data.status;
data["cancelTime"] = task_data.cancelTime;
data["middleFlag"] = task_data.middleFlag;
data["tradeCode"] = task_data.tradeCode;
data["instID"] = task_data.instID;
data["price"] = task_data.price;
data["validDate"] = task_data.validDate;
data["matchQty"] = task_data.matchQty;
data["clientID"] = task_data.clientID;
data["marketID"] = task_data.marketID;
data["trigPrice"] = task_data.trigPrice;
data["forceoffset_flag"] = task_data.forceoffset_flag;
data["orderFlag"] = task_data.orderFlag;
data["volumnCheck"] = task_data.volumnCheck;
data["cancelQty"] = task_data.cancelQty;
data["priceFlag"] = task_data.priceFlag;
data["exchangeID"] = task_data.exchangeID;
data["amount"] = task_data.amount;
data["matchWeight"] = task_data.matchWeight;
data["seatID"] = task_data.seatID;
data["priceFlag"] = task_data.priceFlag;
data["LocalOrderNo"] = task_data.LocalOrderNo;
data["tradeWay"] = task_data.tradeWay;
CThostFtdcRspInfoField task_error = any_cast<CThostFtdcRspInfoField>(task.task_error);
dict error;
@ -205,31 +168,18 @@ void TdApi::processErrRtnOrderInsert(Task task)
CThostFtdcInputOrderField task_data = any_cast<CThostFtdcInputOrderField>(task.task_data);
dict data;
data["offsetFlag"] = task_data.offsetFlag;
data["weight"] = task_data.weight;
data["entrustTime"] = task_data.entrustTime;
data["LocalOrderNo"] = task_data.LocalOrderNo;
data["marketID"] = task_data.marketID;
data["orderNo"] = task_data.orderNo;
data["tradeWay"] = task_data.tradeWay;
data["buyOrSell"] = task_data.buyOrSell;
data["instID"] = task_data.instID;
data["seatID"] = task_data.seatID;
data["status"] = task_data.status;
data["cancelTime"] = task_data.cancelTime;
data["middleFlag"] = task_data.middleFlag;
data["tradeCode"] = task_data.tradeCode;
data["instID"] = task_data.instID;
data["price"] = task_data.price;
data["validDate"] = task_data.validDate;
data["matchQty"] = task_data.matchQty;
data["clientID"] = task_data.clientID;
data["marketID"] = task_data.marketID;
data["trigPrice"] = task_data.trigPrice;
data["forceoffset_flag"] = task_data.forceoffset_flag;
data["orderFlag"] = task_data.orderFlag;
data["volumnCheck"] = task_data.volumnCheck;
data["cancelQty"] = task_data.cancelQty;
data["priceFlag"] = task_data.priceFlag;
data["exchangeID"] = task_data.exchangeID;
data["amount"] = task_data.amount;
data["matchWeight"] = task_data.matchWeight;
data["seatID"] = task_data.seatID;
data["priceFlag"] = task_data.priceFlag;
data["LocalOrderNo"] = task_data.LocalOrderNo;
data["tradeWay"] = task_data.tradeWay;
CThostFtdcRspInfoField task_error = any_cast<CThostFtdcRspInfoField>(task.task_error);
dict error;
@ -242,25 +192,12 @@ void TdApi::processErrRtnOrderInsert(Task task)
void TdApi::processRtnOrder(Task task)
{
PyLock lock;
CThostFtdcOrderField task_data = any_cast<CThostFtdcOrderField>(task.task_data);
CThostFtdcOrderRtnField task_data = any_cast<CThostFtdcOrderRtnField>(task.task_data);
dict data;
data["status"] = task_data.status;
data["cancelTime"] = task_data.cancelTime;
data["offsetFlag"] = task_data.offsetFlag;
data["buyOrSell"] = task_data.buyOrSell;
data["instID"] = task_data.instID;
data["localOrderNo"] = task_data.localOrderNo;
data["matchQty"] = task_data.matchQty;
data["weight"] = task_data.weight;
data["marketID"] = task_data.marketID;
data["amount"] = task_data.amount;
data["forceoffset_flag"] = task_data.forceoffset_flag;
data["entrustTime"] = task_data.entrustTime;
data["orderNo"] = task_data.orderNo;
data["localOrderNo"] = task_data.localOrderNo;
data["cancelQty"] = task_data.cancelQty;
data["matchWeight"] = task_data.matchWeight;
data["price"] = task_data.price;
data["tradeWay"] = task_data.tradeWay;
this->onRtnOrder(data);
};
@ -270,22 +207,7 @@ void TdApi::processForceLogout(Task task)
PyLock lock;
CThostFtdcUserLogoutField task_data = any_cast<CThostFtdcUserLogoutField>(task.task_data);
dict data;
data["loginbatch"] = task_data.loginbatch;
data["gateWayYYBDB"] = task_data.gateWayYYBDB;
data["tradeDate"] = task_data.tradeDate;
data["machineID"] = task_data.machineID;
data["localOrderNo"] = task_data.localOrderNo;
data["traderID"] = task_data.traderID;
data["memberID"] = task_data.memberID;
data["obligate"] = task_data.obligate;
data["gateWayCurLinkNum"] = task_data.gateWayCurLinkNum;
data["lastLoginDate"] = task_data.lastLoginDate;
data["lastLoginTime"] = task_data.lastLoginTime;
data["msg"] = task_data.msg;
data["lastLoginIp"] = task_data.lastLoginIp;
data["password"] = task_data.password;
data["ipAddress"] = task_data.ipAddress;
data["clientName"] = task_data.clientName;
this->onForceLogout(data);
};
@ -295,11 +217,9 @@ void TdApi::processRspOrderAction(Task task)
PyLock lock;
CThostFtdcInputOrderActionField task_data = any_cast<CThostFtdcInputOrderActionField>(task.task_data);
dict data;
data["tradeWay"] = task_data.tradeWay;
data["status"] = task_data.status;
data["localOrderNo"] = task_data.localOrderNo;
data["marketID"] = task_data.marketID;
data["traderID"] = task_data.traderID;
data["orderFlag"] = task_data.orderFlag;
CThostFtdcRspInfoField task_error = any_cast<CThostFtdcRspInfoField>(task.task_error);
dict error;
@ -460,7 +380,6 @@ void TdApi::processRspQryInvestorPosition(Task task)
data["todayOffsetLong"] = task_data.todayOffsetLong;
data["shortPosiFrozen"] = task_data.shortPosiFrozen;
data["instID"] = task_data.instID;
data["clientID"] = task_data.clientID;
data["lastShort"] = task_data.lastShort;
data["todayOffsetShort"] = task_data.todayOffsetShort;
data["longPosiAvgPrice"] = task_data.longPosiAvgPrice;

View File

@ -202,7 +202,7 @@ void TdApi::OnErrRtnOrderInsert(CThostFtdcInputOrderField *pInputOrder, CThostFt
this->task_queue.push(task);
};
void TdApi::OnRtnOrder(CThostFtdcOrderField *pOrder)
void TdApi::OnRtnOrder(CThostFtdcOrderRtnField *pOrder)
{
Task task = Task();
task.task_name = ONRTNORDER;
@ -213,7 +213,7 @@ void TdApi::OnRtnOrder(CThostFtdcOrderField *pOrder)
}
else
{
CThostFtdcOrderField empty_data = CThostFtdcOrderField();
CThostFtdcOrderRtnField empty_data = CThostFtdcOrderRtnField();
memset(&empty_data, 0, sizeof(empty_data));
task.task_data = empty_data;
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0"?>
<SubscriptionDataContainer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:Microsoft.VisualStudio.WindowsAzure.CommonAzureTools.Authentication.CacheManagement">
<Items />
<TokenCache>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAtT6l7mFaOE6IUjoFpngY+wAAAAACAAAAAAAQZgAAAAEAACAAAAC3lvUQB5CD6dZv3KbSkrwYzgnYSLlRPtx/2QGEeHWhigAAAAAOgAAAAAIAACAAAACChdhEc9CeUlA2e2ACUzUAG8Zbt7bIMRNk7rLbZ37WwhAAAADWtmtxkWmKACLpqlrYubjZQAAAAOjWOwvVDo3lgRFGGBh0zQ5rZ4EfOCkm5vgKXT9eylzt+mO7Dy5G+5IkzzKuYvX8zZefUMk7Ia7eQN0Po8A+DJs=</TokenCache>
</SubscriptionDataContainer>

View File

@ -277,7 +277,7 @@ void TdApi::OnErrRtnOrderInsert(CThostFtdcInputOrderField *pInputOrder, CThostFt
this->task_queue.push(task);
};
void TdApi::OnRtnOrder(CThostFtdcOrderField *pOrder)
void TdApi::OnRtnOrder(CThostFtdcOrderRtnField *pOrder)
{
Task task = Task();
task.task_name = ONRTNORDER;
@ -288,7 +288,7 @@ void TdApi::OnRtnOrder(CThostFtdcOrderField *pOrder)
}
else
{
CThostFtdcOrderField empty_data = CThostFtdcOrderField();
CThostFtdcOrderRtnField empty_data = CThostFtdcOrderRtnField();
memset(&empty_data, 0, sizeof(empty_data));
task.task_data = empty_data;
}
@ -541,6 +541,9 @@ void TdApi::OnRspQryClientStorage(CThostFtdcStorageField *pStorage, CThostFtdcRs
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);
};
@ -728,24 +731,15 @@ void TdApi::processRspUserLogin(Task task)
PyLock lock;
CThostFtdcRspUserLoginField task_data = any_cast<CThostFtdcRspUserLoginField>(task.task_data);
dict data;
data["loginbatch"] = task_data.loginbatch;
data["SeatNo"] = task_data.SeatNo;
data["gateWayYYBDB"] = task_data.gateWayYYBDB;
data["tradeDate"] = task_data.tradeDate;
data["tradeCode"] = task_data.tradeCode;
data["machineID"] = task_data.machineID;
data["localOrderNo"] = task_data.localOrderNo;
data["traderID"] = task_data.traderID;
data["memberID"] = task_data.memberID;
data["loginbatch"] = task_data.loginbatch;
data["clientID"] = task_data.clientID;
data["obligate"] = task_data.obligate;
data["gateWayCurLinkNum"] = task_data.gateWayCurLinkNum;
data["lastLoginDate"] = task_data.lastLoginDate;
data["lastLoginTime"] = task_data.lastLoginTime;
data["msg"] = task_data.msg;
data["lastLoginIp"] = task_data.lastLoginIp;
data["password"] = task_data.password;
data["ipAddress"] = task_data.ipAddress;
data["clientName"] = task_data.clientName;
CThostFtdcRspInfoField task_error = any_cast<CThostFtdcRspInfoField>(task.task_error);
@ -761,22 +755,7 @@ void TdApi::processRspUserLogout(Task task)
PyLock lock;
CThostFtdcUserLogoutField task_data = any_cast<CThostFtdcUserLogoutField>(task.task_data);
dict data;
data["loginbatch"] = task_data.loginbatch;
data["gateWayYYBDB"] = task_data.gateWayYYBDB;
data["tradeDate"] = task_data.tradeDate;
data["machineID"] = task_data.machineID;
data["localOrderNo"] = task_data.localOrderNo;
data["traderID"] = task_data.traderID;
data["memberID"] = task_data.memberID;
data["obligate"] = task_data.obligate;
data["gateWayCurLinkNum"] = task_data.gateWayCurLinkNum;
data["lastLoginDate"] = task_data.lastLoginDate;
data["lastLoginTime"] = task_data.lastLoginTime;
data["msg"] = task_data.msg;
data["lastLoginIp"] = task_data.lastLoginIp;
data["password"] = task_data.password;
data["ipAddress"] = task_data.ipAddress;
data["clientName"] = task_data.clientName;
CThostFtdcRspInfoField task_error = any_cast<CThostFtdcRspInfoField>(task.task_error);
dict error;
@ -793,8 +772,6 @@ void TdApi::processNtyMktStatus(Task task)
dict data;
data["mktStatus"] = task_data.MktStatus;
data["marketID"] = task_data.marketID;
data["exchCode"] = task_data.ExchCode;
data["mktChgTime"] = task_data.MktChgTime;
this->onNtyMktStatus(data);
};
@ -884,32 +861,20 @@ void TdApi::processRspOrderInsert(Task task)
PyLock lock;
CThostFtdcInputOrderField task_data = any_cast<CThostFtdcInputOrderField>(task.task_data);
dict data;
data["offsetFlag"] = task_data.offsetFlag;
data["weight"] = task_data.weight;
data["entrustTime"] = task_data.entrustTime;
data["LocalOrderNo"] = task_data.LocalOrderNo;
data["marketID"] = task_data.marketID;
data["orderNo"] = task_data.orderNo;
data["tradeWay"] = task_data.tradeWay;
data["buyOrSell"] = task_data.buyOrSell;
data["instID"] = task_data.instID;
data["seatID"] = task_data.seatID;
data["status"] = task_data.status;
data["cancelTime"] = task_data.cancelTime;
data["offsetFlag"] = (char) task_data.offsetFlag;
data["buyOrSell"] = (char) task_data.buyOrSell;
data["middleFlag"] = task_data.middleFlag;
data["tradeCode"] = task_data.tradeCode;
data["instID"] = task_data.instID;
data["price"] = task_data.price;
data["validDate"] = task_data.validDate;
data["matchQty"] = task_data.matchQty;
data["clientID"] = task_data.clientID;
data["marketID"] = task_data.marketID;
data["trigPrice"] = task_data.trigPrice;
data["forceoffset_flag"] = task_data.forceoffset_flag;
data["orderFlag"] = task_data.orderFlag;
data["volumnCheck"] = task_data.volumnCheck;
data["cancelQty"] = task_data.cancelQty;
data["priceFlag"] = task_data.priceFlag;
data["exchangeID"] = task_data.exchangeID;
data["amount"] = task_data.amount;
data["matchWeight"] = task_data.matchWeight;
data["seatID"] = task_data.seatID;
data["priceFlag"] = task_data.priceFlag;
data["LocalOrderNo"] = task_data.LocalOrderNo;
data["tradeWay"] = task_data.tradeWay;
CThostFtdcRspInfoField task_error = any_cast<CThostFtdcRspInfoField>(task.task_error);
dict error;
@ -925,31 +890,18 @@ void TdApi::processErrRtnOrderInsert(Task task)
CThostFtdcInputOrderField task_data = any_cast<CThostFtdcInputOrderField>(task.task_data);
dict data;
data["offsetFlag"] = task_data.offsetFlag;
data["weight"] = task_data.weight;
data["entrustTime"] = task_data.entrustTime;
data["LocalOrderNo"] = task_data.LocalOrderNo;
data["marketID"] = task_data.marketID;
data["orderNo"] = task_data.orderNo;
data["tradeWay"] = task_data.tradeWay;
data["buyOrSell"] = task_data.buyOrSell;
data["instID"] = task_data.instID;
data["seatID"] = task_data.seatID;
data["status"] = task_data.status;
data["cancelTime"] = task_data.cancelTime;
data["middleFlag"] = task_data.middleFlag;
data["tradeCode"] = task_data.tradeCode;
data["instID"] = task_data.instID;
data["price"] = task_data.price;
data["validDate"] = task_data.validDate;
data["matchQty"] = task_data.matchQty;
data["clientID"] = task_data.clientID;
data["marketID"] = task_data.marketID;
data["trigPrice"] = task_data.trigPrice;
data["forceoffset_flag"] = task_data.forceoffset_flag;
data["orderFlag"] = task_data.orderFlag;
data["volumnCheck"] = task_data.volumnCheck;
data["cancelQty"] = task_data.cancelQty;
data["priceFlag"] = task_data.priceFlag;
data["exchangeID"] = task_data.exchangeID;
data["amount"] = task_data.amount;
data["matchWeight"] = task_data.matchWeight;
data["seatID"] = task_data.seatID;
data["priceFlag"] = task_data.priceFlag;
data["LocalOrderNo"] = task_data.LocalOrderNo;
data["tradeWay"] = task_data.tradeWay;
CThostFtdcRspInfoField task_error = any_cast<CThostFtdcRspInfoField>(task.task_error);
dict error;
@ -962,25 +914,12 @@ void TdApi::processErrRtnOrderInsert(Task task)
void TdApi::processRtnOrder(Task task)
{
PyLock lock;
CThostFtdcOrderField task_data = any_cast<CThostFtdcOrderField>(task.task_data);
CThostFtdcOrderRtnField task_data = any_cast<CThostFtdcOrderRtnField>(task.task_data);
dict data;
data["status"] = task_data.status;
data["cancelTime"] = task_data.cancelTime;
data["offsetFlag"] = task_data.offsetFlag;
data["buyOrSell"] = task_data.buyOrSell;
data["instID"] = task_data.instID;
data["localOrderNo"] = task_data.localOrderNo;
data["matchQty"] = task_data.matchQty;
data["weight"] = task_data.weight;
data["marketID"] = task_data.marketID;
data["amount"] = task_data.amount;
data["forceoffset_flag"] = task_data.forceoffset_flag;
data["entrustTime"] = task_data.entrustTime;
data["status"] = (char) task_data.status;
data["orderNo"] = task_data.orderNo;
data["localOrderNo"] = task_data.localOrderNo;
data["cancelQty"] = task_data.cancelQty;
data["matchWeight"] = task_data.matchWeight;
data["price"] = task_data.price;
data["tradeWay"] = task_data.tradeWay;
this->onRtnOrder(data);
};
@ -990,22 +929,7 @@ void TdApi::processForceLogout(Task task)
PyLock lock;
CThostFtdcUserLogoutField task_data = any_cast<CThostFtdcUserLogoutField>(task.task_data);
dict data;
data["loginbatch"] = task_data.loginbatch;
data["gateWayYYBDB"] = task_data.gateWayYYBDB;
data["tradeDate"] = task_data.tradeDate;
data["machineID"] = task_data.machineID;
data["localOrderNo"] = task_data.localOrderNo;
data["traderID"] = task_data.traderID;
data["memberID"] = task_data.memberID;
data["obligate"] = task_data.obligate;
data["gateWayCurLinkNum"] = task_data.gateWayCurLinkNum;
data["lastLoginDate"] = task_data.lastLoginDate;
data["lastLoginTime"] = task_data.lastLoginTime;
data["msg"] = task_data.msg;
data["lastLoginIp"] = task_data.lastLoginIp;
data["password"] = task_data.password;
data["ipAddress"] = task_data.ipAddress;
data["clientName"] = task_data.clientName;
this->onForceLogout(data);
};
@ -1015,11 +939,9 @@ void TdApi::processRspOrderAction(Task task)
PyLock lock;
CThostFtdcInputOrderActionField task_data = any_cast<CThostFtdcInputOrderActionField>(task.task_data);
dict data;
data["tradeWay"] = task_data.tradeWay;
data["status"] = task_data.status;
data["localOrderNo"] = task_data.localOrderNo;
data["marketID"] = task_data.marketID;
data["traderID"] = task_data.traderID;
data["orderFlag"] = task_data.orderFlag;
CThostFtdcRspInfoField task_error = any_cast<CThostFtdcRspInfoField>(task.task_error);
dict error;
@ -1053,8 +975,8 @@ void TdApi::processRtnTrade(Task task)
PyLock lock;
CThostFtdcTradeField task_data = any_cast<CThostFtdcTradeField>(task.task_data);
dict data;
data["offSetFlag"] = task_data.offSetFlag;
data["buyOrSell"] = task_data.buyOrSell;
data["offSetFlag"] = (char) task_data.offSetFlag;
data["buyOrSell"] = (char) task_data.buyOrSell;
data["order_flag"] = task_data.order_flag;
data["instID"] = task_data.instID;
data["price"] = task_data.price;
@ -1070,7 +992,7 @@ void TdApi::processRtnTrade(Task task)
data["forcebatchnum"] = task_data.forcebatchnum;
data["localOrderNo"] = task_data.localOrderNo;
data["matchDate"] = task_data.matchDate;
data["forceoffset_flag"] = task_data.forceoffset_flag;
data["forceoffset_flag"] = task_data.forceoffset_flag;
this->onRtnTrade(data);
};
@ -1110,23 +1032,23 @@ void TdApi::processRspQryOrder(Task task)
PyLock lock;
CThostFtdcOrderField task_data = any_cast<CThostFtdcOrderField>(task.task_data);
dict data;
data["status"] = task_data.status;
data["status"] = (char) task_data.status;
data["cancelTime"] = task_data.cancelTime;
data["offsetFlag"] = task_data.offsetFlag;
data["buyOrSell"] = task_data.buyOrSell;
data["offsetFlag"] = (char) task_data.offsetFlag;
data["buyOrSell"] = (char) task_data.buyOrSell;
data["instID"] = task_data.instID;
data["localOrderNo"] = task_data.localOrderNo;
data["matchQty"] = task_data.matchQty;
data["weight"] = task_data.weight;
data["marketID"] = task_data.marketID;
data["amount"] = task_data.amount;
data["forceoffset_flag"] = task_data.forceoffset_flag;
data["forceoffset_flag"] = (char) task_data.forceoffset_flag;
data["entrustTime"] = task_data.entrustTime;
data["orderNo"] = task_data.orderNo;
data["cancelQty"] = task_data.cancelQty;
data["matchWeight"] = task_data.matchWeight;
data["price"] = task_data.price;
data["tradeWay"] = task_data.tradeWay;
data["tradeWay"] = (char) task_data.tradeWay;
CThostFtdcRspInfoField task_error = any_cast<CThostFtdcRspInfoField>(task.task_error);
dict error;
@ -1141,8 +1063,8 @@ void TdApi::processRspQryTrade(Task task)
PyLock lock;
CThostFtdcTradeField task_data = any_cast<CThostFtdcTradeField>(task.task_data);
dict data;
data["offSetFlag"] = task_data.offSetFlag;
data["buyOrSell"] = task_data.buyOrSell;
data["offSetFlag"] = (char) task_data.offSetFlag;
data["buyOrSell"] = (char) task_data.buyOrSell;
data["order_flag"] = task_data.order_flag;
data["instID"] = task_data.instID;
data["price"] = task_data.price;
@ -1158,7 +1080,7 @@ void TdApi::processRspQryTrade(Task task)
data["forcebatchnum"] = task_data.forcebatchnum;
data["localOrderNo"] = task_data.localOrderNo;
data["matchDate"] = task_data.matchDate;
data["forceoffset_flag"] = task_data.forceoffset_flag;
data["forceoffset_flag"] = (char) task_data.forceoffset_flag;
CThostFtdcRspInfoField task_error = any_cast<CThostFtdcRspInfoField>(task.task_error);
dict error;
@ -1180,7 +1102,6 @@ void TdApi::processRspQryInvestorPosition(Task task)
data["todayOffsetLong"] = task_data.todayOffsetLong;
data["shortPosiFrozen"] = task_data.shortPosiFrozen;
data["instID"] = task_data.instID;
data["clientID"] = task_data.clientID;
data["lastShort"] = task_data.lastShort;
data["todayOffsetShort"] = task_data.todayOffsetShort;
data["longPosiAvgPrice"] = task_data.longPosiAvgPrice;
@ -1288,28 +1209,32 @@ void TdApi::registerFront(string pszFrontAddress)
this->api->RegisterFront((char*)pszFrontAddress.c_str());
};
int TdApi::subscribeMarketData(string instrumentID)
{
char* buffer = (char*)instrumentID.c_str();
char* myreq[1] = { buffer };
int i = this->api->SubscribeMarketData(myreq, 1);
return i;
};
int TdApi::unSubscribeMarketData(string instrumentID)
{
char* buffer = (char*)instrumentID.c_str();
char* myreq[1] = { buffer };;
int i = this->api->UnSubscribeMarketData(myreq, 1);
return i;
};
int TdApi::reqUserLogin(dict req, int nRequestID)
{
CThostFtdcReqUserLoginField myreq = CThostFtdcReqUserLoginField();
memset(&myreq, 0, sizeof(myreq));
getChar(req, "ipGatewayAddress", myreq.ipGatewayAddress);
getChar(req, "obligate", myreq.obligate);
getInt(req, "loginType", &myreq.loginType);
getInt(req, "gateWayCurLinkNum", &myreq.gateWayCurLinkNum);
getChar(req, "gateWayYYBDB", myreq.gateWayYYBDB);
getChar(req, "lastLoginTime", myreq.lastLoginTime);
getChar(req, "lastLoginIp", myreq.lastLoginIp);
getChar(req, "password", myreq.password);
getChar(req, "clientName", myreq.clientName);
getChar(req, "msg", myreq.msg);
getChar(req, "lastLoginDate", myreq.lastLoginDate);
getInt(req, "machineID", &myreq.machineID);
getChar(req, "accountID", myreq.accountID);
getInt(req, "loginbatch", &myreq.loginbatch);
getChar(req, "localOrderNo", myreq.localOrderNo);
getChar(req, "tradeDate", myreq.tradeDate);
getInt(req, "portGateway", &myreq.portGateway);
getChar(req, "memberID", myreq.memberID);
getInt(req, "loginType", &myreq.loginType);
getChar(req, "accountID", myreq.accountID);
int i = this->api->ReqUserLogin(&myreq, nRequestID);
return i;
};
@ -1318,22 +1243,7 @@ int TdApi::reqUserLogout(dict req, int nRequestID)
{
CThostFtdcUserLogoutField myreq = CThostFtdcUserLogoutField();
memset(&myreq, 0, sizeof(myreq));
getChar(req, "obligate", myreq.obligate);
getChar(req, "tradeDate", myreq.tradeDate);
getChar(req, "localOrderNo", myreq.localOrderNo);
getInt(req, "gateWayCurLinkNum", &myreq.gateWayCurLinkNum);
getChar(req, "gateWayYYBDB", myreq.gateWayYYBDB);
getChar(req, "lastLoginTime", myreq.lastLoginTime);
getChar(req, "lastLoginIp", myreq.lastLoginIp);
getChar(req, "password", myreq.password);
getChar(req, "clientName", myreq.clientName);
getChar(req, "ipAddress", myreq.ipAddress);
getInt(req, "machineID", &myreq.machineID);
getInt(req, "loginbatch", &myreq.loginbatch);
getChar(req, "msg", myreq.msg);
getChar(req, "lastLoginDate", myreq.lastLoginDate);
getChar(req, "traderID", myreq.traderID);
getChar(req, "memberID", myreq.memberID);
int i = this->api->ReqUserLogout(&myreq, nRequestID);
return i;
};
@ -1344,35 +1254,6 @@ int TdApi::reqUserReLogin()
return i;
}
int TdApi::reqQryTradingAccount(dict req, int nRequestID)
{
CThostFtdcQryTradingAccountField myreq = CThostFtdcQryTradingAccountField();
memset(&myreq, 0, sizeof(myreq));
getChar(req, "clientID", myreq.clientID);
getChar(req, "traderID", myreq.traderID);
getChar(req, "memberID", myreq.memberID);
getChar(req, "marketID", myreq.marketID);
//getChar(req, "accountType", &myreq.accountType);
//ÒÔÏÂΪÊÖ¶¯¸Äд
if (req.has_key("accountType"))
{
object o = req["accountType"];
extract<string> x(o);
if (x.check())
{
string s = x();
const char *buffer = s.c_str();
myreq.accountType = (unsigned char) *buffer;
}
}
int i = this->api->ReqQryTradingAccount(&myreq, nRequestID);
return i;
};
int TdApi::reqQryInstrument(dict req, int nRequestID)
{
CThostFtdcQryInstrumentField myreq = CThostFtdcQryInstrumentField();
@ -1387,30 +1268,60 @@ int TdApi::reqOrderInsert(dict req, int nRequestID)
{
CThostFtdcInputOrderField myreq = CThostFtdcInputOrderField();
memset(&myreq, 0, sizeof(myreq));
getUnsignedChar(req, "offsetFlag", &myreq.offsetFlag);
getChar(req, "entrustTime", myreq.entrustTime);
getChar(req, "LocalOrderNo", myreq.LocalOrderNo);
getChar(req, "marketID", myreq.marketID);
getChar(req, "orderNo", myreq.orderNo);
getUnsignedChar(req, "tradeWay", &myreq.tradeWay);
getUnsignedChar(req, "buyOrSell", &myreq.buyOrSell);
getChar(req, "tradeCode", myreq.tradeCode);
getChar(req, "instID", myreq.instID);
getChar(req, "marketID", myreq.marketID);
getInt(req, "amount", &myreq.amount);
getChar(req, "seatID", myreq.seatID);
getUnsignedChar(req, "status", &myreq.status);
getChar(req, "cancelTime", myreq.cancelTime);
getUnsignedChar(req, "middleFlag", &myreq.middleFlag);
getChar(req, "validDate", myreq.validDate);
getInt(req, "matchQty", &myreq.matchQty);
getChar(req, "clientID", myreq.clientID);
getChar(req, "clientID", myreq.clientID);
getUnsignedChar(req, "forceoffset_flag", &myreq.forceoffset_flag);
getUnsignedChar(req, "orderFlag", &myreq.orderFlag);
getInt(req, "volumnCheck", &myreq.volumnCheck);
getInt(req, "cancelQty", &myreq.cancelQty);
getUnsignedChar(req, "priceFlag", &myreq.priceFlag);
getChar(req, "exchangeID", myreq.exchangeID);
getInt(req, "amount", &myreq.amount);
getInt(req, "amount", &myreq.amount);
getChar(req, "LocalOrderNo", myreq.LocalOrderNo);
getUnsignedChar(req, "tradeWay", &myreq.tradeWay);
getUnsignedChar(req, "middleFlag", &myreq.middleFlag);
getDouble(req, "price", &myreq.price);
//ÒÔÏ´úÂëΪÊÖд
if (req.has_key("offsetFlag"))
{
object o = req["offsetFlag"];
extract<string> x(o);
if (x.check())
{
string s = x();
const char *offsetBuffer = s.c_str();
if (*offsetBuffer == '0')
{
myreq.offsetFlag = '0';
}
else if (*offsetBuffer == '1')
{
myreq.offsetFlag = '1';
}
}
}
if (req.has_key("buyOrSell"))
{
object o2 = req["buyOrSell"];
extract<string> x2(o2);
if (x2.check())
{
string s2 = x2();
const char *bsBuffer = s2.c_str();
if (*bsBuffer == '0')
{
myreq.buyOrSell = '0';
}
else if (*bsBuffer == '1')
{
myreq.buyOrSell = '1';
}
}
}
int i = this->api->ReqOrderInsert(&myreq, nRequestID);
return i;
};
@ -1419,11 +1330,9 @@ int TdApi::reqOrderAction(dict req, int nRequestID)
{
CThostFtdcInputOrderActionField myreq = CThostFtdcInputOrderActionField();
memset(&myreq, 0, sizeof(myreq));
getUnsignedChar(req, "tradeWay", &myreq.tradeWay);
getUnsignedChar(req, "status", &myreq.status);
getChar(req, "localOrderNo", myreq.localOrderNo);
getChar(req, "marketID", myreq.marketID);
getChar(req, "traderID", myreq.traderID);
getUnsignedChar(req, "orderFlag", &myreq.orderFlag);
int i = this->api->ReqOrderAction(&myreq, nRequestID);
return i;
};
@ -1433,27 +1342,28 @@ int TdApi::reqQryInvestorPosition(dict req, int nRequestID)
CThostFtdcQryInvestorPositionField myreq = CThostFtdcQryInvestorPositionField();
memset(&myreq, 0, sizeof(myreq));
getChar(req, "instID", myreq.instID);
getChar(req, "traderID", myreq.traderID);
getChar(req, "memberID", myreq.memberID);
getChar(req, "clientID", myreq.clientID);
getChar(req, "marketID", myreq.marketID);
int i = this->api->ReqQryInvestorPosition(&myreq, nRequestID);
return i;
};
int TdApi::reqQryTradingAccount(dict req, int nRequestID)
{
CThostFtdcQryTradingAccountField myreq = CThostFtdcQryTradingAccountField();
memset(&myreq, 0, sizeof(myreq));
getChar(req, "remian", myreq.remian);
int i = this->api->ReqQryTradingAccount(&myreq, nRequestID);
return i;
};
int TdApi::reqQryTrade(dict req, int nRequestID)
{
CThostFtdcQryTradeField myreq = CThostFtdcQryTradeField();
memset(&myreq, 0, sizeof(myreq));
getChar(req, "exchangeID", myreq.exchangeID);
getChar(req, "instID", myreq.instID);
getChar(req, "localOrderNo", myreq.localOrderNo);
getChar(req, "traderID", myreq.traderID);
getChar(req, "memberID", myreq.memberID);
getChar(req, "clientID", myreq.clientID);
getChar(req, "marketID", myreq.marketID);
getChar(req, "matchNo", myreq.matchNo);
getChar(req, "orderNo", myreq.orderNo);
getChar(req, "marketID", myreq.marketID);
int i = this->api->ReqQryTrade(&myreq, nRequestID);
return i;
};
@ -1462,16 +1372,9 @@ int TdApi::reqQryOrder(dict req, int nRequestID)
{
CThostFtdcQryOrderField myreq = CThostFtdcQryOrderField();
memset(&myreq, 0, sizeof(myreq));
getUnsignedChar(req, "status", &myreq.status);
getChar(req, "exchangeID", myreq.exchangeID);
getUnsignedChar(req, "offsetFlag", &myreq.offsetFlag);
getChar(req, "instID", myreq.instID);
getChar(req, "localOrderNo", myreq.localOrderNo);
getChar(req, "traderID", myreq.traderID);
getChar(req, "memberID", myreq.memberID);
getChar(req, "clientID", myreq.clientID);
getChar(req, "marketID", myreq.marketID);
getChar(req, "orderNo", myreq.orderNo);
int i = this->api->ReqQryOrder(&myreq, nRequestID);
return i;
};
@ -1480,9 +1383,7 @@ int TdApi::reqQryStorage(dict req, int nRequestID)
{
CThostFtdcQryStorageField myreq = CThostFtdcQryStorageField();
memset(&myreq, 0, sizeof(myreq));
getChar(req, "traderID", myreq.traderID);
getChar(req, "memberID", myreq.memberID);
getChar(req, "clientID", myreq.clientID);
getChar(req, "varietyID", myreq.varietyID);
int i = this->api->ReqQryStorage(&myreq, nRequestID);
return i;
};
@ -1713,7 +1614,7 @@ struct TdApiWrap : TdApi, wrapper < TdApi >
};
BOOST_PYTHON_MODULE(vnctptd)
BOOST_PYTHON_MODULE(vnksgoldtd)
{
PyEval_InitThreads(); //导入时运行保证先创建GIL
@ -1726,6 +1627,8 @@ BOOST_PYTHON_MODULE(vnctptd)
.def("registerFront", &TdApiWrap::registerFront)
.def("reqUserLogin", &TdApiWrap::reqUserLogin)
.def("reqUserLogout", &TdApiWrap::reqUserLogout)
.def("subscribeMarketData", &TdApiWrap::subscribeMarketData)
.def("unSubscribeMarketData", &TdApiWrap::unSubscribeMarketData)
.def("reqUserReLogin", &TdApiWrap::reqUserReLogin)
.def("reqQryInstrument", &TdApiWrap::reqQryInstrument)
.def("reqOrderInsert", &TdApiWrap::reqOrderInsert)

View File

@ -16,7 +16,7 @@
#include <boost/python/module.hpp> //python封装
#include <boost/python/def.hpp> //python封装
#include <boost/python/dict.hpp> //python封装
#include <boost/python/object.hpp> //python·â×°
#include <boost/python/object.hpp> //python·â×°
#include <boost/python.hpp> //python封装
#include <boost/thread.hpp> //任务队列的线程功能
#include <boost/bind.hpp> //任务队列的线程功能
@ -24,6 +24,7 @@
//API
#include "GoldTradeApi.h"
#include "Constant.h"
//命名空间
using namespace std;
@ -195,7 +196,6 @@ public:
///请求查询合约响应
virtual void OnRspQryInstrument(CThostFtdcInstrumentField *pInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
///深度行情通知
virtual void OnRtnDepthMarketData(CThostFtdcDepthMarketDataField *pDepthMarketData);
@ -206,7 +206,8 @@ public:
virtual void OnErrRtnOrderInsert(CThostFtdcInputOrderField *pInputOrder, CThostFtdcRspInfoField *pRspInfo);
///报单通知
virtual void OnRtnOrder(CThostFtdcOrderField *pOrder);
//virtual void OnRtnOrder(CThostFtdcOrderField *pOrder); //´íÎó
virtual void OnRtnOrder(CThostFtdcOrderRtnField *pOrder);
//强退通知
virtual void OnForceLogout(CThostFtdcUserLogoutField *pLogout);
@ -355,6 +356,10 @@ public:
int reqUserReLogin();
int subscribeMarketData(string instrumentID);
int unSubscribeMarketData(string instrumentID);
int reqQryInstrument(dict req, int nRequestID);
int reqOrderInsert(dict req, int nRequestID);

Binary file not shown.

View File

View File

@ -80,6 +80,8 @@ class CtpGateway(VtGateway):
"""连接"""
# 载入json文件
fileName = self.gatewayName + '_connect.json'
fileName = os.getcwd() + '\\ctpGateway\\' + fileName
try:
f = file(fileName)
except IOError:

View File

View File

@ -78,6 +78,8 @@ class FemasGateway(VtGateway):
"""连接"""
# 载入json文件
fileName = self.gatewayName + '_connect.json'
fileName = os.getcwd() + '\\femasGateway\\' + fileName
try:
f = file(fileName)
except IOError:

View File

View File

@ -132,6 +132,8 @@ class IbGateway(VtGateway):
"""连接"""
# 载入json文件
fileName = self.gatewayName + '_connect.json'
fileName = os.getcwd() + '\\ibGateway\\' + fileName
try:
f = file(fileName)
except IOError:

View File

@ -0,0 +1,5 @@
{
"address": "tcp://124.74.239.38:18961",
"password": "请联系浦发银行申请",
"accountID": "请联系浦发银行申请"
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,19 @@
-----BEGIN CERTIFICATE-----
MIIDBTCCAe0CCQDlZanJ47kXxzANBgkqhkiG9w0BAQUFADCBjzELMAkGA1UEBhMC
Y24xETAPBgNVBAgTCHNoYW5naGFpMREwDwYDVQQHEwhzaGFuZ2hhaTERMA8GA1UE
ChMIa2luZ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Info: DES-EDE3-CBC,88F693FD0F362212
FASYVUUP5rX7H1jkrladPQxTmdjfQ1gCOL/GtityDevQhoU5KHieG+EzpZIBKX/e
KAjtf0bwbT4zsbovlZuFGGM8ok1Myp1bHl7ye9+ZfA527u2sH028mw1HYv6OwvH1
fQ0tSX6kyAvvv6FdkiFhD3CGtnJa1QvXotHhTi3qE1A/bimnHypZW87u/naHlxEL
jG56cCmlKuO3FNPkXFl09VrPRBy2aF+7g/qzAEEUaL3Ua8QHyX16AfzA20WSgWzE
JyrOTIAf70hT+edeR9OzYBs5j4GNhetZB1dVCg1JjsnF/wVIUOWvPN5eC2vp9Ntg
q5+b3yHLwEqy8J2bg45RF724U7d7JdhP7REhISFtrp+PNn10awJG9azcOUN1LbkA
ncvuRUfbptRKYwIuYvihmPB6HCrIFlE2mv/ehaUd4leEaLJ7PRW622wpSUXa50Pf
GEVC8Tr+T5Vgut5+FyOEqw1w6k+Z9CWUc1cafnc9IVI6HDLSnB+cOTFoi3BTIeci
l4TbUO683o9I66MbTF+Wsu0OQ/2f353GbptTH44/0bnMIWTPhf/k4MH23p/doUej
4N78UorNWv5sl4WKOo8/f4IC8MEk+QXkwHHrcu5ix5E83yDRYN/JNmaZ9OdST0J3
MF09yLwd46QzrVVCmvu5T840PIWlbht27InGEYDxbIaJ8V4oqoJP4pUnqOxG3lT9
BPQOnk1uo5k4On+oKpGyAAqaOyLjOh/bEGbFYgCZ9fPKPRwXpSzsSh2xZW1U+dlL
R4W3/0LdjY/HXQhM92lHVe8iFEh07O1umNgw0W/rP9sjkAS3yyjxpw==
-----END RSA PRIVATE KEY-----

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,16 @@
[SafePolicy]
;索引 = 安全策略名称
1 = 动态令牌
2 = 数字证书
[SafeSupplier]
;索引 = 厂商简称,标识,接口是否需要提供私钥密码
1 = 上海ECA,SHECA,1
2 = 上海动联,DCDT,1
3 = 金仕达SSL,KSCA,1
[SupplierPolicy]
;索引 =厂商索引,安全策略索引
1 = 3,2

Binary file not shown.

View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,799 @@
# encoding: UTF-8
'''
vn.ksgold的gateway接入
金仕达黄金接口在用户登录后并不提供之前的Order和Trade数据主动推送
而是需要用户自行查询因此API里做了初始化后的查询设计
'''
import os
import json
import time
from vnksgoldtd import TdApi
from ksgoldDataType import *
from vtGateway import *
# 价格类型映射
#priceTypeMap = {}
#priceTypeMap[PRICETYPE_LIMITPRICE] = defineDict["THOST_FTDC_OPT_LimitPrice"]
#priceTypeMap[PRICETYPE_MARKETPRICE] = defineDict["THOST_FTDC_OPT_AnyPrice"]
#priceTypeMapReverse = {v: k for k, v in priceTypeMap.items()}
# 以下类型映射参考的是原生API里的Constant.h
# 方向类型映射
directionMap = {}
directionMap[DIRECTION_LONG] = '0'
directionMap[DIRECTION_SHORT] = '1'
directionMapReverse = {v: k for k, v in directionMap.items()}
# 开平类型映射
offsetMap = {}
offsetMap[OFFSET_OPEN] = '0'
offsetMap[OFFSET_CLOSE] = '1'
offsetMapReverse = {v:k for k,v in offsetMap.items()}
########################################################################
class KsgoldGateway(VtGateway):
"""金仕达黄金接口"""
#----------------------------------------------------------------------
def __init__(self, eventEngine, gatewayName='KSGOLD'):
"""Constructor"""
super(KsgoldGateway, self).__init__(eventEngine, gatewayName)
self.tdApi = KsgoldTdApi(self) # 黄金接口只有交易API
self.tdConnected = False # 交易API连接状态
self.qryEnabled = False # 是否要启动循环查询
self.orderInited = False # 委托初始化查询
self.tradeInited = False # 成交初始化查询
#----------------------------------------------------------------------
def connect(self):
"""连接"""
# 载入json文件
fileName = self.gatewayName + '_connect.json'
fileName = os.getcwd() + '\\ksgoldGateway\\' + fileName
try:
f = file(fileName)
except IOError:
log = VtLogData()
log.gatewayName = self.gatewayName
log.logContent = u'读取连接配置出错,请检查'
self.onLog(log)
return
# 解析json文件
setting = json.load(f)
try:
accountID = str(setting['accountID'])
password = str(setting['password'])
address = str(setting['address'])
except KeyError:
log = VtLogData()
log.gatewayName = self.gatewayName
log.logContent = u'连接配置缺少字段,请检查'
self.onLog(log)
return
# 创建行情和交易接口对象
self.tdApi.connect(accountID, password, address)
# 初始化并启动查询
self.initQuery()
#----------------------------------------------------------------------
def subscribe(self, subscribeReq):
"""订阅行情"""
self.tdApi.subscribe(subscribeReq)
#----------------------------------------------------------------------
def sendOrder(self, orderReq):
"""发单"""
return self.tdApi.sendOrder(orderReq)
#----------------------------------------------------------------------
def cancelOrder(self, cancelOrderReq):
"""撤单"""
self.tdApi.cancelOrder(cancelOrderReq)
#----------------------------------------------------------------------
def getAccount(self):
"""查询账户资金"""
self.tdApi.getAccount()
#----------------------------------------------------------------------
def getPosition(self):
"""查询持仓"""
self.tdApi.getPosition()
#----------------------------------------------------------------------
def close(self):
"""关闭"""
if self.mdConnected:
self.mdApi.close()
if self.tdConnected:
self.tdApi.close()
#----------------------------------------------------------------------
def initQuery(self):
"""初始化连续查询"""
# 需要循环的查询函数列表
self.qryFunctionList = [self.getAccount, self.getPosition]
self.qryCount = 0 # 查询触发倒计时
self.qryTrigger = 2 # 查询触发点
self.qryNextFunction = 0 # 上次运行的查询函数索引
#----------------------------------------------------------------------
def query(self, event):
"""注册到事件处理引擎上的查询函数"""
self.qryCount += 1
if self.qryCount > self.qryTrigger:
# 清空倒计时
self.qryCount = 0
# 如果尚未完成委托查询则先查询委托
if not self.orderInited:
self.tdApi.getOrder()
# 然后如果未完成成交查询则再查询成交
elif not self.tradeInited:
self.tdApi.getTrade()
else:
# 执行查询函数
function = self.qryFunctionList[self.qryNextFunction]
function()
# 计算下次查询函数的索引如果超过了列表长度则重新设为0
self.qryNextFunction += 1
if self.qryNextFunction == len(self.qryFunctionList):
self.qryNextFunction = 0
#----------------------------------------------------------------------
def startQuery(self):
"""启动连续查询"""
if self.qryEnabled:
self.eventEngine.register(EVENT_TIMER, self.query)
#----------------------------------------------------------------------
def setQryEnabled(self, qryEnabled):
"""设置是否要启动循环查询"""
self.qryEnabled = qryEnabled
########################################################################
class KsgoldTdApi(TdApi):
"""金仕达黄金交易API实现"""
#----------------------------------------------------------------------
def __init__(self, gateway):
"""API对象的初始化函数"""
super(KsgoldTdApi, self).__init__()
self.gateway = gateway # gateway对象
self.gatewayName = gateway.gatewayName # gateway对象名称
self.reqID = EMPTY_INT # 操作请求编号
self.orderRef = EMPTY_INT # 订单编号
self.connectionStatus = False # 连接状态
self.loginStatus = False # 登录状态
self.accountID = EMPTY_STRING # 账号
self.password = EMPTY_STRING # 密码
self.memberID = EMPTY_STRING # 会员代码(应该是银行)
self.address = EMPTY_STRING # 服务器地址
self.seatID = EMPTY_STRING; # 席位号
self.tradeCode = EMPTY_STRING # 交易编码
self.subscribedSymbols = set() # 已订阅合约代码
self.orderDict = {} # 委托字典用于缓存委托对象key为整数
# 循环登录相关
self.loginThread = None
#----------------------------------------------------------------------
def onFrontConnected(self):
"""服务器连接"""
self.connectionStatus = True
log = VtLogData()
log.gatewayName = self.gatewayName
log.logContent = u'交易服务器连接成功'
self.gateway.onLog(log)
self.login()
#----------------------------------------------------------------------
def onFrontDisconnected(self, n):
"""服务器断开"""
self.connectionStatus = False
self.loginStatus = False
self.gateway.tdConnected = False
log = VtLogData()
log.gatewayName = self.gatewayName
log.logContent = u'交易服务器连接断开'
self.gateway.onLog(log)
#----------------------------------------------------------------------
def onRspUserLogin(self, data, error, n, last):
"""登陆回报"""
# 如果登录成功,推送日志信息
if error['ErrorID'] == 0:
self.seatID = str(data['SeatNo'])
self.tradeCode = str(data['tradeCode'])
self.loginStatus = True
self.gateway.tdConnected = True
log = VtLogData()
log.gatewayName = self.gatewayName
log.logContent = u'交易服务器登录完成'
self.gateway.onLog(log)
# 重新订阅之前订阅的合约
for subscribeReq in self.subscribedSymbols:
self.subscribe(subscribeReq)
# 查询合约信息
self.reqID += 1
self.reqQryInstrument({}, self.reqID)
# 启动查询
self.gateway.startQuery()
# 否则,推送错误信息
else:
err = VtErrorData()
err.gatewayName = self.gatewayName
err.errorID = error['ErrorID']
err.errorMsg = error['ErrorMsg'].decode('gbk')
self.gateway.onError(err)
if error['ErrorID'] == -8:
self.login()
#----------------------------------------------------------------------
def onRspUserLogout(self, data, error, n, last):
"""登出回报"""
# 如果登出成功,推送日志信息
if error['ErrorID'] == 0:
self.loginStatus = False
self.gateway.tdConnected = False
log = VtLogData()
log.gatewayName = self.gatewayName
log.logContent = u'交易服务器登出完成'
self.gateway.onLog(log)
# 否则,推送错误信息
else:
err = VtErrorData()
err.gatewayName = self.gatewayName
err.errorID = error['ErrorID']
err.errorMsg = error['ErrorMsg'].decode('gbk')
self.gateway.onError(err)
#----------------------------------------------------------------------
def onNtyMktStatus(self, data, error, n, last):
"""更新市场状态"""
pass
#----------------------------------------------------------------------
def onRspOrderInsert(self, data, error, n, last):
"""发单错误(柜台)"""
if error['ErrorID']:
err = VtErrorData()
err.gatewayName = self.gatewayName
err.errorID = error['ErrorID']
err.errorMsg = error['ErrorMsg'].decode('gbk')
self.gateway.onError(err)
#----------------------------------------------------------------------
def onRspOrderAction(self, data, error, n, last):
"""撤单错误(柜台)"""
if error['ErrorID']:
err = VtErrorData()
err.gatewayName = self.gatewayName
err.errorID = error['ErrorID']
err.errorMsg = error['ErrorMsg'].decode('gbk')
self.gateway.onError(err)
#----------------------------------------------------------------------
def onRspQryOrder(self, data, error, n, last):
""""""
if not self.gateway.orderInited:
self.gateway.orderInited = True
log = VtLogData()
log.gatewayName = self.gatewayName
log.logContent = u'委托查询完成'
self.gateway.onLog(log)
# 更新最大报单编号
newref = data['localOrderNo']
self.orderRef = max(self.orderRef, int(newref))
# 创建报单数据对象
order = VtOrderData()
order.gatewayName = self.gatewayName
# 保存代码和报单号
order.symbol = data['instID']
order.exchange = EXCHANGE_SGE
order.vtSymbol = order.symbol
order.orderID = data['localOrderNo']
# 方向
if data['buyOrSell'] == '0':
order.direction = DIRECTION_LONG
elif data['buyOrSell'] == '1':
order.direction = DIRECTION_SHORT
else:
order.direction = DIRECTION_UNKNOWN
# 开平
if data['offsetFlag'] == '0':
order.offset = OFFSET_OPEN
elif data['offsetFlag'] == '1':
order.offset = OFFSET_CLOSE
else:
order.offset = OFFSET_UNKNOWN
# 状态
if data['status'] == '5':
order.status = STATUS_ALLTRADED
elif data['status'] == '6':
order.status = STATUS_PARTTRADED
elif data['status'] == '3':
order.status = STATUS_NOTTRADED
elif data['status'] == '4' or data['status'] == '7': # 全部撤销和部成部撤
order.status = STATUS_CANCELLED
else:
order.status = STATUS_UNKNOWN
# CTP的报单号一致性维护需要基于frontID, sessionID, orderID三个字段
# 但在本接口设计中已经考虑了CTP的OrderRef的自增性避免重复
# 唯一可能出现OrderRef重复的情况是多处登录并在非常接近的时间内几乎同时发单
# 考虑到VtTrader的应用场景认为以上情况不会构成问题
order.vtOrderID = '.'.join([self.gatewayName, order.orderID])
# 价格、报单量等数值
order.price = data['price']
order.totalVolume = data['amount']
order.tradedVolume = data['matchQty']
order.orderTime = data['entrustTime']
order.cancelTime = data['cancelTime']
# 推送
self.gateway.onOrder(order)
#----------------------------------------------------------------------
def onRspQryTrade(self, data, error, n, last):
""""""
if not self.gateway.tradeInited:
self.gateway.tradeInited = True
log = VtLogData()
log.gatewayName = self.gatewayName
log.logContent = u'成交查询完成'
self.gateway.onLog(log)
# 创建报单数据对象
trade = VtTradeData()
trade.gatewayName = self.gatewayName
# 保存代码和报单号
trade.symbol = data['instID']
trade.exchange = EXCHANGE_SGE
trade.vtSymbol = trade.symbol
trade.tradeID = data['matchNo']
trade.vtTradeID = '.'.join([self.gatewayName, trade.tradeID])
trade.orderID = data['localOrderNo']
trade.vtOrderID = '.'.join([self.gatewayName, trade.orderID])
# 方向
trade.direction = directionMapReverse.get(data['buyOrSell'], '')
# 开平
trade.offset = offsetMapReverse.get(data['offSetFlag'], '')
# 价格、报单量等数值
trade.price = data['price']
trade.volume = data['volume']
trade.tradeTime = data['matchTime']
# 推送
self.gateway.onTrade(trade)
#----------------------------------------------------------------------
def onRspQryInvestorPosition(self, data, error, n, last):
"""持仓查询回报"""
# 过滤一些空的数据
if data['instID']:
# 黄金API推送的持仓数据把多空仓放在了一条中需要分离
longPos = VtPositionData()
longPos.gatewayName = self.gatewayName
longPos.symbol = data['instID']
longPos.vtSymbol = longPos.symbol
longPos.direction = DIRECTION_LONG
longPos.frozen = data['longPosiFrozen']
longPos.position = data['longPosiVol']
longPos.ydPosition = data['lastLong']
longPos.price = data['longPosiAvgPrice']
longPos.vtPositionName = '.'.join([longPos.vtSymbol, longPos.direction])
self.gateway.onPosition(longPos)
shortPos = VtPositionData()
shortPos.gatewayName = self.gatewayName
shortPos.symbol = data['instID']
shortPos.vtSymbol = shortPos.symbol
shortPos.direction = DIRECTION_SHORT
shortPos.frozen = data['shortPosiFrozen']
shortPos.position = data['shortPosiVol']
shortPos.ydPosition = data['lastShort']
shortPos.price = data['shortPosiAvgPrice']
shortPos.vtPositionName = '.'.join([shortPos.vtSymbol, shortPos.direction])
self.gateway.onPosition(shortPos)
#----------------------------------------------------------------------
def onRspQryTradingAccount(self, data, error, n, last):
"""资金账户查询回报"""
account = VtAccountData()
account.gatewayName = self.gatewayName
# 账户代码
account.accountID = 'sge_account' # API不提供该字段自行定义
account.vtAccountID = '.'.join([self.gatewayName, account.accountID])
# 数值相关
account.available = data['availCap']
account.commission = data['totalFee']
account.margin = data['posiMargin']
# 推送
self.gateway.onAccount(account)
#----------------------------------------------------------------------
def onRspQryInstrument(self, data, error, n, last):
"""合约查询回报"""
contract = VtContractData()
contract.gatewayName = self.gatewayName
contract.symbol = data['instID']
contract.exchange = EXCHANGE_SGE # 交易所只有金交所
# 合约类型分为现货、延期、未知
if data['marketID'] == '00':
contract.productClass = PRODUCT_SPOT
elif data['marketID'] == '10':
contract.productClass = PRODUCT_DEFER
else:
contract.productclass = PRODUCT_UNKNOWN
contract.vtSymbol = contract.symbol
contract.name = data['name'].decode('GBK')
# 合约数值
contract.size = data['unit']
contract.priceTick = data['tick']
# 推送考虑到只对T+D类带杠杆的产品感兴趣API里默认过滤了现货
if data['marketID'] == '10':
self.gateway.onContract(contract)
if last:
log = VtLogData()
log.gatewayName = self.gatewayName
log.logContent = u'交易合约信息获取完成'
self.gateway.onLog(log)
#----------------------------------------------------------------------
def onRtnDepthMarketData(self, data):
"""行情推送"""
tick = VtTickData()
tick.gatewayName = self.gatewayName
tick.symbol = data['InstID']
tick.vtSymbol = tick.symbol
tick.lastPrice = data['Last']
tick.volume = data['Volume']
tick.openInterest = data['OpenInt']
tick.time = data['QuoteTime']
tick.date = data['QuoteDate']
tick.openPrice = data['Open']
tick.highPrice = data['High']
tick.lowPrice = data['Low']
tick.preClosePrice = data['PreClose']
tick.upperLimit = data['highLimit']
tick.lowerLimit = data['lowLimit']
# CTP只有一档行情
tick.bidPrice1 = data['Bid1']
tick.bidPrice2 = data['Bid2']
tick.bidPrice3 = data['Bid3']
tick.bidPrice4 = data['Bid4']
tick.bidPrice5 = data['Bid5']
tick.askPrice1 = data['Ask1']
tick.askPrice2 = data['Ask2']
tick.askPrice3 = data['Ask3']
tick.askPrice4 = data['Ask4']
tick.askPrice5 = data['Ask5']
tick.bidVolume1 = data['BidLot1']
tick.bidVolume2 = data['BidLot2']
tick.bidVolume3 = data['BidLot3']
tick.bidVolume4 = data['BidLot4']
tick.bidVolume5 = data['BidLot5']
tick.askVolume1 = data['AskLot1']
tick.askVolume2 = data['AskLot2']
tick.askVolume3 = data['AskLot3']
tick.askVolume4 = data['AskLot4']
tick.askVolume5 = data['AskLot5']
self.gateway.onTick(tick)
#----------------------------------------------------------------------
def onRtnOrder(self, data):
"""报单回报"""
# 更新最大报单编号
newref = data['localOrderNo']
self.orderRef = max(self.orderRef, int(newref))
# 创建报单数据对象
order = self.orderDict.get(int(newref), VtOrderData())
order.gatewayName = self.gatewayName
order.exchange = EXCHANGE_SGE
order.orderID = data['localOrderNo']
# 状态
if data['status'] == '5':
order.status = STATUS_ALLTRADED
elif data['status'] == '6':
order.status = STATUS_PARTTRADED
elif data['status'] == '3':
order.status = STATUS_NOTTRADED
elif data['status'] == '4' or data['status'] == '7': # 全部撤销和部成部撤
order.status = STATUS_CANCELLED
else:
order.status = STATUS_UNKNOWN
# 推送
self.gateway.onOrder(order)
#----------------------------------------------------------------------
def onForceLogout(self, data):
"""强制登出推送"""
self.gateway.onLog(u'被强制登出')
#----------------------------------------------------------------------
def onRtnTrade(self, data):
"""成交回报"""
# 创建报单数据对象
trade = VtTradeData()
trade.gatewayName = self.gatewayName
# 保存代码和报单号
trade.symbol = data['instID']
trade.exchange = EXCHANGE_SGE
trade.vtSymbol = trade.symbol
trade.tradeID = data['matchNo']
trade.vtTradeID = '.'.join([self.gatewayName, trade.tradeID])
trade.orderID = data['localOrderNo']
trade.vtOrderID = '.'.join([self.gatewayName, trade.orderID])
# 方向
trade.direction = directionMapReverse.get(data['buyOrSell'], '')
# 开平
trade.offset = offsetMapReverse.get(data['offSetFlag'], '')
# 价格、报单量等数值
trade.price = data['price']
trade.volume = data['volume']
trade.tradeTime = data['matchTime']
# 推送
self.gateway.onTrade(trade)
# 计算还原Order状态并推送
order = self.orderDict.get(int(trade.orderID), None)
if order:
order.tradedVolume = order.tradedVolume + trade.volume
if order.tradedVolume == order.totalVolume:
order.status = STATUS_ALLTRADED
else:
order.status = STATUS_PARTTRADED
self.gateway.onOrder(order)
#----------------------------------------------------------------------
def onErrRtnOrderInsert(self, data, error):
"""发单错误回报(交易所)"""
if error['ErrorID']:
err = VtErrorData()
err.gatewayName = self.gatewayName
err.errorID = error['ErrorID']
err.errorMsg = error['ErrorMsg'].decode('gbk')
self.gateway.onError(err)
#----------------------------------------------------------------------
def onErrRtnOrderAction(self, data, error):
"""撤单错误回报(交易所)"""
if error['ErrorID']:
err = VtErrorData()
err.gatewayName = self.gatewayName
err.errorID = error['ErrorID']
err.errorMsg = error['ErrorMsg'].decode('gbk')
self.gateway.onError(err)
#----------------------------------------------------------------------
def onRspQryClientStorage(self, data, error, n, last):
""""""
pass
#----------------------------------------------------------------------
def onRspSubMarketData(self, data, error, n, last):
""""""
pass
#----------------------------------------------------------------------
def connect(self, accountID, password, address):
"""初始化连接"""
self.accountID = accountID
self.password = password
self.address = address
# 如果尚未建立服务器连接,则进行连接
if not self.connectionStatus:
self.createGoldTraderApi()
# 注册服务器地址
self.registerFront(self.address)
# 初始化连接成功会调用onFrontConnected
self.init(False)
self.connectionStatus = True
# 金仕达接口第一次连接不会调用onFrontConnected只有断线重连才会直接登录
self.login()
# 若已经连接但尚未登录,则进行登录
else:
if not self.loginStatus:
self.login()
#----------------------------------------------------------------------
def login(self):
"""连接服务器"""
# 如果填入了用户名密码等,则登录
if self.accountID and self.password:
req = {}
req['accountID'] = self.accountID
req['password'] = self.password
req['loginType'] = 1
self.reqID += 1
self.reqUserLogin(req, self.reqID)
#----------------------------------------------------------------------
def getAccount(self):
"""查询账户"""
self.reqID += 1
self.reqQryTradingAccount({}, self.reqID)
#----------------------------------------------------------------------
def getPosition(self):
"""查询持仓"""
self.reqID += 1
self.reqQryInvestorPosition({}, self.reqID)
#----------------------------------------------------------------------
def getTrade(self):
"""查询成交"""
self.reqID += 1
self.reqQryTrade({}, self.reqID)
#----------------------------------------------------------------------
def getOrder(self):
"""查询委托"""
self.reqID += 1
self.reqQryOrder({}, self.reqID)
#----------------------------------------------------------------------
def sendOrder(self, orderReq):
"""发单"""
self.reqID += 1
self.orderRef += 1
req = {}
req['instID'] = orderReq.symbol
req['marketID'] = '10'
req['price'] = orderReq.price
req['amount'] = orderReq.volume
# 下面如果由于传入的类型本接口不支持,则会返回空字符串
try:
req['buyOrSell'] = directionMap[orderReq.direction]
req['offsetFlag'] = offsetMap[orderReq.offset]
except KeyError:
return ''
strOrderID = generateStrLocalID(self.orderRef)
req['LocalOrderNo'] = strOrderID
req['seatID'] = self.seatID
req['tradeCode'] = self.tradeCode
self.reqOrderInsert(req, self.reqID)
# 返回订单号(字符串),便于某些算法进行动态管理
vtOrderID = '.'.join([self.gatewayName, strOrderID])
# 保存请求到本地,用于在收到回报时查询
# 金仕达黄金API的onRtnOrder只推送很有限的几个数据因此整个数据需要自己还原
order = VtOrderData()
order.gatewayName = self.gatewayName
order.symbol = orderReq.symbol
order.vtSymbol = orderReq.symbol
order.exchange = EXCHANGE_SGE
order.orderID = strOrderID
order.vtOrderID = strOrderID
order.direction = orderReq.direction
order.offset = orderReq.offset
order.price = orderReq.price
order.totalVolume = orderReq.volume
order.orderTime = time.strftime('%H:%M:%S') # 保存委托时间
self.orderDict[self.orderRef] = order
return vtOrderID
#----------------------------------------------------------------------
def cancelOrder(self, cancelOrderReq):
"""撤单"""
self.reqID += 1
req = {}
req['localOrderNo'] = cancelOrderReq.orderID
req['marketID'] = '10' # API默认只允许交易T+D延期
self.reqOrderAction(req, self.reqID)
#----------------------------------------------------------------------
def subscribe(self, subscribeReq):
"""订阅行情"""
# 黄金API的订阅传入的参数不是具体交易合约代码而是类型代码
# 考虑到只希望交易T+D这里直接传入'10'
self.subscribeMarketData('10')
#----------------------------------------------------------------------
def close(self):
"""关闭"""
self.exit()
#----------------------------------------------------------------------
def generateStrLocalID(localID):
"""把整数的本地委托号转化为字符串"""
return str(localID).rjust(12, '0')

View File

@ -0,0 +1,24 @@
[MemberInfo]
//会员代码
MemberID=0001
//超时设置
TimeOut = 15000
//保存网络最优秀或者客户选择的交易网关
SelectServer=1
//是否显示登录返回的信息(0-不显示 1-显示)
bShowLoginInfo=1
//日志开关(0-不记录日志 1-记录日志)
KLG_LOG=0
//标题显示的内容
Caption =SunGard KingStar 黄金交易简易客户端
//菜单root节点显示的名称
RootMenu=金仕达黄金交易
//交易网关配置
[GateWay]
GateWayName=交易网关
//交易网关IP地址, 也可以为域名
IPAddress=124.74.239.38
//端口,端口需要大于10000
Port=18961

Binary file not shown.

Binary file not shown.

View File

View File

@ -74,6 +74,8 @@ class KsotpGateway(VtGateway):
"""连接"""
# 载入json文件
fileName = self.gatewayName + '_connect.json'
fileName = os.getcwd() + '\\ksotpGateway\\' + fileName
try:
f = file(fileName)
except IOError:

View File

View File

@ -75,6 +75,8 @@ class LtsGateway(VtGateway):
"""连接"""
# 载入json 文件
fileName = self.gatewayName + '_connect.json'
fileName = os.getcwd() + '\\ltsGateway\\' + fileName
try:
f = file(fileName)
except IOError:

View File

@ -83,6 +83,9 @@ class MainWindow(QtGui.QMainWindow):
connectFemasAction = QtGui.QAction(u'连接飞马', self)
connectFemasAction.triggered.connect(self.connectFemas)
connectKsgoldAction = QtGui.QAction(u'连接金仕达黄金', self)
connectKsgoldAction.triggered.connect(self.connectKsgold)
connectWindAction = QtGui.QAction(u'连接Wind', self)
connectWindAction.triggered.connect(self.connectWind)
@ -93,7 +96,7 @@ class MainWindow(QtGui.QMainWindow):
connectDbAction.triggered.connect(self.mainEngine.dbConnect)
testAction = QtGui.QAction(u'测试', self)
testAction.triggered.connect(self.testSubscribe)
testAction.triggered.connect(self.test)
exitAction = QtGui.QAction(u'退出', self)
exitAction.triggered.connect(self.close)
@ -113,14 +116,15 @@ class MainWindow(QtGui.QMainWindow):
sysMenu = menubar.addMenu(u'系统')
sysMenu.addAction(connectCtpAction)
sysMenu.addAction(connectLtsAction)
sysMenu.addAction(connectKsotpAction)
sysMenu.addAction(connectFemasAction)
sysMenu.addAction(connectIbAction)
sysMenu.addAction(connectKsotpAction)
sysMenu.addAction(connectKsgoldAction)
sysMenu.addAction(connectIbAction)
sysMenu.addSeparator()
sysMenu.addAction(connectWindAction)
sysMenu.addSeparator()
sysMenu.addAction(connectDbAction)
sysMenu.addSeparator()
sysMenu.addAction(testAction)
sysMenu.addAction(exitAction)
functionMenu = menubar.addMenu(u'功能')
@ -132,7 +136,8 @@ class MainWindow(QtGui.QMainWindow):
# 帮助
helpMenu = menubar.addMenu(u'帮助')
helpMenu.addAction(aboutAction)
helpMenu.addAction(aboutAction)
helpMenu.addAction(testAction)
#----------------------------------------------------------------------
def initStatusBar(self):
@ -182,6 +187,11 @@ class MainWindow(QtGui.QMainWindow):
def connectFemas(self):
"""连接飞马接口"""
self.mainEngine.connect('FEMAS')
#----------------------------------------------------------------------
def connectKsgold(self):
"""连接金仕达黄金接口"""
self.mainEngine.connect('KSGOLD')
#----------------------------------------------------------------------
def connectWind(self):
@ -194,31 +204,13 @@ class MainWindow(QtGui.QMainWindow):
self.mainEngine.connect('IB')
#----------------------------------------------------------------------
def testSubscribe(self):
"""测试订阅"""
api = self.mainEngine.gatewayDict['LTS'].qryApi
def test(self):
"""测试按钮用的函数"""
api = self.mainEngine.gatewayDict['KSGOLD'].tdApi
api.reqID += 1
api.reqQryOFInstrument({}, api.reqID)
#req = VtSubscribeReq()
#req.symbol = 'GOOG'
#req.productClass = PRODUCT_EQUITY
#req.exchange = EXCHANGE_SMART
#req.currency = CURRENCY_USD
#self.mainEngine.subscribe(req, 'IB')
#req.symbol = 'AAPL'
#self.mainEngine.subscribe(req, 'IB')
#req.symbol = 'YHOO'
#self.mainEngine.subscribe(req, 'IB')
#req.symbol = 'MSFT'
#self.mainEngine.subscribe(req, 'IB')
#req.symbol = 'GE'
#self.mainEngine.subscribe(req, 'IB')
api.reqQryOrder({}, api.reqID)
#api.reqQryTrade({}, api.reqID)
#----------------------------------------------------------------------
def openAbout(self):
"""打开关于"""

View File

@ -37,6 +37,8 @@ PRODUCT_INDEX = u'指数'
PRODUCT_COMBINATION = u'组合'
PRODUCT_FOREX = u'外汇'
PRODUCT_UNKNOWN = u'未知'
PRODUCT_SPOT = u'现货'
PRODUCT_DEFER = u'延期'
# 价格类型常量
PRICETYPE_LIMITPRICE = u'限价'
@ -55,7 +57,7 @@ EXCHANGE_CFFEX = 'CFFEX' # 中金所
EXCHANGE_SHFE = 'SHFE' # 上期所
EXCHANGE_CZCE = 'CZCE' # 郑商所
EXCHANGE_DCE = 'DCE' # 大商所
EXCHANGE_SGE = 'SGE' # 上金所
EXCHANGE_UNKNOWN = 'UNKNOWN'# 未知交易所
EXCHANGE_NONE = '' # 空交易所

View File

@ -32,41 +32,48 @@ class MainEngine(object):
# 创建我们想要接入的接口对象
try:
from ctpGateway import CtpGateway
from ctpGateway.ctpGateway import CtpGateway
self.addGateway(CtpGateway, 'CTP')
self.gatewayDict['CTP'].setQryEnabled(True)
except Exception, e:
print e
try:
from ltsGateway import LtsGateway
from ltsGateway.ltsGateway import LtsGateway
self.addGateway(LtsGateway, 'LTS')
self.gatewayDict['LTS'].setQryEnabled(True)
except Exception, e:
print e
try:
from ksotpGateway import KsotpGateway
from ksotpGateway.ksotpGateway import KsotpGateway
self.addGateway(KsotpGateway, 'KSOTP')
self.gatewayDict['KSOTP'].setQryEnabled(True)
except Exception, e:
print e
try:
from femasGateway import FemasGateway
from femasGateway.femasGateway import FemasGateway
self.addGateway(FemasGateway, 'FEMAS')
self.gatewayDict['FEMAS'].setQryEnabled(True)
except Exception, e:
print e
try:
from windGateway import WindGateway
from ksgoldGateway.ksgoldGateway import KsgoldGateway
self.addGateway(KsgoldGateway, 'KSGOLD')
self.gatewayDict['KSGOLD'].setQryEnabled(True)
except Exception, e:
print e
try:
from windGateway.windGateway import WindGateway
self.addGateway(WindGateway, 'Wind')
except Exception, e:
print e
try:
from ibGateway import IbGateway
from ibGateway.ibGateway import IbGateway
self.addGateway(IbGateway, 'IB')
except Exception, e:
print e

View File