if (FALSE) {
tmp <- websocketAPIpublic$new()
tmp$connect()
# subscribe BTC-USDT-SWAP 5m candlesticks data
msg <- list(
op = "unsubscribe",
args = list(
list(channel = "candle5m", instId = "BTC-USDT-SWAP")
)
)
msg <- jsonlite::toJSON(msg, auto_unbox = TRUE, pretty = TRUE)
tmp$send(msg)
# pass your own callback function
tmp$on_message(function(event) {
if (event$data == "pong") {
cat("Bingo!!\n")
}
})
tmp$send("ping")
tmp$close()
}
Run the code above in your browser using DataLab