What Tinkoff Investments does not say. We pull out all the data on the portfolio via the API into a large Excel table

Tinkoff Investments is a popular Russian broker with an advanced client application for mobile devices and browsers. The application is designed to simplify the trading process and reduce the threshold for entering investments to such a minimum as to capture the widest possible audience.





However, when investments become serious, the investor needs accurate and detailed data on his portfolio, in particular, to assess the effectiveness of the investment. And this is where ambiguities arise with the application.





Description of the problem

I will consider it using the example of my portfolio (not IIS) in a mobile application. (From the date of publication, the application may be updated).





On the main screen, we see encouraging meanings:





I immediately have questions here:





  • How was this green amount and 12.21% calculated? Moreover, a few days ago I had something about + 17%, then I fixed one security with a profit, the portfolio value remained almost unchanged, but this green "total percentage" immediately fell to 12.21.





  • For all the time - is it over several years of investment? There is also an option: for today. And what percentage do I have, for example, for a year?





  • My portfolio is almost entirely in foreign securities and USD. How was it translated into rubles: at the exchange rate of the Central Bank or at the market?





  • How much of this amount will I really have left after taxes and commissions if I sell the entire portfolio and withdraw the money?





, :





+955 644, 2 ?





, , , .





, .





! -.





. 4 +6,67%, 2020 , +31,41%. , , S&P 500 2020 16,26%. , , . , +12,21% , .. 2019 2018 . , , , .





, , :





  • , ,









  • ,





  • , ,





, , , , . , USD , .





  • , Excel, Excel Google Sheets.





, , . , .





Tinkoff API - , .





, API . , .





API

Open API :





https://tinkoffcreditsystems.github.io/invest-openapi/





SDK: Java, C#, Go, NodeJS.





: Python @daxartio,Python @Awethon, Python @Fatal1ty, PHP, Ruby.





, . , DIY Arduino- WiFi, , WEB- - . .., Arduino Wiring ( C++).





Python, - print('Hello World')



. , , API Python.





.





.





: , API.





, :





  • Python









  • PIP tinvest





, Idle, :





import tinvest







API:





client = tinvest.SyncClient(account_data['my_token'])







my_token API key, .





-, API .





:





positions = client.get_portfolio()



, .





. .





operations = client.get_operations(from_=account_data['start_date'], to=account_data['now_date'])







( ):





course_usd = client.get_market_orderbook(figi='BBG0013HGFT4', depth=20







course_eur = client.get_market_orderbook(figi='BBG0013HJJ31', depth=20)







, , :





currencies = client.get_portfolio_currencies()







print



, :





for pos in positions.payload.positions:







print('name:', pos.name)







print('ticker:', pos.ticker)







print('balance:', pos.balance)







print('currency:', pos.average_position_price.currency)







print('price:', pos.average_position_price.value)







print(' ')







- Excel . XlsxWriter:





https://xlsxwriter.readthedocs.io/





import xlsxwriter







excel . - . , , , / :





ecxelFileName = 'tinkoffReport_' + today + '.xlsx'







workbook = xlsxwriter.Workbook(ecxelFileName)







worksheet = workbook.add_worksheet()







, , , , API, :





, , , , , .





: .





Idle, - : ( !)





DO NOT REPEAT

Python, , , -, .





, , .





Python

, PyCharm.





, PEP8 ( ).





Python : https://www.w3schools.com/





, .





, , . . , , - , , . , , . , https://stackoverflow.com/





3 ( .py) .txt .





main.py - , . , , . API .





data_parser.py - , , .





excel_builder.py - , , main.py .





-

:





(, API):





name -





ticker -





balance -





currency -





ave.price -





exp.yield - ( )





, , , 955 644 (+12,21%) - exp.yield .





, :





market price - (ave.price + exp.yield)





% change - (market_price / ave.price) * 100) - 100)





market value - (market_price * balance)





market value RUB - ( )





ave. % - % change. , . -, .





total value: - ( market value RUB)





, total value 8 782 836, : 8 782 160, --. 0,0077%. , , . - , , .





- !





, , , : .





CB value RUB - .





, 8 749 045 - , , 33 791 , .





ave.buy in RUB - . .





, , , . , , .





, (). , figi , , . , . . , .





, , Tinkoff API , , .





API , , . , , . 15 430 , 1 .





- , , , .





, :





sum.buy in RUB - (ave.buy in RUB * balance)





, 7 178 123 - , , .





tax base - (sum.buy in RUB - CB value RUB)





expected tax - 13%, , .





: 207 145 . - , .





-

, , Tinkoff API. , , :





. , . - .





( )





, , :





, , , !





, .





.





-

.





Investing period - , . , .





, , , - .





PayIn - PayOut - . 5 843 172 - .





Commissions payed - , . 17 315 , 2200 - 2% IPO , . , 15 000 , , , . $1000 18,22 .





, - "" IPO . API .





Taxes payed - , . , , , .





, W8BEN, , , , .





, 117 631 , , , 207, .





: , $100 60 , , 80, $100, 260 , , , 6000, 8000, $ .





Clean portfolio - . , , . , , . , $116000 , - 2000. , . , .





Profit - , . Clean portfolio - (PayIn - PayOut), .., , , . 2 732 519, " " " " , 207. 2500 . , .





-, , .





. , . , , , , , . - XIRR Excel, , . - , .





, , , .





, , , .





, , .





: Excel, Excel, Google Sheets, .





GitHub





.exe , Python , ( , , ).





Python .





I hope the information will be useful for improving interaction with Tinkoff applications, working with APIs and developing similar programs, as well as contribute to a more informed investment, and therefore, increase your well-being. Thank you for reading to the end.








All Articles