A high-performance trading bot written in C designed for automated crypto/stock trading. The engine operates on a command-based protocol (reading from stdin, writing to stdout) and uses a dynamic plugin architecture to evaluate market conditions using various technical indicators.
- Modular Plugin System: Loads trading strategies dynamically at runtime using
dlopenanddlsym. - Multi-Strategy Aggregation: Combines signals from multiple indicators (e.g., RSI, Ichimoku) to calculate a weighted decision cursor.
- Wallet Management: Real-time tracking of asset balances (Asset A vs. Asset B) and transaction fee calculations.
- Technical Indicators:
- RSI (Relative Strength Index): Identifies overbought/oversold conditions.
- Ichimoku Cloud: Evaluates trend direction and momentum using Tenkan, Kijun, and Senkou spans.
- Circular Buffer Logic: Efficiently manages historical candle data to minimize memory overhead.
The project is divided into several logical modules:
| Module | Description |
|---|---|
Core Engine (main.c, trade.c) |
Initializes settings, loads plugins, and manages the main execution loop. |
Plugin Loader (loader.c) |
Scans a directory for .so files and registers trading strategies. |
Interpreter (input.c) |
Parses incoming game commands (updates on stacks, next candles, and action requests). |
Decision Logic (decision.c) |
Aggregates plugin signals and determines whether to buy, sell, or pass. |
Wallet (wallet.c) |
Handles currency conversions and ensures trades are viable based on current balance. |
Data Utils (array.c, chart.c) |
Manages OHLCV (Open, High, Low, Close, Volume) data structures. |
The bot is designed to be extensible. To add a new strategy, you simply create a shared library with a plugin_entry_point.
- Ichimoku (
plugin_ichimoku.c): Uses a 9/26/52 period configuration to detect trend reversals. - RSI (
plugin_rsi.c): Calculates momentum over a 7-period window to find entry/exit points at the 30/70 thresholds.
Each plugin returns a signal (BUY, SELL, or PASS) and a strength (0.0 to 1.0). The engine calculates a Decision Cursor:
SIGNAL_LIMIT.
Use the provided Makefile (not included in snippet, but standard for this project) to compile the core and the plugins:
makeThe bot reads from standard input. You can test it using a pipe or by running it manually:
./trade_bot < communication_dump.txtThe engine looks for .so files in the path defined by PLUGIN_PATH (usually ./plugins/). Ensure your compiled indicators are placed there.
The bot follows a specific line-by-line protocol:
- Settings:
settings [key] [value](e.g.,settings time_per_move 100) - Updates:
update game next_candles [data] - Actions:
action order [time]-> Bot responds withbuy [pair] [quantity],sell [pair] [quantity], orpass.