Path: blob/master/ invest-robot-contest_tinkoff-invest-volume-analysis-robot-master/services/user_service.py
5932 views
import logging12from tinkoff.invest import Client3from tinkoff.invest.utils import now45from settings import TOKEN, IS_SANDBOX, INSTRUMENTS67logger = logging.getLogger(__name__)8910def get_instrument_by_asset(asset, instruments):11futures = list(12filter(lambda item: item.basic_asset == asset and now() < item.last_trade_date, instruments))13futures.sort(key=lambda item: item.last_trade_date)14return futures151617class UserService:18def show_settings(self):19if not TOKEN:20print("Не задан токен профиля для Тинькофф Инвестиций. Проверьте общие настройки приложения")21exit()2223try:24with Client(TOKEN) as client:25if IS_SANDBOX:26print("Установлен режим работы с песочницей.\n")27response = client.sandbox.get_sandbox_accounts()28else:29print("Установлен режим работы с реальным счетом.\n")30response = client.users.get_accounts()3132print("Список счетов:")33for account in response.accounts:34print(35f"name=[{account.name}], opened=[{account.opened_date}], status=[{account.status}], id=[{account.id}]"36)37print()3839print("Актуальный список фьючерсов по выбранным активам:")40response = client.instruments.futures()41for instrument in INSTRUMENTS:42asset = instrument["alias"] if "alias" in instrument else instrument["name"]43futures = get_instrument_by_asset(asset, response.instruments)44print(f"{instrument['name']}:")45for future in futures:46print(f"name=[{future.name}], ticker=[{future.ticker}], figi=[{future.figi}]")47print()4849input("Сверьте настройки приложения и нажмите Enter...")50except Exception as ex:51logger.error(ex)525354