-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtinkof.py
22 lines (20 loc) · 906 Bytes
/
tinkof.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import tinkoff
from tinkoff.invest import AsyncClient
import asyncio
def quotation2float(quot):
return float(str(quot.units)+"."+str(quot.nano))
async def FetchPortfolios(tinkoffToken):
async with AsyncClient(tinkoffToken) as tinkoff:
accounts = await tinkoff.users.get_accounts()
portfolios = []
for account in accounts.accounts:
portfolio = await tinkoff.operations.get_portfolio(account_id=account.id)
bonds = {}
for i in portfolio.positions:
if i.instrument_type=='bond':
bonds[i.figi] = quotation2float(i.quantity_lots)
portfolios.append({'name': account.name, 'bonds':bonds})
return portfolios
async def FetchPrices(figis, tinkoffToken):
async with AsyncClient(tinkoffToken) as tinkoff:
return (await tinkoff.market_data.get_last_prices(figi=figis)).last_prices