| restAPI {okxAPI} | R Documentation |
restAPI Class
Description
Base class for Okx exchange v5 API.
Details
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.
Public fields
urlOkx REST API url, which is https://www.okx.com.
api_keyOkx API key.
secret_keyOkx API secret key.
passphraseOkx API passphrase.
simulateWhether to use demo trading service.
Methods
Public methods
Method new()
Create a new REST API object.
Usage
restAPI$new(api_key, secret_key, passphrase, simulate = FALSE)
Arguments
api_keyOkx API key.
secret_keyOkx API secret key.
passphraseOkx API passphrase.
simulateWhether to use demo trading service.
Method get_timestamp()
Get UTC timestamp.
Usage
restAPI$get_timestamp()
Method get_request_path()
Get request path.
Usage
restAPI$get_request_path(api, method = c("GET", "POST"), ...)Arguments
apiRequest api e.g. /api/v5/account/positions-history.
methodRequest method,
GETorPOST....Other request parameters.
Method get_body()
Get request body.
Usage
restAPI$get_body(method = c("GET", "POST"), ...)Arguments
methodRequest method,
GETorPOST....Other request parameters.
Method get_message()
Get the signing messages.
Usage
restAPI$get_message(timestamp, request_path, body, method = c("GET", "POST"))Arguments
timestampRetrieve through method
get_timestamp.request_pathRetrieve through method
get_request_path.bodyRetrieve through method
get_body.methodRequest method,
GETorPOST.
Method get_signature()
Get the signature.
Usage
restAPI$get_signature(msg, secret_key = self$secret_key)
Arguments
msgRetrieve through method
get_message.secret_keyOkx API secret key.
Method get_header()
Get request headers.
Usage
restAPI$get_header(timestamp, msg)
Arguments
timestampRetrieve through method
get_timestamp.msgRetrieve through method
get_message.
Method get_result()
Retrieve data from api.
Usage
restAPI$get_result(api, method = c("GET", "POST"), process, ...)Arguments
apiRequest api e.g. /api/v5/account/positions-history.
methodRequest method,
GETorPOST.processA function to process the data received from the API.
...Other request parameters.
Method clone()
The objects of this class are cloneable with this method.
Usage
restAPI$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
See Also
restAPItrade
restAPIaccount
restAPImarket
Examples
## 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)