Skip to content

Commit

Permalink
sdk: fix getBestBid/Ask to handle undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
crispheaney committed Dec 27, 2023
1 parent c371190 commit 5098b61
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions sdk/src/dlob/DLOB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1472,31 +1472,37 @@ export class DLOB {
slot: number,
marketType: MarketType,
oraclePriceData: OraclePriceData
): BN {
return this.getRestingLimitAsks(
): BN | undefined {
const bestAsk = this.getRestingLimitAsks(
marketIndex,
slot,
marketType,
oraclePriceData
)
.next()
.value.getPrice(oraclePriceData, slot);
).next().value;

if (bestAsk) {
return bestAsk.getPrice(oraclePriceData, slot);
}
return undefined;
}

public getBestBid(
marketIndex: number,
slot: number,
marketType: MarketType,
oraclePriceData: OraclePriceData
): BN {
return this.getRestingLimitBids(
): BN | undefined {
const bestBid = this.getRestingLimitBids(
marketIndex,
slot,
marketType,
oraclePriceData
)
.next()
.value.getPrice(oraclePriceData, slot);
).next().value;

if (bestBid) {
return bestBid.getPrice(oraclePriceData, slot);
}
return undefined;
}

public *getStopLosses(
Expand Down

0 comments on commit 5098b61

Please sign in to comment.