Tinkoff Invest Python SDK

repository·main·Indexed 43 days ago

https://github.com/tinkoff/invest-python

A Python client library (tinkoff-investments v0.2.0-beta59) for the Tinkoff Invest API. It enables developers to manage trading accounts, execute orders, and access market data such as candles and real-time streams. The SDK supports both synchronous and asynchronous clients, as well as Production and Sandbox environments for testing trading hypotheses.

Tokens
6.1K
Snippets
38
Records
39
Agent score
56%

What's inside Tinkoff Invest

  1. Switch between Production and Sandbox environments

    main

    The Tinkoff Invest API provides two environments:

    • Production (INVEST_GRPC_API): For executing real orders on the exchange.
    • Sandbox (INVEST_GRPC_API_SANDBOX): For testing API calls and trading hypotheses in an emulator without real market impact.

    To switch environments, pass the desired constant to the target parameter when initializing the Client.

    from tinkoff.invest import Client
    from tinkoff.invest.constants import INVEST_GRPC_API
    
    TOKEN = 'token'
    
    # Using INVEST_GRPC_API for production or INVEST_GRPC_API_SANDBOX for sandbox
    with Client(TOKEN, target=INVEST_GRPC_API) as client:
        print(client.users.get_accounts())
  2. Explore ready-made trading robots

    main

    Several community projects implement trading robots using the Tinkoff Invest API. These examples cover various strategies and technical implementations:

    • Volume Analysis Robot: Implements market profile methods, specifically reacting to maximum horizontal intraday volume. Includes mathematical modeling and algorithm visualization. Repository
    • Simple Interval Strategy Bot: A beginner-friendly bot implementing an interval-based strategy with SQLite for statistics tracking. Repository
    • investRobot: An algorithmic trading robot demonstrating a strategy based on the two moving averages indicator. Repository
    • Intraday Trading Bot with Telegram: An intraday bot for the Moscow Exchange that supports optional Telegram notifications for trades and results; otherwise, it logs to a file. Repository
  3. Set up the INVEST_TOKEN environment variable

    main

    Before running any examples or using the library, you must add your Tinkoff Invest API token to your environment variables. This allows the client to authenticate your requests.

    Set the INVEST_TOKEN variable in your terminal session:

    $ export INVEST_TOKEN=YOUR_TOKEN