RAPTOR v18.4: Исправлена отчетность, активированы выходные
This commit is contained in:
166
invest-python-master/.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
Normal file
166
invest-python-master/.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
Normal file
@@ -0,0 +1,166 @@
|
||||
name: Bug Report
|
||||
description: Сообщить об ошибке
|
||||
title: '[Bug] Title'
|
||||
labels:
|
||||
- bug
|
||||
assignees:
|
||||
- daxartio
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: 'Спасибо, что нашли время заполнить этот отчет об ошибке!
|
||||
|
||||
'
|
||||
- type: textarea
|
||||
id: what-happened
|
||||
attributes:
|
||||
label: Что случилось?
|
||||
description: Краткое описание.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: to-reproduce
|
||||
attributes:
|
||||
label: Воспроизведение
|
||||
description: Код повторяющий кейс
|
||||
render: Python
|
||||
validations:
|
||||
required: false
|
||||
- type: dropdown
|
||||
id: package-version
|
||||
attributes:
|
||||
label: T-Tech Invest Version
|
||||
description: Какая версия библиотеки используется?
|
||||
options:
|
||||
- 0.3.5
|
||||
- 0.3.4
|
||||
- 0.3.3
|
||||
- 0.3.2
|
||||
- 0.3.1
|
||||
- 0.2.0-beta118
|
||||
- 0.2.0-beta117
|
||||
- 0.2.0-beta116
|
||||
- 0.2.0-beta115
|
||||
- 0.2.0-beta114
|
||||
- 0.2.0-beta113
|
||||
- 0.2.0-beta112
|
||||
- 0.2.0-beta111
|
||||
- 0.2.0-beta110
|
||||
- 0.2.0-beta109
|
||||
- 0.2.0-beta108
|
||||
- 0.2.0-beta107
|
||||
- 0.2.0-beta106
|
||||
- 0.2.0-beta105
|
||||
- 0.2.0-beta104
|
||||
- 0.2.0-beta103
|
||||
- 0.2.0-beta101
|
||||
- 0.2.0-beta100
|
||||
- 0.2.0-beta99
|
||||
- 0.2.0-beta98
|
||||
- 0.2.0-beta97
|
||||
- 0.2.0-beta96
|
||||
- 0.2.0-beta95
|
||||
- 0.2.0-beta94
|
||||
- 0.2.0-beta93
|
||||
- 0.2.0-beta92
|
||||
- 0.2.0-beta91
|
||||
- 0.2.0-beta90
|
||||
- 0.2.0-beta89
|
||||
- 0.2.0-beta88
|
||||
- 0.2.0-beta87
|
||||
- 0.2.0-beta86
|
||||
- 0.2.0-beta85
|
||||
- 0.2.0-beta84
|
||||
- 0.2.0-beta83
|
||||
- 0.2.0-beta82
|
||||
- 0.2.0-beta81
|
||||
- 0.2.0-beta80
|
||||
- 0.2.0-beta79
|
||||
- 0.2.0-beta78
|
||||
- 0.2.0-beta77
|
||||
- 0.2.0-beta76
|
||||
- 0.2.0-beta75
|
||||
- 0.2.0-beta74
|
||||
- 0.2.0-beta73
|
||||
- 0.2.0-beta72
|
||||
- 0.2.0-beta71
|
||||
- 0.2.0-beta70
|
||||
- 0.2.0-beta69
|
||||
- 0.2.0-beta68
|
||||
- 0.2.0-beta67
|
||||
- 0.2.0-beta66
|
||||
- 0.2.0-beta65
|
||||
- 0.2.0-beta64
|
||||
- 0.2.0-beta63
|
||||
- 0.2.0-beta62
|
||||
- 0.2.0-beta61
|
||||
- 0.2.0-beta60
|
||||
- 0.2.0-beta59
|
||||
- 0.2.0-beta58
|
||||
- 0.2.0-beta57
|
||||
- 0.2.0-beta56
|
||||
- 0.2.0-beta55
|
||||
- 0.2.0-beta54
|
||||
- 0.2.0-beta53
|
||||
- 0.2.0-beta52
|
||||
- 0.2.0-beta51
|
||||
- 0.2.0-beta50
|
||||
- 0.2.0-beta49
|
||||
- 0.2.0-beta48
|
||||
- 0.2.0-beta47
|
||||
- 0.2.0-beta46
|
||||
- 0.2.0-beta45
|
||||
- 0.2.0-beta44
|
||||
- 0.2.0-beta43
|
||||
- 0.2.0-beta42
|
||||
- 0.2.0-beta41
|
||||
- 0.2.0-beta40
|
||||
- 0.2.0-beta39
|
||||
- 0.2.0-beta38
|
||||
- 0.2.0-beta37
|
||||
- 0.2.0-beta36
|
||||
- 0.2.0-beta35
|
||||
- 0.2.0-beta34
|
||||
- 0.2.0-beta33
|
||||
- 0.2.0-beta32
|
||||
- 0.2.0-beta31
|
||||
- 0.2.0-beta30
|
||||
- 0.2.0-beta29
|
||||
- 0.2.0-beta28
|
||||
- 0.2.0-beta27
|
||||
- Другая
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: python-version
|
||||
attributes:
|
||||
label: Python Version
|
||||
description: Какая версия Python-а используется?
|
||||
options:
|
||||
- '3.11'
|
||||
- '3.10'
|
||||
- '3.9'
|
||||
- '3.8'
|
||||
- Другая
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: os
|
||||
attributes:
|
||||
label: OS
|
||||
description: Ваша операционная система.
|
||||
options:
|
||||
- Windows
|
||||
- Linux
|
||||
- Mac OS
|
||||
- Mac OS (m1)
|
||||
- Другая
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: logs
|
||||
attributes:
|
||||
label: Логи
|
||||
description: Скопируйте и вставьте сюда логи. Не забудьте скрыть чувствительные
|
||||
данные.
|
||||
render: Shell
|
||||
25
invest-python-master/.github/ISSUE_TEMPLATE/feature_request.yaml
vendored
Normal file
25
invest-python-master/.github/ISSUE_TEMPLATE/feature_request.yaml
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
name: Feature request
|
||||
description: Предложите идею для этого проекта
|
||||
title: "[Feature] Title"
|
||||
labels: ["enhancement"]
|
||||
body:
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: Описание
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: to-resolve
|
||||
attributes:
|
||||
label: Желаемое решение
|
||||
description: Что нужно сделать?
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: additional
|
||||
attributes:
|
||||
label: Дополнительно
|
||||
description: Фрагменты кода, описание апи, ...
|
||||
validations:
|
||||
required: false
|
||||
156
invest-python-master/.github/ISSUE_TEMPLATE/issue.yaml
vendored
Normal file
156
invest-python-master/.github/ISSUE_TEMPLATE/issue.yaml
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
name: Custom Issue
|
||||
description: Проблемы, вопросы, ...
|
||||
body:
|
||||
- type: textarea
|
||||
id: what-happened
|
||||
attributes:
|
||||
label: Что случилось?
|
||||
description: Краткое описание.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: to-reproduce
|
||||
attributes:
|
||||
label: Воспроизведение
|
||||
description: Код повторяющий кейс
|
||||
render: Python
|
||||
validations:
|
||||
required: false
|
||||
- type: dropdown
|
||||
id: package-version
|
||||
attributes:
|
||||
label: T-Tech Invest Version
|
||||
description: Какая версия библиотеки используется?
|
||||
options:
|
||||
- 0.3.5
|
||||
- 0.3.4
|
||||
- 0.3.3
|
||||
- 0.3.2
|
||||
- 0.3.1
|
||||
- 0.2.0-beta118
|
||||
- 0.2.0-beta117
|
||||
- 0.2.0-beta116
|
||||
- 0.2.0-beta115
|
||||
- 0.2.0-beta114
|
||||
- 0.2.0-beta113
|
||||
- 0.2.0-beta112
|
||||
- 0.2.0-beta111
|
||||
- 0.2.0-beta110
|
||||
- 0.2.0-beta109
|
||||
- 0.2.0-beta108
|
||||
- 0.2.0-beta107
|
||||
- 0.2.0-beta106
|
||||
- 0.2.0-beta105
|
||||
- 0.2.0-beta104
|
||||
- 0.2.0-beta103
|
||||
- 0.2.0-beta101
|
||||
- 0.2.0-beta100
|
||||
- 0.2.0-beta99
|
||||
- 0.2.0-beta98
|
||||
- 0.2.0-beta97
|
||||
- 0.2.0-beta96
|
||||
- 0.2.0-beta95
|
||||
- 0.2.0-beta94
|
||||
- 0.2.0-beta93
|
||||
- 0.2.0-beta92
|
||||
- 0.2.0-beta91
|
||||
- 0.2.0-beta90
|
||||
- 0.2.0-beta89
|
||||
- 0.2.0-beta88
|
||||
- 0.2.0-beta87
|
||||
- 0.2.0-beta86
|
||||
- 0.2.0-beta85
|
||||
- 0.2.0-beta84
|
||||
- 0.2.0-beta83
|
||||
- 0.2.0-beta82
|
||||
- 0.2.0-beta81
|
||||
- 0.2.0-beta80
|
||||
- 0.2.0-beta79
|
||||
- 0.2.0-beta78
|
||||
- 0.2.0-beta77
|
||||
- 0.2.0-beta76
|
||||
- 0.2.0-beta75
|
||||
- 0.2.0-beta74
|
||||
- 0.2.0-beta73
|
||||
- 0.2.0-beta72
|
||||
- 0.2.0-beta71
|
||||
- 0.2.0-beta70
|
||||
- 0.2.0-beta69
|
||||
- 0.2.0-beta68
|
||||
- 0.2.0-beta67
|
||||
- 0.2.0-beta66
|
||||
- 0.2.0-beta65
|
||||
- 0.2.0-beta64
|
||||
- 0.2.0-beta63
|
||||
- 0.2.0-beta62
|
||||
- 0.2.0-beta61
|
||||
- 0.2.0-beta60
|
||||
- 0.2.0-beta59
|
||||
- 0.2.0-beta58
|
||||
- 0.2.0-beta57
|
||||
- 0.2.0-beta56
|
||||
- 0.2.0-beta55
|
||||
- 0.2.0-beta54
|
||||
- 0.2.0-beta53
|
||||
- 0.2.0-beta52
|
||||
- 0.2.0-beta51
|
||||
- 0.2.0-beta50
|
||||
- 0.2.0-beta49
|
||||
- 0.2.0-beta48
|
||||
- 0.2.0-beta47
|
||||
- 0.2.0-beta46
|
||||
- 0.2.0-beta45
|
||||
- 0.2.0-beta44
|
||||
- 0.2.0-beta43
|
||||
- 0.2.0-beta42
|
||||
- 0.2.0-beta41
|
||||
- 0.2.0-beta40
|
||||
- 0.2.0-beta39
|
||||
- 0.2.0-beta38
|
||||
- 0.2.0-beta37
|
||||
- 0.2.0-beta36
|
||||
- 0.2.0-beta35
|
||||
- 0.2.0-beta34
|
||||
- 0.2.0-beta33
|
||||
- 0.2.0-beta32
|
||||
- 0.2.0-beta31
|
||||
- 0.2.0-beta30
|
||||
- 0.2.0-beta29
|
||||
- 0.2.0-beta28
|
||||
- 0.2.0-beta27
|
||||
- Другая
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: python-version
|
||||
attributes:
|
||||
label: Python Version
|
||||
description: Какая версия Python-а используется?
|
||||
options:
|
||||
- '3.11'
|
||||
- '3.10'
|
||||
- '3.9'
|
||||
- '3.8'
|
||||
- Другая
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: os
|
||||
attributes:
|
||||
label: OS
|
||||
description: Ваша операционная система.
|
||||
options:
|
||||
- Windows
|
||||
- Linux
|
||||
- Mac OS
|
||||
- Mac OS (m1)
|
||||
- Другая
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: logs
|
||||
attributes:
|
||||
label: Логи
|
||||
description: Скопируйте и вставьте сюда логи. Не забудьте скрыть чувствительные
|
||||
данные.
|
||||
render: Shell
|
||||
3
invest-python-master/.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
3
invest-python-master/.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
<!-- Опишите ваши изменения. Это ускорит процесс review. -->
|
||||
|
||||
<!-- Убедитесь, что прочитали файл https://github.com/RussianInvestments/invest-python/blob/main/CONTRIBUTING.md -->
|
||||
35
invest-python-master/.github/workflows/bumpversion.yml
vendored
Normal file
35
invest-python-master/.github/workflows/bumpversion.yml
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
name: Bump version
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- "tinkoff/**"
|
||||
- "!tinkoff/invest/__init__.py"
|
||||
- "!tinkoff/invest/constants.py"
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.BOT_ACCESS_TOKEN }}
|
||||
|
||||
- name: Git user
|
||||
run: |
|
||||
git config --local user.name 'github-actions[bot]'
|
||||
git config --local user.email 'github-actions[bot]@users.noreply.github.com'
|
||||
|
||||
- name: Install python dependencies
|
||||
run: make install-poetry install-bump
|
||||
|
||||
- name: Bump version
|
||||
run: make bump-version v=$(make next-version)
|
||||
|
||||
- name: Push
|
||||
run: |
|
||||
git push
|
||||
git push --tags
|
||||
49
invest-python-master/.github/workflows/check.yml
vendored
Normal file
49
invest-python-master/.github/workflows/check.yml
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
name: CI Tests/Lints
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build-ubuntu:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.8'
|
||||
|
||||
- name: Install python dependencies
|
||||
run: make install-poetry install
|
||||
|
||||
- name: Run linters
|
||||
run: make lint
|
||||
|
||||
- name: Test docs
|
||||
run: make docs
|
||||
|
||||
- name: Run test
|
||||
run: make test
|
||||
env:
|
||||
INVEST_SANDBOX_TOKEN: ${{ secrets.INVEST_SANDBOX_TOKEN }}
|
||||
INVEST_TOKEN: ${{ secrets.INVEST_TOKEN }}
|
||||
|
||||
build-windows:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Install make
|
||||
run: choco install make
|
||||
|
||||
- name: Install python dependencies
|
||||
run: make install-poetry install
|
||||
|
||||
- name: Run test
|
||||
run: make test
|
||||
env:
|
||||
INVEST_SANDBOX_TOKEN: ${{ secrets.INVEST_SANDBOX_TOKEN }}
|
||||
16
invest-python-master/.github/workflows/check_pr_title.yml
vendored
Normal file
16
invest-python-master/.github/workflows/check_pr_title.yml
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
name: Check PR title
|
||||
on:
|
||||
pull_request_target:
|
||||
types:
|
||||
- opened
|
||||
- reopened
|
||||
- edited
|
||||
- synchronize
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: aslafy-z/conventional-pr-title-action@v3
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
24
invest-python-master/.github/workflows/github_pages.yml
vendored
Normal file
24
invest-python-master/.github/workflows/github_pages.yml
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
name: Github pages
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Install python dependencies
|
||||
run: make install-poetry install-docs
|
||||
|
||||
- name: Generate docs
|
||||
run: make docs
|
||||
|
||||
- name: Deploy pages
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./site
|
||||
25
invest-python-master/.github/workflows/pypi.yml
vendored
Normal file
25
invest-python-master/.github/workflows/pypi.yml
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
name: Publish to PYPI
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
release:
|
||||
types:
|
||||
- created
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Install poetry
|
||||
run: make install-poetry
|
||||
|
||||
- name: Publish package to pypi
|
||||
run: make publish
|
||||
env:
|
||||
pypi_username: ${{ secrets.PYPI_USERNAME }}
|
||||
pypi_password: ${{ secrets.PYPI_PASSWORD }}
|
||||
149
invest-python-master/.gitignore
vendored
Normal file
149
invest-python-master/.gitignore
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
# For a library or package, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# .python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv*
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
tests/pytest.ini
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
.env
|
||||
|
||||
docs/README.md
|
||||
docs/CHANGELOG.md
|
||||
docs/CONTRIBUTING.md
|
||||
|
||||
.idea
|
||||
.market_data_cache
|
||||
.DS_Store
|
||||
7
invest-python-master/BREAKING_CHANGES.md
Normal file
7
invest-python-master/BREAKING_CHANGES.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Breaking changes
|
||||
## 0.3.0
|
||||
- Package naming changed to `t_tech` with all corresponding subpackages
|
||||
## 0.2.0-beta60
|
||||
- `MarketDataCache` was moved to [t_tech/invest/caching/market_data_cache/cache.py](t_tech/invest/caching/market_data_cache/cache.py).
|
||||
- The correct import is now `from t_tech.invest.caching.market_data_cache.cache import MarketDataCache` instead of `from t_tech.invest.services import MarketDataCache`.
|
||||
- Import in [download_all_candles.py](examples/download_all_candles.py) was also corrected.
|
||||
3
invest-python-master/CHANGELOG.md
Normal file
3
invest-python-master/CHANGELOG.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Changelog
|
||||
|
||||
You can see [the commits](https://github.com/RussianInvestments/invest-python/commits/main)
|
||||
143
invest-python-master/CONTRIBUTING.md
Normal file
143
invest-python-master/CONTRIBUTING.md
Normal file
@@ -0,0 +1,143 @@
|
||||
# Contributing
|
||||
|
||||
Спасибо за участие в проекте T-Invest!
|
||||
|
||||
## Быстрый старт
|
||||
|
||||
1. Сделайте [fork](https://opensource.tbank.ru/invest/invest-python/-/forks/new) проекта
|
||||
2. Склонируйте репозиторий на свой локальный компьютер
|
||||
```bash
|
||||
git clone https://opensource.tbank.ru/<username>/invest-python.git
|
||||
```
|
||||
> Вы должны использовать свой username вместо `username`
|
||||
3. Создайте новую ветку для ваших изменений
|
||||
```bash
|
||||
git checkout -b branch_name
|
||||
```
|
||||
4. Добавьте изменения и выполните команды на локальной машине (см. ниже)
|
||||
1. Установите зависимости
|
||||
2. Проверьте свой код с помощью тестов и линтеров
|
||||
5. Создайте коммит своих изменений. Формат описан ниже
|
||||
```bash
|
||||
git add .
|
||||
git commit -m "feat: add new feature"
|
||||
```
|
||||
6. Отправьте свои изменения на github
|
||||
```bash
|
||||
git push
|
||||
```
|
||||
7. Создайте Pull Request в этот репозиторий
|
||||
|
||||
## Commit Message Format
|
||||
|
||||
Мы придерживаемся соглашений [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) для наименование коммитов.
|
||||
|
||||
> A specification for adding human and machine readable meaning to commit messages.
|
||||
|
||||
Body и Footer можно указать по желанию.
|
||||
|
||||
### Commit Message Header
|
||||
|
||||
```
|
||||
<type>(<scope>): <short summary>
|
||||
│ │ │
|
||||
│ │ └─⫸ Summary in present tense. Not capitalized. No period at the end.
|
||||
│ │
|
||||
│ └─⫸ Commit Scope: grpc, async, mypy, schemas, sandbox
|
||||
│
|
||||
└─⫸ Commit Type: feat|fix|build|ci|docs|perf|refactor|test|chore
|
||||
```
|
||||
|
||||
#### Type
|
||||
|
||||
| feat | Features | A new feature |
|
||||
|----------|--------------------------|--------------------------------------------------------------------------------------------------------|
|
||||
| fix | Bug Fixes | A bug fix |
|
||||
| docs | Documentation | Documentation only changes |
|
||||
| style | Styles | Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc) |
|
||||
| refactor | Code Refactoring | A code change that neither fixes a bug nor adds a feature |
|
||||
| perf | Performance Improvements | A code change that improves performance |
|
||||
| test | Tests | Adding missing tests or correcting existing tests |
|
||||
| build | Builds | Changes that affect the build system or external dependencies (example scopes: mypy, pip, pytest) |
|
||||
| ci | Continuous Integrations | Changes to our CI configuration files and scripts (example scopes: Github Actions) |
|
||||
| chore | Chores | Other changes that don't modify src or test files |
|
||||
| revert | Reverts | Reverts a previous commit |
|
||||
|
||||
## Выполнение команд на локальной машине
|
||||
|
||||
Для работы с проектом рекомендуем использовать [poetry](https://pypi.org/project/poetry/).
|
||||
|
||||
Также рекомендуем использовать таск раннер make. Все команды описаны в Makefile. Вы можете их скопировать и запускать напрямую.
|
||||
|
||||
## Установка зависимостей
|
||||
|
||||
```
|
||||
make install-poetry
|
||||
make install
|
||||
```
|
||||
|
||||
### Виртуальное окружение
|
||||
|
||||
По умолчанию, poetry создает виртуальное окружение в директории `~/.cache/pypoetry/virtualenvs/`. Чтобы создавать виртуальное окружение в директории проекта, выполните команду:
|
||||
|
||||
```
|
||||
poetry config virtualenvs.in-project true
|
||||
```
|
||||
|
||||
Вы можете сами создать виртуальное окружение в директории проекта:
|
||||
|
||||
```
|
||||
python -m venv .venv
|
||||
```
|
||||
|
||||
poetry будет использовать его.
|
||||
|
||||
### Запуск тестов
|
||||
|
||||
```
|
||||
make test
|
||||
```
|
||||
|
||||
### Запуск линтеров
|
||||
|
||||
```
|
||||
make lint
|
||||
```
|
||||
|
||||
### Запуск автоформатирования
|
||||
|
||||
```
|
||||
make format
|
||||
```
|
||||
|
||||
### Загрузка proto файлов
|
||||
|
||||
```
|
||||
make download-protos
|
||||
```
|
||||
|
||||
По дефолту загружает из ветки `main`.
|
||||
|
||||
### Генерация клиента
|
||||
|
||||
```
|
||||
make gen-grpc
|
||||
```
|
||||
|
||||
Затем, добавить изменения в модули:
|
||||
- t_tech/invest/\_\_init__.py
|
||||
- t_tech/invest/async_services.py
|
||||
- t_tech/invest/schemas.py
|
||||
- t_tech/invest/services.py
|
||||
|
||||
### Загрузка proto файлов и генерация клиента
|
||||
|
||||
Можно упростить все до одной команды.
|
||||
|
||||
```
|
||||
make gen-client
|
||||
```
|
||||
|
||||
### Release новой версии
|
||||
|
||||
Релиз новой версии происходит автоматически после слияния изменений в main ветку.
|
||||
202
invest-python-master/LICENSE
Normal file
202
invest-python-master/LICENSE
Normal file
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2023 Tinkoff
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
106
invest-python-master/Makefile
Normal file
106
invest-python-master/Makefile
Normal file
@@ -0,0 +1,106 @@
|
||||
PYTHONPATH = PYTHONPATH=./
|
||||
POETRY_RUN = poetry run
|
||||
|
||||
PROTO_DIR = protos/t_tech/invest/grpc
|
||||
PACKAGE_PROTO_DIR = t_tech/invest/grpc
|
||||
OUT = .
|
||||
PROTOS = protos
|
||||
|
||||
TEST = $(POETRY_RUN) pytest $(args)
|
||||
MAIN_CODE = t_tech examples scripts
|
||||
CODE = tests $(MAIN_CODE)
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
$(TEST) --cov
|
||||
|
||||
.PHONY: test-fast
|
||||
test-fast:
|
||||
$(TEST)
|
||||
|
||||
.PHONY: test-sandbox
|
||||
test-sandbox:
|
||||
$(TEST) --test-sandbox --cov
|
||||
|
||||
.PHONY: lint
|
||||
lint:
|
||||
$(POETRY_RUN) ruff $(CODE)
|
||||
$(POETRY_RUN) black --check $(CODE)
|
||||
$(POETRY_RUN) pytest --dead-fixtures --dup-fixtures
|
||||
$(POETRY_RUN) mypy $(MAIN_CODE)
|
||||
$(POETRY_RUN) poetry check
|
||||
|
||||
.PHONY: format
|
||||
format:
|
||||
$(POETRY_RUN) isort $(CODE)
|
||||
$(POETRY_RUN) black $(CODE)
|
||||
$(POETRY_RUN) ruff --fix $(CODE)
|
||||
|
||||
.PHONY: check
|
||||
check: lint test
|
||||
|
||||
.PHONY: docs
|
||||
docs:
|
||||
mkdir -p ./docs
|
||||
cp README.md ./docs/
|
||||
cp CHANGELOG.md ./docs/
|
||||
cp CONTRIBUTING.md ./docs/
|
||||
$(POETRY_RUN) mkdocs build -s -v
|
||||
|
||||
.PHONY: docs-serve
|
||||
docs-serve:
|
||||
$(POETRY_RUN) mkdocs serve
|
||||
|
||||
.PHONY: next-version
|
||||
next-version:
|
||||
@$(POETRY_RUN) python -m scripts.version
|
||||
|
||||
.PHONY: bump-version
|
||||
bump-version:
|
||||
poetry version $(v)
|
||||
$(POETRY_RUN) python -m scripts.update_package_version $(v)
|
||||
$(POETRY_RUN) python -m scripts.update_issue_templates $(v)
|
||||
git add . && git commit -m "chore(release): bump version to $(v)"
|
||||
git tag -a $(v) -m ""
|
||||
|
||||
.PHONY: install-poetry
|
||||
install-poetry:
|
||||
pip install poetry==2.3.2
|
||||
|
||||
.PHONY: install-docs
|
||||
install-docs:
|
||||
poetry install --only docs
|
||||
|
||||
.PHONY: install-bump
|
||||
install-bump:
|
||||
poetry install --only bump
|
||||
|
||||
.PHONY: install
|
||||
install:
|
||||
poetry install -E all
|
||||
|
||||
.PHONY: publish
|
||||
publish:
|
||||
@poetry publish --build --no-interaction --username=$(pypi_username) --password=$(pypi_password)
|
||||
|
||||
.PHONY: publish-opensource
|
||||
publish-opensource:
|
||||
@poetry publish --build --no-interaction -r opensource --username=$(pypi_username) --password=$(pypi_password)
|
||||
|
||||
.PHONY: config-opensource
|
||||
config-opensource:
|
||||
@poetry config repositories.opensource https://opensource.tbank.ru/api/v4/projects/238/packages/pypi
|
||||
|
||||
.PHONY: download-protos
|
||||
download-protos:
|
||||
$(POETRY_RUN) python -m scripts.download_protos
|
||||
|
||||
.PHONY: gen-grpc
|
||||
gen-grpc:
|
||||
rm -r ${PACKAGE_PROTO_DIR}
|
||||
$(POETRY_RUN) python -m grpc_tools.protoc -I${PROTOS} --python_out=${OUT} --mypy_out=${OUT} --grpc_python_out=${OUT} ${PROTO_DIR}/google/api/*.proto
|
||||
$(POETRY_RUN) python -m grpc_tools.protoc -I${PROTOS} --python_out=${OUT} --mypy_out=${OUT} --grpc_python_out=${OUT} ${PROTO_DIR}/*.proto
|
||||
touch ${PACKAGE_PROTO_DIR}/__init__.py
|
||||
|
||||
.PHONY: gen-client
|
||||
gen-client: download-protos gen-grpc
|
||||
84
invest-python-master/README.md
Normal file
84
invest-python-master/README.md
Normal file
@@ -0,0 +1,84 @@
|
||||
# T-Invest
|
||||
|
||||
[](https://opensource.tbank.ru/invest/invest-python/-/packages)
|
||||
[](https://www.python.org/downloads/)
|
||||
[](https://opensource.tbank.ru/invest/invest-python/-/blob/master/LICENSE)
|
||||
|
||||
[//]: # ()
|
||||
|
||||
Данный репозиторий предоставляет клиент для взаимодействия с торговой платформой
|
||||
[Т-Инвестиции](https://www.tbank.ru/invest/) на языке Python.
|
||||
|
||||
Проект является продуктом независимой разработки и не связан с какими-либо компаниями. Библиотека распространяется
|
||||
свободно и не является коммерческим продуктом или официальным выпуском какого-либо стороннего разработчика. Все
|
||||
исходные материалы, архитектура и реализация созданы самостоятельно.
|
||||
|
||||
The project is the result of independent development and is not affiliated with any companies. The library is
|
||||
distributed freely and is not a commercial product or official release of any third-party vendor. All source materials,
|
||||
architecture, and implementation were created independently.
|
||||
|
||||
|
||||
- [Документация](https://opensource.tbank.ru/invest/invest-python/-/blob/master/README.md?ref_type=heads)
|
||||
- [Документация по Invest API](https://developer.tbank.ru/invest/intro/intro)
|
||||
|
||||
## Начало работы
|
||||
|
||||
<!-- terminal -->
|
||||
|
||||
```
|
||||
$ pip install t-tech-investments --index-url https://opensource.tbank.ru/api/v4/projects/238/packages/pypi/simple
|
||||
```
|
||||
|
||||
## Возможности
|
||||
|
||||
- ☑ Синхронный и асинхронный GRPC клиент
|
||||
- ☑ Возможность отменить все заявки
|
||||
- ☑ Выгрузка истории котировок "от" и "до"
|
||||
- ☑ Кеширование данных
|
||||
- ☑ Торговая стратегия
|
||||
|
||||
## Как пользоваться
|
||||
|
||||
### Получить список аккаунтов
|
||||
|
||||
```python
|
||||
from t_tech.invest import Client
|
||||
|
||||
TOKEN = 'token'
|
||||
|
||||
with Client(TOKEN) as client:
|
||||
print(client.users.get_accounts())
|
||||
```
|
||||
|
||||
### Переопределить target
|
||||
|
||||
В T-Invest API есть два контура - "боевой", предназначенный для исполнения ордеров на бирже и "песочница",
|
||||
предназначенный для тестирования API и торговых гипотез, заявки с которого не выводятся на биржу,
|
||||
а исполняются в эмуляторе.
|
||||
|
||||
Переключение между контурами реализовано через target, INVEST_GRPC_API - "боевой", INVEST_GRPC_API_SANDBOX - "песочница"
|
||||
|
||||
```python
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.constants import INVEST_GRPC_API
|
||||
|
||||
TOKEN = 'token'
|
||||
|
||||
with Client(TOKEN, target=INVEST_GRPC_API) as client:
|
||||
print(client.users.get_accounts())
|
||||
```
|
||||
|
||||
> :warning: **Не публикуйте токены в общедоступные репозитории**
|
||||
<br/>
|
||||
|
||||
Остальные примеры доступны в [examples](https://opensource.tbank.ru/invest/invest-python/-/tree/master/examples).
|
||||
|
||||
## Contribution
|
||||
|
||||
Для тех, кто хочет внести свои изменения в проект.
|
||||
|
||||
- [CONTRIBUTING](https://opensource.tbank.ru/invest/invest-python/-/blob/master/CONTRIBUTING.md)
|
||||
|
||||
## License
|
||||
|
||||
Лицензия [The Apache License](https://opensource.tbank.ru/invest/invest-python/-/blob/master/LICENSE).
|
||||
18
invest-python-master/conftest.py
Normal file
18
invest-python-master/conftest.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import pytest
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption(
|
||||
"--test-sandbox",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="Run sandbox tests",
|
||||
)
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(config, items):
|
||||
if not config.getoption("--test-sandbox"):
|
||||
skipper = pytest.mark.skip(reason="Only run when --test-sandbox is given")
|
||||
for item in items:
|
||||
if "test_sandbox" in item.keywords:
|
||||
item.add_marker(skipper)
|
||||
4
invest-python-master/docs/api/clients.md
Normal file
4
invest-python-master/docs/api/clients.md
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
# Clients
|
||||
|
||||
::: t_tech.invest.clients
|
||||
122
invest-python-master/docs/examples.md
Normal file
122
invest-python-master/docs/examples.md
Normal file
@@ -0,0 +1,122 @@
|
||||
Больше примеров доступно [здесь](https://github.com/RussianInvestments/invest-python/tree/main/examples).
|
||||
|
||||
## Получение и вывод в консоль свечей с часовым интервалом за год
|
||||
[examples/all_candles.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/all_candles.py)
|
||||
~~~python
|
||||
{% include "../examples/all_candles.py" %}
|
||||
~~~
|
||||
## Асинхронная функция получения и вывода в консоль свечей с часовым интервалом за год
|
||||
[examples/async_all_candles.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/async_all_candles.py)
|
||||
~~~python
|
||||
{% include "../examples/async_all_candles.py" %}
|
||||
~~~
|
||||
## Асинхронная функция получения и вывода счетов пользователя
|
||||
[examples/async_client.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/async_client.py)
|
||||
~~~python
|
||||
{% include "../examples/async_client.py" %}
|
||||
~~~
|
||||
## Асинхронная функция получения и вывода минутных свечей
|
||||
[examples/async_retrying_client.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/async_retrying_client.py)
|
||||
~~~python
|
||||
{% include "../examples/async_retrying_client.py" %}
|
||||
~~~
|
||||
## Подписка на стрим котировок по минутным свечам и вывод получаемых свечей в консоль
|
||||
[examples/async_stream_client.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/async_stream_client.py)
|
||||
~~~python
|
||||
{% include "../examples/async_stream_client.py" %}
|
||||
~~~
|
||||
## Отмена всех выставленных поручений
|
||||
[examples/cancel_orders.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/cancel_orders.py)
|
||||
~~~python
|
||||
{% include "../examples/cancel_orders.py" %}
|
||||
~~~
|
||||
## Функция получения и вывода счетов клиента
|
||||
[examples/client.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/client.py)
|
||||
~~~python
|
||||
{% include "../examples/client.py" %}
|
||||
~~~
|
||||
## Загрузка и вывод всех минутных свечей по интрументу
|
||||
[examples/download_all_candles.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/download_all_candles.py)
|
||||
~~~python
|
||||
{% include "../examples/download_all_candles.py" %}
|
||||
~~~
|
||||
## Асинхронная подписка на стрим минутных свечей
|
||||
[examples/easy_async_stream_client.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/easy_async_stream_client.py)
|
||||
~~~python
|
||||
{% include "../examples/easy_async_stream_client.py" %}
|
||||
~~~
|
||||
## Простая подписка на стрим минутных свечей
|
||||
[examples/easy_stream_client.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/easy_stream_client.py)
|
||||
~~~python
|
||||
{% include "../examples/easy_stream_client.py" %}
|
||||
~~~
|
||||
## Получение списка операций и их постраничный вывод
|
||||
[examples/get_operations_by_cursor.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/get_operations_by_cursor.py)
|
||||
~~~python
|
||||
{% include "../examples/get_operations_by_cursor.py" %}
|
||||
~~~
|
||||
## Функция кэширования инструментов
|
||||
[examples/instrument_cache.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/instrument_cache.py)
|
||||
~~~python
|
||||
{% include "../examples/instrument_cache.py" %}
|
||||
~~~
|
||||
## Функция получения списка инструментов подходящих под строку query
|
||||
[examples/instruments/instruments.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/instruments/instruments.py)
|
||||
~~~python
|
||||
{% include "../examples/instruments/instruments.py" %}
|
||||
~~~
|
||||
## Функция логгирования ошибок
|
||||
[examples/logger.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/logger.py)
|
||||
~~~python
|
||||
{% include "../examples/logger.py" %}
|
||||
~~~
|
||||
## Подписка на стрим портфолио и вывод информации
|
||||
[examples/porfolio_stream_client.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/porfolio_stream_client.py)
|
||||
~~~python
|
||||
{% include "../examples/porfolio_stream_client.py" %}
|
||||
~~~
|
||||
## Подписка на стрим позиций и вывод информации
|
||||
[examples/positions_stream.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/positions_stream.py)
|
||||
~~~python
|
||||
{% include "../examples/positions_stream.py" %}
|
||||
~~~
|
||||
## Функция получения и вывода минутных свечей
|
||||
[examples/retrying_client.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/retrying_client.py)
|
||||
~~~python
|
||||
{% include "../examples/retrying_client.py" %}
|
||||
~~~
|
||||
## Получение и вывод информации об аккаунте пользователя в песочнице
|
||||
[examples/sandbox_client.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/sandbox_client.py)
|
||||
~~~python
|
||||
{% include "../examples/sandbox_client.py" %}
|
||||
~~~
|
||||
## Подписка на стрим минутных свечей и их вывод
|
||||
[examples/stream_client.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/stream_client.py)
|
||||
~~~python
|
||||
{% include "../examples/stream_client.py" %}
|
||||
~~~
|
||||
## Создание тэйк-профит стоп ордера
|
||||
[examples/wiseplat_create_take_profit_stop_order.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/wiseplat_create_take_profit_stop_order.py)
|
||||
~~~python
|
||||
{% include "../examples/wiseplat_create_take_profit_stop_order.py" %}
|
||||
~~~
|
||||
## Отмена всех выставленных стоп ордеров
|
||||
[examples/wiseplat_cancel_all_stop_orders.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/wiseplat_cancel_all_stop_orders.py)
|
||||
~~~python
|
||||
{% include "../examples/wiseplat_cancel_all_stop_orders.py" %}
|
||||
~~~
|
||||
## Получение figi для тикера
|
||||
[examples/wiseplat_get_figi_for_ticker.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/wiseplat_get_figi_for_ticker.py)
|
||||
~~~python
|
||||
{% include "../examples/wiseplat_get_figi_for_ticker.py" %}
|
||||
~~~
|
||||
## Получение / установка баланса для песочницы. Получение / закрытие всех песочниц. Создание новой песочницы.
|
||||
[examples/wiseplat_set_get_sandbox_balance.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/wiseplat_set_get_sandbox_balance.py)
|
||||
~~~python
|
||||
{% include "../examples/wiseplat_set_get_sandbox_balance.py" %}
|
||||
~~~
|
||||
## Пример live стратегии для нескольких тикеров. Вывод OHLCV для каждой сформировавшейся свечи.
|
||||
[examples/wiseplat_live_strategy_print_ohlcv.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/wiseplat_live_strategy_print_ohlcv.py)
|
||||
~~~python
|
||||
{% include "../examples/wiseplat_live_strategy_print_ohlcv.py" %}
|
||||
~~~
|
||||
16
invest-python-master/docs/robots.md
Normal file
16
invest-python-master/docs/robots.md
Normal file
@@ -0,0 +1,16 @@
|
||||
## Примеры готовых роботов
|
||||
|
||||
| Ссылка на репозиторий | Описание |
|
||||
|------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| [tromario/tinkoff-invest-volume-analysis-robot](https://github.com/tromario/tinkoff-invest-volume-analysis-robot) | Проектом был реализован один из методов работы с профилем рынка - реакция на максимальный горизонтальный объем внутри дня за выбранный период.Основной объем работы был заложен в математический аппарат. Работа имеет визуализацию алгоритма. |
|
||||
| [qwertyo1/tinkoff-trading-bot](https://github.com/qwertyo1/tinkoff-trading-bot) | Проектом реализована простая интервальная стратегия. Несложный код поможет начинающим разработчикам быстро разобраться, запустить, проверить и доработать торговую стратегию под свои цели. Простое ведение статистики через sqllite. |
|
||||
| [karpp/investRobot](https://github.com/karpp/investRobot) | investRobot - это робот для алгоритмической торговли на бирже Тинькофф Инвестиций посредством Tinkoff Invest API. В качестве демонстрации представлена одна торговая стратегия, основанная на индикаторе двух скользящих средних. |
|
||||
| [EIDiamond/invest-bot](https://github.com/EIDiamond/invest-bot) | Робот интрадей торговли на Московской бирже с возможность информирования о сделках и результатах торговли в Telegram чат.Удобное решение опционального включения\выключения информирования в Телеграм. Без подключения Телеграм чата все события и результаты пишутся в лог файл. |
|
||||
|
||||
## Готовые стратегии
|
||||
|
||||
Функция создает дополнительный столбец с действиями ("ma200_support_action"), куда записываются сигналы на шорт или лонг по условиям.
|
||||
Затем данные агрегируются и выводятся в виде списка акций, по которым пришли сигналы, в порядке убывания даты сигнала.
|
||||
~~~python
|
||||
{% include "../examples/strategies/moving_average.py" %}
|
||||
~~~
|
||||
13
invest-python-master/examples/README.md
Normal file
13
invest-python-master/examples/README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
Cначала нужно добавить токен в переменную окружения.
|
||||
|
||||
<!-- termynal -->
|
||||
|
||||
```console
|
||||
$ export INVEST_TOKEN=YOUR_TOKEN
|
||||
```
|
||||
|
||||
А потом можно запускать примеры
|
||||
|
||||
```console
|
||||
$ python examples/client.py
|
||||
```
|
||||
0
invest-python-master/examples/__init__.py
Normal file
0
invest-python-master/examples/__init__.py
Normal file
25
invest-python-master/examples/all_candles.py
Normal file
25
invest-python-master/examples/all_candles.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import os
|
||||
from datetime import timedelta
|
||||
|
||||
from t_tech.invest import CandleInterval, Client
|
||||
from t_tech.invest.schemas import CandleSource
|
||||
from t_tech.invest.utils import now
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
for candle in client.get_all_candles(
|
||||
instrument_id="BBG004730N88",
|
||||
from_=now() - timedelta(days=365),
|
||||
interval=CandleInterval.CANDLE_INTERVAL_HOUR,
|
||||
candle_source_type=CandleSource.CANDLE_SOURCE_UNSPECIFIED,
|
||||
):
|
||||
print(candle)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
24
invest-python-master/examples/async_all_candles.py
Normal file
24
invest-python-master/examples/async_all_candles.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import asyncio
|
||||
import os
|
||||
from datetime import timedelta
|
||||
|
||||
from t_tech.invest import AsyncClient, CandleInterval
|
||||
from t_tech.invest.schemas import CandleSource
|
||||
from t_tech.invest.utils import now
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
async for candle in client.get_all_candles(
|
||||
instrument_id="BBG004730N88",
|
||||
from_=now() - timedelta(days=365),
|
||||
interval=CandleInterval.CANDLE_INTERVAL_HOUR,
|
||||
candle_source_type=CandleSource.CANDLE_SOURCE_EXCHANGE,
|
||||
):
|
||||
print(candle)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
15
invest-python-master/examples/async_client.py
Normal file
15
invest-python-master/examples/async_client.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from t_tech.invest import AsyncClient
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
print(await client.users.get_accounts())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,25 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from t_tech.invest import AsyncClient, CandleInterval
|
||||
from t_tech.invest.utils import now
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
candles = await client.market_data.get_candles(
|
||||
instrument_id="BBG004730N88",
|
||||
to=now(),
|
||||
limit=3,
|
||||
interval=CandleInterval.CANDLE_INTERVAL_HOUR,
|
||||
)
|
||||
for candle in candles.candles:
|
||||
print(candle)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
38
invest-python-master/examples/async_get_insider_deals.py
Normal file
38
invest-python-master/examples/async_get_insider_deals.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""Example - How to get list of insider deals.
|
||||
Request data in loop with batches of 10 records.
|
||||
"""
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
|
||||
from t_tech.invest import AsyncClient
|
||||
from t_tech.invest.schemas import GetInsiderDealsRequest
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
deals = []
|
||||
|
||||
next_cursor = None
|
||||
while True:
|
||||
response = await client.instruments.get_insider_deals(
|
||||
request=GetInsiderDealsRequest(
|
||||
instrument_id="BBG004730N88", limit=10, next_cursor=next_cursor
|
||||
)
|
||||
)
|
||||
deals.extend(response.insider_deals)
|
||||
if not next_cursor:
|
||||
break
|
||||
next_cursor = response.next_cursor
|
||||
print("Insider deals:")
|
||||
for deal in deals:
|
||||
print(deal)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
20
invest-python-master/examples/async_get_last_prices.py
Normal file
20
invest-python-master/examples/async_get_last_prices.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from t_tech.invest import AsyncClient, InstrumentStatus
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
print(
|
||||
await client.market_data.get_last_prices(
|
||||
figi=["BBG004730ZJ9"],
|
||||
instrument_status=InstrumentStatus.INSTRUMENT_STATUS_ALL,
|
||||
)
|
||||
) # pylint:disable=line-too-long
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
28
invest-python-master/examples/async_get_market_values.py
Normal file
28
invest-python-master/examples/async_get_market_values.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from t_tech.invest import AsyncClient
|
||||
from t_tech.invest.schemas import GetMarketValuesRequest, MarketValueType
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
market_values = await client.market_data.get_market_values(
|
||||
request=GetMarketValuesRequest(
|
||||
instrument_id=["BBG004730N88", "64c0da45-4c90-41d4-b053-0c66c7a8ddcd"],
|
||||
values=[
|
||||
MarketValueType.INSTRUMENT_VALUE_LAST_PRICE,
|
||||
MarketValueType.INSTRUMENT_VALUE_CLOSE_PRICE,
|
||||
],
|
||||
)
|
||||
)
|
||||
for instrument in market_values.instruments:
|
||||
print(instrument.instrument_uid)
|
||||
for value in instrument.values:
|
||||
print(value)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
39
invest-python-master/examples/async_get_orders.py
Normal file
39
invest-python-master/examples/async_get_orders.py
Normal file
@@ -0,0 +1,39 @@
|
||||
"""Example - How to get list of orders for 1 last hour (maximum requesting period)."""
|
||||
import asyncio
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
|
||||
from t_tech.invest import AsyncClient
|
||||
from t_tech.invest.schemas import OrderExecutionReportStatus
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
response = await client.users.get_accounts()
|
||||
account, *_ = response.accounts
|
||||
account_id = account.id
|
||||
|
||||
now = datetime.datetime.now()
|
||||
orders = await client.orders.get_orders(
|
||||
account_id=account_id,
|
||||
from_=now - datetime.timedelta(hours=1),
|
||||
to=now,
|
||||
# filter only executed or partially executed orders
|
||||
execution_status=[
|
||||
OrderExecutionReportStatus.EXECUTION_REPORT_STATUS_FILL,
|
||||
OrderExecutionReportStatus.EXECUTION_REPORT_STATUS_PARTIALLYFILL,
|
||||
],
|
||||
)
|
||||
print("Orders list:")
|
||||
for order in orders.orders:
|
||||
print(order)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
22
invest-python-master/examples/async_get_risk_rates.py
Normal file
22
invest-python-master/examples/async_get_risk_rates.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from t_tech.invest import AsyncClient
|
||||
from t_tech.invest.schemas import RiskRatesRequest
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
request = RiskRatesRequest()
|
||||
request.instrument_id = ["BBG001M2SC01", "BBG004730N88"]
|
||||
r = await client.instruments.get_risk_rates(request=request)
|
||||
for i in r.instrument_risk_rates:
|
||||
print(i.instrument_uid)
|
||||
print(i.short_risk_rate)
|
||||
print(i.long_risk_rate)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
22
invest-python-master/examples/async_get_sandbox_max_lots.py
Normal file
22
invest-python-master/examples/async_get_sandbox_max_lots.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from t_tech.invest import GetMaxLotsRequest
|
||||
from t_tech.invest.sandbox.async_client import AsyncSandboxClient
|
||||
from t_tech.invest.sandbox.client import SandboxClient
|
||||
|
||||
TOKEN = os.environ["INVEST_SANDBOX_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncSandboxClient(TOKEN) as client:
|
||||
account_id = (await client.users.get_accounts()).accounts[0].id
|
||||
request = GetMaxLotsRequest(
|
||||
account_id=account_id,
|
||||
instrument_id="BBG004730N88",
|
||||
)
|
||||
print(await client.sandbox.get_sandbox_max_lots(request=request))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
26
invest-python-master/examples/async_get_signals.py
Normal file
26
invest-python-master/examples/async_get_signals.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""Example - How to get Signals"""
|
||||
import asyncio
|
||||
import datetime
|
||||
import os
|
||||
|
||||
from t_tech.invest import AsyncClient
|
||||
from t_tech.invest.schemas import GetSignalsRequest, SignalState
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
request = GetSignalsRequest()
|
||||
request.instrument_uid = "e6123145-9665-43e0-8413-cd61b8aa9b13" # Сбербанк
|
||||
request.active = SignalState.SIGNAL_STATE_ALL # все сигналы
|
||||
request.from_ = datetime.datetime.now() - datetime.timedelta(
|
||||
weeks=4
|
||||
) # сигналы, созданные не больше чем 4 недели назад
|
||||
r = await client.signals.get_signals(request=request)
|
||||
for signal in r.signals:
|
||||
print(signal)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
19
invest-python-master/examples/async_get_strategies.py
Normal file
19
invest-python-master/examples/async_get_strategies.py
Normal file
@@ -0,0 +1,19 @@
|
||||
"""Example - How to get all strategies"""
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from t_tech.invest import AsyncClient
|
||||
from t_tech.invest.schemas import GetStrategiesRequest
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
r = await client.signals.get_strategies(request=GetStrategiesRequest())
|
||||
for strategy in r.strategies:
|
||||
print(strategy)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
41
invest-python-master/examples/async_get_tech_analysis.py
Normal file
41
invest-python-master/examples/async_get_tech_analysis.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import asyncio
|
||||
import os
|
||||
from datetime import timedelta
|
||||
from decimal import Decimal
|
||||
|
||||
from t_tech.invest import AsyncClient
|
||||
from t_tech.invest.schemas import (
|
||||
Deviation,
|
||||
GetTechAnalysisRequest,
|
||||
IndicatorInterval,
|
||||
IndicatorType,
|
||||
Smoothing,
|
||||
TypeOfPrice,
|
||||
)
|
||||
from t_tech.invest.utils import decimal_to_quotation, now
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
request = GetTechAnalysisRequest(
|
||||
indicator_type=IndicatorType.INDICATOR_TYPE_RSI,
|
||||
instrument_uid="6542a064-6633-44ba-902f-710c97507522",
|
||||
from_=now() - timedelta(days=7),
|
||||
to=now(),
|
||||
interval=IndicatorInterval.INDICATOR_INTERVAL_4_HOUR,
|
||||
type_of_price=TypeOfPrice.TYPE_OF_PRICE_AVG,
|
||||
length=42,
|
||||
deviation=Deviation(
|
||||
deviation_multiplier=decimal_to_quotation(Decimal(1.0)),
|
||||
),
|
||||
smoothing=Smoothing(fast_length=13, slow_length=7, signal_smoothing=3),
|
||||
)
|
||||
response = await client.market_data.get_tech_analysis(request=request)
|
||||
for indicator in response.technical_indicators:
|
||||
print(indicator.signal)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
18
invest-python-master/examples/async_get_trading_statuses.py
Normal file
18
invest-python-master/examples/async_get_trading_statuses.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from t_tech.invest import AsyncClient
|
||||
|
||||
token = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(token) as client:
|
||||
statuses = await client.market_data.get_trading_statuses(
|
||||
instrument_ids=["BBG004730N88"]
|
||||
)
|
||||
print(statuses)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
19
invest-python-master/examples/async_indicatives.py
Normal file
19
invest-python-master/examples/async_indicatives.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from t_tech.invest import AsyncClient
|
||||
from t_tech.invest.schemas import IndicativesRequest
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
request = IndicativesRequest()
|
||||
indicatives = await client.instruments.indicatives(request=request)
|
||||
for instrument in indicatives.instruments:
|
||||
print(instrument.name)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
55
invest-python-master/examples/async_instrument_favorites.py
Normal file
55
invest-python-master/examples/async_instrument_favorites.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from t_tech.invest import AsyncClient
|
||||
from t_tech.invest.schemas import (
|
||||
CreateFavoriteGroupRequest,
|
||||
DeleteFavoriteGroupRequest,
|
||||
EditFavoritesActionType as At,
|
||||
EditFavoritesRequestInstrument,
|
||||
GetFavoriteGroupsRequest,
|
||||
)
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
r = await client.instruments.get_favorites()
|
||||
|
||||
print("Список избранных инструментов:")
|
||||
for i in r.favorite_instruments:
|
||||
print(f"{i.ticker} - {i.name}")
|
||||
|
||||
request = CreateFavoriteGroupRequest()
|
||||
request.group_name = "My test favorite group"
|
||||
request.group_color = "aa0000" # red color
|
||||
r = await client.instruments.create_favorite_group(request=request)
|
||||
group_id = r.group_id
|
||||
print(f"Создана новая группа избранного с ИД: {group_id}")
|
||||
|
||||
await client.instruments.edit_favorites(
|
||||
instruments=[EditFavoritesRequestInstrument(instrument_id="BBG001M2SC01")],
|
||||
action_type=At.EDIT_FAVORITES_ACTION_TYPE_ADD,
|
||||
group_id=group_id,
|
||||
)
|
||||
|
||||
request = GetFavoriteGroupsRequest()
|
||||
request.instrument_id = ["BBG001M2SC01"]
|
||||
r = await client.instruments.get_favorite_groups(request=request)
|
||||
print(f"Список групп избранного:")
|
||||
for i in r.groups:
|
||||
print(
|
||||
f"{i.group_id} - {i.group_name}. Количество элементов: {i.size}. "
|
||||
f"Содержит выбранный инструмент {request.instrument_id[0]}: "
|
||||
f"{i.contains_instrument} "
|
||||
)
|
||||
|
||||
request = DeleteFavoriteGroupRequest()
|
||||
request.group_id = group_id
|
||||
await client.instruments.delete_favorite_group(request=request)
|
||||
print(f"Удалена группа избранного с ИД: {group_id}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
27
invest-python-master/examples/async_operations_stream.py
Normal file
27
invest-python-master/examples/async_operations_stream.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from t_tech.invest import AsyncClient
|
||||
from t_tech.invest.schemas import OperationsStreamRequest, PingDelaySettings
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
accounts = await client.users.get_accounts()
|
||||
accounts = [i.id for i in accounts.accounts]
|
||||
print(f"Subscribe for operations on accounts: {accounts}")
|
||||
async for operation in client.operations_stream.operations_stream(
|
||||
OperationsStreamRequest(
|
||||
accounts=accounts,
|
||||
ping_settings=PingDelaySettings(
|
||||
ping_delay_ms=10_000,
|
||||
),
|
||||
)
|
||||
):
|
||||
print(operation)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
19
invest-python-master/examples/async_order_state_stream.py
Normal file
19
invest-python-master/examples/async_order_state_stream.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from t_tech.invest import AsyncClient
|
||||
from t_tech.invest.schemas import OrderStateStreamRequest
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
request = OrderStateStreamRequest()
|
||||
stream = client.orders_stream.order_state_stream(request=request)
|
||||
async for order_state in stream:
|
||||
print(order_state)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
28
invest-python-master/examples/async_post_order_async.py
Normal file
28
invest-python-master/examples/async_post_order_async.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import asyncio
|
||||
import os
|
||||
from uuid import uuid4
|
||||
|
||||
from t_tech.invest import AsyncClient
|
||||
from t_tech.invest.schemas import OrderDirection, OrderType, PostOrderAsyncRequest
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
accounts = await client.users.get_accounts()
|
||||
account_id = accounts.accounts[0].id
|
||||
request = PostOrderAsyncRequest(
|
||||
order_type=OrderType.ORDER_TYPE_MARKET,
|
||||
direction=OrderDirection.ORDER_DIRECTION_BUY,
|
||||
instrument_id="BBG004730ZJ9",
|
||||
quantity=1,
|
||||
account_id=account_id,
|
||||
order_id=str(uuid4()),
|
||||
)
|
||||
response = await client.orders.post_order_async(request=request)
|
||||
print(response)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
29
invest-python-master/examples/async_retrying_client.py
Normal file
29
invest-python-master/examples/async_retrying_client.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
from datetime import timedelta
|
||||
|
||||
from t_tech.invest import CandleInterval
|
||||
from t_tech.invest.retrying.aio.client import AsyncRetryingClient
|
||||
from t_tech.invest.retrying.settings import RetryClientSettings
|
||||
from t_tech.invest.utils import now
|
||||
|
||||
logging.basicConfig(format="%(asctime)s %(levelname)s:%(message)s", level=logging.DEBUG)
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
retry_settings = RetryClientSettings(use_retry=True, max_retry_attempt=2)
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncRetryingClient(TOKEN, settings=retry_settings) as client:
|
||||
async for candle in client.get_all_candles(
|
||||
figi="BBG000B9XRY4",
|
||||
from_=now() - timedelta(days=301),
|
||||
interval=CandleInterval.CANDLE_INTERVAL_1_MIN,
|
||||
):
|
||||
print(candle)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
41
invest-python-master/examples/async_stream_client.py
Normal file
41
invest-python-master/examples/async_stream_client.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import asyncio
|
||||
import os
|
||||
from typing import AsyncIterable
|
||||
|
||||
from t_tech.invest import (
|
||||
AsyncClient,
|
||||
CandleInstrument,
|
||||
MarketDataRequest,
|
||||
SubscribeCandlesRequest,
|
||||
SubscriptionAction,
|
||||
SubscriptionInterval,
|
||||
)
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async def request_iterator():
|
||||
yield MarketDataRequest(
|
||||
subscribe_candles_request=SubscribeCandlesRequest(
|
||||
subscription_action=SubscriptionAction.SUBSCRIPTION_ACTION_SUBSCRIBE,
|
||||
instruments=[
|
||||
CandleInstrument(
|
||||
figi="BBG004730N88",
|
||||
interval=SubscriptionInterval.SUBSCRIPTION_INTERVAL_ONE_MINUTE,
|
||||
)
|
||||
],
|
||||
)
|
||||
)
|
||||
while True:
|
||||
await asyncio.sleep(1)
|
||||
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
async for marketdata in client.market_data_stream.market_data_stream(
|
||||
request_iterator()
|
||||
):
|
||||
print(marketdata)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
23
invest-python-master/examples/cancel_orders.py
Normal file
23
invest-python-master/examples/cancel_orders.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
response = client.users.get_accounts()
|
||||
account, *_ = response.accounts
|
||||
account_id = account.id
|
||||
logger.info("Orders: %s", client.orders.get_orders(account_id=account_id))
|
||||
client.cancel_all_orders(account_id=account.id)
|
||||
logger.info("Orders: %s", client.orders.get_orders(account_id=account_id))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
14
invest-python-master/examples/client.py
Normal file
14
invest-python-master/examples/client.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
print(client.users.get_accounts())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
32
invest-python-master/examples/download_all_candles.py
Normal file
32
invest-python-master/examples/download_all_candles.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import logging
|
||||
import os
|
||||
from datetime import timedelta
|
||||
from pathlib import Path
|
||||
|
||||
from t_tech.invest import CandleInterval, Client
|
||||
from t_tech.invest.caching.market_data_cache.cache import MarketDataCache
|
||||
from t_tech.invest.caching.market_data_cache.cache_settings import (
|
||||
MarketDataCacheSettings,
|
||||
)
|
||||
from t_tech.invest.utils import now
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.DEBUG)
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
settings = MarketDataCacheSettings(base_cache_dir=Path("market_data_cache"))
|
||||
market_data_cache = MarketDataCache(settings=settings, services=client)
|
||||
for candle in market_data_cache.get_all_candles(
|
||||
figi="BBG004730N88",
|
||||
from_=now() - timedelta(days=1),
|
||||
interval=CandleInterval.CANDLE_INTERVAL_HOUR,
|
||||
):
|
||||
print(candle.time, candle.is_complete)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
46
invest-python-master/examples/easy_async_stream_client.py
Normal file
46
invest-python-master/examples/easy_async_stream_client.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from t_tech.invest import (
|
||||
AsyncClient,
|
||||
CandleInstrument,
|
||||
InfoInstrument,
|
||||
MarketDataResponse,
|
||||
SubscriptionInterval,
|
||||
TradeInstrument,
|
||||
)
|
||||
from t_tech.invest.async_services import AsyncMarketDataStreamManager
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
market_data_stream: AsyncMarketDataStreamManager = (
|
||||
client.create_market_data_stream()
|
||||
)
|
||||
market_data_stream.candles.waiting_close().subscribe(
|
||||
[
|
||||
CandleInstrument(
|
||||
figi="BBG004730N88",
|
||||
interval=SubscriptionInterval.SUBSCRIPTION_INTERVAL_ONE_MINUTE,
|
||||
)
|
||||
]
|
||||
)
|
||||
market_data_stream.trades.subscribe(
|
||||
[
|
||||
TradeInstrument(
|
||||
figi="BBG004730N88",
|
||||
)
|
||||
]
|
||||
)
|
||||
async for marketdata in market_data_stream:
|
||||
marketdata: MarketDataResponse = marketdata
|
||||
print(marketdata)
|
||||
market_data_stream.info.subscribe([InfoInstrument(figi="BBG004730N88")])
|
||||
if marketdata.subscribe_info_response:
|
||||
market_data_stream.stop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
28
invest-python-master/examples/easy_stream_client.py
Normal file
28
invest-python-master/examples/easy_stream_client.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import CandleInstrument, Client, InfoInstrument, SubscriptionInterval
|
||||
from t_tech.invest.services import MarketDataStreamManager
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
market_data_stream: MarketDataStreamManager = client.create_market_data_stream()
|
||||
market_data_stream.candles.waiting_close().subscribe(
|
||||
[
|
||||
CandleInstrument(
|
||||
figi="BBG004730N88",
|
||||
interval=SubscriptionInterval.SUBSCRIPTION_INTERVAL_ONE_MINUTE,
|
||||
)
|
||||
]
|
||||
)
|
||||
for marketdata in market_data_stream:
|
||||
print(marketdata)
|
||||
market_data_stream.info.subscribe([InfoInstrument(figi="BBG004730N88")])
|
||||
if marketdata.subscribe_info_response:
|
||||
market_data_stream.stop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
29
invest-python-master/examples/get_active_orders.py
Normal file
29
invest-python-master/examples/get_active_orders.py
Normal file
@@ -0,0 +1,29 @@
|
||||
"""Example - How to get list of active orders."""
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
response = client.users.get_accounts()
|
||||
account, *_ = response.accounts
|
||||
account_id = account.id
|
||||
|
||||
orders = client.orders.get_orders(
|
||||
account_id=account_id,
|
||||
)
|
||||
print("Active orders:")
|
||||
for order in orders.orders:
|
||||
print(order)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
23
invest-python-master/examples/get_candles_with_limit.py
Normal file
23
invest-python-master/examples/get_candles_with_limit.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import CandleInterval, Client
|
||||
from t_tech.invest.utils import now
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
for candle in client.market_data.get_candles(
|
||||
instrument_id="BBG004730N88",
|
||||
to=now(),
|
||||
limit=24,
|
||||
interval=CandleInterval.CANDLE_INTERVAL_HOUR,
|
||||
).candles:
|
||||
print(candle)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
19
invest-python-master/examples/get_last_prices.py
Normal file
19
invest-python-master/examples/get_last_prices.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client, InstrumentStatus
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
print(
|
||||
client.market_data.get_last_prices(
|
||||
figi=["BBG004730ZJ9"],
|
||||
instrument_status=InstrumentStatus.INSTRUMENT_STATUS_BASE,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
20
invest-python-master/examples/get_last_trades.py
Normal file
20
invest-python-master/examples/get_last_trades.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.schemas import TradeSourceType
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
print(
|
||||
client.market_data.get_last_trades(
|
||||
instrument_id="BBG004730ZJ9",
|
||||
trade_source=TradeSourceType.TRADE_SOURCE_EXCHANGE,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
27
invest-python-master/examples/get_market_values.py
Normal file
27
invest-python-master/examples/get_market_values.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.schemas import GetMarketValuesRequest, MarketValueType
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
for values in client.market_data.get_market_values(
|
||||
request=GetMarketValuesRequest(
|
||||
instrument_id=["BBG004730N88"],
|
||||
values=[
|
||||
MarketValueType.INSTRUMENT_VALUE_LAST_PRICE,
|
||||
MarketValueType.INSTRUMENT_VALUE_CLOSE_PRICE,
|
||||
],
|
||||
)
|
||||
).instruments:
|
||||
for value in values.values:
|
||||
print(value)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
28
invest-python-master/examples/get_operations_by_cursor.py
Normal file
28
invest-python-master/examples/get_operations_by_cursor.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import os
|
||||
from pprint import pprint
|
||||
|
||||
from t_tech.invest import Client, GetOperationsByCursorRequest
|
||||
|
||||
token = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
with Client(token) as client:
|
||||
accounts = client.users.get_accounts()
|
||||
account_id = accounts.accounts[0].id
|
||||
|
||||
def get_request(cursor=""):
|
||||
return GetOperationsByCursorRequest(
|
||||
account_id=account_id,
|
||||
instrument_id="BBG004730N88",
|
||||
cursor=cursor,
|
||||
limit=1,
|
||||
)
|
||||
|
||||
operations = client.operations.get_operations_by_cursor(get_request())
|
||||
print(operations)
|
||||
depth = 10
|
||||
while operations.has_next and depth > 0:
|
||||
request = get_request(cursor=operations.next_cursor)
|
||||
operations = client.operations.get_operations_by_cursor(request)
|
||||
pprint(operations)
|
||||
depth -= 1
|
||||
38
invest-python-master/examples/get_orders.py
Normal file
38
invest-python-master/examples/get_orders.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""Example - How to get list of orders for 1 last hour (maximum requesting period)."""
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.schemas import OrderExecutionReportStatus
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
response = client.users.get_accounts()
|
||||
account, *_ = response.accounts
|
||||
account_id = account.id
|
||||
|
||||
now = datetime.datetime.now()
|
||||
orders = client.orders.get_orders(
|
||||
account_id=account_id,
|
||||
from_=now - datetime.timedelta(hours=1),
|
||||
to=now,
|
||||
# filter only executed or partially executed orders
|
||||
execution_status=[
|
||||
OrderExecutionReportStatus.EXECUTION_REPORT_STATUS_FILL,
|
||||
OrderExecutionReportStatus.EXECUTION_REPORT_STATUS_PARTIALLYFILL,
|
||||
],
|
||||
)
|
||||
print("Orders list:")
|
||||
for order in orders.orders:
|
||||
print(order)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
21
invest-python-master/examples/get_risk_rates.py
Normal file
21
invest-python-master/examples/get_risk_rates.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.schemas import RiskRatesRequest
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
request = RiskRatesRequest()
|
||||
request.instrument_id = ["BBG001M2SC01", "BBG004730N88"]
|
||||
r = client.instruments.get_risk_rates(request=request)
|
||||
for i in r.instrument_risk_rates:
|
||||
print(i.instrument_uid)
|
||||
print(i.short_risk_rate)
|
||||
print(i.long_risk_rate)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
20
invest-python-master/examples/get_sandbox_max_lots.py
Normal file
20
invest-python-master/examples/get_sandbox_max_lots.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import GetMaxLotsRequest
|
||||
from t_tech.invest.sandbox.client import SandboxClient
|
||||
|
||||
TOKEN = os.environ["INVEST_SANDBOX_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with SandboxClient(TOKEN) as client:
|
||||
account_id = client.users.get_accounts().accounts[0].id
|
||||
request = GetMaxLotsRequest(
|
||||
account_id=account_id,
|
||||
instrument_id="BBG004730N88",
|
||||
)
|
||||
print(client.sandbox.get_sandbox_max_lots(request=request))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
22
invest-python-master/examples/get_signals.py
Normal file
22
invest-python-master/examples/get_signals.py
Normal file
@@ -0,0 +1,22 @@
|
||||
"""Example - How to get Signals with filtering"""
|
||||
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.schemas import GetSignalsRequest, SignalState
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
request = GetSignalsRequest()
|
||||
request.instrument_uid = "e6123145-9665-43e0-8413-cd61b8aa9b13" # Сбербанк
|
||||
request.active = SignalState.SIGNAL_STATE_ACTIVE # только активные сигналы
|
||||
r = client.signals.get_signals(request=request)
|
||||
for signal in r.signals:
|
||||
print(signal)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
19
invest-python-master/examples/get_strategies.py
Normal file
19
invest-python-master/examples/get_strategies.py
Normal file
@@ -0,0 +1,19 @@
|
||||
"""Example - How to get Strategies"""
|
||||
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.schemas import GetStrategiesRequest
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
r = client.signals.get_strategies(request=GetStrategiesRequest())
|
||||
for strategy in r.strategies:
|
||||
print(strategy)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
40
invest-python-master/examples/get_tech_analysis.py
Normal file
40
invest-python-master/examples/get_tech_analysis.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import os
|
||||
from datetime import timedelta
|
||||
from decimal import Decimal
|
||||
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.schemas import (
|
||||
Deviation,
|
||||
GetTechAnalysisRequest,
|
||||
IndicatorInterval,
|
||||
IndicatorType,
|
||||
Smoothing,
|
||||
TypeOfPrice,
|
||||
)
|
||||
from t_tech.invest.utils import decimal_to_quotation, now
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
request = GetTechAnalysisRequest(
|
||||
indicator_type=IndicatorType.INDICATOR_TYPE_RSI,
|
||||
instrument_uid="6542a064-6633-44ba-902f-710c97507522",
|
||||
from_=now() - timedelta(days=7),
|
||||
to=now(),
|
||||
interval=IndicatorInterval.INDICATOR_INTERVAL_4_HOUR,
|
||||
type_of_price=TypeOfPrice.TYPE_OF_PRICE_AVG,
|
||||
length=42,
|
||||
deviation=Deviation(
|
||||
deviation_multiplier=decimal_to_quotation(Decimal(1.0)),
|
||||
),
|
||||
smoothing=Smoothing(fast_length=13, slow_length=7, signal_smoothing=3),
|
||||
)
|
||||
response = client.market_data.get_tech_analysis(request=request)
|
||||
for indicator in response.technical_indicators:
|
||||
print(indicator.signal)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
10
invest-python-master/examples/get_trading_statuses.py
Normal file
10
invest-python-master/examples/get_trading_statuses.py
Normal file
@@ -0,0 +1,10 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
|
||||
token = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
with Client(token) as client:
|
||||
statuses = client.market_data.get_trading_statuses(instrument_ids=["BBG004730N88"])
|
||||
print(statuses)
|
||||
44
invest-python-master/examples/instrument_cache.py
Normal file
44
invest-python-master/examples/instrument_cache.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import logging
|
||||
import os
|
||||
from pprint import pprint
|
||||
|
||||
from t_tech.invest import Client, InstrumentIdType
|
||||
from t_tech.invest.caching.instruments_cache.instruments_cache import InstrumentsCache
|
||||
from t_tech.invest.caching.instruments_cache.settings import InstrumentsCacheSettings
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
inst = client.instruments.etfs().instruments[-1]
|
||||
pprint(inst)
|
||||
|
||||
from_server = client.instruments.etf_by(
|
||||
id_type=InstrumentIdType.INSTRUMENT_ID_TYPE_UID,
|
||||
class_code=inst.class_code,
|
||||
id=inst.uid,
|
||||
)
|
||||
pprint(from_server)
|
||||
|
||||
settings = InstrumentsCacheSettings()
|
||||
instruments_cache = InstrumentsCache(
|
||||
settings=settings, instruments_service=client.instruments
|
||||
)
|
||||
|
||||
from_cache = instruments_cache.etf_by(
|
||||
id_type=InstrumentIdType.INSTRUMENT_ID_TYPE_UID,
|
||||
class_code=inst.class_code,
|
||||
id=inst.uid,
|
||||
)
|
||||
pprint(from_cache)
|
||||
|
||||
if str(from_server) != str(from_cache):
|
||||
raise Exception("cache miss")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,28 @@
|
||||
import asyncio
|
||||
import os
|
||||
from datetime import timedelta
|
||||
|
||||
from t_tech.invest import AsyncClient
|
||||
from t_tech.invest.schemas import GetAssetReportsRequest
|
||||
from t_tech.invest.utils import now
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
instruments = await client.instruments.find_instrument(
|
||||
query="Тинькофф Квадратные метры"
|
||||
)
|
||||
instrument = instruments.instruments[0]
|
||||
print(instrument.name)
|
||||
request = GetAssetReportsRequest(
|
||||
instrument_id=instrument.uid,
|
||||
from_=now() - timedelta(days=7),
|
||||
to=now(),
|
||||
)
|
||||
print(await client.instruments.get_asset_reports(request=request))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,24 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from t_tech.invest import AsyncClient
|
||||
from t_tech.invest.schemas import AssetsRequest, InstrumentStatus, InstrumentType
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
r = await client.instruments.get_assets(
|
||||
request=AssetsRequest(
|
||||
instrument_type=InstrumentType.INSTRUMENT_TYPE_SHARE,
|
||||
instrument_status=InstrumentStatus.INSTRUMENT_STATUS_BASE,
|
||||
) # pylint:disable=line-too-long
|
||||
)
|
||||
print("BASE SHARE ASSETS")
|
||||
for bond in r.assets:
|
||||
print(bond)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,27 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from t_tech.invest import AsyncClient, InstrumentType
|
||||
from t_tech.invest.schemas import EventType, GetBondEventsRequest
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
bond = (
|
||||
await client.instruments.find_instrument(
|
||||
query="Тинькофф Банк выпуск 1",
|
||||
instrument_kind=InstrumentType.INSTRUMENT_TYPE_BOND,
|
||||
)
|
||||
).instruments[0]
|
||||
|
||||
request = GetBondEventsRequest(
|
||||
instrument_id=bond.uid,
|
||||
type=EventType.EVENT_TYPE_CALL,
|
||||
)
|
||||
print(await client.instruments.get_bond_events(request=request))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
20
invest-python-master/examples/instruments/async_get_bonds.py
Normal file
20
invest-python-master/examples/instruments/async_get_bonds.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from t_tech.invest import AsyncClient
|
||||
from t_tech.invest.schemas import InstrumentExchangeType
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
bonds = await client.instruments.bonds(
|
||||
instrument_exchange=InstrumentExchangeType.INSTRUMENT_EXCHANGE_UNSPECIFIED,
|
||||
)
|
||||
for bond in bonds.instruments:
|
||||
print(bond)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,22 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from t_tech.invest import AsyncClient
|
||||
from t_tech.invest.schemas import GetConsensusForecastsRequest, Page
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
request = GetConsensusForecastsRequest(
|
||||
paging=Page(page_number=0, limit=2),
|
||||
)
|
||||
response = await client.instruments.get_consensus_forecasts(request=request)
|
||||
print(response.page)
|
||||
for forecast in response.items:
|
||||
print(forecast.uid, forecast.consensus.name)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,23 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from t_tech.invest import AsyncClient
|
||||
from t_tech.invest.schemas import GetForecastRequest
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
async def main():
|
||||
async with AsyncClient(TOKEN) as client:
|
||||
instrument = (
|
||||
await client.instruments.find_instrument(
|
||||
query="Сбер Банк - привилегированные акции"
|
||||
)
|
||||
).instruments[0]
|
||||
request = GetForecastRequest(instrument_id=instrument.uid)
|
||||
response = await client.instruments.get_forecast_by(request=request)
|
||||
print(instrument.name, response.consensus.recommendation.name)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,22 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from t_tech.invest import AsyncClient
|
||||
from t_tech.invest.schemas import InstrumentsRequest, InstrumentStatus
|
||||
|
||||
|
||||
async def main():
|
||||
token = os.environ["INVEST_TOKEN"]
|
||||
|
||||
with AsyncClient(token) as client:
|
||||
r = await client.instruments.structured_notes(
|
||||
request=InstrumentsRequest(
|
||||
instrument_status=InstrumentStatus.INSTRUMENT_STATUS_ALL
|
||||
)
|
||||
)
|
||||
for note in r.instruments:
|
||||
print(note)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,21 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from t_tech.invest import AsyncClient
|
||||
from t_tech.invest.schemas import InstrumentIdType, InstrumentRequest
|
||||
|
||||
|
||||
async def main():
|
||||
token = os.environ["INVEST_TOKEN"]
|
||||
|
||||
with AsyncClient(token) as client:
|
||||
r = await client.instruments.structured_note_by(
|
||||
request=InstrumentRequest(
|
||||
id_type=InstrumentIdType.INSTRUMENT_ID_TYPE_FIGI, id="BBG012S2DCJ8"
|
||||
)
|
||||
)
|
||||
print(r.instrument)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,18 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.schemas import GetAssetFundamentalsRequest
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
request = GetAssetFundamentalsRequest(
|
||||
assets=["40d89385-a03a-4659-bf4e-d3ecba011782"],
|
||||
)
|
||||
print(client.instruments.get_asset_fundamentals(request=request))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,27 @@
|
||||
import os
|
||||
from datetime import timedelta
|
||||
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.schemas import GetAssetReportsRequest
|
||||
from t_tech.invest.utils import now
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
instruments = client.instruments.find_instrument(
|
||||
query="Тинькофф Квадратные метры"
|
||||
)
|
||||
instrument = instruments.instruments[0]
|
||||
print(instrument.name)
|
||||
request = GetAssetReportsRequest(
|
||||
instrument_id=instrument.uid,
|
||||
from_=now() - timedelta(days=7),
|
||||
to=now(),
|
||||
)
|
||||
print(client.instruments.get_asset_reports(request=request))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
28
invest-python-master/examples/instruments/get_assets.py
Normal file
28
invest-python-master/examples/instruments/get_assets.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.schemas import AssetsRequest, InstrumentStatus, InstrumentType
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
r = client.instruments.get_assets(
|
||||
request=AssetsRequest(instrument_type=InstrumentType.INSTRUMENT_TYPE_BOND)
|
||||
)
|
||||
print("BONDS")
|
||||
for bond in r.assets:
|
||||
print(bond)
|
||||
r = client.instruments.get_assets(
|
||||
request=AssetsRequest(
|
||||
instrument_status=InstrumentStatus.INSTRUMENT_STATUS_BASE
|
||||
)
|
||||
)
|
||||
print("BASE ASSETS")
|
||||
for bond in r.assets:
|
||||
print(bond)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
24
invest-python-master/examples/instruments/get_bond_events.py
Normal file
24
invest-python-master/examples/instruments/get_bond_events.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.schemas import EventType, GetBondEventsRequest, InstrumentType
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
bond = client.instruments.find_instrument(
|
||||
query="Тинькофф Банк выпуск 1",
|
||||
instrument_kind=InstrumentType.INSTRUMENT_TYPE_BOND,
|
||||
).instruments[0]
|
||||
|
||||
request = GetBondEventsRequest(
|
||||
instrument_id=bond.uid,
|
||||
type=EventType.EVENT_TYPE_CALL,
|
||||
)
|
||||
print(client.instruments.get_bond_events(request=request))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
19
invest-python-master/examples/instruments/get_bonds.py
Normal file
19
invest-python-master/examples/instruments/get_bonds.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.schemas import InstrumentExchangeType
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
r = client.instruments.bonds(
|
||||
instrument_exchange=InstrumentExchangeType.INSTRUMENT_EXCHANGE_UNSPECIFIED
|
||||
)
|
||||
for bond in r.instruments:
|
||||
print(bond)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
18
invest-python-master/examples/instruments/get_brands.py
Normal file
18
invest-python-master/examples/instruments/get_brands.py
Normal file
@@ -0,0 +1,18 @@
|
||||
"""Example - How to get Brands"""
|
||||
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
r = client.instruments.get_brands()
|
||||
for brand in r.brands:
|
||||
print(brand)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,28 @@
|
||||
import os
|
||||
from datetime import timedelta
|
||||
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.schemas import (
|
||||
GetAssetReportsRequest,
|
||||
GetConsensusForecastsRequest,
|
||||
InstrumentIdType,
|
||||
Page,
|
||||
)
|
||||
from t_tech.invest.utils import now
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
request = GetConsensusForecastsRequest(
|
||||
paging=Page(page_number=0, limit=2),
|
||||
)
|
||||
response = client.instruments.get_consensus_forecasts(request=request)
|
||||
print(response.page)
|
||||
for forecast in response.items:
|
||||
print(forecast.uid, forecast.consensus.name)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
20
invest-python-master/examples/instruments/get_dfa_by.py
Normal file
20
invest-python-master/examples/instruments/get_dfa_by.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client, InstrumentIdType, InstrumentRequest
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
dfa = client.instruments.dfa_by(
|
||||
request=InstrumentRequest(
|
||||
id_type=InstrumentIdType.INSTRUMENT_ID_TYPE_POSITION_UID,
|
||||
id="ce604b33-70c7-4609-9f42-075dbd9fe278",
|
||||
)
|
||||
)
|
||||
print(dfa)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
16
invest-python-master/examples/instruments/get_dfas.py
Normal file
16
invest-python-master/examples/instruments/get_dfas.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
r = client.instruments.dfas()
|
||||
for dfa in r.instruments:
|
||||
print(dfa)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
28
invest-python-master/examples/instruments/get_forecast_by.py
Normal file
28
invest-python-master/examples/instruments/get_forecast_by.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import os
|
||||
from datetime import timedelta
|
||||
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.schemas import (
|
||||
GetAssetReportsRequest,
|
||||
GetConsensusForecastsRequest,
|
||||
GetForecastRequest,
|
||||
InstrumentIdType,
|
||||
Page,
|
||||
)
|
||||
from t_tech.invest.utils import now
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
instrument = client.instruments.find_instrument(
|
||||
query="Сбер Банк - привилегированные акции"
|
||||
).instruments[0]
|
||||
request = GetForecastRequest(instrument_id=instrument.uid)
|
||||
response = client.instruments.get_forecast_by(request=request)
|
||||
print(instrument.name, response.consensus.recommendation.name)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,37 @@
|
||||
"""Example - How to get list of insider deals.
|
||||
Request data in loop with batches of 10 records.
|
||||
"""
|
||||
import logging
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.schemas import GetInsiderDealsRequest
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
deals = []
|
||||
|
||||
next_cursor = None
|
||||
while True:
|
||||
response = client.instruments.get_insider_deals(
|
||||
request=GetInsiderDealsRequest(
|
||||
instrument_id="BBG004730N88", limit=10, next_cursor=next_cursor
|
||||
)
|
||||
)
|
||||
deals.extend(response.insider_deals)
|
||||
next_cursor = response.next_cursor
|
||||
if not next_cursor:
|
||||
break
|
||||
print("Insider deals:")
|
||||
for deal in deals:
|
||||
print(deal)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
18
invest-python-master/examples/instruments/indicatives.py
Normal file
18
invest-python-master/examples/instruments/indicatives.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.schemas import IndicativesRequest
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
request = IndicativesRequest()
|
||||
indicatives = client.instruments.indicatives(request=request)
|
||||
for instrument in indicatives.instruments:
|
||||
print(instrument.name)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,54 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.schemas import (
|
||||
CreateFavoriteGroupRequest,
|
||||
DeleteFavoriteGroupRequest,
|
||||
EditFavoritesActionType as At,
|
||||
EditFavoritesRequestInstrument,
|
||||
GetFavoriteGroupsRequest,
|
||||
)
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
r = client.instruments.get_favorites()
|
||||
|
||||
print("Список избранных инструментов:")
|
||||
for i in r.favorite_instruments:
|
||||
print(f"{i.uid} - {i.name}")
|
||||
|
||||
request = CreateFavoriteGroupRequest()
|
||||
request.group_name = "My test favorite group"
|
||||
request.group_color = "aa0000" # red color
|
||||
r = client.instruments.create_favorite_group(request=request)
|
||||
group_id = r.group_id
|
||||
print(f"Создана новая группа избранного с ИД: {group_id}")
|
||||
|
||||
client.instruments.edit_favorites(
|
||||
instruments=[EditFavoritesRequestInstrument(instrument_id="BBG001M2SC01")],
|
||||
action_type=At.EDIT_FAVORITES_ACTION_TYPE_ADD,
|
||||
group_id=group_id,
|
||||
)
|
||||
|
||||
request = GetFavoriteGroupsRequest()
|
||||
request.instrument_id = ["BBG001M2SC01"]
|
||||
r = client.instruments.get_favorite_groups(request=request)
|
||||
print(f"Список групп избранного:")
|
||||
for i in r.groups:
|
||||
print(
|
||||
f"{i.group_id} - {i.group_name}. Количество элементов: {i.size}. "
|
||||
f"Содержит выбранный инструмент {request.instrument_id[0]}: "
|
||||
f"{i.contains_instrument} "
|
||||
)
|
||||
|
||||
request = DeleteFavoriteGroupRequest()
|
||||
request.group_id = group_id
|
||||
client.instruments.delete_favorite_group(request=request)
|
||||
print(f"Удалена группа избранного с ИД: {group_id}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,19 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client, InstrumentIdType
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
r = client.instruments.get_instrument_by(
|
||||
id_type=InstrumentIdType.INSTRUMENT_ID_TYPE_TICKER,
|
||||
id="LKOH",
|
||||
class_code="TQBR",
|
||||
)
|
||||
print(r.instrument)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
16
invest-python-master/examples/instruments/instruments.py
Normal file
16
invest-python-master/examples/instruments/instruments.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
r = client.instruments.find_instrument(query="BBG001M2SC01")
|
||||
for i in r.instruments:
|
||||
print(i)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
16
invest-python-master/examples/instruments/options.py
Normal file
16
invest-python-master/examples/instruments/options.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
r = client.instruments.options()
|
||||
for instrument in r.instruments:
|
||||
print(instrument)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,21 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.schemas import InstrumentsRequest, InstrumentStatus
|
||||
|
||||
|
||||
def main():
|
||||
token = os.environ["INVEST_TOKEN"]
|
||||
|
||||
with Client(token) as client:
|
||||
r = client.instruments.structured_notes(
|
||||
request=InstrumentsRequest(
|
||||
instrument_status=InstrumentStatus.INSTRUMENT_STATUS_ALL
|
||||
)
|
||||
)
|
||||
for note in r.instruments:
|
||||
print(note)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,21 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.schemas import InstrumentIdType, InstrumentRequest
|
||||
|
||||
|
||||
def main():
|
||||
token = os.environ["INVEST_TOKEN"]
|
||||
|
||||
with Client(token) as client:
|
||||
r = client.instruments.structured_note_by(
|
||||
request=InstrumentRequest(
|
||||
id_type=InstrumentIdType.INSTRUMENT_ID_TYPE_UID,
|
||||
id="1d7dfabb-9e82-4de4-8add-8475db83d2bd",
|
||||
)
|
||||
)
|
||||
print(r.instrument)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
23
invest-python-master/examples/logger.py
Normal file
23
invest-python-master/examples/logger.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client, RequestError
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
logging.basicConfig(format="%(asctime)s %(levelname)s:%(message)s", level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
_ = client.users.get_accounts().accounts
|
||||
try:
|
||||
client.users.get_margin_attributes(account_id="123")
|
||||
except RequestError as err:
|
||||
tracking_id = err.metadata.tracking_id if err.metadata else ""
|
||||
logger.error("Error tracking_id=%s code=%s", tracking_id, str(err.code))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
137
invest-python-master/examples/market_order_stop_order.py
Normal file
137
invest-python-master/examples/market_order_stop_order.py
Normal file
@@ -0,0 +1,137 @@
|
||||
"""
|
||||
Алгоритм:
|
||||
|
||||
выставляем рыночный ордер по дешевой бумаге
|
||||
если он не исполнен - возвращаем ошибку (код и message)
|
||||
если он исполнен и вернулся его идентификатор,
|
||||
то выставляем тейкпрофит на цену +5% к цене покупки
|
||||
и стоплосс на -2% к цене покупки.
|
||||
Контур выбираем: песочница или боевой.
|
||||
|
||||
Примеры дешевых акций:
|
||||
BBG001M2SC01 84.120000000р
|
||||
BBG000K3STR7 134.900000000р
|
||||
BBG00F9XX7H4 142.000000000р
|
||||
"""
|
||||
import logging
|
||||
import os
|
||||
import uuid
|
||||
from datetime import timedelta
|
||||
from decimal import Decimal
|
||||
|
||||
from t_tech.invest import (
|
||||
Client,
|
||||
OrderDirection,
|
||||
OrderExecutionReportStatus,
|
||||
OrderType,
|
||||
PostOrderResponse,
|
||||
StopOrderDirection,
|
||||
StopOrderExpirationType,
|
||||
StopOrderType,
|
||||
)
|
||||
from t_tech.invest.services import Services
|
||||
from t_tech.invest.utils import decimal_to_quotation, money_to_decimal, now
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
QUANTITY = 1
|
||||
INSTRUMENT_ID = "BBG001M2SC01"
|
||||
TAKE_PROFIT_PERCENTAGE = 0.05
|
||||
STOP_LOSS_PERCENTAGE = -0.02
|
||||
MIN_PRICE_STEP = 0.02
|
||||
STOP_ORDER_EXPIRE_DURATION = timedelta(hours=1)
|
||||
EXPIRATION_TYPE = StopOrderExpirationType.STOP_ORDER_EXPIRATION_TYPE_GOOD_TILL_DATE
|
||||
|
||||
|
||||
def main():
|
||||
logger.info("Using Real market")
|
||||
with Client(TOKEN) as client:
|
||||
response = client.users.get_accounts()
|
||||
account, *_ = response.accounts
|
||||
account_id = account.id
|
||||
|
||||
order_id = str(uuid.uuid4())
|
||||
|
||||
logger.info(
|
||||
"Placing order for %s security of %s, with order_id=%s",
|
||||
QUANTITY,
|
||||
INSTRUMENT_ID,
|
||||
order_id,
|
||||
)
|
||||
post_order_response: PostOrderResponse = client.orders.post_order(
|
||||
quantity=QUANTITY,
|
||||
direction=OrderDirection.ORDER_DIRECTION_BUY,
|
||||
account_id=account_id,
|
||||
order_type=OrderType.ORDER_TYPE_MARKET,
|
||||
order_id=order_id,
|
||||
instrument_id=INSTRUMENT_ID,
|
||||
)
|
||||
|
||||
status = post_order_response.execution_report_status
|
||||
if status == OrderExecutionReportStatus.EXECUTION_REPORT_STATUS_FILL:
|
||||
logger.info("Order was fulfilled, posting stop orders.")
|
||||
|
||||
post_stop_orders(
|
||||
client=client,
|
||||
account_id=account_id,
|
||||
post_order_response=post_order_response,
|
||||
)
|
||||
else:
|
||||
logger.info(
|
||||
'Order was not fulfilled: (%s) "%s"',
|
||||
post_order_response.execution_report_status,
|
||||
post_order_response.message,
|
||||
)
|
||||
logger.info("Cancelling all orders.")
|
||||
client.cancel_all_orders(account_id=account_id)
|
||||
|
||||
|
||||
def post_stop_orders(
|
||||
client: Services, account_id: str, post_order_response: PostOrderResponse
|
||||
):
|
||||
executed_order_price = money_to_decimal(post_order_response.executed_order_price)
|
||||
take_profit_price = executed_order_price * Decimal((1 + TAKE_PROFIT_PERCENTAGE))
|
||||
take_profit_price -= take_profit_price % Decimal(MIN_PRICE_STEP)
|
||||
take_profit_response = client.stop_orders.post_stop_order(
|
||||
quantity=QUANTITY,
|
||||
price=decimal_to_quotation(take_profit_price),
|
||||
stop_price=decimal_to_quotation(take_profit_price),
|
||||
direction=StopOrderDirection.STOP_ORDER_DIRECTION_SELL,
|
||||
account_id=account_id,
|
||||
stop_order_type=StopOrderType.STOP_ORDER_TYPE_TAKE_PROFIT,
|
||||
instrument_id=INSTRUMENT_ID,
|
||||
expire_date=now() + STOP_ORDER_EXPIRE_DURATION,
|
||||
expiration_type=EXPIRATION_TYPE,
|
||||
order_id=str(uuid.uuid4()),
|
||||
)
|
||||
logger.info(
|
||||
"Take profit order was placed stop_order_id=%s. Price: %s",
|
||||
take_profit_response.stop_order_id,
|
||||
take_profit_price,
|
||||
)
|
||||
stop_loss_price = executed_order_price * Decimal((1 + STOP_LOSS_PERCENTAGE))
|
||||
stop_loss_price -= stop_loss_price % Decimal(MIN_PRICE_STEP)
|
||||
take_profit_response = client.stop_orders.post_stop_order(
|
||||
quantity=QUANTITY,
|
||||
stop_price=decimal_to_quotation(stop_loss_price),
|
||||
direction=StopOrderDirection.STOP_ORDER_DIRECTION_SELL,
|
||||
account_id=account_id,
|
||||
stop_order_type=StopOrderType.STOP_ORDER_TYPE_STOP_LOSS,
|
||||
instrument_id=INSTRUMENT_ID,
|
||||
expire_date=now() + STOP_ORDER_EXPIRE_DURATION,
|
||||
expiration_type=EXPIRATION_TYPE,
|
||||
order_id=str(uuid.uuid4()),
|
||||
)
|
||||
logger.info(
|
||||
"Stop loss order was placed stop_order_id=%s. Price: %s",
|
||||
take_profit_response.stop_order_id,
|
||||
stop_loss_price,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
36
invest-python-master/examples/max_lots.py
Normal file
36
invest-python-master/examples/max_lots.py
Normal file
@@ -0,0 +1,36 @@
|
||||
"""Example - How to get available limits."""
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client, GetMaxLotsRequest
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
INSTRUMENT_ID = "TCS00A105GE2"
|
||||
|
||||
|
||||
def main():
|
||||
logger.info("Getting Max Lots")
|
||||
with Client(TOKEN) as client:
|
||||
response = client.users.get_accounts()
|
||||
account, *_ = response.accounts
|
||||
account_id = account.id
|
||||
|
||||
logger.info(
|
||||
"Calculating available order amount for instrument=%s and market price",
|
||||
INSTRUMENT_ID,
|
||||
)
|
||||
get_max_lots = client.orders.get_max_lots(
|
||||
GetMaxLotsRequest(account_id=account_id, instrument_id=INSTRUMENT_ID)
|
||||
)
|
||||
|
||||
print(get_max_lots)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
15
invest-python-master/examples/open_sandbox_account.py
Normal file
15
invest-python-master/examples/open_sandbox_account.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest.sandbox.client import SandboxClient
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with SandboxClient(TOKEN) as client:
|
||||
print(client.sandbox.open_sandbox_account(name="tcs"))
|
||||
print(client.users.get_accounts())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
26
invest-python-master/examples/operations_stream.py
Normal file
26
invest-python-master/examples/operations_stream.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.schemas import OperationsStreamRequest, PingDelaySettings
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
accounts = client.users.get_accounts().accounts
|
||||
accounts = [i.id for i in accounts]
|
||||
print(f"Subscribe for operations on accounts: {accounts}")
|
||||
for operation in client.operations_stream.operations_stream(
|
||||
OperationsStreamRequest(
|
||||
accounts=accounts,
|
||||
ping_settings=PingDelaySettings(
|
||||
ping_delay_ms=5000,
|
||||
),
|
||||
)
|
||||
):
|
||||
print(operation)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
48
invest-python-master/examples/order_price.py
Normal file
48
invest-python-master/examples/order_price.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""Example - How to get order price."""
|
||||
|
||||
import logging
|
||||
import os
|
||||
from decimal import Decimal
|
||||
|
||||
from t_tech.invest import Client, GetOrderPriceRequest, OrderDirection
|
||||
from t_tech.invest.utils import decimal_to_quotation
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
INSTRUMENT_ID = "TCS00A105GE2"
|
||||
QUANTITY = 1
|
||||
PRICE = 230.1
|
||||
|
||||
|
||||
def main():
|
||||
logger.info("Getting Max Lots")
|
||||
with Client(TOKEN) as client:
|
||||
response = client.users.get_accounts()
|
||||
account, *_ = response.accounts
|
||||
account_id = account.id
|
||||
|
||||
logger.info(
|
||||
"Get pre-trade order commission and price for instrument=%s, quantity=%s and price=%s",
|
||||
INSTRUMENT_ID,
|
||||
QUANTITY,
|
||||
PRICE,
|
||||
)
|
||||
get_order_price = client.orders.get_order_price(
|
||||
GetOrderPriceRequest(
|
||||
account_id=account_id,
|
||||
instrument_id=INSTRUMENT_ID,
|
||||
quantity=QUANTITY,
|
||||
direction=OrderDirection.ORDER_DIRECTION_BUY,
|
||||
price=decimal_to_quotation(Decimal(PRICE)),
|
||||
)
|
||||
)
|
||||
|
||||
print(get_order_price)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
19
invest-python-master/examples/order_state_stream.py
Normal file
19
invest-python-master/examples/order_state_stream.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
from t_tech.invest.schemas import OrderStateStreamRequest
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
request = OrderStateStreamRequest()
|
||||
request.ping_delay_millis = 10000
|
||||
stream = client.orders_stream.order_state_stream(request=request)
|
||||
for order_state in stream:
|
||||
print(order_state)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
18
invest-python-master/examples/porfolio_stream_client.py
Normal file
18
invest-python-master/examples/porfolio_stream_client.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
accounts = client.users.get_accounts()
|
||||
for portfolio in client.operations_stream.portfolio_stream(
|
||||
accounts=[acc.id for acc in accounts.accounts], ping_delay_ms=60_000
|
||||
):
|
||||
print(portfolio)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
19
invest-python-master/examples/positions_stream.py
Normal file
19
invest-python-master/examples/positions_stream.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import os
|
||||
|
||||
from t_tech.invest import Client
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
response = client.users.get_accounts()
|
||||
accounts = [account.id for account in response.accounts]
|
||||
for response in client.operations_stream.positions_stream(
|
||||
accounts=accounts, with_initial_positions=True
|
||||
): # noqa:E501 # pylint:disable=line-too-long
|
||||
print(response)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
36
invest-python-master/examples/post_order.py
Normal file
36
invest-python-master/examples/post_order.py
Normal file
@@ -0,0 +1,36 @@
|
||||
"""Example - How to Post order"""
|
||||
|
||||
import os
|
||||
from uuid import uuid4
|
||||
|
||||
from t_tech.invest import Client, OrderDirection, OrderType
|
||||
from t_tech.invest.sandbox.client import SandboxClient
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
"""
|
||||
Примеры дешевых акций:
|
||||
BBG001M2SC01 84.120000000р
|
||||
BBG000K3STR7 134.900000000р
|
||||
BBG00F9XX7H4 142.000000000р
|
||||
"""
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
accounts = client.users.get_accounts()
|
||||
account_id = accounts.accounts[0].id
|
||||
|
||||
response = client.orders.post_order(
|
||||
order_type=OrderType.ORDER_TYPE_MARKET,
|
||||
direction=OrderDirection.ORDER_DIRECTION_BUY,
|
||||
instrument_id="BBG004730ZJ9",
|
||||
quantity=1,
|
||||
account_id=account_id,
|
||||
order_id=str(uuid4()),
|
||||
)
|
||||
print(response)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
30
invest-python-master/examples/post_order_async.py
Normal file
30
invest-python-master/examples/post_order_async.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""Example - How to get Post Order"""
|
||||
|
||||
import os
|
||||
from uuid import uuid4
|
||||
|
||||
from t_tech.invest import Client, OrderDirection, OrderType
|
||||
from t_tech.invest.schemas import PostOrderAsyncRequest
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
|
||||
def main():
|
||||
with Client(TOKEN) as client:
|
||||
accounts = client.users.get_accounts()
|
||||
account_id = accounts.accounts[0].id
|
||||
|
||||
request = PostOrderAsyncRequest(
|
||||
order_type=OrderType.ORDER_TYPE_MARKET,
|
||||
direction=OrderDirection.ORDER_DIRECTION_BUY,
|
||||
instrument_id="BBG004730ZJ9",
|
||||
quantity=1,
|
||||
account_id=account_id,
|
||||
order_id=str(uuid4()),
|
||||
)
|
||||
response = client.orders.post_order_async(request=request)
|
||||
print(response)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
22
invest-python-master/examples/retrying_client.py
Normal file
22
invest-python-master/examples/retrying_client.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import logging
|
||||
import os
|
||||
from datetime import timedelta
|
||||
|
||||
from t_tech.invest import CandleInterval
|
||||
from t_tech.invest.retrying.settings import RetryClientSettings
|
||||
from t_tech.invest.retrying.sync.client import RetryingClient
|
||||
from t_tech.invest.utils import now
|
||||
|
||||
logging.basicConfig(format="%(asctime)s %(levelname)s:%(message)s", level=logging.DEBUG)
|
||||
|
||||
TOKEN = os.environ["INVEST_TOKEN"]
|
||||
|
||||
retry_settings = RetryClientSettings(use_retry=True, max_retry_attempt=2)
|
||||
|
||||
with RetryingClient(TOKEN, settings=retry_settings) as client:
|
||||
for candle in client.get_all_candles(
|
||||
figi="BBG000B9XRY4",
|
||||
from_=now() - timedelta(days=301),
|
||||
interval=CandleInterval.CANDLE_INTERVAL_1_MIN,
|
||||
):
|
||||
print(candle)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user