コード例 #1
0
        public bool PlaceOrder(ThostFtdcInputOrderField order)
        {
            isSuccess = false;

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

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

            autoResetEventOrderCompleted.WaitOne();
            frame.CtpTrader.OnRtnOrder -= CtpTrader_OnRtnOrder;

            return(isSuccess);
        }
コード例 #2
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);
        }