MCPcopy Index your code
hub / github.com/0xKitsune/bid_ask_service

github.com/0xKitsune/bid_ask_service @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
128 symbols 249 edges 23 files 17 documented · 13%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

bid_ask_service

bid_ask_service is a Rust program designed to aggregate real-time orderbook data from multiple CeFi exchanges in order to publish the bid-ask spread, top n bids and top n asks via a gRPC server.

This README provides a step-by-step guide on how to install/run the program. Additionally, this repo also contains a code walkthrough and a post build reflection detailing thoughts, upgrades and improvements to the current codebase. If you would like to jump to any of these sections, feel free to use the table of contents below.

Table of Contents

  1. Installing
  2. Usage
  3. Code Walkthrough/Reflections

Installing

Installing the program is quick and easy. First, make sure that you have Rust installed. Once installed, you can run the following commands to install the Bid-Ask Service from source.

git clone https://github.com/0xKitsune/bid_ask_service
cd bid_ask_service
cargo install --path .

Since this program uses a gRPC server to stream aggregated order book updates to clients, you will also need to install the protoc Protocol Buffers compiler, along with Protocol Buffers resource files.

Ubuntu

sudo apt update && sudo apt upgrade -y
sudo apt install -y protobuf-compiler libprotobuf-dev

Alpine Linux

sudo apk add protoc protobuf-dev

macOS

Assuming Homebrew is already installed. (If not, see instructions for installing Homebrew on the Homebrew website.)

brew install protobuf

With that out of the way, you are ready to run the program!

Usage

The Bid Ask Service is configurable via command-line arguments. Here's a rundown of each option:

  • --exchanges, -e: Specifies the list of exchanges the service should connect to. They should be separated by commas. For example, if you wanted to connect to Binance and Bitstamp, you would specify --exchanges binance,bitstamp. If this argument is left blank, all exchanges will be used. Note that to use Binance, you will need to be in an authorized geographic location or use a VPN.

  • --pair, -p: Specifies the trading pair to listen to updates. Trading pairs should be separated by commas. For example, if you wanted to listen to updates for the ETH/BTC pairing, you would specify --pair eth,btc.

  • --order_book_depth: Determines the max depth of the aggregated order book. This specifies the maximum amount of bids or asks the book will hold. For example, if the depth is set to 20, there will be a maximum of 20 bids and 20 asks in the orderbook. The default depth is 25.

  • --best_n_orders: Determines the number of best bids and asks to stream via the gRPC server. The default number is 10.

  • --exchange_stream_buffer: Sets the channel buffer size for streaming live order book data from exchanges. The default size is 100.

  • --price_level_channel_buffer: Sets the channel buffer size to pass the price level updates from the exchange module to the aggregated order book. The default size is 100.

  • --summary_buffer: Sets the buffer size for the tokio broadcast channel used to stream the aggregated order book to the gRPC server. The default size is 300.

  • --socket_address: Specifies the socket address for the gRPC server. The default address is [::1]:50051.

  • --level: Sets the level of logging. The options are trace, debug, info, warn, and error. The default level is info.

  • --log_file_path: Specifies the path to the output file for logging. All log files will be written to the log dir. The default path is output.log, writing the file to log/output.log.

Here is an example showing how to use the command line arguments together.

bid_ask_service --exchanges binance,bitstamp --pair eth,btc --order_book_depth 50 --best_n_orders 20 --level info --log_file_path my_log.log

Running Tests / Benchmarks

To run the test suite, you can run cargo test in your terminal while in the project's root directory. Note that the Binance tests will not pass if you are in an unauthorized geographic region (this is also the reason why the CI pipeline currently fails). You can also use a VPN to successfully run the Binance tests.

To run the benchmarks suite, run cargo bench in your terminal while in the project's root directory.

Extension points exported contracts — how you extend this code

OrderBookService (Interface)
(no doc) [2 implementers]
src/exchanges/mod.rs
Order (Interface)
(no doc) [2 implementers]
src/order_book/mod.rs
BuySide (Interface)
(no doc) [1 implementers]
src/order_book/mod.rs
SellSide (Interface)
(no doc) [1 implementers]
src/order_book/mod.rs
OrderBook (Interface)
(no doc)
src/order_book/mod.rs

Core symbols most depended-on inside this repo

update_bids
called by 49
src/order_book/btree_set/mod.rs
update_asks
called by 49
src/order_book/btree_set/mod.rs
set_quantity
called by 10
src/order_book/price_level/bid.rs
initialize_bids
called by 5
benches/btree_set_order_book.rs
initialize_asks
called by 5
benches/btree_set_order_book.rs
to_string
called by 5
src/exchanges/mod.rs
get_best_bid
called by 5
src/order_book/btree_set/mod.rs
get_best_ask
called by 5
src/order_book/btree_set/mod.rs

Shape

Function 54
Method 42
Class 18
Enum 9
Interface 5

Languages

Rust100%

Modules by API surface

src/order_book/btree_set/mod.rs16 symbols
benches/btree_set_order_book.rs16 symbols
src/order_book/price_level/bid.rs13 symbols
src/order_book/price_level/ask.rs13 symbols
src/exchanges/bitstamp/stream.rs12 symbols
src/order_book/mod.rs9 symbols
src/exchanges/mod.rs9 symbols
src/exchanges/binance/stream.rs9 symbols
src/exchanges/exchange_utils.rs5 symbols
src/server/mod.rs4 symbols
tests/integration_test.rs3 symbols
src/order_book/price_level/mod.rs3 symbols

For agents

$ claude mcp add bid_ask_service \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact