/// <summary>
        /// 委托回报变更。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OrderDriver_OnOrderBookChanged(object sender, USeOrderBookChangedEventArgs e)
        {
            try
            {
                OrderBookUpdateResult result = null;
                lock (m_syncObj)
                {
                    result = m_arbitrageOrder.UpdateOrderBook(e.OrderBook);
                    if (result != null)
                    {
                        result.Task.UpdateTaskState();

                        m_arbitrageOrder.UpdataArbitrageOrderState();
                        m_operatorEvent.Set();
                    }
                }

                if (result != null)
                {
                    //委托更新触发流程监控运行
                    m_operatorEvent.Set();
                    SafeFireArbitrageOrderChanged();

                    AutoTraderNotice tradeNotice = result.CreateNotice(this.TraderIdentify, this.Alias);
                    if (tradeNotice != null)
                    {
                        SafeFireAutoTraderNotice(tradeNotice);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Assert(false, ex.Message);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 更新委托回报。
        /// </summary>
        /// <param name="orderBook">委托回报。</param>
        /// <returns>更新委托回报条数。</returns>
        public OrderBookUpdateResult UpdateOrderBook(USeOrderBook orderBook)
        {
            OrderBookUpdateResult result = m_firstSubTask.UpdateOrderBook(orderBook);

            if (result != null)
            {
                return(result);
            }
            result = m_secondSubTask.UpdateOrderBook(orderBook);
            return(result);
        }
Beispiel #3
0
        private OrderBookUpdateResult GetOrderBookUpdateResult(USeOrderBook oldOrderBook, USeOrderBook newOrderBook)
        {
            OrderBookUpdateResult result = new OrderBookUpdateResult()
            {
                TradeQty  = newOrderBook.TradeQty - oldOrderBook.TradeQty,
                CancelQty = newOrderBook.CancelQty - oldOrderBook.CancelQty,
                BlankQty  = newOrderBook.BlankQty - oldOrderBook.BlankQty
            };

            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// 更新委托回报。
        /// </summary>
        /// <param name="orderBook">委托回报。</param>
        /// <returns>更新委托回报条数。</returns>
        public OrderBookUpdateResult UpdateOrderBook(USeOrderBook orderBook)
        {
            for (int i = 0; i < m_orderBookList.Count; i++)
            {
                USeOrderBook orderBookItem = m_orderBookList[i];
                if (orderBookItem.OrderNum.Equals(orderBook.OrderNum))
                {
                    OrderBookUpdateResult result = GetOrderBookUpdateResult(m_orderBookList[i], orderBook);
                    m_orderBookList[i] = orderBook.Clone();
                    return(result);
                }
            }

            return(null);
        }
Beispiel #5
0
        /// <summary>
        /// 更新委托回报。
        /// </summary>
        /// <param name="orderBook">委托回报。</param>
        /// <returns>影响的任务。</returns>
        public OrderBookUpdateResult UpdateOrderBook(USeOrderBook orderBook)
        {
            OrderBookUpdateResult result = m_openTaskGroup.UpdateOrderBook(orderBook);

            if (result != null)
            {
                return(result);
            }

            result = m_closeTaskGroup.UpdateOrderBook(orderBook);
            if (result != null)
            {
                return(result);
            }

            return(null);
        }
Beispiel #6
0
        /// <summary>
        /// 更新委托回报。
        /// </summary>
        /// <param name="orderBook">委托回报。</param>
        public OrderBookUpdateResult UpdateOrderBook(USeOrderBook orderBook)
        {
            foreach (ArbitrageTask task in m_taskList)
            {
                if (task.ContainsOrderBook(orderBook.OrderNum))
                {
                    OrderBookUpdateResult result = task.UpdateOrderBook(orderBook);
                    Debug.Assert(result != null);

                    if (result != null)
                    {
                        result.Task = task;
                        return(result);
                    }
                }
            }

            return(null);
        }
Beispiel #7
0
        /// <summary>
        /// 检查套利单是否有异常委托。
        /// </summary>
        /// <remarks>
        /// 1.非今日的历史委托回报未结束,无法更新,列入异常套利单
        /// </remarks>
        private ErrorArbitrageOrder CheckErrorArbitrageOrder(USeArbitrageOrder arbitrageOrder)
        {
            ErrorArbitrageOrder errorArbitrageOrder = new ErrorArbitrageOrder();

            errorArbitrageOrder.ArbitrageOrder = arbitrageOrder;

            List <ErrorUSeOrderBook> errorBookList = new List <ErrorUSeOrderBook>();

            if (arbitrageOrder.HasUnFinishOrderBook == false)
            {
                return(errorArbitrageOrder);
            }

            List <USeOrderBook> unFinishOrderBookList = arbitrageOrder.GetAllUnfinishOrderBooks();

            Debug.Assert(unFinishOrderBookList != null && unFinishOrderBookList.Count > 0);

            foreach (USeOrderBook orderBook in unFinishOrderBookList)
            {
                USeOrderBook newOrderBook = m_orderDriver.QueryOrderBook(orderBook.OrderNum);
                if (newOrderBook != null)
                {
                    OrderBookUpdateResult updateResult = arbitrageOrder.UpdateOrderBook(newOrderBook);
                    updateResult.Task.UpdateTaskState();
                    arbitrageOrder.UpdataArbitrageOrderState();
                    errorArbitrageOrder.HasChanged = true;
                }
                else
                {
                    ErrorUSeOrderBook errorOrderBook = new ErrorUSeOrderBook()
                    {
                        TradeIdentify = arbitrageOrder.TraderIdentify,
                        Alias         = arbitrageOrder.Alias,
                        OrderBook     = orderBook.Clone()
                    };
                    errorBookList.Add(errorOrderBook);
                }
            }

            errorArbitrageOrder.ErrorOrderBooks = errorBookList;

            return(errorArbitrageOrder);
        }
Beispiel #8
0
        /// <summary>
        /// 处理异常委托单。
        /// </summary>
        /// <returns></returns>
        private bool PorcessErrorOrderBook()
        {
            //m_checkErrorOrderBook = true;
            //return true;

            string text = string.Empty;

            try
            {
                //1.读取所有未完成套利单信息
                List <USeArbitrageOrder> arbitrageOrderList = m_dataAccessor.GetUnfinishArbitrageOrders(m_loginUser.BrokerId, m_loginUser.Account);
                text = string.Format("读取[{0}]所有未完成套利单信息成功,共计{1}个套利单", m_loginUser, arbitrageOrderList.Count);
                m_eventLogger.WriteInformation(text);

                //2.检查是否有异常套利单
                Dictionary <Guid, ErrorArbitrageOrder> errorArbitrageOrderDic = new Dictionary <Guid, ErrorArbitrageOrder>();
                List <ErrorUSeOrderBook> errorOrderBookList = new List <ErrorUSeOrderBook>();

                foreach (USeArbitrageOrder arbitrageOrder in arbitrageOrderList)
                {
                    ErrorArbitrageOrder errorArbitrageOrder = CheckErrorArbitrageOrder(arbitrageOrder);
                    if (errorArbitrageOrder.HasError)
                    {
                        errorArbitrageOrderDic.Add(arbitrageOrder.TraderIdentify, errorArbitrageOrder);
                        errorOrderBookList.AddRange(errorArbitrageOrder.ErrorOrderBooks);
                    }
                    if (errorArbitrageOrder.HasChanged)
                    {
                        //有变更先记录到文件
                        m_dataAccessor.SaveUSeArbitrageOrder(errorArbitrageOrder.ArbitrageOrder);
                    }
                }

                text = string.Format("[{0}]有{1}个异常套利单共计{2}条委托回报需人工介入",
                                     m_loginUser, errorArbitrageOrderDic.Count, errorOrderBookList.Count);
                m_eventLogger.WriteError(text);

                //3.人工处理异常套利单
                if (errorOrderBookList.Count > 0)
                {
                    ErrorOrderBookProcessForm errorOrderBookForm = new ErrorOrderBookProcessForm(errorOrderBookList);
                    if (DialogResult.Yes != errorOrderBookForm.ShowDialog())
                    {
                        return(false);
                    }

                    List <ErrorUSeOrderBook> checkBookList = errorOrderBookForm.Result;
                    Debug.Assert(checkBookList.Count == errorOrderBookList.Count);

                    foreach (ErrorUSeOrderBook checkOrderBook in checkBookList)
                    {
                        Debug.Assert(checkOrderBook.OrderBook.IsFinish);
                        ErrorArbitrageOrder errorArbitrageOrder = null;
                        if (errorArbitrageOrderDic.TryGetValue(checkOrderBook.TradeIdentify, out errorArbitrageOrder) == false)
                        {
                            Debug.Assert(false);
                            continue;
                        }
                        OrderBookUpdateResult updateResult = errorArbitrageOrder.ArbitrageOrder.UpdateOrderBook(checkOrderBook.OrderBook);
                        Debug.Assert(updateResult != null);
                        if (updateResult != null)
                        {
                            updateResult.Task.UpdateTaskState();
                            errorArbitrageOrder.ArbitrageOrder.UpdataArbitrageOrderState();
                        }
                    }

                    foreach (ErrorArbitrageOrder errorArbitageOrder in errorArbitrageOrderDic.Values)
                    {
                        m_dataAccessor.SaveUSeArbitrageOrder(errorArbitageOrder.ArbitrageOrder);
                    }
                }

                m_checkErrorOrderBook = true;
                return(true);
            }
            catch (Exception ex)
            {
                text = "异常单处理失败," + ex.Message;
                m_eventLogger.WriteError(text);
                throw new ApplicationException(text);
            }
        }