Production‑ready algorithmic trading bot for Solana on DEX Raydium using ML models.
The bot collects and filters pools, builds a dataset from OHLCV (GeckoTerminal), trains the LSTM model, makes purchase/sale decisions based on the strategy configuration, and sends reports to Telegram. It works locally or in Docker. Secrets and keys are available only through environment variables.
Disclaimer: The project is provided for educational purposes. Trading crypto assets is risky. Use mock mode/non‑combat wallet at your own risk.
- Features
- Architecture
- Repository structure
- Quick start
- Work stages
- Strategy parameters
- Docker
- Testing
- Practical notes
- Recommended GitHub tags
- License
- Solana + Raydium: collecting all pools and filtering according to your criteria (liquidity, number of holders, 24h volume, etc.).
- Data pipeline: OHLCV from GeckoTerminal → PostgreSQL.
- ML: preprocessing, LSTM training, artifact export (model, scaler, t_scaler), offline threshold validation.
- Execution: entry/exit rules by thresholds, two purchase modes, position limits.
- Reporting: messages in the Telegram channel(s).
- Operational practices: configuration in JSON, secrets from
.env, launch via Docker or directly from VSCode.
flowchart LR
A[Raydium pools] -->|filtered pools| B[(PostgreSQL)]
A2[GeckoTerminal OHLCV] --> B
B --> C[ML preprocessing]
C --> D[LSTM training]
D --> E[Validation & thresholds]
E --> F[Strategy / transaction planner]
F --> G[Solana contractor]
G --> H[Telegram reports]
.
├── core/
│ ├── main.py # launching the bot (locally)
│ ├── docker_main.py # Docker entry point
│ ├── main_config.json # strategy/path settings
│ ├── execution/ # tx execution (slippage, retries)
│ ├── strategy/ # thresholds and sizing rules (buy_mode)
│ ├── reporters/ # Telegram reports and other sinks
│ └── utils/ # logs, metrics, helpers
├── ml/
│ ├── use_preprocessor.py # building dataset
│ ├── lstm_trainer.py # train the model (PyTorch)
│ ├── validate.py # validation and review of metrics by thresholds
│ ├── ready_models/ # exported .pth
│ ├── scalers/ # .joblib for features
│ └── t_scalers/ # .pt for targets
├── api/
│ └── gecko_ohlcv_new.py # get OHLCV of GeckoTerminal → SQL
├── tools/
│ ├── raydium_pools.ipynb # full acquisition/enrichment of pools → DB
│ └── ... # auxiliary scripts
├── configs/
│ ├── dataset_config.yaml # dataset config example
│ └── trainer_config.yaml # training config example
├── reports/ # reports and graphs
├── logs/ # logs
├── docker/
│ ├── Dockerfile
│ └── docker-compose.yml
├── tests/ # pytest (unit/integration/e2e)
├── .env.example # sample with empty values
├── requirements.txt / pyproject.toml
└── README.md
- Python 3.12+ or Docker
- PostgreSQL 13+
- Available Solana RPC (public/paid)
- Telegram bot token and Channel ID
Copy .env.example → .env and fill in:
# Solana / Wallet
SOLANA_RPC_URL=...
SOL_PRIVATE_KEY=... # Don't show it to anyone!
SOL_WALLET_ADDRESS=...
# Database
POSTGRES_DSN=postgresql://user:pass@host:5432/dbname
# Telegram
TELEGRAM_BOT_TOKEN=...
TELEGRAM_CHANNEL_ID=-100XXXXXXXXXX
# External APIs
RAYDIUM_API_BASE=https://api-v3.raydium.io/
GECKOTERMINAL_BASE=https://api.geckoterminal.com/{
"scaler_path": "ml/scalers/scaler_test_47_fold1.joblib",
"model_path": "ml/ready_models/model_test_47_fold1.pth",
"t_scaler_path": "ml/t_scalers/t_scaler_test_47_fold1.pt",
"report_path": "reports",
"tg_channel_id": "-1xxxxxxxxxxxx",
"log_path": "logs",
"threshold_buy": 0.8,
"threshold_sell": 0.6,
"buy_mode": "correlation",
"max_tokens_cnt": 20,
"sol_per_trade": 0.001,
"max_alloc_per_pos": 1.0
}threshold_buy— if the model score ≥ threshold → buy.threshold_sell— if the model score < threshold → sell.buy_mode:- correlation —
sol_per_tradeis minimum, allocation is scaled by the confidence of the model, but not higher thanmax_alloc_per_pos. Themax_tokens_cntparameter does not limit the purchase until the balance is exhausted. - max_tokens — purchase of exactly
sol_per_tradeand no more thanmax_tokens_cntactive positions.
- correlation —
Open the notebook tools/raydium_pools.ipynb: get all the pools, filter (Raydium only and according to the criteria of liquidity/holders/volume), enrich and save to the database.
python ml/use_preprocessor.py --dsn "$POSTGRES_DSN" --timeframe day --window 128 --features rsi,ema,corr,vol,spread --out data/dataset_v1.parquetpython ml/lstm_trainer.py --dataset data/dataset_v1.parquet --model-out ml/ready_models/model_v1.pth --scaler-out ml/scalers/scaler_v1.joblib --t-scaler-out ml/t_scalers/t_scaler_v1.pt --epochs 50 --batch-size 512 --lr 1e-3python ml/validate.py --dataset data/dataset_v1.parquet --model ml/ready_models/model_v1.pth --scaler ml/scalers/scaler_v1.joblib --t-scaler ml/t_scalers/t_scaler_v1.pt --thresholds 0.5,0.6,0.7,0.8,0.9The script will output metrics by thresholds and save graphs in reports/.
Locally
python core/main.py --config core/main_config.jsonDocker
docker build -t rebuild-bot ./docker
docker run --rm --env-file .env -v $(pwd)/core/main_config.json:/app/core/main_config.json rebuild-bot- Input:
score ≥ threshold_buy→ open/increase. - Output:
score < threshold_sell→ close. - Sizing:
- mode correlation (minimum =
sol_per_trade, confidence scale, capmax_alloc_per_pos) - or max_tokens (exactly
sol_per_trade, maximummax_tokens_cnt).
- mode correlation (minimum =
We recommend a multistage build + .dockerignore, pinned dependencies and a minimum of artifacts in the runtime layer.
The CMD example is set to core/docker_main.py.
We use pytest (unit/integration/e2e).
Basic launch:
python -m pytest -qRecommended practices: fixtures and mockups for network/chain calls; property‑based tests (Hypothesis) for sizing functions and rules.
- GeckoTerminal OHLCV: use the API at the pool address and the desired timeframe.
- Solana RPC: specify a reliable endpoint, provide a backup.
- Telegram: add the bot as an admin to the channel; format messages (
MarkdownV2/HTML).
solana, raydium, defi, dex, amm, algorithmic-trading, trading-bot, market-data, ohlcv, geckoterminal, lstm, machine-learning, time-series, pytorch, python, docker, postgresql, telegram-bot, jupyter-notebook, pytest, ci-cd
MIT or your internal license of choice.