Пример #1
0
        private void InternalStart()
        {
            try
            {
                m_dataSaver.Start();
            }
            catch (Exception ex)
            {
                m_eventLogger.WriteError("数据保存器启动失败," + ex.Message);
                throw new ApplicationException("数据保存器启动失败");
            }

            string text = string.Empty;
            //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.检查是否有异常套利单
            //[yangming] 测试环境暂时不校验

            if ((m_orderDriver is USe.TradeDriver.Test.USeTestOrderDriver) == false)
            {
                foreach (USeArbitrageOrder arbitrageOrder in arbitrageOrderList)
                {
                    ErrorArbitrageOrder errorArbitrageOrder = CheckErrorArbitrageOrder(arbitrageOrder);
                    if (errorArbitrageOrder.HasError)
                    {
                        text = string.Format("{0}有未处理异常委托单", arbitrageOrder);
                        m_eventLogger.WriteError(text);
                        throw new Exception(text);
                    }
                    if (errorArbitrageOrder.HasChanged)
                    {
                        m_dataAccessor.SaveUSeArbitrageOrder(arbitrageOrder);
                    }
                }
            }

            //3.初始化自动下单机管理类
            Debug.Assert(m_orderDriver != null);
            Debug.Assert(m_quoteDriver != null);
            Debug.Assert(m_alarmManager != null);
            m_autoTraderManager.Initialize(arbitrageOrderList, m_orderDriver, m_quoteDriver, m_alarmManager, m_systemConfigManager);

            m_fundCalculator.Initialize(m_orderDriver, m_quoteDriver);
            m_fundCalculator.Start();
        }
Пример #2
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);
        }
Пример #3
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);
            }
        }