private void RemoveGoodTillDateOrder(int time, OrderId orderId)
        {
            if (_goodTillDateOrders.TryGetValue(time, out var orderIds))
            {
                orderIds.Remove(orderId);
                if (orderIds.Count == 0)
                {
                    _goodTillDateOrders.Remove(time);

                    if (time == _firstGoodTillDate.Value.Key)
                    {
                        _firstGoodTillDate = _goodTillDateOrders.Count > 0 ? _goodTillDateOrders.First() : (KeyValuePair <int, HashSet <OrderId> >?)null;
                    }
                }
            }
        }
Beispiel #2
0
        public static byte[] Serialize(OrderId makerOrderId, OrderId takerOrderId, Price matchRate, Quantity matchQuantity, Quantity?remainingAskQuantiy, Quantity?askFee, Quantity?bidCost, Quantity?bidFee, int timeStamp)
        {
            byte[] msg = new byte[sizeOfMessage];
            Write(msg, messageLengthOffset, sizeOfMessage);
            msg[messageTypeOffset] = (byte)MessageType.Fill;
            Write(msg, versionOffset, version);
            Write(msg, makerOrderIdOffset, makerOrderId);
            Write(msg, takerOrderIdOffset, takerOrderId);
            Write(msg, matchRateOffset, matchRate);
            Write(msg, matchQuantityOffset, matchQuantity);
            msg[isAskRemainingNullOffset] = Convert.ToByte(remainingAskQuantiy.HasValue ? true : false);

            if (remainingAskQuantiy.HasValue)
            {
                Write(msg, askRemainingQuantityOffset, remainingAskQuantiy.Value);
            }

            msg[isAskFeeNullOffset] = Convert.ToByte(askFee.HasValue ? true : false);

            if (askFee.HasValue)
            {
                Write(msg, askFeeOffset, askFee.Value);
            }

            msg[isBidCostNullOffset] = Convert.ToByte(bidCost.HasValue ? true : false);

            if (bidCost.HasValue)
            {
                Write(msg, bidCostOffset, bidCost.Value);
            }

            msg[isBidFeeNullOffset] = Convert.ToByte(bidFee.HasValue ? true : false);

            if (bidFee.HasValue)
            {
                Write(msg, bidFeeOffset, bidFee.Value);
            }

            Write(msg, timestampOffset, timeStamp);
            return(msg);
        }
        private OrderMatchingResult CancelOrder(OrderId orderId, CancelReason cancelReason)
        {
            if (_currentOrders.TryGetValue(orderId, out Order? order))
            {
                var quantityCancel = order.OpenQuantity;
                _book.RemoveOrder(order);
                _currentOrders.Remove(orderId);
                if (order.IsTip)
                {
                    quantityCancel += order.TotalQuantity;
                }

                if (order.CancelOn > 0)
                {
                    RemoveGoodTillDateOrder(order.CancelOn, order.OrderId);
                }

                _tradeListener?.OnCancel(orderId, quantityCancel, order.Cost, order.Fee, cancelReason);
                return(OrderMatchingResult.CancelAcepted);
            }
            return(OrderMatchingResult.OrderDoesNotExists);
        }
 public OrderMatchingResult CancelOrder(OrderId orderId)
 {
     return(CancelOrder(orderId, CancelReason.UserRequested));
 }