Discover Refinitiv
MyRefinitiv Refinitiv Perspectives Careers
Created with Sketch.
All APIs Questions & Answers  Register |  Login
Ask a question
  • Questions
  • Tags
  • Badges
  • Unanswered
Search:
  • Home /
  • Elektron /
  • WebSocket API /
avatar image
Question by g.suhharukov · Jan 11 at 12:51 PM · elektronwebsocketrrdp

How save the messages from the websocket server using R?

I am using following file to connect to the Elektron service websocketr (1).txt This file is based on the following link https://github.com/Refinitiv/websocket-api/blob/master/Applications/Examples/R/market_price_authentication.R

I got a message (with bid and ask prices) with the output from the server like:


> ws$connect()
Connection opened
send login request
Got Message [{"ID":1,"Type":"Refresh","Domain":"Login","Key":{"Name":"","Elements":{"AllowSuspectData":1,"ApplicationId":"256","ApplicationName":"ADS","AuthenticationErrorCode":0,"AuthenticationErrorText":{"Type":"AsciiString","Data":null},"AuthenticationTTReissue":xxx,"Position":"xxx","ProvidePermissionExpressions":1,"ProvidePermissionProfile":0,"SingleOpen":1,"SupportEnhancedSymbolList":1,"SupportOMMPost":1,"SupportPauseResume":0,"SupportStandby":0,"SupportBatchRequests":7,"SupportViewRequests":1,"SupportOptimizedPauseResume":0}},"State":{"Stream":"Open","Data":"Ok","Text":"Login accepted by host ads-premium-az1-blue-15-main-prd.euw1-az1."},"Elements":{"PingTimeout":30,"MaxMsgSize":61430}}] 
Single Message 
{"ID":2,"Key":{"Name":"xxx"},"View":["BID","ASK"]}
Got Message [{"ID":2,"Type":"Refresh","Key":{"Service":"ELEKTRON_DD","Name":"xxx"},"State":{"Stream":"Open","Data":"Ok","Text":"*All is well"},"Qos":{"Timeliness":"Realtime","Rate":"JitConflated"},"PermData":"xxx","SeqNumber":xxx,"Fields":{"BID":16.300,"ASK":16.345}}] 
Single Message 
Got Message [{"Type":"Ping"}] 
Single Message 


How can I save the output seen in the console to the datatrame/ or csv file, or better if for every refresh token(every 5 min) a file with the output is saved to the computer memory. it seems that ws$onMessage or process_message() functions should be slightly modified, but do not understand how. Could you help?

websocketr-1.txt (3.8 KiB)

People who like this

0 Show 0
Comment
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

2 Replies

  • Sort: 
avatar image
REFINITIV
Best Answer
Answer by Gurpreet · Jan 11 at 06:30 PM

Hi @g.suhharukov,

The messages from websocket API are in the JSON format, which is a nested message format unlike CSV. Your application you will have to parse the JSON and need to pick a branch which represents the tabular data that it needs. This tabular data can then be loaded into a Dataframe or written to a file as CSV. For e.g. in the data message you received, the Fields key contains this data.

DataFrame(jMsg[0]['Fields'])

See this question on loading JSON into DF: https://stackoverflow.com/questions/36454638/how-can-i-convert-json-to-data-frame-in-r

Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

avatar image
REFINITIV
Answer by wasin.waeosri · Jan 12 at 03:02 AM

Hello @g.suhharukov

Please note that you can find how to write a file (CSV, etc. format) in R from the following external resources:

  • Writing Data From R to txt|csv Files: R Base Functions
  • How to Export DataFrame to CSV in R
Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

Watch this question

Add to watch list
Add to your watch list to receive emailed updates for this question. Too many emails? Change your settings >
10 People are following this question.

Related Questions

Establish a websocket connection and set headers?

Domains in Elektron WebSocket API

Reason to select neovisionaries Websocket library

How to retrieve timestamp for update messages via Elektron Websocket API

Any action needed for this error: Message Ordering Error. Recalling?

  • Feedback
  • Copyright
  • Cookie Policy
  • Privacy Statement
  • Terms of Use
  • Careers
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Alpha
  • App Studio
  • Block Chain
  • Bot Platform
  • Calais
  • Connected Risk APIs
  • DSS
  • Data Fusion
  • Data Model Discovery
  • Datastream
  • Eikon COM
  • Eikon Data APIs
  • Elektron
    • EMA
    • ETA
    • WebSocket API
  • Legal One
  • Messenger Bot
  • Messenger Side by Side
  • ONESOURCE
    • Indirect Tax
  • Open PermID
    • Entity Search
  • Org ID
  • PAM
    • PAM - Logging
  • ProView
  • ProView Internal
  • Product Insight
  • Project Tracking
  • Refinitiv Data Platform
    • Refinitiv Data Platform Libraries
  • Rose's Space
  • Screening
    • Qual-ID API
    • Screening Deployed
    • Screening Online
    • World-Check One
    • World-Check One Zero Footprint
  • Side by Side Integration API
  • TR Knowledge Graph
  • TREP APIs
    • CAT
    • DACS Station
    • Open DACS
    • RFA
    • UPA
  • TREP Infrastructure
  • TRIT
  • TRKD
  • TRTH
  • Thomson One Smart
  • Transactions
    • REDI API
  • Velocity Analytics
  • Wealth Management Web Services
  • World-Check Data File
  • Explore
  • Tags
  • Questions
  • Badges