【发布时间】:2021-01-11 09:38:13
【问题描述】:
我使用与这里https://cran.r-project.org/web/packages/websocket/readme/README.html相同的方法连接到websocket服务器
但是,使用ws$connect() 函数的输出具有以下结构
> ws$connect()
Connection opened
send login request
Got Message [{"ID":1,"Type":"Refresh","Domain":"Login","Key":{"Name":"XXXX","Elements":{"AllowSuspectData":1,"ApplicationId":"XXX","ApplicationName":"XXX","AuthenticationErrorCode":XXX,
"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 XXX"},"Elements":{"PingTimeout":XX,"MaxMsgSize":XXX}}]
#here starts part, which is needed to be saved (Price1-3)
Single Message
{"ID":2,"Key":{"Name":"XXX"},"View":["Price1","Price2","Price3"]}
Got Message [{"ID":2,"Type":"Refresh","Key":{"Service":"XXX","Name":"XXX"},"State":{"Stream":"Open","Data":"Ok","Text":"*All is well"},"Qos":{"Timeliness":"XXX","Rate":"XXX"},"PermData":"XXX","SeqNumber":4000,"Fields":{"Price1":16.255,"Price2":16.345,"Price3":5}}]
$onMessage() 函数如下(用# 标记了我添加的行,来源:https://github.com/Refinitiv/websocket-api/blob/master/Applications/Examples/R/market_price_authentication.R)
test1<-NULL
ws$onMessage(function(event) {
cat("Got Message",event$data,"\n")
jsonresp <- fromJSON(event$data, simplifyDataFrame=FALSE)
#test1<-event$data
#event$data
for (singleMsg in jsonresp){
process_message(singleMsg) # Single Message send pong
}
}
)
如何保存这个函数的输出?
【问题讨论】:
-
从在线文档看来,您似乎需要重写
onMessage()函数来存储/处理收到的消息。 -
@Limey 我更新了问题并将此功能添加到问题的底部。有 # 个市场行,我尝试保存,但没有保存。