Hydra
Docs

How to extend and customise the Hydra Polymarket bot.

Customising the Bot

The bot is designed to be extended. The core infrastructure is fixed — connection, market discovery, order routing. Everything else is pluggable.

Configuration File

Most behaviour is controlled via config/strategy.ts:

export const strategy: StrategyConfig = {
  // Signal filtering
  minSeverity: 3,              // ignore signals below this severity
  categories: [                // only process these signal categories
    'MISSILE_ALERT',
    'NAVAL',
    'FORCE_DEPLOYMENT',
    'CYBER',
  ],

  // Correlation
  correlationThreshold: 0.65,  // min score to act on a market
  maxMarketsPerSignal: 3,      // limit markets acted on per signal

  // Position sizing
  maxPositionUsd: 100,         // maximum stake per trade
  kellyFraction: 0.25,         // fraction of Kelly criterion
  minEdge: 0.04,               // minimum perceived edge to place order (4%)

  // Risk
  maxOpenPositions: 10,        // maximum concurrent open positions
  maxDailyLossUsd: 500,        // halt trading if daily loss exceeds this
  skipMarketsResolvingWithin: 24 * 60 * 60 * 1000,  // skip markets resolving < 24h

  // Execution
  orderType: 'limit',          // 'limit' | 'market'
  limitSlippagePct: 0.02,      // limit order placed 2% better than mid
}

Custom Signal Filters

Add pre-processing logic before signals reach the correlation engine:

// src/filters/my-filter.ts
import type { SignalFilter } from 'hydra-bot'

export const geographicFilter: SignalFilter = (signal) => {
  // Only care about Middle East events
  if (!signal.tags.some(t => MIDDLE_EAST_TAGS.includes(t))) return null
  return signal
}

Chain multiple filters:

const bot = new HydraBot({
  filters: [geographicFilter, severityFilter, categoryFilter],
})

Custom Position Sizing

Replace the default Kelly sizer:

import type { PositionSizer } from 'hydra-bot'

export const flatSizer: PositionSizer = ({ signal, market, correlation }) => {
  // Flat $25 on all trades with high correlation
  if (correlation.correlationScore > 0.85) return 25
  return 0  // skip
}

const bot = new HydraBot({ positionSizer: flatSizer })

Hooking Into Events

The bot emits events you can listen to without modifying core logic:

const bot = new HydraBot(config)

bot.on('signal', (signal) => {
  console.log('Signal received:', signal.title)
})

bot.on('correlation', (result) => {
  console.log('Correlated market:', result.market.question, result.correlationScore)
})

bot.on('order:placed', (order) => {
  // Send to Telegram, Discord, etc.
  notify(`Placed ${order.side} ${order.size} on ${order.market.question}`)
})

bot.on('order:filled', (fill) => {
  console.log('Filled at', fill.price)
})

bot.on('position:closed', (result) => {
  console.log('PnL:', result.pnlUsd)
})

Example — Discord Alerts Only (No Trading)

Use the bot purely for alerts without enabling order execution:

const bot = new HydraBot({
  ...config,
  dryRun: true,
  onCorrelation: async (result) => {
    if (result.correlationScore > 0.8) {
      await discord.send(
        `🔴 **Signal → Market**\n` +
        `Signal: ${result.signal.title} (severity ${result.signal.severity})\n` +
        `Market: ${result.market.question}\n` +
        `Current price: ${result.market.outcomes[0].price}\n` +
        `Correlation: ${(result.correlationScore * 100).toFixed(0)}%`
      )
    }
  }
})

bot.start()