Skip to content

loki128/asgard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

ASGARD

Autonomous AI Trading Agent for Prediction Markets

A production trading system that scans 2,000+ markets on Polymarket, runs multi-LLM analysis, detects cross-platform arbitrage, and executes trades with 5-layer risk management — all through a Discord interface.

16,000+ lines of Python. Built solo. Source is private.

Python Discord Claude Polymarket


Note: This is a showcase repository. The source code is private. This README documents the architecture, capabilities, and design decisions.


What It Does

ASGARD is an autonomous prediction market trading agent. You interact with it through Discord slash commands. It scans markets, researches fundamentals, calculates edges, and manages a portfolio of positions with real money on the line.

It doesn't just give you picks. It tells you why, scores its own confidence, tracks whether it was right, and adjusts its strategy over time.


Architecture

┌─────────────────────────────────────────────────────┐
│                   DISCORD INTERFACE                   │
│   13 slash commands · 4-tier permissions · embeds     │
└──────────────────────┬──────────────────────────────┘
                       │
        ┌──────────────┼──────────────┐
        ▼              ▼              ▼
┌──────────────┐ ┌──────────┐ ┌──────────────┐
│  MARKET      │ │ WEATHER  │ │    NEWS      │
│  SCANNER     │ │ ENGINE   │ │  VELOCITY    │
│              │ │          │ │              │
│ 2000+ mkts  │ │ NWS API  │ │ 60s polling  │
│ Firecrawl   │ │ CDF calc │ │ Tavily+Claude│
│ gamma-api   │ │ bracket  │ │ dislocation  │
│ keyword     │ │ pricing  │ │ detection    │
└──────┬───────┘ └────┬─────┘ └──────┬───────┘
       │              │              │
       └──────────────┼──────────────┘
                      ▼
       ┌──────────────────────────────┐
       │      MULTI-LLM PIPELINE      │
       │                              │
       │  Stage 1: Ollama (local)     │
       │  → Pre-filter, classify      │
       │  → Cost: $0 per market       │
       │                              │
       │  Stage 2: Claude (cloud)     │
       │  → Deep analysis, scoring    │
       │  → Only high-signal markets  │
       │                              │
       │  Anti-hallucination guards   │
       │  Date verification           │
       │  Evidence requirements       │
       └──────────────┬───────────────┘
                      ▼
       ┌──────────────────────────────┐
       │     5-LAYER RISK ENGINE      │
       │                              │
       │  1. Circuit breaker          │
       │  2. Position sizing          │
       │  3. Stop loss / take profit  │
       │  4. Volatility gate          │
       │  5. Portfolio exposure cap   │
       └──────────────┬───────────────┘
                      ▼
       ┌──────────────────────────────┐
       │      ORDER EXECUTION         │
       │                              │
       │  Polymarket CLOB API         │
       │  Stale price guard (3%)      │
       │  Confirmation flow           │
       │  30-second timeout           │
       └──────────────────────────────┘

Key Systems

Multi-LLM Pipeline

Local Ollama (qwen2.5) pre-filters markets before Claude does deep analysis. 90% of markets get rejected at the cheap stage. Only high-signal opportunities reach the expensive model. Same cost optimization pattern used by production AI companies.

MIMIR Memory

Episodic + semantic memory system. The bot remembers every market it scanned, every trade it made, every strategy that worked or failed. Temporal supersession chains ensure newer information overrides stale data. Built on SQLite with HNSW vector search.

Weather Engine

Zero-cost edge detection using NWS (National Weather Service) forecasts. Pulls 7-day forecasts, calculates bracket probabilities using normal distribution CDF, identifies mispriced weather markets on Polymarket. No API costs — NWS data is free.

News Velocity Scanner

Background process polling breaking news every 60 seconds via Tavily. Detects news-price dislocations — when breaking news hasn't been priced into prediction markets yet. Keyword heuristic pre-filter, Claude verification gate.

Cross-Platform Arbitrage (XARB)

Compares prices between Polymarket and Kalshi for the same event. When the price gap exceeds a threshold, it flags the opportunity. The Peru election trade was sourced this way — 13% price gap between platforms.


Strategies

Strategy Description Edge Source
XARB Cross-platform arbitrage (Polymarket vs Kalshi) Price divergence
THETA Time decay plays with known catalysts Calendar events
BIAS Recency bias and anchoring exploitation Behavioral economics
EXTREME VALUE Base rate analysis on mispriced tails Statistical
MOMENTUM Geopolitical catalyst-driven momentum News flow
WEATHER NWS forecast-based edge on weather markets Free data advantage

Discord Commands

Command Description
/scan Scan markets by category with AI analysis
/weather Run NWS weather engine on temperature markets
/velocity Check breaking news velocity signals
/picks Get AI-scored trading recommendations
/analyze Deep-dive analysis on a specific market
/live-trade Execute a real trade on Polymarket
/paper-trade Execute a paper (simulated) trade
/auto-trade Toggle autonomous trading mode
/wallet Check Polymarket wallet balance
/portfolio View open positions and P&L
/pnl Detailed profit & loss breakdown
/whales Track large-position whale activity
/status System health and configuration

Risk Management

Every trade passes through a 7-step validation before execution:

  1. Edge threshold — minimum required edge before entry
  2. Position limits — max size per trade, per tier
  3. Circuit breaker — blocks trading after consecutive losses
  4. Stale price guard — re-fetches price before execution, aborts on 3%+ drift
  5. Duplicate check — prevents opening the same position twice
  6. Exposure cap — maximum total portfolio exposure
  7. Credential verification — confirms wallet connectivity before every trade

Stats

Metric Value
Lines of Code 16,000+
Source Files 16
Discord Commands 13
Trading Strategies 6
Safety Checks 7
Markets Scanned 2,000+ per run
Permission Tiers 4 (Owner → Admin → Trader → Viewer)

Why Private?

This system trades real money. The source code contains:

  • Trading strategies and edge calculations
  • Risk parameters and position sizing logic
  • API integration details
  • Memory architecture specifics

Making it public would eliminate the trading edge. The architecture and design decisions are shared here for portfolio purposes.


Built By

Karim Lukita — One-person product studio. SaaS platforms, trading bots, AI tools, games. Design to deployment, shipped fast.

Portfolio GitHub LinkedIn

About

Autonomous AI trading agent for prediction markets. Multi-LLM pipeline, MIMIR episodic memory, 5-layer risk management, live execution on Polymarket. 16K+ lines. Private source — showcase only.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors