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
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.
Methods
Public methods
Method new()
Create a new REST API object.
Usage
restAPI$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
restAPI$get_timestamp()
Method get_request_path()
Get request path.
Usage
restAPI$get_request_path(api, method = c("GET", "POST"), ...)
Arguments
api
Request api e.g. /api/v5/account/positions-history.
method
Request method,
GET
orPOST
....
Other request parameters.
Method get_body()
Get request body.
Usage
restAPI$get_body(method = c("GET", "POST"), ...)
Arguments
method
Request method,
GET
orPOST
....
Other request parameters.
Method get_message()
Get the signing messages.
Usage
restAPI$get_message(timestamp, request_path, body, method = c("GET", "POST"))
Arguments
timestamp
Retrieve through method
get_timestamp
.request_path
Retrieve through method
get_request_path
.body
Retrieve through method
get_body
.method
Request method,
GET
orPOST
.
Method get_signature()
Get the signature.
Usage
restAPI$get_signature(msg, secret_key = self$secret_key)
Arguments
msg
Retrieve through method
get_message
.secret_key
Okx API secret key.
Method get_header()
Get request headers.
Usage
restAPI$get_header(timestamp, msg)
Arguments
timestamp
Retrieve through method
get_timestamp
.msg
Retrieve through method
get_message
.
Method get_result()
Retrieve data from api.
Usage
restAPI$get_result(api, method = c("GET", "POST"), process, ...)
Arguments
api
Request api e.g. /api/v5/account/positions-history.
method
Request method,
GET
orPOST
.process
A 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
deep
Whether 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)