public long cancel ( long orderId , long quantity ) { Order order = orders . get ( orderId ) ; if ( order == null ) { return 0 ; } OrderBook book = order . getOrderBook ( ) ; long remainingQuantity = order . getRemainingQuantity ( ) ; long canceledQuantity = Math . min ( quantity , remainingQuantity ) ; boolean bbo = book . update ( order . getSide ( ) , order . getPrice ( ) , - canceledQuantity ) ; if ( canceledQuantity == remainingQuantity ) { orders . remove ( orderId ) ; } else { order . reduce ( canceledQuantity ) ; } listener . update ( book , bbo ) ; return remainingQuantity - canceledQuantity ; }
Cancel a quantity of an order in an order book . If the remaining quantity reaches zero the order is deleted from the order book .