Skip to content

refactor(trading-strategies): align --slippage-clamp flag with broker config key - #1314

Merged
bennycode merged 2 commits into
mainfrom
refactor/slippage-clamp-flag
Aug 17, 2026
Merged

refactor(trading-strategies): align --slippage-clamp flag with broker config key#1314
bennycode merged 2 commits into
mainfrom
refactor/slippage-clamp-flag

Conversation

@bennycode

Copy link
Copy Markdown
Owner

Why

The backtest CLI declared a no-slippage-clamp boolean and inverted it by hand:

'no-slippage-clamp': {default: false, type: 'boolean'},
// ...
const clampSlippage = !values['no-slippage-clamp'];

So the CLI name, the local constant, and the slippage.clamp key it ultimately feeds were three different spellings of one setting. The flag was named negatively because parseArgs booleans are presence-only — --slippage-clamp=false throws ERR_PARSE_ARGS_INVALID_OPTION_VALUE, and --slippage-clamp false throws ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL — so a default: true option had no way to be switched off.

parseArgs has a built-in answer for exactly this: allowNegative (added in v22.4.0 / v20.16.0).

What

Declare the option under its positive name and let the parser handle negation:

allowNegative: true,
// ...
'slippage-clamp': {default: true, type: 'boolean'},
// ...
const slippageClamp = values['slippage-clamp'];

--no-slippage-clamp is normalized to slippage-clamp: false during tokenization, so nothing downstream inverts anything and there is never a no-slippage-clamp key.

Invocation Result
(nothing) clamp: true
--slippage-clamp clamp: true — previously an unknown-option error
--no-slippage-clamp clamp: false — unchanged

Also fixed two help-text nits: the usage line omitted the flag entirely, and its options-block entry broke the description column the other five align to.

Compatibility

No breaking change. --no-slippage-clamp behaves exactly as before; --slippage-clamp becomes newly valid.

Verification

Ran against a real backtest at --slippage-rate 0.05 to confirm the flag reaches BrokerMock rather than only the log line:

--slippage-clamp      P&L: -2697.95 USDT   Portfolio: 10000.00 → 7302.05 USDT
--no-slippage-clamp   P&L: -9990.87 USDT   Portfolio: 10000.00 →     9.13 USDT

Default and explicit-on both print Slippage: 5.00% (clamped to candle range); the negated form omits it. oxlint and oxfmt --list-different are clean.

… config key

The backtest CLI declared a `no-slippage-clamp` boolean and inverted it by
hand, so the flag name did not match the `slippage.clamp` key it feeds.

Use `parseArgs({allowNegative: true})` (Node v22.4.0+) and declare the option
under its positive name instead. `--no-slippage-clamp` is normalized to
`slippage-clamp: false` by the parser, so the CLI name, the local constant and
the broker config key now all read the same.

- `--no-slippage-clamp` keeps working unchanged for existing callers
- `--slippage-clamp` is now a valid explicit-on instead of an unknown option
- usage line lists the flag, options block realigns to one description column
@bennycode
bennycode enabled auto-merge (squash) August 17, 2026 11:13
@bennycode
bennycode merged commit 6178196 into main Aug 17, 2026
7 checks passed
@bennycode
bennycode deleted the refactor/slippage-clamp-flag branch August 17, 2026 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant