Skip to content

Commit

Permalink
sdk: fix bug for cancel existing orders (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpipta authored Nov 14, 2023
1 parent 6eade46 commit 340ec36
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions sdk/src/driftClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2448,7 +2448,7 @@ export class DriftClient {
* @param makerInfo
* @param txParams
* @param bracketOrdersParams
* @param cancelExistingOrders - Builds and returns an extra transaciton to cancel the existing orders in the same market. Intended use is to auto-cancel TP/SL orders when closing a position
* @param cancelExistingOrders - Builds and returns an extra transaciton to cancel the existing orders in the same perp market. Intended use is to auto-cancel TP/SL orders when closing a position. Ignored if orderParams.marketType is not MarketType.PERP
* @returns
*/
public async sendMarketOrderAndGetSignedFillTx(
Expand Down Expand Up @@ -2491,7 +2491,7 @@ export class DriftClient {

let cancelOrdersIx: TransactionInstruction;
let cancelExistingOrdersTx: Transaction;
if (cancelExistingOrders) {
if (cancelExistingOrders && isVariant(orderParams.marketType, 'perp')) {
cancelOrdersIx = await this.getCancelOrdersIx(
orderParams.marketType,
orderParams.marketIndex,
Expand Down Expand Up @@ -2896,7 +2896,8 @@ export class DriftClient {

let readablePerpMarketIndex = undefined;
let readableSpotMarketIndexes = undefined;
if (marketIndex) {

if (typeof marketIndex === 'number') {
if (marketType && isVariant(marketType, 'perp')) {
readablePerpMarketIndex = marketIndex;
} else if (marketType && isVariant(marketType, 'spot')) {
Expand Down Expand Up @@ -3736,7 +3737,7 @@ export class DriftClient {
if (!quote) {
throw new Error("Could not fetch Jupiter's quote. Please try again.");
}

const transaction = await jupiterClient.getSwap({
quote,
userPublicKey: this.provider.wallet.publicKey,
Expand Down

0 comments on commit 340ec36

Please sign in to comment.