filter indicative + random prettify (#443)
* filter indicative + random prettify * bug fix * update to filter orders that arent as good as resting orders
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
BN,
|
||||
BigNum,
|
||||
DLOBSubscriber,
|
||||
DLOBSubscriptionConfig,
|
||||
DriftEnv,
|
||||
@@ -11,10 +10,10 @@ import {
|
||||
OrderStatus,
|
||||
OrderTriggerCondition,
|
||||
OrderType,
|
||||
PRICE_PRECISION,
|
||||
PerpOperation,
|
||||
PositionDirection,
|
||||
ZERO,
|
||||
getLimitPrice,
|
||||
isOperationPaused,
|
||||
isVariant,
|
||||
} from '@drift-labs/sdk';
|
||||
@@ -151,10 +150,31 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
||||
|
||||
override async updateDLOB(): Promise<void> {
|
||||
await super.updateDLOB();
|
||||
const dlob = this.getDLOB();
|
||||
let indicativeOrderId = 0;
|
||||
for (const marketArgs of this.marketArgs) {
|
||||
try {
|
||||
if (this.indicativeQuotesRedisClient) {
|
||||
const oraclePriceData = isVariant(marketArgs.marketType, 'perp')
|
||||
? this.driftClient.getOracleDataForPerpMarket(
|
||||
marketArgs.marketIndex
|
||||
)
|
||||
: this.driftClient.getOracleDataForSpotMarket(
|
||||
marketArgs.marketIndex
|
||||
);
|
||||
const bestBid = dlob.getBestBid(
|
||||
marketArgs.marketIndex,
|
||||
this.slotSource.getSlot(),
|
||||
marketArgs.marketType,
|
||||
oraclePriceData
|
||||
);
|
||||
const bestAsk = dlob.getBestAsk(
|
||||
marketArgs.marketIndex,
|
||||
this.slotSource.getSlot(),
|
||||
marketArgs.marketType,
|
||||
oraclePriceData
|
||||
);
|
||||
|
||||
const marketType = isVariant(marketArgs.marketType, 'perp')
|
||||
? 'perp'
|
||||
: 'spot';
|
||||
@@ -208,7 +228,6 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
||||
|
||||
if (quote['bid_size'] && quote['bid_price'] != null) {
|
||||
// Sanity check bid price and size
|
||||
|
||||
const indicativeBid: Order = Object.assign(
|
||||
{},
|
||||
indicativeBaseOrder,
|
||||
@@ -224,15 +243,21 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
||||
direction: PositionDirection.LONG,
|
||||
}
|
||||
);
|
||||
this.dlob.insertOrder(
|
||||
const limitPrice = getLimitPrice(
|
||||
indicativeBid,
|
||||
INDICATIVE_QUOTES_PUBKEY,
|
||||
this.slotSource.getSlot(),
|
||||
false
|
||||
oraclePriceData,
|
||||
this.slotSource.getSlot()
|
||||
);
|
||||
indicativeOrderId += 1;
|
||||
if (limitPrice.lte(bestBid)) {
|
||||
this.dlob.insertOrder(
|
||||
indicativeBid,
|
||||
INDICATIVE_QUOTES_PUBKEY,
|
||||
this.slotSource.getSlot(),
|
||||
false
|
||||
);
|
||||
indicativeOrderId += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (quote['ask_size'] && quote['ask_price'] != null) {
|
||||
const indicativeAsk: Order = Object.assign(
|
||||
{},
|
||||
@@ -249,13 +274,20 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
||||
direction: PositionDirection.SHORT,
|
||||
}
|
||||
);
|
||||
this.dlob.insertOrder(
|
||||
const limitPrice = getLimitPrice(
|
||||
indicativeAsk,
|
||||
INDICATIVE_QUOTES_PUBKEY,
|
||||
this.slotSource.getSlot(),
|
||||
false
|
||||
oraclePriceData,
|
||||
this.slotSource.getSlot()
|
||||
);
|
||||
indicativeOrderId += 1;
|
||||
if (limitPrice.gte(bestAsk)) {
|
||||
this.dlob.insertOrder(
|
||||
indicativeAsk,
|
||||
INDICATIVE_QUOTES_PUBKEY,
|
||||
this.slotSource.getSlot(),
|
||||
false
|
||||
);
|
||||
indicativeOrderId += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,7 +303,7 @@ const initializeAllMarketSubscribers = async (driftClient: DriftClient) => {
|
||||
}
|
||||
}
|
||||
|
||||
markets[market.marketIndex].tickSize = market?.orderTickSize ?? ONE
|
||||
markets[market.marketIndex].tickSize = market?.orderTickSize ?? ONE;
|
||||
}
|
||||
|
||||
return markets;
|
||||
@@ -527,7 +527,7 @@ const main = async () => {
|
||||
killSwitchSlotDiffThreshold: KILLSWITCH_SLOT_DIFF_THRESHOLD,
|
||||
protectedMakerView: false,
|
||||
indicativeQuotesRedisClient: indicativeRedisClient,
|
||||
enableOffloadQueue
|
||||
enableOffloadQueue,
|
||||
});
|
||||
await dlobSubscriberIndicative.subscribe();
|
||||
|
||||
|
||||
@@ -96,7 +96,10 @@ const getRedisChannelFromMessage = (message: any): string => {
|
||||
case 'orderbook':
|
||||
return `orderbook_${marketType}_${marketIndex}`;
|
||||
case 'orderbook_indicative': {
|
||||
if (message.grouping && GROUPING_OPTIONS.includes(parseInt(message.grouping))) {
|
||||
if (
|
||||
message.grouping &&
|
||||
GROUPING_OPTIONS.includes(parseInt(message.grouping))
|
||||
) {
|
||||
return `orderbook_${marketType}_${marketIndex}_grouped_${message.grouping}_indicative`;
|
||||
}
|
||||
return `orderbook_${marketType}_${marketIndex}_indicative`;
|
||||
|
||||
Reference in New Issue
Block a user