Polymarket
Config
class PolymarketDataClientConfig
Bases: LiveDataClientConfig
Configuration for PolymarketDataClient
instances.
- Parameters:
- venue (Venue , default POLYMARKET_VENUE) – The venue for the client.
- private_key (str , optional) – The private key for the wallet on the Polygon network.
If
None
then will source the POLYMARKET_PK environment variable. - signature_type (int , default 0 *(*EOA )) – The Polymarket signature type.
- funder (str , optional) – The wallet address (public key) on the Polygon network used for funding USDC.
If
None
then will source the POLYMARKET_FUNDER environment variable. - api_key (str , optional) – The Polymarket API public key.
If
None
then will source the POLYMARKET_API_KEY environment variable. - api_secret (str , optional) – The Polymarket API public key.
If
None
then will source the POLYMARKET_API_SECRET environment variable. - passphrase (str , optional) – The Polymarket API passphrase.
If
None
then will source the POLYMARKET_PASSPHRASE environment variable. - base_url_http (str , optional) – The HTTP client custom endpoint override.
- base_url_ws (str , optional) – The WebSocket client custom endpoint override.
- ws_connection_delay_secs (PositiveInt , default 5) – The delay (seconds) prior to main websocket connection to allow initial subscriptions to arrive.
- update_instruments_interval_mins (PositiveInt or None , default 60) – The interval (minutes) between updating Polymarket instruments.
- compute_effective_deltas (bool , default False) – If True, computes effective deltas by comparing old and new order book states, reducing snapshot size. This takes ~1 millisecond, so is not recommended for latency-sensitive strategies.
venue : Venue
private_key : str | None
signature_type : int
funder : str | None
api_key : str | None
api_secret : str | None
passphrase : str | None
base_url_http : str | None
base_url_ws : str | None
ws_connection_delay_secs : Annotated[int, msgspec.Meta(gt=0)]
update_instruments_interval_mins : Annotated[int, msgspec.Meta(gt=0)] | None
compute_effective_deltas : bool
dict() → dict[str, Any]
Return a dictionary representation of the configuration.
- Return type: dict[str, Any]
classmethod fully_qualified_name() → str
Return the fully qualified name for the NautilusConfig class.
- Return type: str
handle_revised_bars : bool
property id : str
Return the hashed identifier for the configuration.
- Return type: str
instrument_provider : InstrumentProviderConfig
json() → bytes
Return serialized JSON encoded bytes.
- Return type: bytes
json_primitives() → dict[str, Any]
Return a dictionary representation of the configuration with JSON primitive types as values.
- Return type: dict[str, Any]
classmethod parse(raw: bytes | str) → Any
Return a decoded object of the given cls.
- Parameters:
- cls (type) – The type to decode to.
- raw (bytes or str) – The raw bytes or JSON string to decode.
- Return type: Any
routing : RoutingConfig
validate() → bool
Return whether the configuration can be represented as valid JSON.
- Return type: bool
class PolymarketExecClientConfig
Bases: LiveExecClientConfig
Configuration for PolymarketExecutionClient
instances.
- Parameters:
- venue (Venue , default POLYMARKET_VENUE) – The venue for the client.
- private_key (str , optional) – The private key for the wallet on the Polygon network.
If
None
then will source the POLYMARKET_PK environment variable. - signature_type (int , default 0 *(*EOA )) – The Polymarket signature type.
- funder (str , optional) – The wallet address (public key) on the Polygon network used for funding USDC.
If
None
then will source the POLYMARKET_FUNDER environment variable. - api_key (str , optional) – The Polymarket API public key.
If
None
then will source the POLYMARKET_API_KEY environment variable. - api_secret (str , optional) – The Polymarket API public key.
If
None
then will source the POLYMARKET_API_SECRET environment variables. - passphrase (str , optional) – The Polymarket API passphrase.
If
None
then will source the POLYMARKET_PASSPHRASE environment variable. - base_url_http (str , optional) – The HTTP client custom endpoint override.
- base_url_ws (str , optional) – The WebSocket client custom endpoint override.
- max_retries (PositiveInt , optional) – The maximum number of times a submit or cancel order request will be retried.
- retry_delay (PositiveFloat , optional) – The delay (seconds) between retries.
- generate_order_history_from_trades (bool , default False) – If True, uses trades history to generate reports for orders which are no longer active. The Polymarket API only returns active orders and trades. This feature is experimental and is not currently recommended (leave set to False).
venue : Venue
private_key : str | None
signature_type : int
funder : str | None
api_key : str | None
api_secret : str | None
passphrase : str | None
base_url_http : str | None
base_url_ws : str | None
max_retries : Annotated[int, msgspec.Meta(gt=0)] | None
retry_delay : Annotated[float, msgspec.Meta(gt=0.0)] | None
generate_order_history_from_trades : bool
dict() → dict[str, Any]
Return a dictionary representation of the configuration.
- Return type: dict[str, Any]
classmethod fully_qualified_name() → str
Return the fully qualified name for the NautilusConfig class.
- Return type: str
property id : str
Return the hashed identifier for the configuration.
- Return type: str
instrument_provider : InstrumentProviderConfig
json() → bytes
Return serialized JSON encoded bytes.
- Return type: bytes
json_primitives() → dict[str, Any]
Return a dictionary representation of the configuration with JSON primitive types as values.
- Return type: dict[str, Any]
classmethod parse(raw: bytes | str) → Any
Return a decoded object of the given cls.
- Parameters:
- cls (type) – The type to decode to.
- raw (bytes or str) – The raw bytes or JSON string to decode.
- Return type: Any
routing : RoutingConfig
validate() → bool
Return whether the configuration can be represented as valid JSON.
- Return type: bool
Factories
get_polymarket_http_client(api_key: str | None = None, api_secret: str | None = None, passphrase: str | None = None, base_url: str | None = None, chain_id: int = 137, signature_type: int = 0, private_key: str | None = None, funder: str | None = None) → ClobClient
Cache and return a Polymarket CLOB client.
If a cached client with matching parameters already exists, the cached client will be returned.
- Parameters:
- api_key (str , optional) – The API key for the client.
- api_secret (str , optional) – The API secret for the client.
- passphrase (str , optional) – The passphrase for the client.
- base_url (str , optional) – The base URL for the API endpoints.
- chain_id (int , default POLYGON) – The chain ID for the client.
- signature_type (int , default 0 *(*EOA )) – The Polymarket signature type.
- private_key (str , optional) – The private key for the wallet on the Polygon network.
- funder (str , optional) – The wallet address (public key) on the Polygon network used for funding USDC.
- Return type: ClobClient
get_polymarket_instrument_provider(client: ClobClient, clock: LiveClock, config: InstrumentProviderConfig) → PolymarketInstrumentProvider
Cache and return a Polymarket instrument provider.
If a cached provider already exists, then that provider will be returned.
- Parameters:
- client (py_clob_client.client.ClobClient) – The client for the instrument provider.
- clock (LiveClock) – The clock for the instrument provider.
- config (InstrumentProviderConfig) – The configuration for the instrument provider.
- Return type: PolymarketInstrumentProvider
class PolymarketLiveDataClientFactory
Bases: LiveDataClientFactory
Provides a Polymarket live data client factory.
static create(loop: AbstractEventLoop, name: str, config: PolymarketDataClientConfig, msgbus: MessageBus, cache: Cache, clock: LiveClock) → PolymarketDataClient
Create a new Polymarket data client.
- Parameters:
- loop (asyncio.AbstractEventLoop) – The event loop for the client.
- name (str) – The custom client ID.
- config (BybitDataClientConfig) – The client configuration.
- msgbus (MessageBus) – The message bus for the client.
- cache (Cache) – The cache for the client.
- clock (LiveClock) – The clock for the instrument provider.
- Return type: PolymarketDataClient
class PolymarketLiveExecClientFactory
Bases: LiveExecClientFactory
Provides a Polymarket live execution client factory.
static create(loop: AbstractEventLoop, name: str, config: PolymarketExecClientConfig, msgbus: MessageBus, cache: Cache, clock: LiveClock) → PolymarketDataClient
Create a new Polymarket execution client.
- Parameters:
- loop (asyncio.AbstractEventLoop) – The event loop for the client.
- name (str) – The custom client ID.
- config (BybitDataClientConfig) – The client configuration.
- msgbus (MessageBus) – The message bus for the client.
- cache (Cache) – The cache for the client.
- clock (LiveClock) – The clock for the instrument provider.
- Return type: PolymarketDataClient
Enums
class PolymarketSignatureType
Bases: Enum
EOA = 0
POLY_PROXY = 1
POLY_GNOSIS_SAFE = 2
class PolymarketOrderSide
Bases: Enum
BUY = 'BUY'
SELL = 'SELL'
class PolymarketLiquiditySide
Bases: Enum
MAKER = 'MAKER'
TAKER = 'TAKER'
class PolymarketOrderType
Bases: Enum
FOK = 'FOK'
GTC = 'GTC'
GTD = 'GTD'
class PolymarketEventType
Bases: Enum
PLACEMENT = 'PLACEMENT'
UPDATE = 'UPDATE'
CANCELLATION = 'CANCELLATION'
TRADE = 'TRADE'
class PolymarketOrderStatus
Bases: Enum
INVALID = 'INVALID'
LIVE = 'LIVE'
DELAYED = 'DELAYED'
MATCHED = 'MATCHED'
UNMATCHED = 'UNMATCHED'
CANCELED = 'CANCELED'
class PolymarketTradeStatus
Bases: Enum
MATCHED = 'MATCHED'
MINED = 'MINED'
CONFIRMED = 'CONFIRMED'
RETRYING = 'RETRYING'
FAILED = 'FAILED'
Providers
class PolymarketInstrumentProvider
Bases: InstrumentProvider
Provides Nautilus instrument definitions from Polymarket.
- Parameters:
- client (ClobClient) – The Polymarket CLOB HTTP client.
- clock (LiveClock) – The clock instance.
- config (InstrumentProviderConfig , optional) – The instrument provider configuration, by default None.
async load_all_async(filters: dict | None = None) → None
Load the latest instruments into the provider asynchronously, optionally applying the given filters.
async load_ids_async(instrument_ids: list[InstrumentId], filters: dict | None = None) → None
Load the instruments for the given IDs into the provider, optionally applying the given filters.
- Parameters:
- instrument_ids (list [InstrumentId ]) – The instrument IDs to load.
- filters (frozendict *[*str , Any ] or dict *[*str , Any ] , optional) – The venue specific instrument loading filters to apply.
- Raises: ValueError – If any instrument_id.venue is not equal to self.venue.
async load_async(instrument_id: InstrumentId, filters: dict | None = None) → None
Load the instrument for the given ID into the provider asynchronously, optionally applying the given filters.
- Parameters:
- instrument_id (InstrumentId) – The instrument ID to load.
- filters (frozendict *[*str , Any ] or dict *[*str , Any ] , optional) – The venue specific instrument loading filters to apply.
- Raises: ValueError – If instrument_id.venue is not equal to self.venue.
add(instrument: Instrument) → None
Add the given instrument to the provider.
- Parameters: instrument (Instrument) – The instrument to add.
add_bulk(instruments: list[Instrument]) → None
Add the given instruments bulk to the provider.
- Parameters: instruments (list [Instrument ]) – The instruments to add.
add_currency(currency: Currency) → None
Add the given currency to the provider.
- Parameters: currency (Currency) – The currency to add.
property count : int
Return the count of instruments held by the provider.
- Return type: int
currencies() → dict[str, Currency]
Return all currencies held by the instrument provider.
- Return type: dict[str, Currency]
currency(code: str) → Currency | None
Return the currency with the given code (if found).
- Parameters: code (str) – The currency code.
- Return type:
Currency or
None
- Raises: ValueError – If code is not a valid string.
find(instrument_id: InstrumentId) → Instrument | None
Return the instrument for the given instrument ID (if found).
- Parameters: instrument_id (InstrumentId) – The ID for the instrument
- Return type:
Instrument or
None
get_all() → dict[InstrumentId, Instrument]
Return all loaded instruments as a map keyed by instrument ID.
If no instruments loaded, will return an empty dict.
- Return type: dict[InstrumentId, Instrument]
async initialize(reload: bool = False) → None
Initialize the instrument provider.
- Parameters: reload (bool , default False) – If True, then will always reload instruments. If False, then will immediately return if already loaded.
list_all() → list[Instrument]
Return all loaded instruments.
- Return type: list[Instrument]
load(instrument_id: InstrumentId, filters: dict | None = None) → None
Load the instrument for the given ID into the provider, optionally applying the given filters.
- Parameters:
- instrument_id (InstrumentId) – The instrument ID to load.
- filters (frozendict *[*str , Any ] or dict *[*str , Any ] , optional) – The venue specific instrument loading filters to apply.
load_all(filters: dict | None = None) → None
Load the latest instruments into the provider, optionally applying the given filters.
- Parameters: filters (frozendict *[*str , Any ] or dict *[*str , Any ] , optional) – The venue specific instrument loading filters to apply.
load_ids(instrument_ids: list[InstrumentId], filters: dict | None = None) → None
Load the instruments for the given IDs into the provider, optionally applying the given filters.
- Parameters:
- instrument_ids (list [InstrumentId ]) – The instrument IDs to load.
- filters (frozendict *[*str , Any ] or dict *[*str , Any ] , optional) – The venue specific instrument loading filters to apply.
Data
class PolymarketDataClient
Bases: LiveMarketDataClient
Provides a data client for Polymarket, a decentralized predication market.
- Parameters:
- loop (asyncio.AbstractEventLoop) – The event loop for the client.
- http_client (py_clob_client.client.ClobClient) – The Polymarket HTTP client.
- msgbus (MessageBus) – The message bus for the client.
- cache (Cache) – The cache for the client.
- clock (LiveClock) – The clock for the client.
- instrument_provider (PolymarketInstrumentProvider) – The instrument provider.
- config (PolymarketDataClientConfig) – The configuration for the client.
- name (str , optional) – The custom client ID.
connect() → None
Connect the client.
create_task(coro: ~collections.abc.Coroutine, log_msg: str | None = None, actions: ~collections.abc.Callable | None = None, success_msg: str | None = None, success_color: ~nautilus_trader.core.rust.common.LogColor = <LogColor.NORMAL: 0>) → Task
Run the given coroutine with error handling and optional callback actions when done.
- Parameters:
- coro (Coroutine) – The coroutine to run.
- log_msg (str , optional) – The log message for the task.
- actions (Callable , optional) – The actions callback to run when the coroutine is done.
- success_msg (str , optional) – The log message to write on actions success.
- success_color (LogColor, default
NORMAL
) – The log message color for actions success.
- Return type: asyncio.Task
degrade(self) → void
Degrade the component.
While executing on_degrade() any exception will be logged and reraised, then the component
will remain in a DEGRADING
state.
WARNING
Do not override.
If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.
disconnect() → None
Disconnect the client.
dispose(self) → void
Dispose of the component.
While executing on_dispose() any exception will be logged and reraised, then the component
will remain in a DISPOSING
state.
WARNING
Do not override.
If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.
fault(self) → void
Fault the component.
Calling this method multiple times has the same effect as calling it once (it is idempotent). Once called, it cannot be reversed, and no other methods should be called on this instance.
While executing on_fault() any exception will be logged and reraised, then the component
will remain in a FAULTING
state.
WARNING
Do not override.
If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.
classmethod fully_qualified_name(cls) → str
Return the fully qualified name for the components class.
- Return type: str
id
The components ID.
- Returns: ComponentId
is_connected
If the client is connected.
- Returns: bool
is_degraded
bool
Return whether the current component state is DEGRADED
.
- Return type: bool
- Type: Component.is_degraded
is_disposed
bool
Return whether the current component state is DISPOSED
.
- Return type: bool
- Type: Component.is_disposed
is_faulted
bool
Return whether the current component state is FAULTED
.
- Return type: bool
- Type: Component.is_faulted
is_initialized
bool
Return whether the component has been initialized (component.state >= INITIALIZED
).
- Return type: bool
- Type: Component.is_initialized
is_running
bool
Return whether the current component state is RUNNING
.
- Return type: bool
- Type: Component.is_running
is_stopped
bool
Return whether the current component state is STOPPED
.
- Return type: bool
- Type: Component.is_stopped
request(self, DataType data_type, UUID4 correlation_id, dict params=None) → void
Request data for the given data type.
- Parameters:
request_bars(self, BarType bar_type, int limit, UUID4 correlation_id, datetime start=None, datetime end=None, dict params=None) → void
Request historical Bar data. To load historical data from a catalog, you can pass a list[DataCatalogConfig] to the TradingNodeConfig or the BacktestEngineConfig.
- Parameters:
- bar_type (BarType) – The bar type for the request.
- limit (int) – The limit for the number of returned bars.
- correlation_id (UUID4) – The correlation ID for the request.
- start (datetime , optional) – The start datetime (UTC) of request time range (inclusive).
- end (datetime , optional) – The end datetime (UTC) of request time range. The inclusiveness depends on individual data client implementation.
- params (dict *[*str , Any ] , optional) – Additional params to be sent with the request.
request_instrument(self, InstrumentId instrument_id, UUID4 correlation_id, datetime start=None, datetime end=None, dict params=None) → void
Request Instrument data for the given instrument ID.
- Parameters:
- instrument_id (InstrumentId) – The instrument ID for the request.
- correlation_id (UUID4) – The correlation ID for the request.
- start (datetime , optional) – The start datetime (UTC) of request time range (inclusive).
- end (datetime , optional) – The end datetime (UTC) of request time range. The inclusiveness depends on individual data client implementation.
- params (dict *[*str , Any ] , optional) – Additional params to be sent with the request.
request_instruments(self, Venue venue, UUID4 correlation_id, datetime start=None, datetime end=None, dict params=None) → void
Request all Instrument data for the given venue.
- Parameters:
- venue (Venue) – The venue for the request.
- correlation_id (UUID4) – The correlation ID for the request.
- start (datetime , optional) – The start datetime (UTC) of request time range (inclusive).
- end (datetime , optional) – The end datetime (UTC) of request time range. The inclusiveness depends on individual data client implementation.
- params (dict *[*str , Any ] , optional) – Additional params to be sent with the request.
request_order_book_snapshot(self, InstrumentId instrument_id, int limit, UUID4 correlation_id, dict params=None) → void
Request order book snapshot data.
- Parameters:
- instrument_id (InstrumentId) – The instrument ID for the order book snapshot request.
- limit (int) – The limit on the depth of the order book snapshot.
- correction_id (UUID4) – The correlation ID for the request.
request_quote_ticks(self, InstrumentId instrument_id, int limit, UUID4 correlation_id, datetime start=None, datetime end=None, dict params=None) → void
Request historical QuoteTick data.
- Parameters:
- instrument_id (InstrumentId) – The tick instrument ID for the request.
- limit (int) – The limit for the number of returned ticks.
- correlation_id (UUID4) – The correlation ID for the request.
- start (datetime , optional) – The start datetime (UTC) of request time range (inclusive).
- end (datetime , optional) – The end datetime (UTC) of request time range. The inclusiveness depends on individual data client implementation.
- params (dict *[*str , Any ] , optional) – Additional params to be sent with the request.
request_trade_ticks(self, InstrumentId instrument_id, int limit, UUID4 correlation_id, datetime start=None, datetime end=None, dict params=None) → void
Request historical TradeTick data.
- Parameters:
- instrument_id (InstrumentId) – The tick instrument ID for the request.
- limit (int) – The limit for the number of returned ticks.
- correlation_id (UUID4) – The correlation ID for the request.
- start (datetime , optional) – The start datetime (UTC) of request time range (inclusive).
- end (datetime , optional) – The end datetime (UTC) of request time range. The inclusiveness depends on individual data client implementation.
- params (dict *[*str , Any ] , optional) – Additional params to be sent with the request.
reset(self) → void
Reset the component.
All stateful fields are reset to their initial value.
While executing on_reset() any exception will be logged and reraised, then the component
will remain in a RESETTING
state.
WARNING
Do not override.
If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.
resume(self) → void
Resume the component.
While executing on_resume() any exception will be logged and reraised, then the component
will remain in a RESUMING
state.
WARNING
Do not override.
If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.
async run_after_delay(delay: float, coro: Coroutine) → None
Run the given coroutine after a delay.
- Parameters:
- delay (float) – The delay (seconds) before running the coroutine.
- coro (Coroutine) – The coroutine to run after the initial delay.
shutdown_system(self, unicode reason=None) → void
Initiate a system-wide shutdown by generating and publishing a ShutdownSystem command.
The command is handled by the system’s NautilusKernel, which will invoke either stop (synchronously) or stop_async (asynchronously) depending on the execution context and the presence of an active event loop.
- Parameters: reason (str , optional) – The reason for issuing the shutdown command.
start(self) → void
Start the component.
While executing on_start() any exception will be logged and reraised, then the component
will remain in a STARTING
state.
WARNING
Do not override.
If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.
state
ComponentState
Return the components current state.
- Return type: ComponentState
- Type: Component.state
stop(self) → void
Stop the component.
While executing on_stop() any exception will be logged and reraised, then the component
will remain in a STOPPING
state.
WARNING
Do not override.
If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.
subscribe(self, DataType data_type, dict params=None) → void
Subscribe to data for the given data type.
- Parameters: data_type (DataType) – The data type for the subscription.
subscribe_bars(self, BarType bar_type, dict params=None) → void
Subscribe to Bar data for the given bar type.
- Parameters:
- bar_type (BarType) – The bar type to subscribe to.
- params (dict *[*str , Any ] , optional) – Additional params for the subscription.
subscribe_instrument(self, InstrumentId instrument_id, dict params=None) → void
Subscribe to the Instrument with the given instrument ID.
- Parameters: params (dict *[*str , Any ] , optional) – Additional params for the subscription.
subscribe_instrument_close(self, InstrumentId instrument_id, dict params=None) → void
Subscribe to InstrumentClose updates for the given instrument ID.
- Parameters:
- instrument_id (InstrumentId) – The tick instrument to subscribe to.
- params (dict *[*str , Any ] , optional) – Additional params for the subscription.
subscribe_instrument_status(self, InstrumentId instrument_id, dict params=None) → void
Subscribe to InstrumentStatus data for the given instrument ID.
- Parameters:
- instrument_id (InstrumentId) – The tick instrument to subscribe to.
- params (dict *[*str , Any ] , optional) – Additional params for the subscription.
subscribe_instruments(self, dict params=None) → void
Subscribe to all Instrument data.
- Parameters: params (dict *[*str , Any ] , optional) – Additional params for the subscription.
subscribe_order_book_deltas(self, InstrumentId instrument_id, BookType book_type, int depth=0, dict params=None) → void
Subscribe to OrderBookDeltas data for the given instrument ID.
- Parameters:
- instrument_id (InstrumentId) – The order book instrument to subscribe to.
- book_type (BookType {
L1_MBP
,L2_MBP
,L3_MBO
}) – The order book type. - depth (int , optional , default None) – The maximum depth for the subscription.
- params (dict *[*str , Any ] , optional) – Additional params for the subscription.
subscribe_order_book_snapshots(self, InstrumentId instrument_id, BookType book_type, int depth=0, dict params=None) → void
Subscribe to OrderBook snapshots data for the given instrument ID.
- Parameters:
- instrument_id (InstrumentId) – The order book instrument to subscribe to.
- book_type (BookType {
L1_MBP
,L2_MBP
,L3_MBO
}) – The order book level. - depth (int , optional) – The maximum depth for the order book. A depth of 0 is maximum depth.
- params (dict *[*str , Any ] , optional) – Additional params for the subscription.
subscribe_quote_ticks(self, InstrumentId instrument_id, dict params=None) → void
Subscribe to QuoteTick data for the given instrument ID.
- Parameters:
- instrument_id (InstrumentId) – The tick instrument to subscribe to.
- params (dict *[*str , Any ] , optional) – Additional params for the subscription.
subscribe_trade_ticks(self, InstrumentId instrument_id, dict params=None) → void
Subscribe to TradeTick data for the given instrument ID.
- Parameters:
- instrument_id (InstrumentId) – The tick instrument to subscribe to.
- params (dict *[*str , Any ] , optional) – Additional params for the subscription.
subscribed_bars(self) → list
Return the bar types subscribed to.
- Return type: list[BarType]
subscribed_custom_data(self) → list
Return the custom data types subscribed to.
- Return type: list[DataType]
subscribed_instrument_close(self) → list
Return the instrument closes subscribed to.
- Return type: list[InstrumentId]
subscribed_instrument_status(self) → list
Return the status update instruments subscribed to.
- Return type: list[InstrumentId]
subscribed_instruments(self) → list
Return the instruments subscribed to.
- Return type: list[InstrumentId]
subscribed_order_book_deltas(self) → list
Return the order book delta instruments subscribed to.
- Return type: list[InstrumentId]
subscribed_order_book_snapshots(self) → list
Return the order book snapshot instruments subscribed to.
- Return type: list[InstrumentId]
subscribed_quote_ticks(self) → list
Return the quote tick instruments subscribed to.
- Return type: list[InstrumentId]
subscribed_trade_ticks(self) → list
Return the trade tick instruments subscribed to.
- Return type: list[InstrumentId]
trader_id
The trader ID associated with the component.
- Returns: TraderId
type
The components type.
- Returns: type
unsubscribe(self, DataType data_type, dict params=None) → void
Unsubscribe from data for the given data type.
- Parameters: data_type (DataType) – The data type for the subscription.
unsubscribe_bars(self, BarType bar_type, dict params=None) → void
Unsubscribe from Bar data for the given bar type.
- Parameters:
- bar_type (BarType) – The bar type to unsubscribe from.
- params (dict *[*str , Any ] , optional) – Additional params for the subscription.
unsubscribe_instrument(self, InstrumentId instrument_id, dict params=None) → void
Unsubscribe from Instrument data for the given instrument ID.
- Parameters:
- instrument_id (InstrumentId) – The instrument to unsubscribe from.
- params (dict *[*str , Any ] , optional) – Additional params for the subscription.
unsubscribe_instrument_close(self, InstrumentId instrument_id, dict params=None) → void
Unsubscribe from InstrumentClose data for the given instrument ID.
- Parameters:
- instrument_id (InstrumentId) – The tick instrument to unsubscribe from.
- params (dict *[*str , Any ] , optional) – Additional params for the subscription.
unsubscribe_instrument_status(self, InstrumentId instrument_id, dict params=None) → void
Unsubscribe from InstrumentStatus data for the given instrument ID.
- Parameters:
- instrument_id (InstrumentId) – The instrument status updates to unsubscribe from.
- params (dict *[*str , Any ] , optional) – Additional params for the subscription.
unsubscribe_instruments(self, dict params=None) → void
Unsubscribe from all Instrument data.
- Parameters: params (dict *[*str , Any ] , optional) – Additional params for the subscription.
unsubscribe_order_book_deltas(self, InstrumentId instrument_id, dict params=None) → void
Unsubscribe from OrderBookDeltas data for the given instrument ID.
- Parameters:
- instrument_id (InstrumentId) – The order book instrument to unsubscribe from.
- params (dict *[*str , Any ] , optional) – Additional params for the subscription.
unsubscribe_order_book_snapshots(self, InstrumentId instrument_id, dict params=None) → void
Unsubscribe from OrderBook snapshots data for the given instrument ID.
- Parameters:
- instrument_id (InstrumentId) – The order book instrument to unsubscribe from.
- params (dict *[*str , Any ] , optional) – Additional params for the subscription.
unsubscribe_quote_ticks(self, InstrumentId instrument_id, dict params=None) → void
Unsubscribe from QuoteTick data for the given instrument ID.
- Parameters:
- instrument_id (InstrumentId) – The tick instrument to unsubscribe from.
- params (dict *[*str , Any ] , optional) – Additional params for the subscription.
unsubscribe_trade_ticks(self, InstrumentId instrument_id, dict params=None) → void
Unsubscribe from TradeTick data for the given instrument ID.
- Parameters:
- instrument_id (InstrumentId) – The tick instrument to unsubscribe from.
- params (dict *[*str , Any ] , optional) – Additional params for the subscription.
venue
The clients venue ID (if applicable).
- Returns:
Venue or
None
Execution
class PolymarketExecutionClient
Bases: LiveExecutionClient
Provides an execution client for Polymarket, a decentralized predication market.
- Parameters:
- loop (asyncio.AbstractEventLoop) – The event loop for the client.
- http_client (py_clob_client.client.ClobClient) – The Polymarket HTTP client.
- msgbus (MessageBus) – The message bus for the client.
- cache (Cache) – The cache for the client.
- clock (LiveClock) – The clock for the client.
- instrument_provider (PolymarketInstrumentProvider) – The instrument provider.
- config (PolymarketExecClientConfig) – The configuration for the client.
- name (str , optional) – The custom client ID.
async generate_order_status_reports(instrument_id: InstrumentId | None = None, start: Timestamp | None = None, end: Timestamp | None = None, open_only: bool = False) → list[OrderStatusReport]
Generate a list of
`
OrderStatusReport`s with optional query filters.
The returned list may be empty if no orders match the given parameters.
- Parameters:
- instrument_id (InstrumentId , optional) – The instrument ID query filter.
- start (pd.Timestamp , optional) – The start datetime (UTC) query filter.
- end (pd.Timestamp , optional) – The end datetime (UTC) query filter.
- open_only (bool , default False) – If the query is for open orders only.
- Return type: list[OrderStatusReport]
async generate_order_status_report(instrument_id: InstrumentId, client_order_id: ClientOrderId | None = None, venue_order_id: VenueOrderId | None = None) → OrderStatusReport | None
Generate an OrderStatusReport for the given order identifier parameter(s).
If the order is not found, or an error occurs, then logs and returns None
.
- Parameters:
- instrument_id (InstrumentId) – The instrument ID for the report.
- client_order_id (ClientOrderId , optional) – The client order ID for the report.
- venue_order_id (VenueOrderId , optional) – The venue order ID for the report.
- Return type:
OrderStatusReport or
None
- Raises:
ValueError – If both the client_order_id and venue_order_id are
None
.
async generate_fill_reports(instrument_id: InstrumentId | None = None, venue_order_id: VenueOrderId | None = None, start: Timestamp | None = None, end: Timestamp | None = None) → list[FillReport]
Generate a list of
`
FillReport`s with optional query filters.
The returned list may be empty if no trades match the given parameters.
- Parameters:
- instrument_id (InstrumentId , optional) – The instrument ID query filter.
- venue_order_id (VenueOrderId , optional) – The venue order ID (assigned by the venue) query filter.
- start (pd.Timestamp , optional) – The start datetime (UTC) query filter.
- end (pd.Timestamp , optional) – The end datetime (UTC) query filter.
- Return type: list[FillReport]
async generate_position_status_reports(instrument_id: InstrumentId | None = None, start: Timestamp | None = None, end: Timestamp | None = None) → list[PositionStatusReport]
Generate a list of
`
PositionStatusReport`s with optional query filters.
The returned list may be empty if no positions match the given parameters.
- Parameters:
- instrument_id (InstrumentId , optional) – The instrument ID query filter.
- start (pd.Timestamp , optional) – The start datetime (UTC) query filter.
- end (pd.Timestamp , optional) – The end datetime (UTC) query filter.
- Return type: list[PositionStatusReport]
account_id
The clients account ID.
- Returns:
AccountId or
None
account_type
The clients account type.
- Returns: AccountType
base_currency
The clients account base currency (None for multi-currency accounts).
- Returns:
Currency or
None
batch_cancel_orders(self, BatchCancelOrders command) → void
Batch cancel orders for the instrument ID contained in the given command.
- Parameters: command (BatchCancelOrders) – The command to execute.
cancel_all_orders(self, CancelAllOrders command) → void
Cancel all orders for the instrument ID contained in the given command.
- Parameters: command (CancelAllOrders) – The command to execute.
cancel_order(self, CancelOrder command) → void
Cancel the order with the client order ID contained in the given command.
- Parameters: command (CancelOrder) – The command to execute.
connect() → None
Connect the client.
create_task(coro: ~collections.abc.Coroutine, log_msg: str | None = None, actions: ~collections.abc.Callable | None = None, success_msg: str | None = None, success_color: ~nautilus_trader.core.rust.common.LogColor = <LogColor.NORMAL: 0>) → Task
Run the given coroutine with error handling and optional callback actions when done.
- Parameters:
- coro (Coroutine) – The coroutine to run.
- log_msg (str , optional) – The log message for the task.
- actions (Callable , optional) – The actions callback to run when the coroutine is done.
- success_msg (str , optional) – The log message to write on actions success.
- success_color (str, default
NORMAL
) – The log message color for actions success.
- Return type: asyncio.Task
degrade(self) → void
Degrade the component.
While executing on_degrade() any exception will be logged and reraised, then the component
will remain in a DEGRADING
state.
WARNING
Do not override.
If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.
disconnect() → None
Disconnect the client.
dispose(self) → void
Dispose of the component.
While executing on_dispose() any exception will be logged and reraised, then the component
will remain in a DISPOSING
state.
WARNING
Do not override.
If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.