From 7445c970bc92e39f5d47f432951082ddc71a77b7 Mon Sep 17 00:00:00 2001 From: David Lau Date: Wed, 8 Apr 2026 11:02:31 +0800 Subject: [PATCH] feat(swap): support profit_stop_trace and loss_stop_trace in condition orders - Add drawdown_rate optional field to StrategyConditionOrder interface - Make price_scale optional (required only for fixed-price types) - Update --condition-orders help text with trace type example - Document all 4 condition order types in SKILL.md with field requirements, drawdown_rate semantics, and usage examples - Sync order strategy create params: replace --side / auto-inference with explicit --order-type and --sub-order-type required options - Add --group-tag to order strategy list params - Add --order-type to order strategy cancel params - Fix --gas-price description: gwei (not wei); CLI converts internally Co-Authored-By: Claude Sonnet 4.6 --- skills/gmgn-swap/SKILL.md | 14 ++++++++++---- src/client/OpenApiClient.ts | 6 ++++-- src/commands/swap.ts | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/skills/gmgn-swap/SKILL.md b/skills/gmgn-swap/SKILL.md index 64cc6f9..818e621 100644 --- a/skills/gmgn-swap/SKILL.md +++ b/skills/gmgn-swap/SKILL.md @@ -223,10 +223,11 @@ Each element in the `--condition-orders` JSON array supports: | Field | Required | Type | Description | |-------|----------|------|-------------| -| `order_type` | Yes | string | Sub-order type. Supported: `profit_stop` (take-profit), `loss_stop` (stop-loss). Not yet supported: `profit_stop_trace`, `loss_stop_trace`, `follow_dev_sell`, `migrated_sell` | +| `order_type` | Yes | string | Sub-order type: `profit_stop` (fixed take-profit), `loss_stop` (fixed stop-loss), `profit_stop_trace` (trailing take-profit), `loss_stop_trace` (trailing stop-loss) | | `side` | Yes | string | Always `"sell"` | -| `price_scale` | Yes | string | Gain/drop % from entry. For `profit_stop`: gain % (e.g., `"100"` = +100% / 2× entry, `"300"` = +300% / 4× entry). For `loss_stop`: drop % (e.g., `"65"` = drops 65%, triggers at 35% of entry). | +| `price_scale` | Conditional | string | Gain/drop % from entry. Required for `profit_stop` / `loss_stop` / `profit_stop_trace`; optional for `loss_stop_trace`. For `profit_stop` / `profit_stop_trace`: gain % (e.g. `"100"` = +100% / 2× entry). For `loss_stop` / `loss_stop_trace`: drop % (e.g. `"65"` = drops 65%, triggers at 35% of entry). | | `sell_ratio` | Yes | string | Percentage of position to sell when triggered, e.g. `"100"` = 100% | +| `drawdown_rate` | Conditional | string | Required for `profit_stop_trace` and `loss_stop_trace`. Trailing callback %: after price peaks, how far it must fall before the order fires. E.g. `"50"` = 50% drawdown from peak. | **Example — attach take-profit at 2× (+100%) and stop-loss at -60%:** @@ -349,7 +350,8 @@ Convert `filled_input_amount` and `filled_output_amount` from smallest unit usin | `--from` | Yes | Wallet address (must match API Key binding) | | `--base-token` | Yes | Base token contract address | | `--quote-token` | Yes | Quote token contract address | -| `--side` | Yes | Direction: `buy` / `sell` | +| `--order-type` | Yes | Order type: `limit_order` | +| `--sub-order-type` | Yes | Sub-order type: `buy_low` / `buy_high` / `stop_loss` / `take_profit` | | `--check-price` | Yes | Trigger check price | | `--amount-in` | No* | Input amount (smallest unit). Mutually exclusive with `--amount-in-percent` | | `--amount-in-percent` | No* | Input as percentage (e.g. `50` = 50%). Mutually exclusive with `--amount-in` | @@ -360,7 +362,7 @@ Convert `filled_input_amount` and `filled_output_amount` from smallest unit usin | `--auto-slippage` | No | Enable automatic slippage | | `--priority-fee` | No | Priority fee in SOL (SOL only) | | `--tip-fee` | No | Tip fee | -| `--gas-price` | No | Gas price in wei (EVM chains) | +| `--gas-price` | No | Gas price in gwei (BSC ≥ 0.05 gwei / BASE/ETH ≥ 0.01 gwei) | | `--anti-mev` | No | Enable anti-MEV protection | @@ -378,6 +380,7 @@ Convert `filled_input_amount` and `filled_output_amount` from smallest unit usin | `--chain` | Yes | `sol` / `bsc` / `base` | | `--type` | No | `open` (default) / `history` | | `--from` | No | Filter by wallet address | +| `--group-tag` | No | Filter by group: `LimitOrder` / `STMix` | | `--base-token` | No | Filter by token address | | `--page-token` | No | Pagination cursor from previous response | | `--limit` | No | Results per page (default 10 for history) | @@ -397,6 +400,7 @@ Convert `filled_input_amount` and `filled_output_amount` from smallest unit usin | `--chain` | Yes | `sol` / `bsc` / `base` | | `--from` | Yes | Wallet address (must match API Key binding) | | `--order-id` | Yes | Order ID to cancel | +| `--order-type` | No | Order type: `limit_order` / `smart_trade` | | `--close-sell-model` | No | Sell model when closing the order | ## `order strategy` Usage Examples @@ -408,6 +412,7 @@ gmgn-cli order strategy create \ --from \ --base-token \ --quote-token \ + --order-type limit_order \ --sub-order-type take_profit \ --check-price 0.002 \ --amount-in 1000000 \ @@ -419,6 +424,7 @@ gmgn-cli order strategy create \ --from \ --base-token \ --quote-token \ + --order-type limit_order \ --sub-order-type stop_loss \ --check-price 0.0005 \ --amount-in-percent 100 \ diff --git a/src/client/OpenApiClient.ts b/src/client/OpenApiClient.ts index fd43e11..d0224a6 100644 --- a/src/client/OpenApiClient.ts +++ b/src/client/OpenApiClient.ts @@ -90,10 +90,11 @@ export interface SwapParams { } export interface StrategyConditionOrder { - order_type: string; // "profit_stop" | "loss_stop" + order_type: string; // "profit_stop" | "loss_stop" | "profit_stop_trace" | "loss_stop_trace" side: string; // "sell" - price_scale: string; + price_scale?: string; sell_ratio: string; + drawdown_rate?: string; } export interface StrategyCreateParams { @@ -104,6 +105,7 @@ export interface StrategyCreateParams { order_type: string; sub_order_type: string; check_price: string; + open_price?: string; amount_in?: string; amount_in_percent?: string; limit_price_mode?: string; diff --git a/src/commands/swap.ts b/src/commands/swap.ts index cc6dd2f..c678854 100644 --- a/src/commands/swap.ts +++ b/src/commands/swap.ts @@ -24,7 +24,7 @@ export function registerSwapCommands(program: Command): void { .option("--gas-price ", "Gas price in gwei (BSC ≥ 0.05 / BASE/ETH ≥ 0.01)") .option("--max-fee-per-gas ", "EIP-1559 max fee per gas (Base)") .option("--max-priority-fee-per-gas ", "EIP-1559 max priority fee per gas (Base)") - .option("--condition-orders ", 'JSON array of take-profit/stop-loss conditions, e.g. \'[{"order_type":"profit_stop","side":"sell","price_scale":"150","sell_ratio":"100"}]\'') + .option("--condition-orders ", 'JSON array of take-profit/stop-loss conditions, e.g. \'[{"order_type":"profit_stop","side":"sell","price_scale":"150","sell_ratio":"100"}]\'; trace types: \'[{"order_type":"profit_stop_trace","side":"sell","price_scale":"150","sell_ratio":"100","drawdown_rate":"50"}]\'') .option("--sell-ratio-type ", "Sell ratio base: buy_amount (default) / hold_amount; only used with --condition-orders") .option("--raw", "Output raw JSON") .action(async (opts) => {