Exemplo n.º 1
0
        /// <summary>
        /// 呈现损益信息。
        /// </summary>
        /// <param name="profitResult"></param>
        private void ShowProfit(ProfitResult profitResult)
        {
            if (profitResult == null)
            {
                return;
            }

            this.lblBuyInstrumentProfit.Text       = profitResult.BuyProfit.ToString("#,0");
            this.lblBuyInstrumentProfit.ForeColor  = profitResult.BuyProfit >= 0 ? Color.Red : Color.Green;
            this.lblSellInstrumentProfit.Text      = profitResult.SellProfit.ToString("#,0");
            this.lblSellInstrumentProfit.ForeColor = profitResult.SellProfit >= 0 ? Color.Red : Color.Green;
            this.lblTotalProfit.Text      = profitResult.TotalProfit.ToString("#,0");
            this.lblTotalProfit.ForeColor = profitResult.TotalProfit >= 0 ? Color.Red : Color.Green;


            if (profitResult.CurrentPriceSpread.HasValue)
            {
                this.lblCurrPriceSpread.Text      = profitResult.CurrentPriceSpread.Value.ToString();
                this.lblCurrPriceSpread.ForeColor = profitResult.CurrentPriceSpread.Value >= 0 ? Color.Red : Color.Green;
            }
            else
            {
                this.lblCurrPriceSpread.Text      = "----";
                this.lblCurrPriceSpread.ForeColor = Color.Black;
            }
        }
Exemplo n.º 2
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.º 3
0
        /// <summary>
        /// 定时计算损益。
        /// </summary>
        /// <param name="state"></param>
        private void CalculateProfitCallback(object state)
        {
            try
            {
                ArbitrageOrderState orderState = m_arbitrageOrder.State;

                ProfitResult result = null;
                if (orderState <= ArbitrageOrderState.Opened)
                {
                    result = CalculatOpenProfit(m_arbitrageOrder);
                }
                else
                {
                    result = CalculatCloseProfit(m_arbitrageOrder);
                }

                if (this.InvokeRequired)
                {
                    this.BeginInvoke(new Action <ProfitResult>(ShowProfit), result);
                    return;
                }
            }
            catch (Exception ex)
            {
                Debug.Assert(false, ex.Message);
            }

            m_porfitCalcTimer.Change(500, Timeout.Infinite);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 计算每个航段的价格及返点
        /// </summary>
        public static void CalPnrsPrices(RtResult rtres, LoginInfo li,
                                         ref int [] sFare,
                                         ref int [] sBuild,
                                         ref int [] sFuel,
                                         ref double[] sGain,
                                         ref int [] sFareY,
                                         ref int totalEtdz)
        {
            int total = 0;

            CalPnrsTotalPrice(rtres, li.b2b.webservice, ref totalEtdz, ref sFare, ref sBuild, ref sFuel, ref sFareY);
            EagleWebService.kernalFunc kf = new EagleWebService.kernalFunc(li.b2b.webservice);
            EagleString.ProfitResult   profitResult;
            for (int i = 0; i < rtres.SEGMENG.Length; ++i)
            {
                profitResult = new ProfitResult(
                    kf.GetPolicies(
                        li.b2b.username,
                        rtres.FLIGHTS[i],
                        rtres.FLIGHTDATES[i].ToShortDateString(),
                        rtres.CITYPAIRS[i]
                        ));
                string profit = profitResult.ProfitWithFlightAndBunk(rtres.FLIGHTS[i], rtres.BUNKS[i]);
                try
                {
                    sGain[i] = double.Parse(profit.Replace("%", ""));
                }
                catch
                {
                    sGain[i] = 0;
                }
            }
        }
Exemplo n.º 5
0
        private void OnAccumulationCompleted(GeneratorInfo targetGenerator, ProfitResult profit)
        {
            if (targetGenerator.GeneratorId == generator.GeneratorId)
            {
                AddCompanyCash(targetGenerator.AccumulatedCash);
                CreateAccumulatedText(targetGenerator.AccumulatedCash, targetGenerator.IsManual);

                OnAccumulationProgressUpdated((float)BosUtils.Clamp01(targetGenerator.GenerateTimer / targetGenerator.AccumulateInterval));
                UpdateTimerText(generator.RemainTime);
            }
        }
Exemplo n.º 6
0
 private void UpdateIncomeText(int brokenedCount)
 {
     if (manager != null)
     {
         ProfitResult profitResult = Generator.ConstructProfitResult(Services.GenerationService.Generators); //Services.GenerationService.CalculateProfitPerSecond(Generator,
         //Services.TransportService.GetUnitLiveCount(manager.Id));
         CurrencyNumber number = profitResult.ValuePerSecond.ToCurrencyNumber();
         if (brokenedCount == 0)
         {
             incomeText.text = string.Format(Services.ResourceService.Localization.GetString("fmt_your_profit_normal"),
                                             FormatProfit(number).Colored("#F9F7BC"));
         }
         else
         {
             incomeText.text = string.Format(Services.ResourceService.Localization.GetString("fmt_income_drop"),
                                             FormatProfit(number).Colored("#F9F7BC"));
         }
     }
 }
Exemplo n.º 7
0
        public void Setup(ManagerInfo manager)
        {
            this.manager = manager;


            GeneratorInfo generator = Services.GenerationService.GetGetenerator(manager.Id);

            updateTimer.Setup(1.0f, (delta) => {
                ProfitResult profitResult = generator.ConstructProfitResult(Services.GenerationService.Generators); //Services.GenerationService.CalculateProfitPerSecond(generator,Services.TransportService.GetUnitLiveCount(manager.Id));
                CurrencyNumber number     = profitResult.ValuePerSecond.ToCurrencyNumber();
                profitText.text           = FormatProfit(profitResult.ValuePerSecond.ToCurrencyNumber());
                UpdateEfficiencyText();
            }, invokeImmediatly: true);

            UpdateManagerIcon();
            UpdateMegaTextObject();
            UpdateRollbackChanged();

            if (!isInitialized)
            {
                isInitialized = true;
            }
        }
Exemplo n.º 8
0
 private void OnAccumualtionProgressChanged(GeneratorInfo targetGenerator, double timer, double interval, ProfitResult profit)
 {
     if (targetGenerator.GeneratorId == generator.GeneratorId)
     {
         OnAccumulationProgressUpdated((float)BosUtils.Clamp01(timer / interval));
         UpdateTimerText(targetGenerator.RemainTime);
     }
 }
Exemplo n.º 9
0
 public void UpdateFromOther(ProfitResult other)
 {
     this.ValuePerRound      = other.ValuePerRound;
     this.ValuePerSecond     = other.ValuePerSecond;
     this.GenerationInterval = other.GenerationInterval;
 }