Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Trading bot based on Tinkoff Invest gRPC API

License

NotificationsYou must be signed in to change notification settings

EIDiamond/invest-bot

Repository files navigation

Project Status

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.

Description

Here is trading bot for MOEX Exchange with ability to send information about trading to a telegram chat.The bot is usingTinkoff Invest Python gRPC client api.

Features

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

Before Start

Dependencies

$ pip install tinkoff-investments
$ pip install -U aiogram

Brokerage account

Open brokerage accountТинькофф Инвестиции and top up your account:

  1. "Margin trading" must be enabled

Do not forget to take TOKEN for API trading.

Telegram (optional)

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.

Required configuration (minimal)

  1. Opensettings.ini file
  2. Specify token for trade API inTOKEN (sectionINVEST_API)
  3. (Optinal) Specify token for a telegram bot inTELEGRAM_BOT_TOKEN (sectionBLOG)
  4. (Optinal) Specify id of a telegram chat inTELEGRAM_CHAT_ID (sectionBLOG)

Run

Recommendation is to use python 3.10 (bot has been tested on 3.10 version include real trading).

Run main.py

Configuration

Configuration can be specified via settings.ini file.

Section INVEST_API

Token and app name forТинькофф Инвестиции api.

Section BLOG

  • status - telegram working mode:
    • 0 - disabled
    • 1 - enabled
  • token and chat id for telegram api

Section TRADING_ACCOUNT

Minimal amount of rub on account for start trading.

Section TRADING_SETTINGS

Settings for time management. Bot trades only in main trade session. Bot ignore pre\post market etc.

Section Strategies

Settings for trade strategies.

Section STRATEGY_ticker_name:

  • STRATEGY_NAME - name of algorithm
  • TICKER - ticker name (human-friendly name for telegram messages)
  • FIGI - figi of stock. Required for API
  • MAX_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.

Trading on stocks exchange

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.

How to add a new strategy

  • 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 inSTRATEGY_NAME
  • Test the new class on historical candles

Telegram messages

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.

Logging

All logs are written in logs/robot.log.Any kind of settings can be changed in main.py code

Project change log

Here

Disclaimer

The author is not responsible for any errors or omissions, or for the trade results obtained from the use of this bot.

About

Trading bot based on Tinkoff Invest gRPC API

Topics

Resources

License

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp