websocketAPIpublic | R Documentation |
Public channel of WebSocket API for Okx exchange v5 API. See Public Channel for more information.
channel
Public WebSocket url.
simulate
Whether to use demo trading service.
ws
A websocket::WebSocket object to establish a connection to the server.
new()
Create a new websocketAPIpublic object.
websocketAPIpublic$new(simulate = FALSE)
simulate
Whether to use demo trading service.
connect()
Initiate the connection to the server.
websocketAPIpublic$connect()
on_open()
Called when the connection is established.
websocketAPIpublic$on_open(func)
func
A Callback function.
on_close()
Called when a previously-opened connection is closed. The event will have 'code' (integer) and 'reason' (one-element character) elements that describe the remote's reason for closing.
websocketAPIpublic$on_close(func)
func
A Callback function.
on_message()
Called each time a message is received from the server. The event will have a 'data' element, which is the message content.
websocketAPIpublic$on_message(func)
func
A Callback function.
on_error()
Called when the connection fails to be established. The event will have an 'message' element, a character vector of length 1 describing the reason for the error.
websocketAPIpublic$on_error(func)
func
A Callback function.
send()
Send a message to the server.
websocketAPIpublic$send(msg)
msg
Messages.
close()
Close the connection.
websocketAPIpublic$close()
clone()
The objects of this class are cloneable with this method.
websocketAPIpublic$clone(deep = FALSE)
deep
Whether to make a deep clone.
## Not run:
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()
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.