Last updated

Market Websocket API

Connect websocket to https://data-api.hibachi.xyz/ws/market

Please note no authorization header is needed to use the market api.

Usage

This websocket endpoint is used to get realtime market data.

You should start with subscribe with a few symbols and topics. You can subscribe to multiple symbol and topics at the same time.

Supported topics

  • Price: mark_price, spot_price, ask_bid_price, funding_rate_estimation
  • Trade: trades
  • Klines: klines
  • Orderbook: orderbook

Supported Methods

For orderbook you can specify optional parameter granularity and depth. See the REST API /market/data/orderbook for the details. You can only subscribe to one set of parameters. If you subscribe with different parameters it will unsubscribe the previous subscription automatically.

After that the server will send you events.

You can use unsubscribe to unsubscribe all or a subset of topics. You don't need to specify parameters in this case.

You can use list_subscription to know all subscriptions.

Notes for orderbook events

When you first subscribe it should send you one message with "messageType": "Snapshot" immediately, it contains all price levels.
After that you will receive message with "messageType": "Update" periodically and you should update your state in this way for both sides:

  1. If it is null then remove all price levels.
  2. Remove all price levels outside startPrice and endPrice.
  3. For each level in levels, if the quantity is zero then remove it.
  4. Otherwise create or update the price level accordingly.

Subscribe

Request Body

{
    "method": "subscribe",
    "parameters": {
        "subscriptions": [
            {
                "symbol": "ETH/USDT-P",
                "topic": "mark_price"
            },
            {
                "symbol": "ETH/USDT-P",
                "topic": "spot_price"
            },
            {
                "symbol": "ETH/USDT-P",
                "topic": "funding_rate_estimation"
            },
            {
                "symbol": "ETH/USDT-P",
                "topic": "trades"
            },
            {
                "symbol": "ETH/USDT-P",
                "topic": "klines"
            },
            {
                "symbol": "ETH/USDT-P",
                "topic": "orderbook"
            },
            {
                "symbol": "ETH/USDT-P",
                "topic": "ask_bid_price"
            }
        ]
    }
}

Response Body

no response

Unsubscribe

Request Body

{
    "method": "unsubscribe",
    "parameters": {
        "subscriptions": [
            {
                "symbol": "ETH/USDT-P",
                "topic": "mark_price"
            },
            {
                "symbol": "ETH/USDT-P",
                "topic": "spot_price"
            },
            {
                "symbol": "ETH/USDT-P",
                "topic": "funding_rate_estimation"
            },
            {
                "symbol": "ETH/USDT-P",
                "topic": "trades"
            },
            {
                "symbol": "ETH/USDT-P",
                "topic": "klines"
            },
            {
                "symbol": "ETH/USDT-P",
                "topic": "orderbook"
            },
            {
                "symbol": "ETH/USDT-P",
                "topic": "ask_bid_price"
            }
        ]
    }
}

Response Body

{
    "id": 123,
    "status": 200
}

List subscriptions

Request Body

{ "method": "list_subscriptions" }

Response Body

{
    "subscriptions": [
        {
            "symbol": "ETH/USDT-P",
            "topic": "markPrice"
        },
        {
            "symbol": "ETH/USDT-P",
            "topic": "spotPrice"
        },
        {
            "symbol": "ETH/USDT-P",
            "topic": "askBidPrice"
        },
        {
            "symbol": "ETH/USDT-P",
            "topic": "fundingRateEstimation"
        },
        {
            "symbol": "ETH/USDT-P",
            "topic": "trades"
        },
        {
            "symbol": "ETH/USDT-P",
            "topic": "klines"
        },
        {
            "symbol": "ETH/USDT-P",
            "topic": "orderbook"
        }
    ]
}

Events

// Those are examples of message send by server
[
    {
        "data": {
            "markPrice": "3513.365000"
        },
        "symbol": "ETH/USDT-P",
        "topic": "mark_price"
    },
    {
        "data": {
            "spotPrice": "3513.365000"
        },
        "symbol": "ETH/USDT-P",
        "topic": "spot_price"
    },
    {
        "data": {
            "askPrice": "3513.716336",
            "bidPrice": "3513.013663"
        },
        "symbol": "ETH/USDT-P",
        "topic": "ask_bid_price"
    },
    {
        "data": {
            "fundingRateEstimation": {
                "estimatedFundingRate": "-0.000040",
                "nextFundingTimestamp": 1712793600
            }
        },
        "symbol": "ETH/USDT-P",
        "topic": "funding_rate_estimation"
    },
    {
        "data": {
            "trade": {
                "price": "3514.370559",
                "quantity": "0.284517521",
                "takerSide": "Sell",
                "timestamp": 1712782611
            }
        },
        "symbol": "ETH/USDT-P",
        "topic": "trades"
    },
    {
        "data": {
            "close": "3512.964670",
            "high": "3517.318806",
            "interval": "1h",
            "low": "3511.145033",
            "open": "3512.659268",
            "timestamp": 1712779200,
            "volumeNotional": "320479.592130"
        },
        "symbol": "ETH/USDT-P",
        "topic": "klines"
    },
    {
        "data": {
            "ask": {
                "endPrice": "3518.25",
                "levels": [
                    {
                        "price": "3515.09",
                        "quantity": "0.284516833"
                    },
                    {
                        "price": "3515.34",
                        "quantity": "0.000000000"
                    }
                ],
                "startPrice": "3515.09"
            },
            "bid": null
        },
        "depth": 10,
        "granularity": "0.01",
        "messageType": "Update",
        "symbol": "ETH/USDT-P",
        "topic": "orderbook"
    }
]