restAPI | R Documentation |
Base class for Okx exchange v5 API.
You can implement all REST API requests in Okx exchange by inheriting the restAPI
class.
Please refer to the example provided at the end of the document.
For commonly used interfaces, they have been implemented in this package.
The naming convention is as follows: for "/api/v5/AAA/BBB", a new class named restAPIAAA
,
which inherits from restAPI
, has been defined in this package.
The BBB
method in this new class is used to call the API.
url
Okx REST API url, which is https://www.okx.com.
api_key
Okx API key.
secret_key
Okx API secret key.
passphrase
Okx API passphrase.
simulate
Whether to use demo trading service.
new()
Create a new REST API object.
restAPI$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.
restAPI$get_timestamp()
get_request_path()
Get request path.
restAPI$get_request_path(api, method = c("GET", "POST"), ...)
api
Request api e.g. /api/v5/account/positions-history.
method
Request method, GET
or POST
.
...
Other request parameters.
get_body()
Get request body.
restAPI$get_body(method = c("GET", "POST"), ...)
method
Request method, GET
or POST
.
...
Other request parameters.
get_message()
Get the signing messages.
restAPI$get_message(timestamp, request_path, body, method = c("GET", "POST"))
timestamp
Retrieve through method get_timestamp
.
request_path
Retrieve through method get_request_path
.
body
Retrieve through method get_body
.
method
Request method, GET
or POST
.
get_signature()
Get the signature.
restAPI$get_signature(msg, secret_key = self$secret_key)
msg
Retrieve through method get_message
.
secret_key
Okx API secret key.
get_header()
Get request headers.
restAPI$get_header(timestamp, msg)
timestamp
Retrieve through method get_timestamp
.
msg
Retrieve through method get_message
.
get_result()
Retrieve data from api.
restAPI$get_result(api, method = c("GET", "POST"), process, ...)
api
Request api e.g. /api/v5/account/positions-history.
method
Request method, GET
or POST
.
process
A function to process the data received from the API.
...
Other request parameters.
clone()
The objects of this class are cloneable with this method.
restAPI$clone(deep = FALSE)
deep
Whether to make a deep clone.
restAPItrade
restAPIaccount
restAPImarket
## Not run:
# for [Get currencies](https://www.okx.com/docs-v5/en/#rest-api-funding-get-currencies)
# you can define the class like this
myRestAPI <- R6::R6Class(
inherit = restAPI,
public = list(
get_currencies = function(ccy, process = "identity") {
self$get_result(
api = "/api/v5/asset/currencies", method = "GET", process = process,
ccy = ccy
)
}
)
)
# And call it like this
tmp <- myRestAPI$new(api_key, secret_key, passphrase)
tmp$get_currencies("BTC")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.