A cryptocurrency trading platform receives a continuous stream of order events published to a message queue. Each event describes an update to a buy or sell order, either a brand-new order being placed, or a portion of an existing order being executed. Your task is to build the system that consumes these messages and reports the current status of any given order.
Each message is a comma-separated string with the format "<orderId>, <operation>, <symbol>, <quantity>, <eventType>". The eventType field is either "NEW" (a new order has been placed for the given quantity) or "FILLED" (some units of an existing order have been executed).
An order transitions through the following statuses:
"NEW": The order has been placed, but no portion has been filled yet."IN_PROGRESS": At least one fill has been received, but the cumulative filled quantity is still less than the original order quantity."COMPLETED": The cumulative filled quantity equals the original quantity recorded at the time of the"NEW"event.
Implement the OrderManagementSystem class:
-
OrderManagementSystem()Initializes the system with empty in-memory storage. -
void consumeMessages(List<String> messages)Processes a batch of order event messages in sequence. Each message updates the internal state of the corresponding order. -
String getOrderStatus(String orderId)Returns the current status string for the order identified byorderId. The returned value is one of"NEW","IN_PROGRESS", or"COMPLETED".
Constraints:
- 1 ≤
messages.length≤ 105 orderIdis a non-empty string- 1 ≤
quantity≤ 106 - For any
orderId, a"NEW"event is guaranteed to arrive before any"FILLED"events for that order. - The cumulative filled quantity for any order will never exceed the original quantity from the
"NEW"event. getOrderStatusis only called withorderIdvalues that exist in the system (i.e., have been seen in at least one"NEW"event).
Example
Input: ["OrderManagementSystem", "consumeMessages", "getOrderStatus", "getOrderStatus", "getOrderStatus", "getOrderStatus"] [[], [["1234, BUY, BTC, 10, NEW", "1234, BUY, BTC, 5, FILLED", "1234, BUY, BTC, 3, FILLED", "1234, BUY, BTC, 2, FILLED", "5678, SELL, BTC, 20, NEW", "5678, SELL, BTC, 10, FILLED", "5678, SELL, BTC, 10, FILLED", "0, BUY, BTC, 10, NEW", "1111, BUY, BTC, 10, NEW", "1111, BUY, BTC, 5, FILLED"]], ["1234"], ["5678"], ["0"], ["1111"]]
Output: [null, null, "COMPLETED", "COMPLETED", "NEW", "IN_PROGRESS"]
Explanation:
OrderManagementSystem oms = new OrderManagementSystem();oms.consumeMessages(messages);// All 10 messages are processed in a single batch.oms.getOrderStatus("1234");// Returns "COMPLETED". Order 1234: NEW(10), FILLED(5), FILLED(3), FILLED(2). Total filled = 10.oms.getOrderStatus("5678");// Returns "COMPLETED". Order 5678: NEW(20), FILLED(10), FILLED(10). Total filled = 20.oms.getOrderStatus("0");// Returns "NEW". Order 0: No fills received for this order.oms.getOrderStatus("1111");// Returns "IN_PROGRESS". Order 1111: NEW(10) and FILLED(5). Only 5 of 10 units filled.
