Skip to content

Fix/add leverage bounds validation - #31

Open
MayurK-cmd wants to merge 2 commits into
jup-ag:mainfrom
MayurK-cmd:fix/add-leverage-bounds-validation
Open

MayurK-cmd wants to merge 2 commits into
jup-ag:mainfrom
MayurK-cmd:fix/add-leverage-bounds-validation

Conversation

@MayurK-cmd

Copy link
Copy Markdown

fix: add leverage bounds validation to perps open command

Users can now specify any leverage value to perps open --leverage, but
there are real bounds (1-100x) beyond which the Perps protocol rejects
positions. Validate leverage at the CLI before sending to the API so users
get immediate, clear feedback instead of a cryptic API error.

Changes:

  • Add leverage bounds check in PerpsCommand.open()
  • Validate1 <= leverage <= 100 and reject non-numeric values
  • Add 4 e2e tests: below 1, above 100, non-numeric, valid range

Fixes: #26

Both SpotCommand and PerpsCommand had duplicate parseTimestamp() methods
with inconsistent behavior. Created shared DateConverter.parseTimestamp()
utility to ensure consistent timestamp handling across all commands.

Changes:
- Create src/lib/DateConverter.ts with parseTimestamp() method
- Update SpotCommand to use DateConverter.parseTimestamp()
- Update PerpsCommand to use DateConverter.parseTimestamp()
- Reduces code duplication by 2 implementations
The perps open command now validates that leverage is between 1 and 100,
rejecting values outside this range with a clear error message.

Changes:
- Add leverage bounds check (1 <= leverage <= 100) inPerpsCommand.open()
- Reject non-numeric leverage values
- Add4 e2e tests covering boundary cases and valid range
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.

perps open should validate leverage is within reasonable bounds

1 participant