-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtinkoff.py
68 lines (50 loc) · 1.9 KB
/
tinkoff.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import datetime
import tinvest
TOKEN = os.getenv("TINVEST_TOKEN")
client = tinvest.SyncClient(TOKEN)
def get_portfolio() -> list:
api = tinvest.PortfolioApi(client)
response = api.portfolio_get()
positions = response.parse_json().payload.positions
return positions
def get_portfolio_currencies() -> list:
api = tinvest.PortfolioApi(client)
response = api.portfolio_currencies_get()
positions = response.parse_json().payload.currencies
return positions
def get_operations(date1, date2) -> list:
day_begin = date1.replace(hour=2, minute=0, second=0, microsecond=0)
if date2 is None:
day_end = day_begin + datetime.timedelta(days=1)
else:
day_end = date2.replace(hour=2, minute=0, second=0, microsecond=0) + datetime.timedelta(days=1)
api = tinvest.OperationsApi(client)
response = api.operations_get(from_=day_begin, to=day_end)
operations = response.parse_json().payload.operations
return operations
def get_market_instruments(type_instrument: str) -> list:
api = tinvest.MarketApi(client)
if type_instrument.lower() == "stocks":
response = api.market_stocks_get()
elif type_instrument.lower() == "bonds":
response = api.market_bonds_get
elif type_instrument.lower() == "etfs":
response = api.market_etfs_get
elif type_instrument.lower() == "currencies":
response = api.market_currencies_get
instruments = response.parse_json().payload.instruments
return instruments
def get_market_stocks_tickers_from_figi() -> dict:
instruments = get_market_instruments("stocks")
D = dict()
for instrument in instruments:
D[instrument.figi] = instrument.ticker
return D
def search_figi(figi):
api = tinvest.MarketApi(client)
response = api.market_search_by_figi_get(figi)
result = response.parse_json().payload
return result
if __name__ == "__main__":
pass