Skip to content

feat(oracle-worker): OKX REST price fetcher #172

@IbrahimIjai

Description

@IbrahimIjai

Context

The oracle currently aggregates prices from Binance, Coinbase, and Pyth. Adding OKX as a fourth source improves median robustness — a single exchange outage or manipulation attempt now has to beat three other sources instead of two before it can skew the aggregated price.

OKX public ticker API requires no API key for spot prices.

Implementation

Add `oracle/src/sources/okx.rs` following the same interface pattern as the existing fetchers:

GET https://www.okx.com/api/v5/market/ticker?instId=<SYMBOL>-USDT

Response field: `data[0].last` (string, USD price).

  • Map SO4 token symbols to OKX instrument IDs via the `PRICE_FEED_CONFIG` `sources` field (add `"okx"` as a valid source name)
  • Parse the price string to `i128` at `FLOAT_PRECISION`
  • Plug into the existing `aggregate_prices` pipeline alongside Binance, Coinbase, and Pyth

Acceptance criteria

  • `oracle/src/sources/okx.rs` implemented with the same `fetch_prices(symbols) → HashMap<String, i128>` signature as other fetchers
  • OKX optionally included per token via `PRICE_FEED_CONFIG` `"sources": ["okx"]`
  • HTTP errors and JSON parse failures return `Err`, do not panic
  • Unit test with a mocked HTTP response covering happy path and error path
  • OKX prices flow through outlier rejection and median aggregation correctly

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestoracle-workerCloudflare Worker oracle crate

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions