Skip to content

Commit

Permalink
Bugfix getMaxTradeSize with leverage option (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipzeta authored Nov 17, 2023
1 parent e848f9a commit 270e70b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ Version changes are pinned to SDK releases.

## Unreleased

## [1.12.2]

- Bugfix getMaxTradeSize with leverage option. ([#300](https://github.com/zetamarkets/sdk/pull/300))

## [1.12.1]

- Add optional override equity param in leverage util([#301](https://github.com/zetamarkets/sdk/pull/301))
- Add optional override equity param in leverage util. ([#301](https://github.com/zetamarkets/sdk/pull/301))

## [1.12.0]

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zetamarkets/sdk",
"repository": "https://github.com/zetamarkets/sdk/",
"version": "1.12.1",
"version": "1.12.2",
"description": "Zeta SDK",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
10 changes: 8 additions & 2 deletions src/risk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -997,11 +997,17 @@ export class RiskCalculator {
// TODO if this is slow then do only the necessary calcs manually, there's a bunch of extra calcs in here
// that aren't needed in getMaxTradeSize()
let newState = this.getCrossMarginAccountState(editedAccount);
let nonLeverageBuffer =
newState.availableBalanceInitial / newState.balance;
let buffer =
maxLeverage == -1
? newState.availableBalanceInitial / newState.balance
: (maxLeverage - this.getLeverage(editedAccount, undefined, false)) /
maxLeverage;
: Math.min(
(maxLeverage -
this.getLeverage(editedAccount, undefined, false)) /
maxLeverage,
nonLeverageBuffer
);

if (
buffer < thresholdPercent / 100 &&
Expand Down

0 comments on commit 270e70b

Please sign in to comment.