🤑Trades

Subscribing and Unsubscribing to Trades

Our WebSocket API provides real-time trade data, allowing you to subscribe to and receive updates on trades as they happen. To manage your subscriptions, you'll need to send structured messages over your established WebSocket connection. Below are the details on how to subscribe to and unsubscribe from trade updates for specific asset pairs.

Subscribing to Trade Updates

To start receiving real-time updates for trades, you need to send a subscription message over your WebSocket connection. The message should specify that you wish to subscribe ("action": "subscribe") to trades ("subscription_type": "Trades") for a specific pair and asset ID.

Here's the structure of the subscription message you should send:

{
    "action": "subscribe",
    "subscription_type": "Trades",
    "pair_id": "YourPairID",
    "asset_id": "YourAssetID"
}

Replace YourPairID and YourAssetID with the identifiers of the trade pair and asset you are interested in. For example, if you want to subscribe to trades for a specific pair, your message might look like this:

{
    "action": "subscribe",
    "subscription_type": "Trades",
    "pair_id": "0x16b9a82891338f9ba80e2d6970fdda79d1eb0dae:56",
    "asset_id": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c:56"
}

Unsubscribing from Trade Updates

If you wish to stop receiving updates for a particular trade pair, you can unsubscribe by sending a similar message with the action set to "unsubscribe":

{
    "action": "unsubscribe",
    "subscription_type": "Trades",
    "pair_id": "YourPairID",
    "asset_id": "YourAssetID"
}

Just like with subscribing, replace YourPairID and YourAssetID with the appropriate identifiers.

Receiving Trade Updates

Once you've successfully subscribed, trade updates will be sent to your WebSocket connection in real-time. These messages will follow this format:

{
    "channel": "trades::0x16b9a82891338f9ba80e2d6970fdda79d1eb0dae:56::0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c:56",
    "subscription_type": "Trades",
    "data": {
        "pair_id": "0x16b9a82891338f9ba80e2d6970fdda79d1eb0dae:56",
        "date": "2024-03-15T10:43:40Z",
        "block_number": 36988324,
        "chain": 56,
        "exchange": "0x6d02f76a2f4a3ea81889a837f093783e64650d54",
        "factory_address": "0xca143ce32fe78f1f7019d7d551a6402fc5350c73",
        "hash": "0x9d8f6d0b57fd29b9a209719fbe6a75f0737b90fffe6cec36dbb0ec0053bd8c16",
        "log_index": 71,
        "maker": "0xac8b4f3444ba492430835c18f02b592160f0344d",
        "pair_address": "0x16b9a82891338f9ba80e2d6970fdda79d1eb0dae",
        "token0_address": "0x55d398326f99059ff775485246999027b3197955",
        "token0_amount": 13.762950581938505,
        "token0_price": 1.0055291890728444,
        "token0_reserves": 4683398.4869126035,
        "token0_symbol": "usdt",
        "token1_address": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
        "token1_amount": 0.02393612237372071,
        "token1_price": 578.1658500000001,
        "token1_reserves": 7876.829972525677,
        "token1_symbol": "wbnb",
        "side": "sell",
        "price": 578.1658500000001,
        "volume": 13.839048537906251
    }
}

Last updated