Beispiel #1
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);
        }
Beispiel #2
0
        /// <summary>
        /// 转移为历史记录(不在更改)。
        /// </summary>
        public void TransferToHistoryArbitrage()
        {
            lock (m_syncObj)
            {
                if (m_arbitrageOrder.State != ArbitrageOrderState.Closed)
                {
                    throw new Exception(string.Format("{0}为{1}状态,未结束不能转移", this, this.ArbitrageOrderState.ToDescription()));
                }
            }

            ArbitrageOrderSettlement settlemetResult = CalculateSettlementResult();

            lock (m_syncObj)
            {
                m_arbitrageOrder.State            = ArbitrageOrderState.Finish;
                m_arbitrageOrder.FinishTime       = DateTime.Now;
                m_arbitrageOrder.SettlementResult = settlemetResult;
            }

            SafeFireArbitrageOrderChanged();

            string           text   = "交易结束,转移到历史记录";
            AutoTraderNotice notice = CreateTraderNotice(text);

            SafeFireAutoTraderNotice(notice);
            WriteTraderNoticeLog(notice);
        }