exchange-orderbook is an implementation of a spot exchange; like Coinbase, Kraken, or Binance supporting Bitcoin (BTC) and Ether (ETH) (NB: crypto is just an implementation detail here that is easier to implement than stocks.)
Backend written in Rust, using Tokio and the Axum web framework, also using postgreSQL via SQLx.
Frontend was made with HTMX, DaisyUI, Tailwind CSS, and SSR with minijinja.
Check out the screenshots
Please ensure you have the following programs installed on the system:
To only build the exchange and grpc-proxy executable binaries:
cargo build --release --bins
They should be found in target/release/exchange
and target/release/bitcoind-grpc-proxy
respectively.
To run the exchange and grpc-proxy it is recommended to use docker-compose:
docker compose up -d --build
This will start the exchange, nginx, postgres, and bitcoind and bitcoind-grpc-proxy services.
It will take some time for the bitcoin core full node to sync with the testnet, this is only a couple hours to a day depending on your internet connection. If you dont want to wait you can always configure the bitcoind service to use the regtest network instead of the testnet.
disable or comment out testnet=1
in etc/bitcoind/bitcoin.conf
and set regtest=1
instead.
Assuming you are using docker to run nginx the website should be available http://localhost:3000/
you can take a look at the screenshots to know what to expect.
The following services can be found in the docker-compose.yml
file:
- exchange, monolith service providing trading, funding, and account related services via a RESTful webserver API
- NGINX, used for SSL/TLS termination and reverse proxying requests to exchange
- Postgres, Schema migrations are located in the migrations directory and are managed using the diesel migrate tool. To minimize operational risk—such as system downtime, data loss, or state incoherence between replicas—migrations are executed manually.
- bitcoind, a bitcoin core node used for generating addresses and streaming transactions configured to use the testnet
- bitcoind-grpc-proxy, a grpc server to proxy requests to bitcoind written because a well-typed grpc api is much nicer to work with.
The exchange service is a single-process service providing trading, funding, and account related services via a RESTful/Hypermedia-driven webserver.
NGINX serves as the web server and reverse proxy:
- SSL/TLS Termination: Handles encryption for secure traffic.
- Reverse Proxy: Routes traffic to
exchange
API instances. - Future Capabilities: Potential rate limiting implementation.
The database is a Postgres database. Schema migrations are located in the migrations directory and are managed using the diesel migrate tool. To minimize operational risk—such as system downtime, data loss, or state incoherence between replicas—migrations are executed manually.
The best way to interact with the Bitcoin network is to run a full node. It will index, verify, track, and manage transactions and wallets. It will also allow us to generate addresses and off-ramp BTC to users.
The currently existing jsonrpc and bitcoin rpc crates are difficult to use and not fully featured. The bitcoin core code itself is a type of C/C++ I can not navigate very well. So I wrote a grpc proxy to expose a well-typed interface to the exchange service while dealing with the bitcoin core jsonrpc interactions in a separate process.
The software is distributed under a Limited Use License Agreement, which grants you a non-exclusive, non-transferable, limited right to access and use the software for educational purposes only. This includes viewing, studying, and manually copying code snippets for personal educational use in non-commercial settings. Any electronic reproduction or reintegration of the code into other software is prohibited without prior written consent. The software may not be used, copied, modified, merged, published, distributed, sublicensed, or sold for any commercial purposes.
It is a pretty restrictive license but that's just to deter anyone that wants to come and exploit source-available code for commercial use to make a quick buck. Please do not feel unwelcomed to rifle through the code out of curiosity or if you have questions to reach out or start a discussion.
Yes, you have permission to run the software on your personal device for educational purposes only. This means you can use the software to learn and understand the coding practices and techniques employed. However, you are not allowed to use the software for any commercial activities, nor can you modify or distribute the software in any form, whether modified or original.
I wanted to see if I could put one together end-to-end for fun. It is shared publicly to showcase the capabilities and design decisions involved in building a full-stack crypto exchange. The project is intended to be used as an educational tool to help others understand and gain insights into software development and engineering practices in this specific domain.
Any questions about the project should use GitHub discussions.