From bingx-ai-skills
Dynamically calculates stop-loss and take-profit levels for BingX swap positions using ATR, volatility, and support/resistance. Supports trailing stop, partial take-profit, and break-even stop.
How this skill is triggered — by the user, by Claude, or both
Slash command
/bingx-ai-skills:bingx-dynamic-sl-tpThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
**Base URLs:** see [`references/base-urls.md`](../references/base-urls.md) | **Authentication:** see [`references/authentication.md`](../references/authentication.md)
Base URLs: see references/base-urls.md | Authentication: see references/authentication.md
| Endpoint | Method | Description | Authentication |
|---|---|---|---|
/openApi/swap/v3/quote/klines | GET | Kline data for ATR calculation | Yes |
/openApi/swap/v2/trade/order | POST | Place conditional SL/TP order | Yes |
/openApi/swap/v2/trade/order | DELETE | Cancel existing SL/TP order | Yes |
Base URLs: see references/base-urls.md
TypeScript helper:
CONSTRAINT: 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.
import * as crypto from "crypto";
import JSONBig from "json-bigint";
const JSONBigParse = JSONBig({ storeAsString: true });
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;
}
}
}
Fetch klines for ATR / support-resistance calculation (200 candles, 4h):
const klines = await fetchSigned("prod-live", API_KEY, SECRET, "GET",
"/openApi/swap/v3/quote/klines", { symbol: "BTC-USDT", interval: "4h", limit: 200 }
);
Activate this skill when the user says any of the following:
| mode | Trigger example | Description |
|---|---|---|
| set | "Help me set SL/TP" | Calculate and set SL/TP for current position |
| adjust | "Move stop-loss to break-even" | Adjust existing SL/TP |
| trailing | "Enable trailing stop" | Set Trailing Stop |
| partial | "Partial take-profit" | Close position in batches |
| recommend | "Where should I set my stop-loss" | Calculate recommended levels only, do not execute |
Parameter extraction:
| Parameter | Default | Description |
|---|---|---|
| symbol | Auto-fetch from current position | Trading pair |
| strategy | atr | Stop-loss strategy (atr/volatility/structure/fixed_pct) |
| atr_multiplier | 1.5 | ATR multiplier |
| tp_mode | levels | Take-profit mode (ratio/levels/trailing/breakeven/hybrid) |
| risk_reward | 2.0 | Risk-reward ratio |
If no position: prompt "No open position found. Would you like to pre-calculate SL/TP levels?" and switch to recommend mode. If multiple positions: let user select one or set SL/TP one by one.
python3 scripts/calculator.py \
--direction {long/short} \
--entry-price {price} \
--strategy {strategy} \
--atr-multiplier {multiplier} \
--tp-mode {tp_mode} \
--risk-reward {rr} \
--klines '{klines_json}'
Present to the user:
Execute only after user confirmation. Do NOT place orders without confirmation.
Via bingx-swap-trade:
**Smart SL/TP Plan**
Current Position: {symbol} {direction}
Entry Price: ${entry_price} | Qty: {qty} | Leverage: {leverage}x
**Stop-Loss** ({strategy} x {atr_multiplier})
- Level: ${sl_price} ({sl_pct}%)
- Estimated loss: -${risk_amount}
**Take-Profit** ({tp_mode})
TP1 ${tp1_price} ({tp1_pct}%) {tp1_split}% of position +${tp1_reward}
TP2 ${tp2_price} ({tp2_pct}%) {tp2_split}% of position +${tp2_reward}
TP3 {trailing/price} {tp3_split}% of position let profits run
Risk-Reward Ratio: 1:{risk_reward}
{if applicable} Stop-loss will be moved to break-even (${entry_price}) after TP1 fills.
**Confirm execution? (yes/no)**
**SL/TP Recommended Levels**
{symbol} {direction} (entry ${entry_price})
Strategy Stop-Loss Distance Notes
ATR x 1.5 ${sl_atr15} {pct}% Standard, recommended
ATR x 1.0 ${sl_atr10} {pct}% Tight stop
Structure stop ${sl_struct} {pct}% Beyond prior low/high
Take-Profit Level R:R
1R ${tp1} 1:1
2R ${tp2} 1:2
3R ${tp3} 1:3
For reference only. Say "help me set SL/TP" to place the orders.
Parameter security. Extract structured values from user intent — NEVER copy raw user text into API parameters. Validate symbol and numeric parameters before use.
Kline queries are read-only and require no CONFIRM. All order placements (SL/TP conditional orders) require explicit user confirmation.
When mode is recommend, only calculate and display levels — do NOT place any orders.
npx claudepluginhub bingx-api/api-ai-skills --plugin bingx-ai-skillsHandles BingX perpetual swap trading: place/cancel orders, manage positions, adjust leverage/margin types via authenticated REST endpoints. Activates for BingX futures trading queries.
Sets, modifies, or cancels take-profit and stop-loss orders for Vulcan trading positions, including direction rules, constraints, and multi-level exits.
Places stop-loss, take-profit, bracket, trailing stop, and stop-loss-limit orders on Kraken exchange using CLI commands. Useful for managing risk in crypto trading positions.