Polymarket BTC 15m Assistant

repository·main·Indexed 20 days ago

https://github.com/frondent/polymarketbtc15massistant

A real-time console-based trading assistant for Polymarket's 'Bitcoin Up or Down' 15-minute markets. It provides technical analysis (RSI, MACD), predictive scoring, and live price feeds from Polymarket, Chainlink on Polygon, and Binance. The tool includes utilities for fetching CLOB order books, managing WebSocket price streams with exponential backoff, and calculating trading edges.

Tokens
8.2K
Snippets
29
Records
38
Agent score
72%

What's inside polyassistent

  1. Install and run Polymarket BTC 15m Assistant

    main

    Follow these steps to set up the real-time console trading assistant for Polymarket 'Bitcoin Up or Down' 15-minute markets.

    Prerequisites

    • Node.js 18+
    • npm

    Installation Steps

    1. Clone the repository:
      git clone https://github.com/FrondEnt/PolymarketBTC15mAssistant.git
      cd PolymarketBTC15mAssistant
    2. Install dependencies:
      npm install
    3. Run the assistant:
      npm start

    To stop the assistant, press Ctrl + C in the terminal.

    git clone https://github.com/FrondEnt/PolymarketBTC15mAssistant.git
    npm install
    npm start
  2. Configure Proxy support

    main

    The assistant supports HTTP(S) and SOCKS5 proxies for both HTTP requests and WebSocket connections using standard environment variables.

    Supported Variables

    • HTTPS_PROXY / https_proxy
    • HTTP_PROXY / http_proxy
    • ALL_PROXY / all_proxy

    Using Proxies with Authentication

    If your proxy requires a username and password, use the following format:

    • HTTP/HTTPS: http://USERNAME:PASSWORD@HOST:PORT
    • SOCKS5: socks5://USERNAME:PASSWORD@HOST:PORT

    Note: If your password contains special characters (like @ or :), you must URL-encode them. For example, p@ss:word becomes p%40ss%3Aword.

    # PowerShell example with authentication
    $env:HTTPS_PROXY = "http://user:p%40ss%3Aword@1.2.3.4:8080"
    npm start
  3. Configure Chainlink on Polygon fallback

    main

    If the Polymarket WebSocket is unavailable, the assistant falls back to on-chain Chainlink prices on Polygon. It is highly recommended to provide working Polygon RPC URLs for stability.

    VariableDefaultDescription
    CHAINLINK_BTC_USD_AGGREGATOR0xc907E116054Ad103354f2D350FD2514433D57F6fThe Chainlink aggregator address.
    POLYGON_RPC_URLhttps://polygon-rpc.comPrimary HTTP RPC URL.
    POLYGON_RPC_URLSNoneA comma-separated list of optional HTTP RPC URLs.
    POLYGON_WSS_URLNoneOptional WebSocket RPC URL.
    POLYGON_WSS_URLSNoneA comma-separated list of optional WebSocket RPC URLs.
  4. How the Polymarket BTC 15m Assistant works

    main

    The Polymarket BTC 15m Assistant is a real-time monitoring and decision-support tool designed for Polymarket BTC price prediction markets. It continuously aggregates data from multiple sources to provide a unified view of market conditions:

    1. Price Data: Fetches real-time BTC prices from Binance (spot), Chainlink (via WebSocket or fallback REST), and Polymarket (CLOB prices).
    2. Technical Analysis: Computes indicators including VWAP (Volume Weighted Average Price), RSI (Relative Strength Index), MACD, Heiken Ashi candles, and price momentum (Delta).
    3. Decision Engine: Uses a multi-stage engine to:
      • Detect Regime: Analyzes price/VWAP relationship and volume.
      • Score Direction: Combines TA indicators into probability scores.
      • Apply Time Awareness: Adjusts probabilities based on the time remaining until market settlement.
      • Compute Edge: Compares model probabilities against Polymarket's current market prices to find mathematical edges.
      • Decide: Outputs a final recommendation (e.g., BUY UP, BUY DOWN, or NO TRADE).
    4. Logging: Records all signals, probabilities, and market states to ./logs/signals.csv for backtesting and analysis.
  5. Configure Polymarket settings

    main

    The assistant uses environment variables to manage Polymarket market selection and connection settings.

    VariableDefaultDescription
    POLYMARKET_AUTO_SELECT_LATESTtrueIf true, automatically picks the latest 15m market.
    POLYMARKET_SERIES_ID10192The series ID for the market series.
    POLYMARKET_SERIES_SLUGbtc-up-or-down-15mThe series slug.
    POLYMARKET_SLUGNoneUse this to pin the assistant to a specific market slug.
    POLYMARKET_LIVE_WS_URLwss://ws-live-data.polymarket.comThe WebSocket URL for Polymarket live data.
  6. Troubleshoot Chainlink price updates

    main

    If the console shows no Chainlink updates, it usually means the Polymarket WebSocket is unavailable and the fallback mechanism is being used.

    Solution: Ensure you have at least one working Polygon RPC URL configured via POLYGON_RPC_URL or POLYGON_RPC_URLS to allow the assistant to fetch on-chain prices.

  7. Configure Chainlink WebSocket URLs

    main

    The startChainlinkPriceStream function determines which WebSocket endpoints to use by inspecting the CONFIG.chainlink object. You can provide a single URL or a list of fallback URLs.

    Configuration Keys:

    • CONFIG.chainlink.polygonWssUrl: A single WebSocket URL string.
    • CONFIG.chainlink.polygonWssUrls: An array of WebSocket URL strings used for fallback/rotation.

    If no valid URLs are found in the configuration, the stream will return a dummy object where getLast() always returns { price: null, updatedAt: null, source: "chainlink_ws" } and close() is a no-op.

  8. Configure global proxy settings via environment variables

    main

    The project supports configuring a global proxy for HTTP/HTTPS requests using standard environment variables. The system checks for proxy URLs in the following order of precedence based on the target URL protocol:

    For HTTPS/WSS targets:

    1. HTTPS_PROXY or https_proxy
    2. ALL_PROXY or all_proxy

    For HTTP/WS targets:

    1. HTTP_PROXY or http_proxy
    2. ALL_PROXY or all_proxy

    If no specific protocol proxy is found, it falls back to ALL_PROXY.

  9. Configure the Polymarket market selection

    main

    The assistant can either target a specific market or automatically find the latest one in a series. This is controlled via the CONFIG object (imported from ./config.js).

    • Pin a specific market: Set CONFIG.polymarket.marketSlug to the specific slug of the market you want to track.
    • Auto-select latest: If marketSlug is not set, ensure CONFIG.polymarket.autoSelectLatest is true. The assistant will then use CONFIG.polymarket.seriesId to fetch the most recent live market in that series.
  10. Count consecutive candle trends with countConsecutive()

    main

    The countConsecutive function analyzes an array of Heiken Ashi candles to determine the length of the current trend (the most recent streak of same-colored candles).

    It returns an object with:

    • color: Either `
  11. Pick the latest live or upcoming market

    main

    Use pickLatestLiveMarket(markets, nowMs) to find the most relevant market from a list.

    Logic:

    1. It first looks for live markets (where startTime <= nowMs < endDate). If multiple exist, it returns the one with the earliest endDate.
    2. If no live markets are found, it returns the upcoming market with the earliest endDate.
    3. Returns null if no valid markets are found.
    const currentMarket = pickLatestLiveMarket(markets); // uses Date.now() by default