async def test_request_with_ctx(token, session, tracking_id, headers): async with AsyncClient(token, session=session) as client: result = await client._request('GET', '/path', Empty, params={'k': 1}) assert result.tracking_id == tracking_id session.request.assert_called_once_with( 'GET', f'{PRODUCTION}/path', headers=headers, params={'k': 1}, raise_for_status=False, ) session.close.assert_called_once_with()
async def test_default_session(token): client = AsyncClient(token) assert isinstance(client._session, aiohttp.ClientSession)
async def test_request_unexpected_error(token, session): client = AsyncClient(token, session=session) with pytest.raises(UnexpectedError): await client._request('GET', '/path', Empty)
async def test_request_bad_request(token, session): client = AsyncClient(token, session=session) with pytest.raises(BadRequestError): await client._request('GET', '/path', Empty)
async def get_market_orderbook(self, figi, depth): async with AsyncClient(self.TOKEN) as client: return await client.get_market_orderbook(figi, depth)
async def test_request_too_many_requests(token, session): client = AsyncClient(token, session=session) with pytest.raises(TooManyRequestsError): await client._request('GET', '/path', Empty)
async def get_market_candles(self, figi, from_, to, interval): async with AsyncClient(self.TOKEN) as client: return await client.get_market_candles(figi, from_, to, interval)
async def get_market_etfs(self): async with AsyncClient(self.TOKEN) as client: return await client.get_market_etfs()
async def get_market_search_by_figi(self, figi): async with AsyncClient(self.TOKEN) as client: response = await client.get_market_search_by_figi(figi) return {figi: response.payload}
async def get_market_stocks(self): async with AsyncClient(self.TOKEN) as client: response = await client.get_market_stocks() return response
async def get_market_currencies(self): async with AsyncClient(self.TOKEN) as client: result = await client.get_market_currencies() result = result.payload.json() return json.loads(result)['instruments']
async def get_accounts(self): async with AsyncClient(self.TOKEN) as client: return await client.get_accounts()
async def get_portfolio_currencies(self): async with AsyncClient(self.TOKEN) as client: result = await client.get_portfolio_currencies() result = result.payload.json() return json.loads(result)['currencies']
async def get_operations(self, from_, to): async with AsyncClient(self.TOKEN) as client: response = await client.get_operations(from_, to) return response.payload
async def get_portfolio(self): async with AsyncClient(self.TOKEN) as client: response = await client.get_portfolio() return response.payload.json()