Skip to content

tstone-dev/polymarket-stocks-hedging

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Polymarket Stocks Hedging

screenshot

What is this?

Polymarket offers prediction markets on stock prices, such as "Will GOOGL close above $200 by end of February?". These markets let you bet YES or NO on outcomes.

The opportunity

By buying NO shares on price targets significantly above the current stock price, you're essentially betting the stock won't reach that price. If you're right, you get $1 per share at expiration. If you're wrong but own the actual stock, your stock gains offset the prediction market loss.

Why it works

Prediction markets, especially low-liquidity ones, are often inefficient. You can frequently find 20-50%+ APY on relatively safe scenarios (e.g., betting a stock won't rise 30% in 2 weeks).

Example

GOOGL is at $180. A market asks "Will GOOGL hit $250 by March?". NO shares cost $0.92. If GOOGL stays below $250, you profit $0.08/share (8.7% in a few weeks = high APY). If GOOGL somehow hits $250, you lose $0.92/share but your GOOGL stock gained ~39%.

This tool scans Polymarket for these opportunities, ranks them by attractiveness, and optionally lets you execute trades directly.

Features

  • Market Scanner: Scans Polymarket for stock price prediction markets and identifies opportunities based on delta from current price, time to expiry, and APY
  • Portfolio Dashboard: View positions, available balance, and portfolio breakdown
  • Stock Holdings Tracker: Enter your stock holdings to see hedge scenario calculations when trading
  • Trade Execution: Execute trades directly with configurable max price and amount (optional - requires wallet setup)
  • Position Redemption: Automatically redeems resolved winning positions

Quick Start (View Only)

You can run the scanner without any wallet configuration to just discover opportunities.

1. Install dependencies

npm install

2. Configure scanner

Edit config/config.json:

{
  "stocks": ["GOOGL", "AMZN"],
  "opportunities": {
    "opportunityAPY": 25,
    "minDisplayAPY": 8,
    "minDeltaPercent": 7
  }
}
Field Description
stocks Stock tickers to scan for
opportunityAPY Minimum APY to flag as "opportunity" (green highlight)
minDisplayAPY APY cutoff - hide opportunities below this
minDeltaPercent Delta (% from current stock price) cutoff

3. Run

npm run dev

Open http://localhost:3000

Trading Setup (Optional)

To execute trades, you need to configure your Polymarket wallet.

⚠ Please read the Security section carefully before enabling trading features

1. Create .env file

# Wallet credentials (required for trading)
POLYGON_PRIVATE_KEY=your_wallet_private_key
POLYMARKET_FUNDER_ADDRESS=your_polymarket_proxy_wallet_address
POLYGON_RPC_URL=https://polygon-rpc.com

# Auth password for trading
TRADE_PASSWORD=your_secure_password

# Readonly mode (default: true)
# When true, requires login to trade or skip opportunities
READONLY_MODE=true

Finding your Polymarket proxy address: This is the address Polymarket uses to hold your funds. You can find it in your Polymarket account settings or by checking the deposit address.

2. Login to trade

Click Login in the app header and enter your TRADE_PASSWORD to enable trading.

Usage

Dashboard

  • Positions: Total value of open positions with count
  • Balance: USDC balance available for trading
  • Opportunities: Count of opportunities meeting the opportunityAPY threshold
  • Stock Holdings: Enter shares you own for each stock to enable hedge calculations

Opportunities Table

Click column headers to sort. Columns:

Column Description
Market Event title with link to Polymarket
Strike Strike price of the bracket
Delta % difference from current stock price
NO Price Current best ask price for NO shares
APY Annualized yield if NO wins
Score Opportunity score (0-100)
Expires Days until market resolution

Trading

  1. Click Trade on an opportunity
  2. Adjust Max Price (highest price you'll pay)
  3. Adjust Max Amount (budget limit)
  4. Review shares, cost, APY, and profit preview
  5. If you've entered stock holdings, see hedge scenarios showing:
    • Bet profit if stock stays below strike
    • Hedge cost % if stock rises above strike
  6. Click Execute

Skipping

Click Skip to hide an opportunity:

  • Snooze (24h): Reappears after 24 hours
  • Dismiss Forever: Permanently hidden

Scoring Formula

Score = APY Score (30 pts max) + Delta Score (70 pts max)

APY Score = min(APY, 200) / 200 * 30
Delta Score = min(|delta|, 50) / 50 * 70

Higher delta = safer bet (stock less likely to reach strike price).

Security

  • Private Key: Your POLYGON_PRIVATE_KEY grants full control over your wallet. Never share it, commit it to git, or expose it publicly. Use a dedicated wallet with limited funds.
  • Trade Password: If exposing the UI on the internet, use a strong TRADE_PASSWORD. Anyone with access can execute trades on your behalf.
  • Readonly Mode: Enabled by default (READONLY_MODE=true). Requires login to skip opportunities, preventing visitors from modifying your data.
  • Stock Holdings: Stored locally in your browser (localStorage). Never sent to any server.
  • Self-hosted: This app is designed to run on your own infrastructure. Don't use third-party hosted versions with your private key.

Production Deployment

Using Docker

docker compose up -d --build

The app runs on port 50003 by default.

VPN Setup (Optional)

Required to place orders if your server is in a country where Polymarket is restricted (e.g., France).
If you don't need it, remove the vpn service from the docker-compose.yml file & the references to it in the app service.

Step 1: Get OpenVPN Configuration

Using Proton VPN as an example (works with other providers too):

  1. Log in to Proton VPN Dashboard
  2. Navigate to Downloads > OpenVPN configuration files
  3. Select:
    • Platform: Linux
    • Protocol: UDP (recommended) or TCP
    • Connection: Choose a specific server (e.g., Ireland)
  4. Download the .ovpn file
  5. Get your OpenVPN Credentials from Account section (different from login password)

Step 2: Prepare VPN Files

mkdir -p vpn
mv ~/Downloads/your-server.ovpn vpn/vpn.ovpn

Step 3: Create Authentication File

Create vpn/vpn.auth with your OpenVPN credentials:

your-openvpn-username
your-openvpn-password

One credential per line (username on line 1, password on line 2).

Step 4: Edit VPN Configuration

Open vpn/vpn.ovpn and:

  1. Find auth-user-pass and change it to:

    auth-user-pass /vpn/vpn.auth
    
  2. Comment out update-resolv-conf references if present:

    # script-security 2
    # up /etc/openvpn/update-resolv-conf
    # down /etc/openvpn/update-resolv-conf
    

Step 5: Deploy

The docker-compose.yml includes VPN configuration. Just run:

docker compose up -d

The app traffic will route through the VPN while the port remains accessible on your host.

Made with ❤️ by


Reza Rahemtola

About

Find high-yield hedging opportunities on Polymarket stock prediction markets

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 96.8%
  • CSS 2.2%
  • Other 1.0%