Ejemplo n.º 1
0
        public bool OrderCancel(CustomOrder order, out string errMsg)
        {
            if (order == null || string.IsNullOrEmpty(order.InstrumentID))
            {
                errMsg = "CTP撤单时Order参数不能为空,InstrumentID信息也不能为空";
                return(false);
            }

            ThostFtdcInputOrderActionField inAction = new ThostFtdcInputOrderActionField();

            inAction.BrokerID   = BROKER_ID;
            inAction.InvestorID = INVESTOR_ID;
            inAction.FrontID    = FRONT_ID;
            inAction.SessionID  = SESSION_ID;

            inAction.InstrumentID = order.InstrumentID;
            inAction.OrderRef     = order.OrderNo.ToString();
            inAction.ActionFlag   = EnumActionFlagType.Delete;

            // 撤单
            var ret = trader.ReqOrderAction(inAction, iRequestID++);

            errMsg = (ret == 0) ? "-" : "CTP撤单失败,返回值:" + ret;

            return(ret == 0);
        }
Ejemplo n.º 2
0
 private void CtpTrader_OnRspOrderAction(ThostFtdcInputOrderActionField pInputOrderAction, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (pRspInfo != null)
     {
         Console.WriteLine(pRspInfo.ErrorMsg);
     }
 }
Ejemplo n.º 3
0
 public static string ToString2(this ThostFtdcInputOrderActionField field)
 {
     return(string.Format("OrderRef:{0},{1},{2}",
                          field.OrderRef,
                          field.UserID,
                          field.InstrumentID
                          ));
 }
Ejemplo n.º 4
0
        public int ReqOrderAction(string exchangeId, string orderSysId, string instrumentId, EnumActionFlagType actionFlag = EnumActionFlagType.Delete)
        {
            var req = new ThostFtdcInputOrderActionField
            {
                ActionFlag   = actionFlag,
                ExchangeID   = exchangeId,
                OrderSysID   = orderSysId,
                InstrumentID = instrumentId
            };

            int ret = ReqOrderAction(req, ++RequestId);

            return(ret);
        }
Ejemplo n.º 5
0
        public int ReqOrderAction(int frontId, int sessionId, string orderRef, string instrumentId, EnumActionFlagType actionFlag = EnumActionFlagType.Delete)
        {
            var req = new ThostFtdcInputOrderActionField
            {
                ActionFlag   = actionFlag,
                BrokerID     = _brokerId,
                InvestorID   = _investorId,
                FrontID      = frontId,
                SessionID    = sessionId,
                OrderRef     = orderRef,
                InstrumentID = instrumentId
            };

            int ret = ReqOrderAction(req, ++RequestId);

            return(ret);
        }
Ejemplo n.º 6
0
        private void OnRspOrderAction(ThostFtdcInputOrderActionField pInputOrderAction, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            __DEBUGPF__();
            //IsErrorRspInfo(pRspInfo);

            if (HandleErrRtnOrderCancelDel != null)
            {
                var customOrder = new CustomOrder();
                // 原始报单信息
                customOrder.OrderNo      = int.Parse(pInputOrderAction.OrderRef);
                customOrder.InstrumentID = pInputOrderAction.InstrumentID;
                customOrder.Price        = pInputOrderAction.LimitPrice;
                // 更新委托回报信息
                customOrder.tradeRef = pInputOrderAction.ExchangeID + "_" + pInputOrderAction.OrderSysID;

                HandleErrRtnOrderCancelDel(customOrder, pRspInfo.ErrorMsg);
            }
        }
Ejemplo n.º 7
0
        void ReqOrderAction(ThostFtdcOrderField pOrder)
        {
            if (ORDER_ACTION_SENT)
            {
                return;
            }

            ThostFtdcInputOrderActionField req = new ThostFtdcInputOrderActionField();

            ///经纪公司代码
            req.BrokerID = pOrder.BrokerID;
            ///投资者代码
            req.InvestorID = pOrder.InvestorID;
            ///报单操作引用
            //	TThostFtdcOrderActionRefType	OrderActionRef;
            ///报单引用
            req.OrderRef = pOrder.OrderRef;
            ///请求编号
            //	TThostFtdcRequestIDType	RequestID;
            ///前置编号
            req.FrontID = FRONT_ID;
            ///会话编号
            req.SessionID = SESSION_ID;
            ///交易所代码
            //	TThostFtdcExchangeIDType	ExchangeID;
            ///报单编号
            //	TThostFtdcOrderSysIDType	OrderSysID;
            ///操作标志
            req.ActionFlag = CTP.EnumActionFlagType.Delete;
            ///价格
            //	TThostFtdcPriceType	LimitPrice;
            ///数量变化
            //	TThostFtdcVolumeType	VolumeChange;
            ///用户代码
            //	TThostFtdcUserIDType	UserID;
            ///合约代码
            req.InstrumentID = pOrder.InstrumentID;

            int iResult = api.ReqOrderAction(req);

            Console.WriteLine("--->>> 报单操作请求: " + ((iResult == 0) ? "成功" : "失败"));

            ORDER_ACTION_SENT = true;
        }
Ejemplo n.º 8
0
        public void CancelOrder(OptionOrder order)
        {
            var native = new List <ThostFtdcOrderField>(this._orders).First(_ => _.OrderSysID == order.OrderID);
            var action = new ThostFtdcInputOrderActionField
            {
                BrokerID     = this._config.BrokerId,
                InvestorID   = this._config.Account,
                OrderSysID   = native.OrderSysID,
                ActionFlag   = EnumActionFlagType.Delete,
                UserID       = this._config.Account,
                ExchangeID   = native.ExchangeID,
                OrderRef     = native.OrderRef,
                InstrumentID = order.InstrumentID
            };
            var ret = this._trade.ReqOrderAction(action, this._session.NextRequestID());

            if (ret != 0)
            {
                this.OnLog(string.Format("发送撤单请求失败,返回{0}", ret));
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 下单、超时撤单
        /// </summary>
        /// <param name="order"></param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        public bool PlaceOrder(ThostFtdcInputOrderField order, int timeout)
        {
            isSuccess = true;

            autoResetEventOrderCompleted = new AutoResetEvent(false);
            frame.CtpTrader.OnRtnOrder  += CtpTrader_OnRtnOrder;

            Console.WriteLine("Send order. ({0})", order.ToString2());
            frame.CtpTrader.ReqOrderInsert(order);

            var isTimeout = !autoResetEventOrderCompleted.WaitOne(timeout);

            if (isTimeout)
            {
                isSuccess = false;
                frame.CtpTrader.OnRspOrderAction += CtpTrader_OnRspOrderAction;
                var cancelOrder = new ThostFtdcInputOrderActionField()
                {
                    ActionFlag   = EnumActionFlagType.Delete,
                    BrokerID     = orderOnWay.BrokerID,
                    InvestorID   = orderOnWay.InvestorID,
                    InstrumentID = orderOnWay.InstrumentID,
                    FrontID      = orderOnWay.FrontID,
                    SessionID    = orderOnWay.SessionID,
                    OrderSysID   = orderOnWay.OrderSysID,
                    OrderRef     = orderOnWay.OrderRef,
                    ExchangeID   = orderOnWay.ExchangeID,
                };
                Console.WriteLine("撤单。({0})", cancelOrder.ToString2());
                frame.CtpTrader.ReqOrderAction(cancelOrder);

                autoResetEventOrderCompleted.WaitOne();
            }

            frame.CtpTrader.OnRtnOrder -= CtpTrader_OnRtnOrder;

            return(isSuccess);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 撤单
        /// </summary>
        /// <param name="req"></param>
        public void CancelOrder(CancelOrderReq cancelOrderReq)
        {
            ThostFtdcInputOrderActionField req = new ThostFtdcInputOrderActionField();

            ///经纪公司代码
            req.BrokerID = this.BrokerID;
            ///投资者代码
            req.InvestorID = this.UserID;
            ///报单操作引用
            //	TThostFtdcOrderActionRefType	OrderActionRef;
            ///报单本地委托号
            req.OrderRef = cancelOrderReq.orderID;
            ///请求编号
            //	TThostFtdcRequestIDType	RequestID;
            ///前置编号
            req.FrontID = cancelOrderReq.frontID;
            ///会话编号
            req.SessionID = cancelOrderReq.sessionID;
            ///交易所代码
            //	TThostFtdcExchangeIDType	ExchangeID;
            ///报单编号
            //	TThostFtdcOrderSysIDType	OrderSysID;
            ///操作标志
            req.ActionFlag = CTP.EnumActionFlagType.Delete;
            ///价格
            //	TThostFtdcPriceType	LimitPrice;
            ///数量变化
            //	TThostFtdcVolumeType	VolumeChange;
            ///用户代码
            //	TThostFtdcUserIDType	UserID;
            ///合约代码
            req.InstrumentID = cancelOrderReq.symbol;

            int iResult = this.ReqOrderAction(req, ++this.reqID);

            Console.WriteLine("--->>> 报单操作请求: " + ((iResult == 0) ? "成功" : "失败"));
        }
Ejemplo n.º 11
0
 /// <summary>
 /// 撤单错误(柜台)
 /// </summary>
 /// <param name="pInputOrderAction"></param>
 /// <param name="pRspInfo"></param>
 /// <param name="nRequestID"></param>
 /// <param name="bIsLast"></param>
 public void HandleOnRspOrderAction(ThostFtdcInputOrderActionField pInputOrderAction, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     Console.WriteLine("撤单错误(柜台)" + pRspInfo.ErrorMsg);
 }
Ejemplo n.º 12
0
        /// <summary>
        /// 报单操作请求响应
        /// </summary>
        /// <param name="pInputOrderAction"></param>
        /// <param name="pRspInfo"></param>
        /// <param name="nRequestID"></param>
        /// <param name="bIsLast"></param>
        void OnRspOrderAction(ThostFtdcInputOrderActionField pInputOrderAction, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            DateTime logtime = DateTime.Now;
            if (IsErrorRspInfo(pRspInfo))
            {

            }
            if (bIsLast && IsErrorRspInfo(pRspInfo))
            {

            }
        }
Ejemplo n.º 13
0
 /// <summary>
 /// 撤单
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void GridView_RtnOrder_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
 {
     //"报单引用", "会话标识", "前置机标识", "品种名称", "买卖", "开平", "投机标志", "价格", "报单量", "今成交", "剩余量", "报单日期", "报单时间", "报单状态", "状态信息", "备注" };
     if (e.RowIndex >= 0)
     {
         ThostFtdcInputOrderActionField OrderAction = new ThostFtdcInputOrderActionField();
         var result = MessageBox.Show("是否撤单?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (result == DialogResult.Yes)
         {
             OrderAction.BrokerID = this.sBrokerID;
             OrderAction.ActionFlag = EnumActionFlagType.Delete;
             OrderAction.FrontID = Int32.Parse(this.GridView_RtnOrder.Rows[e.RowIndex].Cells["前置机标识"].Value.ToString());
             OrderAction.InstrumentID = this.GridView_RtnOrder.Rows[e.RowIndex].Cells["品种名称"].Value.ToString();
             OrderAction.InvestorID = this.sUserID;
             OrderAction.UserID = null;
             OrderAction.OrderSysID = this.GridView_RtnOrder.Rows[e.RowIndex].Cells["报单编号"].Value.ToString();
             OrderAction.ExchangeID = this.GridView_RtnOrder.Rows[e.RowIndex].Cells["交易所"].Value.ToString();
             OrderAction.OrderRef = this.GridView_RtnOrder.Rows[e.RowIndex].Cells["报单引用"].Value.ToString();
             OrderAction.SessionID = Int32.Parse(this.GridView_RtnOrder.Rows[e.RowIndex].Cells["会话标识"].Value.ToString());
             this.TDReqOrderAction(OrderAction);
         }
     }
 }
Ejemplo n.º 14
0
 ///报单操作请求响应
 public void OnRspOrderAction(ThostFtdcInputOrderActionField pInputOrderAction, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (!IsErrorRspInfo(pRspInfo))
     {
     }
 }
Ejemplo n.º 15
0
 public void TDReqOrderAction(ThostFtdcInputOrderActionField OrderAction)
 {
     this.CtpTDApi.ReqOrderAction(OrderAction, ++nRequestID);
 }
Ejemplo n.º 16
0
 private string GetOrderKey(ThostFtdcInputOrderActionField pInputOrderAction)
 {
     return(string.Format("{0}:{1}", pInputOrderAction.ExchangeID, pInputOrderAction.OrderSysID));
 }
Ejemplo n.º 17
0
 private void TD_OnCancelAction(ThostFtdcInputOrderActionField pInputOrderAction, ThostFtdcRspInfoField pRspInfo)
 {
 }
Ejemplo n.º 18
0
        /// <summary>
        /// 取消报单
        /// </summary>
        /// <param name="order"></param>
        /// <returns>-1--无效报单,0--下撤单指令成功,1--下撤单指令失败</returns>
        public int CancelOrder(ThostFtdcOrderField pOrder)
        {
            lock (ReqLock)
            {
                ThostFtdcInputOrderActionField req = new ThostFtdcInputOrderActionField();
                ///操作标志
                req.ActionFlag = EnumActionFlagType.Delete;
                ///经纪公司代码
                req.BrokerID = pOrder.BrokerID;
                ///交易所代码
                req.ExchangeID = pOrder.ExchangeID;
                ///前置编号
                req.FrontID = pOrder.FrontID;
                ///投资者代码
                req.InvestorID = pOrder.InvestorID;
                ///合约代码
                req.InstrumentID = pOrder.InstrumentID;
                ///报单引用
                req.OrderRef = pOrder.OrderRef;
                ///报单编号
                req.OrderSysID = pOrder.OrderSysID;
                //请求编号
                //req.RequestID = pOrder.RequestID;
                ///会话编号
                req.SessionID = pOrder.SessionID;
                ///用户代码
                req.UserID = pOrder.UserID;
                int iResult = trader.ReqOrderAction(req, ++RequestID);

                if (OrderRef2ArbitrageStategyMap.ContainsKey(pOrder.OrderRef))
                {
                    OrderRef2ArbitrageStategyMap.Remove(pOrder.OrderRef);
                }
                return iResult;
            }
        }
Ejemplo n.º 19
0
 /// <summary>
 /// 撤销报单
 /// </summary>
 /// <param name="pInputOrderAction"></param>
 /// <returns></returns>
 public int CancelOrder(ThostFtdcInputOrderActionField pInputOrderAction)
 {
     lock (ReqLock)
     {
         int iResult = trader.ReqOrderAction(pInputOrderAction, ++RequestID);
         if (OrderRef2ArbitrageStategyMap.ContainsKey(pInputOrderAction.OrderRef))
         {
             OrderRef2ArbitrageStategyMap.Remove(pInputOrderAction.OrderRef);
         }
         return iResult;
     }
 }
Ejemplo n.º 20
0
 void OnRspOrderAction(ThostFtdcInputOrderActionField pInputOrderAction, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     DebugPrintFunc(new StackTrace());
     IsErrorRspInfo(pRspInfo);
 }
Ejemplo n.º 21
0
 void OnRspOrderAction(ThostFtdcInputOrderActionField pInputOrderAction, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     __DEBUGPF__();
     IsErrorRspInfo(pRspInfo);
 }
Ejemplo n.º 22
0
 private void TD_OnCancelAction(ThostFtdcInputOrderActionField pInputOrderAction, ThostFtdcRspInfoField pRspInfo)
 {
     if (pRspInfo.ErrorID == 26 || pRspInfo.ErrorID == 25 || pRspInfo.ErrorID == 24)
     {
         //不处理
     }
     else
     {
         int cancelOrderResult = -1;
         do
         {
             //cancelOrderResult = TDManager.TD.CancelOrder(pInputOrderAction);
         }
         while (cancelOrderResult != 0);
     }
 }
Ejemplo n.º 23
0
        /// <summary>
        /// 报单操作请求
        /// </summary>
        /// <param name="pOrder"></param>
        void ReqOrderAction(ThostFtdcOrderField pOrder)
        {
            if (ORDER_ACTION_SENT)
                return;

            ThostFtdcInputOrderActionField req = new ThostFtdcInputOrderActionField();
            //经纪公司代码
            req.BrokerID = pOrder.BrokerID;
            //投资者代码
            req.InvestorID = pOrder.InvestorID;
            //报单引用
            req.OrderRef = pOrder.OrderRef;
            //请求编号
               req.RequestID = 5;
            //前置编号
            req.FrontID = FRONT_ID;
            //会话编号
            req.SessionID = SESSION_ID;
            //交易所代码
            req.ExchangeID = INVESTOR_ID;
            //报单编号
            //	TThostFtdcOrderSysIDType	OrderSysID;
            //操作标志
            req.ActionFlag = KSFT.EnumActionFlagType.Delete;
            //用户代码
            req.UserID = INVESTOR_ID;
            //合约代码
            req.InstrumentID = pOrder.InstrumentID;

            int iResult = api.ReqOrderAction(req, ++iRequestID);
            Console.WriteLine("--->>> 报单操作请求: " + ((iResult == 0) ? "成功" : "失败"));

            ORDER_ACTION_SENT = true;
        }
Ejemplo n.º 24
0
 public static extern int TdReqOrderAction(IntPtr pApi, ThostFtdcInputOrderActionField pInputOrderAction, int nRequestID);
Ejemplo n.º 25
0
 /// <summary>
 /// 报单操作应答
 /// </summary>
 /// <param name="pInputOrderAction"></param>
 /// <param name="pRspInfo"></param>
 /// <param name="nRequestID"></param>
 /// <param name="bIsLast"></param>
 void OnRspOrderAction(ThostFtdcInputOrderActionField pInputOrderAction, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     DebugPrintFunc(new StackTrace());
     IsErrorRspInfo(pRspInfo);
 }
Ejemplo n.º 26
0
 /// <summary>
 ///报单操作请求
 /// </summary>
 public int ReqOrderAction(ThostFtdcInputOrderActionField pInputOrderAction, int nRequestID)
 {
     return(Interop.TdReqOrderAction(Handle, pInputOrderAction, nRequestID));
 }
Ejemplo n.º 27
0
 private void TraderAdapter_OnRspOrderAction(ThostFtdcInputOrderActionField pInputOrderAction,
                                             ThostFtdcRspInfoField pRspInfo, int nRequestId, bool bIsLast)
 {
 }