How harshendram/orchestratingarbbot-probo-polymarket works
Project Type and Purpose
• This is a single-process, TypeScript-based arbitrage bot that continuously polls two prediction-market APIs (Probo in INR and Polymarket in USD), detects cross-currency price discrepancies, and executes paired trades to lock in risk-free profit.
File Structure
• Top-level entrypoints:
• cli.ts – command-line interface for “start”, “check”, “dry-run”, custom polling intervals
• index.ts – main orchestration, sets up scheduler, injects config, invokes core logic
• API integrations:
• probo.ts – wrapper for Probo REST API (INR-denominated orderbook)
• polymarket.ts – wrapper for Polymarket CLOB/REST API (USD orderbook + signer for blockchain)
• Configuration:
• config.ts – loads and validates environment variables (API keys, RPC URL, thresholds, DB path, dry-run flag)
• Core logic & types:
• types.ts – TS type definitions (Orderbook, Opportunity, TradeResult)
• utils/helpers.ts – conversion (USD→INR), profit calculation, threshold checks
• Execution and persistence:
• utils/database.ts – SQLite (or file) DB operations for history
• utils/logger.ts – structured logging (“debug”, “info”, “warn”, “error”)
• Testing and resilience:
• mocks/ – mock implementations for probo, polymarket, ethers
• index.test.ts – end-to-end test harness with Jest
• Other: tsconfig.json, bun.lock / package.json, .env.sample, package-lock.json
README for Architecture Insights
• Two embedded PNGs in utils/assets/ illustrate (a) component interactions, (b) logic flow.
• High-level steps: fetch → convert → analyze → execute → repeat.
• Mentions retry logic, rate limiting, dry-run mode.
Main Components & Interactions (
A. Scheduler / CLI (cli.ts → index.ts)
• Triggers polling at --interval or default loop
B. Configuration Manager (config.ts)
• Reads .env, injects into all modules
C. Market Data Collectors
1. Probo Module (probo.ts) → Probo REST API
2. Polymarket Module (polymarket.ts) → Polymarket CLOB/REST + Ethereum JSON-RPC
• Both pass raw orderbook objects to the analyzer
D. Currency Converter (helpers.ts)
• Applies DOLLAR_PRICE_INR to normalize USD prices to INR
E. Opportunity Analyzer (core logic in index.ts + helpers.ts)
• Computes combined YES/NO cost vs. 100%
• Checks against EXPECTED_ARB_PERCENT_MIN
F. Order Executor (polymarket.ts + probo.ts wrappers + ethers SDK)
• Places hedged orders on both platforms simultaneously
• Honors DRY_RUN flag
• Implements retry logic & rate limiter (in helpers or wrapper layers)
G. Persistence Layer (database.ts)
• Records all candidate opportunities and executed trades to DB_PATH
H. Logging (logger.ts)
• Emits detailed logs at each step
Architectural Patterns & Principles
• Modular Layers: clear separation (CLI → Config → Data Collection → Conversion → Analysis → Execution → Persistence → Logging)
• Single Responsibility per module
• Dependency Injection via config.ts
• Resilience: rate limiting + retry wrappers around external-API calls
• Testability: mocks for API & blockchain interactions