[Request] return an ID on each follow up response from the subscribe command
Summary
A feature request to implement a way to ID the different responses from a subscribe command (account/orderbook)
Motivation
For a DEX UI there needs to be at least two subscriptions with the Websocket API namely: account & orderbook. It would be great if there is way to separate the two incoming transactions with an ID for example like in the initial response, this is needed for the correct parsing of the data.
Addition:
Currently, when a subscribe command is sent over a WebSocket connection to rippled, the direct response reflects the value provided in the id field when sending the subscribe command:
> {"command":"subscribe","streams":["ledger"],"id":"123123123"}
< {"id":"123123123","result":{"fee_base":10,"fee_ref":10,"ledger_hash":"61DEA0A8ED544D59236A1BF7B9FBA3E66E9C3970839A3F8C2B0FDE7393935DCA","ledger_index":66473882,"ledger_time":685405220,"reserve_base":10000000,"reserve_inc":2000000,"validated_ledgers":"65208976-66473882"},"status":"success","type":"response"}
All subsequent subscription updates don't have this ID attached:
< {"fee_base":10,"fee_ref":10,"ledger_hash":"E013DAED4CBBF2C1BCA82C9258CF4D1176869E0953E76285F84D7F90FF998BA5","ledger_index":66473887,"ledger_time":685405240,"reserve_base":10000000,"reserve_inc":2000000,"txn_count":82,"type":"ledgerClosed","validated_ledgers":"65208976-66473887"}
It would be great if these subscription updates (all types, ledger, account, ...) contained the same id field as well, or (to be able to distinct the update from the original response) e.g. an originId field.
So do you just want each distinct stream to have a distinct ID? Does it matter what that ID is? Also, say you subscribe to multiple accounts on the accounts stream, do you want different IDs for different accounts?
In case of multiple streams / multiple accounts: the update message type / account are the unique keys to track. If one would want to track them separately, one should send separate subscribe commands with their own ID.
The id doesn't matter, as long as (just like with the simple request/response flow) the async subscription responses match the original subscription id (so it can be tracked that it's an async subscription response matching a specific subscribe flow)
I'm slightly confused by the actual feature being requested. @KoenPaas @WietseWind Are you both asking for the same feature? We can add the original id passed in the request to the responses sent on the subscription stream. Is that all that's needed? Because the original question said this:
For a DEX UI there needs to be at least two subscriptions with the Websocket API namely: account & orderbook. It would be great if there is way to separate the two incoming transactions with an ID
If you subscribe to accounts and books via the same subscribe call, with an ID in the request, and we add that ID to any responses on the stream, you won't be able to separate responses that are for the accounts stream versus responses for the books stream, since they would both have the same ID.
Just so you understand, if I send this request:
{
"id": "some id",
"command": "subscribe",
"accounts": ["rrpNnNLKrartuEqfJGpqyDwPj1AFPg9vn1"],
"books": [
{
"taker_pays": {
"currency": "XRP"
},
"taker_gets": {
"currency": "USD",
"issuer": "rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq"
},
"snapshot": true
}
]
}
I will then get messages about transactions affecting the specified account, and transactions affecting the specified book. Both messages would have the same ID though. Is that ok?
My apologies if it it was confusing at first. The issue is that the response you will get after the initial response: that there is no ID at all plus we need to identify the separate responses from each subscription.
after using the command you gave here's an example of where the issue is:
{
"id": "some id",
"result": {
"offers": [...]
},
"status": "success",
"type": "response"
}
The following responses will be as follows:
{
"engine_result": "tesSUCCESS",
"engine_result_code": 0,
"engine_result_message": "The transaction was applied. Only final in a validated ledger.",
"ledger_hash": "78140F83621D8A783942147DD7F85529FA25C4BD4517A4C35CE9B51E3DD6CC88",
"ledger_index": 66491446,
"meta": {...},
"type": "transaction",
"validated": true
}
As you can see there is no ID and it can be either from the account subscribe or orderbook this is what we want to separate.
Does this clarify the issue at hand?
Ok, so you want an ID in the followup messages, and you want a way to determine whether the message is from the account subscribe or the order book subscribe?
Yes exactly!
Ok cool. So we can add the ID to each message on the stream, and we could probably add some sort of field like:
{
...
"stream":"books"
}
to specify which stream type this message corresponds to. Would that be sufficient?
That would be perfect!