Исправление запроса SDK, дописать README, добавить модуль для

уведомлений в ТГ (пока не готово)
This commit is contained in:
Dmitry
2026-01-11 14:43:01 +03:00
parent 08a43c876c
commit 898e5eca2c
11 changed files with 316 additions and 56 deletions
+18 -17
View File
@@ -1,14 +1,14 @@
# check_balance.py
from dotenv import load_dotenv
from tinkoff.invest import Client
from tinkoff.invest.utils import quotation_to_decimal
from decimal import Decimal
import os
import sys
from decimal import Decimal
from dotenv import load_dotenv
from t_tech.invest import Client
from t_tech.invest.utils import quotation_to_decimal
def dec_money(mv) -> Decimal:
# Работает и для MoneyValue, и для Quotation
return quotation_to_decimal(mv) if mv is not None else Decimal(0)
@@ -26,30 +26,31 @@ with Client(token) as client:
accs = client.users.get_accounts().accounts
if not accs:
print(
"Нет реальных счетов. Проверь права токена: accounts:read и наличие счёта.")
"Нет реальных счетов. Проверь права токена: accounts:read и наличие счёта."
)
sys.exit(3)
account_id = accs[0].id
# Универсальный способ: get_positions -> money (остатки) и blocked (заморожено)
pos = client.operations.get_positions(account_id=account_id)
rub_money = next(
(m for m in pos.money if m.currency.lower() == "rub"), None)
rub_blocked = next(
(m for m in pos.blocked if m.currency.lower() == "rub"), None)
rub_money = next((m for m in pos.money if m.currency.lower() == "rub"), None)
rub_blocked = next((m for m in pos.blocked if m.currency.lower() == "rub"), None)
rub_free = dec_money(rub_money) if rub_money else Decimal(0)
rub_frozen = dec_money(rub_blocked) if rub_blocked else Decimal(0)
rub_available = rub_free - rub_frozen
print("ACCOUNT_ID:", account_id)
print("RUB free: ", rub_free)
print("RUB blocked: ", rub_frozen)
print("RUB available:", rub_available)
print(f"RUB free: {rub_free:.2f}")
print(f"RUB blocked: {rub_frozen:.2f}")
print(f"RUB available: {rub_available:.2f}")
# Дополнительно: оценка портфеля (если нужно)
pf = client.operations.get_portfolio(account_id=account_id)
total_currencies = dec_money(pf.total_amount_currencies) if hasattr(
pf, "total_amount_currencies") else None
total_currencies = (
dec_money(pf.total_amount_currencies)
if hasattr(pf, "total_amount_currencies")
else None
)
if total_currencies is not None:
print("Portfolio total_amount_currencies:", total_currencies)
print(f"Portfolio total_amount_currencies: {total_currencies:.2f}")
+9 -10
View File
@@ -1,14 +1,14 @@
# check_figi.py
from dotenv import load_dotenv
from tinkoff.invest import Client, InstrumentIdType
from tinkoff.invest.utils import quotation_to_decimal
import os
import sys
FIGI = ["BBG00425VG07", "BBG0073DLHS1"
# вставь сюда твои FIGI из config.yaml
# "BBG004730N88", ...
]
from dotenv import load_dotenv
from t_tech.invest import Client, InstrumentIdType
from t_tech.invest.utils import quotation_to_decimal
FIGI = [
"BBG00425VG07",
"BBG0073DLHS1",
]
load_dotenv()
token = os.environ.get("TINKOFF_TOKEN")
@@ -26,8 +26,7 @@ with Client(token) as client:
print(f"{f}: NOT FOUND")
continue
print(
f"{f}: {inst.ticker} | {inst.name} | lot={
inst.lot} | curr={inst.currency}"
f"{f}: {inst.ticker} | {inst.name} | lot={inst.lot} | curr={inst.currency}"
)
# Проверка last price
+3 -2
View File
@@ -1,7 +1,8 @@
from tinkoff.invest import Client
from dotenv import load_dotenv
import os
from dotenv import load_dotenv
from t_tech.invest import Client
load_dotenv()
TOKEN = os.getenv("TINKOFF_TOKEN")