ChainUp Spot (Script-First)
Why This Skill
Use this skill immediately when the user mentions OpenAPI V2, spot trading, margin trading, X-CH-SIGN, /sapi/v2/order, /sapi/v1/margin/*, /sapi/v1/account, or similar ChainUp trading/account scenarios.
Goals:
- Prefer the script entrypoint instead of rebuilding signing logic each time.
- Return raw exchange JSON by default.
- If some parameters are still unknown, keep placeholders (
TODO) first and let the user fill them in later. - After the skill triggers, move to the script call quickly and avoid unnecessary explanation, extra reasoning, or repeated confirmation.
Runtime Entry
Unified entry script:
scripts/chainup_api.py
Core capabilities:
- Built-in signing:
X-CH-APIKEY,X-CH-SIGN,X-CH-TS - Built-in common headers:
Content-Type,admin-language,User-Agent - Unified
action -> endpointmapping - Real balance-changing actions require
--confirm CONFIRMby default - Order actions support
--prepare-only: fetch symbol rules viaspot_symbolsfirst, then preprocessprice/volume - Supports
--show-todoto display unresolved required placeholders for the current action
Execution Rules
- When this skill is triggered, call
scripts/chainup_api.pyfirst. Do not restate API parameter planning in natural language before using the script. - For read-only actions that do not affect balances or order state, call the script directly once parameters are clear. Only ask follow-up questions when required parameters are missing and cannot be inferred safely.
- For any action that can change balances, positions, open orders, or fills, provide a short execution summary in natural language before the live request, then wait for the user to reply with an exact standalone
Confirmbefore calling the script. - For non-fund-changing queries, avoid extra confirmation and execute directly.
- Do not treat "the user wants to place/cancel/transfer" as execution permission. No live request is allowed until a separate user message contains
Confirm. - For
spot_create_order,spot_test_order, andmargin_create_order, run the script with--prepare-onlybefore asking for confirmation. The script will callspot_symbols, fetch symbol precision, and round down usingpricePrecision/quantityPrecision. - When showing parameters that need confirmation, always use the
preparedBodyfrom--prepare-only. Do not show the unadjusted raw order payload. - After the user sends a standalone
Confirm, execute the live balance-changing action and keep using--confirm CONFIRM. - If
spot_create_ordersucceeds, follow up withspot_get_orderby default. - All HTTP requests must be sent through
scripts/chainup_api.py. - If the script call fails, return the script failure result and continue debugging through the Python script only. Do not switch to
curl, handwritten signing, or any backup HTTP implementation. - Do not add a second implementation "just to verify the API". Avoid branching logic and duplicated reasoning.
Required Config
Prefer /root/TOOLS.md first:
BASE_URL: ...API_KEY: ...SECRET_KEY: ...
Use environment variables only as the next fallback:
CHAINUP_BASE_URLCHAINUP_API_KEYCHAINUP_SECRET_KEY
CLI arguments are also supported:
--base-url--api-key--secret-key
Config resolution priority:
CLI arguments>/root/TOOLS.md>environment variables- If
/root/TOOLS.mdalready contains usable credentials, use them directly and do not require the user to set environment variables first.
Sensitive data handling:
CHAINUP_API_KEYandCHAINUP_SECRET_KEYare sensitive. Never print them in full in the terminal, natural-language responses, execution summaries, error relays, or example commands.- If they must be referenced, only show masked values: keep the first 4 and last 4 characters and replace the middle with
***, for example915c***815e. - Avoid inlining secrets in visible commands whenever possible. If a command must include them, do not repeat that full secret-bearing command in the response.
- Even if the user provides the full secret explicitly, never echo it back verbatim later.
Call Template
python /root/.codex/skills/chainup-spot/scripts/chainup_api.py <action> \
--query-json '<json-object>' \
--body-json '<json-object>' \
--show-todo
Notes:
- Use
--query-jsonforGETactions - Use
--body-jsonforPOSTactions - For order actions,
--prepare-onlycan be used first to return precision-adjustedpreparedBodyfor confirmation - For actions that change balances or orders, append
--confirm CONFIRMonly after the user sends a standaloneConfirm - Unless the user asks for explanation, prefer executing first and returning the result instead of giving a long preface
Action Map
Public:
spot_ping->GET /sapi/v2/pingspot_time->GET /sapi/v2/timespot_symbols->GET /sapi/v2/symbolsspot_depth->GET /sapi/v2/depthspot_ticker->GET /sapi/v2/tickerspot_trades->GET /sapi/v2/tradesspot_klines->GET /sapi/v2/klines
Spot Signed:
spot_create_order->POST /sapi/v2/orderspot_test_order->POST /sapi/v2/order/testspot_batch_orders->POST /sapi/v2/batchOrdersspot_get_order->GET /sapi/v2/orderspot_cancel_order->POST /sapi/v2/cancelspot_batch_cancel->POST /sapi/v2/batchCancelspot_open_orders->GET /sapi/v2/openOrdersspot_my_trades->GET /sapi/v2/myTrades
Account Signed:
spot_account->GET /sapi/v1/accountasset_transfer->POST /sapi/v1/asset/transferasset_transfer_query->POST /sapi/v1/asset/transferQuery
Margin Signed:
margin_create_order->POST /sapi/v1/margin/ordermargin_get_order->GET /sapi/v1/margin/ordermargin_cancel_order->POST /sapi/v1/margin/cancelmargin_open_orders->GET /sapi/v1/margin/openOrdersmargin_my_trades->GET /sapi/v1/margin/myTrades
Response Rules
- Return raw JSON by default (script stdout).
--prepare-onlyreturnsoriginalBody,preparedBody,adjustments, andsymbolRuleso the user can review the precision-adjusted live order payload before confirmation.- After a successful
spot_create_order, immediately follow withspot_get_orderby default and return the latest order details. - When fetching the follow-up order, prefer
symbol + orderIdfrom the create-order response. If the gateway also returnsorderIdString, preserve it as well. spot_accountis filtered directly in the Python script and returns only assets wherefree > 0orlocked > 0.- Add a short summary only when the user asks to "show just the key points".
- If returned content, errors, or debug output contains full
api-key,secret-key, or other credentials, mask them before showing anything.
Safety Rules
- All live balance-changing actions (place order, cancel order, transfer) require the user to send
Confirmmanually before execution, then use--confirm CONFIRM. - Any action that affects balances, even if it may not fill immediately, is still treated as a live balance-changing action. This includes but is not limited to limit orders, batch orders, cancellations, transfers, margin orders, and margin cancellations.
- Query actions can execute directly, including but not limited to balance queries, order queries, trade history queries, market data queries, and open-order queries.
- Precision prechecks are mandatory before order confirmation so the script does not send prices or quantities that exceed symbol precision to the live gateway.
- If the user explicitly requests to bypass confirmation,
--no-confirm-gatemay be used. This is high risk and should only be used with explicit user authorization. - Never print full credentials in the terminal or reply. If the script throws an error that could expose secrets, summarize the failure rather than copying the raw sensitive output.
Examples
Query spot balances:
python /root/.codex/skills/chainup-spot/scripts/chainup_api.py spot_account --query-json '{}'
Spot market order preparation (live request requires confirmation):
python /root/.codex/skills/chainup-spot/scripts/chainup_api.py spot_create_order \
--body-json '{"symbol":"BTC/USDT","volume":"100.123456","side":"BUY","type":"MARKET"}' \
--prepare-only
Execute the live request after confirmation:
python /root/.codex/skills/chainup-spot/scripts/chainup_api.py spot_create_order \
--body-json '{"symbol":"BTC/USDT","volume":"100","side":"BUY","type":"MARKET"}' \
--confirm CONFIRM --show-todo
Additional spot order conventions:
- When
type=MARKETandside=BUY,volumeis interpreted in the quote asset. - For example, for
ETH/USDT,volume=1withside=BUYmeans buying ETH with1 USDTat market. - When
type=MARKETandside=SELL,volumeis interpreted in the base asset amount. - For example, for
ETH/USDT,volume=0.1withside=SELLmeans selling0.1 ETHat market. - For non-market order types such as
LIMIT,volumeis still interpreted as the base asset amount. - After
spot_create_ordersucceeds, the default next step is not just returning the order receipt. The script should continue withspot_get_orderand return the latest order information.
Margin limit order:
python /root/.codex/skills/chainup-spot/scripts/chainup_api.py margin_create_order \
--body-json '{"symbol":"BTC/USDT","volume":"0.001","side":"BUY","type":"LIMIT","price":"30000"}' \
--confirm CONFIRM --show-todo
References
- Authentication and signing:
references/authentication.md - Spot endpoints:
references/spot-endpoints.md - Margin endpoints:
references/margin-endpoints.md