# setOracleUpdates

`setOracleUpdates` is a live-only stream. It does not support replay on reconnect, and live messages currently use `"cursor": "0"`.

### Subscribe

```json
{
    "type": "subscribe",
    "subscription": {
        "type": "setOracleUpdates",
        "dex": "vntls"
    }
}
```

### Unsubscribe

```json
{
    "type": "unsubscribe",
    "subscription": {
        "type": "setOracleUpdates",
        "dex": "vntls"
    }
}
```

### setOracle update format

## Succesful

```json
{
  "type": "setOracleUpdates",
  "seq": 1,
  "cursor": "0",
  "updates": [
    {
      "block_time": "2025-10-06T14:56:40.274583420",
      "dex": "vntls",
      "success": true,
      "error": null,
      "oracle_pxs": [
        ["vntls:vANDRL", "52.146"],
        ["vntls:vANTHRPC", "206.71"],
        ["vntls:vCLUELY", "0.111"]
      ],
      "mark_pxs": [
        [
          ["vntls:vANDRL", "50.809"],
          ["vntls:vANTHRPC", "208.32"],
          ["vntls:vCLUELY", "0.1"]
        ],
        [
          ["vntls:vANDRL", "50.809"],
          ["vntls:vANTHRPC", "208.32"],
          ["vntls:vCLUELY", "0.1"]
        ]
      ],
      "external_perp_pxs": [
        ["vntls:vANDRL", "50.809"],
        ["vntls:vANTHRPC", "208.32"],
        ["vntls:vCHAIN", "2.2"]
      ]
    }
  ]
}
```

### Failed

```json
{
  "type": "setOracleUpdates",
  "seq": 2,
  "cursor": "0",
  "updates": [
    {
      "block_time": "2025-10-06T14:57:44.736855156",
      "dex": "qwerty",
      "success": false,
      "error": "Invalid oracle updater",
      "oracle_pxs": [
        ["qwerty:BTC", "124486.0"]
      ],
      "mark_pxs": [
        [
          ["qwerty:BTC", "0"]
        ]
      ],
      "external_perp_pxs": [
        ["qwerty:BTC", "124546.2"]
      ]
    }
  ]
}
```

### Examples

{% tabs %}
{% tab title="Javascript" %}

```js
const WebSocket = require('ws');

const ws = new WebSocket(`wss://api-testnet.hydromancer.xyz/ws?token=${process.env.HYDROMANCER_API_KEY}`);

ws.on('open', () => {
    console.log('WebSocket connection opened');
});

ws.on('error', (error) => {
    console.error('WebSocket error:', error);
});

ws.on('close', () => {
    console.log('WebSocket connection closed');
});

ws.on('message', (data) => {
    const msg = JSON.parse(data);
    console.log('Received message:', msg.type, msg);

    if (msg.type === 'connected') {
        // Subscribe to oracle updates for vntls DEX
        console.log('Subscribing to setOracleUpdates...');
        ws.send(JSON.stringify({
            type: 'subscribe',
            subscription: {
                type: 'setOracleUpdates',
                dex: 'vntls'
            }
        }));
    } else if (msg.type === 'ping') {
        ws.send(JSON.stringify({ type: 'pong' }));
    } else if (msg.type === 'setOracleUpdates') {
        msg.updates.forEach(update => {
            console.log(`setOracle update for ${update.dex} at ${update.block_time}`);
            console.log(`Success: ${update.success}`);
            if (update.error) {
                console.log(`Error: ${update.error}`);
            }
            console.log(`Oracle prices: ${update.oracle_pxs.length} assets`);
            console.log(`Mark price tiers: ${update.mark_pxs.length}`);
            console.log(`External perp prices: ${update.external_perp_pxs.length} assets`);
        });
    }
});
```

{% endtab %}

{% tab title="Python" %}

```python
import websocket
import json
import os

def on_message(ws, message):
    msg = json.loads(message)

    if msg['type'] == 'connected':
        ws.send(json.dumps({
            "type": "subscribe",
            "subscription": {
                "type": "setOracleUpdates",
                "dex": "vntl"
            }
        }))
    elif msg['type'] == 'ping':
        print("Received ping, sending pong")
        ws.send(json.dumps({'type': 'pong'}))
    elif msg['type'] == 'setOracleUpdates':
        for update in msg['updates']:
            print(f"\nOracle update for {update['dex']} at {update['block_time']}")
            print(f"Success: {update['success']}")
            if update.get('error'):
                print(f"Error: {update['error']}")
            print(f"Oracle prices: {len(update['oracle_pxs'])} assets")
            print(f"Mark price tiers: {len(update['mark_pxs'])} with length {len(update['mark_pxs'][0])}")
            print(f"External perp prices: {len(update['external_perp_pxs'])} assets")
    elif msg['type'] == 'subscriptionUpdate':
        print(f"Subscription update: {msg}")
    elif msg['type'] == 'error':
        print(f"Error: {msg}")

API_KEY = os.environ.get('HYDROMANCER_API_KEY')
ws = websocket.WebSocketApp(f'wss://api.hydromancer.xyz/ws?token={API_KEY}',
                            on_message=on_message)
ws.run_forever()
```

{% endtab %}
{% endtabs %}


---

# 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.hydromancer.xyz/readme/websocket/setoracleupdates.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.
