Last updated

Account Websocket API

This websocket endpoint is used to get realtime account updates.

Authorization

To use the trade websocket api you must connect with the Authorization header set to your apikey.

"Authorization": "YOURAPIKEY"

Connect websocket to https://api.hibachi.xyz/ws/account?accountId={YOUR_ACCOUNT_ID}

Usage

  • You should start with stream.start, the server will respond with a listen_key, then you need to do stream.ping with the same listen_key otherwise it will expire after 10 seconds.

  • You can use stream.stop to stop the stream.

  • id in the packet is your unique identifier for the request, the server will respond with the same id.

The server will send you these updates:

  • Order: ORDER_CREATED, ORDER_UPDATED, ORDER_CANCELED
  • Balance: balance_update (deposit, withdrawal and trades)
  • Trade: trade_update, position_update

You can see the examples in "(Events from Server)" under "Saved messages".

Supported Methods

  • stream.start
  • stream.ping
  • stream.stop

Stream Start

Request Body

{
    "id": 123,
    "method": "stream.start",
    "params": {
        "accountId": "<accountId>"
    }
}

Response Body

{
    "id": 123,
    "result": {
        "accountSnapshot": {
            "account_id": 128,
            "balance": "910.997790",
            "positions": [
                {
                    "direction": "Long",
                    "entryNotional": "10.003168",
                    "markPrice": "3917.478177",
                    "notionalValue": "10.000146",
                    "openPrice": "3918.661809",
                    "quantity": "0.002552700",
                    "symbol": "ETH/USDT-P",
                    "unrealizedFundingPnl": "0.000000",
                    "unrealizedTradingPnl": "-0.003021"
                }
            ]
        },
        "listenKey": "128-di7hdiewgt4symwnfp4tfhodzzn774skyi"
    },
    "status": 200
}

Stream Ping

Request Body

{
    "id": 123,
    "method": "stream.ping",
    "params": {
        "accountId": "<accountId>",
        "listenKey": "<accountId>-zzwuxbp63bfpztkghoradc5blgk7rgumoy"
    },
    "timestamp": 1234567
}

Response Body

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

Stream Stop

Request Body

{
    "id": 123,
    "method": "stream.stop",
    "params": {
        "accountId": "<accountId>",
        "listenKey": "<accountId>-jiqu3ig4ur23ti2lksrgjjoruyuwr73i4u"
    },
    "timestamp": 1234567
}

Response Body

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

Events

Examples of messages sent by server

[
    {
        "account": "<accountId>",
        "data": {
            "orderId": 578745035695106058,
            "price": "69762.24077",
            "quantity": "0.1288935088",
            "side": "BID",
            "symbol": "BTC/USDT-P",
            "timestamp": 1712781049,
            "nonce": 1714701600000000
        },
        "event": "order_creation"
    },
    {
        "account": "<accountId>",
        "data": {
            "orderId": 578745035695106058,
            "price": "69762.24077",
            "quantity": "0.1288935088",
            "side": "BID",
            "symbol": "BTC/USDT-P",
            "timestamp": 1712781049,
            "executed_quantity": "0.096987527"
        },
        "event": "order_update"
    },
    {
        "account": "<accountId>",
        "data": {
            "orderId": 578745034376521742,
            "side": "ASK",
            "symbol": "DDNG/USDT-P",
            "timestamp": 1712781045
        },
        "event": "order_cancellation"
    },
    {
        "account": "<accountId>",
        "data": {
            "depositQuantity": "123.000000"
        },
        "event": "balance_update"
    },
    {
        "account": "<accountId>",
        "data": {
            "withdrawQuantity": "123.000000"
        },
        "event": "balance_update"
    },
    {
        "account": "<accountId>",
        "data": {
            "updatedCollateralBalance": "1234.000000"
        },
        "event": "balance_update"
    },
    {
        "account": "<accountId>",
        "data": {
            "isTaker": true,
            "orderId": "582871374158365696",
            "orderType": "Limit",
            "price": "2345.000000",
            "quantity": "0.000421590",
            "realizedPnl": "0.022107",
            "side": "BID",
            "symbol": "ETH/USDT-P",
            "timestamp": 1728526563
        },
        "event": "trade_update"
    },
    {
        "account": "<accountId>",
        "data": {
            "symbol": "BTC/USDT-P",
            "updatedPosition": {
                "direction": "Closed",
                "entryNotional": "0.000000",
                "quantity": "0.000000"
            }
        },
        "event": "position_update"
    },
    {
        "account": "<accountId>",
        "data": {
            "symbol": "HFT/USDT-P",
            "updatedPosition": {
                "direction": "Long",
                "entryNotional": "11926.363515",
                "quantity": "28179.202190"
            }
        },
        "event": "position_update"
    },
    {
        "account": "<accountId>",
        "data": {
            "indexPrice": "61097.00801",
            "quantity": "0.5580484584",
            "settledAmount": "0.8618780736305764",
            "side": "Buy",
            "symbol": "BTC/USDT-P",
            "timestamp": 1719446400,
            "unrealizedFunding": "-734.608435"
        },
        "event": "funding_settlement"
    },
    {
        "account": "<accountId>",
        "event": "account_created",
        "data": {
            "ledgerAccountId": 123,
            "timestamp": 123456789
        }
    },
    {
        "event": "deposit_status_update",
        "account": "<accountId>",
        "data": {
            "depositQuantity": 1234,
            "depositTxnHash": "0xabcdef",
            "etaTsSecond": 10,
            "status": "Processing/Accepted/Rejected/Succeeded",
            "note": "Note"
        }
    },
    {
        "account": 2,
        "data": {
            "matchedQuantity": "0.000000004",
            "orderId": "3",
            "orderType": "MarketOrder",
            "remainingQuantity": "0.000000005",
            "symbol": "ETH/USDT-P",
            "timestamp": 123456789
        },
        "event": "order_not_fully_matched"
    },
    {
        "event": "order_request_rejected",
        "account": "<accountId>",
        "data": {
            "orderId": 1234,
            "error": "RiskLimitExceeded",
            "requestType": "Update/New"
        }
    },
    {
        "event": "stream_expired",
        "account": "<accountId>",
        "params": {
            "listenKey": "123",
            "timestampMs": 123456789
        }
    },
    {
        "event": "transfer_status_update",
        "sourceAccountId": "<accountId>",
        "data": {
            "transferQuantity": "1234",
            "destAccountPublicKey": "0xabcdef",
            "status": "Processing/Accepted/Rejected/Succeeded",
            "isInstantWithdrawal": true,
            "note": "Note"
        }
    },
    {
        "event": "withdraw_rejection",
        "account": "<accountId>",
        "data": {
            "withdraw_quantity": 1234,
            "timestamp": 123456789
        }
    },
    {
        "event": "withdraw_status_update",
        "account": "<accountId>",
        "data": {
            "withdrawQuantity": 1234,
            "withdrawAddress": "0xabcdef",
            "etaTsSecond": 10,
            "status": "Processing/Accepted/Rejected/Succeeded",
            "note": "Note"
        }
    },
    {
        "event": "order_matched",
        "account": "<accountId>",
        "data": {
            "orderId": 1234,
            "symbol": "ETH/USDT-P",
            "orderType": "LIMIT",
            "matchedQuantity": "1234",
            "remainingQuantity": "1234",
            "timestamp": 123456789,
            "nonce": 1714701600000000
        }
    },
    {
        "event": "trade_rejected",
        "account": "<accountId>",
        "data": {
            "symbol": "ETH/USDT-P",
            "orderId": 1234,
            "quantity": "1234",
            "timestamp": 123456789
        }
    }
]