Files
ritmex-bot/docs/nado/developer-resources/api/subscriptions/streams.md
T

8.9 KiB

Streams

Available Streams

See below the available streams you can subscribe to:

pub enum StreamSubscription {
    // pass `null` product_id to subscribe to all products
    OrderUpdate { product_id: Option<u32>, subaccount: H256 },
    Trade { product_id: u32 },
    BestBidOffer { product_id: u32 },
    // pass `null` product_id to subscribe to all products
    Fill { product_id: Option<u32>, subaccount: H256 },
    // pass `null` product_id to subscribe to all products
    PositionChange { product_id: Option<u32>, subaccount: H256},
    BookDepth { product_id: u32 },
    // pass `null` product_id to subscribe to all products
    Liquidation { product_id: Option<u32> },
    LatestCandlestick {
        product_id: u32,
        // time interval in seconds (e.g., 60, 300, 900, 3600)
        granularity: i32
    },
    FundingPayment { product_id: u32 },
    // pass `null` product_id to subscribe to all products
    FundingRate { product_id: Option<u32> }
}

Subscribing to a stream

{% tabs %} {% tab title="Order Update" %} Connect

WEBSOCKET [SUBSCRIPTIONS_ENDPOINT]

Message

Requires Authentication: Yes.

{% hint style="info" %} Note: Set product_id to null to subscribe to order updates across all products for the subaccount. {% endhint %}

{
  "method": "subscribe",
  "stream": {
    "type": "order_update",
    "subaccount": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43746573743000000000000000",
    "product_id": 1
  },
  "id": 10
}

Subscribe to all products:

{
  "method": "subscribe",
  "stream": {
    "type": "order_update",
    "subaccount": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43746573743000000000000000",
    "product_id": null
  },
  "id": 10
}

{% endtab %}

{% tab title="Trade" %} Connect

WEBSOCKET [SUBSCRIPTIONS_ENDPOINT]

Message

Requires Authentication: No.

{
  "method": "subscribe",
  "stream": {
    "type": "trade",
    "product_id": 0
  },
  "id": 10
}

{% endtab %}

{% tab title="Best Bid Offer" %} Connect

WEBSOCKET [SUBSCRIPTIONS_ENDPOINT]

Message

Requires Authentication: No.

{
  "method": "subscribe",
  "stream": {
    "type": "best_bid_offer",
    "product_id": 0
  },
  "id": 10
}

{% endtab %} {% endtabs %}

{% tabs %} {% tab title="Fill" %} Connect

WEBSOCKET [SUBSCRIPTIONS_ENDPOINT]

Message

Requires Authentication: No.

{% hint style="info" %} Note: Set product_id to null to subscribe to fills across all products for the subaccount. {% endhint %}

{
  "method": "subscribe",
  "stream": {
    "type": "fill",
    "product_id": 1,
    "subaccount": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43746573743000000000000000"
  },
  "id": 10
}

Subscribe to all products:

{
  "method": "subscribe",
  "stream": {
    "type": "fill",
    "product_id": null,
    "subaccount": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43746573743000000000000000"
  },
  "id": 10
}

{% endtab %}

{% tab title="Position Change" %} Connect

WEBSOCKET [SUBSCRIPTIONS_ENDPOINT]

Message

Requires Authentication: No.

{% hint style="info" %} Note: Set product_id to null to subscribe to position changes across all products for the subaccount. {% endhint %}

{
  "method": "subscribe",
  "stream": {
    "type": "position_change",
    "product_id": 0,
    "subaccount": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43746573743000000000000000"
  },
  "id": 10
}

Subscribe to all products:

{
  "method": "subscribe",
  "stream": {
    "type": "position_change",
    "product_id": null,
    "subaccount": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43746573743000000000000000"
  },
  "id": 10
}

{% endtab %}

{% tab title="Book Depth" %} Connect

WEBSOCKET [SUBSCRIPTIONS_ENDPOINT]

Message

Requires Authentication: No.

{
  "method": "subscribe",
  "stream": {
    "type": "book_depth",
    "product_id": 0
  },
  "id": 10
}

{% endtab %} {% endtabs %}

{% tabs %} {% tab title="Liquidation" %} Connect

WEBSOCKET [SUBSCRIPTIONS_ENDPOINT]

Message

Requires Authentication: No.

{% hint style="info" %} Note: Set product_id to null to subscribe to liquidations across all products. {% endhint %}

{
  "method": "subscribe",
  "stream": {
    "type": "liquidation",
    "product_id": 1
  },
  "id": 10
}

Subscribe to all products:

{
  "method": "subscribe",
  "stream": {
    "type": "liquidation",
    "product_id": null
  },
  "id": 10
}

{% endtab %}

{% tab title="Latest Candlestick" %} Connect

WEBSOCKET [SUBSCRIPTIONS_ENDPOINT]

Message

{% hint style="info" %} See all supportes granularity values in Available Granularities {% endhint %}

Requires Authentication: No.

{
  "method": "subscribe",
  "stream": {
    "type": "latest_candlestick",
    "product_id": 1,
    "granularity": 60
  },
  "id": 10
}

{% endtab %}

{% tab title="Funding Payment" %} Connect

WEBSOCKET [SUBSCRIPTIONS_ENDPOINT]

Message

Requires Authentication: No.

{
  "method": "subscribe",
  "stream": {
    "type": "funding_payment",
    "product_id": 2
  },
  "id": 10
}

{% endtab %}

{% tab title="Funding Rate" %} Connect

WEBSOCKET [SUBSCRIPTIONS_ENDPOINT]

Message

Requires Authentication: No.

{% hint style="info" %} Note: Set product_id to null to subscribe to funding rate updates across all products. {% endhint %}

{
  "method": "subscribe",
  "stream": {
    "type": "funding_rate",
    "product_id": 2
  },
  "id": 10
}

Subscribe to all products:

{
  "method": "subscribe",
  "stream": {
    "type": "funding_rate",
    "product_id": null
  },
  "id": 10
}

{% endtab %} {% endtabs %}

Response

{
  "result": null,
  "id": 10
}

Unsubscribing

{% tabs %} {% tab title="Order Update" %} Connect

WEBSOCKET [SUBSCRIPTIONS_ENDPOINT]

Message

{
  "method": "unsubscribe",
  "stream": {
    "type": "order_update",
    "subaccount": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43746573743000000000000000",
    "product_id": 1
  },
  "id": 10
}

Unsubscribe from all products:

{
  "method": "unsubscribe",
  "stream": {
    "type": "order_update",
    "subaccount": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43746573743000000000000000",
    "product_id": null
  },
  "id": 10
}

{% endtab %}

{% tab title="Trade" %} Connect

WEBSOCKET [SUBSCRIPTIONS_ENDPOINT]

Message

{
  "method": "unsubscribe",
  "stream": {
    "type": "trade",
    "product_id": 0
  },
  "id": 10
}

{% endtab %}

{% tab title="Best Bid Offer" %} Connect

WEBSOCKET [SUBSCRIPTIONS_ENDPOINT]

Message

{
  "method": "unsubscribe",
  "stream": {
    "type": "best_bid_offer",
    "product_id": 0
  },
  "id": 10
}

{% endtab %}

{% tab title="Fill" %} Connect

WEBSOCKET [SUBSCRIPTIONS_ENDPOINT]

Message

{
  "method": "unsubscribe",
  "stream": {
    "type": "fill",
    "product_id": 0,
    "subaccount": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43746573743000000000000000"
  },
  "id": 10
}

{% endtab %}

{% tab title="Position Change" %} Connect

WEBSOCKET [SUBSCRIPTIONS_ENDPOINT]

Message

{
  "method": "unsubscribe",
  "stream": {
    "type": "position_change",
    "product_id": 0,
    "subaccount": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43746573743000000000000000"
  },
  "id": 10
}

{% endtab %}

{% tab title="Book Depth" %} Connect

WEBSOCKET [SUBSCRIPTIONS_ENDPOINT]

Message

{
  "method": "unsubscribe",
  "stream": {
    "type": "book_depth",
    "product_id": 0,
  },
  "id": 10
}

{% endtab %} {% endtabs %}

Response

{
  "result": null,
  "id": 10
}

Listing subscribed streams

{
  "method": "list",
  "id": 10
}

Response

{
  "result": [
    {
      "type": "default"
    },
    {
      "type": "trade",
      "product_id": 0
    }
  ],
  "id": 10
}