Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wiseplat
GitHub Repository: wiseplat/python-code
Path: blob/master/ invest-robot-contest_tinkoff-invest-volume-analysis-robot-master/services/user_service.py
5932 views
1
import logging
2
3
from tinkoff.invest import Client
4
from tinkoff.invest.utils import now
5
6
from settings import TOKEN, IS_SANDBOX, INSTRUMENTS
7
8
logger = logging.getLogger(__name__)
9
10
11
def get_instrument_by_asset(asset, instruments):
12
futures = list(
13
filter(lambda item: item.basic_asset == asset and now() < item.last_trade_date, instruments))
14
futures.sort(key=lambda item: item.last_trade_date)
15
return futures
16
17
18
class UserService:
19
def show_settings(self):
20
if not TOKEN:
21
print("Не задан токен профиля для Тинькофф Инвестиций. Проверьте общие настройки приложения")
22
exit()
23
24
try:
25
with Client(TOKEN) as client:
26
if IS_SANDBOX:
27
print("Установлен режим работы с песочницей.\n")
28
response = client.sandbox.get_sandbox_accounts()
29
else:
30
print("Установлен режим работы с реальным счетом.\n")
31
response = client.users.get_accounts()
32
33
print("Список счетов:")
34
for account in response.accounts:
35
print(
36
f"name=[{account.name}], opened=[{account.opened_date}], status=[{account.status}], id=[{account.id}]"
37
)
38
print()
39
40
print("Актуальный список фьючерсов по выбранным активам:")
41
response = client.instruments.futures()
42
for instrument in INSTRUMENTS:
43
asset = instrument["alias"] if "alias" in instrument else instrument["name"]
44
futures = get_instrument_by_asset(asset, response.instruments)
45
print(f"{instrument['name']}:")
46
for future in futures:
47
print(f"name=[{future.name}], ticker=[{future.ticker}], figi=[{future.figi}]")
48
print()
49
50
input("Сверьте настройки приложения и нажмите Enter...")
51
except Exception as ex:
52
logger.error(ex)
53
54