diff --git a/src/dlob-subscriber/DLOBSubscriberIO.ts b/src/dlob-subscriber/DLOBSubscriberIO.ts index 5acbc7a..0287d78 100644 --- a/src/dlob-subscriber/DLOBSubscriberIO.ts +++ b/src/dlob-subscriber/DLOBSubscriberIO.ts @@ -1,14 +1,17 @@ import { BN, + BigNum, DLOBSubscriber, DLOBSubscriptionConfig, DriftEnv, L2OrderBookGenerator, MarketType, + ONE, Order, OrderStatus, OrderTriggerCondition, OrderType, + PRICE_PRECISION, PerpOperation, PositionDirection, ZERO, @@ -21,6 +24,7 @@ import { SubscriberLookup, addMarketSlotToResponse, addOracletoResponse, + aggregatePrices, l2WithBNToStrings, parsePositiveIntArray, } from '../utils/utils'; @@ -35,10 +39,12 @@ type wsMarketArgs = { numVammOrders?: number; fallbackL2Generators?: L2OrderBookGenerator[]; updateOnChange?: boolean; + tickSize?: BN }; require('dotenv').config(); +export const GROUPING_OPTIONS = [1, 10, 100, 500, 1000]; const PERP_MAKRET_STALENESS_THRESHOLD = 30 * 60 * 1000; const SPOT_MAKRET_STALENESS_THRESHOLD = 60 * 60 * 1000; const STALE_ORACLE_REMOVE_VAMM_THRESHOLD = 160; @@ -114,6 +120,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber { includeVamm, updateOnChange: false, fallbackL2Generators: [], + tickSize: perpMarket?.amm?.orderTickSize ?? ONE }); } for (const market of config.spotMarketInfos) { @@ -128,6 +135,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber { config.spotMarketSubscribers[market.marketIndex].phoenix, config.spotMarketSubscribers[market.marketIndex].openbook, ].filter((a) => !!a), + tickSize: config.spotMarketSubscribers[market.marketIndex].tickSize ?? ONE }); } } @@ -391,6 +399,30 @@ export class DLOBSubscriberIO extends DLOBSubscriber { }`, l2Formatted_depth100 ); + + GROUPING_OPTIONS.forEach(group => { + const pricePrecision = BigNum.from(group).mul(marketArgs.tickSize).toNum() + const aggregatedBids = aggregatePrices(l2Formatted.bids, 'bid', pricePrecision) + .sort((a, b) => b[0] - a[0]) + .slice(0, 20) + + const aggregatedAsks = aggregatePrices(l2Formatted.asks, 'ask', pricePrecision) + .sort((a, b) => a[0] - b[0]) + .slice(0, 20) + + const l2Formatted_grouped20 = Object.assign({}, l2Formatted, { + bids: aggregatedBids, + asks: aggregatedAsks, + }); + + this.redisClient.publish( + `${clientPrefix}orderbook_${marketType}_${marketArgs.marketIndex}_grouped_${group}${ + this.indicativeQuotesRedisClient ? '_indicative' : '' + }`, + l2Formatted_grouped20 + ); + }) + if (!this.indicativeQuotesRedisClient) { const bids = this.dlob diff --git a/src/publishers/dlobPublisher.ts b/src/publishers/dlobPublisher.ts index 2432be0..694b457 100644 --- a/src/publishers/dlobPublisher.ts +++ b/src/publishers/dlobPublisher.ts @@ -20,6 +20,7 @@ import { PhoenixSubscriber, MarketType, OraclePriceData, + ONE, } from '@drift-labs/sdk'; import { RedisClient, RedisClientPrefix } from '@drift/common/clients'; @@ -114,10 +115,7 @@ const KILLSWITCH_SLOT_DIFF_THRESHOLD = parseInt(process.env.KILLSWITCH_SLOT_DIFF_THRESHOLD) || 200; // comma separated list of perp market indexes to load: i.e. 0,1,2,3 -const PERP_MARKETS_TO_LOAD = - process.env.PERP_MARKETS_TO_LOAD !== undefined - ? parsePositiveIntArray(process.env.PERP_MARKETS_TO_LOAD) - : undefined; +const PERP_MARKETS_TO_LOAD = [0] // comma separated list of spot market indexes to load: i.e. 0,1,2,3 const SPOT_MARKETS_TO_LOAD = @@ -299,6 +297,8 @@ const initializeAllMarketSubscribers = async (driftClient: DriftClient) => { } } } + + markets[market.marketIndex].tickSize = market?.orderTickSize ?? ONE } return markets; diff --git a/src/templates/full.html b/src/templates/full.html new file mode 100644 index 0000000..ae8c50c --- /dev/null +++ b/src/templates/full.html @@ -0,0 +1,787 @@ + + +
+ + +