If you want to start reading code, start from the matchingengine directory. For execute program you will need Ganache for private ETH environment.
A matching engine is a software component that sits at the core of a crypto exchange, responsible for matching buy and sell orders from traders. It works by continuously monitoring the order book, which is a list of all the buy and sell orders that traders have placed on the exchange.
Imagine there are two people, Sara and John, and each one has their own order request like this:
Each order contains the price, amount of crypto or stock, and type of order, which can be a buy or sell order.
A limit is a group of orders at a certain price level. It's like a bucket of Orders with the same price but different amount that is for different people.
As I said, each limit can contain multiple orders like this:
In theory, what the matching engine does is simple. The matching engine tries to sort the orders correctly in the first stage. Buyers' orders are sorted in descending order, and sellers' orders are sorted in ascending order based on price.
When a new order is placed, the matching engine will look for the best available match among the existing orders in the order book. If a match is found, the trade is executed and the orders are removed from the order book. If no match is found, the new order is added to the order book.
A market maker is a software program that automatically places buy and sell orders on an exchange to provide liquidity and stability for traders. This market maker, which is separate from the exchange, aims to enhance the trading experience by providing more consistent bid-ask spreads and increased trading activity.A market maker is a software program that automatically places buy and sell orders on an exchange in an effort to maintain liquidity and stability in the market.
GET /books/{market} (Currently we have only ETH market)
Response:
"TotalAsksVolume": 13000,
"TotalBidsVolume": 13000,
"Asks": [
{
"UserID": 7,
"ID": 122540,
"Amount": 1000,
"IsBid": false,
"Price": 9700,
"Timestamp": 1674833074926966443
},
{
"UserID": 7,
"ID": 941318,
"Amount": 1000,
"IsBid": false,
"Price": 9800,
"Timestamp": 1674833074926969800
},
{
"UserID": 7,
"ID": 984059,
"Amount": 1000,
"IsBid": false,
"Price": 9900,
"Timestamp": 1674833074926971287
},
{
"UserID": 8,
"ID": 498081,
"Amount": 10000,
"IsBid": false,
"Price": 10000,
"Timestamp": 1674833074926974852
}
],
"Bids": [
{
"UserID": 7,
"ID": 954425,
"Amount": 1000,
"IsBid": true,
"Price": 9300,
"Timestamp": 1674833074926977231
},
{
"UserID": 7,
"ID": 902081,
"Amount": 1000,
"IsBid": true,
"Price": 9200,
"Timestamp": 1674833074926977976
},
{
"UserID": 7,
"ID": 131847,
"Amount": 1000,
"IsBid": true,
"Price": 9100,
"Timestamp": 1674833074926978939
},
{
"UserID": 8,
"ID": 727887,
"Amount": 10000,
"IsBid": true,
"Price": 9000,
"Timestamp": 1674833074926982393
}
]
}
GET /books/{market}/best/ask
Response:
{
"Price": 9700
}
GET /books/{market}/best/bid
Response:
{
"Price": 9400
}
GET /orders/{userID}
Response:
{
"Asks": [
{
"UserID": 8,
"ID": 498081,
"Amount": 10000,
"IsBid": false,
"Price": 10000,
"Timestamp": 1674833061829744659
}
],
"Bids": [
{
"UserID": 8,
"ID": 727887,
"Amount": 10000,
"IsBid": true,
"Price": 9000,
"Timestamp": 1674833061830209674
}
]
}
POST /orders
Parameters:
{
"userID": 1,
"Type": "LIMIT",
"IsBid": true,
"Amount": 1000,
"Price": 90,
"Market": "ETH"
}
Response:
{
"OrderID": 203300
}
DELETE /orders/{orderID}
Response:
{
"msg": "Canceled"
}