Пример #1
0
        /// <summary>
        /// 创建新的套利订单。
        /// </summary>
        /// <param name="argument">套利单参数。</param>
        /// <param name="currentInvestor">当前投资者帐号。</param>
        public AutoTrader CreateNewAutoTrader(ArbitrageArgument argument, InvestorAccount currentInvestor)
        {
            Guid traderIdentify = CreateNewAutoTraderIdentify();
            int  aliasNum       = CreateNewAutoTraderAliasNum();

            USeArbitrageOrder arbitrageOrder = new USeArbitrageOrder();

            arbitrageOrder.TraderIdentify = traderIdentify;
            arbitrageOrder.AliasNum       = aliasNum;
            arbitrageOrder.State          = ArbitrageOrderState.None;
            arbitrageOrder.BrokerId       = currentInvestor.BrokerId;
            arbitrageOrder.Account        = currentInvestor.Account;
            arbitrageOrder.Argument       = argument.Clone();
            arbitrageOrder.CreateTime     = DateTime.Now;

            TaskOrderSetting taskOrderSetting = m_systemConfigManager.GetTaskOrderSetting();
            //任务组待开仓或者平仓时在创建
            AutoTrader trader = new AutoTrader();

            trader.SetRecordLogger(USeManager.Instance.CommandLogger);
            trader.SetTryOrderCondition(taskOrderSetting.TaskMaxTryCount, taskOrderSetting.TryOrderMinInterval);
            trader.Initialize(arbitrageOrder, m_orderDriver, m_quoteDriver, m_alarmManager);

            trader.OnNotify += AutoTrader_OnNotify;
            trader.OnAlarm  += AutoTrader_OnAlarm;
            trader.OnArbitrageOrderChanged += AutoTrader_OnArbitrageOrderChanged;
            trader.OnStateChanged          += AutoTrader_OnStateChanged;

            lock (m_syncObj)
            {
                m_autoTraderDic.Add(traderIdentify, trader);
            }

            SafeFireAddAutoTrader(traderIdentify);
            string           text   = "创建套利单成功";
            AutoTraderNotice notice = new AutoTraderNotice(trader.TraderIdentify, trader.Alias, AutoTraderNoticeType.Infomation, text);

            SafeFireAutoTraderNotice(notice);
            trader.WriteTraderNoticeLog(notice);

            return(trader);
        }
Пример #2
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);
            }
        }