public void RemoveOrder(EffectProcessorsContainer effectsContainer, OrderbookBase orderbook, Order order)
 {
     effectsContainer.AddOrderRemoved(orderbook, order);
     if (awaitedUpdates != null)
     {
         var updateTime   = new DateTime(((Quantum)effectsContainer.Envelope.Message).Timestamp, DateTimeKind.Utc);
         var exchangeItem = new ExchangeUpdate(orderbook.Market, updateTime);
         exchangeItem.OrderUpdates.Add(order.ToOrderInfo(OrderState.Deleted));
         awaitedUpdates.Add(exchangeItem);
     }
 }
        //TODO: find more elegant and reliable way to validate cross orders count. This method is  could have rounding errors.
        /// <summary>
        /// Prevents too many trade effects.
        /// </summary>
        private void ValidateCounterOrdersCount(OrderRequest orderRequest, OrderbookBase orderbook)
        {
            var counterOrdersSum   = 0L;
            var counterOrdersCount = 0;

            foreach (var order in orderbook)
            {
                counterOrdersSum += order.Amount;
                counterOrdersCount++;
                if (counterOrdersSum >= orderRequest.Amount)
                {
                    break;
                }
                if (counterOrdersCount > MaxCrossOrdersCount)
                {
                    throw new BadRequestException("Failed to execute order. Maximum crossed orders length exceeded");
                }
            }
        }
Exemple #3
0
 public OrderPlacedEffectProcessor(OrderPlacedEffect effect, OrderbookBase orderBook, Order order)
     : base(effect)
 {
     this.orderBook = orderBook ?? throw new ArgumentNullException(nameof(orderBook));
     this.order     = order ?? throw new ArgumentNullException(nameof(order));
 }
Exemple #4
0
 public OrderRemovedEffectProccessor(OrderRemovedEffect effect, OrderbookBase orderbook)
     : base(effect)
 {
     this.orderbook = orderbook ?? throw new ArgumentNullException(nameof(orderbook));
 }
        public static void AddOrderPlaced(this EffectProcessorsContainer effectProcessors, OrderbookBase orderBook, Order order)
        {
            var decodedOrderId = OrderIdConverter.Decode(order.OrderId);
            var effect         = new OrderPlacedEffect
            {
                Apex           = effectProcessors.Apex,
                Account        = order.AccountWrapper.Id,
                AccountWrapper = order.AccountWrapper,
                Asset          = decodedOrderId.Asset,
                Amount         = order.Amount,
                QuoteAmount    = order.QuoteAmount,
                Price          = order.Price,
                OrderId        = order.OrderId,
                OrderSide      = decodedOrderId.Side
            };

            effectProcessors.Add(new OrderPlacedEffectProcessor(effect, orderBook, order));
        }
 public static void AddOrderRemoved(this EffectProcessorsContainer effectProcessors, OrderbookBase orderbook, Order order)
 {
     effectProcessors.Add(new OrderRemovedEffectProccessor(
                              new OrderRemovedEffect
     {
         Apex           = effectProcessors.Apex,
         OrderId        = order.OrderId,
         Account        = order.AccountWrapper.Id,
         AccountWrapper = order.AccountWrapper,
         Amount         = order.Amount,
         QuoteAmount    = order.QuoteAmount,
         Price          = order.Price
     },
                              orderbook
                              ));
 }