Skip to content

Commit

Permalink
ts: add seenOrders to jitter to avoid queuing 2 of the same orders
Browse files Browse the repository at this point in the history
  • Loading branch information
crispheaney committed Jan 24, 2024
1 parent 64e874b commit fd7cb35
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
11 changes: 11 additions & 0 deletions ts/sdk/src/jitter/baseJitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export abstract class BaseJitter {
perpParams = new Map<number, JitParams>();
spotParams = new Map<number, JitParams>();

seenOrders = new Set<string>();
onGoingAuctions = new Map<string, Promise<void>>();

userFilter: UserFilter;
Expand Down Expand Up @@ -107,6 +108,11 @@ export abstract class BaseJitter {
order.orderId
);

if (this.seenOrders.has(orderSignature)) {
continue;
}
this.seenOrders.add(orderSignature);

if (this.onGoingAuctions.has(orderSignature)) {
continue;
}
Expand Down Expand Up @@ -175,6 +181,11 @@ export abstract class BaseJitter {
throw new Error('Not implemented');
}

deleteOnGoingAuction(orderSignature: string): void {
this.onGoingAuctions.delete(orderSignature);
this.seenOrders.delete(orderSignature);
}

getOrderSignatures(takerKey: string, orderId: number): string {
return `${takerKey}-${orderId}`;
}
Expand Down
8 changes: 4 additions & 4 deletions ts/sdk/src/jitter/jitterShotgun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class JitterShotgun extends BaseJitter {
while (i < 10) {
const params = this.perpParams.get(order.marketIndex);
if (!params) {
this.onGoingAuctions.delete(orderSignature);
this.deleteOnGoingAuction(orderSignature);
return;
}

Expand Down Expand Up @@ -90,7 +90,7 @@ export class JitterShotgun extends BaseJitter {

console.log(`Filled ${orderSignature} txSig ${txSig}`);
await sleep(10000);
this.onGoingAuctions.delete(orderSignature);
this.deleteOnGoingAuction(orderSignature);
return;
} catch (e) {
console.error(`Failed to fill ${orderSignature}`);
Expand All @@ -102,15 +102,15 @@ export class JitterShotgun extends BaseJitter {
console.log('Oracle invalid, retrying');
} else {
await sleep(10000);
this.onGoingAuctions.delete(orderSignature);
this.deleteOnGoingAuction(orderSignature);
return;
}
}
await sleep(200);
i++;
}

this.onGoingAuctions.delete(orderSignature);
this.deleteOnGoingAuction(orderSignature);
};
}
}
Expand Down
14 changes: 7 additions & 7 deletions ts/sdk/src/jitter/jitterSniper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class JitterSniper extends BaseJitter {
return async () => {
const params = this.perpParams.get(order.marketIndex);
if (!params) {
this.onGoingAuctions.delete(orderSignature);
this.deleteOnGoingAuction(orderSignature);
return;
}

Expand Down Expand Up @@ -100,7 +100,7 @@ export class JitterSniper extends BaseJitter {
order.marketType
)}-${order.marketIndex}) too much`
);
this.onGoingAuctions.delete(orderSignature);
this.deleteOnGoingAuction(orderSignature);
return;
}
} else if (
Expand All @@ -113,7 +113,7 @@ export class JitterSniper extends BaseJitter {
order.marketType
)}-${order.marketIndex}) too much`
);
this.onGoingAuctions.delete(orderSignature);
this.deleteOnGoingAuction(orderSignature);
return;
}
}
Expand Down Expand Up @@ -152,7 +152,7 @@ export class JitterSniper extends BaseJitter {
).then(async ({ slot, updatedDetails }) => {
if (slot === -1) {
console.log('Auction expired without crossing');
this.onGoingAuctions.delete(orderSignature);
this.deleteOnGoingAuction(orderSignature);
return;
}

Expand Down Expand Up @@ -209,7 +209,7 @@ export class JitterSniper extends BaseJitter {

console.log(`Filled ${orderSignature} txSig ${txSig}`);
await sleep(3000);
this.onGoingAuctions.delete(orderSignature);
this.deleteOnGoingAuction(orderSignature);
return;
} catch (e) {
console.error(`Failed to fill ${orderSignature}`);
Expand All @@ -221,15 +221,15 @@ export class JitterSniper extends BaseJitter {
console.log('Oracle invalid');
} else {
await sleep(3000);
this.onGoingAuctions.delete(orderSignature);
this.deleteOnGoingAuction(orderSignature);
return;
}
}
await sleep(200);
i++;
}
});
this.onGoingAuctions.delete(orderSignature);
this.deleteOnGoingAuction(orderSignature);
};
}

Expand Down

0 comments on commit fd7cb35

Please sign in to comment.