Tinkoff Invest
Project description
T-Invest
pip install tinvest
import asyncio
import tinvest
TOKEN = "<TOKEN>"
events = tinvest.StreamingEvents()
@events.candle()
async def handle_candle(
api: tinvest.StreamingApi, payload: tinvest.CandleStreamingSchema
):
print(payload)
@events.orderbook()
async def handle_orderbook(
api: tinvest.StreamingApi, payload: tinvest.OrderbookStreamingSchema
):
print(payload)
@events.instrument_info()
async def handle_instrument_info(
api: tinvest.StreamingApi, payload: tinvest.InstrumentInfoStreamingSchema
):
print(payload)
@events.error()
async def handle_error(
api: tinvest.StreamingApi, payload: tinvest.ErrorStreamingSchema
):
print(payload)
@events.startup()
async def startup(api: tinvest.StreamingApi):
await api.candle.subscribe("BBG0013HGFT4", "1min")
await api.orderbook.subscribe("BBG0013HGFT4", 5, "123ASD1123")
await api.instrument_info.subscribe("BBG0013HGFT4")
@events.cleanup()
async def cleanup(api: tinvest.StreamingApi):
await api.candle.unsubscribe("BBG0013HGFT4", "1min")
await api.orderbook.unsubscribe("BBG0013HGFT4", 5)
await api.instrument_info.unsubscribe("BBG0013HGFT4")
async def main():
await tinvest.Streaming(TOKEN, state={"postgres": ...}).add_handlers(events).run()
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
pass
import tinvest
TOKEN = "<TOKEN>"
client = tinvest.SyncClient(TOKEN)
api = tinvest.PortfolioApi(client)
response = api.portfolio_get() # requests.Response
if response.status_code == 200:
print(response.parse_json()) # tinvest.PortfolioResponse
# Handle error
...
api = tinvest.OperationsApi(client)
response = api.operations_get("", "")
if response.status_code != 200:
print(response.parse_error()) # tinvest.Error
import asyncio
import tinvest
TOKEN = "<TOKEN>"
client = tinvest.AsyncClient(TOKEN)
api = tinvest.PortfolioApi(client)
async def request():
async with api.portfolio_get() as response: # aiohttp.ClientResponse
if response.status == 200:
print(await response.parse_json()) # tinvest.PortfolioResponse
loop = asyncio.get_event_loop()
loop.run_until_complete(request())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tinvest-1.0.16.tar.gz
(11.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
tinvest-1.0.16-py3-none-any.whl
(12.3 kB
view details)
File details
Details for the file tinvest-1.0.16.tar.gz.
File metadata
- Download URL: tinvest-1.0.16.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.3 CPython/3.7.1 Linux/4.15.0-1028-gcp
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9dd8f059d1abaafc263652988f0f2444db94ab92c6e9655fa0b90686a5680145
|
|
| MD5 |
47cf129c97584f349d5918de84e32ea6
|
|
| BLAKE2b-256 |
09b9412cd70d4009acd05a4ac7dc093d7d665328d811fb023d52583cb2e7455f
|
File details
Details for the file tinvest-1.0.16-py3-none-any.whl.
File metadata
- Download URL: tinvest-1.0.16-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.3 CPython/3.7.1 Linux/4.15.0-1028-gcp
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4905579213b836be3f73f55720c4c61106c22544255d2a6232656c696e64487
|
|
| MD5 |
99fd6cbedc362bf8c1606eea077aee5e
|
|
| BLAKE2b-256 |
ed13e5368b4181ed1805322aed61ad78ffab5da6f96272eac094604b705c7e1d
|