
Crypto Agent Trading
- 339 installs
- 16 repo stars
- Updated June 10, 2026
- crypto-com/crypto-agent-trading
This is a copy of crypto-com-app by crypto-com - installs and ranking accrue to the original listing.
crypto-agent-trading is an agent skill repository that executes Crypto.com App and Exchange trades, balance queries, and market data via API scripts for developers building autonomous or agent-driven cryptocurrency tradi
About
crypto-agent-trading is an official Crypto.com agent skill repo containing two independent integrations: crypto-com-app for retail App API trades across 200+ tokens and crypto-com-exchange for spot and derivatives orders via the cdcx CLI. App trades follow a two-step quotation-then-confirm flow through TypeScript scripts/trade.ts with CDC_API_KEY and CDC_API_SECRET. Exchange coverage includes LIMIT, MARKET, STOP_LOSS, OCO bracket orders, paper trading, and 86+ OpenAPI-driven cdcx endpoints with safety tiers from read-only to dangerous mutations. Features include portfolio balance queries, kill-switch API revocation, and fiat deposit or withdrawal management. Reach for crypto-agent-trading when building Claude or Cursor agents that must place audited Crypto.com orders with dry-run previews rather than hand-written REST clients.
- Exchange and market API integration patterns
- Order placement, cancellation, and position management
- Risk limits, sizing, and guardrail conventions
- Portfolio and PnL monitoring workflows
- Reusable agent prompts for crypto trading tasks
Crypto Agent Trading by the numbers
- 339 all-time installs (skills.sh)
- Data as of Jul 29, 2026 (Skillselion catalog sync)
npx skills add https://github.com/crypto-com/crypto-agent-trading --skill crypto-com-appAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 339 |
|---|---|
| repo stars | ★ 16 |
| Last updated | June 10, 2026 |
| Repository | crypto-com/crypto-agent-trading ↗ |
How do agents trade crypto via Crypto.com APIs?
Implement autonomous crypto trading agents with exchange APIs, order logic, risk controls, and portfolio monitoring for algorithmic or agent-driven trading workflows.
Who is it for?
Developers building AI trading agents who need Crypto.com App or Exchange API integration with quotation-confirm safety flows and cdcx CLI order tiers.
Skip if: Developers who need non-Crypto.com exchanges, unmanaged high-frequency trading without confirmation gates, or purely educational blockchain tutorials should skip crypto-agent-trading.
When should I use this skill?
User asks to buy, sell, or swap crypto via Crypto.com API, query portfolio balances, or place Exchange orders with cdcx dry-run
What you get
Trade quotations, confirmed orders, portfolio balance reports, transaction history, and cdcx dry-run JSON previews
- trade quotations and confirmations
- portfolio balance reports
- cdcx dry-run order previews
By the numbers
- Crypto.com App skill supports 200+ tradable tokens
- Exchange cdcx CLI exposes 86+ OpenAPI-driven endpoints
- Repository contains 2 independent skills: crypto-com-app and crypto-com-exchange
Files
Skill: crypto-agent-trading
Agent Capability Requirements
This skill requires your agent platform to support the following capabilities. If your platform lacks any required capability, the skill will not function.
| Capability | Required | Details |
|---|---|---|
| Shell command execution | Yes | Must be able to run npx tsx ./scripts/... and capture stdout |
| Environment variables | Yes | Must read CDC_API_KEY and CDC_API_SECRET from the shell environment |
| JSON parsing | Yes | Must parse structured JSON from script stdout to extract fields |
| Multi-turn conversation | Yes | Trading uses a quote → confirm flow that spans multiple user turns |
| Persistent memory | No | Used for confirmation_required preference. If unsupported, default to always confirming trades |
| Elapsed-time awareness | No | Used to check quote expiry (countdown field). If unsupported, always attempt confirmation and handle invalid_quotation errors gracefully |
CRITICAL: How This Skill Works
You MUST use the TypeScript scripts for ALL API interactions. NEVER call the API directly with `curl`, `fetch`, or any other HTTP method.
The scripts handle request signing, error handling, and response formatting. If you bypass them:
- The request will fail (missing HMAC signature)
- The response won't be filtered or structured
For every user request, find the matching command below and run it via `npx tsx`. Read the JSON output. Act on it.
Configurations
- BASE_URL:
https://wapi.crypto.com - CDC_API_KEY:
{{env.CDC_API_KEY}} - CDC_API_SECRET:
{{env.CDC_API_SECRET}} - CONFIRMATION_REQUIRED:
{{memory.confirmation_required}}(Default: true) - SKILL_DIR: The directory containing this
SKILL.mdfile. Resolve it from the path you loaded this file from (e.g. if you read/home/user/skills/crypto-agent-trading/SKILL.md, thenSKILL_DIRis/home/user/skills/crypto-agent-trading).
Environment Setup
- Both
CDC_API_KEYandCDC_API_SECRETmust be set as environment variables before use. - Before running any script, check whether both variables are set by running:
echo "CDC_API_KEY=${CDC_API_KEY:+set}" "CDC_API_SECRET=${CDC_API_SECRET:+set}"If either prints empty instead of set, prompt the user:
"Your API credentials are not configured. Please set them in your terminal before I can proceed:
```
export CDC_API_KEY="your-api-key"
export CDC_API_SECRET="your-api-secret"
```
You can generate an API key at https://help.crypto.com/en/articles/13843786-api-key-management.
Let me know once you've set them."
Then stop and wait for the user to confirm before retrying.
- If a script returns a
MISSING_ENVerror, treat it the same way: prompt the user to set the variables and wait.
Script Commands
ALL API interactions MUST go through these scripts. They handle signing, execution, filtering, and error formatting. Run the appropriate command below via shell, then parse the JSON output.
Prerequisite: npx tsx (Node.js 18+ required; tsx is fetched automatically by npx).
Important: All script paths below use $SKILL_DIR as a placeholder for this skill's root directory. Resolve it from the path you loaded this SKILL.md from, or cd into the skill directory and use ./scripts/... as the path. Either approach works.
Account Commands
# Filtered non-zero balances (scope: fiat | crypto | all)
npx tsx $SKILL_DIR/scripts/account.ts balances [fiat|crypto|all]
# Single token balance lookup
npx tsx $SKILL_DIR/scripts/account.ts balance <SYMBOL>
# Weekly trading limit
npx tsx $SKILL_DIR/scripts/account.ts trading-limit
# Find funded source wallets for a trade type
npx tsx $SKILL_DIR/scripts/account.ts resolve-source <purchase|sale|exchange>
# Kill switch — revoke API key
npx tsx $SKILL_DIR/scripts/account.ts revoke-keyTrade Commands
Trading follows a two-step flow: get a quotation first, then confirm the order.
# Step 1 — Get quotation (type: purchase | sale | exchange)
npx tsx $SKILL_DIR/scripts/trade.ts quote <type> '<json-params>'
# Returns: {"ok": true, "data": {"id": "<quotation-id>", "from_amount": {...}, "to_amount": {...}, "countdown": 15, ...}}
# Step 2 — Confirm order: pass the data.id from Step 1 as <quotation-id>
npx tsx $SKILL_DIR/scripts/trade.ts confirm <type> <quotation-id>
# View recent transactions
npx tsx $SKILL_DIR/scripts/trade.ts historyHow to map user intent to trade type:
| User says | Trade type | From | To |
|---|---|---|---|
| "Buy CRO with 100 USD" | purchase | USD (fiat) | CRO (crypto) |
| "Sell 0.1 BTC" | sale | BTC (crypto) | USD (fiat) |
| "Swap 0.1 BTC to ETH" | exchange | BTC (crypto) | ETH (crypto) |
Quotation JSON params by trade type:
| Type | JSON fields |
|---|---|
| purchase | {"from_currency":"USD","to_currency":"CRO","from_amount":"100"} or use to_amount instead |
| sale | {"from_currency":"BTC","to_currency":"USD","from_amount":"0.1","fixed_side":"from"} |
| exchange | {"from_currency":"BTC","to_currency":"ETH","from_amount":"0.1","side":"buy"} |
Example — "Buy CRO with 100 USD":
1. Run: npx tsx $SKILL_DIR/scripts/trade.ts quote purchase '{"from_currency":"USD","to_currency":"CRO","from_amount":"100"}' 2. Read data.id, data.from_amount, data.to_amount, data.countdown from the response. 3. If confirmation required (default): Ask user "Confirm: 100 USD for X CRO? Valid for {countdown}s. Reply 'YES' to proceed."
- If user says YES (within countdown):
npx tsx $SKILL_DIR/scripts/trade.ts confirm purchase <data.id>
4. If confirmation opted out (memory.confirmation_required is false): Skip asking and immediately run npx tsx $SKILL_DIR/scripts/trade.ts confirm purchase <data.id>
Opt-in / Opt-out: Users can say "stop asking for confirmation" to auto-execute trades, or "require confirmation" to re-enable the prompt. See Section 3 below.
Coin Discovery Commands
# Search coins
npx tsx $SKILL_DIR/scripts/coins.ts search '{"keyword":"BTC","sort_by":"rank","sort_direction":"asc","native_currency":"USD","page_size":10}'Required JSON parameters:
| Parameter | Type | Allowed values |
|---|---|---|
sort_by | string | rank, market_cap, alphabetical, volume, performance |
sort_direction | string | asc, desc |
native_currency | string | Uppercase currency code (e.g. USD) |
keyword | string | Search string, 1–100 chars; matches coin name and symbol only |
page_size | integer | Number of results per page |
Optional: page_token — opaque token for fetching the next page (see pagination below).
Pagination: The response includes a pagination object with has_more (boolean) and next_page_token (string). When has_more is true, pass next_page_token as page_token in the next request to fetch the next page.
Key response fields per coin: rails_id (identical to currency_id / currency in trade and account APIs — use this to cross-reference), price_native, price_usd, percent_change_*_native (price performance over past timeframes, e.g. percent_change_24h_native).
Output Format
Every script prints structured JSON to stdout:
Success:
{"ok": true, "data": { ... }}Error:
{"ok": false, "error": "ERROR_CODE", "error_message": "Human-readable message"}Constraints
- Validation: Success requires
ok: truein the script output. - Confirmation Window: Quote validity is defined by the
countdownfield in the quotation data. - Execution Warning: If order confirmation takes > 5s, notify: "Order submitted but taking longer than expected. Check order status with 'Show recent trades'".
- Rate Limits:
- Max 10 trades per minute.
- Max 100 API calls per minute.
- On HTTP 429 (
RATE_LIMITEDerror): wait 60 seconds before retrying the same request. Inform the user: "Rate limit reached — please wait 60 seconds before trying again."
Error Handling
All scripts return structured errors. Parse the error field to determine the appropriate response.
Script Error Codes
These are the error values in the script's JSON output. They tell you what category of failure occurred.
| Error Code | Meaning | Agent Response |
|---|---|---|
MISSING_ENV | CDC_API_KEY or CDC_API_SECRET not set | Tell user to set env vars via terminal |
API_ERROR | API returned non-200 or ok !== true | Report: "Transaction failed: {error_message}" |
INVALID_ARGS | Bad command-line arguments | Show correct usage from the error_message |
QUOTATION_FAILED | Quotation request rejected by API | Report the error_message to user (see API errors below) |
EXECUTION_FAILED | Order confirmation failed | Report and suggest: "Check order status with 'Show recent trades'" |
API_KEY_NOT_FOUND | Key already revoked or does not exist | "API key not found — it may have already been revoked." |
RATE_LIMITED | Too many requests (HTTP 429) | "Rate limit reached — please wait 60 seconds before trying again." |
UNKNOWN | Unexpected error | Report the raw error_message |
Rule: When ok is false in the output, stop the current operation and report the error to the user using the guidance above. Never proceed to the next step after a failure.
Common API Errors (Quick Reference)
These are the specific API error codes that appear inside the error_message of QUOTATION_FAILED, EXECUTION_FAILED, or API_ERROR responses. They tell you why the API rejected the request.
error | Meaning | Recovery |
|---|---|---|
not_enough_balance | Insufficient funds | Check balances, reduce trade amount |
invalid_currency | Currency code not recognized | Verify via coin search |
invalid_quotation | Quote expired or already used | Request a new quotation |
failed_to_create_quotation | Quotation engine error | Retry shortly |
not_eligible_for_prime | Not eligible for Prime benefits | Proceed without Prime |
unauthorized | Account not approved for trading | Contact support |
restricted_feature | Feature restricted on account | Report error_message to user |
existing_currency_order_error | An existing order is in progress | Wait or cancel existing order |
viban_purchase_not_enabled | Fiat-to-crypto not enabled | Account feature not available |
crypto_viban_not_enabled | Crypto-to-fiat not enabled | Account feature not available |
bank_transfer_not_enabled | Bank transfer not enabled | Account feature not available |
missing_parameter | Required parameter missing | Script bug — report it |
failed_to_create_transaction | Transaction creation failed | Retry or contact support |
key_not_active | API key revoked or expired | Generate a new API key, update env vars |
api_key_not_found | Key doesn't exist or belongs to another user | Verify correct key is set in CDC_API_KEY |
For dynamic errors (limit exceeded, currency disabled, cooling-off, etc.), report the error and error_message directly to the user. For full details, see references/errors.md.
---
Logic & Rules
1. Asset & Source Disambiguation
Determine the trade type first:
- Purchase — fiat → crypto
- Sale — crypto → fiat
- Exchange — crypto → crypto
Then resolve the source wallet:
- For purchase: run
npx tsx $SKILL_DIR/scripts/account.ts resolve-source purchase. The script returns only funded fiat entries. - For sale or exchange: run
npx tsx $SKILL_DIR/scripts/account.ts resolve-source sale(orexchange). The script returns only funded crypto entries.
Result (from `data.status`):
- `SELECTED` → auto-select
data.currency. - `AMBIGUOUS` → prompt user to choose from
data.options. - `EMPTY` → inform user "No funded wallets found" and stop.
"Sell All" Scenario: If user says "Sell all [TOKEN]", run npx tsx $SKILL_DIR/scripts/account.ts balance [TOKEN]. Use the data.available amount (or data.balance) as from_amount for the quotation.
2. Trading Process (Quotation → Confirmation → Execution)
When the user asks to buy, sell, or swap crypto, always follow this three-step flow:
- Step A — Get Quotation: Build the JSON params from the user's request (see the "Quotation JSON params" table in Trade Commands) and run:
npx tsx $SKILL_DIR/scripts/trade.ts quote <type> '<json-params>' Read data.id, data.from_amount, data.to_amount, and data.countdown from the response.
- Step B — Ask User to Confirm:
- IF
memory.confirmation_requiredistrue(or unset): - Prompt: "Confirm: {from_amount} for {to_amount}? Valid for {countdown}s. Reply 'YES' to proceed."
- Expiration Logic: If the user replies "YES" after
countdownseconds have elapsed, reject: "Transaction rejected: The quotation rate has expired. Please request a new quote." - Execute Step C ONLY if user replies "YES" within the valid window.
- ELSE (Opted Out):
- Notify: "Quotation received. Proceeding to execution automatically..."
- Immediately proceed to Step C.
- Step C — Execute Order: Run:
npx tsx $SKILL_DIR/scripts/trade.ts confirm <type> <data.id>using theidfrom Step A.
3. Memory Management (Opt-in/Out)
- To Opt-out: If user says "stop asking for confirmation" or "enable auto-trade", update
memory.confirmation_requiredtofalse. - To Opt-in: If user says "require confirmation" or "enable manual trade", update
memory.confirmation_requiredtotrue. - Platforms without persistent memory: If your platform does not support
{{memory.*}}, treatconfirmation_requiredas alwaystrue(safest default).
4. Error Handling
- All script outputs include an
okfield. Success is defined ONLY asok: true. - If
okisfalse, readerrorand respond per the Error Handling table above. - Never proceed to the next step after a failed command.
5. Account & History
- History: Run
npx tsx $SKILL_DIR/scripts/trade.ts history— display the entries fromdata. - Weekly Trading Limit: Run
npx tsx $SKILL_DIR/scripts/account.ts trading-limit— display as: "📊 Weekly Trading Limit: {data.used} / {data.limit} USD (Remaining: {data.remaining} USD)". - Balances (Categorized):
- If "List Fiat": run
npx tsx $SKILL_DIR/scripts/account.ts balances fiat. - If "List Crypto": run
npx tsx $SKILL_DIR/scripts/account.ts balances crypto. - If "List All": run
npx tsx $SKILL_DIR/scripts/account.ts balances all. Crucial: Display Fiat category first, followed by Crypto balances below. - The scripts automatically filter out zero-balance entries. If a category has no entries in the output, display "No holdings" under that header.
6. Kill Switch
- Trigger: User says "STOP ALL TRADING", "kill switch", or similar emergency stop command.
- ALWAYS require explicit confirmation regardless of
memory.confirmation_required: - Prompt: "⚠️ WARNING: This will immediately revoke your API key and disable all trading. A new API key must be generated to resume. Type 'CONFIRM KILL SWITCH' to proceed."
- Execute ONLY if user replies with the exact phrase.
- Execution: Run
npx tsx $SKILL_DIR/scripts/account.ts revoke-key. - On success (`ok: true`): Notify: "🛑 Kill switch activated. API key has been revoked. All trading is disabled. Generate a new API key and update your environment variables to resume."
- On `API_KEY_NOT_FOUND` error: Notify: "API key not found — it may have already been revoked or does not exist."
- Idempotency: Revoking an already-revoked key is not an error; treat it the same as a successful revocation.
7. Balance Display Format
- Fiat Header: "🏦 Fiat Balances"
- Crypto Header: "🪙 Crypto Balances"
- Always list Fiat section before Crypto section when both are requested.
- Never display zero-balance assets. Only show assets with a balance greater than 0. If all assets in a category are zero, show "No holdings" under that header.
{
"slug": "crypto-agent-trading",
"version": "1.0.0",
"publishedAt": 1772262436
}
Error Reference
This document covers error scenarios, API error codes, and recovery guidance. The scripts return structured errors — use this reference when the compact table in SKILL.md needs more context.
Error format:
{"ok": false, "error": "error_code", "error_message": "Human-readable message"}---
Script Error Codes
These are the error values returned by the TypeScript scripts when a problem is caught before or after the API call.
MISSING_ENV
Cause: CDC_API_KEY or CDC_API_SECRET environment variable is not set.
Recovery: Tell the user to set both variables in their terminal:
export CDC_API_KEY="your-api-key"
export CDC_API_SECRET="your-api-secret"API_ERROR
Cause: The API returned a non-200 HTTP status or the response body has ok: false.
Recovery: Report the error_message to the user. If the message is vague, suggest checking API key validity and account status.
INVALID_ARGS
Cause: The script received bad or missing command-line arguments (wrong scope, missing symbol, malformed JSON, unknown trade type).
Recovery: The error_message includes correct usage. Show it to the user or fix the command and retry.
QUOTATION_FAILED
Cause: The quotation request was rejected by the API. See the API error tables below for specific codes.
Recovery: Report the error_message. Suggest the user adjust trade parameters and try again.
EXECUTION_FAILED
Cause: The order confirmation failed after a successful quotation. See the API error tables below for specific codes.
Recovery: Report the error. Suggest: "Check order status with 'Show recent trades' to verify whether the order was partially processed."
API_KEY_NOT_FOUND
Cause: The API key does not exist or has already been revoked.
Recovery: Inform the user: "API key not found — it may have already been revoked or does not exist." The key is already inactive.
UNKNOWN
Cause: An unexpected error (network failure, JSON parse error, script crash).
Recovery: Report the raw error_message. If it's a network issue, suggest checking connectivity.
---
API Error Codes — Quotation
These errors can appear when requesting a quotation via trade.ts quote. They apply across purchase, sale, and exchange operations unless noted otherwise.
Balance & Eligibility
error | error_message | Applies to | Recovery |
|---|---|---|---|
not_enough_balance | (none) | All | Insufficient funds. Check balances and reduce trade amount. |
unauthorized | (none) | All | User account not approved for trading. Contact support. |
restricted_feature | varies | All | Account has a feature restriction. The error_message explains which feature. |
not_eligible_for_prime | "user is not eligible for prime" | All | User is not eligible for Prime benefits. Proceed without Prime. |
Currency & Pair
error | error_message | Applies to | Recovery |
|---|---|---|---|
invalid_currency | (none) | Exchange | Currency code not recognized. Verify spelling via coin search. |
existing_currency_order_error | varies (from QRE) | Exchange | An existing order for this currency pair is in progress. Wait or cancel it first. |
failed_to_create_quotation | "failed to create quotation" | All | Internal quotation engine error. Retry in a moment. |
Feature Availability
error | error_message | Applies to | Recovery |
|---|---|---|---|
viban_purchase_not_enabled | (none) | Purchase | Fiat-to-crypto purchase is not enabled for this account. |
bank_transfer_not_enabled | (none) | Purchase, Sale | Bank transfer feature is not enabled. |
crypto_viban_not_enabled | (none) | Sale | Crypto-to-fiat sale is not enabled for this account. |
Authentication
error | error_message | Applies to | Recovery |
|---|---|---|---|
invalid_passcode | (none) | All | Passcode verification failed. |
passcode_not_set | (none) | All | User has not set a passcode. HTTP 400. |
---
API Error Codes — Order Confirmation
These errors can appear when confirming an order via trade.ts confirm. They apply across purchase, sale, and exchange operations unless noted otherwise.
Quotation Issues
error | error_message | Applies to | Recovery |
|---|---|---|---|
invalid_quotation | (none) | All | Quotation has expired or was already used. Request a new quote. |
missing_parameter | (none) | All | quotation_id was not provided. This is a script bug — report it. |
Balance & Eligibility
error | error_message | Applies to | Recovery |
|---|---|---|---|
not_enough_balance | (none) | Exchange | Balance changed between quote and confirm. Check balances and re-quote. |
unauthorized | (none) | Exchange | User account not approved. Contact support. |
Transaction Failures
error | error_message | Applies to | Recovery |
|---|---|---|---|
failed_to_create_transaction | (none) | Sale | Internal error creating the transaction. Retry or contact support. |
failed_to_activate_prime_account | "failed to activate prime account" | All | Prime account activation failed during order. Retry without Prime. |
Feature Availability
error | error_message | Applies to | Recovery |
|---|---|---|---|
bank_transfer_not_enabled | (none) | Purchase | Bank transfer feature is not enabled for this account. |
restricted_feature | varies | Exchange | Account has a feature restriction. The error_message explains which feature. |
---
API Error Codes — API Keys
These errors can appear when interacting with API key endpoints (trading-limit, revoke-key). The /v1/api-keys path may return errors in either {"ok": false, "error": "..."} or {"code": "...", "message": "..."} format — the scripts handle both.
error / code | error_message / message | Meaning | Recovery |
|---|---|---|---|
key_not_active | (none) | API key has been revoked or expired | Generate a new API key and update env vars |
api_key_not_found | "not found" | Key doesn't exist or belongs to another user | Verify the correct API key is set in CDC_API_KEY |
invalid_scope | (none) | One or more scopes in the request don't exist | Verify the API key has the required scopes |
invalid_expiration | (none) | expires_at is in the past or more than 1 year out | Use a valid expiration date |
invalid_public_key | (none) | Not a valid PEM-encoded Ed25519 public key | Provide a valid Ed25519 public key |
passcode_required | (none) | Sensitive fields changed but no passcode provided | N/A for API-key-based trading |
Note: The key_not_active and api_key_not_found errors are the most relevant for this skill. If either appears during trading-limit or any other operation, the API key is no longer valid — the user must generate a new one.
---
Dynamic Error Codes
Some API errors return dynamic codes and messages from internal subsystems. These will not match the exact strings above but follow the same {"ok": false, "error": "...", "error_message": "..."} format. Common categories:
| Pattern | Meaning |
|---|---|
| Limit / exceeded errors | Trade amount exceeds a limit (weekly, per-trade, or per-currency). Reduce amount or check trading-limit. |
| Currency disabled errors | The specific currency is temporarily disabled for trading. Try a different currency or wait. |
| Cooling-off / trade restriction | Account is in a cooling-off period after a security event. Wait for the period to end. |
| Finalized / cancelling errors | The order is already finalized or being cancelled. No action needed. |
| Risk / payment rejected | The transaction was rejected by risk assessment. Contact support if recurring. |
| Account inactive / not accessible | The target account is inactive. Verify account status. |
| Unsupported strategy / payout | The requested trade strategy or payout method is not supported. Use a different method. |
When the agent encounters a dynamic error code not listed above, report the error and error_message directly to the user.
---
API HTTP Status Codes
The scripts handle these internally, but for reference:
| Status | Meaning |
|---|---|
| 200 | Success (must also check ok: true in body) |
| 400 | Bad request — invalid parameters |
| 401 | Unauthorized — invalid or missing API key |
| 403 | Forbidden — API key lacks required permissions |
| 404 | Endpoint not found |
| 429 | Rate limited — too many requests |
| 500 | Internal server error |
| 503 | Service unavailable — maintenance |
---
Troubleshooting Checklist
If a command fails unexpectedly:
1. Check env vars — echo $CDC_API_KEY should return a value (not empty) 2. Check API key status — run npx tsx ./scripts/account.ts trading-limit (from the skill directory). If it returns successfully, the key is valid. 3. Check network — can the machine reach https://wapi.crypto.com? 4. Check Node version — node --version should be 18+ 5. Check timestamps — system clock must be accurate for HMAC signing to work
import { apiGet, apiPost, assertOk } from "./lib/api.js";
import { ErrorCode, fail, run, success } from "./lib/output.js";
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
function filterFiat(balances: any[]): any[] {
return balances.filter((b: any) => parseFloat(b.amount?.amount ?? "0") > 0);
}
function filterCrypto(wallets: any[]): any[] {
return wallets.filter((w: any) => {
const amt = w.available?.amount ?? w.balance?.amount ?? "0";
return parseFloat(amt) > 0;
});
}
// ---------------------------------------------------------------------------
// Commands
// ---------------------------------------------------------------------------
async function balances(scope: string) {
const validScopes = ["fiat", "crypto", "all"];
if (!validScopes.includes(scope)) {
fail(ErrorCode.INVALID_ARGS, `Invalid scope "${scope}". Use: fiat | crypto | all`);
}
const includeFiat = scope !== "crypto";
const includeCrypto = scope !== "fiat";
const result: Record<string, any> = {};
if (includeFiat) {
const res = await apiGet("/v1/fiat-account");
assertOk(res, "Fiat balance fetch");
result.fiat = filterFiat(res.data.account.balances);
}
if (includeCrypto) {
const res = await apiGet("/v1/crypto-account");
assertOk(res, "Crypto balance fetch");
result.crypto = filterCrypto(res.data.account.wallets);
}
success(result);
}
async function balance(symbol: string) {
if (!symbol) {
fail(ErrorCode.INVALID_ARGS, "Token symbol required. Example: npx tsx scripts/account.ts balance BTC");
}
const upper = symbol.toUpperCase();
const res = await apiGet("/v1/crypto-account");
assertOk(res, "Crypto balance fetch");
const wallet = (res.data.account.wallets as any[]).find(
(w: any) => w.currency.toUpperCase() === upper,
);
success({
currency: upper,
available: wallet?.available?.amount ?? "0",
balance: wallet?.balance?.amount ?? "0",
});
}
async function tradingLimit() {
const res = await apiGet("/v1/api-keys/current");
assertOk(res, "Trading limit fetch");
const k = res.data.api_key;
const limit = parseFloat(k.weekly_trading_limit_in_usd);
const remaining = parseFloat(k.remaining_weekly_trading_limit_in_usd);
success({ used: limit - remaining, limit, remaining, currency: "USD" });
}
async function resolveSource(tradeType: string) {
const validTypes = ["purchase", "sale", "exchange"];
if (!validTypes.includes(tradeType)) {
fail(ErrorCode.INVALID_ARGS, `Invalid trade type "${tradeType}". Use: purchase | sale | exchange`);
}
const walletType = tradeType === "purchase" ? "fiat" : "crypto";
if (walletType === "fiat") {
const res = await apiGet("/v1/fiat-account");
assertOk(res, "Fiat balance fetch");
emitResolveResult(filterFiat(res.data.account.balances), walletType);
} else {
const res = await apiGet("/v1/crypto-account");
assertOk(res, "Crypto balance fetch");
emitResolveResult(filterCrypto(res.data.account.wallets), walletType);
}
}
function emitResolveResult(funded: any[], walletType: string): never {
if (funded.length === 1) {
success({ status: "SELECTED", currency: funded[0].currency, walletType });
} else if (funded.length > 1) {
success({ status: "AMBIGUOUS", options: funded.map((w: any) => w.currency), walletType });
} else {
success({ status: "EMPTY", walletType });
}
}
async function revokeKey() {
const res = await apiPost("/v1/api-keys/self-revoke", {});
const errorCode = res.data?.error || res.data?.code;
if (errorCode === "api_key_not_found") {
fail(ErrorCode.API_KEY_NOT_FOUND, "API key not found — it may have already been revoked or does not exist.");
}
if (errorCode === "key_not_active") {
fail(ErrorCode.API_KEY_NOT_FOUND, "API key is not active — it has been revoked or expired.");
}
if (res.status !== 200 || res.data?.ok === false) {
const apiMsg = res.data?.error_message || res.data?.message;
const detail = apiMsg && errorCode ? `${errorCode}: ${apiMsg}` : errorCode || apiMsg || `HTTP ${res.status}`;
fail(ErrorCode.API_ERROR, `Kill switch request failed: ${detail}`);
}
success({ revoked: true });
}
// ---------------------------------------------------------------------------
// CLI router
// ---------------------------------------------------------------------------
const USAGE = `Usage: npx tsx scripts/account.ts <command> [args]
Commands:
balances [fiat|crypto|all] Filtered non-zero balances (default: all)
balance <SYMBOL> Single token balance lookup
trading-limit Weekly trading limit info
resolve-source <type> Find funded wallets (purchase|sale|exchange)
revoke-key Revoke API key (kill switch)`;
run(async () => {
const [command, arg] = process.argv.slice(2);
switch (command) {
case "balances":
return balances(arg || "all");
case "balance":
return balance(arg);
case "trading-limit":
return tradingLimit();
case "resolve-source":
return resolveSource(arg);
case "revoke-key":
return revokeKey();
default:
fail(ErrorCode.INVALID_ARGS, command ? `Unknown command "${command}".\n\n${USAGE}` : USAGE);
}
});
import { apiGet, assertOk } from "./lib/api.js";
import { ErrorCode, fail, run, success } from "./lib/output.js";
// ---------------------------------------------------------------------------
// Commands
// ---------------------------------------------------------------------------
async function search(paramsJson: string) {
if (!paramsJson) {
fail(
ErrorCode.INVALID_ARGS,
`JSON params required. Example: npx tsx scripts/coins.ts search '{"keyword":"BTC","sort_by":"rank","sort_direction":"asc","native_currency":"USD","page_size":10}'`,
);
}
let params: any;
try {
params = JSON.parse(paramsJson);
} catch {
fail(ErrorCode.INVALID_ARGS, `Invalid JSON: ${paramsJson}`);
}
const qs = new URLSearchParams();
for (const [key, val] of Object.entries(params)) {
if (val !== undefined && val !== null) qs.set(key, String(val));
}
const path = `/v1/crypto/coins?${qs.toString()}`;
const res = await apiGet(path);
assertOk(res, "Coin search");
success({
coins: res.data.coins,
pagination: res.data.pagination,
});
}
// ---------------------------------------------------------------------------
// CLI router
// ---------------------------------------------------------------------------
const USAGE = `Usage: npx tsx scripts/coins.ts <command> [args]
Commands:
search '<json>' Search coins by keyword, sort, pagination`;
run(async () => {
const [command, arg] = process.argv.slice(2);
switch (command) {
case "search":
return search(arg);
default:
fail(ErrorCode.INVALID_ARGS, command ? `Unknown command "${command}".\n\n${USAGE}` : USAGE);
}
});
import crypto from "node:crypto";
import os from "node:os";
import { ErrorCode, fail } from "./output.js";
export const BASE_URL = "https://wapi.crypto.com";
function getCredentials(): { apiKey: string; apiSecret: string } {
const apiKey = process.env.CDC_API_KEY;
const apiSecret = process.env.CDC_API_SECRET;
if (!apiKey || !apiSecret) {
fail(
ErrorCode.MISSING_ENV,
`CDC_API_KEY and/or CDC_API_SECRET not set. Run:\n export CDC_API_KEY="your-key"\n export CDC_API_SECRET="your-secret"`,
);
}
return { apiKey, apiSecret };
}
function getSignedHeaders(method: string, path: string, body?: unknown): Record<string, string> {
const { apiKey, apiSecret } = getCredentials();
const timestamp = Date.now().toString();
const bodyStr = body ? JSON.stringify(body) : "";
const signPayload = timestamp + method.toUpperCase() + path + bodyStr;
const signature = crypto
.createHmac("sha256", apiSecret)
.update(signPayload)
.digest("base64");
const userAgent = `Node/${process.version} ${os.platform()}/${os.release()}-cdc-clawbot/1.0`;
return {
"Content-Type": "application/json",
"User-Agent": userAgent,
"Cdc-Api-Key": apiKey,
"Cdc-Api-Timestamp": timestamp,
"Cdc-Api-Signature": signature,
};
}
interface ApiResponse {
status: number;
data: any;
}
async function request(method: string, path: string, body?: unknown): Promise<ApiResponse> {
const headers = getSignedHeaders(method, path, body);
const url = `${BASE_URL}${path}`;
const res = await fetch(url, {
method,
headers,
body: body ? JSON.stringify(body) : undefined,
});
let data: any;
try {
data = await res.json();
} catch {
fail(ErrorCode.API_ERROR, `Non-JSON response from ${method} ${path} (HTTP ${res.status})`);
}
return { status: res.status, data };
}
export async function apiGet(path: string): Promise<ApiResponse> {
return request("GET", path);
}
export async function apiPost(path: string, body?: unknown): Promise<ApiResponse> {
return request("POST", path, body);
}
export function assertOk(res: ApiResponse, context: string): void {
if (res.status === 429) {
fail(
ErrorCode.RATE_LIMITED,
`${context}: Rate limit exceeded. Wait 60 seconds before retrying.`,
);
}
if (res.status !== 200 || res.data?.ok !== true) {
const apiError = res.data?.error || res.data?.code;
const apiMsg = res.data?.error_message || res.data?.message;
const detail = apiMsg && apiError ? `${apiError}: ${apiMsg}` : apiError || apiMsg || `HTTP ${res.status}`;
fail(ErrorCode.API_ERROR, `${context}: ${detail}`);
}
}
export const ErrorCode = {
MISSING_ENV: "MISSING_ENV",
API_ERROR: "API_ERROR",
INVALID_ARGS: "INVALID_ARGS",
QUOTATION_FAILED: "QUOTATION_FAILED",
EXECUTION_FAILED: "EXECUTION_FAILED",
API_KEY_NOT_FOUND: "API_KEY_NOT_FOUND",
RATE_LIMITED: "RATE_LIMITED",
UNKNOWN: "UNKNOWN",
} as const;
export type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
interface SuccessOutput {
ok: true;
data: unknown;
}
interface ErrorOutput {
ok: false;
error: string;
error_message: string;
}
export function success(data: unknown): never {
const out: SuccessOutput = { ok: true, data };
console.log(JSON.stringify(out, null, 2));
process.exit(0);
}
export function fail(code: ErrorCode, message: string): never {
const out: ErrorOutput = { ok: false, error: code, error_message: message };
console.log(JSON.stringify(out, null, 2));
process.exit(1);
}
export function run(fn: () => Promise<void>): void {
fn().catch((err: unknown) => {
const message = err instanceof Error ? err.message : String(err);
fail(ErrorCode.UNKNOWN, message);
});
}
import { apiGet, apiPost, assertOk } from "./lib/api.js";
import { ErrorCode, fail, run, success } from "./lib/output.js";
// ---------------------------------------------------------------------------
// Quotation body builders
// ---------------------------------------------------------------------------
const QUOTE_PATHS: Record<string, string> = {
purchase: "/v1/crypto-purchase/quotations",
sale: "/v1/crypto-sales/quotations",
exchange: "/v1/crypto-exchange/quotations",
};
const ORDER_PATHS: Record<string, string> = {
purchase: "/v1/crypto-purchase/orders",
sale: "/v1/crypto-sales/orders",
exchange: "/v1/crypto-exchange/orders",
};
function buildQuotationBody(type: string, params: any): Record<string, any> {
switch (type) {
case "purchase":
return {
from_currency: params.from_currency,
to_currency: params.to_currency,
...(params.from_amount
? { from_amount: params.from_amount }
: { to_amount: params.to_amount }),
};
case "sale":
return {
from_currency: params.from_currency,
from_amount: params.from_amount,
to_currency: params.to_currency,
fixed_side: params.fixed_side || "from",
};
case "exchange":
return {
from: params.from_currency,
to: params.to_currency,
from_amount: params.from_amount,
side: params.side || "buy",
};
default:
fail(ErrorCode.INVALID_ARGS, `Unknown trade type: ${type}`);
}
}
// ---------------------------------------------------------------------------
// Commands
// ---------------------------------------------------------------------------
async function quote(type: string, paramsJson: string) {
if (!QUOTE_PATHS[type]) {
fail(ErrorCode.INVALID_ARGS, `Invalid trade type "${type}". Use: purchase | sale | exchange`);
}
if (!paramsJson) {
fail(ErrorCode.INVALID_ARGS, `JSON params required. Example: npx tsx scripts/trade.ts quote purchase '{"from_currency":"USD","to_currency":"BTC","from_amount":"100"}'`);
}
let params: any;
try {
params = JSON.parse(paramsJson);
} catch {
fail(ErrorCode.INVALID_ARGS, `Invalid JSON: ${paramsJson}`);
}
const body = buildQuotationBody(type, params);
const res = await apiPost(QUOTE_PATHS[type], body);
if (res.status !== 200 || res.data?.ok !== true) {
const apiError = res.data?.error;
const apiMsg = res.data?.error_message;
const msg = apiMsg && apiError ? `${apiError}: ${apiMsg}` : apiError || apiMsg || "Quotation request rejected.";
fail(ErrorCode.QUOTATION_FAILED, msg);
}
success(res.data.quotation);
}
async function confirm(type: string, quotationId: string) {
if (!ORDER_PATHS[type]) {
fail(ErrorCode.INVALID_ARGS, `Invalid trade type "${type}". Use: purchase | sale | exchange`);
}
if (!quotationId) {
fail(ErrorCode.INVALID_ARGS, "Quotation ID required. Example: npx tsx scripts/trade.ts confirm purchase <quotation-id>");
}
const body: Record<string, string> =
type === "exchange"
? { quotation_id: quotationId, side: "buy" }
: { quotation_id: quotationId };
const res = await apiPost(ORDER_PATHS[type], body);
if (res.status !== 200 || res.data?.ok !== true) {
const apiError = res.data?.error;
const apiMsg = res.data?.error_message;
const msg = apiMsg && apiError ? `${apiError}: ${apiMsg}` : apiError || apiMsg || "Order confirmation failed.";
fail(ErrorCode.EXECUTION_FAILED, msg);
}
success(res.data.transaction);
}
async function history() {
const res = await apiGet("/v1/transactions");
assertOk(res, "Transaction history fetch");
const txns = (res.data.transactions ?? []).slice(0, 5);
success(txns);
}
// ---------------------------------------------------------------------------
// CLI router
// ---------------------------------------------------------------------------
const USAGE = `Usage: npx tsx scripts/trade.ts <command> [args]
Commands:
quote <type> '<json>' Get quotation (purchase|sale|exchange)
confirm <type> <quotation-id> Confirm order
history Last 5 transactions`;
run(async () => {
const [command, arg1, arg2] = process.argv.slice(2);
switch (command) {
case "quote":
return quote(arg1, arg2);
case "confirm":
return confirm(arg1, arg2);
case "history":
return history();
default:
fail(ErrorCode.INVALID_ARGS, command ? `Unknown command "${command}".\n\n${USAGE}` : USAGE);
}
});
Related skills
How it compares
Pick crypto-agent-trading App scripts for retail portfolio trades and the Exchange cdcx skill when you need limit orders, derivatives, and paper trading with tiered safety controls.
FAQ
What trading flow does crypto-agent-trading use on the App API?
crypto-agent-trading App trades use a two-step flow: trade.ts quote returns a quotation ID, then trade.ts confirm executes purchase, sale, or exchange orders against https://wapi.crypto.com with CDC_API_KEY credentials.
How many tokens does the Crypto.com App skill support?
The crypto-com-app skill supports market buy, sell, swap, and exchange operations across 200+ tokens including BTC, ETH, and CRO via scripted App API commands with optional confirmation gates.
What does the Exchange skill provide beyond the App skill?
The crypto-com-exchange skill adds cdcx CLI access to 86+ Exchange endpoints for spot and derivatives orders, paper trading, WebSocket streaming, and safety tiers separating read, sensitive_read, mutate, and dangerous operations.