TweetStream

Polymarket Trading Bot: Real-Time X Alerts

Build a Polymarket trading bot that reacts to selected X and Truth Social posts, then prove the complete workflow locally with fixtures before risking capital.

Start 3-day trial

3 days · 5 accounts · 1 WebSocket · Card trial or $5 stablecoin deposit · Minimum is $199/mo after trial

View docs

Published July 13, 2026 · Updated August 6, 2026

Direct answer

Use TweetStream for selected X and supported Truth Social events, use official Polymarket interfaces for market data and execution, and put deterministic mapping, freshness, deduplication, position limits, and a kill switch between them. The included fixture runner demonstrates the decision path without placing a trade.

Catch the catalyst before the odds finish moving

Odds move when new information reaches the market. TweetStream gets selected X and supported Truth Social posts into your strategy, while the official Polymarket interface supplies prices and execution. Keep those boundaries separate, then optimize the path from source post to risk-approved order.

  • Polymarket API: markets, odds, liquidity, positions, and orders
  • TweetStream: selected X and supported Truth Social posts
  • Strategy service: source mapping, classification, confidence, and risk
  • Execution service: order construction, limits, idempotency, and reconciliation

Map every market to its decisive sources

Build a source map for each market before writing keyword rules. If a market resolves from an agency announcement, track the agency and responsible officials. If it resolves from a company action, track the company, executives, and primary reporters. For political markets, include supported Trump and White House Truth Social posts where relevant.

  • Store market id, resolution criteria, source handles, keywords, and expiry together
  • Rank first-party sources above commentary accounts
  • Use author identity and post time before interpreting text
  • Expire mappings as soon as the market closes or the thesis changes

Turn the live feed into one inspectable decision path

Open one TweetStream WebSocket, route content events by author, and join matching posts to live venue markets. The first pass should be deterministic: source match, evidence term, market open, event fresh, and not previously processed. The maintained example demonstrates this locally for both Polymarket and Kalshi without placing an order.

  • Authenticate with the TweetStream v1 WebSocket subprotocol
  • Persist event ids before producing any trade side effect
  • Use OCR text when market-moving details are published in an image
  • Consume enrichment events without delaying the first content decision unnecessarily

Turn the post into a bounded decision

Classification should produce a small decision object, not a free-form opinion: market id, implied direction, confidence, evidence span, event timestamp, and expiry. That makes risk rules inspectable and prevents a language model from becoming the execution policy.

  • Reject posts that do not map to explicit resolution criteria
  • Require stronger confidence as liquidity falls or spread widens
  • Set a maximum event age and maximum odds movement before entry
  • Route ambiguous events to a human desk instead of forcing a trade

Use an AI coding agent without giving it the keys

Use a coding agent to build the adapter; use a Polymarket agent framework to orchestrate narrow tools, not control capital. The framework should consume typed market reads and produce paper-only intents. Deterministic code should verify source identity, market state, freshness, liquidity, exposure, and order idempotency before any execution client is called.

  • Use Claude Code, Codex, Cursor, or another coding agent to adapt the maintained fixture-backed example
  • Expose narrow tools for market reads and paper intents instead of unrestricted exchange access
  • Require schema-validated decisions with evidence spans, confidence, and expiry
  • Keep API credentials, maximum loss, and the kill switch outside the agent runtime

Measure signal-to-fill, not one vendor number

A fast alert is valuable only if the rest of the path is measured. Record source-post timestamp, TweetStream arrival, classifier completion, order submission, exchange acknowledgement, and fill. TweetStream publishes 167ms median server detection; test your own watchlist because the end-to-end path still includes network, processing, and venue execution.

Prove the strategy before giving it capital

Before live trading, replay captured events against historical market snapshots, then shadow the production feed without placing orders. Promote only strategies whose source mappings, stale-event rules, and loss limits survive both paths.

  • Backtest market mapping and classifier direction separately
  • Shadow live events and compare theoretical versus executable prices
  • Start with hard position and daily-loss limits
  • Keep a kill switch outside the classifier and execution worker

Implementation asset: prediction-market source router

Turn validated X and supported Truth Social events into typed, venue-neutral routing decisions. Adapt the source list, market mapping, and keyword rules to your strategy, then keep duplicate, stale-event, position-limit, credential, and execution controls in deterministic code around this pattern.

ts
type SocialPlatform = "twitter" | "truth_social";
 
type TweetStreamContentEvent = {
  d: {
    author: { handle?: string; platform: SocialPlatform };
    createdAt: number;
    kind: "post" | "quote" | "reply" | "retweet";
    text: string;
    tweetId: string;
  };
  id?: string;
  op: "content";
  t: "tweet";
  ts: number;
  v: 1;
};
 
const sourceRules = [
  {
    handles: ["whitehouse", "potus"],
    platform: "twitter",
    strategy: "policy-markets",
    terms: ["executive order", "tariff"],
    venue: "polymarket",
  },
  {
    handles: ["realdonaldtrump"],
    platform: "truth_social",
    strategy: "trade-policy",
    terms: ["trade policy", "announcement"],
    venue: "kalshi",
  },
] as const;
 
export function routePredictionMarketSourceEvent(event: TweetStreamContentEvent) {
  const handle = event.d.author.handle?.toLowerCase().replace(/^@/, "");
  const platform = event.d.author.platform;
  const text = event.d.text.toLowerCase();
  const rule = sourceRules.find(
    (candidate) =>
      candidate.platform === platform &&
      candidate.handles.some((candidateHandle) => candidateHandle === handle),
  );
  const matchedTerm = rule?.terms.find((term) => text.includes(term));
 
  if (!rule || !matchedTerm) {
    return { deliver: false } as const;
  }
 
  return {
    deliver: true,
    eventId: event.d.tweetId,
    matchedTerm,
    strategy: rule.strategy,
    venue: rule.venue,
  } as const;
}

Why implement this with TweetStream

You can build this workflow from raw APIs, polling, and custom scraping, but TweetStream is the better starting point when speed, delete/pin alerts, profile/follow signals, token/OCR enrichment, and reliable WebSocket delivery matter. Start the 3-day trial and route your first high-signal accounts into your alerting or trading flow.

Start 3-day trial

Questions

Build on the live feed

Start with the accounts that matter, then route X and Truth Social events into your bots, alerts, and trading workflows.