An open-source trading sandbox that demonstrates how to operationalise Kronos – the Tsinghua University foundation model for financial markets (https://github.com/shiyu-coder/Kronos). The platform couples Kronos-powered forecasts with a Spring Boot order engine and a modern Next.js UI, giving you an end-to-end playground for research, prototyping, and future broker integration.
- Generate 5-day BUY/SELL/HOLD signals with the Kronos model.
- Create demo buy/sell orders with portfolio-level buying power and inventory rules.
- Inspect predictions, orders, and signals in a single web experience optimized for rapid experimentation.
graph LR
User((Trader)) -->|Browser| UI[Next.js trading-ui]
UI -->|REST /orders /predictions| Spring[Spring Boot trading-service]
Spring -->|REST /predict| FastAPI[FastAPI ai-service]
Spring -->|JPA| H2[(In-memory H2 DB)]
FastAPI -->|KronosPredictor| Kronos[(Kronos Model + Weights)]
FastAPI -->|HuggingFace Hub| HF[(Model Weights Cache)]
docker compose up --buildEnvironment highlights:
| Variable | Purpose | Default |
|---|---|---|
KRONOS_DEVICE |
Set to cpu, cuda, or cuda:0 |
cpu |
KRONOS_MODEL_ID |
Hugging Face model ID for Kronos | NeoQuasar/Kronos-small |
KRONOS_TOKENIZER_ID |
Hugging Face tokenizer ID | NeoQuasar/Kronos-Tokenizer-base |
PREDICTION_SERVICE_BASE_URL |
AI service URL used by Spring Boot | http://localhost:5001 |
NEXT_PUBLIC_API_BASE_URL |
Frontend base URL for the trading service | http://localhost:8080 |
To persist Kronos weights across rebuilds, mount a cache directory:
services:
ai-service:
volumes:
- ./cache/huggingface:/root/.cache/huggingfaceStart each service in its own terminal once dependencies are installed:
# FastAPI (requires Python 3.12+)
cd ai-service
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
uvicorn main:app --host 0.0.0.0 --port 5001
# Spring Boot API
cd ..
./mvnw spring-boot:run
# Next.js UI (Node 18+)
cd trading-ui
npm install
npm run dev -- --port 3000Note: The platform uses an in-memory H2 database by default. All data (orders, portfolios, inventory) is lost when the Spring Boot service restarts.
Right now, the Kronos predictor in ai-service/kronos_integration/predictor.py uses synthetic price bars purely to demonstrate end-to-end wiring. In production you should fetch real historical OHLCV data for the requested ISIN and pass it to the predictor. At minimum you need a DataFrame with columns:
open,high,low,close,volume(optionallyamount)- A matching timestamp index (5-minute bars are assumed in the sample)
Where should this data come from?
- Your own market data store (PostgreSQL, TimescaleDB, ClickHouse, etc.)
- A vendor API (e.g., Polygon.io, Tiingo, Alpha Vantage) cached into your DB
- For research, any CSV/Parquet you maintain for the instruments you support
See ref/Kronos-demo/update_predictions.py for a simple example that loads a local dataset and runs a prediction pipeline; we follow a similar shape. To wire this into our service, replace the placeholder synthetic block in kronos_integration/predictor.py with a function that queries your data store by ISIN, builds x_df (historical lookback rows), and constructs x_timestamp/y_timestamp ranges to match the desired prediction horizon.
Pseudo-contract for that function:
- input:
isin: str,lookback: int,pred_len: int - output:
(x_df: pd.DataFrame[open,high,low,close,volume,amount], x_timestamp: DatetimeIndex, y_timestamp: DatetimeIndex)
Once you have it, inject it into the predictor and remove the synthetic data code path.
- Keep the Kronos inference service running (Docker or host Python) so forecasts remain available.
- Extend the Spring Boot trading service with real broker adapters while preserving its existing REST surface for the UI.
- Carefully separate simulation and live modes; require explicit configuration before forwarding orders to an exchange.
- Store exchange credentials in environment variables or a secrets manager—never commit keys to the repository.
- Add monitoring (latency/error metrics) and rollback pathways so you can fall back to simulation when the exchange API degrades.
You can connect this project to your own Binance account by following the official developer guidance (https://developers.binance.com/en):
- Pick the environment – start with Binance Testnet; switch to Production only after end-to-end validation.
- Create API keys – log into the Binance dashboard, enable trading permissions, and record the API key/secret securely (e.g., AWS Secrets Manager, HashiCorp Vault).
- Understand signing – Binance REST requests require HMAC SHA256 signatures and timestamps; use the official SDK or sign requests server-side in Spring Boot.
- Use REST + WebSocket APIs – REST for order placement/account queries, WebSockets for live fills and market data; handle automatic reconnects and listen-key heartbeats.
- Implement rate limiting – respect Binance weight limits, back off when
429responses occur, and log usage for auditing. - Add risk controls – enforce portfolio limits, throttle strategy execution, and maintain an audit log of all outbound orders.
- Secrets injection – expose keys to containers via variables such as
BINANCE_API_KEY&BINANCE_API_SECRET; rotate them regularly. - Test extensively – run integration tests and dry runs against Testnet, then enable production access behind a feature flag for manual confirmation.
MIT