Skip to content

Replace mock data with live API integration for arbitrage detection across Kalshi and Polymarket#2

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/fix-3bb48efb-6f8f-4aa2-8fa6-00293c4710e5
Draft

Replace mock data with live API integration for arbitrage detection across Kalshi and Polymarket#2
Copilot wants to merge 5 commits intomainfrom
copilot/fix-3bb48efb-6f8f-4aa2-8fa6-00293c4710e5

Conversation

Copy link

Copilot AI commented Aug 9, 2025

This PR completely replaces hardcoded mock data in all four React components with live API integration for real-time arbitrage detection between Kalshi and Polymarket prediction markets.

Overview

The application now fetches live market data, performs fuzzy market matching, calculates real arbitrage opportunities, and provides a complete workflow for cross-platform prediction market arbitrage detection.

Key Changes

Core Infrastructure

  • API Layer: New TypeScript modules for Kalshi (src/api/kalshi.ts) and Polymarket (src/api/polymarket.ts) with normalized market data structures
  • Business Logic: Arbitrage calculation utilities implementing the formula APR = (1-C)/C * 365/D where C = minYes + minNo
  • Fuzzy Matching: Market similarity scoring using title token overlap, category matching, and close date proximity
  • State Management: Central store with localStorage persistence for matches and ecosystems

Live Data Integration

  • Real-time Polling: Configurable intervals (Polymarket: 2.5s, Kalshi: 5s) with automatic pause on tab visibility change
  • Market Normalization: CommonMarket interface standardizing data across platforms with pricing, conditions, and metadata
  • Error Handling: Connection status monitoring and graceful fallback for API failures

Component Refactoring

Arbitrage Bets Component: Now displays live arbitrage opportunities calculated from matched markets in the store, showing real APR calculations, profit projections, and detailed condition pricing breakdowns.

Market Matcher Component: Replaced static market lists with live feeds from both exchanges. Implements fuzzy similarity scoring for match suggestions and provides a manual approval workflow with confidence metrics.

Ecosystem Matcher Component: Multi-platform market selection from live data with real-time ecosystem creation. Markets are grouped across exchanges with derived statistics (exchange count, market count, total conditions).

Matched Ecosystems Component: Displays stored ecosystems with live-calculated days until close, expandable details showing constituent markets, and integrated condition mapping interfaces.

Arbitrage Detection Logic

The system now detects arbitrage opportunities when:

  1. Markets are matched between platforms with "same" condition mappings
  2. Total cost C = minYes + minNo < 1.00
  3. Calculates period return as (1-C)/C and annualizes using days to expiry
  4. Updates opportunities in real-time as prices change

Data Persistence

  • Market matches and ecosystems persist across browser sessions via localStorage
  • Central store provides reactive updates to all components
  • Condition mappings support 6 relationship types (same, subset, mutually-exclusive, etc.)

Example Usage

// Live market fetching
const kalshiMarkets = await fetchNormalizedKalshiMarkets();
const polymarketMarkets = await fetchNormalizedPolymarketMarkets();

// Arbitrage calculation
const opportunities = calculateArbitrageOpportunities(matches, kalshiMarkets, polymarketMarkets);
// Result: [{ apr: 0.15, profitOn100: 2.34, C: 0.977, ... }]

// Market matching with similarity
const similarity = calculateSimilarity(kalshiMarket, polymarketMarket);
// Result: { overall: 0.94, title: 0.89, date: 1.0, conditions: 0.87, settlement: 1.0 }

The application is now ready for production use with live prediction market data and real arbitrage detection capabilities.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 4 commits August 9, 2025 19:57
Co-authored-by: Warhawk69 <112916099+Warhawk69@users.noreply.github.com>
…tate management

Co-authored-by: Warhawk69 <112916099+Warhawk69@users.noreply.github.com>
…bets and market-matcher

Co-authored-by: Warhawk69 <112916099+Warhawk69@users.noreply.github.com>
…ems using live data and store

Co-authored-by: Warhawk69 <112916099+Warhawk69@users.noreply.github.com>
Copilot AI changed the title [WIP] Integrate Live Kalshi & Polymarket Data + Arbitrage Logic (Replace Mock Data) Replace mock data with live API integration for arbitrage detection across Kalshi and Polymarket Aug 9, 2025
Copilot AI requested a review from Warhawk69 August 9, 2025 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants