This is a bot for trading on Tinkoff broker. It uses Tinkoff investments API
This is a bot for trading on Tinkoff broker. It uses Tinkoff investments API
App name is qwertyo1
To run the bot, you need to have a Tinkoff account.
.env
with required env variables. You can find an example in .env.example
instuments_config.json
with configurations. You can find an example in instruments_config.json.example
pip install virtualenv
virtualenv --python=python3.9 venv
source venv/bin/activate
pip install -r requirements.txt
make start
TOKEN
: Your Tinkoff token. You can generate it in the settings
Can be a token for sandbox or for real account.ACCOUNT_ID
: Your Tinkoff account id. You can get it using get accounts tool. If not specified, the first account used.SANDBOX
: Set to false
if you want to use real account. Default is true
.List of instruments you want to trade along with their settings. Each list element is a dictionary with the following keys:
figi
: Tinkoff instrument idstrategy
: The strategy configuration
name
: The name of the strategy to useparameters
: Parameters of the strategy. More details can be found in the documentation of the strategyinterval_size
: The percent of the prices to include into intervaldays_back_to_consider
: The number of days back to consider in interval calculationcheck_interval
: The interval in seconds to check for a new prices and for interval recalculationstop_loss_percent
: The percent from the price to trigger a stop lossquantity_limit
: The maximum quantity of the instrument to have in the portfolioMain strategy logic is to buy at the lowest price and sell at the highest price of the calculated interval.
Interval is calculated by taking interval_size
percents of the last prices
for the last days_back_to_consider
days. By default, it's set to 80 percents which means
that the interval is from 10th to 90th percentile.
This is the tool to get your Tinkoff accounts. Useful when you don't know your account id. To run use this command:
make get_accounts
In test/strategies/interval/backtest/conftest.py
you can find the test configuration.
Set up figi
, comission
, strategy config object, and from_date
offset.
To run backtest use this command:
make backtest
The result is saved in test/strategies/interval/backtest/test_on_historical_data.txt
Use this command to display stats:
make display_stats
It will display the list of executed trades