Skip to content

Aggregator Bot (Node.js)

This covers the multi-user aggregator-based bot code found typically in index.js (or bot/index.js). It's responsible for:

  • Connecting to InsideX to fetch pools & OHLC data
  • Using Aftermath Finance aggregator for route creation
  • Executing time-based or indicator-based buys & sells
  • Consolidating gas + tokens on Sui

Key Features

  1. Indicators: RSI, Stochastic RSI, or ML signals
  2. DCA Logic: Merge repeated buys into a weighted cost basis
  3. Sui Gas & Token Consolidation
  4. InsideX pool lookups & aggregator routes via Aftermath
  5. Multi-user with saved JSON state

Architecture Overview

  1. Positions stored in-memory & in bot_state.json.
  2. Nginx or Node-based server sees API requests, which call bot logic.
  3. InsideX fetch for newly created tokens & OHLC.
  4. Aftermath aggregator for best route & swap execution.

Example Code Snippet

// aggregator-based logic snippet from index.js
async function tradingBot(userId) {
  // ...
  const route = await getTradeRoute(baseToken, targetToken, buyAmountAtomic, aftermath);
  if (route) {
    await executeSwap(route, suiClient, keypair, gasCoin, config, aftermath, targetToken);
  }
  // ...
}