Exemplo n.º 1
0
        /// <summary>
        /// 计算平仓损益。
        /// </summary>
        /// <param name="arbitrageOrder"></param>
        /// <returns></returns>
        private ProfitResult CalculatCloseProfit(USeArbitrageOrder arbitrageOrder)
        {
            USeOrderDriver orderDriver = USeManager.Instance.OrderDriver;
            USeQuoteDriver quoteDriver = USeManager.Instance.QuoteDriver;

            Debug.Assert(orderDriver != null);
            Debug.Assert(quoteDriver != null);

            ArbitrageTaskGroup  closeTaskGroup = arbitrageOrder.CloseTaskGroup;
            List <USeOrderBook> orderBookList  = arbitrageOrder.GetAllOrderBooks();


            USeMarketData       buyMarketData        = USeManager.Instance.QuoteDriver.Query(closeTaskGroup.BuyInstrument);
            USeMarketData       sellMarketData       = USeManager.Instance.QuoteDriver.Query(closeTaskGroup.SellInstrument);
            USeInstrumentDetail buyInstrumentDetail  = USeManager.Instance.OrderDriver.QueryInstrumentDetail(closeTaskGroup.BuyInstrument);
            USeInstrumentDetail sellInstrumentDetail = USeManager.Instance.OrderDriver.QueryInstrumentDetail(closeTaskGroup.SellInstrument);

            decimal buyProfit   = CalculateProfitByOrderBook(orderBookList, buyInstrumentDetail, buyMarketData);
            decimal sellProfit  = CalculateProfitByOrderBook(orderBookList, sellInstrumentDetail, sellMarketData);
            decimal totalProfit = buyProfit + sellProfit;

            ProfitResult result = new ProfitResult()
            {
                BuyProfit  = buyProfit,
                SellProfit = sellProfit
            };

            return(result);
        }
Exemplo n.º 2
0
        private ArbitrageOrderSettlement CalculateSettlementResult()
        {
            USeArbitrageOrder arbitrageOrder = null;

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

            List <USeOrderBook> orderBookList = arbitrageOrder.GetAllOrderBooks();

            USeInstrument buyInstrument  = arbitrageOrder.OpenArgument.BuyInstrument;
            USeInstrument sellInstrument = arbitrageOrder.OpenArgument.SellInstrument;

            USeMarketData       buyMarketData        = USeManager.Instance.QuoteDriver.Query(buyInstrument);
            USeMarketData       sellMarketData       = USeManager.Instance.QuoteDriver.Query(sellInstrument);
            USeInstrumentDetail buyInstrumentDetail  = USeManager.Instance.OrderDriver.QueryInstrumentDetail(buyInstrument);
            USeInstrumentDetail sellInstrumentDetail = USeManager.Instance.OrderDriver.QueryInstrumentDetail(sellInstrument);

            decimal buyProfit   = CalculateProfit(orderBookList, buyInstrumentDetail, buyMarketData);
            decimal sellProfit  = CalculateProfit(orderBookList, sellInstrumentDetail, sellMarketData);
            decimal totalProfit = buyProfit + sellProfit;

            ArbitrageOrderSettlement settlemt = new ArbitrageOrderSettlement()
            {
                BuyInstrumentProfit  = buyProfit,
                SellInstrumentProfit = sellProfit,
                Profit = totalProfit
            };

            return(settlemt);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 展示开仓信息。
        /// </summary>
        /// <param name="arbitrageOrder"></param>
        private void ShowOpenInfo(USeArbitrageOrder arbitrageOrder)
        {
            Debug.Assert(arbitrageOrder.OpenArgument != null);
            Debug.Assert(arbitrageOrder.OpenTaskGroup != null);

            this.panelTop.BackColor         = Color.FromArgb(255, 255, 192);
            this.panelPriceSpread.BackColor = Color.FromArgb(255, 255, 192);

            ArbitrageTaskGroup taskGroup = arbitrageOrder.OpenTaskGroup;

            this.lblAlias.Text = arbitrageOrder.Alias;
            if (taskGroup.BuyInstrument != null)
            {
                this.lblBuyInstrument.Text = taskGroup.BuyInstrument.InstrumentCode;
            }
            else
            {
                this.lblBuyInstrument.Text = "---";
            }
            if (taskGroup.SellInstrument != null)
            {
                this.lblSellInstrument.Text = taskGroup.SellInstrument.InstrumentCode;
            }
            else
            {
                this.lblSellInstrument.Text = "---";
            }

            this.lblBuyTradeInfo.Text              = string.Format("{0}/{1}", taskGroup.BuySubTaskTradeQty, taskGroup.BuySubTaskPlanOrderQty);
            this.lblBuyInstrmentOpenAvgPrice.Text  = taskGroup.BuySubTaskAvgTradePrice.ToString();
            this.lblSellTradeInfo.Text             = string.Format("{0}/{1}", taskGroup.SellSubTaskTradeQty, taskGroup.SellSubTaskPlanOrderQty);
            this.lblSellInstrmentOpenAvgPrice.Text = taskGroup.SellSubTaskAvgTradePrice.ToString();
        }
        /// <summary>
        /// 未完成套利单文件存储路径。
        /// </summary>
        /// <param name="arbitrageOrder">套利单。</param>
        /// <returns></returns>
        private string GetUnFinishArbitrageOrderFileFullName(USeArbitrageOrder arbitrageOrder)
        {
            Debug.Assert(string.IsNullOrEmpty(arbitrageOrder.BrokerId) == false);
            Debug.Assert(string.IsNullOrEmpty(arbitrageOrder.Account) == false);

            string directoryPath = GetUnFinishOrderPath(arbitrageOrder.BrokerId, arbitrageOrder.Account);
            string fileName      = string.Format("ArbitrageOrder_{0}.xml", arbitrageOrder.CreateTime.ToString(ORDER_TIME_FORMAT));

            return(Path.Combine(directoryPath, fileName));
        }
Exemplo n.º 6
0
 private void ModifyArbitrageOpenArgumentForm_Load(object sender, EventArgs e)
 {
     if (m_autoTrader != null)
     {
         m_arbitrageOrder = m_autoTrader.GetArbitrageOrder();
     }
     if (m_arbitrageOrder != null)
     {
         this.Text = string.Format("套利单[{0}]开仓参数", m_arbitrageOrder.Alias);
         this.arbitrageOrderOpenArgumentViewControl1.SetOpenArgument(m_arbitrageOrder.OpenArgument);
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// 获取历史完成套利单。
        /// </summary>
        /// <returns></returns>
        /// <param name="brokerId">经纪商ID。</param>
        /// <param name="account">资金帐号。</param>
        /// <param name="beginTime">起始时间。</param>
        /// <param name="endTime">截至时间。</param>
        public List <USeArbitrageOrder> GetHistoryArbitrageOrders(string brokerId, string account, DateTime?beginTime, DateTime?endTime)
        {
            List <USeArbitrageOrder> list = new List <USeArbitrageOrder>();

            string        finishOrderPath = GetFinishOrderPath(brokerId, account);
            DirectoryInfo finishOrderDir  = new DirectoryInfo(finishOrderPath);

            if (finishOrderDir.Exists == false)
            {
                return(list);  // 目录不存在
            }

            FileInfo[] fileArray = finishOrderDir.GetFiles("ArbitrageOrder_*.xml");
            if (fileArray == null || fileArray.Length <= 0)
            {
                return(list);  // 目录无文件
            }

            foreach (FileInfo fileInfo in finishOrderDir.GetFiles())
            {
                try
                {
                    ArbitrageOrderKey orderKey = ArbitrageOrderKey.Create(fileInfo.FullName);
                    if (beginTime.HasValue)
                    {
                        Debug.Assert(orderKey.FinishTime.HasValue);
                        //过滤结束时间小于开始时间的
                        if (orderKey.FinishTime.Value < beginTime)
                        {
                            continue;
                        }
                    }
                    if (endTime.HasValue)
                    {
                        // 过滤创建时间大于截止时间的
                        if (orderKey.CreateTime > endTime)
                        {
                            continue;
                        }
                    }

                    XmlAttributeOverrides xmlOverrides   = CreateArbitrageOrderXMLOverrides();
                    USeArbitrageOrder     arbitrageOrder = USeXmlSerializer.LoadFromXml <USeArbitrageOrder>(fileInfo.FullName, xmlOverrides);
                    list.Add(arbitrageOrder);
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("GetHistoryArbitrageOrders failed,FilePath:{0},Error:{1}", fileInfo.FullName, ex.Message));
                }
            }

            return(list);
        }
Exemplo n.º 8
0
 private void M_autoTraderManager_OnArbitrageOrderChanged(Guid tradeIdentify)
 {
     try
     {
         AutoTrader        trader         = m_autoTraderManager.GetAutoTrader(tradeIdentify);
         USeArbitrageOrder arbitrageOrder = trader.GetArbitrageOrder();
         m_dataSaver.AddSaveTask(arbitrageOrder);
     }
     catch (Exception ex)
     {
         Debug.Assert(false, ex.Message);
     }
 }
Exemplo n.º 9
0
        private void HistoryArbitrageView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0 || e.ColumnIndex < 0)
            {
                return;
            }

            ArbitrageOrderBookViewModel arbitrageOrderModel = this.gridArbitrage.Rows[e.RowIndex].DataBoundItem as ArbitrageOrderBookViewModel;
            USeArbitrageOrder           order = arbitrageOrderModel.ArbitrageOrder;

            ArbitrageOrderViewForm arbitrageOrderViewForm = new ArbitrageOrderViewForm(order);

            arbitrageOrderViewForm.ShowDialog();
        }
Exemplo n.º 10
0
        /// <summary>
        /// 保存套利单。
        /// </summary>
        /// <param name="order"></param>
        public void SaveUSeArbitrageOrder(USeArbitrageOrder order)
        {
            //判断order.State决定保存到未完成还是已完成
            if (order.State == ArbitrageOrderState.Finish)
            {
                // 保存到已完成
                try
                {
                    XmlAttributeOverrides xmlAttributeOrderNum = CreateArbitrageOrderXMLOverrides();
                    string fileFullName = GetFinishArbitrageOrderFilePath(order);
                    USeXmlSerializer.SaveToXml(fileFullName, order, xmlAttributeOrderNum);
                }
                catch (Exception ex)
                {
                    throw new Exception("SaveFinishUSeArbitrageOrder failed,Error:" + ex.Message);
                }

                //删除相对应的未完成的目录的对应的文件
                try
                {
                    string fileFullName = GetUnFinishArbitrageOrderFileFullName(order);
                    if (File.Exists(fileFullName) == false)
                    {
                        Debug.Assert(false);
                    }
                    else
                    {
                        File.Delete(fileFullName);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Delete UnFinishUseArbitrageOrder failed, Error:" + ex.Message);
                }
            }
            else
            {
                //  保存到未完成
                try
                {
                    XmlAttributeOverrides xmlOverrides = CreateArbitrageOrderXMLOverrides();
                    string fileFullName = GetUnFinishArbitrageOrderFileFullName(order);
                    USeXmlSerializer.SaveToXml(fileFullName, order, xmlOverrides);
                }
                catch (Exception ex)
                {
                    throw new Exception("SaveUnFinishUSeArbitrageOrder failed,Error:" + ex.Message);
                }
            }
        }
Exemplo n.º 11
0
 private void BeginSaveAribtrageOrder()
 {
     while (m_saveQueue.Count > 0)
     {
         USeArbitrageOrder arbitrageOrder = m_saveQueue.Dequeue();
         Debug.Assert(arbitrageOrder != null);
         try
         {
             m_dataAccessor.SaveUSeArbitrageOrder(arbitrageOrder);
         }
         catch (Exception ex)
         {
             m_eventLogger.WriteError("保存套利单信息失败," + ex.Message);
         }
     }
 }
Exemplo n.º 12
0
        /// <summary>
        /// 设置图形区域数据源。
        /// </summary>
        /// <param name="arbitrageOrder"></param>
        private void SetChartViewData(USeArbitrageOrder arbitrageOrder)
        {
            switch (arbitrageOrder.State)
            {
            case ArbitrageOrderState.None:
            case ArbitrageOrderState.Opening:
            case ArbitrageOrderState.Opened:
                m_chartView.SetData(arbitrageOrder.OpenTaskGroup);
                break;

            case ArbitrageOrderState.Closeing:
            case ArbitrageOrderState.Closed:
            case ArbitrageOrderState.Finish:
                m_chartView.SetData(arbitrageOrder.CloseTaskGroup);
                break;
            }
        }
Exemplo n.º 13
0
        private void M_autoTrader_OnArbitrageOrderChanged(Guid orderIdentify)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new ArbitrageOrderChangedEventHandle(M_autoTrader_OnArbitrageOrderChanged), orderIdentify);
                return;
            }

            Debug.Assert(orderIdentify == m_autoTrader.TraderIdentify);
            m_arbitrageOrder = m_autoTrader.GetArbitrageOrder();
            ResetContextMenu();
            SetChartViewData(m_arbitrageOrder);

            ShowArbitrageOrderView();
            ShowChartView();
            ShowTaskGrid();
            ShowRunButton();
        }
        public static ArbitrageOrderBookViewModel Creat(USeArbitrageOrder arbitrageOrder)
        {
            ArbitrageOrderBookViewModel viewModel = new ArbitrageOrderBookViewModel();

            viewModel.CreateTime         = arbitrageOrder.CreateTime;
            viewModel.FinishTime         = arbitrageOrder.FinishTime;
            viewModel.Alias              = arbitrageOrder.Alias;
            viewModel.OpenBuyInstrument  = arbitrageOrder.OpenArgument.BuyInstrument;
            viewModel.OpenSellInstrument = arbitrageOrder.OpenArgument.SellInstrument;
            if (arbitrageOrder.SettlementResult != null)
            {
                viewModel.BuyProfit   = arbitrageOrder.SettlementResult.BuyInstrumentProfit;
                viewModel.SellProfit  = arbitrageOrder.SettlementResult.SellInstrumentProfit;
                viewModel.TotalProfit = arbitrageOrder.SettlementResult.Profit;
            }
            viewModel.ArbitrageOrder = arbitrageOrder;
            return(viewModel);
        }
Exemplo n.º 15
0
        /// <summary>
        /// 展示平仓信息。
        /// </summary>
        /// <param name="arbitrageOrder"></param>
        private void ShowCloseInfo(USeArbitrageOrder arbitrageOrder)
        {
            Debug.Assert(arbitrageOrder.CloseArgument != null);
            Debug.Assert(arbitrageOrder.CloseTaskGroup != null);
            this.panelTop.BackColor         = System.Drawing.Color.AliceBlue;
            this.panelPriceSpread.BackColor = System.Drawing.Color.AliceBlue;

            ArbitrageTaskGroup closeTaskGroup = arbitrageOrder.CloseTaskGroup;

            this.lblAlias.Text          = arbitrageOrder.Alias;
            this.lblBuyInstrument.Text  = closeTaskGroup.BuyInstrument.InstrumentCode;
            this.lblSellInstrument.Text = closeTaskGroup.SellInstrument.InstrumentCode;

            this.lblBuyTradeInfo.Text              = string.Format("{0}/{1}", closeTaskGroup.BuySubTaskTradeQty, closeTaskGroup.BuySubTaskPlanOrderQty);
            this.lblBuyInstrmentOpenAvgPrice.Text  = closeTaskGroup.BuySubTaskAvgTradePrice.ToString();
            this.lblSellTradeInfo.Text             = string.Format("{0}/{1}", closeTaskGroup.SellSubTaskTradeQty, closeTaskGroup.SellSubTaskPlanOrderQty);
            this.lblSellInstrmentOpenAvgPrice.Text = closeTaskGroup.SellSubTaskAvgTradePrice.ToString();
        }
Exemplo n.º 16
0
 private void btnRefresh_Click(object sender, EventArgs e)
 {
     if (m_arbitrageOrder == null)
     {
         return;
     }
     try
     {
         AutoTrader        trader         = USeManager.Instance.AutoTraderManager.GetAutoTrader(m_arbitrageOrder.TraderIdentify);
         USeArbitrageOrder arbitrageOrder = trader.GetArbitrageOrder();
         Debug.Assert(arbitrageOrder != null);
         m_arbitrageOrder = arbitrageOrder;
         BindData();
     }
     catch (Exception ex)
     {
         Debug.Assert(false, ex.Message);
     }
 }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
        /// <summary>
        /// 初始化。
        /// </summary>
        public override void Initialize()
        {
            Debug.Assert(m_autoTrader != null);
            m_autoTrader.OnStateChanged          += M_autoTrader_OnStateChanged;
            m_autoTrader.OnArbitrageOrderChanged += M_autoTrader_OnArbitrageOrderChanged;
            m_autoTrader.OnAlarm += M_autoTrader_OnAlarm;
            m_arbitrageOrder      = m_autoTrader.GetArbitrageOrder();

            ResetContextMenu();
            SetChartViewData(m_arbitrageOrder);

            ShowArbitrageOrderView();
            ShowAlarmIcon();
            ShowChartView();
            ShowTaskGrid();
            ShowRunButton();

            m_porfitCalcTimer.Change(500, Timeout.Infinite);
        }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
0
        /// <summary>
        /// 获取所有未完成套利单。
        /// </summary>
        /// <param name="brokerId">经纪商ID。</param>
        /// <param name="account">资金帐号。</param>
        /// <returns></returns>
        public List <USeArbitrageOrder> GetUnfinishArbitrageOrders(string brokerId, string account)
        {
            List <USeArbitrageOrder> list = new List <USeArbitrageOrder>();

            string        unFinishOrderPath = GetUnFinishOrderPath(brokerId, account);
            DirectoryInfo unFinishOrderDir  = new DirectoryInfo(unFinishOrderPath);

            if (unFinishOrderDir.Exists == false)
            {
                return(list);
            }

            FileInfo[] fileArray = unFinishOrderDir.GetFiles("ArbitrageOrder_*.xml");
            if (fileArray == null || fileArray.Length <= 0)
            {
                return(list);
            }

            XmlAttributeOverrides xmlOverrides = CreateArbitrageOrderXMLOverrides();

            foreach (FileInfo fileInfo in fileArray)
            {
                try
                {
                    USeArbitrageOrder unFinishOrder = USeXmlSerializer.LoadFromXml <USeArbitrageOrder>(fileInfo.FullName, xmlOverrides);
                    if (unFinishOrder != null)
                    {
                        list.Add(unFinishOrder);
                    }
                    else
                    {
                        Debug.Assert(false);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("GetUnfinishArbitrageOrders failed,FileName:{0},Error:{1}", fileInfo.FullName, ex.Message));
                }
            }

            return(list);
        }
Exemplo n.º 21
0
        public static void TestOrder()
        {
            USeArbitrageOrder order = new USeArbitrageOrder();


            //ArbiOrder基础参数
            order.BrokerId       = "9000";
            order.TraderIdentify = Guid.NewGuid();
            order.Account        = "090952";
            order.State          = ArbitrageOrderState.Closed;
            order.CreateTime     = DateTime.Now;
            order.FinishTime     = DateTime.Now;

            //order.OpenArgument = CreateOpenArg();
            //order.CloseArgument = CreateCloseArg();


            order.CloseTaskGroup = CreateTaskGroup();
            USeDataAccessor dataAccessor = new USeDataAccessor();

            dataAccessor.SaveUSeArbitrageOrder(order);
        }
Exemplo n.º 22
0
 public ArbitrageOrderViewForm(USeArbitrageOrder arbitrageOrder)
 {
     m_arbitrageOrder = arbitrageOrder;
     InitializeComponent();
 }
Exemplo n.º 23
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;
        }
Exemplo n.º 24
0
 public void AddSaveTask(USeArbitrageOrder arbitrageOrder)
 {
     m_saveQueue.Enqueue(arbitrageOrder);
     m_resetEvent.Set();
 }