Skip to contents

Constructs an httr2::request, optionally signs it, performs it via the supplied .perform function, and parses the KuCoin JSON response. This is the single point through which all KuCoin API calls flow.

Usage

kucoin_build_request(
  base_url,
  endpoint,
  method = "GET",
  query = list(),
  body = NULL,
  keys = NULL,
  .perform = httr2::req_perform,
  .parser = identity,
  is_async = FALSE,
  timeout = 10,
  .get_timestamp_ms = NULL
)

Arguments

base_url

Character; the API base URL.

endpoint

Character; the API path.

method

Character; HTTP method. Default "GET".

query

Named list; query parameters. Default list().

body

Named list or NULL; request body. Default NULL.

keys

List or NULL; API credentials. Default NULL.

.perform

Function; the httr2 perform function. Default httr2::req_perform.

.parser

Function; post-processing function applied to parsed $data. Default identity.

is_async

Logical; whether .perform returns promises. Default FALSE.

timeout

Numeric; request timeout in seconds. Default 10.

.get_timestamp_ms

Function or NULL; zero-argument function returning epoch milliseconds for HMAC signing. When NULL (default), uses lubridate::now(). Pass a custom function (e.g. one that fetches KuCoin server time) to avoid clock-drift issues.

Value

Parsed and post-processed API response data, or a promise thereof.

Details

Sync vs Async

The .perform argument controls execution mode: