> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ngnmarket.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Forex Rates

> Live updates over WebSocket for current NGN exchange rates.

```
wss://api.ngnmarket.com/v1/ws/forex
```

This pushes current exchange rates whenever they change, with the same derived fields [`GET /forex/current`](/api-reference/forex/current) computes: inverse rate and day-over-day change. No query parameters.

The REST endpoint scopes to one `?target=` currency at a time; this channel sends every currency pair for every target at once, and `target_currency` on each entry tells you which one it is.

```
wss://api.ngnmarket.com/v1/ws/forex?api_key=ngm_live_YOUR_KEY
```

<CodeGroup>
  ```javascript Browser theme={null}
  const ws = new WebSocket(
    'wss://api.ngnmarket.com/v1/ws/forex?api_key=ngm_live_YOUR_KEY'
  );

  ws.onmessage = (event) => {
    const msg = JSON.parse(event.data);
    console.log(msg.type, msg.rates);
  };
  ```

  ```javascript Node.js theme={null}
  import WebSocket from 'ws';

  const ws = new WebSocket(
    'wss://api.ngnmarket.com/v1/ws/forex?api_key=ngm_live_YOUR_KEY'
  );

  ws.on('message', (data) => {
    const msg = JSON.parse(data.toString());
    console.log(msg.type, msg.rates);
  });
  ```

  ```python Python theme={null}
  import asyncio
  import json
  import websockets

  async def main():
      url = "wss://api.ngnmarket.com/v1/ws/forex?api_key=ngm_live_YOUR_KEY"
      async with websockets.connect(url) as ws:
          async for raw in ws:
              msg = json.loads(raw)
              print(msg["type"], msg["rates"])

  asyncio.run(main())
  ```
</CodeGroup>

## Message format

`snapshot` arrives once on connect with every currency pair's current rate. `update` arrives whenever any rate changes, and always carries the full list.

```json theme={null}
{
  "type": "update",
  "rates": [
    {
      "currency": "USD",
      "target_currency": "NGN",
      "rate": 1580.25,
      "inverse_rate": 0.000633,
      "daily_change": 2.15,
      "daily_change_percent": 0.1364,
      "last_updated": "2026-08-21",
      "last_updated_timestamp": 1787392834000
    },
    {
      "currency": "GBP",
      "target_currency": "NGN",
      "rate": 2015.80,
      "inverse_rate": 0.000496,
      "daily_change": -3.40,
      "daily_change_percent": -0.1684,
      "last_updated": "2026-08-21",
      "last_updated_timestamp": 1787392834000
    }
  ]
}
```

See [Errors](/websocket/errors) for connection-level error codes. This channel takes no parameters, so nothing about it specifically can fail.
