/// <summary> /// 移除自动下单机。 /// </summary> /// <param name="traderIdentify">自动下单机标识。</param> public void RemoveAutoTrader(Guid traderIdentify) { AutoTrader trader = null; lock (m_syncObj) { if (m_autoTraderDic.TryGetValue(traderIdentify, out trader) == false) { Debug.Assert(false); return; } } if (trader.State == AutoTraderState.Enable) { throw new Exception(string.Format("套利单[{0}]为运行状态,请先停止在移除", trader.Alias)); } if (trader.IsFinish == false) { throw new Exception(string.Format("套利单[{0}]当前状态为 {1} ,不能移除", trader, trader.ArbitrageOrderState.ToDescription())); } if (trader.HasUnFinishOrderBook) { throw new Exception(string.Format("套利单[{0}]有未完成委托单 ,不能移除", trader)); } trader.OnNotify -= AutoTrader_OnNotify; trader.OnAlarm -= AutoTrader_OnAlarm; trader.OnArbitrageOrderChanged -= AutoTrader_OnArbitrageOrderChanged; lock (m_syncObj) { m_autoTraderDic.Remove(traderIdentify); } string text = "移除套利单成功"; AutoTraderNotice notice = new AutoTraderNotice(trader.TraderIdentify, trader.Alias, AutoTraderNoticeType.Infomation, text); SafeFireAutoTraderNotice(notice); trader.WriteTraderNoticeLog(notice); SafeFireRemoveAutoTrader(traderIdentify); }
/// <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); }