Skip to content

Commit

Permalink
calculate lockedBase & lockedQuote
Browse files Browse the repository at this point in the history
  • Loading branch information
mschneider committed Mar 13, 2024
1 parent 999e071 commit 3a45745
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@ yarn build

```bash
export SOL_RPC_URL=https://a.b.c
export KEYPAIR="1,2,3,4"
export KEYPAIR="[1,2,3,4,...]"
yarn ts/client/src/test/market.ts
```
21 changes: 21 additions & 0 deletions ts/client/src/accounts/openOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,27 @@ export class OpenOrders {
return debug;
}

getLockedBaseNative() {
return this.account.position.asksBaseLots
.mul(this.market.account.baseLotSize)
.iadd(this.account.position.baseFreeNative);
}

getLockedQuoteNative() {
return this.account.position.bidsQuoteLots
.mul(this.market.account.quoteLotSize)
.iadd(this.account.position.quoteFreeNative)
.iadd(this.account.position.lockedMakerFees);
}

getLockedBaseUi() {
return Number(this.getLockedBaseNative().toString()) / 10 ** this.market.account.baseDecimals;
}

getLockedQuoteUi() {
return Number(this.getLockedQuoteNative().toString()) / 10 ** this.market.account.quoteDecimals;
}

/// low-level API

public async placeOrderIx(
Expand Down
8 changes: 4 additions & 4 deletions ts/client/src/test/openOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async function testPlaceAndCancelOrderByClientId(): Promise<void> {
console.log('cancelled order', sigCancel);
}

testLoadIndexerNonExistent();
testLoadOOForMarket();
testPlaceAndCancelOrder();
testPlaceAndCancelOrderByClientId();
// testLoadIndexerNonExistent();
void testLoadOOForMarket();
// testPlaceAndCancelOrder();
// testPlaceAndCancelOrderByClientId();

0 comments on commit 3a45745

Please sign in to comment.