Creates a new sub-account on KuCoin asynchronously by sending a POST request to the /api/v2/sub/user/created
endpoint. This internal function is designed for use within an R6 class and is not intended for direct end-user consumption.
Usage
add_subaccount_impl(
keys = get_api_keys(),
base_url = get_base_url(),
password,
subName,
access = c("Spot", "Futures", "Margin"),
remarks = NULL,
.__coro_env_parent__ = <environment>
)
Arguments
- keys
List containing API configuration parameters from
get_api_keys()
, including:api_key
: Character string; your KuCoin API key.api_secret
: Character string; your KuCoin API secret.api_passphrase
: Character string; your KuCoin API passphrase.key_version
: Character string; API key version (e.g.,"2"
). Defaults toget_api_keys()
.
- base_url
Character string representing the base URL for the API. Defaults to
get_base_url()
.- password
Character string; sub-account password (7–24 characters, must contain both letters and numbers).
- subName
Character string; desired sub-account name (7–32 characters, must include at least one letter and one number, no spaces).
- access
Character string; permission type for the sub-account (allowed values:
"Spot"
,"Futures"
,"Margin"
).- remarks
Character string (optional); remarks or notes about the sub-account (1–24 characters if provided).
Value
Promise resolving to a data.table
containing sub-account details, including at least:
uid
(integer): Unique identifier for the sub-account.subName
(character): Name of the sub-account.remarks
(character): Any provided remarks or notes.access
(character): Permission type granted to the sub-account.
Details
Workflow Overview
URL Construction: Retrieves the base URL using
get_base_url()
(or the user-suppliedbase_url
) and appends the endpoint.Request Body Preparation: Creates a list with required parameters (
password
,subName
,access
, and optionalremarks
), converted to JSON format usingjsonlite::toJSON()
withauto_unbox = TRUE
.Header Preparation: Generates authentication headers asynchronously via
build_headers()
, incorporating the signature, timestamp, encrypted passphrase, and API key details.API Request: Sends a POST request using
httr::POST()
with the constructed URL, headers, and JSON body, applying a 3-second timeout.Response Handling: Processes the JSON response with
process_kucoin_response()
, raising an error if the HTTP status is not 200 or the API code is not"200000"
.Result Conversion: Converts the
data
field of the successful response into adata.table
.
Usage
Utilised internally to establish sub-accounts for managing separate trading permissions within the KuCoin ecosystem.
Official Documentation
Raw Response Schema:
code
(string): Status code, where"200000"
indicates success.data
(object): Contains the sub-account details as described above.
Example JSON response:
{
"code": "200000",
"data": {
"currentPage": 1,
"pageSize": 10,
"totalNum": 1,
"totalPage": 1,
"items": [
{
"userId": "63743f07e0c5230001761d08",
"uid": 169579801,
"subName": "testapi6",
"status": 2,
"type": 0,
"access": "All",
"createdAt": 1668562696000,
"remarks": "remarks",
"tradeTypes": ["Spot", "Futures", "Margin"],
"openedTradeTypes": ["Spot"],
"hostedStatus": null
}
]
}
}
Examples
if (FALSE) { # \dontrun{
keys <- get_api_keys()
base_url <- "https://api.kucoin.com"
main_async <- coro::async(function() {
result <- await(add_subaccount_impl(
keys = keys,
base_url = base_url,
password = "1234567",
subName = "Name1234567",
access = "Spot",
remarks = "Test sub-account"
))
print(result)
})
main_async()
while (!later::loop_empty()) later::run_now()
} # }