Exemplo n.º 1
0
        /// <summary>
        /// Gets or creates the order queue.
        /// </summary>
        /// <param name="currencyPair">The currency pair.</param>
        /// <param name="side">The side.</param>
        /// <returns>Order queue for currency pair and side.</returns>
        public OrderQueue GetOrCreateQueue(CurrencyPair currencyPair, Side side)
        {
            var foundQueue =
                _queues.FirstOrDefault(q => Equals(q.Key.CurrencyPair, currencyPair) && q.Key.Side == side);

            if (foundQueue == null)
            {
                var newQueue = new OrderQueue(currencyPair, side);
                _queues.Add(newQueue);
                return(newQueue);
            }

            return(foundQueue);
        }
        private void ProcessOrders(
            Order order1,
            OrderQueue order1Queue,
            Order order2,
            OrderQueue order2Queue)
        {
            var amountToSubtract = Math.Min(order1.RemainingAmount, order2.RemainingAmount);

            order1.RemainingAmount -= amountToSubtract;
            order2.RemainingAmount -= amountToSubtract;

            if (order1.IsClosed)
            {
                order1Queue.Remove(order1);
                RaiseOrderClosed(order1);
            }
            if (order2.IsClosed)
            {
                order2Queue.Remove(order2);
                RaiseOrderClosed(order2);
            }
        }