Options

API changes: Subscription call bug fix for req_id argument

Dear developers,
As per current API behaviour applicable for the following subscription calls:

ticks
ticks_history
exchange_rates

If a request is made with different req_id, API considers those as separate subscriptions requests and provides multiple subscription responses for the same symbol or same asset requested.

For example, currently, subscribes to tick with different req_id with same symbol, for example,

{
  "ticks": "R_50",
  "subscribe": 1,
  "req_id": 1
}
{
  "ticks": "R_50",
  "subscribe": 1,
  "req_id": 2
}

will lead to two separate subscriptions

{
  "echo_req": {
    "req_id": 1,
    "subscribe": 1,
    "ticks": "R_50"
  },
  "msg_type": "tick",
  "req_id": 1,
  "subscription": {
    "id": "f0499013-9edd-3b7b-88b2-27b21e2be755"
  },
  "tick": {
    "ask": 191.5129,
    "bid": 191.4929,
    "epoch": 1698231168,
    "id": "f0499013-9edd-3b7b-88b2-27b21e2be755",
    "pip_size": 4,
    "quote": 191.5029,
    "symbol": "R_50"
  }
}
{
  "echo_req": {
    "req_id": 2,
    "subscribe": 1,
    "ticks": "R_50"
  },
  "msg_type": "tick",
  "req_id": 2,
  "subscription": {
    "id": "34ccc31a-27d7-3c08-9158-6d0778f66ddd"
  },
  "tick": {
    "ask": 191.5568,
    "bid": 191.5368,
    "epoch": 1698231170,
    "id": "34ccc31a-27d7-3c08-9158-6d0778f66ddd",
    "pip_size": 4,
    "quote": 191.5468,
    "symbol": "R_50"
  }
}

when you send forget_all call to forget all the subscriptions

{
  "forget_all": "ticks"
}

you will notice that two subscriptions were active

{
  "echo_req": {
    "forget_all": "ticks"
  },
  "forget_all": [
    "34ccc31a-27d7-3c08-9158-6d0778f66ddd",
    "f0499013-9edd-3b7b-88b2-27b21e2be755"
  ],
  "msg_type": "forget_all"
}

We are fixing this bug of removing req_id consideration for subscription, and going forward the second request for the same symbol with different req_id

{
  "ticks": "R_50",
  "subscribe": 1,
  "req_id": 2
}

will result in the following error

{
  "echo_req": {
    "req_id": 2,
    "subscribe": 1,
    "ticks": "R_50"
  },
  "error": {
    "code": "AlreadySubscribed",
    "message": "You are already subscribed to R_50"
  },
  "msg_type": "tick",
  "req_id": 2
}

But request for subscription with different symbol, for example:

{
  "ticks": "R_100",
  "subscribe": 1, 
  "req_id": 2
}

will work normally

{
  "echo_req": {
    "req_id": 2,
    "subscribe": 1,
    "ticks": "R_100"
  },
  "msg_type": "tick",
  "req_id": 2,
  "subscription": {
    "id": "1c653e0b-61f8-00ba-fbee-b3b46ac01cb1"
  },
  "tick": {
    "ask": 1442.01,
    "bid": 1441.61,
    "epoch": 1698231336,
    "id": "1c653e0b-61f8-00ba-fbee-b3b46ac01cb1",
    "pip_size": 2,
    "quote": 1441.81,
    "symbol": "R_100"
  }
}

This change applies to the following API calls:

ticks
ticks_history
exchange rates

Please make the necessary changes to your app(s) by week starting December 4, 2023.
If you have any questions, write to us at api-support@deriv.com.

Sign In or Register to comment.