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

# WebSocket: private

> Spot API: websocket: private.

## General WSS information

### Base Address

**wss\://stream.monochrome.exchange/private**

### Request Headers

The request header of the compression extension protocol must be added.

Sec-Websocket-Extensions:permessage-deflate

## Request message format

**param format**

\{topic}@\{arg},\{arg},…

```javascript subscribe theme={null}
{
    "method": "subscribe", 
    "params": [
        "{topic}@{arg},{arg}",    //event
        "{topic}@{arg}"
    ], 
    "listenKey": "512312356123123123",   //the listener Key, Apply accessToken through /v4/ws-token interface
    "id": "{id}"
}
```

```javascript unsubscribe theme={null}
{
    "method": "unsubscribe", 
    "params": [
        "{topic}@{arg},{arg}",    //event
        "{topic}@{arg}"
    ], 
    "listenKey": "512312356123123123",   //the listener Key, Apply accessToken through /v4/ws-token interface
    "id": "{id}"
}
```

## Response message format

```javascript format theme={null}
{
    "id": "{id}", //call back ID
    "code": 1,     //result 0=success;1=fail;2=listenKey invalid
    "msg": ""
}
```

## Get token

`POST` `/v4/ws-token`

### Limit Flow Rules

1/10s/apikey

### Note

The accessToken is valid for 2 days. Calling the endpoint again will reset the validity period.

accessToken = listenKey

```json Response theme={null}
{
    "rc": 0,
    "mc": "SUCCESS",
    "ma": [],
    "result": {
        "accessToken": "eyJhbqGciOiJSUzI1NiJ9.eyJhY2NvdW50SWQiOiIyMTQ2Mjg1MzIyNTU5Iiwic3ViIjoibGh4dDRfMDAwMUBzbmFwbWFpbC5jYyIsInNjb3BlIjoiYXV0aCIsImlzcyI6Inh0LmNvbSIsImxhc3RBdXRoVGltZSI6MTY2MzgxMzY5MDk1NSwic2lnblR5cGUiOiJBSyIsInVzZXJOYW1lIjoibGh4dDRfMDAwMUBzbmFwbWFpbC5jYyIsImV4cCI6MTY2NjQwNTY5MCwiZGV2aWNlIjoidW5rbm93biIsInVzZXJJZCI6MjE0NjI4NTMyMjU1OX0.h3zJlJBQrK2x1HvUxsKivnn6PlSrSDXXXJ7WqHAYSrN2CG5XPTKc4zKnTVoYFbg6fTS0u1fT8wH7wXqcLWXX71vm0YuP8PCvdPAkUIq4-HyzltbPr5uDYd0UByx0FPQtq1exvsQGe7evXQuDXx3SEJXxEqUbq_DNlXPTq_JyScI",
        "refreshToken": "eyJhbGciOiqJSUzI1NiJ9.eyJhY2NvdW50SWQiOiIyMTQ2Mjg1MzIyNTU5Iiwic3ViIjoibGh4dDRfMDAwMUBzbmFwbWFpbC5jYyIsInNjb3BlIjoicmVmcmVzaCIsImlzcyI6Inh0LmNvbSIsImxhc3RBdXRoVGltZSI6MTY2MzgxMzY5MDk1NSwic2lnblR5cGUiOiJBSyIsInVzZXJOYW1lIjoibGh4dDRfMDAwMUBzbmFwbWFpbC5jYyIsImV4cCI6MTY2NjQwNTY5MCwiZGV2aWNlIjoidW5rbm93biIsInVzZXJJZCI6MjE0NjI4NTMyMjU1OX0.Fs3YVm5YrEOzzYOSQYETSmt9iwxUHBovh2u73liv1hLUec683WGfktA_s28gMk4NCpZKFeQWFii623FvdfNoteXR0v1yZ2519uNvNndtuZICDdv3BQ4wzW1wIHZa1skxFfqvsDnGdXpjqu9UFSbtHwxprxeYfnxChNk4ssei430"
    }
}
```

## Push message format

```javascript format theme={null}
{
    "topic": "trade",          
    "event": "trade@btc_usdt", 
    "data": { }                
}
```

## Change of balance

param

format: balance

eg: balance

```json push theme={null}
{
    "topic": "balance", 
    "event": "balance", 
    "data": {
        "a": "123",           // accountId                     
        "t": 1656043204763,   // time happened time
        "c": "btc",           // currency
        "b": "123",           // all spot balance
        "f": "11",            // frozen
        "z": "SPOT",           // bizType [SPOT,LEVER]
        "s": "btc_usdt"       // symbol
    }
}
```

## Change of order

param

format: order

eg: order

```json push theme={null}
{
    "topic": "order", 
    "event": "order", 
    "data": {
        "s": "btc_usdt",                // symbol
        "bc": "btc",                    // base currency 
        "qc": "usdt",                   // quotation currency 
        "t": 1656043204763,             // happened time
        "ct": 1656043204663,            // create time
        "i": "6216559590087220004",     // order id,
        "ci": "test123",                // client order id
        "st": "PARTIALLY_FILLED",       // state NEW/PARTIALLY_FILLED/FILLED/CANCELED/REJECTED/EXPIRED
        "sd": "BUY",                    // side BUY/SELL
        "tp": "LIMIT",                  // type LIMIT/MARKET
        "oq":  "4"                      // original quantity
        "oqq":  48000,                  // original quotation quantity 
        "eq": "2",                      // executed quantity
        "lq": "2",                      // remaining quantity
        "p": "4000",                    // price 
        "ap": "30000",                  // avg price
        "f":"0.002"                     // fee 
    }
}
```

## Order filled

param

format: trade

eg: trade

```json push theme={null}
{
    "topic": "trade", 
    "event": "trade", 
    "data": {
        "s": "btc_usdt",           //symbol
        "i": 6316559590087222000,  //tradeId
        "t": 1655992403617,        //time
        "oi": 6616559590087222666, //orderId
        "p": "43000",              //price
        "q": "0.21",               //quantity
        "v": "9030",               //quoteQty
        "b": true,                 //whether is buyerMaker or not
        "tm": 1                    //1-taker 2-maker
    }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.