> ## 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: market

> Futures API: websocket: market.

## General WSS information

### Base Address

**wss\://fstream.monochrome.exchange/ws/market**

### Request Headers

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

Sec-Websocket-Extensions:permessage-deflate

## Request message format

```javascript subscribe theme={null}
{
    "method": "subscribe", 
    "params": [
        "{topic}@{arg},{arg}", 
        "{topic}@{arg}"
    ], 
    "id": "{id}"    //call back ID
}
```

```javascript unsubscribe theme={null}
{
    "method": "unsubscribe", 
    "params": [
        "{topic}@{arg},{arg}"
    ], 
    "id": "{id}"   //call back ID
}
```

## Response message format

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

```json Response-success theme={null}
{"id":"123", "code": 0, "msg": "success"}   
```

```json response-token invalid theme={null}
{"id":"123", "code": 401, "msg": "token expire"}
```

## Push message format

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

```json Example of transaction record (real-time push message) theme={null}
{
    "topic": "trade", 
    "event": "trade@btc_usdt", 
    "data": {
        "s": "btc_usdt", 
        "i": 6316559590087222000, 
        "t": 1655992403617, 
        "p": "43000", 
        "q": "0.21", 
        "b": true
    }
}
```

## Heartbeat

Each link of the client needs to send a text “ping” periodically, and the server will reply to the text “pong”. If the server does not receive a ping message from the client within 30 seconds, it will actively disconnect the link.

## Subscription parameters

**format**

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

## Orderbook manage

**How to manage a local order book correctly**

1.Open a stream to wss\://fstream.monochrome.exchange/ws/market , depth\_update\@btc\_usdt

2.Buffer the events you receive from the stream.

3.Get a depth snapshot from [https://fapi.monochrome.exchange/future/market/v1/public/depth?symbol=btc\_usdt\&level=500](https://fapi.monochrome.exchange/future/market/v1/public/depth?symbol=btc_usdt\&level=500)

4.Drop any event where u is \<= lastUpdateId in the snapshot.

5.The first processed event should have fu \<= lastUpdateId+1 AND u >= lastUpdateId+1.

6.While listening to the stream, each new event’s fu should be equal to the previous event’s u+1.

7.The data in each event is the absolute quantity for a price level.

8.If the quantity is 0, remove the price level.

9.Receiving an event that removes a price level that is not in your local order book can happen and is normal.

Note: Due to depth snapshots having a limit on the number of price levels, a price level outside of the initial snapshot that doesn’t have a quantity change won’t have an update in the Diff.
Depth Stream. Consequently, those price levels will not be visible in the local order book even when applying all updates from the Diff.
Depth Stream correctly and cause the local order book to have some slight differences with the real order book. However,
for most use cases the depth limit of 500 is enough to understand the market and trade effectively.

## Trade record

**request**

format: trade@\{symbol}

eg: trade\@btc\_usdt

rate: real

```json Response theme={null}
{
    "topic": "trade", 
    "event": "trade@btc_usdt", 
    "data": {
        "s":"btc_index", //trading pair
        "p":"50000",    //price
        "a":"0.1"   //Quantity
        "m": "BID"   //Deal side  BID:Buy ASK:Sell
        "t":123124124   //timestamp
    }
}
```

## K-line

**request**

format: kline@\{symbol},\{interval}

interval: 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w, 1M

eg: kline\@btc\_usdt,5m

rate: 1000ms

```json Response theme={null}
{
    "topic": "kline", 
    "event": "kline@btc_usdt,5m", 
    "data": {
        "s":"btc_index", //trading pair
        "o":"49000",     // opening price
        "c":"50000",    //Closing price
        "h":"0.1",      //highest price
        "l":"0.1",       //lowest price
        "a":"0.1",      //volume
        "v":"0.1",       //Turnover
        "ch":"0.21",   //Quote change
        "t":123124124   //timestamp
    }
}
```

## Ticker

**request**

format: ticker@\{symbol}

eg: ticker\@btc\_usdt

rate: 1000ms

```json Response theme={null}
{
    "topic": "ticker", 
    "event": "ticker@btc_usdt", 
    "data": {
        "s":"btc_index", //trading pair
        "o":"49000",     // opening price
        "c":"50000",    //Closing price
        "h":"0.1",      //highest price
        "l":"0.1",       //lowest price
        "a":"0.1",      //volume
        "v":"0.1",       //Turnover
        "ch":"0.21",   //Quote change
        "t":123124124   //timestamp
   }
}
```

## Agg ticker

**request**

format: agg\_ticker@\{symbol}

eg: agg\_ticker\@btc\_usdt

rate: 1000ms

```json Response theme={null}
{
    "topic": "agg_ticker", 
    "event": "agg_ticker@btc_usdt", 
    "data": {
        "s":"btc_index", //trading pair
        "o":"49000",     // opening price
        "c":"50000",    //Closing price
        "h":"0.1",      //highest price
        "l":"0.1",       //lowest price
        "a":"0.1",      //volume
        "v":"0.1",       //Turnover
        "ch":"0.21",   //Quote change

        "i":"0.21" ,   //index price

        "m":"0.21",   //mark price

        "bp":"0.21",   //bid price

        "ap":"0.21" ,  //ask price
        "t":123124124   //timestamp
   }
}
```

## Index price

**request**

format: index\_price@\{symbol}

eg: index\_price\@btc\_usdt

rate: 1000ms

```json Response theme={null}
{
    "topic": "index_price", 
    "event": "index_price@btc_usdt", 
    "data": {
        "s":"btc_usdt", //trading pair
        "p":"50000",    //price
        "t":123124124   //timestamp
   }
}
```

## Mark price

**request**

format: mark\_price@\{symbol}

eg: mark\_price\@btc\_usdt

rate: 1000ms

```json Response theme={null}
{
    "topic": "mark_price", 
    "event": "mark_price@btc_usdt", 
    "data": {
        "s":"btc_usdt", //trading pair
        "p":"50000",    //price
        "t":123124124   //timestamp
   }
}
```

## Incremental depth

**request**

format: depth\_update@\{symbol},\{interval}

interval: 100/250/500/1000   default rate 100ms

eg: depth\_update\@btc\_usdt,100ms

```json Response theme={null}
{
    "topic": "depth_update", 
    "event": "depth_update@btc_usdt", 
    "data": {
        "s": "btc_usdt",        // symbol
        "pu": 120,              // previousUpdateId = previous lastUpdateId
        "fu": 121,              // firstUpdateId = previous lastUpdateId + 1
        "u": 123,               // lastUpdateId
        "a": [                  // asks  sell order
            [                   // [0]price, [1]quantity
                "34000",        //price
                "1.2"           //quantity
            ], 
            [
                "34001", 
                "2.3"
            ]
        ], 
        "b": [                  // bids buy order
            [
                "32000", 
                "0.2"
            ], 
            [
                "31000", 
                "0.5"
            ]
        ],
        "t": 123456789 // time stamp
    }
}
```

## Limited depth

**request**

format: depth@\{symbol},\{levels},\{interval}

levels: 5/10/20/50

interval: 100/250/500/1000   default rate 1000ms

eg: depth\@btc\_usdt,50,1000ms

```json Response theme={null}
{
    "topic": "depth", 
    "event": "depth@btc_usdt,20", 
    "data": {
        "id": "1234", //lastUpdateId
        "s":"btc_index", //trading pair
        "a":[["50000","0.1"],["50001","0.2"]],    //ask sell order queue,[price, quantity]
        "b":[["49999","0.1"],["48888","0.2"]],   //bid buy queue
        "t": 123456789 // time stamp
    }
}
```

## Fund rate

**request**

format: fund\_rate@\{symbol}

eg: fund\_rate\@btc\_usdt

rate: 60s

```json Response theme={null}
{
    "topic": "fund_rate", 
    "event": "fund_rate@btc_usdt", 
    "data": {
        "s":"btc_usdt", //Trading pair
        "r":"0.01",    // Fund fee
        "t":123124124   //timestamp
   }
}
```


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