ctp手册

更新时间:2024-05-29 14:59:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

CTP交易报告 ——应用编程手册

1、历年版本

版本:v4.2 时间:2009-11-6 备注:英文版

2、索引

第一章 简介

1.1 背景

1.2 API文件介绍 第二章 结构 2.1 通讯模式 2.2 数据流

第三章 编程接口类型

3.1 对话模式的编程接口 3.2 私有模式的编程接口 3.3 广播模式的编程接口

第一章 介绍

综合交易平台(Comprehensive Transaction Platform),是专门为期货公司开发的一套期货经纪业务管理系统,由交易、风险控制和结算三大系统组成。

API,实现了客户端和综合交易平台之间的通讯。通过API,投资者可以接收来自上交所,大商所和郑商所的行情数据,发送交易指令,接收相应的反馈和交易状态等信息。

1.1 背景

2006年,上海金融期货交易所完成了新一代交易系统的开发,我们借助其成功经验,开发了CTP。

2007年4月,我们获得了来自中国期货公司交易的第一笔订单。通过近三年的不懈努力, 使用CTP的投资者遍布全球,国内使用CTP的期货公司已到达30家。

1.2 API文件

CTP上使用的API是基于C++程序库,来实现客户端和CTP服务器之间的数据传输。客户端包括,所有投资者都可以使用的CTP标准客户端(比如,Q7,popo,weisoft等第三方开发的客户端),以及个性化交易工具(由投资者个人或其合作者开发)。通过API,客户端可以发出或撤销普通单、条件单、查询委托或交易状态、查询账户实时信息和交易头寸。API程序库包括:

注:使用MS VC 6.0,MS VC.NET 2003等编程工具的,需要在编程设置中打开“multi-thread”选项。

第二章 结构

CTP的API和CTP服务器之间使用的通讯协议是期货交易数据协议(futures TradingData Exchange protocol ,FTD),它基于TCP协议。

2.1 通讯模式

在FTD协议中,通讯模式包括以下三种模式:

?对话模式,客户端给CTP发送请求,CTP将会相应返回结果。

?私有模式,CTP把特定的私人信息发送给对应的客户端,包括持仓信息、

交易确认信息等。

?广播模式,CTP将把公告等信息发送给所有的注册用户。

每种模式并不限于一种连接状态。也就是说,建立一种连接之后,客户端可以同时使用三种通讯模式 ,或者建立集中不同的连接之后,客户端也可以使用同样的通讯模式。比如,客户可以使用广播模式来接收设备状态的变动信息,同时也可接收私人信息(如下单确认等)。

下图描绘了三种通讯模式的工作流程:

2.2 数据流

CTP提供了对话、私有、广播等三种通讯模式。在对话模式中,传输的是对话数据流和查询数据流。

对话和查询数据流是双向数据流,客户端发出请求,CTP服务器返回结果。CTP服务器并不保存对话和查询数据流。当故障发生时,比如连接中断后又重新连接,对话和查询数据流将回复原值,之间传输的数据将丢失。

在私人通讯模式中,传输的是私人数据流。私人数据流是单向数据流,CTP服务器就是利用它来把相应的私人信息发给提出申请的客户端。私人信息包括,风险提示、指令状态、指令确认、交易确认等。私人数据流是可靠的。当客户端和CTP服务器失去连接后,在同一交易日的任何时间,客户端都可重新连上CTP服务器,获取一系列指定的私人信息而不用担心这些数据会丢失。

在广播通讯模式中,传输的是公共数据流。和私人数据流一样,它是单向数据流,而且可靠。区别在于,广播通讯数据会发送到所有连接的客户端上。它的主要用途就是发布公共设备的状态信息或重要的公共信息。

第三章 编程接口类型

CTP的交易API提供了两种编程接口:CThostFtdcTraderApi 与CThostFtdcTraderSpi。行情API提供的是CThostFtdcMdApi 与 CThostFtdcMdSpi等两种编程接口。这四种接口遵循FTD协议。客户端可使用CThostFtdcXXXApi来发送请求,并通过CThostFtdcXXXSpi来接收CTP返回的数据。

3.1 对话模式的编程接口

对话模式的通讯函数常常这样定义:

Request函数的第一个参数是请求的内容,不能为空。第二个参数是请求的ID,由client trade application保管,并且最好独一无二,这样,当客户端从CTP服务器接收到数据时,客户端可以用同一个ID重新建立请求并获得反馈。

当客户端收到CTP服务器发出的反馈时,callback函数CThostFtdcXXXSpi被激活。如果反馈多于一条,callback函数CThostFtdcXXXSpi会反复被激活,直到数据全部接收完毕。

Response函数的第一个参数是反馈的数据,它一般包括最初的请求数据。如

果故障发生或CTP不能找到请求的记录,那么这个参数就是空值。第二个参数是CTP用来判断反馈是否成功的一个标识。当callback函数被激活的次数超过一次,除第一次被激活外,其他callback过程发生时第二个参数的值均为空。第三个参数是反馈的ID,作用和Request函数中的一样。最后一个参数是结束标识,其值为“true”时表示进行的是该请求的最后一个反馈。

3.2 私有模式的编程接口

下面的例子为私有模式的常用接口:

在私有模式里并没有连接API与CTP服务器的行情函数。

当CTP服务器发出私有数据流时, CThostFtdcTradeSpi的callback函数将被激活。

所有callback函数的第一个参数都是CTP服务器返回的内容。

OnErrRtnCThostFtdcTradeSpi 函数的第二个参数是报错时详细的错误信息。

3.3 广播模式的编程接口

使用广播模式时,客户端可以用以下两种方式与CTP服务器进行通讯:

callback函数OnRtnInstrumentStatus 用于通知客户端设备状态的变化。 callback函数OnRtnDepthMarketData用于公布最新的交易所行情数据。

第四章 运作模式

4.1 工作线程

CTP客户端进程需要两种线程,一是应用程序线程,另一种是交易API工作线程。如果客户端想要接收行情数据,那么也需要行情API工作线程。API工作线程连接了客户端和CTP服务器。

交易API和行情API是安全线程,客户端的应用程序可以同时使用两种或多种的工作线程,而无须担心线程冲突。客户单的应用程序要能尽快的处理callback信息,这样才能避免未处理的callback信息堵塞工作线程。要避免通讯堵塞,客户端的应用程序需要使用缓冲层来储存从CTP接收的数据,当然缓冲层也可以用来保护客户端自有数据,以便使之与CTP API的数据区分开。

4.2 文件

CTP API 的动态链接数据库会产生一些文件来储存运行过程中的数据,这些文件的后缀名为“.con”。交易客户端的应用程序通过CreateFtdcTraderApi() 或CreateFtdcMdApi() 函数的第一个参数来判断这些文件的本地路径。

4.3 商业术语与接口函数对比

第五章 CTP API 特别说明

5.1 一般规则

客户端应用程序需要经过两步才能连接到CTP服务器:初始化与功能启用。 使用交易API,客户端交易应用程序需要编写: (1)创建一个“CThostFtdcTraderApi”实例。

(2)创建一个处理来自“CThostFtdcTraderSpi”接口的事件处理器,然后使用“CThostFtdcTraderApi”的“RegisterSpi”函数记录下这些事件。

(3)使用“CThostFtdcTraderApi”的“SubscribePrivateTopic”函数处理私有数据流。

(4)使用“CThostFtdcTraderApi”的“SubscribePublicTopic” 函数处理公共数据流。

(5)使用“CThostFtdcTraderApi”的“RegisterFront” 函数记录CTP服务器的前端地址。客户端多运行几次这种函数,以便与服务器建立更可靠的联系。强烈建议。

(6)使用“CThostFtdcTraderApi”的“Init“函数来连接CTP服务器。 (7)服务器连上之后,“CThostFtdcTraderSpi”接口的callback函数“OnFrontConnected”将被激活。函数运行过程中,客户端的应用程序需要使用“CThostFtdcTraderApi”的“ReqUserLogin” 函数来提交“login”请求。

(8)当CTP服务器确认登陆成功后,“CThostFtdcTraderSpi”接口的callback 函数“OnRspUserLogin” 将被激活。

(9)这样,客户端与CTP服务器的通讯就建立起来了。客户端交易应用程序可以使用其他CTP API来与CTP服务器进行通讯。

如果客户端应用程序需要使用行情API,客户端需要采取以下步骤来描述先前的数据流,不包括私有数据流和公共信息流。具体如下:

(1)所有request函数的参数都不能为空值;

(2)如果函数返回的数值为“int”,数值0意味着函数运行良好,其他数值则表示返回错误,具体的错误信息在“error.xml”文件里面。

5.2 CThostFtdcTraderSpi

CTP用CThostFtdcTraderSpi表示事件接口。客户端应用程序可以通过CThostFtdcTraderSpi 函数获得CTP服务器发出的通知。

5.2.1 OnFrontConnected

当客户端与CTP服务器连接上后,此函数被激活,进而,客户端可以使用“ReqUserLogin”来发送登陆请求。

定义:void OnFrontConnected();

5.2.2 OnFrontDisconnected

当连接终止或中断时,此函数被激活。如果该信息没有被处理,那么API会使用登陆地址列表上的一个前端地址,自动重新连接CTP服务器。

定义:void OnFrontDisconnected (int nReason); 参数:

nReason:the reason of disconnecion 0x1001 network reading failed 0x1002 network writing failed

0x2001 heartbeat receiving timeout 0x2002 heartbeat sending timeout 0x2003 received an error message

5.2.3 OnHeartBeatWarning

此函数用来表示与服务器长时间连接的接口是否可用。 定义:void OnHeartBeatWarning(int nTimeLapse);

参数: nTimeLapse:Length of time elapsed since the last received message

5.2.4 OnRspUserLogin

CTP服务器使用次callback 函数OnRspUserLogin 来通知客户端登陆函数OnRspUserLogin是否被服务器接受。

定义:void OnRspUserLogin(

CThostFtdcRspUserLoginField *pRspUserLogin, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

参数:

pRspUserLogin:The pointer of the structure for user’s login response. The following is definition of the structure: struct CThostFtdcRspUserLoginField {

///trading day

TThostFtdcDateType TradingDay; ///time of login

TThostFtdcTimeType LoginTime; ///broker id

TThostFtdcBrokerIDType BrokerID; ///user id

TThostFtdcUserIDType UserID; ///trade system name

TThostFtdcSystemNameType SystemName; };

pRspInfo:Pointer of the structure for system response. The following is definition of the structure:

struct CThostFtdcRspInfoField {

///error id

TThostFtdcErrorIDType ErrorID; ///error information

TThostFtdcErrorMsgType ErrorMsg; };

5.2.5 OnRspUserLogout

CTP服务器利用此callback函数来通知客户端“RspUserLogout”是否运行成功。

定义:void OnRspUserLogout(

CThostFtdcUserLogoutField *pUserLogout, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

参数:

pRspUserLogout:Pointerof the structure for user’s logout response. The following is definition of the structure: struct CThostFtdcUserLogoutField {

///broker id

TThostFtdcBrokerIDType BrokerID; ///user id

TThostFtdcUserIDType UserID; };

5.2.6 OnRspUserPasswordUpdate

CTP服务器使用此callback函数来通知客户端函数“RspUserPasswordUpdate”是否运行成功。

定义:void OnRspUserPasswordUpdate(

CThostFtdcUserPasswordUpdateField *pUserPasswordUpdate,

CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

参数:

pUserPasswordUpdate:Pointer of the structure for the response of user’s password modification. The following is definition of the structure: struct CThostFtdcUserPasswordUpdateField {

///broker id

TThostFtdcBrokerIDType BrokerID; ///user id

TThostFtdcUserIDType UserID; ///old password

TThostFtdcPasswordTypeOldPassword; ///new password

TThostFtdcPasswordTypeNewPassword; };

5.2.7 OnRspTradingAccountPasswordUpdate

CTP服务器使用此callback函数来通知客户端是否函数“RspTradingAccountPasswordUpdate”运行成功。

定义:void OnRspTradingAccountPasswordUpdate( CThostFtdcTradingAccountPasswordUpdateField *pTradingAccountPasswordUpdate, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

///user id

TThostFtdcUserIDType UserID; ///order price type

TThostFtdcOrderPriceTypeType OrderPriceType; ///direction

TThostFtdcDirectionType Direction; ///combination order’s offset flag

TThostFtdcCombOffsetFlagType CombOffsetFlag; ///combination or hedge flag

TThostFtdcCombHedgeFlagType CombHedgeFlag; ///price

TThostFtdcPriceType LimitPrice; ///volume

TThostFtdcVolumeType VolumeTotalOriginal; ///valid date type

TThostFtdcTimeConditionType TimeCondition; ///GTD DATE

TThostFtdcDateType GTDDate; ///volume condition

TThostFtdcVolumeConditionType VolumeCondition; ///min volume

TThostFtdcVolumeType MinVolume; ///trigger condition

TThostFtdcContingentConditionType ContingentCondition; ///stop price

TThostFtdcPriceType StopPrice; ///force close reason

TThostFtdcForceCloseReasonType ForceCloseReason; /// auto suspend flag

TThostFtdcBoolType IsAutoSuspend; ///business unit

TThostFtdcBusinessUnitType BusinessUnit; ///request ID

TThostFtdcRequestIDType RequestID; ///order local ID

TThostFtdcOrderLocalIDType OrderLocalID; ///exchange ID

TThostFtdcExchangeIDType ExchangeID; ///participant ID

TThostFtdcParticipantIDType ParticipantID; ///trading code

TThostFtdcClientIDTypeClientID; ///exchange instrument ID

TThostFtdcExchangeInstIDType ExchangeInstID;

///trader ID

TThostFtdcTraderIDType TraderID; ///install ID

TThostFtdcInstallIDType InstallID; ///order submit status

TThostFtdcOrderSubmitStatusType OrderSubmitStatus; ///order notify sequence

TThostFtdcSequenceNoType NotifySequence; ///trading day

TThostFtdcDateType TradingDay; ///settlement ID

TThostFtdcSettlementIDType SettlementID; ///order system ID

TThostFtdcOrderSysIDType OrderSysID; ///order source

TThostFtdcOrderSourceType OrderSource; ///order status

TThostFtdcOrderStatusType OrderStatus; ///order type

TThostFtdcOrderTypeType OrderType; ///volume traded

TThostFtdcVolumeType VolumeTraded; /// total volume

TThostFtdcVolumeType VolumeTotal; ///insert date

TThostFtdcDateType InsertDate; ///insert time

TThostFtdcTimeType InsertTime; ///active time

TThostFtdcTimeType ActiveTime; ///suspend time

TThostFtdcTimeType SuspendTime; ///update time

TThostFtdcTimeType UpdateTime; ///cancel time

TThostFtdcTimeType CancelTime; ///active trader ID

TThostFtdcTraderIDType ActiveTraderID; ///clear participant ID

TThostFtdcParticipantIDType ClearingPartID; ///sequence No.

TThostFtdcSequenceNoType SequenceNo; ///front ID

TThostFtdcFrontIDType FrontID;

///session ID

TThostFtdcSessionIDType SessionID; ///user product information

TThostFtdcProductInfoType UserProductInfo; ///status message

TThostFtdcErrorMsgType StatusMsg; };

5.2.14 OnRspQryTrade

CTP服务器利用此callback函数反馈客户端应用程序“ReqQryTrade”的请求。

定义:void OnRspQryTrade(

CThostFtdcTradeField *pTrade, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

参数:

pTrade:Pointer of the structure for the response of ReqQryTrade. The following is definition of the structure, struct CThostFtdcTradeField {

///broker id

TThostFtdcBrokerIDType BrokerID; ///investor ID

TThostFtdcInvestorIDType InvestorID; ///instrument ID

TThostFtdcInstrumentIDType InstrumentID; ///order reference

TThostFtdcOrderRefType OrderRef; ///user id

TThostFtdcUserIDType UserID; ///exchange ID

TThostFtdcExchangeIDType ExchangeID; ///trade ID

TThostFtdcTradeIDTypeTradeID; ///direction

TThostFtdcDirectionType Direction; ///order system ID

TThostFtdcOrderSysIDType OrderSysID; ///participant ID

TThostFtdcParticipantIDType ParticipantID; ///trading code

TThostFtdcClientIDTypeClientID; ///trading role

TThostFtdcTradingRoleType TradingRole; ///exchange instrument ID

TThostFtdcExchangeInstIDType ExchangeInstID; ///offset flag

TThostFtdcOffsetFlagType OffsetFlag; ///hedge flag

TThostFtdcHedgeFlagType HedgeFlag; ///price

TThostFtdcPriceType Price; ///volume

TThostFtdcVolumeType Volume; ///trade date

TThostFtdcDateType TradeDate; ///trade time

TThostFtdcTimeType TradeTime; ///trade type

TThostFtdcTradeTypeType TradeType; ///price source

TThostFtdcPriceSourceType PriceSource; ///trader ID

TThostFtdcTraderIDType TraderID; ///order local ID

TThostFtdcOrderLocalIDType OrderLocalID; ///clear participant ID

TThostFtdcParticipantIDType ClearingPartID; ///business unit

TThostFtdcBusinessUnitType BusinessUnit; ///sequence No.

TThostFtdcSequenceNoType SequenceNo; ///trading day

TThostFtdcDateType TradingDay; ///settlement ID

TThostFtdcSettlementIDType SettlementID; };

5.2.15 OnRspQryInvestor

CTP服务器利用此callback函数反馈客户端应用程序“ReqQryInvestor”的请求。

定义:void OnRspQry Investor (

CThostFtdcInvestorField *pInvestor, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

参数:

pInvestor:Pointer of the structure for the response of ReqQryInvestor. The following is definition of the structure, struct CThostFtdcInvestorField {

///investor ID

TThostFtdcInvestorIDType InvestorID; ///broker id

TThostFtdcBrokerIDType BrokerID; ///investor group ID

TThostFtdcInvestorIDType InvestorGroupID; ///investor name

TThostFtdcPartyNameType InvestorName; ///Identified Card Type

TThostFtdcIdCardTypeType IdentifiedCardType; ///Identified Card No.

TThostFtdcIdentifiedCardNoType IdentifiedCardNo; ///is active

TThostFtdcBoolType IsActive; };

5.2.16 OnRspQryInvestorPosition

CTP服务器利用此callback函数反馈客户端应用程序“ReqQryInvestorPosition”的请求。

定义:void OnRspQry InvestorPosition(

CThostFtdcInvestorPositionField *pInvestorPosition, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

参数:

pInvestorPosition : Pointer of the structure for the response of ReqQryInvestorPosition. The following is definition of the structure, struct CThostFtdcInvestorPositionField {

///instrument ID

TThostFtdcInstrumentIDType InstrumentID; ///broker id

TThostFtdcBrokerIDType BrokerID; ///investor ID

TThostFtdcInvestorIDType InvestorID; ///position direction

TThostFtdcPosiDirectionType PosiDirection; ///hedge flag

TThostFtdcHedgeFlagType HedgeFlag; ///position date

TThostFtdcPositionDateType PositionDate; ///position of last trading day

TThostFtdcVolumeType YdPosition; OpenVolume; ///close volume

TThostFtdcVolumeType CloseVolume; ///open amount

TThostFtdcMoneyType OpenAmount; ///close amount

TThostFtdcMoneyType CloseAmount; ///position cost

TThostFtdcMoneyType PositionCost; ///previous margin

TThostFtdcMoneyType PreMargin; ///used margin

TThostFtdcMoneyType UseMargin; ///frozen margin

TThostFtdcMoneyType FrozenMargin; ///frozen cash

TThostFtdcMoneyType FrozenCash; ///frozen commission

TThostFtdcMoneyType FrozenCommission; ///cash in

TThostFtdcMoneyType CashIn; ///commission

TThostFtdcMoneyType Commission; ///close profit

TThostFtdcMoneyType CloseProfit; ///position profit

TThostFtdcMoneyType PositionProfit; ///previous settlement price

TThostFtdcPriceType PreSettlementPrice; ///settlement price

TThostFtdcPriceType SettlementPrice; ///trading day

TThostFtdcDateType TradingDay; ///settlement ID

TThostFtdcSettlementIDType SettlementID; };

5.2.17 OnRspQryTradingAccount

CTP服务器利用此callback函数反馈客户端应用程序“ReqQryTradingAccount”的请求。

定义:void OnRspQryTradingAccount(

CThostFtdcTradingAccountField *pTradingAccount, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

参数:

pTradingAccount : Pointer of the structure for the response of ReqQryTradingAccount. The following is definition of the structure, struct CThostFtdcTradingAccountField {

///broker id

TThostFtdcBrokerIDType BrokerID; ///account id

TThostFtdcAccountIDType AccountID; ///previous mortgage

TThostFtdcMoneyType PreMortgage; ///previous credit

TThostFtdcMoneyType PreCredit; ///previous deposit

TThostFtdcMoneyType PreDeposit; ///previous balance

TThostFtdcMoneyType PreBalance; ///premargin

TThostFtdcMoneyType PreMargin; ///interest base

TThostFtdcMoneyType InterestBase; ///interest

TThostFtdcMoneyType Interest; ///deposit

TThostFtdcMoneyType Deposit; ///withdraw

TThostFtdcMoneyType Withdraw; ///frozen margin

TThostFtdcMoneyType FrozenMargin; ///frozen cash

TThostFtdcMoneyType FrozenCash; ///frozen commission

TThostFtdcMoneyType FrozenCommission; ///current margin

TThostFtdcMoneyType CurrMargin; ///cash in

TThostFtdcMoneyType CashIn; ///commission

TThostFtdcMoneyType Commission; ///close profit

TThostFtdcMoneyType CloseProfit; ///position profit

TThostFtdcMoneyType PositionProfit; ///balance

TThostFtdcMoneyType Balance; ///available

TThostFtdcMoneyType Available; ///withdraw quota

TThostFtdcMoneyType WithdrawQuota; ///reserve

TThostFtdcMoneyType Reserve; ///trading day

TThostFtdcDateType TradingDay; ///settlement ID

TThostFtdcSettlementIDType SettlementID; ///credit

TThostFtdcMoneyType Credit; ///Mortgage

TThostFtdcMoneyType Mortgage; ///excahnge margin

TThostFtdcMoneyType ExchangeMargin; };

5.2.18 OnRspQryTradingCode

CTP服务器利用此callback函数反馈客户端应用程序“ReqQryTradingCode”的请求。

定义:void OnRspQryTradingCode(

CThostFtdcTradingCodeField *pTradingCode, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) ;

参数:

pTradingCode:Pointer of the structure for the response of ReqQryTradingCode. The following is definition of the structure, struct CThostFtdcTradingCodeField {

///investor ID

TThostFtdcInvestorIDType InvestorID; ///broker id

TThostFtdcBrokerIDType BrokerID; ///exchange ID

TThostFtdcExchangeIDType ExchangeID; ///trading code

TThostFtdcClientIDTypeClientID;

///is active

TThostFtdcBoolType IsActive; };

5.2.19 OnRspQryExchange

CTP服务器利用此callback函数反馈客户端应用程序“ReqQryExchange”的请求。

定义:void OnRspQryExchange(

CThostFtdcExchangeField *pExchange, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) ;

参数:

pExchange:Pointer of the structure for the response of ReqQryExchange. The following is definition of the structure, struct CThostFtdcExchangeField {

///exchange ID

TThostFtdcExchangeIDType ExchangeID; ///exchange name

TThostFtdcExchangeNameType ExchangeName; ///exchange property

TThostFtdcExchangePropertyTypeExchangeProperty; };

5.2.20 OnRspQryInstrument

CTP服务器利用此callback函数反馈客户端应用程序“ReqQryInstrument”的请求。

定义:void OnRspQryInstrument(

CThostFtdcInstrumentField *pInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) ;

参数:

pInstrument:Pointer of the structure for the response of ReqQryInstrument. The following is definition of the structure, struct CThostFtdcInstrumentField {

///instrument ID

TThostFtdcInstrumentIDType InstrumentID; ///exchange ID

TThostFtdcExchangeIDType ExchangeID; ///instrument name

TThostFtdcInstrumentNameType InstrumentName; ///exchange instrument ID

TThostFtdcExchangeInstIDType ExchangeInstID; ///product ID DeliveryMonth;

///max volume for market order

TThostFtdcVolumeType MaxMarketOrderVolume; ///min volume for market order

TThostFtdcVolumeType MinMarketOrderVolume; ///max volume for limit order

TThostFtdcVolumeType MaxLimitOrderVolume; ///min volume for limit order

TThostFtdcVolumeType MinLimitOrderVolume; ///volume multiple of instrument

TThostFtdcVolumeMultipleType VolumeMultiple; ///price tick

TThostFtdcPriceType PriceTick; ///create date

TThostFtdcDateType CreateDate; ///open date

TThostFtdcDateType OpenDate; ///expire date

TThostFtdcDateType ExpireDate; ///start delivery date

TThostFtdcDateType StartDelivDate; ///end delivery date

TThostFtdcDateType EndDelivDate; ///instrument life phase

TThostFtdcInstLifePhaseTypeInstLifePhase; ///is trading

TThostFtdcBoolType IsTrading; ///position type

TThostFtdcPositionTypeType PositionType; ///position date type

TThostFtdcPositionDateTypeType PositionDateType; ///long margin ratio

TThostFtdcRatioType LongMarginRatio; ///short margin ratio

TThostFtdcRatioType ShortMarginRatio; };

5.2.21 OnRspQryDepthMarketData

CTP服务器利用此callback函数反馈客户端应用程序“ReqQryDepthMarketData”的请求。

定义:void OnRspQryDepthMarketData(

CThostFtdcDepthMarketDataField *pDepthMarketData, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) ;

参数:

pDepthMarketData : Pointer of the structure for the response of ReqQryDepthMarketData. The following is definition of the structure, struct CThostFtdcDepthMarketDataField {

///trading day

TThostFtdcDateType TradingDay; ///instrument ID

TThostFtdcInstrumentIDType InstrumentID; ///exchange ID

TThostFtdcExchangeIDType ExchangeID; ///exchange instrument ID

TThostFtdcExchangeInstIDType ExchangeInstID; ///last price

TThostFtdcPriceType LastPrice; ///previous settlement price

TThostFtdcPriceType PreSettlementPrice; ///previous close price

TThostFtdcPriceType PreClosePrice; ///previous open volume

TThostFtdcLargeVolumeType PreOpenInterest; ///open price

TThostFtdcPriceType OpenPrice; ///highest price

TThostFtdcPriceType HighestPrice; ///lowest price

TThostFtdcPriceType LowestPrice; ///trade volume

TThostFtdcVolumeType Volume; ///turnover

TThostFtdcMoneyType Turnover; ///open interest

TThostFtdcLargeVolumeType OpenInterest; ///close Price

TThostFtdcPriceType ClosePrice; ///settlement price

TThostFtdcPriceType SettlementPrice; ///upper limit price

TThostFtdcPriceType UpperLimitPrice;

///lower limit price

TThostFtdcPriceType LowerLimitPrice; ///pre-delta

TThostFtdcRatioType PreDelta; ///current delta

TThostFtdcRatioType CurrDelta; ///update time

TThostFtdcTimeType UpdateTime; ///Update Millisecond

TThostFtdcMillisecType UpdateMillisec; ///the first bid price

TThostFtdcPriceType BidPrice1; ///the first bid volume

TThostFtdcVolumeType BidVolume1; ///the first ask price

TThostFtdcPriceType AskPrice1; ///the first ask volume

TThostFtdcVolumeType AskVolume1; ///the second bid price

TThostFtdcPriceType BidPrice2; ///the second bid volume

TThostFtdcVolumeType BidVolume2; ///the second ask price

TThostFtdcPriceType AskPrice2; ///the second ask volume

TThostFtdcVolumeType AskVolume2; ///the third bid price

TThostFtdcPriceType BidPrice3; TThostFtdcPriceType AskPrice3; ///the third ask volume

TThostFtdcVolumeType AskVolume3; ///the forth bid price

TThostFtdcPriceType BidPrice4; ///the forth bid volume

TThostFtdcVolumeType BidVolume4; ///the forth ask price

TThostFtdcPriceType AskPrice4; ///the forth ask volume

TThostFtdcVolumeType AskVolume4; ///the fifth bid price

TThostFtdcPriceType BidPrice5; ///the fifth bid volume

TThostFtdcVolumeType BidVolume5; ///the fifth ask price

TThostFtdcPriceType AskPrice5; ///the fifth ask volume

TThostFtdcVolumeType AskVolume5; };

5.2.22 OnRspQrySettlementInfo

CTP服务器利用此callback函数反馈客户端应用程序“ReqQrySettlementInfo”的请求。

定义:void OnRspQrySettlementInfo(

CThostFtdcSettlementInfoField *pSettlementInfo, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) ;

参数:

pSettlementInfo : Pointer of the structure for the response of ReqQrySettlementInfo. The following is definition of the structure, struct CThostFtdcSettlementInfoField {

///trading day

TThostFtdcDateType TradingDay; ///settlement ID

TThostFtdcSettlementIDType SettlementID; ///broker id

TThostFtdcBrokerIDType BrokerID; ///investor ID

TThostFtdcInvestorIDType InvestorID; ///sequence No.

TThostFtdcSequenceNoType SequenceNo; ///content

TThostFtdcContentType Content; };

5.2.23 OnRspQryInvestorPositionDetail

CTP服务器利用此callback函数反馈客户端应用程序“ReqQryInvestorPositionDetail”的请求。

定义:void OnRspQryInvestorPositionDetail(

CThostFtdcInvestorPositionDetailField *pInvestorPositionDetail, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) ;

参数:

pInvestorPositionDetail : Pointer of the structure for the response of ReqQryInvestorPositionDetail. The following is definition of the structure, struct CThostFtdcInvestorPositionDetailField

{

///instrument ID

TThostFtdcInstrumentIDType InstrumentID; ///broker id

TThostFtdcBrokerIDType BrokerID; ///investor ID

TThostFtdcInvestorIDType InvestorID; ///hedge flag

TThostFtdcHedgeFlagType HedgeFlag; ///direction

TThostFtdcDirectionType Direction; ///open date

TThostFtdcDateType OpenDate; ///trade ID

TThostFtdcTradeIDTypeTradeID; ///volume

TThostFtdcVolumeType Volume; ///open price

TThostFtdcPriceType OpenPrice; ///trading day

TThostFtdcDateType TradingDay; ///settlement ID

TThostFtdcSettlementIDType SettlementID; ///trade type

TThostFtdcTradeTypeType TradeType; ///combination instrument ID

TThostFtdcInstrumentIDTypeCombInstrumentID; };

5.2.24 OnRspQryNotice

CTP服务器利用此callback函数反馈客户端应用程序“ReqQryNotice”的请求。

定义:void OnRspQryNotice(

CThostFtdcNoticeField *pNotice, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

参数:

pNotice:Pointer of the structure for the response of ReqQryNotice. The following is definition of the structure, struct CThostFtdcNoticeField {

///broker id

TThostFtdcBrokerIDType BrokerID;

///content

TThostFtdcContentType Content; ///Sequence Label of broker notice

TThostFtdcSequenceLabelType SequenceLabel; };

5.2.25 OnRspQryInstrument

CTP服务器利用此callback函数反馈客户端应用程序“ReqQryInstrument”的请求。

定义:void OnRspQryInstrument(

CThostFtdcInstrumentField *pInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

参数:

pRspInstrument:Pointer of the structure for the response of ReqQryInstrument. The following is definition of the structure, struct CThostFtdcInstrumentField {

///instrument ID

TThostFtdcInstrumentIDType InstrumentID; ///exchange ID

TThostFtdcExchangeIDType ExchangeID; ///instrument name

TThostFtdcInstrumentNameType InstrumentName; ///exchange instrument ID

TThostFtdcExchangeInstIDType ExchangeInstID; ///product ID

TThostFtdcInstrumentIDTypeProductID; ///product class

TThostFtdcProductClassTypeProductClass; ///delivery year

TThostFtdcYearType DeliveryYear; ///delivery month

TThostFtdcMonthType DeliveryMonth; ///max volume for market order

TThostFtdcVolumeType MaxMarketOrderVolume; ///min volume for market order

TThostFtdcVolumeType MinMarketOrderVolume; ///max volume for limit order

TThostFtdcVolumeType MaxLimitOrderVolume; ///min volume for limit order

TThostFtdcVolumeType MinLimitOrderVolume;

///volume multiple of instrument

TThostFtdcVolumeMultipleType VolumeMultiple; ///price tick

TThostFtdcPriceType PriceTick; ///create date

TThostFtdcDateType CreateDate; ///open date

TThostFtdcDateType OpenDate; ///expire date

TThostFtdcDateType ExpireDate; ///start delivery date

TThostFtdcDateType StartDelivDate; ///end delivery date

TThostFtdcDateType EndDelivDate; ///instrument life phase

TThostFtdcInstLifePhaseTypeInstLifePhase; ///is trading

TThostFtdcBoolType IsTrading; ///position type

TThostFtdcPositionTypeType PositionType; ///position date type

TThostFtdcPositionDateTypeType PositionDateType; };

5.2.26 OnRtnTrade

CTP服务器利用此callback函数通知客户端应用程序,什么时候交易已经结束。

定义:void OnRtnTrade(CThostFtdcTradeField *pTrade); 参数:

pTrade:Pointer of the structure for the trade information. The following is definition of the structure, struct CThostFtdcTradeField {

///broker id

TThostFtdcBrokerIDType BrokerID; ///investor ID

TThostFtdcInvestorIDType InvestorID; ///instrument ID

TThostFtdcInstrumentIDType InstrumentID; ///order reference

TThostFtdcOrderRefType OrderRef; ///user id

TThostFtdcUserIDType UserID; ///exchange ID

TThostFtdcExchangeIDType ExchangeID; ///trade ID

TThostFtdcTradeIDTypeTradeID; ///direction

TThostFtdcDirectionType Direction; ///order system ID

TThostFtdcOrderSysIDType OrderSysID; ///participant ID

TThostFtdcParticipantIDType ParticipantID; ///trading code

TThostFtdcClientIDTypeClientID; ///trading role

TThostFtdcTradingRoleType TradingRole; ///exchange instrument ID

TThostFtdcExchangeInstIDType ExchangeInstID; ///offset flag

TThostFtdcOffsetFlagType OffsetFlag; ///hedge flag

TThostFtdcHedgeFlagType HedgeFlag; ///price

TThostFtdcPriceType Price; ///volume

TThostFtdcVolumeType Volume; ///trade date

TThostFtdcDateType TradeDate; ///trade time

TThostFtdcTimeType TradeTime; ///trade type

TThostFtdcTradeTypeType TradeType; ///price source

TThostFtdcPriceSourceType PriceSource; ///trader ID

TThostFtdcTraderIDType TraderID; ///order local ID

TThostFtdcOrderLocalIDType OrderLocalID; ///clear participant ID

TThostFtdcParticipantIDType ClearingPartID; ///business unit

TThostFtdcBusinessUnitType BusinessUnit; ///sequence No.

TThostFtdcSequenceNoType SequenceNo; ///trading day

TThostFtdcDateType TradingDay; ///settlement ID

TThostFtdcSettlementIDType SettlementID; };

5.2.27 OnRtnOrder

CTP服务器利用此callback函数通知客户端应用程序,订单状态的变化。 定义:void OnRtnOrder(CThostFtdcOrderField *pOrder); 参数:

pOrder:Pointer of the structure for the order information. The following is definition of the structure, struct CThostFtdcOrderField {

///broker id

TThostFtdcBrokerIDType BrokerID; ///investor ID

TThostFtdcInvestorIDType InvestorID; ///instrument ID

TThostFtdcInstrumentIDType InstrumentID; ///order reference

TThostFtdcOrderRefType OrderRef; ///user id

TThostFtdcUserIDType UserID; ///order price type

TThostFtdcOrderPriceTypeType OrderPriceType; ///direction

TThostFtdcDirectionType Direction; ///combination order’s offset flag

TThostFtdcCombOffsetFlagType CombOffsetFlag; ///combination or hedge flag

TThostFtdcCombHedgeFlagType CombHedgeFlag; MinVolume;

///trigger condition

TThostFtdcContingentConditionType ContingentCondition; ///stop price

TThostFtdcPriceType StopPrice; ///force close reason

TThostFtdcForceCloseReasonType ForceCloseReason; /// auto suspend flag

TThostFtdcBoolType IsAutoSuspend; ///business unit

TThostFtdcBusinessUnitType BusinessUnit; ///request ID

TThostFtdcRequestIDType RequestID; ///order local ID

TThostFtdcOrderLocalIDType OrderLocalID;

///exchange ID

TThostFtdcExchangeIDType ExchangeID; ///participant ID

TThostFtdcParticipantIDType ParticipantID; ///trading code

TThostFtdcClientIDTypeClientID; ///exchange instrument ID

TThostFtdcExchangeInstIDType ExchangeInstID; ///trader ID

TThostFtdcTraderIDType TraderID; ///install ID

TThostFtdcInstallIDType InstallID; ///order submit status

TThostFtdcOrderSubmitStatusType OrderSubmitStatus; ///notify sequence

TThostFtdcSequenceNoType NotifySequence; ///trading day

TThostFtdcDateType TradingDay; VolumeTraded; ///volume total

TThostFtdcVolumeType VolumeTotal; ///insert date

TThostFtdcDateType InsertDate; ///insert time

TThostFtdcTimeType InsertTime; ///active time

TThostFtdcTimeType ActiveTime; ///suspend time

TThostFtdcTimeType SuspendTime; ///update time

TThostFtdcTimeType UpdateTime; ///cancel time

TThostFtdcTimeType CancelTime; ///active trader ID

TThostFtdcTraderIDType ActiveTraderID; ///clear participant ID

TThostFtdcParticipantIDType ClearingPartID; ///sequence No.

TThostFtdcSequenceNoType SequenceNo; ///front ID

TThostFtdcFrontIDType FrontID; ///session ID

TThostFtdcSessionIDType SessionID; ///user product information

TThostFtdcProductInfoType UserProductInfo; ///status message

TThostFtdcErrorMsgType StatusMsg; };

5.2.28 OnErrRtnOrderInsert

此callback函数用于通知客户端应用程序,CTP服务器或交易所的验证出错。 定义:void OnErrRtnOrderInsert(

CThostFtdcInputOrderField *pInputOrder, CThostFtdcRspInfoField *pRspInfo);

参数:

pInputOrder:Pointer of the structure for the order insertion information

including the response from server. The following is definition of the structure, struct CThostFtdcInputOrderField {

///broker id

TThostFtdcBrokerIDType BrokerID; ///investor ID

TThostFtdcInvestorIDType InvestorID; ///instrument ID

TThostFtdcInstrumentIDType InstrumentID; ///order reference

TThostFtdcOrderRefType OrderRef; ///user id

TThostFtdcUserIDType UserID; ///order price type

TThostFtdcOrderPriceTypeType OrderPriceType; ///direction

TThostFtdcDirectionType Direction; ///combination order’s offset flag

TThostFtdcCombOffsetFlagType CombOffsetFlag; ///combination or hedge flag

TThostFtdcCombHedgeFlagType CombHedgeFlag; ///price

TThostFtdcPriceType LimitPrice; ///volume

TThostFtdcVolumeType VolumeTotalOriginal; ///valid date

TThostFtdcTimeConditionType TimeCondition; ///GTD DATE

TThostFtdcDateType GTDDate; ///volume condition

TThostFtdcVolumeConditionType VolumeCondition; ///min volume

TThostFtdcVolumeType MinVolume; ///trigger condition

TThostFtdcContingentConditionType ContingentCondition; ///stop price

TThostFtdcPriceType StopPrice; ///force close reason

TThostFtdcForceCloseReasonType ForceCloseReason; /// auto suspend flag

TThostFtdcBoolType IsAutoSuspend; ///business unit

TThostFtdcBusinessUnitType BusinessUnit; ///request ID

TThostFtdcRequestIDType RequestID; };

5.2.29 OnErrRtnOrderAction

此callback函数用于通知客户端应用程序,CTP服务器或交易所的验证出错。 定义:void OnErrRtnOrderAction (

CThostFtdcOrderActionField *pOrderAction, CThostFtdcRspInfoField *pRspInfo);

参数:

pOrderAction:Pointer of the structure for the order action information

including the response from server. The following is definition of the structure, struct CThostFtdcOrderActionField {

///broker id

TThostFtdcBrokerIDType BrokerID; ///investor ID

TThostFtdcInvestorIDType InvestorID; ///order action reference

TThostFtdcOrderActionRefType OrderActionRef; ///order reference

TThostFtdcOrderRefType OrderRef; ///request ID

TThostFtdcRequestIDType RequestID; ///front ID

TThostFtdcFrontIDType FrontID; ///session ID

TThostFtdcSessionIDType SessionID; ///exchange ID

TThostFtdcExchangeIDType ExchangeID; ///order system ID

TThostFtdcOrderSysIDType OrderSysID; ///action flag

TThostFtdcActionFlagType ActionFlag; ///price

TThostFtdcPriceType LimitPrice; ///volume change

TThostFtdcVolumeType VolumeChange; ///action date

TThostFtdcDateType ActionDate; ///action time

TThostFtdcTimeType ActionTime; ///trader ID

TThostFtdcTraderIDType TraderID; ///install ID

TThostFtdcInstallIDType InstallID; ///order local ID

TThostFtdcOrderLocalIDType OrderLocalID; ///action local ID

TThostFtdcOrderLocalIDType ActionLocalID; ///participant ID

TThostFtdcParticipantIDType ParticipantID; ///trading code

TThostFtdcClientIDTypeClientID; ///business unit

TThostFtdcBusinessUnitType BusinessUnit; ///order action status

TThostFtdcOrderActionStatusTypeOrderActionStatus; ///user id

TThostFtdcUserIDType UserID; ///status message

TThostFtdcErrorMsgType StatusMsg; };

5.2.30 OnRspQrySettlementInfoConfirm

CTP服务器利用此callback函数反馈客户端应用程序“ReqQrySettlementInfoConfirm”运行成功。

定义:void OnRspQrySettlementInfoConfirm(

CThostFtdcSettlementInfoConfirmField *pSettlementInfoConfirm, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

参数:

pSettlementInfoConfirm : Pointer of the structure for the response of ReqQrySettlementInfoConfirm. The following is definition of the structure, struct CThostFtdcSettlementInfoConfirmField {

///broker id

TThostFtdcBrokerIDType BrokerID; ///investor ID

TThostFtdcInvestorIDType InvestorID; ///confirm date

TThostFtdcDateType ConfirmDate; ///confirm time

TThostFtdcTimeType ConfirmTime; };;

5.2.31 RspQryParkedOrder

CTP服务器利用此callback函数反馈预报单(parked order)的查询。 定义:

void OnRspQryParkedOrder(CThostFtdcParkedOrderField *pParkedOrder, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

参数:

pParkedOrder:Pointer of the structure for the response of ReqQryParkedOrder. The following is

definition of the structure,

struct CThostFtdcParkedOrderField {

///broker id

TThostFtdcBrokerIDType BrokerID; ///investor ID

TThostFtdcInvestorIDType InvestorID; ///instrument ID

TThostFtdcInstrumentIDType InstrumentID; ///order reference

TThostFtdcOrderRefType OrderRef; ///user id

TThostFtdcUserIDType UserID; ///order price type

TThostFtdcOrderPriceTypeType OrderPriceType; ///direction

TThostFtdcDirectionType Direction; ///combination order’s offset flag

TThostFtdcCombOffsetFlagType CombOffsetFlag; ///combination or hedge flag

TThostFtdcCombHedgeFlagType CombHedgeFlag; ///price

TThostFtdcPriceType LimitPrice;

///volume

TThostFtdcVolumeType VolumeTotalOriginal; ///valid date

TThostFtdcTimeConditionType TimeCondition; ///GTD DATE

TThostFtdcDateType GTDDate; ///volume condition

TThostFtdcVolumeConditionType VolumeCondition; ///min volume

TThostFtdcVolumeType MinVolume; ///trigger condition

TThostFtdcContingentConditionType ContingentCondition; ///stop price

TThostFtdcPriceType StopPrice; ///force close reason

TThostFtdcForceCloseReasonType ForceCloseReason; /// auto suspend flag

TThostFtdcBoolType IsAutoSuspend; ///business unit

TThostFtdcBusinessUnitType BusinessUnit; ///request ID

TThostFtdcRequestIDType RequestID; ///user force close flag

TThostFtdcBoolType UserForceClose; ///exchange ID

TThostFtdcExchangeIDType ExchangeID; ///parked order system ID

TThostFtdcParkedOrderIDType ParkedOrderID; ///user type

TThostFtdcUserTypeType UserType; ///parked order status

TThostFtdcParkedOrderStatusType Status; };

5.2.32 RspQryParkedOrderAction

CTP服务器利用此callback函数反馈““RspQryParkedOrderAction”的查询。 定义:void OnRspQryParkedOrderAction(

CThostFtdcParkedOrderActionField *pParkedOrderAction, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

参数:

pParkedOrderAction : Pointer of the structure for the response of ReqQryParkedOrderAction. The following is definition of the structure, struct CThostFtdcParkedOrderActionField

{

///broker id

TThostFtdcBrokerIDType BrokerID; ///investor ID

TThostFtdcInvestorIDType InvestorID; ///order action reference

TThostFtdcOrderActionRefType OrderActionRef; ///order reference

TThostFtdcOrderRefType OrderRef; ///request ID

TThostFtdcRequestIDType RequestID; ///front ID

TThostFtdcFrontIDType FrontID; ///session ID

TThostFtdcSessionIDType SessionID; ///exchange ID

TThostFtdcExchangeIDType ExchangeID; ///order system ID

TThostFtdcOrderSysIDType OrderSysID; ///action flag

TThostFtdcActionFlagType ActionFlag; ///price

TThostFtdcPriceType LimitPrice; ///volume change

TThostFtdcVolumeType VolumeChange; ///user id

TThostFtdcUserIDType UserID; ///instrument ID

TThostFtdcInstrumentIDType InstrumentID; ///parked order action ID

TThostFtdcParkedOrderActionIDType ParkedOrderActionID; ///user type

TThostFtdcUserTypeType UserType; ///parked order action status

TThostFtdcParkedOrderStatusType Status; };

5.2.33 RspQryInvestorPositionCombineDetail

CTP服务器利用此callback函数反馈,投资者连接设备的位置查询。 定义:void OnRspQryInvestorPositionCombineDetail(

CThostFtdcInvestorPositionCombineDetailField *pInvestorPositionCombineDetail, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

本文来源:https://www.bwwdw.com/article/ujy6.html

Top