AsyncRequest Class Reference

class aio_trader.AsyncRequest.AsyncRequest(throttlers: List[Throttler], cookie_path: Path | None = None, **kwargs)

Bases: object

A wrapper class for making async requests using aiohttp

Parameters:
  • throttlers (List[throttler.Throttler]) – Default list of throttlers to apply to all requests.

  • kwargs – Additional keyword arguments passed to aiohttp.ClientSession

async __aenter__()

On entering async context manager

async __aexit__(*_)

On exiting async context manager

__init__(throttlers: List[Throttler], cookie_path: Path | None = None, **kwargs) None
async close_session()

Close the session

async delete(endpoint, data=None, json=None, headers=None, throttlers: List[Throttler] | None = None) Any

DELETE Request

Parameters:
  • endpoint (str) – url endpoint

  • data (aiohttp.FormData or any object that can be passed to formdata) – data to send in body of POST request

  • json (dict) – Any json compatible python object (optional). json and data parameters could not be used at the same time.

  • headers (dict) – Additional http headers

  • throttlers (Optional[List[Throttler]]) – Default None. Overide the default throttlers

async get(endpoint, params=None, headers=None, throttlers: List[Throttler] | None = None) Any

GET Request

Parameters:
  • endpoint (str) – url endpoint

  • params (dict or any iterable) – Query string params

  • headers (dict) – Additional http headers

  • throttlers (Optional[List[Throttler]]) – Default None. Overide the default throttlers

async patch(endpoint, data=None, headers=None, throttlers: List[Throttler] | None = None) Any

DELETE Request

Parameters:
  • endpoint (str) – url endpoint

  • data (aiohttp.FormData or any object that can be passed to formdata) – data to send in body of POST request

  • headers (dict) – Additional http headers

  • throttlers (Optional[List[Throttler]]) – Default None. Overide the default throttlers

async post(endpoint, data=None, params=None, json=None, headers=None, throttlers: List[Throttler] | None = None) Any

POST Request

Parameters:
  • endpoint (str) – url endpoint

  • data (aiohttp.FormData or any object that can be passed to formdata) – data to send in body of POST request

  • params (dict or any iterable) – data to send in body of POST request

  • json (dict) – Any json compatible python object (optional). json and data parameters could not be used at the same time.

  • headers (dict) – Additional http headers

  • throttlers (Optional[List[Throttler]]) – Default None. Overide the default throttlers

async put(endpoint, data=None, headers=None, throttlers: List[Throttler] | None = None) Any

PUT Request

Parameters:
  • endpoint (str) – url endpoint

  • data (aiohttp.FormData or any object that can be passed to formdata) – data to send in body of PUT request

  • headers (dict) – Additional http headers

  • throttlers (Optional[List[Throttler]]) – Default None. Overide the default throttlers

start_session()

Starts the aiohttp.ClientSession and maps the HTTP methods

__weakref__

list of weak references to the object

aio_trader.AsyncRequest.retry(max_retries=5, base_wait=3, max_wait=30)

Decorator that retries a function or method with exponential backoff in case of exceptions.

Parameters:
  • max_retries (int) – The maximum number of retry attempts.

  • base_wait (float) – The initial delay in seconds before the first retry.

  • max_wait (float) – The maximum delay in seconds between retries.