Ejemplo n.º 1
0
        /// <summary>
        /// 初始化。
        /// </summary>
        /// <param name="arbitrageOrderList">套利单信息。</param>
        /// <param name="orderDriver">交易驱动。</param>
        /// <param name="quoteDriver">行情驱动。</param>
        /// <param name="alarmManager">预警管理类。</param>
        /// <param name="systemConfigManager">系统配置管理类。</param>
        public void Initialize(List <USeArbitrageOrder> arbitrageOrderList, USeOrderDriver orderDriver, USeQuoteDriver quoteDriver, AlarmManager alarmManager, SystemConfigManager systemConfigManager)
        {
            m_orderDriver         = orderDriver;
            m_quoteDriver         = quoteDriver;
            m_alarmManager        = alarmManager;
            m_systemConfigManager = systemConfigManager;

            m_systemConfigManager.OnSystemSettingChanged += M_systemConfigManager_OnSystemSettingChanged1;

            if (arbitrageOrderList == null || arbitrageOrderList.Count <= 0)
            {
                return;
            }

            lock (m_syncObj)
            {
                int maxAliasNum = 0;  // 当日别名最大号码

                TaskOrderSetting taskOrderSetting = m_systemConfigManager.GetTaskOrderSetting();
                foreach (USeArbitrageOrder arbitrageOrder in arbitrageOrderList)
                {
                    AutoTrader autoTrader = new AutoTrader();
                    autoTrader.SetRecordLogger(USeManager.Instance.CommandLogger);
                    autoTrader.SetTryOrderCondition(taskOrderSetting.TaskMaxTryCount, taskOrderSetting.TryOrderMinInterval);
                    autoTrader.Initialize(arbitrageOrder, m_orderDriver, m_quoteDriver, m_alarmManager);
                    autoTrader.OnNotify                += AutoTrader_OnNotify;
                    autoTrader.OnAlarm                 += AutoTrader_OnAlarm;
                    autoTrader.OnStateChanged          += AutoTrader_OnStateChanged;
                    autoTrader.OnArbitrageOrderChanged += AutoTrader_OnArbitrageOrderChanged;
                    m_autoTraderDic.Add(autoTrader.TraderIdentify, autoTrader);

                    if (arbitrageOrder.CreateTime.Date == DateTime.Today && arbitrageOrder.AliasNum > maxAliasNum)
                    {
                        maxAliasNum = arbitrageOrder.AliasNum;
                    }
                }

                m_aliasIdCrateor.Set(maxAliasNum);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 初始化套利下单机。
        /// </summary>
        /// <param name="arbitrageOrder">套利单信息。</param>
        /// <param name="orderDriver">下单驱动。</param>
        /// <param name="quoteDriver">行情驱动。</param>
        /// <param name="alarmManager">预警管理类。</param>
        public void Initialize(USeArbitrageOrder arbitrageOrder, USeOrderDriver orderDriver, USeQuoteDriver quoteDriver, AlarmManager alarmManager)
        {
            if (m_initialized)
            {
                throw new ApplicationException(string.Format("{0} already initialized.", this));
            }

            if (arbitrageOrder == null)
            {
                throw new ArgumentNullException("arbitrageOrder", "arbitrageOrder is null");
            }

            if (orderDriver == null)
            {
                throw new ArgumentNullException("orderDriver", "orderDriver is null");
            }

            if (quoteDriver == null)
            {
                throw new ArgumentNullException("quoteDrvier", "quoteDrvier is null");
            }

            if (alarmManager == null)
            {
                throw new ArgumentNullException("alarmManager", "alarmManager is null");
            }

            try
            {
                lock (m_syncObj)
                {
                    m_arbitrageOrder = arbitrageOrder.Clone();

                    m_orderDriver = orderDriver;
                    m_quoteDriver = quoteDriver;
                }

                m_orderDriver.OnOrderBookChanged  += OrderDriver_OnOrderBookChanged;
                m_quoteDriver.OnMarketDataChanged += QuoteDriver_OnMarketDataChanged;

                if (arbitrageOrder.OpenArgument != null)
                {
                    m_quoteDriver.Subscribe(arbitrageOrder.OpenArgument.BuyInstrument);
                    m_quoteDriver.Subscribe(arbitrageOrder.OpenArgument.SellInstrument);
                }

                string           text   = string.Format("初始化套利单完成,当前状态为[{0}]", arbitrageOrder.State.ToDescription());
                AutoTraderNotice notice = CreateTraderNotice(text);
                SafeFireAutoTraderNotice(notice);
                WriteTraderNoticeLog(notice);
            }
            catch (Exception ex)
            {
                string           text   = string.Format("初始化套利单失败,原因:{0}", ex.Message);
                AutoTraderNotice notice = CreateTraderNotice(text);
                SafeFireAutoTraderNotice(notice);
                WriteTraderNoticeLog(notice);

                throw new Exception("初始化自定下单机失败");
            }
            m_initialized = true;
        }