websocketAPIprivate | R Documentation |
Private channel of WebSocket API for Okx exchange v5 API. See Private Channel for more information.
channel
Private WebSocket url.
api_key
Okx API key.
secret_key
Okx API secret key.
passphrase
Okx API passphrase.
simulate
Whether to use demo trading service.
ws
A websocket::WebSocket object to establish a connection to the server.
new()
Craeate a new websocketAPIprivate object.
websocketAPIprivate$new(api_key, secret_key, passphrase, simulate = FALSE)
api_key
Okx API key.
secret_key
Okx API secret key.
passphrase
Okx API passphrase.
simulate
Whether to use demo trading service.
get_timestamp()
Get UTC timestamp.
websocketAPIprivate$get_timestamp()
get_message()
Get the signing messages.
websocketAPIprivate$get_message(timestamp)
timestamp
Retrieve through method get_timestamp
.
get_signature()
Get the signature.
websocketAPIprivate$get_signature(secret_key, msg)
secret_key
Okx API secret key.
msg
Retrieve through method get_message
.
connect()
Initiate the connection to the server.
websocketAPIprivate$connect()
login()
Log in.
websocketAPIprivate$login()
on_open()
Called when the connection is established.
websocketAPIprivate$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.
websocketAPIprivate$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.
websocketAPIprivate$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.
websocketAPIprivate$on_error(func)
func
A Callback function.
send()
Send a message to the server.
websocketAPIprivate$send(msg)
msg
Messages.
close()
Close the connection.
websocketAPIprivate$close()
clone()
The objects of this class are cloneable with this method.
websocketAPIprivate$clone(deep = FALSE)
deep
Whether to make a deep clone.
## Not run:
tmp <- websocketAPIprivate$new(api_key, secret_key, passphrase)
tmp$connect()
Sys.sleep(1)
tmp$login()
# subscribe account information
msg <- list(
op = "subscribe",
args = list(
list(channel = "account", ccy = "USDT")
)
)
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.