import os
from datetime import datetime, 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("tok.env")
TOKEN = os.getenv("TINKOFF_TOKEN")
# НОВЫЙ UID ОТ ПОДДЕРЖКИ
SBER_UID = "e6123145-9665-43e0-8413-cd61b8aa9b13"

with Client(TOKEN, target="invest-public-api.tbank.ru:443") as client:
    lp = client.market_data.get_last_prices(instrument_id=[SBER_UID]).last_prices[0]
    price = lp.price.units + lp.price.nano / 1e9
    print(f"\n--- РЕЗУЛЬТАТ ---")
    print(f"Актуальная цена SBER: {price} руб.")
    print(f"Дата и время цены:   {lp.time.strftime('%Y-%m-%d %H:%M:%S')} UTC")
