https://github.com/abouvel/polymarket-firstmoverstrategy

https://github.com/abouvel/polymarket-firstmoverstrategy

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (8.6%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Basic Info
  • Host: GitHub
  • Owner: abouvel
  • Language: TypeScript
  • Default Branch: main
  • Size: 126 MB
Statistics
  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created about 1 year ago · Last pushed 11 months ago
Metadata Files
Readme

README.md

AI-Powered Polymarket Trading Bot

An AI trading system that monitors Twitter for market-relevant content, processes it through an AI pipeline, and executes automated trades on Polymarket based on LLM analysis. I chose polymarket over the stock market due to a lack of traditional players, and subsequently higher inefficiencies.

image Real-time dashboard showing live tweet monitoring and trading activity

What This Project Does

This system combines social media monitoring, AI analysis, and automated trading:

  1. Twitter Monitoring: Scrapes Twitter content from specified accounts using browser automation
  2. AI Content Analysis: Processes tweets through a LangGraph pipeline with web search and market relevance analysis
  3. Vector Search Matching: Uses ChromaDB to find relevant prediction markets based on tweet content similarity
  4. Automated Trading: Makes trading decisions using LLaMA 3.2 and executes trades on Polymarket
  5. Real-time Price Tracking: Maintains current bid/ask prices via WebSocket connections

System Architecture

Data Flow

Twitter → driver.py → FastAPI Webhook → ChromaDB Storage ↓ ChromaDB → LangGraph Pipeline → Market Analysis → Trade Execution ↓ ↓ Web Search Enhancement PostgreSQL Logging

Core Components

  1. driver.py: Twitter scraper using Chrome automation
  2. twitterWebhook.py: FastAPI server handling tweet ingestion
  3. langgraphPipe.py: AI analysis pipeline with structured outputs
  4. websocketPoly.py: Real-time market price monitoring

AI Pipeline Steps

  1. Content Enrichment: Web search via Tavily API
  2. Vector Similarity: ChromaDB semantic matching
  3. Market Analysis: LLM-based relevance scoring
  4. Trade Decision: Structured output with reasoning
  5. Significance Check: Evaluates potential for >5% price movement
  6. Execution Logging: PostgreSQL trade records

Tech Stack

AI & Machine Learning

  • LangGraph: Multi-step AI workflow orchestration
  • LangChain: LLM framework and integrations
  • Ollama: Local LLM inference (LLaMA 3.2)
  • HuggingFace Transformers: Text embeddings (all-MiniLM-L6-v2)
  • ChromaDB: Vector database for semantic search

Backend & APIs

  • FastAPI: High-performance webhook server
  • PostgreSQL: Structured data storage (markets, trades)
  • Tavily: Web search enrichment API
  • Polymarket API: Trading execution and market data

Automation & Frontend

  • nodriver: Chrome browser automation for Twitter scraping
  • WebSockets: Real-time Polymarket price feeds
  • Next.js: React-based dashboard framework
  • TypeScript: Type-safe frontend development
  • Docker Compose: Multi-service orchestration

Frontend Dashboard

Real-time Next.js dashboard with comprehensive monitoring capabilities:

  • Live Tweet Monitoring: Real-time display of incoming tweets
  • Trading Activity Tracking: Visualization of executed and skipped trades
  • Connection Status: Live backend connectivity indicator
  • Real-time Updates: Server-Sent Events (SSE) for instant data streaming

Access Points:

Vector Embedding Visualization

  • https://www.youtube.com/watch?v=6-y4AuxsqeA

How to Run

Environment Setup

  1. Clone and navigate to the project:

bash

git clone <repository-url> cd polyAi/src/backend/expStuff

  1. Create environment file:

bash

cp .env.example .env

  1. Configure your .env file:

env

```

Database Configuration

POSTGRESUSER=yourpostgresuser POSTGRESPASSWORD=yoursecurepassword POSTGRESHOST=localhost POSTGRESPORT=5431 POSTGRESDB=polymarkettrading

API Keys

TAVILYAPIKEY=yourtavilyapikey POLYKEY=yourpolymarketapikey POLYADDRESS=yourpolymarketwallet_address

WebSocket Authentication

APIKEY=yourwebsocketapikey APISECRET=yourwebsocketsecret APIPASSPHRASE=yourwebsocketpassphrase ```

Start the Application

bash

docker-compose up --build

This will automatically start all services and launch the dashboard at http://localhost:3000.

Service Management

bash

```

View service status

docker-compose ps

Check logs

docker-compose logs -f [service-name]

Stop services

docker-compose down ```

Configuration Options

Monitored Twitter Users

Edit MONITORED_USERS in driver.py:

python

MONITORED_USERS = ["username1", "username2", "username3"]

Polling Frequency

Adjust POLL_INTERVAL in driver.py:

python

POLL_INTERVAL = 10 # seconds between Twitter checks

Model Configuration

Modify AI model in langgraphPipe.py:

python

llm = ChatOllama( model="llama3.2:latest", temperature=0, base_url="http://ollama:11434" )

Database Operations

Connect to PostgreSQL

bash

psql -h localhost -p 5431 -U ${POSTGRES_USER} -d ${POSTGRES_DB}

Database Schema

  • markets: Prediction market metadata
  • tokens: Market outcome tokens with pricing data
  • bought: Trade execution log with tweet references

Monitoring & Debugging

API Endpoints

  • Health Check: GET http://localhost:8000/db
  • Tweet IDs: GET http://localhost:8000/tweet-ids
  • Market Data: POST http://localhost:8000/poly

Data Persistence

  • PostgreSQL: ./backend_pgdata/ volume
  • ChromaDB: ./chroma/ directory
  • Ollama Models: ollama_data volume
  • HuggingFace Cache: huggingface_cache volume

Development Challenges

Browser Automation & Anti-Bot Detection

Twitter's anti-bot measures required implementing advanced stealth

Owner

  • Login: abouvel
  • Kind: user

GitHub Events

Total
  • Public event: 1
  • Push event: 9
Last Year
  • Public event: 1
  • Push event: 9

Dependencies

docker-compose.yml docker
  • node 18-alpine
  • ollama/ollama latest
  • polyai-app latest
  • postgres 13
pnpm-lock.yaml npm
requirements.txt pypi
  • Deprecated ==1.2.18
  • Flask ==3.1.1
  • Flask-SocketIO ==5.5.1
  • GitPython ==3.1.44
  • Jinja2 ==3.1.6
  • MarkupSafe ==3.0.2
  • PyPika ==0.48.9
  • PySocks ==1.7.1
  • PyYAML ==6.0.2
  • Pygments ==2.19.2
  • SQLAlchemy ==2.0.41
  • Werkzeug ==3.1.3
  • aiohappyeyeballs ==2.6.1
  • aiohttp ==3.12.14
  • aiosignal ==1.4.0
  • altair ==5.5.0
  • annotated-types ==0.7.0
  • anyio ==4.9.0
  • async-timeout ==4.0.3
  • asyncio ==3.4.3
  • asyncpg ==0.30.0
  • attrs ==25.3.0
  • backoff ==2.2.1
  • bcrypt ==4.3.0
  • beautifulsoup4 ==4.13.4
  • bidict ==0.23.1
  • bitarray ==3.5.0
  • blinker ==1.9.0
  • build ==1.2.2.post1
  • cachetools ==5.5.2
  • certifi ==2025.7.14
  • charset-normalizer ==3.4.2
  • chromadb ==1.0.15
  • ckzg ==2.1.1
  • click ==8.2.1
  • coloredlogs ==15.0.1
  • cytoolz ==1.0.1
  • dash ==3.1.1
  • dataclasses-json ==0.6.7
  • distro ==1.9.0
  • durationpy ==0.10
  • eth-account ==0.13.7
  • eth-hash ==0.7.1
  • eth-keyfile ==0.8.1
  • eth-keys ==0.7.0
  • eth-rlp ==2.2.0
  • eth-typing ==5.2.1
  • eth-utils ==5.3.0
  • eth_abi ==5.2.0
  • exceptiongroup ==1.3.0
  • faiss-cpu ==1.11.0.post1
  • fastapi ==0.116.1
  • feedparser ==6.0.11
  • filelock ==3.18.0
  • flask-cors ==6.0.1
  • flatbuffers ==25.2.10
  • frozenlist ==1.7.0
  • fsspec ==2025.7.0
  • gitdb ==4.0.12
  • google-auth ==2.40.3
  • googleapis-common-protos ==1.70.0
  • greenlet ==3.2.3
  • grpcio ==1.73.1
  • h11 ==0.16.0
  • hexbytes ==1.3.1
  • hf-xet ==1.1.5
  • httpcore ==1.0.9
  • httptools ==0.6.4
  • httpx ==0.28.1
  • httpx-sse ==0.4.1
  • huggingface-hub ==0.33.4
  • humanfriendly ==10.0
  • idna ==3.10
  • importlib_metadata ==8.7.0
  • importlib_resources ==6.5.2
  • iniconfig ==2.1.0
  • itsdangerous ==2.2.0
  • joblib ==1.5.1
  • jsonpatch ==1.33
  • jsonpointer ==3.0.0
  • jsonschema ==4.24.0
  • jsonschema-specifications ==2025.4.1
  • kubernetes ==33.1.0
  • langchain ==0.3.26
  • langchain-chroma ==0.2.5
  • langchain-community ==0.3.27
  • langchain-core ==0.3.70
  • langchain-huggingface ==0.3.1
  • langchain-ollama ==0.3.6
  • langchain-tavily ==0.2.10
  • langchain-text-splitters ==0.3.8
  • langgraph ==0.5.4
  • langgraph-checkpoint ==2.1.1
  • langgraph-prebuilt ==0.5.2
  • langgraph-sdk ==0.1.74
  • langsmith ==0.4.8
  • lxml ==6.0.0
  • markdown-it-py ==3.0.0
  • marshmallow ==3.26.1
  • mdurl ==0.1.2
  • mmh3 ==5.1.0
  • mpmath ==1.3.0
  • mss ==10.0.0
  • multidict ==6.6.3
  • mypy_extensions ==1.1.0
  • narwhals ==1.46.0
  • nest-asyncio ==1.6.0
  • networkx ==3.4.2
  • nodriver ==0.47.0
  • numpy ==2.2.6
  • nvidia-cublas-cu12 ==12.6.4.1
  • nvidia-cuda-cupti-cu12 ==12.6.80
  • nvidia-cuda-nvrtc-cu12 ==12.6.77
  • nvidia-cuda-runtime-cu12 ==12.6.77
  • nvidia-cudnn-cu12 ==9.5.1.17
  • nvidia-cufft-cu12 ==11.3.0.4
  • nvidia-cufile-cu12 ==1.11.1.6
  • nvidia-curand-cu12 ==10.3.7.77
  • nvidia-cusolver-cu12 ==11.7.1.2
  • nvidia-cusparse-cu12 ==12.5.4.2
  • nvidia-cusparselt-cu12 ==0.6.3
  • nvidia-nccl-cu12 ==2.26.2
  • nvidia-nvjitlink-cu12 ==12.6.85
  • nvidia-nvtx-cu12 ==12.6.77
  • oauthlib ==3.3.1
  • ollama ==0.5.1
  • onnxruntime ==1.22.1
  • opentelemetry-api ==1.35.0
  • opentelemetry-exporter-otlp-proto-common ==1.35.0
  • opentelemetry-exporter-otlp-proto-grpc ==1.35.0
  • opentelemetry-proto ==1.35.0
  • opentelemetry-sdk ==1.35.0
  • opentelemetry-semantic-conventions ==0.56b0
  • orjson ==3.11.0
  • ormsgpack ==1.10.0
  • outcome ==1.3.0.post0
  • overrides ==7.7.0
  • packaging ==25.0
  • pandas ==2.3.1
  • parsimonious ==0.10.0
  • pillow ==11.3.0
  • playwright ==1.53.0
  • plotly ==6.2.0
  • pluggy ==1.6.0
  • poly_eip712_structs ==0.0.1
  • posthog ==5.4.0
  • propcache ==0.3.2
  • protobuf ==6.31.1
  • psycopg2-binary ==2.9.10
  • py-clob-client ==0.23.0
  • py_order_utils ==0.3.2
  • pyarrow ==20.0.0
  • pyasn1 ==0.6.1
  • pyasn1_modules ==0.4.2
  • pybase64 ==1.4.1
  • pycryptodome ==3.23.0
  • pydantic ==2.11.7
  • pydantic-settings ==2.10.1
  • pydantic_core ==2.33.2
  • pydeck ==0.9.1
  • pyee ==13.0.0
  • pyproject_hooks ==1.2.0
  • pytest ==8.4.1
  • python-dateutil ==2.9.0.post0
  • python-dotenv ==1.1.1
  • python-engineio ==4.12.2
  • python-socketio ==5.13.0
  • pytz ==2025.2
  • referencing ==0.36.2
  • regex ==2024.11.6
  • requests ==2.32.4
  • requests-oauthlib ==2.0.0
  • requests-toolbelt ==1.0.0
  • retrying ==1.4.0
  • rich ==14.0.0
  • rlp ==4.1.0
  • rpds-py ==0.26.0
  • rsa ==4.9.1
  • safetensors ==0.5.3
  • scikit-learn ==1.7.0
  • scipy ==1.15.3
  • selenium ==4.34.2
  • sentence-transformers ==5.0.0
  • sgmllib3k ==1.0.0
  • shellingham ==1.5.4
  • simple-websocket ==1.1.0
  • six ==1.17.0
  • smmap ==5.0.2
  • sniffio ==1.3.1
  • sortedcontainers ==2.4.0
  • soupsieve ==2.7
  • starlette ==0.47.2
  • streamlit ==1.46.1
  • sympy ==1.14.0
  • tenacity ==9.1.2
  • threadpoolctl ==3.6.0
  • tokenizers ==0.21.2
  • toml ==0.10.2
  • tomli ==2.2.1
  • toolz ==1.0.0
  • torch ==2.7.1
  • tornado ==6.5.1
  • tqdm ==4.67.1
  • transformers ==4.53.3
  • trio ==0.30.0
  • trio-websocket ==0.12.2
  • triton ==3.3.1
  • typer ==0.16.0
  • typing-inspect ==0.9.0
  • typing-inspection ==0.4.1
  • typing_extensions ==4.14.1
  • tzdata ==2025.2
  • undetected-chromedriver ==3.5.5
  • urllib3 ==2.5.0
  • uvicorn ==0.35.0
  • uvloop ==0.21.0
  • watchdog ==6.0.0
  • watchfiles ==1.1.0
  • websocket-client ==1.8.0
  • websockets ==15.0.1
  • wrapt ==1.17.2
  • wsproto ==1.2.0
  • xxhash ==3.5.0
  • yarl ==1.20.1
  • zipp ==3.23.0
  • zstandard ==0.23.0