Design crypto trading order control API
CoinbaseSoftware Engineer · Technical ScreenLast updated
This question evaluates understanding of state management and finite-state machines, API design for lifecycle control, and implementation of in-memory data structures and transition validation in the Coding & Algorithms category.
You are implementing part of a simple crypto trading system that manages client orders. Each order can be in one of several states: NEW, ACTIVE, PAUSED, CANCELLED, or FILLED.
You need to support the following operations for a single order (you can assume order creation is already done):
pause(orderId): Temporarily pause an active order so that it will not be matched or executed while paused.resume(orderId): Resume a paused order so that it becomes active again and can be matched.cancel(orderId): Cancel an order so that it will never be executed in the future.
Rules and constraints:
- Valid state transitions are:
NEW -> ACTIVEACTIVE -> PAUSEDPAUSED -> ACTIVE(on resume)ACTIVE -> CANCELLEDPAUSED -> CANCELLEDACTIVE -> FILLED- Once an order is in
CANCELLEDorFILLED, no further operations (pause,resume, orcancel) should change its state. pauseon a non-ACTIVEorder should be rejected.resumeon a non-PAUSEDorder should be rejected.cancelon aCANCELLEDorFILLEDorder should be a no-op or return an error (choose one behavior and be consistent).
Implement a small in-memory component that:
- Stores the current state of each order by
orderId. - Exposes methods
pause,resume, andcancelthat update state according to the rules above. - Returns success/failure for each operation based on whether the transition is allowed.
Describe your data structures and implement the core logic for these operations.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.