Skip to content

Commit ae9510a

Browse files
authored
ts: sniper checks limit price (#29)
* ts: sniper checks limit price * tweak auction duration
1 parent 7f138ac commit ae9510a

File tree

3 files changed

+65
-39
lines changed

3 files changed

+65
-39
lines changed

ts/sdk/src/jitter/baseJitter.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,10 @@ export abstract class BaseJitter {
6868
this.jitProxyClient = jitProxyClient;
6969
this.userStatsMap =
7070
userStatsMap ||
71-
new UserStatsMap(this.driftClient, new BulkAccountLoader(
72-
this.driftClient.connection,
73-
'confirmed',
74-
0
75-
));
71+
new UserStatsMap(
72+
this.driftClient,
73+
new BulkAccountLoader(this.driftClient.connection, 'confirmed', 0)
74+
);
7675
}
7776

7877
async subscribe(): Promise<void> {

ts/sdk/src/jitter/jitterShotgun.ts

+17-14
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,23 @@ export class JitterShotgun extends BaseJitter {
7373

7474
console.log(`Trying to fill ${orderSignature}`);
7575
try {
76-
const { txSig } = await this.jitProxyClient.jit({
77-
takerKey,
78-
takerStatsKey,
79-
taker,
80-
takerOrderId: order.orderId,
81-
maxPosition: params.maxPosition,
82-
minPosition: params.minPosition,
83-
bid: params.bid,
84-
ask: params.ask,
85-
postOnly: null,
86-
priceType: params.priceType,
87-
referrerInfo,
88-
subAccountId: params.subAccountId,
89-
}, txParams);
76+
const { txSig } = await this.jitProxyClient.jit(
77+
{
78+
takerKey,
79+
takerStatsKey,
80+
taker,
81+
takerOrderId: order.orderId,
82+
maxPosition: params.maxPosition,
83+
minPosition: params.minPosition,
84+
bid: params.bid,
85+
ask: params.ask,
86+
postOnly: null,
87+
priceType: params.priceType,
88+
referrerInfo,
89+
subAccountId: params.subAccountId,
90+
},
91+
txParams
92+
);
9093

9194
console.log(`Filled ${orderSignature} txSig ${txSig}`);
9295
await sleep(10000);

ts/sdk/src/jitter/jitterSniper.ts

+44-20
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
DriftClient,
77
getAuctionPrice,
88
getAuctionPriceForOracleOffsetAuction,
9+
getLimitPrice,
910
getVariant,
1011
isVariant,
1112
OraclePriceData,
@@ -191,21 +192,24 @@ export class JitterSniper extends BaseJitter {
191192
const txParams = {
192193
computeUnits: this.computeUnits,
193194
computeUnitsPrice: this.computeUnitsPrice,
194-
}
195-
const { txSig } = await this.jitProxyClient.jit({
196-
takerKey,
197-
takerStatsKey,
198-
taker,
199-
takerOrderId: order.orderId,
200-
maxPosition: params.maxPosition,
201-
minPosition: params.minPosition,
202-
bid: params.bid,
203-
ask: params.ask,
204-
postOnly: null,
205-
priceType: params.priceType,
206-
referrerInfo,
207-
subAccountId: params.subAccountId,
208-
}, txParams);
195+
};
196+
const { txSig } = await this.jitProxyClient.jit(
197+
{
198+
takerKey,
199+
takerStatsKey,
200+
taker,
201+
takerOrderId: order.orderId,
202+
maxPosition: params.maxPosition,
203+
minPosition: params.minPosition,
204+
bid: params.bid,
205+
ask: params.ask,
206+
postOnly: null,
207+
priceType: params.priceType,
208+
referrerInfo,
209+
subAccountId: params.subAccountId,
210+
},
211+
txParams
212+
);
209213

210214
console.log(`Filled ${orderSignature} txSig ${txSig}`);
211215
await sleep(3000);
@@ -308,6 +312,25 @@ export class JitterSniper extends BaseJitter {
308312
slotsTilCross++;
309313
}
310314

315+
// if it doesnt cross during auction, check if limit price crosses
316+
if (!willCross) {
317+
const slotAfterAuction = order.slot.toNumber() + order.auctionDuration + 1;
318+
const limitPrice = getLimitPrice(order, oraclePrice, slotAfterAuction);
319+
if (!limitPrice) {
320+
willCross = true;
321+
slotsTilCross = order.auctionDuration + 1;
322+
} else {
323+
const limitPriceNum = convertToNumber(limitPrice, PRICE_PRECISION);
324+
if (makerOrderDir === 'buy' || limitPriceNum <= bid) {
325+
willCross = true;
326+
slotsTilCross = order.auctionDuration + 1;
327+
} else if (makerOrderDir === 'sell' || limitPriceNum >= ask) {
328+
willCross = true;
329+
slotsTilCross = order.auctionDuration + 1;
330+
}
331+
}
332+
}
333+
311334
return {
312335
slotsTilCross,
313336
willCross,
@@ -325,12 +348,12 @@ export class JitterSniper extends BaseJitter {
325348
order: Order,
326349
initialDetails: AuctionAndOrderDetails
327350
): Promise<{ slot: number; updatedDetails: AuctionAndOrderDetails }> {
328-
const auctionEndSlot = order.auctionDuration + order.slot.toNumber();
329351
let currentDetails: AuctionAndOrderDetails = initialDetails;
330352
let willCross = initialDetails.willCross;
331-
if (this.slotSubscriber.currentSlot > auctionEndSlot) {
353+
if (this.slotSubscriber.currentSlot > targetSlot) {
354+
const slot = willCross ? this.slotSubscriber.currentSlot : -1;
332355
return new Promise((resolve) =>
333-
resolve({ slot: -1, updatedDetails: currentDetails })
356+
resolve({ slot, updatedDetails: currentDetails })
334357
);
335358
}
336359

@@ -348,13 +371,14 @@ export class JitterSniper extends BaseJitter {
348371

349372
// Update target slot as the bid/ask and the oracle changes
350373
const intervalId = setInterval(async () => {
351-
if (this.slotSubscriber.currentSlot >= auctionEndSlot) {
374+
if (this.slotSubscriber.currentSlot >= targetSlot) {
352375
this.slotSubscriber.eventEmitter.removeListener(
353376
'newSlot',
354377
slotListener
355378
);
356379
clearInterval(intervalId);
357-
resolve({ slot: -1, updatedDetails: currentDetails });
380+
const slot = willCross ? this.slotSubscriber.currentSlot : -1;
381+
resolve({ slot, updatedDetails: currentDetails });
358382
}
359383

360384
currentDetails = this.getAuctionAndOrderDetails(order);

0 commit comments

Comments
 (0)