Code Monkey home page Code Monkey logo

tinkoff-trading-bot's Introduction

๐Ÿฅ‡ The winner in Tinkoff invest robot contest 01.06.2022

Tinkoff Trading Bot

This is a bot for trading on Tinkoff broker. It uses Tinkoff investments API

App name is qwertyo1

How to run

To run the bot, you need to have a Tinkoff account.

  • Generate token for your account at the settings
  • Create a file .env with required env variables. You can find an example in .env.example
  • Create a file instuments_config.json with configurations. You can find an example in instruments_config.json.example
  • [Optional] Create virtual environment and activate it:
    pip install virtualenv
    virtualenv --python=python3.9 venv
    source venv/bin/activate
  • Install dependencies with
    pip install -r requirements.txt
  • Run the bot with
    make start

.env file content

  • 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.

instruments_config.json file content

instruments

List of instruments you want to trade along with their settings. Each list element is a dictionary with the following keys:

  • figi: Tinkoff instrument id
  • strategy: The strategy configuration
    • name: The name of the strategy to use
    • parameters: Parameters of the strategy. More details can be found in the documentation of the strategy

Interval strategy parameters

  • interval_size: The percent of the prices to include into interval
  • days_back_to_consider: The number of days back to consider in interval calculation
  • check_interval: The interval in seconds to check for a new prices and for interval recalculation
  • stop_loss_percent: The percent from the price to trigger a stop loss
  • quantity_limit: The maximum quantity of the instrument to have in the portfolio

Strategies

Interval strategy

Main 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.

Get accounts tool

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

Backtest

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

Stats displaying

Use this command to display stats:

make display_stats

It will display the list of executed trades

tinkoff-trading-bot's People

Contributors

qwertyo1 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.