Skip to main content

Requirements

  • Node.js 18 or higher
  • npm

Installation

1

Install the dependency

The SDK uses eventsource-client for SSE streaming with auto-reconnect and async iterator support.
2

Copy the SDK files

Download polyedge.js and parser_compact_tx.js from the PolyEdge examples repository and copy them into your project directory.

Instantiation

Import PolyEdgeClient and pass your API key. The base URL defaults to https://api.polyedge.dev/v1.
You can also pass a custom base URL as the second argument:
Your API key is sent on every request via the X-PolyEdge-Key header.

Methods

Retrieve the trader leaderboard, optionally filtered and sorted.
Parameters — all optional:Returns a Promise<Object>.
Get a trader’s detailed profile including tags, stats, and metadata.
Returns a Promise<Object>.
Retrieve a trader’s trading history aggregated by market.
Returns a Promise<Object>.
Retrieve a specific trader’s order history within a specific market.
Returns a Promise<Object>.
Get hourly aggregated performance data for a specific trader.
Returns a Promise<Object>.
Retrieve detailed information about a specific market.
Returns a Promise<Object>.
Subscribe to live mempool orders via SSE. Returns an async generator that yields parsed order objects.
Break out of the loop at any time — the underlying SSE connection is closed automatically in the generator’s finally block.Parameters — all optional:Returns AsyncGenerator<Object, void, unknown>.
When format is omitted, each yielded value is the output of parseCompactTx — a fully structured JavaScript object. See Compact format parsing below.

Compact format parsing

By default, streamOrders receives events in a compact array format optimised for low bandwidth. The parser_compact_tx.js utility converts each raw array into a structured object before yielding it. The parsed object has this shape:
USDC and shares values are returned as raw strings in 1e6 format. Divide by 1e6 to convert to human-readable amounts: Number(order.takerOrder.usdc) / 1e6.
If you prefer fully structured JSON from the API rather than parsing compact arrays yourself, pass format: 'json' to streamOrders — the raw response is yielded directly without calling the parser.

Complete example

The following example exercises every method in the SDK, then opens the SSE stream and prints the first three events.