Halo
发布于 2023-10-26 / 225 阅读 / 0 评论 / 0 点赞

ctp下单和其响应

报单(下单)

ReqOrderInsert 必填字段

  1. TThostFtdcBrokerIDType BrokerID 经纪公司代码 必填
  2. TThostFtdcInvestorIDType InvestorID 投资者代码 必填
  3. TThostFtdcInstrumentIDType InstrumentID 合约代码 必填
  4. TThostFtdcCombOffsetFlagType CombOffsetFlag 开平标志 必填
  5. TThostFtdcCombHedgeFlagType CombHedgeFlag 投机套保标志 必填
  6. TThostFtdcExchangeIDType ExchangeID 交易所代码 必填
  7. TThostFtdcVolumeType VolumeTotalOriginal 数量 必填
  8. TThostFtdcBoolType IsAutoSuspend 自动挂起标志 必填0
  9. TThostFtdcBoolType IsSwapOrder 互换单标志 必填
  10. TThostFtdcOrderPriceTypeType OrderPriceType 报单价格条件 必填
  11. TThostFtdcDirectionType Direction 买卖方向 必填
  12. TThostFtdcTimeConditionType TimeCondition 有效期类型 必填
  13. TThostFtdcVolumeConditionType VolumeCondition 成交量类型 必填
  14. TThostFtdcContingentConditionType ContingentCondition 触发条件 必填
  15. TThostFtdcForceCloseReasonType ForceCloseReason 强平原因 必填
  16. TThostFtdcPriceType LimitPrice 价格 必填
  17. TThostFtdcPriceType StopPrice 止损价 必填
//限价单:
CThostFtdcInputOrderField ord = { 0 };
strcpy_s(ord.BrokerID, “0000”);
strcpy_s(ord.InvestorID, “00001”); 
strcpy_s(ord.ExchangeID, “SHFE”);
strcpy_s(ord.InstrumentID, “ag1801”);
strcpy_s(ord.UserID, “00001”);
ord.OrderPriceType = THOST_FTDC_OPT_LimitPrice;//限价
ord.Direction = THOST_FTDC_D_Buy;//买
ord.CombOffsetFlag[0] = THOST_FTDC_OF_Open;//开
ord.CombHedgeFlag[0] = THOST_FTDC_HF_Speculation;//投机
ord.LimitPrice = 100;
ord.VolumeTotalOriginal = 1;
ord.TimeCondition = THOST_FTDC_TC_GFD;///当日有效
ord.VolumeCondition = THOST_FTDC_VC_AV;///任意数量
ord.MinVolume = 1;
ord.ContingentCondition = THOST_FTDC_CC_Immediately;
ord.StopPrice = 0;
ord.ForceCloseReason = THOST_FTDC_FCC_NotForceClose;
ord.IsAutoSuspend = 0;
m_pUserApi->ReqOrderInsert(&ord, nRequestID++);

返回

  1. 0,代表成功。
  2. -1,表示网络连接失败;
  3. -2,表示未处理请求超过许可数;
  4. -3,表示每秒发送请求数超过许可数。

报单响应

类型

  1. 报单回报
    指报单的状态回报,有未知单报单回报、未成交报单回报、部分成交报单回报、全部成交报单回报和撤单回报。对应回调函数OnRtnOrder,以OrderStatus字段区分。

  2. 成交回报
    指报单成交后推送的成交回报,对应回调函数OnRtnTrade。

  3. 错单响应
    指报单被CTP拒绝后返回的响应通知,对应回调函数OnRspOrderInsert,其中ErrorID和ErrorMsg指明了错误原因。

  4. 错单回报
    指报单被CTP或交易所拒绝后的报单的状态回报。对应回调函数OnErrRtnOrderInsert。

顺序

  1. 报单合约ag1207,报入1手,到交易所先未成交,后全部成交1手。
    ReqOrderInsert (报单)
    OnRtnOrder (未知单)
    OnRtnOrder (未成交) // 此时CTP接收到交易所的未成交报单回报
    OnRtnOrder (未成交) // 此时CTP接收到交易所的成交回报和全部成交报单回报
    OnRtnOrder (全部成交)
    OnRtnTrade

  2. 报单合约ag1207,报入1手,到交易所立即全部成交1手。(注意,此案例没有收到交易所的未成交回报状态,而是直接收到全部成交状态)
    ReqOrderInsert (报单)
    OnRtnOrder (未知单) // 此时CTP接收到交易所的成交回报和成交报单回报
    OnRtnOrder (未知单)
    OnRtnOrder (全部成交报单已提交)
    OnRtnTrade

  3. 报单合约ag1207,报入1手,到交易所先未成交,然后撤单1手。
    ReqOrderInsert (报单)
    OnRtnOrder(未知单)
    OnRtnOrder(未成交) // 此时CTP接收到交易所的未成交报单回报
    ReqOrderAction(撤单)
    OnRtnOrder(未成交) // 此时CTP接收到交易所的撤单报单回报
    OnRtnOrder(已撤单)

  4. 报单合约ag1207,报入10手,到交易所先未成交,然后成交3手,然后剩余全部成交7手
    ReqOrderInsert (报单)
    OnRtnOrder (未知单)
    OnRtnOrder (未成交) // 此时CTP接收到交易所的未成交报单回报
    OnRtnOrder (未成交) // 此时CTP接收到交易所的成交回报和部分成交报单回报
    OnRtnOrder (部分成交)
    OnRtnTrade
    OnRtnOrder (部分成交) // 此时CTP接收到交易所的成交回报和全部成交报单回报
    OnRtnOrder (全部成交)
    OnRtnTrade

  5. 报单合约ag1207,报入10手,到交易所先未成交,然后成交4手,然后剩余全部撤单6手
    ReqOrderInsert (报单)
    OnRtnOrder (未知单
    OnRtnOrder (未成交) // 此时CTP接收到交易所的未成交报单回报
    OnRtnOrder (未成交) // 此时CTP接收到交易所的成交回报和部分成交报单回报
    OnRtnOrder (部分成交)
    OnRtnTrade
    ReqOrderAction (撤单)
    OnRtnOrder(部分成交) // 此时CTP接收到交易所的撤单回报
    OnRtnOrder(已撤单)

  6. 对一笔已经撤单的委托单再次撤单。
    ReqOrderAction (撤单)
    OnRspOrderAction (CTP:报单已全成交或已撤销,不能再撤)
    OnErrRtnOrderAction (CTP:报单已全成交或已撤销,不能再撤)

  7. 对一笔未成交委托进行撤单,因为委托号填写错误导致撤单失败
    ReqOrderAction (撤单)
    OnRspOrderAction (CTP:撤单找不到相应报单)
    OnErrRtnOrderAction (CTP:撤单找不到相应报单)

大商所特殊回调规则

针对大商所特殊回调规则,ctp已经补充成以上顺序了。


评论