refactor(trading-strategies): align --slippage-clamp flag with broker config key - #1314
Merged
Conversation
… 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The backtest CLI declared a
no-slippage-clampboolean and inverted it by hand:So the CLI name, the local constant, and the
slippage.clampkey it ultimately feeds were three different spellings of one setting. The flag was named negatively becauseparseArgsbooleans are presence-only —--slippage-clamp=falsethrowsERR_PARSE_ARGS_INVALID_OPTION_VALUE, and--slippage-clamp falsethrowsERR_PARSE_ARGS_UNEXPECTED_POSITIONAL— so adefault: trueoption had no way to be switched off.parseArgshas 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:
--no-slippage-clampis normalized toslippage-clamp: falseduring tokenization, so nothing downstream inverts anything and there is never ano-slippage-clampkey.clamp: true--slippage-clampclamp: true— previously an unknown-option error--no-slippage-clampclamp: false— unchangedAlso 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-clampbehaves exactly as before;--slippage-clampbecomes newly valid.Verification
Ran against a real backtest at
--slippage-rate 0.05to confirm the flag reachesBrokerMockrather than only the log line:Default and explicit-on both print
Slippage: 5.00% (clamped to candle range); the negated form omits it.oxlintandoxfmt --list-differentare clean.