Skip to content

retrogtx/bet

Repository files navigation

YouTube Video Analysis & Kalshi Betting Automation

An automated system that monitors YouTube channels for new videos, analyzes their transcripts for specific keywords, and automatically places bets on Kalshi prediction markets based on word mentions.

Features

  • Real-time Video Monitoring - Automatically polls YouTube channels for new video uploads
  • Transcript Analysis - Fetches and analyzes video transcripts to check for keyword mentions
  • Automated Betting - Places YES/NO bets on Kalshi markets based on transcript analysis
  • Manual Analysis - Web UI for analyzing individual videos on-demand
  • Risk Management - Configurable bet amounts (defaults to 1% daily risk limit)
  • Dual Deployment - Supports local polling or Vercel cron-based execution

Tech Stack

  • Framework: Next.js 16 (App Router) with React 19
  • Language: TypeScript
  • Runtime: Bun
  • UI: Tailwind CSS, Radix UI, Shadcn/UI
  • APIs: YouTube RSS Feeds, Kalshi Trading API
  • Storage: Upstash Redis (for tracking processed videos)
  • Deployment: Vercel with cron jobs

Prerequisites

  • Bun installed
  • Kalshi API credentials (API key + private key)
  • Upstash Redis instance (free tier available)
  • YouTube channel URL to monitor

Environment Variables

Create a .env.local file in the project root:

# Kalshi API Credentials
KALSHI_API_KEY=your_kalshi_api_key
KALSHI_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nYour\nPrivate\nKey\nHere\n-----END PRIVATE KEY-----"

# Trading Configuration
BET_AMOUNT=10                           # Number of contracts per bet
MARKET_ID_YES=your_market_ticker        # Kalshi market ticker for YES bets
MARKET_ID_NO=your_market_ticker         # Kalshi market ticker for NO bets

# YouTube Configuration
YOUTUBE_CHANNEL_URL=https://youtube.com/@channelname
WORDS_TO_CHECK=word1,word2,word3        # Comma-separated words to check

# Redis (Upstash)
UPSTASH_REDIS_REST_URL=https://your-redis-url.upstash.io
UPSTASH_REDIS_REST_TOKEN=your_redis_token

Installation

# Clone the repository
git clone <your-repo-url>
cd bet

# Install dependencies
bun install

Usage

Local Development

# Start the development server
bun dev
  • Opens at http://localhost:3000
  • Automatic polling starts after 5 seconds
  • Polls every 5 minutes for new videos
  • View manual analysis UI in the browser

Production Deployment (Vercel)

# Deploy to Vercel
vercel deploy --prod

On Vercel:

  • Automatic polling is disabled bec we use cron jobs
  • Cron job runs every 5 minutes via /api/poll
  • Configure environment variables in Vercel dashboard
  • Cron schedule defined in vercel.json

How It Works

1. Video Monitoring

  • Fetches YouTube channel RSS feed every 5 minutes
  • Extracts latest video ID and metadata
  • Compares with last processed video stored in Redis

2. Transcript Analysis

  • Downloads video transcript using YouTube's API
  • Searches for configured keywords (case-insensitive, whole word matching)
  • Returns list of mentioned and not mentioned words

3. Automated Betting

  • Words Mentioned: Places YES bets on configured market
  • Words Not Mentioned: Places NO bets on configured market
  • Uses limit orders (99 cents for YES, 1 cent for NO)
  • Each bet uses configured contract amount (default: 10 contracts)

4. State Management

  • Stores last processed video ID in Redis
  • Prevents duplicate processing of the same video
  • Maintains betting history and results

Project Structure

├── app/
│   ├── api/
│   │   ├── analyze-video/    # Manual video analysis endpoint
│   │   ├── get-latest-video/  # Fetch latest video from channel
│   │   ├── place-bet/         # Place individual bet
│   │   └── poll/              # Polling endpoint (cron trigger)
│   ├── globals.css
│   ├── layout.tsx
│   └── page.tsx               # Main UI
├── lib/
│   ├── analyze-video-logic.ts # Video transcript analysis
│   ├── kalshi.ts              # Kalshi API client
│   ├── place-bet-logic.ts     # Betting logic
│   ├── poll-logic.ts          # Polling cycle logic
│   ├── polling-service.ts     # Local polling service
│   ├── redis.ts               # Redis client
│   ├── youtube.ts             # YouTube API utilities
│   └── utils.ts               # Shared utilities
├── components/
│   └── ui/                    # Shadcn UI components
├── vercel.json                # Vercel cron configuration
└── package.json

API Endpoints

POST /api/analyze-video

Manually analyze a video for keyword mentions.

{
  "videoId": "dQw4w9WgXcQ",
  "words": ["word1", "word2"]
}

GET /api/poll

Trigger a polling cycle (checks for new video and processes it).

POST /api/place-bet

Manually place a bet on Kalshi.

{
  "word": "keyword",
  "action": "yes",
  "marketId": "TICKER-123"
}

GET /api/get-latest-video?channelUrl=...

Fetch the latest video from a YouTube channel.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors