avantis_trader_sdk.feed package
Submodules
avantis_trader_sdk.feed.feed_client module
- class avantis_trader_sdk.feed.feed_client.FeedClient(ws_url='wss://hermes.pyth.network/ws', on_error=None, on_close=None, hermes_url='https://hermes.pyth.network/v2/updates/price/latest', socket_api=AVANTIS_SOCKET_API, pair_fetcher=None, feed_v3_url=AVANTIS_FEED_V3_URL, lazer_sse_url=PYTH_LAZER_SSE_URL)[source]
Bases:
objectClient for interacting with the Pyth price feed websocket.
- Parameters:
socket_api (str)
pair_fetcher (Callable)
feed_v3_url (str)
lazer_sse_url (str)
- async default_pair_fetcher()[source]
Default pair fetcher that retrieves data from the Avantis API. :rtype:
List[dict] :returns: A list of validated trading pairs.- Raises:
ValueError if API response is invalid. –
- Return type:
List[dict]
- async get_latest_lazer_price(lazer_feed_ids)[source]
Retrieves the latest prices from the Pyth Lazer API.
- Parameters:
lazer_feed_ids (
List[int]) – List of Lazer feed IDs to get prices for.- Return type:
- Returns:
A LazerPriceFeedResponse containing the latest prices.
- Raises:
requests.HTTPError – If the API request fails.
- async get_latest_price_updates(identifiers)[source]
Retrieves the latest price updates for the specified feed ids.
- Parameters:
feedIds – The list of feed ids to retrieve the latest price updates for.
identifiers (List[str])
- Returns:
A PriceFeedUpdatesResponse object containing the latest price updates.
- get_pair_from_feed_id(feed_id)[source]
Retrieves the pair string from the feed id.
- Parameters:
feed_id – The feed id to retrieve the pair string for.
- Returns:
The pair string.
- async get_price_update_data(pair_index)[source]
Retrieves price update data from the feed-v3 API for a specific pair.
This returns both core (Pyth Hermes) and pro (Pyth Lazer) price data, including the priceUpdateData bytes needed for contract calls.
- Parameters:
pair_index (
int) – The pair index to get price update data for.- Return type:
- Returns:
A FeedV3PriceResponse containing core and pro price data.
- Raises:
requests.HTTPError – If the API request fails.
- async listen_for_lazer_price_updates(lazer_feed_ids, callback)[source]
Listens for real-time price updates from the Pyth Lazer SSE stream.
This is the Pyth Pro alternative to the WebSocket-based listen_for_price_updates.
- Parameters:
lazer_feed_ids (
List[int]) – List of Lazer feed IDs to subscribe to.callback (
Callable[[LazerPriceFeedResponse],None]) – Callback function to handle price updates.
- Raises:
Exception – If an error occurs while listening for price updates.
- async listen_for_price_updates()[source]
Listens for price updates from the Pyth price feed websocket. When a price update is received, the registered callbacks will be called with the updated price feed data.
- Raises:
Exception – If an error occurs while listening for price updates.
- load_pair_feeds()[source]
Loads the pair feeds dynamically using the provided pair_fetcher function.