Files
raptor-trading/tatn_audit.py

38 lines
1.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
from datetime import datetime, timedelta, timezone
from dotenv import load_dotenv
from t_tech.invest import Client
os.environ['SSL_CERT_FILE'] = '/etc/ssl/certs/ca-certificates.crt'
os.environ['GRPC_DEFAULT_SSL_ROOTS_FILE_PATH'] = '/etc/ssl/certs/ca-certificates.crt'
load_dotenv("/root/sber_bot/tok.env")
TOKEN = os.getenv("TINKOFF_TOKEN")
TATN_FIGI = "BBG004730RP6"
def q_to_f(q): return q.units + q.nano/1e9 if q else 0
with Client(TOKEN, target="invest-public-api.tbank.ru:443") as client:
accounts = client.users.get_accounts().accounts
print(f"\n--- ИСТОРИЯ СДЕЛОК ПО ТАТНЕФТИ (ЗА 10 ДНЕЙ) ---")
print(f"{'Дата (MSK)':<15} | {'Счет':<12} | {'Тип':<5} | {'Цена':<8} | {'Кол':<4} | {'Сумма':<10}")
print("-" * 75)
for acc in accounts:
ops = client.operations.get_operations(
account_id=acc.id,
from_=datetime.now(timezone.utc) - timedelta(days=10),
to=datetime.now(timezone.utc),
figi=TATN_FIGI # Фильтруем сразу на уровне сервера
).operations
for o in ops:
if "TYPE_BUY" in o.operation_type.name or "TYPE_SELL" in o.operation_type.name:
date = o.date.astimezone(timezone(timedelta(hours=3))).strftime("%d.%m %H:%M")
op_type = "BUY" if "BUY" in o.operation_type.name else "SELL"
price = q_to_f(o.price)
payment = q_to_f(o.payment)
print(f"{date:<15} | {acc.name[:12]:<12} | {op_type:<5} | {price:<8.2f} | {int(o.quantity):<4} | {payment:<10.2f}")