Real time financial data streaming and resampling with Rust.
This crate is composed of two tasks continuously executing in parallel:
- Obtains Finnhub's realtime data and saves it to a PostgreSQL database in the table
trades. - Resamples data from
tradesinto a predefined interval (by default, 100 milliseconds) and saves it on the tableresampled_trades. Resampling is done by taking the lastest trade that happened prior to that instant.
Additionally an API to query the data is provided.
See k8s folder: https://github.com/randommm/rust-financial-platform/tree/master/k8s.
-
Create a file called
.envin the root directory (same folder thatLICENSEis) with Finnhub API token, the Postgresql database url:FINNHUB_TOKEN=your_token_here POSTGRES_PASSWORD=your_postgresql_password_here DATABASE_URL=postgres://postgres:${POSTGRES_PASSWORD}@postgres/rfplatform PGADMIN_DEFAULT_EMAIL=your@email.com PGADMIN_DEFAULT_PASSWORD=your_password_for_postgres_webadmin_here -
Run
docker compose up. -
The API should became available at http://127.0.0.1:7500 while the API documentation will be at http://127.0.0.1:7500/docs and Postgres webadmin will be at http://127.0.0.1:7510
-
Create a file called
.envas explained in the previous sections (you will need to provide your own PostgreSQL server setup). -
If you don't have
Rustinstalled, seehttps://rustup.rs -
Create the database with:
cargo install sqlx-cli && sqlx database create && sqlx migrate run -
Start the data pipeline with
cargo run --bin rust-financial-platform-pipeline -
Start the API with
cargo run --bin rust-financial-platform-api