The KucoinDeposit
class provides an asynchronous interface for managing deposit operations on KuCoin.
It leverages the coro
package for non-blocking HTTP requests, returning promises that resolve to data.table
objects.
This class supports creating new deposit addresses, retrieving existing deposit addresses, and fetching deposit history,
all requiring authentication via API keys.
Details
Purpose and Scope
This class is designed to handle deposit-related tasks in the KuCoin ecosystem, including:
Address Creation: Generating new deposit addresses for various currencies and chains.
Address Retrieval: Listing all deposit addresses for a currency.
History Tracking: Querying deposit records with filtering and pagination.
Usage
Utilised by traders and developers to programmatically manage deposits on KuCoin. The class is initialized with API credentials,
automatically sourced from get_api_keys()
if not provided, and a base URL from get_base_url()
. All methods require authentication.
For detailed endpoint information, parameters, and response schemas, refer to the official KuCoin API Documentation.
Methods
initialize(keys, base_url): Initialises the object with API credentials and base URL.
add_deposit_address(currency, chain, to, amount): Creates a new deposit address for a currency.
get_deposit_addresses(currency, chain, amount): Retrieves all deposit addresses for a currency.
get_deposit_history(currency, status, startAt, endAt, page_size, max_pages): Fetches paginated deposit history.
Public fields
keys
List containing KuCoin API keys (
api_key
,api_secret
,api_passphrase
,key_version
).base_url
Character string representing the base URL for KuCoin API endpoints. Initialise a New KucoinDeposit Object
Description
Initialises a
KucoinDeposit
object with API credentials and a base URL for managing deposit operations asynchronously. All methods require authentication, so valid credentials are essential.Workflow Overview
Credential Assignment: Sets
self$keys
to the provided or default API keys fromget_api_keys()
.URL Assignment: Sets
self$base_url
to the provided or default base URL fromget_base_url()
.
Usage
Creates an instance for managing KuCoin deposits, requiring authenticated API access for all operations.
Automated Trading Usage
Deposit Automation: Use as the core object for deposit workflows in your bot, integrating with wallet management systems.
Secure Setup: Provide explicit
keys
or useget_api_keys()
from a secure vault for production-grade security.Scalability: Instantiate once and reuse across deposit cycles, pairing with withdrawal classes for full fund management.
Methods
Method new()
Usage
KucoinDeposit$new(keys = get_api_keys(), base_url = get_base_url())
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()
.
Returns
A new instance of the KucoinDeposit
class.
Add Deposit Address
Description
Creates a new deposit address for a specified currency asynchronously via a POST request to /api/v3/deposit-address/create
.
Calls add_deposit_address_v3_impl
.
Workflow Overview
Validation: Ensures
currency
is valid within the implementation.Request Body: Constructs JSON with
currency
,chain
,to
, and optionalamount
.Authentication: Generates headers with API keys.
API Call: Sends POST request.
Response: Returns address details as a
data.table
.
Usage
Utilised to generate new deposit addresses for funding KuCoin accounts, supporting various chains and account types.
Automated Trading Usage
Fund Allocation: Generate addresses for
to = "trade"
to direct funds to trading accounts, automating wallet-to-exchange transfers.Chain Selection: Specify
chain
(e.g., "trx" for USDT) to optimize fees, integrating with fee analysis from market data.Address Rotation: Create new addresses periodically for security, tracking via
chainId
and auditing withget_deposit_addresses
.
Method add_deposit_address()
Arguments
currency
Character string; currency code (e.g., "BTC", "USDT"). Required.
chain
Character string; chain identifier (e.g., "trx", "erc20"). Optional.
to
Character string; account type ("main" or "trade"). Optional, defaults to "main".
amount
Character string; amount for Lightning Network invoices. Optional.
Returns
Promise resolving to a data.table
with:
address
(character): Deposit address.memo
(character): Address remark (if any).chainId
(character): Chain identifier.to
(character): Account type.expirationDate
(integer): Expiration (Lightning Network).currency
(character): Currency code.chainName
(character): Chain name.
JSON Response Example
{"code": "200000", "data": {"address": "T...x", "memo": "", "chainId": "trx", "to": "trade", "currency": "USDT", "chainName": "TRON"}}
Get Deposit Addresses
Description
Retrieves all deposit addresses for a specified currency asynchronously via a GET request to /api/v3/deposit-addresses
.
Calls get_deposit_addresses_v3_impl
.
Workflow Overview
Validation: Ensures
currency
is valid within the implementation.Query: Builds query with
currency
, optionalchain
, andamount
.Authentication: Generates headers with API keys.
API Call: Sends GET request.
Response: Returns a
data.table
of all addresses, empty if none exist.
Automated Trading Usage
Address Inventory: Fetch all addresses for a currency to manage multiple deposit points, selecting based on
to
orchainName
.Verification: Confirm address availability before initiating deposits, retrying
add_deposit_address
if none exist.Chain Preference: Filter by
chain
to use low-fee networks, integrating with deposit history to track usage.
Method get_deposit_addresses()
Arguments
currency
Character string; currency code (e.g., "BTC", "USDT"). Required.
chain
Character string; chain identifier (e.g., "trx"). Optional.
amount
Character string; amount for Lightning Network invoices. Optional.
Returns
Promise resolving to a data.table
with:
address
(character): Deposit address.memo
(character): Address remark (if any).chainId
(character): Chain identifier.to
(character): Account type.expirationDate
(integer): Expiration (Lightning Network).currency
(character): Currency code.contractAddress
(character): Token contract address.chainName
(character): Chain name.
JSON Response Example
{"code": "200000", "data": [{"address": "T...x", "memo": "", "chainId": "trx", "to": "trade", "currency": "USDT", "chainName": "TRON"}]}
Get Deposit History
Description
Retrieves paginated deposit history asynchronously via a GET request to /api/v1/deposits
.
Calls get_deposit_history_impl
.
Workflow Overview
Validation: Ensures parameters meet API constraints (e.g.,
page_size
10-500).Query: Constructs query with filters and pagination settings.
Authentication: Generates headers with API keys.
API Call: Fetches pages up to
max_pages
.Response: Aggregates history into a
data.table
with datetime conversion.
Automated Trading Usage
Fund Tracking: Monitor
status = "SUCCESS"
deposits to confirm fund availability, triggering trading actions.Reconciliation: Use
createdAtDatetime
andamount
to reconcile with external wallet records, polling daily with time filters.Error Handling: Filter
status = "FAILURE"
to investigate issues, alerting users or retrying deposits automatically.
Method get_deposit_history()
Usage
KucoinDeposit$get_deposit_history(
currency,
status = NULL,
startAt = NULL,
endAt = NULL,
page_size = 50,
max_pages = Inf
)
Arguments
currency
Character string; currency code (e.g., "BTC", "USDT"). Required.
status
Character string; status filter ("PROCESSING", "SUCCESS", "FAILURE"). Optional.
startAt
Integer; start time (ms). Optional.
endAt
Integer; end time (ms). Optional.
page_size
Integer; results per page (10-500, default 50).
max_pages
Numeric; max pages to fetch (default
Inf
).
Returns
Promise resolving to a data.table
with:
currency
(character): Currency code.chain
(character): Chain identifier.status
(character): Deposit status.address
(character): Deposit address.amount
(character): Deposit amount.createdAtDatetime
(POSIXct): Creation time.Full schema in implementation docs.
Examples
if (FALSE) { # \dontrun{
# Comprehensive example demonstrating key methods
main_async <- coro::async(function() {
# Initialise the class
deposit <- KucoinDeposit$new()
# Add a new deposit address for USDT on TRON
new_address <- await(deposit$add_deposit_address(
currency = "USDT",
chain = "trx",
to = "trade"
))
print("New Deposit Address:"); print(new_address)
# Get all deposit addresses for USDT
addresses <- await(deposit$get_deposit_addresses(currency = "USDT"))
print("USDT Deposit Addresses:"); print(addresses)
# Get deposit history for USDT over a specific period
history <- await(deposit$get_deposit_history(
currency = "USDT",
status = "SUCCESS",
startAt = as.integer(Sys.time() - 24*3600) * 1000,
endAt = as.integer(Sys.time()) * 1000,
page_size = 10,
max_pages = 2
))
print("USDT Deposit History:"); print(history)
})
main_async()
while (!later::loop_empty()) later::run_now()
} # }