For a deeper look into our Elektron API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
1 1 1 4

How do I Simulate Request/Response Model using WebSockets

Good Afternoon. I have been prototyping some things in C# .net using WebSockets. I am able to connect, login, request data and process the messages as they are streamed for 500 equities, 5 fields. This satisfies my first use case. My second use case is to try to simulate request/response model where I do not really care about 'update' type response messages, rather, only the initial data values returned in the 'refresh' type messages. Is there a difinitive way to determine that the initial response messages have completed? In this scenario I want to do the request, get the data, close the stream and return the data as quickly as possible. Hope you can help me.

Thanks.

Adam Strakna - T. Rowe Price, Baltimore, MD

treprdp-apiwebsocketsrrto.net
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

1 Answer

Upvotes
Accepted
9.7k 49 38 60

Hi @adam_strakna,

When making requests for data, the default behavior is to "Stream" the data, meaning, you get back an initial ('refresh') image and then when market conditions change, you will receive streaming updates. In your case, you will want to override the default behavior and request for "NonStreaming" data. Doing this, you will only receiving the initial image. So, your request will look something like this:

{
  "ID": 2,
  "Streaming": false,
  "Key": {
    "Name": [
      "TRI.N",
      "IBM.N",
      "JUNK.X"
    ]
  }
}

The attribute "Streaming" will control streaming vs non-streaming. The default is true - stream. In your case, you will set it to false - as above. When you make a non-streaming request, once you get a response back for an item, that stream will be automatically closed. You do not need to explicitly close the stream.

In the example above, I've requested for a batch of 3 items, 2 valid ones and one invalid. I did this intentionally to show you the proper way to detect when ALL requests have been fulfilled so you can determine that your request/response has completed.

The "ID" field within the request will drive this. When making a batch request, the server will automatically assign the next 3 subsequent ID's to each of the items within your batch. So in the above example, ID 3 will be assigned to 'TRI.N', ID 4 to 'IBM.N' and ID 5 to 'JUNK.X'.

When you make your request, you will get back the refresh for each of the valid items, i.e. ID 3 and ID 4. For example:

[
  {
    "ID": 3,
    "Type": "Refresh",
    "Key": {
      "Service": "IDN_SELECTFEED",
      "Name": "TRI.N"
    },
    "State": {
      "Stream": "NonStreaming",
      "Data": "Ok",
      "Text": "All is well"
    },
   ...

For the invalid symbol, 'JUNK.X' you will get back a Status message:

  {
    "ID": 5,
    "Type": "Status",
    "Key": {
      "Service": "IDN_SELECTFEED",
      "Name": "JUNK.X"
    },
    "State": {
      "Stream": "Closed",
      "Data": "Suspect",
      "Code": "NotFound",
      "Text": "The record could not be found"
    }

Your application will simply need to monitor all 'Refresh' and 'Status' messages for the ID's you are expecting back. Once all have arrived, the batch request has been fulfilled.

Hope this helps.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Click below to post an Idea Post Idea