> For the complete documentation index, see [llms.txt](https://learn.trovemarkets.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.trovemarkets.com/trove-x-polymarkets/polymarket-oracle.md).

# Polymarket Oracle

### Data sources from Polymarket

Polymarket exposes multiple data feeds that can be used to compute `p_ref`:

#### 1) WebSocket (low latency)

Use for real-time orderbook updates, price changes, and last trade prices.

Example endpoint (market channel):

```
wss://ws-subscriptions-clob.polymarket.com/ws/market
```

You subscribe with the outcome token ID(s) you care about (e.g., YES token ID).

#### 2) Gamma API (metadata + indexing)

Use for:

* market discovery (active markets)
* mapping from condition/event to outcome tokens
* reading current outcome prices in a simple format

#### 3) Onchain data (resolution + settlement events)

For resolution-aware operations, monitor:

* resolution events
* final outcome publication
* redemption conditions

***

### Reference signal definition

Trove defines a reference signal per market:

* `p_ref` = the probability-like value used as oracle/index input

Common choices:

* Midpoint price of YES token (best bid/ask midpoint)
* A short EMA of midpoint (to reduce microstructure noise)
* A robust median across multiple snapshots (to reduce spikes)

> For binary markets, token prices are commonly interpreted within `[0, 1]` as probability-like values. Trove normalizes the signal to `[0, 1]` for “probability perps”.

***

### Operational requirements for HIP-3

HIP-3 requires continuous oracle updates.

Trove runs an **oracle pusher** service that:

1. Fetches Polymarket data (WebSocket preferred, REST fallback)
2. Computes `p_ref` (and optionally a smoothed external reference)
3. Submits HIP-3 `setOracle` updates to Hyperliquid on a fixed cadence
4. Maintains redundancy (multiple feeds / regions / automated failover)

***

### Security and robustness checklist

* Use multi-region WebSocket + REST fallback
* Track sequence numbers and rebuild local orderbook if out-of-sync
* Enforce strict `[0, 1]` bounds post-processing
* Add circuit breakers (halt trading) on:
  * feed outage beyond a threshold
  * abnormal deviations / corrupted data
* Log every update and keep an audit trail for post-incident review


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learn.trovemarkets.com/trove-x-polymarkets/polymarket-oracle.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
