Main goal is download and keep market data for internal purposes, such as manual analyze, historical backtesting trade_backtesting project), ML purposes etc.
The tool is using Tinkoff Invest Python gRPC client api and collecting data from MOEX Exchange.
Please note:
-
The tool is downloading market data via market stream in real-time. Note: You have to keep it running to have whole trade day information.
-
The tool workflow is "run and forgot". The tool reads trade schedule:
- runs and stops data collection by schedule without manual handle it
- handles holiday, weekends, also sleep between trade days etc.
- Downloading the following information from MOEX Exchange:
- Candle
- Trades (executed orders)
- Last price (price in time)
- Saving this data in csv files
- Working as service. Just run it and forget.
$ pip install tinkoff-investments
Open brokerage account Тинькофф Инвестиции.
Do not forget to take TOKEN for API trading.
- Open
settings.ini
file - Specify token for trade API in
TOKEN
(sectionINVEST_API
)
Recommendation is to use python 3.10.
Run main.py
Configuration can be specified via settings.ini file.
Specify MAX_SEC_API_SILENCE
max delay between check for api hung.
Specify DELAY_BETWEEN_API_ERRORS_SEC
max delay between retry runs if api has been failed.
Specify TOKEN
and APP_NAME
for Тинькофф Инвестиции api.
Specify what kind of data the tool will collect:
- 1 - True
- 0 - False
Specify stocks via figi.
Syntax: ticker_name=figi
Specify name of storage (class with storage logic).
TYPE=FILES_CSV
by default, but you are able to add your own. (see below)
Section for storage settings. You will have to add your own, if you add your own storage class.
- Write a new class with storage logic
- The new class must have IStorage as super class
- Give a name for the new class
- Extend StorageFactory 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
STORAGE
section andTYPE
field - Put new settings into
STORAGE_SETTINGS
section
- Put the new class name in
By default, root path is specified in STORAGE_SETTINGS
section and ROOT_PATH
field.
Folders structure: ROOT_PATH
/{figi}/{data_type_folder}/{year}/{month}/{day}/market_data.csv
{data_type_folder} can be:
- "candle" (for candles)
- "trade" (for executed orders)
- "last_price" (for last price information)
Headers in candles csv file: open, close, high, low, volume, time
Headers in trades csv file: direction, price, quantity, time
Direction: 1 - Buy, 2 - sell
Headers in last_prices csv file: price, time
- Download market data using tinkoff_market_data_collector project
- Research data and find an idea for trade strategy using analyze_market_data project
- Test and tune your trade strategy using trade_backtesting project
- Trade by invest-bot and your own strategy.
- Profit!
Your can find example in code:
- Let's imagine your have great idea to invent your own idicator. Rsi idicator was selected for example.
- RSI Calculation alghoritm has been written for research tool
- It has been tested by backtesting
- And now you are able to make your desicion.
All logs are written in logs/collector.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 tool.