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

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
5 1 2 3

Use the websocket API in synchronous mode

What is the best way to get a price snapshot synchronously.

What I would like:

ws.send(request)

result = ws.recv()

The problem is that I can receive different messages (ping for instance..).

Do I have to necessarily implement a logic to filter the answers ?

treprdp-apiwebsocketsrrtosynchronous
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.

13 Answers

Upvotes
Accepted
13k 32 12 18

@chbailly The websocket is a connection oriented API, and there is minimal housekeeping that has to be performed - like login before making a data request, and responding to ping requests. These have to be done, regardless of request for snapshot or streaming data.

We don't have a synchronous access helper for it, but might consider providing such "ease of use library" in future. For now, please see the implementation details in the provided code samples.

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.

Upvotes
5 1 2 3

I realised that I was not in snapshot mode..

So now I think I do not have to filter the answers, I am supposed to receive the answer directly, no need to filter (no ping for instance)

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.

Upvotes
5 1 2 3

Thanks for your answer.

Are you saying that potentially I can receive a ping even in snapshot mode ?

The code is not straightforward.. We have to match the correct request, the error management is also made more complicated. What do we do if we do not fintd the matching request, how do we set a timeout..; This is really easy to write an incorrect code even if it looks simple.

An helper would really be a good idea imho. Sometimes, we just need to write simple and basic code. 2 lines, the send followed by the rcv...

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.

Upvotes
13k 32 12 18

Yes, as long as the connection is held open, ping messages are sent to asset that TCP connection is still open. This would happen regardless of snapshot or any request for data.

The websockets is a protocol specification, rather than an API, and protocol requires that application start with a login and maintain ping/pong messages.

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.

Upvotes
5 1 2 3

I agree, it makes sense; thanks

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.

Upvotes
7 2 0 2

Hhi - just checking to see if any decision had been made on a synchronous access helper as yet and iff there was any potential eta for it?

Many thanks

Ranjit

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.

Upvotes
13k 32 12 18

@ranjit.talukdar You can take a look for Websocket examples in the TR API Samples github repository - specifically the Quote Widget, which uses the TRWebsocketController. This controller sample is in Javascript and can be used as a helper object in your own implementations.

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.

Upvotes
7 2 0 2

Thanks @Gurpreet but do you have anything in python?

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.

Upvotes
7 2 0 2

@Gurpreet - also this looks to be for streaming data as opposed to snapshot

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.

Upvotes
13k 32 12 18

@ranjit.talukdar We don't have anything for python yet. I will try to produce a minimal sample and let you know.

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.

Upvotes
7 2 0 2

@Gurpreet. - Hi - just wopndering if u had any luck as yet.

many thanks in advance.

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.

Upvote
13k 32 12 18

Hi @ranjit.talukdar, We are working on a library. It will be a few weeks before an early beta version can be shared with community.

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.

Hi @Gurpreet

Just wondering if the beta version of the library is ready as yet?

No, we are targeting the library to work across different platforms, and the library interface is not finalized yet.

Thanks @Gurpreet.

is there any eta you think you could share?

many thanks

Hi @ranjit.talukdar, As of now, it we are targeting Q1 2019.

Meanwhile, is there any coding help we can provide to get you going with your project?

Show more comments
Upvotes
7 2 0 2

that would be great - many thanks @Gurpreet.

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