Skip to contents

Converts a POSIXct object into a UNIX timestamp in the specified unit, compatible with KuCoin's server time requirements.

Usage

time_convert_to_kucoin(datetime, unit = c("ms", "ns", "s"))

Arguments

datetime

POSIXct object representing the timestamp to convert.

unit

Character string specifying the output time unit: "ms" for milliseconds (default), "ns" for nanoseconds, or "s" for seconds.

Value

Numeric value representing the UNIX timestamp in the specified unit.

Details

Workflow Overview

  1. Input Validation: Ensures datetime is a POSIXct object, aborting if not.

  2. Unit Matching: Validates unit against allowed options ("ms", "ns", "s") using match.arg().

  3. Time Conversion: Converts the POSIXct to seconds and scales to the desired unit (milliseconds, nanoseconds, or seconds).

API Endpoint

Not applicable (helper function for timestamp conversion).

Usage

Utilised to prepare timestamps in the appropriate UNIX format for KuCoin API requests.

Official Documentation

Not directly tied to a specific endpoint; see KuCoin API timestamp usage guidelines.

Examples

if (FALSE) { # \dontrun{
# Convert to milliseconds
dt <- as.POSIXct("2023-10-31 16:00:00", tz = "UTC")
time_convert_to_kucoin(datetime = dt, unit = "ms")
# Returns 1698777600000

# Convert to nanoseconds
time_convert_to_kucoin(datetime = dt, unit = "ns")
# Returns 1698777600000000000
} # }