This is an Ethereum exchange server built using Go. It allows users to place limit and market orders for trading Ether (ETH). The server integrates with an Ethereum client and handles order placement, matching, and cancellation.
-
Market Orders: Users can place market orders to buy or sell Ether at the current market price.
-
Limit Orders: Users can place limit orders specifying a desired price for buying or selling Ether.
-
Order Matching: The server matches orders between buyers and sellers to facilitate trades.
-
Orderbook Management: It maintains orderbooks for different markets to track orders.
-
User Registration: Users can register with their Ethereum private keys.
-
ETH Transfers: The server supports ETH transfers between users when orders are matched.
To run this project, you need to have Go and an Ethereum client (e.g., geth) installed on your machine.
-
Clone the repository:
git clone https://github.com/inagib21/crypto-exchange.git
-
Install dependencies using Go Modules:
go mod tidy
-
Configure Ethereum client:
- Ensure that you have an Ethereum client (e.g., geth) running on
http://localhost:8545. You can adjust this in the code if necessary.
- Ensure that you have an Ethereum client (e.g., geth) running on
-
Use the Makefile commands to build, run, and test the server:
-
Build the server:
make build
-
Run the server:
make run
-
Run tests:
make test
-
The server should be up and running on http://localhost:3000.
Users need to register with their Ethereum private keys. This can be done programmatically by calling the registerUser function or through a user registration API.
Users can place orders using the /order API endpoint. They can specify the order type (market or limit), bid or ask, order size, price, and market.
Example of placing a limit order:
curl -X POST http://localhost:3000/order -d '{
"UserID": 1,
"Type": "LIMIT",
"Bid": true,
"Size": 1.0,
"Price": 200.0,
"Market": "ETH"
}'Users can view their orders and order history using the /order/:userID API endpoint.
Example of viewing orders for a user with ID 1:
curl http://localhost:3000/order/1The server automatically matches buy and sell orders when conditions are met. The matched orders are then executed.
Users can cancel their orders using the /order/:id API endpoint. Specify the order ID to cancel.
Example of cancelling an order with ID 123:
curl -X DELETE http://localhost:3000/order/123Users can retrieve market data, including the order book, best bid, best ask, and recent trades using various API endpoints.
Special thanks to AnthonyGG for his excellent tutorial on building an Ethereum exchange server in Go. His tutorial was a valuable resource for creating this project.
Create the front end for this project
This project is licensed under the MIT License. See the LICENSE file for details.