# Websocket

Endpoints to open and manage websocket connections to the system.

## Authentication Ticket

`POST /v3/auth/ticket`

Generate a ticket for use with websockets if your client does not support customisable headers.

**Request Body** _(required)_

  | Field | Type | Description |
  |-------|------|-------------|
  | `keyId` | string | Api key id provided during onboarding (e.g. `QNl8Xfl729CJlNgwkA329EL1D8z8BAQ2`) |
  | `secret` | string | Api secret provided during onboarding (e.g. `u0WgWWLXYhcS+UnAGk2H+eZ3JZp1P4kpUxcoNitzu3U=`) |

**Responses**

- **200**: Ok

  | Field | Type | Description |
  |-------|------|-------------|
  | `ticket` | string | The ticket you should include as part of the query when establishing a websocket connection (e.g. `eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJIaSI6IkRpZCBub3QgdGhpbmsgYW55b25lIHdvdWxkIGRlY29kZSB0aGlzIiwicHVia2V5IjoiMHgwMFlvdXJQdWJsaWNLZXkwMCIsImlhdCI6MTY5OTgwMTE5NSwiZXhwIjoxNjk5ODg3NTk1fQ.CZdxZje7VRrMdfbfQSbnaliNmpmhat_tNZWiDqi-tboXqBLnP1qQRpwdl8A89eaGxkvmVmZGbeA8wP6ghqHjuzCjr1G5OwG40draexCZyBgys1IaPJFHVujrKxr3BxI5U0e8fSQ7s_kuWy3mA5SzlQJnlMy6y5WeY0GS7PACgXRBH3g3R0cua-pNmA-PzvRPTaQzU4-Bs3rsisNIcaJMIXCS2ofnvH6aLmWDpucfepJ1NgX0QJHZupBNBAoV67NPz4c9McERwG5G_pykmwz9sOJxLNpjjvf8OyF_21epX_YkxR1tzhPAHQuiIg8DAAWI7S435cR1yQyoY7R0TJWPZQ`) |

- **400**: Bad request

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Invalid schema):
  ```json
  {"code":"INVALID_SCHEMA","description":"Missing or malformed schema"}
  ```

**Example**

```bash
curl -X POST "https://api.demo.omniaexchange.com/api/v3/auth/ticket" \
  -H "Content-Type: application/json" \
  -d '{"keyId": "QNl8Xfl729CJlNgwkA329EL1D8z8BAQ2", "secret": "u0WgWWLXYhcS+UnAGk2H+eZ3JZp1P4kpUxcoNitzu3U="}'
```

---

## Open Websocket

`GET /v2/websocket`

Open a websocket with Alice. This will allow you to subscribe to live data channels. 

**Available Channels:** 
 
**PRICE_FEED_UPDATES** — Receive real-time price updates for specified asset pairs.  
You must provide a list of asset pairs (sellingAsset/buyingAsset) in the subscription body. 
**ACCOUNT_ACTIVITY** — Receive notifications when deposits or withdrawals occur on your account. 
**ORDERS** — Receive notifications when your orders are settled or cancelled,  
including both offchain and on-chain orders. 
 
You must subscribe to at least one channel within 5 seconds or we will close your socket with a 400. 
You can subscribe to multiple channels simultaneously by including them in the same subscription message.

**Parameters**

| Name | In | Required | Type | Description |
|------|-----|----------|------|-------------|
| `token` | query | No | string | If you are connecting via a browser or a client that doesn't support header customisation, you can pass the ticket which you retrieve from '/v3/auth/ticket' as a query param in order to subscribe to price updates (e.g. `eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJrZXktaWQiOiIzdVFjSnJZQkJlVlFwUExsVDNNY3pETGxUVktkRHEzRCIsImtleSI6InVzZXIxNjZpc2FyIiwidmVyc2lvbiI6MSwicGVybWlzc2lvbnMiOlsiQUNDT1VOVF9NQUlOVEVOQU5DRSIsIk1BUktFVF9EQVRBIiwiUkZRIiwiQUNDT1VOVF9JTkZPUk1BVElPTiIsIlRSQURJTkciXSwiaWF0IjoxNzYzMzkyOTYxLCJleHAiOjE3NjM0NzkzNjEsInN1YiI6IjN1UWNKcllCQmVWUXBQTGxUM01jekRMbFRWS2REcTNEIn0.oQgdavtOnn8mdZj8_JM78197F1LUlZN3W8ry3v4Tgg84dpEun6yj-EPr7WqtsWWJckMHB_xbnTjUlwhQFp1JMw`) |

**Request Body** _(required)_

  | Field | Type | Description |
  |-------|------|-------------|
  | `type` | string | Request message type |
  | `metadata` | object | Metadata |

  Example:
  ```json
  {"type":"SUBSCRIBE","metadata":{"subscriptions":[{"channelType":"PRICE_FEED_UPDATES","body":{"assets":[{"sellingAsset":"btc","buyingAsset":"usd"},{"sellingAsset":"eth","buyingAsset":"pyth"},{"sellingAsset":"sol","buyingAsset":"gbp"}]}}]}}
  ```

**Responses**

- **200**: Response examples

  | Field | Type | Description |
  |-------|------|-------------|
  | `type` | string | Message type |
  | `metadata` | object | Response |


  Example (Subscription Response):
  ```json
  {"type":"SUBSCRIPTIONS","metadata":{"subscriptions":[{"channelType":"ACCOUNT_ACTIVITY"},{"channelType":"ORDERS"},{"channelType":"PRICE_FEED_UPDATES","body":{"assets":[{"sellingAsset":"btc","buyingAsset":"usd"},{"sellingAsset":"eth","buyingAsset":"pyth"},{"sellingAsset":"sol","buyingAsset":"gbp"}]}}]}}
  ```

**Example**

```bash
curl "https://api.demo.omniaexchange.com/api/v2/websocket" \
  -H "Content-Type: application/json" \
  -d '{"type":"SUBSCRIBE","metadata":{"subscriptions":[{"channelType":"PRICE_FEED_UPDATES","body":{"assets":[{"sellingAsset":"btc","buyingAsset":"usd"},{"sellingAsset":"eth","buyingAsset":"pyth"},{"sellingAsset":"sol","buyingAsset":"gbp"}]}}]}}'
```

---

