Skip to content

Commit

Permalink
Docs and validated function.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereckmezquita committed Feb 25, 2025
1 parent f444896 commit 89e69a2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
22 changes: 9 additions & 13 deletions R/impl_account_sub_account.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,10 @@ box::use(
#' @param remarks Character string (optional); remarks or notes about the sub-account (1–24 characters if provided).
#'
#' @return Promise resolving to a `data.table` containing sub-account details, including:
#' - `userId` (character): Unique identifier of the master account.
#' - `uid` (integer): Unique identifier for the sub-account.
#' - `uid` (numeric): Unique identifier for the sub-account.
#' - `subName` (character): Name of the sub-account.
#' - `status` (integer): Current status of the sub-account.
#' - `type` (integer): Type of sub-account.
#' - `remarks` (character): Remarks or notes associated with the sub-account.
#' - `access` (character): Permission type granted to the sub-account.
#' - `createdAt` (integer): Timestamp of creation in milliseconds.
#' - `remarks` (character): Any provided remarks or notes.
#' - `tradeTypes` (list): Array of available trade types for the sub-account.
#' - `openedTradeTypes` (list): Array of currently open trade types.
#' - `hostedStatus` (character or NULL): Hosted status of the sub-account.
#'
#' ## Details
#'
Expand All @@ -92,6 +85,10 @@ box::use(
#' ### Response Schema
#' - `code` (string): Status code, where `"200000"` indicates success.
#' - `data` (object): Contains pagination metadata and an `items` array with the sub-account details.
#' - `uid` (integer): Unique identifier for the sub-account.
#' - `subName` (string): Name of the sub-account.
#' - `remarks` (string): Remarks or notes associated with the sub-account.
#' - `access` (string): Permission type granted to the sub-account.
#'
#' **Example JSON Response**:
#' ```json
Expand Down Expand Up @@ -169,9 +166,8 @@ add_subaccount_impl <- coro::async(function(
access = c("Spot", "Futures", "Margin"),
remarks = NULL
) {
access <- rlang::arg_match(access)
access <- rlang::arg_match0(access, values = c("Spot", "Futures", "Margin"))
tryCatch({

endpoint <- "/api/v2/sub/user/created"
method <- "POST"
body_list <- list(
Expand All @@ -186,9 +182,9 @@ add_subaccount_impl <- coro::async(function(
headers <- await(build_headers(method, endpoint, body, keys))
url <- paste0(base_url, endpoint)
response <- httr::POST(url, headers, body = body, encode = "raw", httr::timeout(3))
saveRDS(response, "./api-responses/impl_account_sub_account/response-add_subaccount_impl.ignore.Rds")
# saveRDS(response, "../../api-responses/impl_account_sub_account/response-add_subaccount_impl.ignore.Rds")
parsed_response <- process_kucoin_response(response, url)
saveRDS(parsed_response, "./api-responses/impl_account_sub_account/parsed_response-add_subaccount_impl.Rds")
# saveRDS(parsed_response, "../../api-responses/impl_account_sub_account/parsed_response-add_subaccount_impl.Rds")
return(data.table::as.data.table(parsed_response$data))
}, error = function(e) {
rlang::abort(paste("Error in add_subaccount_impl:", conditionMessage(e)))
Expand Down
23 changes: 13 additions & 10 deletions scripts/tests-manual/run-single_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ box::use(
get_deposit_addresses_v3_impl,
get_deposit_history_impl
],
../../R/impl_account_sub_account[
add_subaccount_impl,
get_subaccount_list_summary_impl,
get_subaccount_detail_balance_impl,
get_subaccount_spot_v2_impl
],
../../R/utils[get_api_keys, get_base_url],
../../R/utils_time_convert_kucoin[time_convert_from_kucoin, time_convert_to_kucoin],
coro[async, await],
Expand All @@ -28,19 +34,16 @@ main_async <- async(function() {
keys <- get_api_keys()
base_url <- get_base_url()

# Example 1: Using lubridate datetime objects directly
cat("\n--- Example 1: Using datetime objects ---\n")
history1 <- await(get_deposit_history_impl(
# 1. Add a subaccount
subaccount <- await(add_subaccount_impl(
keys = keys,
base_url = base_url,
currency = "BTC",
status = "SUCCESS",
startAt = lubridate::now() - lubridate::years(3),
endAt = lubridate::now(),
page_size = 50
password = "some69superComplexS3cr3tP@ssw0rd",
subName = "rtradebot6971469",
access = "Spot",
remarks = "Some super genius remark"
))
cat("\nDeposit History for BTC (using datetime objects):\n")
print(history1)
print(subaccount)
})

# Run the main async function
Expand Down

0 comments on commit 89e69a2

Please sign in to comment.