An implementation of an exchange based on the following:
- Buys / Bids: Best prices to buy, sorted in decreasing order
- Sales / Offers: Best prices to sell, sorted in increasing order
Other entities: Market Participants, Instruments
- Do we want to parallelize at the level of an instrument? i.e. maintain an orderbook datastructure for each instrument. Ocassionaly, we may want to touch two diffent instruments
- Scale, (3M messages/s, 10k symbols)
- Fairness
- Reliability
- Durability
- Matching Engine
- Canceller
- Trade Reporter
- Market Data (filtered versions of the raw transactions)
CREATE KEYSPACE fictitiousstockexchange
WITH REPLICATION = {
'class': 'SimpleStrategy',
'replication_factor': 1
};
USE fictitiousstockexchange;
CREATE TABLE bids (
bid_time_uuid TIMEUUID,
initiater_id TEXT,
ticker_symbol TEXT,
number_of_shares DOUBLE,
bid_price DOUBLE,
country TEXT,
PRIMARY KEY ((country, ticker_symbol), initiater_id, bid_time_uuid)
);
CREATE TABLE asks (
ask_time_uuid TIMEUUID,
initiater_id TEXT,
ticker_symbol TEXT,
number_of_shares DOUBLE,
ask_price DOUBLE,
country TEXT,
PRIMARY KEY ((country, ticker_symbol), initiater_id, ask_time_uuid)
);
CREATE TABLE transfers (
transfer_time_uuid TIMEUUID,
initiater_id TEXT,
ticker_symbol TEXT,
number_of_shares DOUBLE,
credit BOOLEAN,
share_price DOUBLE,
country TEXT,
PRIMARY KEY ((country, ticker_symbol), initiater_id, transfer_time_uuid)
);
Note: The architecture has chnaged since I made this picture. Will change it once I have a stable version
- Apache Kafka
~ ./$KAFKA_BIN/bin/zookeeper-server-start.sh ./$KAFKA_BIN/config/zookeeper.properties
~ ./$KAFKA_BIN/bin/kafka-server-start.sh ./$KAFKA_BIN/config/server.properties
- Compile all sub-projects
~ mvn clean compile
This should also build Docker containers for all the services
- Start all the services
~ docker-compose up -d
Create new bids
curl -X POST -H "Content-Type: application/json" -d '{"country": "US", "tickerSymbol": "AAPL", "initiaterId": "AAPL", "numberOfShares": 1000, "bidPrice": 40}' localhost:8002/bids