websocketAPIprivate {okxAPI} | R Documentation |
websocketAPIprivate Class
Description
Private channel of WebSocket API for Okx exchange v5 API. See Private Channel for more information.
Public fields
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.
Methods
Public methods
Method new()
Craeate a new websocketAPIprivate object.
Usage
websocketAPIprivate$new(api_key, secret_key, passphrase, simulate = FALSE)
Arguments
api_key
Okx API key.
secret_key
Okx API secret key.
passphrase
Okx API passphrase.
simulate
Whether to use demo trading service.
Method get_timestamp()
Get UTC timestamp.
Usage
websocketAPIprivate$get_timestamp()
Method get_message()
Get the signing messages.
Usage
websocketAPIprivate$get_message(timestamp)
Arguments
timestamp
Retrieve through method
get_timestamp
.
Method get_signature()
Get the signature.
Usage
websocketAPIprivate$get_signature(secret_key, msg)
Arguments
secret_key
Okx API secret key.
msg
Retrieve through method
get_message
.
Method connect()
Initiate the connection to the server.
Usage
websocketAPIprivate$connect()
Method login()
Log in.
Usage
websocketAPIprivate$login()
Method on_open()
Called when the connection is established.
Usage
websocketAPIprivate$on_open(func)
Arguments
func
A Callback function.
Method 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.
Usage
websocketAPIprivate$on_close(func)
Arguments
func
A Callback function.
Method on_message()
Called each time a message is received from the server. The event will have a 'data' element, which is the message content.
Usage
websocketAPIprivate$on_message(func)
Arguments
func
A Callback function.
Method 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.
Usage
websocketAPIprivate$on_error(func)
Arguments
func
A Callback function.
Method send()
Send a message to the server.
Usage
websocketAPIprivate$send(msg)
Arguments
msg
Messages.
Method close()
Close the connection.
Usage
websocketAPIprivate$close()
Method clone()
The objects of this class are cloneable with this method.
Usage
websocketAPIprivate$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
Examples
## 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)