This is a program to demonstrate key components of an electronic exchange via C++
and ASIO
.
- Efficient Limit Order Book 💨:
- Add and cancel orders in
O(1)
time complexity. - Executions are done in
O(log k)
, wherek
is the size of the best matching price.
- Add and cancel orders in
- Custom Server-Client interface 📶
- Net Repository is a custom server-client interface built using
ASIO
for low-level server-client communication viaTCP
. - The
ExchangeServer.h
is a sample implementation of thenet_server.h
interface of the Net Repository. This file can be expanded to implement additional functionality such as more sophisticated client authentication. - The
MarketParticipantSample.cpp
is a sample implementation of thenet_client.h
interface of the Net Repository. This file can be expanded to implement additional functionality such as automated order placement based on quantitative models.
- Net Repository is a custom server-client interface built using
- Database Support 💾
- All orders, executions, client information, and registered instruments are synced with a database to save and recover the state of the exchange.
- Install PostgreSQL.
- Use the SQL script located in
Exchange/DB/exchange.sql
to set up the database on your local system. - Install
pqxx
.- Edit the
CMakeLists.txt
to correctly link thepqxx
library to the program.
- Edit the
- Install ASIO.
- Edit the
CMakeLists.txt
to correctly link the ASIO library to the program. - Ensure you have
ASIO_STANDALONE
defined to avoid using the Boost version.
- Edit the
- Clone the Net Repository.
- Edit the
CMakeLists.txt
to correctly link the Net library to the program.
- Edit the
- Run the Server application:
LimitOrderBook
. - Set up the database using
option 0
. - Ensure you have clients registered and instruments listed.
- Set the client IP as
127.0.0.1
since all connections will be local.
- Set the client IP as
- Start the server using
option 3
. - Run sample client application:
Client 1
. - Run sample client application:
Client 2
. - You should now be able to connect with registered client names to the server and send in your orders.
OrderBookManager.h
: Holds pointers to all activeLOB
objects.LOB.h
: Maintains several data structures to provide efficient operations for the limit order book.Limit.h
: Defines a limit object as a doubly linked list of orders to be used in a binary tree.Execution.h
: Defines an execution object to store necessary information for an execution.Order.h
: Defines an order object with all necessary information to operate the limit order book.
MessagingQueue.h
: Thread-Safe Queue.CentralMessageSystem.h
: The application uses a publisher-subscriber pattern to distribute messages to different components. Each class can subscribe to a message topic using a callback function. TheCentralMessageSystem
acts as a dispatcher by constantly dispatching messages to the subscribers of that message type. All messages are stored as pointers, so their type can be determined at runtime.DBConnection.h
: The application uses a PostgreSQL database to store data. TheDBConnection.h
class provides an instance of a connection to the database with an API calledquery
. This API writes queries to a connected database and returns the results.
- Expansion: I would love to see new ideas to expand this project. Feel free to submit pull requests for proposed changes and expansions.
- Python Integration: If anyone is interested in exposing Python API's for this library please contact me, as Python and C++ integration really interests me.
- If you have any issues, feel free to open an issue on the repo.
- If your issue is not resolved, feel free to contact me via email.