# Public Exchange Data

Some data is provided by the exchange without requiring authorization, including:

1. Async API Heartbeat
2. Matcher State
3. Instruments List
4. Coin Price Feed
5. Funding Rate Updates
6. Order Book Depth
7. Order Book Best
8. Last Trades

## Available environments

All channel names have an `{env}` prefix showing the current environment.

* `futures-perp-dev` — for the Development environment
* `futures-perp-demo` — for the Demo environment
* `futures-perp-beta` — for the Beta environment
* `futures-perp` — for the Production environment

## Heartbeat

To check the availability of the exchange's Async API, the `{env}:heartbeat` channel is used, which periodically sends events with the current timestamp.

<details>

<summary>Async API Heartbeat Event Format</summary>

```ts
interface HeartbeatEvent {
  t: number;
}
```

</details>

**Important:** If no events are received on this channel for more than 30 seconds, the connection to the Async API should be considered lost.

## Matcher State

In some cases, trading may be globally paused for all instruments. To detect such states, use the [GET /api/market](https://swagger.evedex.com/?urls.primaryName=Exchange#/Market/get_api_market) method, which returns the current exchange state (`state` field).

The exchange signals state changes via Async API using the `{env}:info` channel, which transmits snapshots of the current state.

<details>

<summary>Async API Matcher State Event Format</summary>

```ts
enum MatcherState {
  Active = "active",
  RequestStatusFail = "request-status-fail",
  MeDead = "me-dead",
  DbAdminDead = "db-admin-dead",
}

interface MatcherUpdateEvent {
  state: MatcherState;
  updatedAt: string;
}
```

</details>

**Important:** Any state other than `active` should be treated as a global trading halt.

## Instruments List

To get a list of instruments available for trading, use the [GET /api/market/instrument](https://swagger.evedex.com/?urls.primaryName=Exchange#/Market/get_api_market_instrument) method. This returns an array of all instruments registered on the exchange (including those not available for trading).

**Important:** If the `trading` field is `none` or `restricted`, the instrument should be considered unavailable for any orders. `onlyClose` means it is only available for position closing and order cancellation. Otherwise, the instrument is available for trading.

Instrument state updates are signaled via Async API on the `{env}:instruments` channel with snapshots of current instrument state.

<details>

<summary>Async API Instrument Event Format</summary>

```ts
enum Trading {
  All = 'all',
  Restricted = 'restricted',
  None = 'none',
  OnlyClose = 'onlyClose',
}

enum Visibility {
  All = 'all',
  Restricted = 'restricted',
  None = 'none',
}

interface InstrumentUpdateEvent {
  id: string;
  name: string;
  displayName: string;
  lastPrice: number;
  high: number;
  low: number;
  volume: number;
  volumeBase: number;
  closePrice: number;
  markPrice: number;
  openInterest: number;
  minPrice: number;
  maxPrice: number;
  fatFingerPriceProtection: number;
  slippageLimit: number;
  trading: Trading;
  visibility: Visibility;
  updatedAt: Date;
}
```

</details>

**Important:** To ensure state consistency on the client, compare snapshots by the `updatedAt` field.

## Coin Price Feed

For the Index Price calculation the following approach should be used:

1. Get the instrument price from the `from.avgLastPrice` field of the REST endpoint [GET /api/market/instrument](https://swagger.evedex.com/?urls.primaryName=Exchange#/Market/get_api_market_instrument) response.
2. Calculate the Index Price as the following:

```ts
  const indexPrice = Big(avgLastPrice ?? 0)
    .mul(pair.lotSize)
    .toNumber();
```

3. Get real-time updates on the Index Price (calculating it using the `lotSize` attribute) using the `{env}:coin-price` WS channel.

```ts
export interface CoinPriceFeed {
  id: string;
  coin: string;
  price: number;
  source: PriceFeedSource;
  createdAt: Date;
}
CoinPriceFeed[]
```

## Funding Rate

To get the current funding rate for an instrument, use the [GET /api/market/instrument](https://swagger.evedex.com/?urls.primaryName=Exchange#/Market/get_api_market_instrument) method with `fields=metrics`. This returns all instruments with additional metrics.

**Important:** This method is relatively heavy and should not be used frequently or during initial client load.

Funding rate updates are sent via Async API using the `{env}:funding-rate` channel.

<details>

<summary>Async API Funding Rate Event Format</summary>

```ts
interface FundingRateEvent {
    instrument: string;
    fundingRate: string;
    createdAt: number;
}
```

</details>

**Important:** To ensure funding rate state consistency on the client, compare snapshots by the `createdAt` field.

## Order Book Depth

To get the current state of the order book, use the [GET api/market/{instrument}/deep](https://swagger.evedex.com/?urls.primaryName=Exchange#/Market/get_api_market__instrument__deep) method, which returns grouped volume data by price levels (up to 4 decimal places).

Order book updates are sent via Async API on the `{env}:orderBook-{instrument}-0.1` channel.

<details>

<summary>Async API Order Book Depth Event Format</summary>

```ts
interface MarketDepthLevel {
  price: number;
  quantity: number;
}

interface MarketDepth {
  t: number;
  asks: Array<MarketDepthLevel>;
  bids: Array<MarketDepthLevel>;
}

interface OrderBookDepthUpdateEvent {
  instrument: string
  orderBook: MarketDepth
}
```

</details>

**Important:** To ensure consistency of the order book state on the client, compare snapshots by the `orderBook.t` timestamp field.

## Order Book Best

To get the best bid and ask prices, use the same REST API method as for order book depth but with the `marketLevel=1` parameter.

Best price updates are sent via Async API using the `{env}:orderBook-{instrument}-best` channel. The event format matches the previous section.

## Last Trades

To get a list of recent trades on the exchange, use the [GET /api/market/{instrument}/recent-trades](https://swagger.evedex.com/?urls.primaryName=Exchange#/Market/get_api_market__instrument__recent_trades) method. This returns anonymized trades for a specific instrument.

Trade updates are sent via Async API using the `{env}:recent-trade-{instrument}` channel.

<details>

<summary>Async API Last Trades Event Format</summary>

```ts
interface Trade {
  instrument: string;
  side: cryptoUtils.Side;
  fillQuantity: number;
  fillPrice: number;
  createdAt: string;
}
```

</details>


---

# Agent Instructions: 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://docs.evedex.com/developers/developers/public_exchange_data.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.
