pub struct PolymarketInstrumentProvider { /* private fields */ }Expand description
Provides Polymarket instruments via the Gamma API.
Wraps PolymarketGammaHttpClient with an [InstrumentStore] and a
token_id index for resolving WebSocket asset IDs to instruments.
Optional InstrumentFilters control which instruments are loaded
during load_all(). Without filters, all active markets are fetched.
Implementations§
Source§impl PolymarketInstrumentProvider
impl PolymarketInstrumentProvider
Sourcepub fn new(http_client: PolymarketGammaHttpClient) -> Self
pub fn new(http_client: PolymarketGammaHttpClient) -> Self
Creates a new PolymarketInstrumentProvider with an empty store and no filters.
Sourcepub fn with_filters(
http_client: PolymarketGammaHttpClient,
filters: Vec<Arc<dyn InstrumentFilter>>,
) -> Self
pub fn with_filters( http_client: PolymarketGammaHttpClient, filters: Vec<Arc<dyn InstrumentFilter>>, ) -> Self
Creates a new PolymarketInstrumentProvider with multiple filters.
Sourcepub fn with_filter(
http_client: PolymarketGammaHttpClient,
filter: Arc<dyn InstrumentFilter>,
) -> Self
pub fn with_filter( http_client: PolymarketGammaHttpClient, filter: Arc<dyn InstrumentFilter>, ) -> Self
Creates a new PolymarketInstrumentProvider with a single filter.
Sourcepub fn add_filter(&mut self, filter: Arc<dyn InstrumentFilter>)
pub fn add_filter(&mut self, filter: Arc<dyn InstrumentFilter>)
Adds an instrument filter for subsequent load_all() calls.
Sourcepub fn clear_filters(&mut self)
pub fn clear_filters(&mut self)
Clears all instrument filters, reverting to bulk load behavior.
Sourcepub fn get_by_token_id(&self, token_id: &Ustr) -> Option<&InstrumentAny>
pub fn get_by_token_id(&self, token_id: &Ustr) -> Option<&InstrumentAny>
Returns the instrument for the given token ID, if found.
Sourcepub fn build_token_map(&self) -> AHashMap<Ustr, InstrumentAny>
pub fn build_token_map(&self) -> AHashMap<Ustr, InstrumentAny>
Builds a frozen snapshot mapping token IDs to instruments.
Used to provide the WS handler task with a read-only lookup table after instruments have been loaded.
Sourcepub async fn load_by_slugs(&mut self, slugs: Vec<String>) -> Result<()>
pub async fn load_by_slugs(&mut self, slugs: Vec<String>) -> Result<()>
Loads instruments for the given slugs additively into the store.
Unlike Self::load_all, this does not clear existing instruments or
mark the store as initialized, allowing incremental loading of
slug-based markets alongside bulk data.
§Errors
Returns an error if the HTTP request or parsing fails.
Sourcepub fn filters(&self) -> Vec<Arc<dyn InstrumentFilter>>
pub fn filters(&self) -> Vec<Arc<dyn InstrumentFilter>>
Returns a clone of the configured instrument filters.
Sourcepub fn http_client(&self) -> &PolymarketGammaHttpClient
pub fn http_client(&self) -> &PolymarketGammaHttpClient
Returns a reference to the underlying HTTP client.
Fetches available tags from the Gamma API.
pub fn add_instruments(&mut self, instruments: Vec<InstrumentAny>)
Trait Implementations§
Source§impl Debug for PolymarketInstrumentProvider
impl Debug for PolymarketInstrumentProvider
Source§impl InstrumentProvider for PolymarketInstrumentProvider
impl InstrumentProvider for PolymarketInstrumentProvider
Source§fn store_mut(&mut self) -> &mut InstrumentStore
fn store_mut(&mut self) -> &mut InstrumentStore
Source§fn load_all<'life0, 'life1, 'async_trait>(
&'life0 mut self,
filters: Option<&'life1 HashMap<String, String>>,
) -> Pin<Box<dyn Future<Output = Result<()>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn load_all<'life0, 'life1, 'async_trait>(
&'life0 mut self,
filters: Option<&'life1 HashMap<String, String>>,
) -> Pin<Box<dyn Future<Output = Result<()>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn load_ids<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
instrument_ids: &'life1 [InstrumentId],
filters: Option<&'life2 HashMap<String, String>>,
) -> Pin<Box<dyn Future<Output = Result<()>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn load_ids<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
instrument_ids: &'life1 [InstrumentId],
filters: Option<&'life2 HashMap<String, String>>,
) -> Pin<Box<dyn Future<Output = Result<()>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn load<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
instrument_id: &'life1 InstrumentId,
filters: Option<&'life2 HashMap<String, String>>,
) -> Pin<Box<dyn Future<Output = Result<()>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn load<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
instrument_id: &'life1 InstrumentId,
filters: Option<&'life2 HashMap<String, String>>,
) -> Pin<Box<dyn Future<Output = Result<()>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Auto Trait Implementations§
impl Freeze for PolymarketInstrumentProvider
impl !RefUnwindSafe for PolymarketInstrumentProvider
impl Send for PolymarketInstrumentProvider
impl Sync for PolymarketInstrumentProvider
impl Unpin for PolymarketInstrumentProvider
impl UnsafeUnpin for PolymarketInstrumentProvider
impl !UnwindSafe for PolymarketInstrumentProvider
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more