Skip to Content
DevelopersMarket MakersBot Architecture Patterns

Bot Architecture Patterns

These patterns are used across keeper-bots (market making, fillers, triggers), and can potentially be useful to copy.

Subscription loop + resubscribe

const orderSubscriber = new OrderSubscriber({ driftClient, subscriptionConfig: { type: "websocket", resubTimeoutMs: 30_000, resyncIntervalMs: 300_000, }, }); await orderSubscriber.subscribe();

Periodic tasks + mutex guard

if (await tryAcquire(periodicTaskMutex)) { try { // refresh quotes, run risk checks, rebalance } finally { // update watchdog timestamp } }

Throttling / backoff

const lastAttempt = throttledNodes.get(nodeKey) ?? 0; if (lastAttempt + 1000 > Date.now()) return; throttledNodes.set(nodeKey, Date.now());

Priority fees and tx sending

const priorityFee = priorityFeeSubscriber.getCustomStrategyResult(); const ix = ComputeBudgetProgram.setComputeUnitPrice({ microLamports: Math.floor(priorityFee * driftClient.txSender.getSuggestedPriorityFeeMultiplier()), });

ALT and blockhash lifecycle

const lookupTableAccounts = await driftClient.fetchAllLookupTableAccounts(); const { blockhash } = await driftClient.connection.getLatestBlockhash({ commitment: "confirmed", });
Last updated on