示例#1
0
        /// <summary>
        /// 克隆。
        /// </summary>
        /// <returns></returns>
        public USeArbitrageOrder Clone()
        {
            USeArbitrageOrder order = new USeArbitrageOrder();

            order.TraderIdentify = this.TraderIdentify;
            order.AliasNum       = this.AliasNum;
            order.BrokerId       = this.BrokerId;
            order.Account        = this.Account;
            order.State          = this.State;
            order.CreateTime     = this.CreateTime;
            order.FinishTime     = this.FinishTime;
            if (m_argument != null)
            {
                order.Argument = m_argument.Clone();
            }
            if (m_openTaskGroup != null)
            {
                order.m_openTaskGroup = m_openTaskGroup.Clone();
            }
            if (m_closeTaskGroup != null)
            {
                order.m_closeTaskGroup = m_closeTaskGroup.Clone();
            }

            return(order);
        }
示例#2
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);
        }
示例#3
0
        /// <summary>
        /// 设定平仓参数。
        /// </summary>
        /// <param name="closeArg">平仓参数。</param>
        public void ModifyArbitrageArgument(ArbitrageArgument argument)
        {
            CheckBackgroundWorker("修改套利单参数");

            lock (m_syncObj)
            {
                if (m_arbitrageOrder.State >= ArbitrageOrderState.Closeing)
                {
                    throw new Exception(string.Format("{0}为{1}状态,不能修改套利单参数", this, this.ArbitrageOrderState.ToDescription()));
                }
                string errorMessage = string.Empty;
                if (VerfiyArbitrageArgument(argument, out errorMessage) == false)
                {
                    string text = string.Format("{0}修改套利单参数失败,{1}", this, errorMessage);
                    throw new ArgumentException(text);
                }

                //[yangming]更新能修改的参数
                m_arbitrageOrder.Argument = argument.Clone();
                //m_arbitrageOrder.CloseArgument = closeArg.Clone();
            }
        }