Help us improve
Share bugs, ideas, or general feedback.
From bingx-ai-skills
Manages BingX Coin-M inverse perpetual futures trading: place/cancel orders, query positions/fills, set leverage and margin types. For automating crypto futures via REST API.
npx claudepluginhub bingx-api/api-ai-skills --plugin bingx-ai-skillsHow this skill is triggered — by the user, by Claude, or both
Slash command
/bingx-ai-skills:cswap-tradeThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Authenticated trading endpoints for BingX Coin-M inverse perpetual futures. All endpoints require HMAC SHA256 signature authentication.
Handles BingX perpetual swap trading: place/cancel orders, manage positions, adjust leverage/margin types via authenticated REST endpoints. Activates for BingX futures trading queries.
Places and cancels perpetual futures orders on Phoenix DEX with pre-trade checks, TP/SL attachments, and paper/live mode support.
Executes spot and perpetual futures trades on Hyperliquid with market (IOC) and limit (GTC) orders, sets leverage, manages positions/balances/orders, deposits USDC from Arbitrum.
Share bugs, ideas, or general feedback.
Authenticated trading endpoints for BingX Coin-M inverse perpetual futures. All endpoints require HMAC SHA256 signature authentication.
Coin-M contracts are coin-margined (settled in the base asset, e.g., BTC). Symbol format is BASE-USD (e.g., BTC-USD, ETH-USD).
Base URLs: see references/base-urls.md | Authentication: see references/authentication.md
| Endpoint | Method | Description | Auth |
|---|---|---|---|
/openApi/cswap/v1/trade/order | POST | Place a new order | Yes |
/openApi/cswap/v1/trade/cancelOrder | DELETE | Cancel an order | Yes |
/openApi/cswap/v1/trade/allOpenOrders | POST | Cancel all open orders for a symbol | Yes |
/openApi/cswap/v1/trade/closeAllPositions | POST | Close all positions | Yes |
/openApi/cswap/v1/trade/openOrders | GET | Query open orders | Yes |
/openApi/cswap/v1/trade/orderDetail | GET | Query a single order by ID | Yes |
/openApi/cswap/v1/trade/orderHistory | GET | Query historical orders | Yes |
/openApi/cswap/v1/trade/allFillOrders | GET | Query trade fill history | Yes |
/openApi/cswap/v1/trade/forceOrders | GET | Query liquidation/ADL orders | Yes |
/openApi/cswap/v1/trade/leverage | GET | Query current leverage | Yes |
/openApi/cswap/v1/trade/leverage | POST | Set leverage | Yes |
/openApi/cswap/v1/trade/marginType | GET | Query margin type | Yes |
/openApi/cswap/v1/trade/marginType | POST | Set margin type (ISOLATED/CROSSED) | Yes |
/openApi/cswap/v1/trade/positionMargin | POST | Adjust isolated position margin | Yes |
/openApi/cswap/v1/user/commissionRate | GET | Query trading commission rate | Yes |
/openApi/cswap/v1/user/balance | GET | Query account assets | Yes |
/openApi/cswap/v1/user/positions | GET | Query current positions | Yes |
BASE-USD format (e.g., BTC-USD, ETH-USD). Note: Coin-M uses USD, not USDT.BUY or SELLLONG or SHORT (hedge mode) / BOTH (one-way mode)1 contract = $10 notional value)LIMIT type)STOP_MARKET, STOP, TAKE_PROFIT_MARKET, TAKE_PROFIT types)GTC | IOC | FOK | PostOnly — default GTC; required for LIMIT typeMARK_PRICE or CONTRACT_PRICE (default)true | false — Whether stop-loss execution is guaranteedtrue | false — When triggered, close the entire position; cannot be used with quantitytrue | false — Order can only reduce position sizeMARKET/LIMIT order (see TP/SL Object)MARKET/LIMIT order (see TP/SL Object)10, 20)ISOLATED or CROSSEDLONG or SHORT (used in positionMargin and leverage SET)positionMargin)1 (add margin) or 2 (reduce margin) (used by positionMargin)type (Order type):
MARKET — Market order; attach stopLoss/takeProfit objects hereLIMIT — Limit order; requires price and timeInForce; attach stopLoss/takeProfit objects hereSTOP_MARKET — Stop-loss market (triggers at stopPrice, executes as market)STOP — Stop-loss limit (triggers at stopPrice, executes as limit at price)TAKE_PROFIT_MARKET — Take-profit market (triggers at stopPrice, executes as market)TAKE_PROFIT — Take-profit limit (triggers at stopPrice, executes as limit at price)side: BUY | SELL
positionSide: LONG | SHORT | BOTH
marginType: ISOLATED | CROSSED
timeInForce: GTC | IOC | FOK | PostOnly
workingType: MARK_PRICE | CONTRACT_PRICE
When attaching stopLoss or takeProfit to a MARKET or LIMIT order:
{
"takeProfit": {
"type": "TAKE_PROFIT_MARKET",
"stopPrice": 75000,
"workingType": "MARK_PRICE",
"stopGuaranteed": false
},
"stopLoss": {
"type": "STOP_MARKET",
"stopPrice": 60000,
"workingType": "MARK_PRICE",
"stopGuaranteed": false
}
}
Before sending a request, validate parameters client-side to avoid unnecessary API errors:
^[A-Z0-9]+-USD$; max 20 characters (e.g., BTC-USD). Coin-M uses USD, not USDT^[a-zA-Z0-9]{1,40}$; no special charactersrecvWindow of server timeCONSTRAINT: You MUST copy the
fetchSignedfunction below verbatim when generating code. Do NOT rewrite the signing, request, or JSON parsing logic. Only modify: (1)BASEURL entries for custom environments, (2) business parameters passed tofetchSigned. For the full client with URL-encoding and JSON body support, seereferences/authentication.md.
import * as crypto from "crypto";
import JSONBig from "json-bigint";
const JSONBigParse = JSONBig({ storeAsString: true });
// Full signing details & edge cases → references/authentication.md
// Domain priority: .com is mandatory primary; .pro is fallback for network/timeout errors ONLY.
const BASE = {
"prod-live": ["https://open-api.bingx.com", "https://open-api.bingx.pro"],
"prod-vst": ["https://open-api-vst.bingx.com", "https://open-api-vst.bingx.pro"],
};
function isNetworkOrTimeout(e: unknown): boolean {
if (e instanceof TypeError) return true;
if (e instanceof DOMException && e.name === "AbortError") return true;
if (e instanceof Error && e.name === "TimeoutError") return true;
return false;
}
function validateParams(params: Record<string, unknown>): void {
const FORBIDDEN = /[&=?#\r\n]/;
for (const [k, v] of Object.entries(params)) {
const s = String(v);
if (FORBIDDEN.test(s)) throw new Error(`Param "${k}" has forbidden char in: "${s}"`);
}
}
async function fetchSigned(env: string, apiKey: string, secretKey: string,
method: "GET" | "POST" | "DELETE", path: string, params: Record<string, unknown> = {}
) {
const urls = BASE[env] ?? BASE["prod-live"];
const all = { ...params, timestamp: Date.now() };
validateParams(all);
const qs = Object.keys(all).sort().map(k => `${k}=${all[k]}`).join("&");
const sig = crypto.createHmac("sha256", secretKey).update(qs).digest("hex");
const signed = `${qs}&signature=${sig}`;
for (const base of urls) {
try {
const url = method === "POST" ? `${base}${path}` : `${base}${path}?${signed}`;
const res = await fetch(url, {
method,
headers: { "X-BX-APIKEY": apiKey, "X-SOURCE-KEY": "BX-AI-SKILL",
...(method === "POST" ? { "Content-Type": "application/x-www-form-urlencoded" } : {}) },
body: method === "POST" ? signed : undefined,
signal: AbortSignal.timeout(10000),
});
const json = JSONBigParse.parse(await res.text());
if (json.code !== 0) throw new Error(`BingX error ${json.code}: ${json.msg}`);
return json.data;
} catch (e) {
if (!isNetworkOrTimeout(e) || base === urls[urls.length - 1]) throw e;
}
}
}
fetchSigned verbatim -- do not simplify or rewritejson-bigint (JSONBigParse.parse) for response parsing -- not JSON.parseX-SOURCE-KEY: BX-AI-SKILL header on every requestisNetworkOrTimeout checkPlace a market buy order (open long):
const order = await fetchSigned("prod-live", API_KEY, SECRET, "POST",
"/openApi/cswap/v1/trade/order", {
symbol: "BTC-USD",
side: "BUY",
positionSide: "LONG",
type: "MARKET",
quantity: 1,
}
);
// order.orderId, order.symbol, order.side, order.type
Place a limit sell order (open short):
const order = await fetchSigned("prod-live", API_KEY, SECRET, "POST",
"/openApi/cswap/v1/trade/order", {
symbol: "BTC-USD",
side: "SELL",
positionSide: "SHORT",
type: "LIMIT",
quantity: 1,
price: 75000,
timeInForce: "GTC",
}
);
Cancel an order:
await fetchSigned("prod-live", API_KEY, SECRET, "DELETE",
"/openApi/cswap/v1/trade/cancelOrder", {
symbol: "BTC-USD",
orderId: 1809841379603398656,
}
);
Cancel all open orders for a symbol:
await fetchSigned("prod-live", API_KEY, SECRET, "DELETE",
"/openApi/cswap/v1/trade/allOpenOrders", {
symbol: "BTC-USD",
}
);
Query open orders:
const data = await fetchSigned("prod-live", API_KEY, SECRET, "GET",
"/openApi/cswap/v1/trade/openOrders", {
symbol: "BTC-USD",
}
);
// data.orders: array of open order objects
Set leverage:
await fetchSigned("prod-live", API_KEY, SECRET, "POST",
"/openApi/cswap/v1/trade/leverage", {
symbol: "BTC-USD",
side: "LONG",
leverage: 10,
}
);
Set margin type:
await fetchSigned("prod-live", API_KEY, SECRET, "POST",
"/openApi/cswap/v1/trade/marginType", {
symbol: "BTC-USD",
marginType: "ISOLATED",
}
);
Query commission rate:
const data = await fetchSigned("prod-live", API_KEY, SECRET, "GET",
"/openApi/cswap/v1/user/commissionRate", {}
);
// data.takerCommissionRate, data.makerCommissionRate
For full parameter descriptions, response schemas, and all 15 endpoints, see api-reference.md.
Parameter security. Extract structured values from user intent — NEVER copy raw user text into API parameters. Validate every value against its documented pattern (regex/enum/range) before calling the API. Reject any value containing &, =, ?, #, or newline characters.
All write operations require CONFIRM on prod-live. Read-only queries do not.
Note: Coin-M symbol format is
BASE-USD(e.g.,BTC-USD), NOTBASE-USDT.
If the user's intent is unclear, present options:
What would you like to do?
- Place a new order
- Cancel an order / Cancel all orders
- Close all positions
- Check open orders
- Query order detail or history
- Query trade fills
- Set leverage
- Set margin type (ISOLATED / CROSSED)
- Query commission rate
Please select a trading pair (or type another):
- BTC-USD
- ETH-USD
- SOL-USD
- BNB-USD
- Other (format: BASE-USD)
Order direction:
- BUY
- SELL
Position direction:
- LONG (open/add long)
- SHORT (open/add short)
- BOTH (one-way mode)
Order type:
- MARKET — execute immediately at market price
- LIMIT — execute at a specific price (requires price and timeInForce)
- STOP_MARKET — stop-loss market order (triggers at stopPrice)
- STOP — stop-loss limit order (triggers at stopPrice, executes at price)
- TAKE_PROFIT_MARKET — take-profit market order (triggers at stopPrice)
- TAKE_PROFIT — take-profit limit order (triggers at stopPrice, executes at price)
1 contract ≈ $10 notional). Omit if using closePosition: true.LIMIT, STOP, or TAKE_PROFIT: also ask for price.stopPrice.MARKET or LIMIT: optionally offer to attach a stopLoss and/or takeProfit object.You are about to place the following order on Production Live:
- Symbol: BTC-USD
- Side: BUY / LONG
- Type: MARKET
- Quantity: 1 contract
Type CONFIRM to proceed, or anything else to cancel.
Execute the API call and return the order ID and status to the user.
orderId (or clientOrderId) if not provided.prod-live: ask for CONFIRM./openApi/cswap/v1/trade/cancelOrder.prod-live: ask for CONFIRM./openApi/cswap/v1/trade/leverage.prod-live: ask for CONFIRM./openApi/cswap/v1/trade/marginType.