Skip to main content

PolymarketInstrumentProvider

Struct PolymarketInstrumentProvider 

Source
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

Source

pub fn new(http_client: PolymarketGammaHttpClient) -> Self

Creates a new PolymarketInstrumentProvider with an empty store and no filters.

Source

pub fn with_filters( http_client: PolymarketGammaHttpClient, filters: Vec<Arc<dyn InstrumentFilter>>, ) -> Self

Creates a new PolymarketInstrumentProvider with multiple filters.

Source

pub fn with_filter( http_client: PolymarketGammaHttpClient, filter: Arc<dyn InstrumentFilter>, ) -> Self

Creates a new PolymarketInstrumentProvider with a single filter.

Source

pub fn add_filter(&mut self, filter: Arc<dyn InstrumentFilter>)

Adds an instrument filter for subsequent load_all() calls.

Source

pub fn clear_filters(&mut self)

Clears all instrument filters, reverting to bulk load behavior.

Source

pub fn get_by_token_id(&self, token_id: &Ustr) -> Option<&InstrumentAny>

Returns the instrument for the given token ID, if found.

Source

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.

Source

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.

Source

pub fn filters(&self) -> Vec<Arc<dyn InstrumentFilter>>

Returns a clone of the configured instrument filters.

Source

pub fn http_client(&self) -> &PolymarketGammaHttpClient

Returns a reference to the underlying HTTP client.

Source

pub async fn list_tags(&self) -> Result<Vec<GammaTag>>

Fetches available tags from the Gamma API.

Source

pub fn add_instruments(&mut self, instruments: Vec<InstrumentAny>)

Trait Implementations§

Source§

impl Debug for PolymarketInstrumentProvider

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl InstrumentProvider for PolymarketInstrumentProvider

Source§

fn store(&self) -> &InstrumentStore

Returns a reference to the provider’s instrument store.
Source§

fn store_mut(&mut self) -> &mut InstrumentStore

Returns a mutable reference to the provider’s instrument store.
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,

Loads all available instruments from the venue. Read more
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,

Loads specific instruments by their IDs. Read more
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,

Loads a single instrument by its ID. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> Ungil for T
where T: Send,