Bondana Client
Неофициальная обертка официального Tinkoff Invest API v2, оптимизированная для торговли облигациями на языке Python.
⚠️ На данный момент отлажена работа на облигациях номиналом 1000 рублей, на других номиналах не тестировалось
Установка клиента
$ pip install tinkoff-investments
$ git clone https://github.com/Mixolap/bondana_client.git
Как пользоваться
Инициализация клиента
from bondana_client.bondana_client import Bondana
TOKEN = 'token'
client = Bondana(TOKEN)
Получить баланс свободных денег в рублях
balance_rub, blocked = client.get_balance('rub')
Получение списка бумаг в портфеле
client.portfolio.portfolio_get()
Получение истории операций
from datetime import datetime, timedelta
nw = datetime.now() - timedelta(days=1) # получим сделки за последний день
d1 = datetime(nw.year, nw.month, nw.day, 0, 0, 0, tzinfo=timezone('Europe/Moscow'))
d2 = datetime.now(tz=timezone('Europe/Moscow'))
ops = client.operations.operations_get(limit=1000, from_=d1, to=d2)
ops.reverse()
for op in ops:
print(op.get("figi"), op.get("price"), op.get("payment"), op.get("quantity"))
Постановка лимитной заявки
# лимитная заявка на покупку
lots = 1
price = 987.65
figi = "BBG00Y9B45C2"
order_limit = client.orders.orders_limit_order_post(figi,
limit_order_request = {"lots": lots, "operation": "Buy", "price":price, })
# лимитная заявка на продажу
lots = 1
price = 997.65
figi = "BBG00Y9B45C2"
order_limit = client.orders.orders_limit_order_post(figi,
limit_order_request = {"lots": lots, "operation": "Sell", "price":price, })
Получение списка активных заявок
client.orders.orders_get() # список заявок в формате объектов Tinkoff API
client.orders.orders_get_json() # список заявок в формате JSON
for order in client.orders.orders_get_json():
print(order.get("order_id"), order.get("operation"), order.get("figi"))
Отмена заявки на покупку
# последовательная отмена всех активных заявок, для примера
for order in client.orders.orders_get_json():
client.orders.orders_cancel_post(order.get("order_id"))
Просмотр стакана по figi
figi = "BBG00Y9B45C2"
orderbook = client.market.market_orderbook_get_dict(figi, 20)
TODO:
получение списка доступных облигаций
получение лотности
шаг цены
Metadata
Release files for bondana-client 2024.11.19134439
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| bondana_client-2024.11.19134439.tar.gz | 2.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bondana_client-2024.11.19134439-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 5.0 kB
Release files / bondana_client-2024.11.19134439.tar.gz
| Download URL | bondana_client-2024.11.19134439.tar.gz |
|---|---|
| Size | 2.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f04c3609d7cb2bcd8f5e058bdeedd6b1f77242ffc9fe291f66ec8b1c423a4929
|
|
BLAKE2b-256 checksum How to use checksums |
eb4d7d0c78769db1521f7c4c48c98c26d0387cb9c395c56ce30ce4fe9a105c79
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / bondana_client-2024.11.19134439-py3-none-any.whl
| Download URL | bondana_client-2024.11.19134439-py3-none-any.whl |
|---|---|
| Size | 2.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
52bb707c7aa6f571bbd59a92f5ed3e951e386b1089ccfe3345165a43c84a6d05
|
|
BLAKE2b-256 checksum How to use checksums |
ef989364b89056e6a0e0abbb64c2702948b35da70313287fce1045217d07e9d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|