← 返回 coinbase 的题目列表Order Management System
类型:online_judge
Question Prompt
We utilize Coinbase's order management system, which plays a pivotal role in our operations. This system is responsible for seamlessly broadcasting messages to a Kafka topic whenever a new order is placed or an existing order is successfully executed (fully or partially). The order should transition from New -> In_Progress -> Completed.
Implement the API consumeMessages which is responsible for reading the message from Kafka and storing it in the database. Implement the API getOrderStatus which is responsible for getting the order details for a given orderId.
Note – The Kafka messages would be provided as inputs, and the local database can be any in-memory data structure you'd like!
At a minimum, an order contains the following fields: orderId, operation, symbol, quantity, orderType Example:
1234, BUY, BTC, 10, TRUE
Sample Input
1234, BUY, BTC, 10, NEW // New order of 10 BTC placed
1234, BUY, BTC, 5, FILLED // 5 BTC of an existing order purchased
1234, BUY, BTC, 3, FILLED // 3 BTC of an existing order purchased
1234, BUY, BTC, 2, FILLED // 2 BTC of an existing order purchased
5678, SELL, BTC, 20, NEW
5678, SELL, BTC, 10, FILLED
5678, SELL, BTC, 10, FILLED
0000, BUY, BTC, 10, NEW // New order of 10 BTC placed
1111, BUY, BTC, 10, NEW // New order of 10 BTC placed
1111, BUY, BTC, 5, FILLED // 5 BTC of an existing order purchased
Sample Output
getOrderStatus(1234) - COMPLETED
getOrderStatus(5678) - COMPLETED
getOrderStatus(0000) - NEW
getOrderStatus(1111) - IN_PROGRESS
[execution time limit] 4 seconds (py3) [memory limit] 2g
Extended Prompt
Extend the solution to handle a new order type called CANCEL, which is responsible for cancelling a new order. If no part of the order has been filled, then the order should be allowed to cancel.
Extended Sample Input
1234, BUY, BTC, 10, NEW // New order of 10 BTC placed
1234, BUY, BTC, 5, FILLED // 5 BTC of an existing order purchased
1234, BUY, BTC, 3, FILLED // 3 BTC of an existing order purchased
1234, BUY, BTC, 10, CANCEL // Cancel should not be allowed
5678, SELL, BTC, 20, NEW
5678, SELL, BTC, 20, CANCEL // Cancel should be allowed
[execution time limit] 4 seconds (py3) [memory limit] 2g
Example
Input
1234, BUY, BTC, 10, NEW
1234, BUY, BTC, 5, FILLED
1234, BUY, BTC, 3, FILLED
1234, BUY, BTC, 10, CANCEL
5678, SELL, BTC, 20, NEW
5678, SELL, BTC, 20, CANCEL