Skip to content

feat(trade): --take-profit / --stop-loss perp flags#63

Open
psmiratisu wants to merge 1 commit into
mainfrom
feat/hl-tp-sl-perp
Open

feat(trade): --take-profit / --stop-loss perp flags#63
psmiratisu wants to merge 1 commit into
mainfrom
feat/hl-tp-sl-perp

Conversation

@psmiratisu

@psmiratisu psmiratisu commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

What

Adds --take-profit / --stop-loss (plus --take-profit-limit / --stop-loss-limit) to acp trade for Hyperliquid perps. Companion to trading-agent #74, which added native TP/SL trigger orders to the planner.

How it works

The CLI stays a pure signer — it just forwards the trigger prices in the flat trade body; the planner builds and the wallet signs the resulting order action (a single signature).

Two modes, driven by whether a size is present:

  • With --size / --amount-usdc → TP/SL bundle onto the opening order (planner uses HL's normalTpsl).
  • Alone (no sizing) → TP/SL attach to the position you already hold (positionTpsl, sized from the live position).

Market close by default; pass --take-profit-limit / --stop-loss-limit to rest a limit on trigger instead.

# open a long with TP + SL in one go
acp trade --side long --token BTC --amount-usdc 100 --take-profit 130000 --stop-loss 80000

# set a stop on an existing long
acp trade --side long --token BTC --stop-loss 80000

Field mapping

commander camelCases the flags; the body uses the backend's names:

flag opts body
--take-profit takeProfit takeProfitPrice
--take-profit-limit takeProfitLimit takeProfitLimitPrice
--stop-loss stopLoss stopLossPrice
--stop-loss-limit stopLossLimit stopLossLimitPrice

The flags live directly on the trade command (no parent/child duplication), so they're free of the optsWithGlobals() swallow issue.

Test

npm run typecheck clean. Verified the flags register (acp trade --help) and that commander produces the exact camelCase keys the fwd() calls map from.

Rollout

Needs trading-agent #74 merged/deployed to take effect. agentic-commerce-be needs no change — its trade proxy forwards the request body verbatim (no DTO / allow-list), so these fields pass straight through.

🤖 Generated with Claude Code


Note

Medium Risk
Touches live perp order parameters; behavior depends on trading-agent deployment, though the CLI only forwards fields and does not implement trigger logic.

Overview
Adds Hyperliquid perp take-profit and stop-loss to acp trade via four new flags: --take-profit, --take-profit-limit, --stop-loss, and --stop-loss-limit. Help text documents that triggers can bundle with --size / --amount-usdc on entry or apply alone to an existing position, with optional limit prices instead of market closes.

runTrade forwards commander’s camelCase options to the trade plan body as takeProfitPrice, takeProfitLimitPrice, stopLossPrice, and stopLossLimitPrice for the trading-agent planner; the CLI still only signs what the backend returns.

Reviewed by Cursor Bugbot for commit f9a103b. Bugbot is set up for automated code reviews on this repo. Configure here.

Forward TP/SL trigger prices to the planner. With a size (--size/--amount-usdc)
they attach to the opening order; alone they attach to an existing position.
Each accepts an optional --*-limit companion to rest a limit on trigger instead
of a market close. Maps to the backend's takeProfitPrice / stopLossPrice
(+ *LimitPrice); the proxy forwards them verbatim.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant