Перейти к содержанию

tinvest/clients.py

AsyncClient

import os
from tinvest import AsyncClient

TOKEN = os.getenv('TINVEST_SANDBOX_TOKEN', '')

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    ...
    await client.close()

clear_sandbox_account(self, broker_account_id=None) async

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    await client.clear_sandbox_account(broker_account_id)

get_accounts(self) async

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    await client.get_accounts()

get_market_bonds(self) async

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    await client.get_market_bonds()

get_market_candles(self, figi, from_, to, interval) async

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    await client.get_market_candles(figi, from_, to, interval)

get_market_currencies(self) async

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    await client.get_market_currencies()

get_market_etfs(self) async

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    await client.get_market_etfs()

get_market_orderbook(self, figi, depth) async

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    await client.get_market_orderbook(figi, depth)

get_market_search_by_figi(self, figi) async

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    await client.get_market_search_by_figi(figi)

get_market_search_by_ticker(self, ticker) async

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    await client.get_market_search_by_ticker(ticker)

get_market_stocks(self) async

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    await client.get_market_stocks()

get_operations(self, from_, to, figi=None, broker_account_id=None) async

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    await client.get_operations(from_, to, figi, broker_account_id)

get_orders(self, broker_account_id=None) async

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    await client.get_orders(broker_account_id)

get_portfolio(self, broker_account_id=None) async

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    await client.get_portfolio(broker_account_id)

get_portfolio_currencies(self, broker_account_id=None) async

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    await client.get_portfolio_currencies(broker_account_id)

post_orders_cancel(self, order_id, broker_account_id=None) async

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    await client.post_orders_cancel(order_id, broker_account_id)

post_orders_limit_order(self, figi, body, broker_account_id=None) async

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    body = LimitOrderRequest(
        lots=2,
        operation='Buy',
        price=100.85,
    )
    await client.post_orders_limit_order(figi, body, broker_account_id)

post_orders_market_order(self, figi, body, broker_account_id=None) async

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    body = MarketOrderRequest(
        lots=2,
        operation='Buy'
    )
    await client.post_orders_market_order(figi, body, broker_account_id)

register_sandbox_account(self, body) async

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    body = SandboxRegisterRequest.tinkoff_iis()
    await client.register_sandbox_account(body)

remove_sandbox_account(self, broker_account_id=None) async

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    await client.remove_sandbox_account(broker_account_id)

set_sandbox_currencies_balance(self, body, broker_account_id=None) async

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    body = SandboxSetCurrencyBalanceRequest(
        balance=1000,
        currency='RUB',
    )
    await client.set_sandbox_currencies_balance(body, broker_account_id)

set_sandbox_positions_balance(self, body, broker_account_id=None) async

async def main():
    client = AsyncClient(TOKEN, use_sandbox=True)
    body = SandboxSetPositionBalanceRequest(
        balance=1000,
        figi='BBG0013HGFT4',
    )
    await client.set_sandbox_positions_balance(body, broker_account_id)

SyncClient

import os
from tinvest import SyncClient

TOKEN = os.getenv('TINVEST_SANDBOX_TOKEN', '')

def main():
    client = SyncClient(TOKEN, use_sandbox=True)

    # SyncClient methods like AsyncClient methods
    market_bonds = client.get_market_bonds()