示例#1
0
        /// <summary>
        /// добавить маркапы и прочее шкурилово
        /// </summary>
        public static void ProcessOrderClosing(MarketOrder order,
            ACCOUNT account,
            ORDER_BILL bill, 
            TradeSharpConnection ctx,
            Dictionary<string, QuoteData> quotes, string brokerCurrency)
        {
            //Logger.Info("BillingManager.ProcessOrderClosing()");
            try
            {
                // перевести маркапы в валюту брокера
                var markupSum = bill.MarkupExit + bill.MarkupEnter;
                // в контрвалюте...
                if (markupSum != 0)
                    markupSum = order.Volume * markupSum;
                Logger.Info("BillingManager: markupSum is " + markupSum);

                // перевести в валюту брокера
                var resultCounter = order.Side * order.Volume * (order.PriceExit.Value - order.PriceEnter);
                var rateCounterDepo = resultCounter == 0 ? 1 : order.ResultDepo / resultCounter;
                // валюта брокера к контрвалюте
                var rateCounterBroker = rateCounterDepo;
                Logger.Info("BillingManager: rateCounterDepo is " + rateCounterDepo);

                if (account.Currency != brokerCurrency)
                {
                    // пример: позиция EURCAD, валюта брокера USD
                    // надо получить курс CADUSD
                    var markupBroker = (float) markupSum;
                    string errorStr;
                    var resultedMarkup = DalSpot.Instance.ConvertToTargetCurrency(order.Symbol, false, brokerCurrency,
                                                                            markupBroker, quotes, out errorStr, true);

                    if (!resultedMarkup.HasValue)
                    {
                        Logger.ErrorFormat("BillingManager.ProcessOrderClosing - невозможно перевести профит по {0} в {1}: {2}",
                            order.Symbol, brokerCurrency, errorStr);
                        return;
                    }
                    markupBroker = (float)resultedMarkup.Value;
                    rateCounterBroker = (float)(markupBroker / markupSum);
                    markupSum = markupBroker;
                }
                else
                    markupSum *= rateCounterBroker;
                bill.MarkupBroker = markupSum;
                bill.ProfitBroker = resultCounter * rateCounterBroker;
                Logger.InfoFormat("BillingManager: MarkupBroker: {0}, ProfitBroker: {1}",
                    bill.MarkupBroker, bill.ProfitBroker);

                // сохранить билль
                ctx.Entry(bill).State = EntityState.Modified;
                Logger.InfoFormat("BillingManager:OK");
            }
            catch (Exception ex)
            {
                Logger.Error("BillingManager.ProcessOrderClosing() - ошибка редактирования счета", ex);
            }
        }
示例#2
0
 public static OrderBill DecorateOrderBill(ORDER_BILL bill)
 {
     return(new OrderBill
     {
         Position = bill.Position,
         MarkupEnter = (float)bill.MarkupEnter,
         MarkupExit = (float)bill.MarkupExit,
         MarkupBroker = (float)bill.MarkupBroker,
         MarkupType = (AccountGroup.MarkupType)bill.MarkupType,
         ProfitBroker = (float)bill.ProfitBroker
     });
 }
示例#3
0
 public static OrderBill DecorateOrderBill(ORDER_BILL bill)
 {
     return new OrderBill
         {
             Position = bill.Position,
             MarkupEnter = (float)bill.MarkupEnter,
             MarkupExit = (float)bill.MarkupExit,
             MarkupBroker = (float)bill.MarkupBroker,
             MarkupType = (AccountGroup.MarkupType)bill.MarkupType,
             ProfitBroker = (float)bill.ProfitBroker
         };
 }