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

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
24 4 7 11

Python Websocket sent multiple batch requests but only one is accepted

Hi

I'm writing a python websoket program to get all HK equities(0001.HK to 9999.HK(main board) and 10000.HK to 99999.HK(CBBCs, warrants, CNY stocks)).

Since there's a MaxMsgSize of 65535 (per batch request I assume?). I try to sent 5 batch requests(requesting 0001.HK to 9999.HK about 1999 RICs per request) but only one batch request is accepted. As shown below

Why is that?

Thank you

.batch-request-accepted.png1to1999.png

python#technologyapiwebsockets
icon clock
10 |1500

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

2000to3999.png4000to5999.png

The above shows the ID of the batch requests

2000to3999.png (8.1 KiB)
4000to5999.png (9.4 KiB)

6000to7999.png8000to9999.png

The rest of the batch requests

6000to7999.png (9.8 KiB)
8000to9999.png (9.8 KiB)
Upvotes
Accepted
17.9k 82 39 63

Hi @tobywong

The MaxMsgSize represents the total number of bytes sent in your request. Given each item is a variable number of bytes, you will have to calculate/estimate the number of items based on a calculation. I think only 1 batch got through because it resulted in a allowable number of total bytes.

icon clock
10 |1500

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

@nick.zincone So the MaxMsgSize is the limit for all the batch requests combined. Not 65535 bytes per batch request?

@tobywong, the max size represents the maximum number of bytes in a request. What you should do if log the size of each batch you send out - the size of the complete message you send on the WebSocket channel. Each batch you send will contain a different size because each batch contains entries that contain a variable number of bytes.
@nick.zincone

Is the MaxMsgSize 65535 bytes limit for one batch request or all the batch requests combined? Since if it's for one request, the other batch requests should go through. Because all the RICs in these batch requests are in the format of 0001.HK, 9999.HK, 5650.HK etc.

Show more comments
Upvotes
80.3k 259 52 75

@tobywong

Thank you for reaching out to us.

It could be the limitation on the server. The server may not have enough resources to process all requested items.

Typically, the application should implement throttling which limits the number of requested items over a set time. For example, after sending the first batch, the application needs to wait for all item responses before sending the next batch request. With this method, the server could have enough reesouces to handl all requested items.

Otherwise, you can contact the server team directly via MyRefinitiv to verify what the problem is.

icon clock
10 |1500

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

@Jirapongse

But I need to keep subscribed to the RICs for the real time update. If I wait for all item responses(but it will not end. Since it's not a snapshot) and then send the next batch request, will I unsubsribed to the previous batch of RICs?

@tobywong

If there are 1999 items in the batch request and all items are valid, the server will send 1999 refresh messages to the application. The application can count the number of the retrieved refresh messages.

WebSocket is not high performance. Please make sure that the application is powerful enough to handle the update rate of all subcribed items.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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