{"id":18730273,"url":"https://github.com/mental32/exchange-orderbook","last_synced_at":"2025-04-12T17:12:39.426Z","repository":{"id":204905081,"uuid":"555822087","full_name":"mental32/exchange-orderbook","owner":"mental32","description":"A Full-stack, Auction-market, Spot-exchange written in Rust.","archived":false,"fork":false,"pushed_at":"2024-09-28T13:37:55.000Z","size":812,"stargazers_count":18,"open_issues_count":0,"forks_count":7,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-12T17:12:32.759Z","etag":null,"topics":["bitcoin","cryptocurrency","cryptocurrency-exchanges","exchange","exchange-api","hft","hft-trading","lock-free","low-latency","matching-engine","order-book","rust","stock-market","trading-api","trading-platform"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mental32.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-22T12:13:20.000Z","updated_at":"2025-02-01T15:54:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"379a0bf5-620a-479c-81b9-f150d329b1f9","html_url":"https://github.com/mental32/exchange-orderbook","commit_stats":null,"previous_names":["mental32/exchange-orderbook"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mental32%2Fexchange-orderbook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mental32%2Fexchange-orderbook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mental32%2Fexchange-orderbook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mental32%2Fexchange-orderbook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mental32","download_url":"https://codeload.github.com/mental32/exchange-orderbook/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248602312,"owners_count":21131616,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitcoin","cryptocurrency","cryptocurrency-exchanges","exchange","exchange-api","hft","hft-trading","lock-free","low-latency","matching-engine","order-book","rust","stock-market","trading-api","trading-platform"],"created_at":"2024-11-07T14:39:21.882Z","updated_at":"2025-04-12T17:12:39.397Z","avatar_url":"https://github.com/mental32.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# exchange-orderbook\n\n## Table Of Contents\n\n- [Greetings! 👋](#greetings-)\n- [Quick Start](#quick-start)\n  - [Prerequisites](#prerequisites)\n  - [Compiling from source (without docker)](#compiling-from-source-without-docker)\n  - [Running (with docker)](#running-with-docker)\n  - [NB: bitcoind initial sync](#nb-bitcoind-initial-sync)\n  - [Accessing the exchange](#accessing-the-exchange)\n- [Service Architecture](#service-architecture)\n  - [High-level breakdown of the services](#high-level-breakdown-of-the-services)\n    - [Exchange](#exchange)\n    - [NGINX](#nginx)\n    - [Postgres](#postgres)\n    - [bitcoind (Bitcoin Core)](#bitcoind-bitcoin-core)\n    - [bitcoind-grpc-proxy](#bitcoind-grpc-proxy)\n- [FAQ](#faq)\n  - [What is the license?](#what-is-the-license)\n  - [Do I have permission to run this?](#do-i-have-permission-to-run-this)\n  - [Why did you write this?](#why-did-you-write-this)\n- [Author](#author)\n- [Screenshots](#screenshots)\n  - [Landing Page](#landing-page)\n  - [Sign-In Page](#sign-in-page)\n  - [Sign-Up Page](#sign-up-page)\n  - [Consumer Dashboard Page](#consumer-dashboard-page)\n  - [Admin Page](#admin-page)\n  - [Trading Dashboard Page](#trading-dashboard-page)\n\n\u003c!-- on my browser from here you have to scroll down --\u003e\n\n\u003chr\u003e\n\n# [Greetings! 👋](#table-of-contents)\n\nexchange-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.)\n\nBackend written in Rust, using Tokio and the Axum web framework, also using postgreSQL via SQLx.\n\nFrontend was made with HTMX, DaisyUI, Tailwind CSS, and SSR with minijinja.\n\nCheck out the [screenshots](#screenshots)\n\n# [Quick Start](#table-of-contents)\n\n## Prerequisites\n\nPlease ensure you have the following programs installed on the system:\n\n- [Docker](https://docs.docker.com/get-docker/)\n- [Docker Compose](https://docs.docker.com/compose/install/)\n- [Rust](https://www.rust-lang.org/tools/install)\n- [Diesel CLI](https://diesel.rs/guides/getting-started/)\n- [Protobuf Compiler](https://grpc.io/docs/protoc-installation/)\n\n## Compiling from source (without docker)\n\nTo only build the exchange and grpc-proxy executable binaries:\n\n```\ncargo build --release --bins\n```\n\nThey should be found in `target/release/exchange` and `target/release/bitcoind-grpc-proxy` respectively.\n\n## Running (with docker)\n\nTo run the exchange and grpc-proxy it is recommended to use docker-compose:\n\n```\ndocker compose up -d --build\n```\n\nThis will start the exchange, nginx, postgres, and bitcoind and bitcoind-grpc-proxy services.\n\n## NB: bitcoind initial sync\n\nIt will take some time for the bitcoin core full node to sync with the testnet, this is only a couple hours to a day\ndepending on your internet connection. If you dont want to wait you can always configure the bitcoind service to use the\nregtest network instead of the testnet.\n\ndisable or comment out `testnet=1` in `etc/bitcoind/bitcoin.conf` and set `regtest=1` instead.\n\n## Accessing the exchange\n\nAssuming you are using docker to run nginx the website should be available `http://localhost:3000/` you can take a look at the [screenshots](#screenshots) to know what to expect.\n\n# [Service Architecture](#table-of-contents)\n\nThe following services can be found in the `docker-compose.yml` file:\n\n* exchange, monolith service providing trading, funding, and account related services via a RESTful webserver API\n* NGINX, used for SSL/TLS termination and reverse proxying requests to exchange\n* 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.\n* bitcoind, a bitcoin core node used for generating addresses and streaming transactions configured to use the testnet\n* bitcoind-grpc-proxy, a grpc server to proxy requests to bitcoind written because a well-typed grpc api is much nicer to work with.\n\n## High-level breakdown of the services\n\n### Exchange\n\nThe exchange service is a single-process service providing trading, funding, and account related services via a RESTful/Hypermedia-driven webserver.\n\n### NGINX\n\nNGINX serves as the web server and reverse proxy:\n\n- **SSL/TLS Termination**: Handles encryption for secure traffic.\n- **Reverse Proxy**: Routes traffic to `exchange` API instances.\n- **Future Capabilities**: Potential rate limiting implementation.\n\n### Postgres\n\nThe 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.\n\n### bitcoind (Bitcoin Core)\n\nThe 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.\n\n### bitcoind-grpc-proxy\n\nThe 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.\n\n# [FAQ](#table-of-contents)\n\n## What is the license?\n\nThe 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.\n\nIt 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.\n\n## Do I have permission to run this?\n\nYes, 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.\nHowever, 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.\n\n## Why did you write this?\n\nI 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.\nThe 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.\n\n# [Author](#table-of-contents)\n\nAny questions about the project should use GitHub discussions.\n\n`mentalfoss@gmail.com`\n\n# [Screenshots](#table-of-contents)\n\n## [Landing Page](#table-of-contents)\n\n![landing-page](./screenshots/landing-page.jpeg)\n\n## [Sign-In Page](#table-of-contents)\n\n![Sign-In Page](./screenshots/sign-in-page.jpeg)\n\n## [Sign-Up Page](#table-of-contents)\n\n![Sign-Up Page](./screenshots/sign-up-page.jpeg)\n\n## [Consumer Dashboard Page](#table-of-contents)\n\n![Consumer Dashboard Page](./screenshots/consumer-dashboard-page.jpeg)\n\n## [Admin Page](#table-of-contents)\n\n![Admin Page](./screenshots/admin-page.jpeg)\n\n## [Trading Dashboard Page](#table-of-contents)\n\n![Trading Dashboard Page](./screenshots/trading-dashboard-page.jpeg)\n\n\n[tinyvec]: https://docs.rs/tinyvec\n[event sourcing]: https://microservices.io/patterns/data/event-sourcing.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmental32%2Fexchange-orderbook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmental32%2Fexchange-orderbook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmental32%2Fexchange-orderbook/lists"}