Depending on the types of security instruments being traded, the amount of data may vary.
Real-time market data may arrive at any time during trading hours. Two piece of data may be nanoseconds or sub-nanoseconds apart on average.
The system is fully automated, but occasionally we need manual intervention. Also, we need authentication APIs.
Authentication:
int auth(user_profile)
returns a status code indicating auth result
Manual intervention:
int change_system_status(new_status)
returns the new system status
this should be a state machine design
long place_order(order)
returns order id of the newly placed order, or -1 if failed
int cancel_order(order_id)
returns order status after cancel request is processed
we also need a killswitch API to cancel everything and put the system to stopped mode, in case anything bad happened
We write executions to database. These are highly structured data so we use SQL.
orders: an order may have zero to many fills
uid, security_id, price, qty, side, type, status, filled_qty, broker_id, created_at, last_updated_at
orders_history:
similar to orders, but tracks the history of every order data change
fills: to store every fill
uid, security_id, order_id, fill_price, filled_qty, broker_id, created_at
securities:
uid, type, open, close, high, low, exchange_id, country_id
portfolio:
date, security_id, qty, broker_id
See diagram
many components run on multi-threading, we need to make sure resources are properly locked when they're shared between different threads. Such a multi-threading set up will slow down single execution, but ensures we can achieve more throughput.
the market data monitoring component is only interested in the market data ingestion, such that they may be combined as one subsystem to reduce complexity. Also, monitoring does not change any market data, such that we could avoid locking certain resources on the ingestion side to mitigate performance loss.
The market data ingestion may be a latency bottleneck. To truly achieve subnanosecond-level latency which is required by high-frequency trading, we have to colocate part of the system to the servers at the market exchange, using hardware to capture data and send trading orders. Pure software system is not capable of achieving true high-frequency trading.
This system works for any types of security instruments. However, to trade multiple security instrument types, as they are all very different in nature, we should run multiple systems on separate machines, each being responsible for trading one type of instrument, such that reducing complexity and unnecessary falsy interference between different instruments.