A vertically scalable stream processing framework focusing on low latency, helping you scale and consume financial data feeds.

Overview

DragonflyBot

A vertically scalable stream processing framework focusing on low latency, helping you scale and consume financial data feeds.

Design

The framework consists of 5 layers where each layer can be easily extended and can have its own builder.

Client/protocol layer

Here different clients (supporting different protocols) can be defined e.g. we can have a builder for WebSockets clients and a different builder for FIX clients.

Feed subscriber layer

Now that we have a connected client, each client/protocol in general require different subscription approaches e.g. a FIX connection might require different methods than a WebSocket connection. We can simply define the requirements or extend them on this layer.

Feed listener layer

Feed listeners are already subscribed to feeds (i.e. they require an active subscriber) and deal only with processing/responding to the data e.g. forward the message only if top of the order book has changed.

Feed listener aggregator layer

In practice, we connect to multiple feeds/venues. If we want to get a world view of all, we need to consume what the feed listeners are emitting in one place/worker. Doing this we can e.g. consume all the order book messages emitted (and filtered) from feed listeners and construct top best bid, best offer (BBO) of all order books (constructing BBO world view).

Service layer

The final layer - the place where you define your services which consume from feed listener aggregators and serve your subscribers e.g. a bot could subscribe to your service to get a BBO world view.

Allowed topologies

Since the layers are connected only with message passing queues, we can quickly change topologies from simple ones

graph TD;
    trading_bot-->gRPC_server;
    
    gRPC_server-->feed_listener_aggregator;
    feed_listener_aggregator-->feed_listener1;
    feed_listener_aggregator-->feed_listener2;
    feed_listener_aggregator-->feed_listener3;

    feed_listener1-->feed_subscriber1;
    feed_listener2-->feed_subscriber2;
    feed_listener3-->feed_subscriber3;

    feed_subscriber1-->client1/protocol1;
    feed_subscriber2-->client2/protocol2;
    feed_subscriber3-->client3/protocol1;

to more complex ones

graph TD;
    trading_bot-->gRPC_server;
    legacy_customer-->FIX_server;
    
    gRPC_server-->|stream BBO| feed_listener_aggregator1;
    FIX_server-->|stream BBO| feed_listener_aggregator1;
    FIX_server-->|stream aggregated liquidity| feed_listener_aggregator2;
    FIX_server-->|liquidate big order| execution_engine

    feed_listener_aggregator1-->feed_listener1;
    feed_listener_aggregator1-->feed_listener2;
    feed_listener_aggregator1-->feed_listener3;

    feed_listener_aggregator2-->feed_listener1;
    feed_listener_aggregator2-->feed_listener2;
    feed_listener_aggregator2-->feed_listener3;

    feed_listener1-->feed_subscriber1;
    feed_listener2-->feed_subscriber2;
    feed_listener3-->feed_subscriber3;

    feed_subscriber1-->client1/protocol1;
    feed_subscriber2-->client2/protocol2;
    feed_subscriber3-->client3/protocol1;

simply by changing the type of the queue (MPSC to e.g. SPMC) and introducing transformers if needed.

Performance considerations

WebSocket client

Based on WS benchmarks, websocket.rs provides the fastest WS client. However, TLS doesn't seem to be supported. The second fastest - fastwebsockets supports TLS and reading single frames. So if we're only interested in top of the book, we could only read a part of the whole message i.e. read only the frames needed to get top N BBO.

JSON document parsing

Since we're only interested in top level access (getting bids/asks), we can go with property based parsing libs which are up to 10x faster than libs which parse the whole JSON. Using property based parsing we also implement functionality of JSON stream parsers, parsing only the number of consecutive values needed i.e. for getting top 10 of the book, we parse only 10 values.

Alternative allocators

tikv-jemallocator is used for improving the performance of allocations.

Other opportunities

For small vectors SmallVec could be used.

Usage

To run an example where we aggregate order books and publish top 10 via a gRPC server:

# start the gRPC server in the background
cargo run --bin dragonflybot-grpc-server -- --instrument-name ethbtc&
 
# run the client
cargo run --bin dragonflybot-grpc-client

# Docker
DOCKER_BUILDKIT=1 docker build -t dragonflybot:latest .

# run the server in the background
docker run \
  --name dragonflybot_grpc_server \
  --rm \
  --user="$(id -u):$(id -u)" \
  --group-add="$(id -u)" \
  -p 127.0.0.1:50051:50051 \
  dragonflybot:latest \
  dragonflybot-grpc-server --instrument-name ethbtc &
 
# run the gRPC client
docker run \
  --name dragonflybot_grpc_client \
  --rm \
  --user="$(id -u):$(id -u)" \
  --group-add="$(id -u)" \
  --net="host" \
  dragonflybot:latest \
  dragonflybot-grpc-client
  
# to stop containers
docker stop dragonflybot_grpc_client \
  && docker stop dragonflybot_grpc_server

Developing

For developing a multi stage, multi branch Dockerfile, supporting Rust build cache via cargo-chef is available.

# run tests
cargo test

DOCKER_BUILDKIT=1 docker build --build-arg "BUILD_PROFILE=dev" -t dragonflybot_dev:latest .
You might also like...
Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.
Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.

Themis provides strong, usable cryptography for busy people General purpose cryptographic library for storage and messaging for iOS (Swift, Obj-C), An

Aptos-core strives towards being the safest and most scalable layer one blockchain solution.
Aptos-core strives towards being the safest and most scalable layer one blockchain solution.

Aptos-core strives towards being the safest and most scalable layer one blockchain solution. Today, this powers the Aptos Devnet, tomorrow Mainnet in order to create universal and fair access to decentralized assets for billions of people.

Scalable layer-2 registry and prover for subspaces
Scalable layer-2 registry and prover for subspaces

Subspacer Note: this does not fully implement the functionality described in the Spaces protocol yet and should be considered a proof of concept. Scal

hello-world geyser plugin to stream accounts and transactions from a solana node

src/lib.rs: entrypoint src/plugin.rs: main plugin code to run: cargo build && solana-test-validator -r --geyser-plugin-config config.json note: make s

Collection of stream cipher algorithms

RustCrypto: stream ciphers Collection of stream cipher algorithms written in pure Rust. ⚠️ Security Warning: Hazmat! Crates in this repository do not

Fiddi is a command line tool that does the boring and complex process of checking and processing/watching transactions on EVM compatible Blockchain.

Fiddi is a command line tool that does the boring and complex process of checking and processing/watching transactions on EVM compatible Blockchain.

Employ your built-in wetware pattern recognition and signal processing facilities to understand your network traffic

Nethoscope Employ your built-in wetware pattern recognition and signal processing facilities to understand your network traffic. Check video on how it

Rust API Client for ImageKit.io a file storage and image processing service

Rust API Client for ImageKit.io a file storage and image processing service Usage You must retrieve your Public and Private Keys from the ImageKit Dev

Synchronized shadow state of Solana programs available for off-chain processing.

Solana Shadow The Solana Shadow crate adds shadows to solana on-chain accounts for off-chain processing. This create synchronises all accounts and the

Owner
Software Architect and Engineer, focusing on crypto and FinTech using Python and Rust
null
Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces.

Building 1. Install rustc, cargo and rustfmt. $ curl https://sh.rustup.rs -sSf | sh $ source $HOME/.cargo/env $ rustup component add rustfmt When buil

Solana Foundation 9.8k Jan 3, 2023
An automated CLI tool that optimizes gas usage in Solidity smart contracts, focusing on storage and function call efficiency.

Solidity-Gas-Optimizoor An high performance automated CLI tool that optimizes gas usage in Solidity smart contracts, focusing on storage and function

Chia Yong Kang 10 Mar 11, 2024
Diem’s mission is to build a trusted and innovative financial network that empowers people and businesses around the world.

Note to readers: On December 1, 2020, the Libra Association was renamed to Diem Association. The project repos are in the process of being migrated. A

Diem 16.7k Jan 8, 2023
Diem’s mission is to build a trusted and innovative financial network that empowers people and businesses around the world.

Note to readers: On December 1, 2020, the Libra Association was renamed to Diem Association. The project repos are in the process of being migrated. A

Diem 16.7k Jan 9, 2023
Financial maths library for risk-neutral pricing and risk

QuantMath Financial maths library for risk-neutral pricing and risk Api Documentation Goals Some quant math libraries are really just a collection of

Marcus Rainbow 309 Dec 29, 2022
A network bandwidth and latency tester.

Crusader Network Tester Setup Run cargo build --release to build the executables which are placed in target/release. Command line usage To host a serv

null 29 Dec 25, 2022
Safeguard your financial privacy with zero-knowledge proofs.

Spinner The Spinner project (https://spinner.cash) takes a privacy first approach to protect users crypto assets. It is a layer-2 protocol built on th

Spinner 21 Dec 28, 2022
A command line tool for managing financial investment portfolios written in Rust.

A command line tool for managing financial investment portfolios written in Rust. This project is the modern successor of finance. Installation You ca

Markus Zoppelt 15 Dec 21, 2022
A guide for Mozilla's developers and data scientists to analyze and interpret the data gathered by our data collection systems.

Mozilla Data Documentation This documentation was written to help Mozillians analyze and interpret data collected by our products, such as Firefox and

Mozilla 75 Dec 1, 2022