Skip to contents

Processes an HTTP response from a KuCoin API request, validating its HTTP status and API-specific response code, returning the parsed JSON object if successful or aborting with an error otherwise.

Usage

process_kucoin_response(response, url = "")

Arguments

response

HTTP response object (e.g., from httr::GET()).

url

Character string representing the requested URL, used for error messages.

Value

List representing the parsed JSON response; users should extract fields like "data" as required.

Details

Workflow Overview

  1. Check HTTP Status: Confirms the status code is 200, aborting if not.

  2. Parse JSON: Extracts the response content as text and parses it into a JSON object using jsonlite::fromJSON().

  3. Validate Structure: Verifies the "code" field exists, aborting if absent.

  4. Check Success: Ensures the "code" is "200000", retrieving an error message from "msg" and aborting if not successful.

API Endpoint

Not applicable (helper function for response processing).

Usage

Utilised to validate and extract data from KuCoin API responses, typically accessing the $data or $data$items field for results.

Official Documentation

Not directly tied to a specific endpoint; see KuCoin API response handling guidelines.

Examples

if (FALSE) { # \dontrun{
response <- httr::GET("https://api.kucoin.com/api/v1/timestamp", httr::timeout(3))
parsed <- process_kucoin_response(response, "https://api.kucoin.com/api/v1/timestamp")
print(parsed$data)
} # }