Bot service for automated trading through exchange brokers API based on trading signals (e.g. from TradingView).
- Multiple Broker Support - Handle multiple brokers (T-Investments and Finam)
- Multiple Account Support - Handle multiple trading accounts with individual broker configuration
- Automatic Position Reconciliation - Smart position management to match signal state
- Position Size Calculation - Dynamic sizing based on available capital and leverage
- Stop-Loss & Take-Profit - Automatic order placement with price validation
- Reserve Capital Support - Configurable capital reserves per strategy
- Profit & Slippage Tracking - Calculate and report trading performance metrics
- Instrument Auto-Detection - Automatic currency and instrument type detection
- Telegram Notifications - Real-time trading notifications with detailed order information
- Asynchronous Signal Processing - Non-blocking signal processing with ThreadPoolExecutor
- Smart Queue Management - One signal per account+instrument, with intelligent queuing and replacement
- Context-Aware Logging - Unique signal IDs for tracking across threads and modules
- Comprehensive Timing - Track queue wait time, processing time, and total system time
- Signal Reception: Bot receives trading signal via webhook
- Queue Management: Signal is queued for processing
- Asynchronous Processing: Signal is processed in background thread
- Position Analysis: Determines current position for instrument
- If current trading position is equal to the signal position, the signal is ignored
- Size Calculation: Calculates position size based on available funds, reserve capital and leverage
- Order Execution: Places market orders to ensure position:
- Opens long position (with closing short position if exists)
- Opens short position (with closing long position if exists)
- Closes all positions (flat)
- Risk Management: Places stop-loss and take-profit orders
- Performance Tracking: Calculates profit, slippage and other metrics
- Notifications: Sends Telegram notifications with results
- One Signal Per Key: Only one signal can be processed at a time per account+instrument
- Smart Queuing: New signals wait if one is already processing
- Signal Replacement: New signals replace waiting signals (not processing ones)
- No Interruption: Processing signals complete fully before next one starts
- Clone the repository:
git clone https://github.com/nixikanius/traiding-bot
cd traiding-bot- Prepare config:
cp config.example.yml config.ymlEdit config.yml with your settings.
docker run -it --name trading-bot \
-p 8000:8000 \
-v $(PWD)/config.yml:/app/config.yml:ro \
nixikanius/trading-bot:latestServer starts on http://127.0.0.1:8000
# Install dependencies
make install
# Run development server with auto-reload
make runDebug Logging: Set log_level: "DEBUG" in config.yml to see detailed request/response logging for debugging purposes.
GET /healthz
POST /signals/enqueue/<account>
Where <account> is the account name from config (the key in the accounts dictionary).
GET /signals/queue
Returns current signal queue status with processing and waiting signals.
Each signal can include the following parameters:
signal_id- unique signal ID (optional, generated by the bot if not provided)position- position state: "long", "short", or "flat"bar_index- bar index (optional)entry_time- signal entry time in ISO 8601 format to calculate slippage (optional)entry_price- signal entry price to calculate slippage (optional)stop_price- stop-loss price (optional)limit_price- take-profit price (optional)reserve_capital- additional sum of money added to available funds for position size calculation (in instrument currency, default: 0)capital_leverage_percent- capital percentage used for position size calculation (default: 100)instrument- instrument code (FIGI for T-Investments, symbol for Finam)
{
"position": "long",
"bar_index": 20567,
"entry_time": "2025-09-26T17:30:00",
"entry_price": 290,
"stop_price": 275,
"limit_price": 320,
"reserve_capital": 0,
"capital_leverage_percent": 100,
"instrument": "BBG004730N88"
}{
"position": "short",
"bar_index": 204112,
"entry_time": "2025-08-15T10:00:00",
"entry_price": 2708.5,
"stop_price": 2750.5,
"limit_price": 2600,
"reserve_capital": 6000000,
"capital_leverage_percent": 250,
"instrument": "IMOEXF@RTSX"
}{
"position": "flat",
"bar_index": 10567,
"entry_time": "2025-09-15T15:15:00",
"entry_price": 270,
"figi": "BBG004730N88"
}The project uses A.B.C version format, where change of:
Aindicates major changes that highly likely break backward compability (be sure to test before upgrade);Bindicates changes that may break backward compability (read the changelog and test before upgrade if necessary);Cindicates bug fixes, minor improvements or new functionality that do not break backward compability.