The project status is an example of trading bot and isn't ready for any production using. The provided trade strategy is just an example and have negative profit by the end.
Here is trading bot for MOEX Exchange with ability to send information about trading to a telegram chat. The bot is using Tinkoff Invest Python gRPC client api.
- Trading RUB stocks via Тинькофф Инвестиции on MOEX Exchange
- Ability to use personal trade strategy for every stock
- Trade information sends to a telegram chat (orders details, trade day summary etc.)
Note: trade strategy is represented in code is just example and not a trade or invest recommendation.
$ pip install tinkoff-investments
$ pip install -U aiogram
Open brokerage account Тинькофф Инвестиции and top up your account:
- "Margin trading" must be enabled
Do not forget to take TOKEN for API trading.
Register your bot via @BotFather.
Create a chat and get chat_id.
PS. Please use Google to find detailed instruction how to get chat_id.
- Open
settings.ini
file - Specify token for trade API in
TOKEN
(sectionINVEST_API
) - (Optinal) Specify token for a telegram bot in
TELEGRAM_BOT_TOKEN
(sectionBLOG
) - (Optinal) Specify id of a telegram chat in
TELEGRAM_CHAT_ID
(sectionBLOG
)
Recommendation is to use python 3.10 (bot has been tested on 3.10 version include real trading).
Run main.py
Configuration can be specified via settings.ini file.
Token and app name for Тинькофф Инвестиции api.
- status - telegram working mode:
- 0 - disabled
- 1 - enabled
- token and chat id for telegram api
Minimal amount of rub on account for start trading.
Settings for time management. Bot trades only in main trade session. Bot ignore pre\post market etc.
Settings for trade strategies.
Section STRATEGY_ticker_name:
STRATEGY_NAME
- name of algorithmTICKER
- ticker name (human-friendly name for telegram messages)FIGI
- figi of stock. Required for APIMAX_LOTS_PER_ORDER
- Maximum count of lots per order
Section STRATEGY_ticker_name_SETTINGS:
Detailed settings for strategy. Strategy class reads and parses settings manually.
Note: Only one strategy for one stock in configuration.
Before start:
- Token verification
- Appropriate account selects automatically by token
- By trading schedule, bot selects time to start trading (start main trading session)
Main session:
- Bot checks:
- stock status for every stock (list of strategies from configuration)
- minimum amount of rub on account
- Starts gRPC stream for data from API
- Strategies analyse candles and return signals if needed
- Bot opens orders by signals from strategies
- If stop or take price levels are confirmed, bot closes orders
Trading schedule:
- Bot awaits start and end of main trading session
- Bot works every trade day
- Restart doesn't require for trading. Only in emergency situations.
- Write a new class with trade logic
- The new class must have IStrategy as super class
- Give a name for the new class
- Extend StrategyFactory class by the name and return the new class by the name
- Specify new settings in settings.ini file. Put the new class name in
STRATEGY_NAME
- Test the new class on historical candles
Information about:
- Trading day summary at start and list of stocks
- Open and close orders, take profit and stop loss price levels
- Trading day summary in the end of day
Telegram messages are optional and can be disabled without any effect on trading.
All logs are written in logs/robot.log. Any kind of settings can be changed in main.py code
The author is not responsible for any errors or omissions, or for the trade results obtained from the use of this bot.