# Order Updates

Use this stream for private order lifecycle events.

### Endpoint

```
wss://order-service.outpoll.com/order/ws
```

### Authentication

Send this message right after connect.

```json
{
  "t": "AUTH",
  "d": {
    "apiKey": "<API_KEY>",
    "signature": "<SIGNATURE>",
    "timestamp": "<UNIX_EPOCH_SECONDS>"
  }
}
```

Build `signature` from `timestamp + "GET" + "/order/ws"`.

Success response:

```json
{
  "t": "success",
  "d": "authorized",
  "r": null
}
```

Failure response:

```json
{
  "t": "error",
  "d": {
    "error": "Invalid or missing credentials"
  }
}
```

### Order event

```json
{
  "t": "ORDER_UPDATE",
  "d": {
    "i": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "u": "user-id",
    "s": "SUCCESS"
  }
}
```

| Field | Type   | Description                   |
| ----- | ------ | ----------------------------- |
| `d.i` | string | Order ID                      |
| `d.u` | string | User ID                       |
| `d.s` | string | Status. `SUCCESS` or `FAILED` |

### TP/SL event

```json
{
  "t": "TPSL_UPDATE",
  "d": {
    "i": "order-id",
    "u": "user-id",
    "a": "asset-id",
    "q": 100,
    "tpp": 0.95,
    "slp": 0.10,
    "s": "ACTIVE"
  }
}
```

| Field   | Type   | Description       |
| ------- | ------ | ----------------- |
| `d.i`   | string | Order ID          |
| `d.u`   | string | User ID           |
| `d.a`   | string | Asset ID          |
| `d.q`   | number | Quantity          |
| `d.tpp` | number | Take-profit price |
| `d.slp` | number | Stop-loss price   |
| `d.s`   | string | Status            |

### Heartbeat

```json
{
  "t": "PING",
  "d": null,
  "r": null
}
```

### Python example

{% code title="order\_updates.py" %}

```python
import asyncio, json, websockets

def auth_message(api_key, signature, timestamp):
    return {
        "t": "AUTH",
        "d": {
            "apiKey": api_key,
            "signature": signature,
            "timestamp": timestamp,
        },
    }

async def order_updates(api_key, signature, timestamp):
    uri = "wss://order-service.outpoll.com/order/ws"
    async with websockets.connect(uri) as ws:
        await ws.send(json.dumps(auth_message(api_key, signature, timestamp)))

        async for msg in ws:
            print(json.loads(msg))
```

{% endcode %}
