Polymarket Trading Bot(Polymarket Copytrading & Polymarket Arbitrage bot) with full credential management, order execution, market analysis, and automated copytrading & arbitrage trading capabilities.
If you have any question or need help, contact here: Telegram | Twitter
- π Credential Management: Secure private key handling and API authentication
- π° Allowance Control: Manage USDC token allowances for trading
- π Market Analysis: Real-time bid/ask spreads and price data
- π― Order Execution: Place market and limit orders
- π Market Discovery: Auto-detect current Bitcoin markets
- π Price Tracking: Get real-time price updates from order books
- π€ Auto Trading Bot: Automated arbitrage trading with risk management

Use the interactive menu to manually place trades, check prices, and manage your account.
Fully automated bot that:
- Monitors price differences between software oracle and market
- Executes trades when profitable opportunities detected
- Automatically sets take profit and stop loss orders
- Manages risk with configurable parameters
# Install dependencies
npm install
# Create .env file
# Edit with your private key and configurationEdit .env file:
PRIVATE_KEY=your_private_key_here
CLOB_API_URL=https://clob.polymarket.com
POLYGON_CHAIN_ID=137
# Auto Trading Parameters
SOFTWARE_WS_URL=ws://172.16.52.93:5001
PRICE_DIFFERENCE_THRESHOLD=0.015
STOP_LOSS_AMOUNT=0.005
TAKE_PROFIT_AMOUNT=0.01
DEFAULT_TRADE_AMOUNT=5.0
TRADE_COOLDOWN=30npm run gen-credsnpm run auto-tradeThis starts the fully automated arbitrage trading bot that:
-
Connects to Data Feeds:
- Software price oracle (WebSocket) for real-time probability calculations
- Polymarket market feed (WebSocket) for current market prices
-
Monitors Price Differences:
- Continuously compares software oracle prices vs. market prices
- Detects when price difference exceeds threshold (default: $0.015)
-
Executes Automated Trades:
- Places market BUY order when opportunity detected
- Sets take profit limit SELL order (+$0.01 above buy price)
- Sets stop loss limit SELL order (-$0.005 below buy price)
- Waits for cooldown period (default: 30 seconds) before next trade
-
Risk Management:
- Automatic stop loss protection
- Take profit locking in gains
- Configurable trade amounts and thresholds
What You'll See:
Starting Auto Trading Bot...
Wallet: 0xYourAddress...
Finding current Bitcoin market...
β
Market found: Bitcoin Up or Down - November 22, 9AM ET
β
Software WebSocket connected
β
Polymarket WebSocket connected
β
Bot started successfully!
Monitoring for trade opportunities...
π― Trade opportunity detected!
Software Price: $0.7500 | Market Price: $0.7300 | Difference: $0.0200
π Executing trade...
β
Buy order placed
β
Take Profit order placed at $0.7400
β
Stop Loss order placed at $0.7250
β
Trade execution complete!
Prerequisites:
- Private key configured in
.env - API credentials generated (
npm run gen-creds) - Sufficient USDC balance (minimum $5, recommended $50+)
- Sufficient MATIC for gas fees (minimum 0.05, recommended 0.5+)
To Stop: Press Ctrl+C to stop the bot gracefully.
See PROFIT_STRATEGY.md for detailed explanation of the trading logic and QUICK_START.md for step-by-step setup guide.
npm run dev# Check credentials
npm run credentials
# Check allowance
npm run allowance
# Find current Bitcoin market
npm run market
# Get bid/ask prices (requires token ID as argument)
npm run bid-ask <token_id>
# Place orders (interactive)
npm run order# Compile TypeScript
npm run build
# Run compiled version
npm startpolymarket-ts-bot/
βββ src/
β βββ main.ts # Interactive CLI trading interface
β βββ auto_trading_bot.ts # Automated arbitrage bot
β βββ _gen_credential.ts # Credential management
β βββ allowance.ts # Token allowance management
β βββ bid_asker.ts # Bid/ask price fetching
β βββ market_order.ts # Order execution
β βββ market_finder.ts # Market discovery
β βββ generate_credentials.ts # Credential generation utility
βββ .env # Environment variables (private)
βββ .credentials.json # Generated API credentials
βββ package.json # Dependencies and scripts
βββ PROFIT_STRATEGY.md # Detailed trading strategy guide
βββ CREDENTIALS_GUIDE.md # How to generate credentials
The automated bot implements a price arbitrage strategy:
- Price Monitoring: Compares software oracle prices with Polymarket market prices
- Opportunity Detection: Triggers trade when price difference exceeds threshold
- Three-Order Execution:
- Market Buy: Buys tokens at current price
- Take Profit Limit Sell: Sells when price rises
- Stop Loss Limit Sell: Sells when price falls
- Risk Management: Configurable stop loss and take profit levels
Read PROFIT_STRATEGY.md for complete explanation of how the bot makes profit.
Software Oracle calculates UP token worth: $0.75
Market selling UP token at: $0.70
Difference: $0.05 (above $0.015 threshold)
Bot executes:
1. BUY @ $0.70 (market order)
2. SELL @ $0.71 (take profit +$0.01)
3. SELL @ $0.695 (stop loss -$0.005)
Expected outcome:
- 70% chance: Take profit hits β +$0.01 profit
- 30% chance: Stop loss hits β -$0.005 loss
- Net expectation: Positive
| Parameter | Default | Description |
|---|---|---|
| PRICE_DIFFERENCE_THRESHOLD | 0.015 | Minimum price difference to trigger trade |
| TAKE_PROFIT_AMOUNT | 0.01 | Profit target above buy price |
| STOP_LOSS_AMOUNT | 0.005 | Maximum loss below buy price |
| DEFAULT_TRADE_AMOUNT | 5.0 | USDC amount per trade |
| TRADE_COOLDOWN | 30 | Seconds between trades |
Manages wallet credentials and API authentication.
import { CredentialGenerator } from './_gen_credential';
const generator = new CredentialGenerator();
generator.displayInfo();Control USDC token allowances for trading.
import { AllowanceManager } from './allowance';
const manager = new AllowanceManager();
await manager.checkAllowance();
await manager.setAllowance('1000'); // Set 1000 USDC allowanceGet real-time order book data.
import { BidAsker } from './bid_asker';
const bidAsker = new BidAsker();
const data = await bidAsker.getPriceData(tokenId);
console.log(data.bidAsk.midpoint);Place and manage orders.
import { MarketOrderExecutor } from './market_order';
const executor = new MarketOrderExecutor();
await executor.placeMarketOrder({
tokenId: 'TOKEN_ID',
side: 'BUY',
amount: 10 // 10 USDC
});Auto-detect and search for markets.
import { MarketFinder } from './market_finder';
const finder = new MarketFinder();
const market = await finder.findCurrentBitcoinMarket();
console.log(market.tokens); // UP and DOWN tokens- β Confirmation prompts before placing orders
- β Price validation and sanity checks
- β Automatic market price buffers
- β Private key never exposed in logs
- β Error handling and recovery
start-bot.ps1
```bash
# Watch mode (auto-reload)
npm run dev
# Type checking
npx tsc --noEmit
# Lint
npx eslint src/- Never commit your
.envfile - Keep your private key secure
- Test with small amounts first
- Review all transactions before confirming
@polymarket/clob-client- Official Polymarket CLOB clientethers- Ethereum wallet and cryptographyaxios- HTTP requestsdotenv- Environment variable managementtypescript- Type safety and modern JavaScript
ISC
For issues or questions, please refer to:
Disclaimer: Use at your own risk. This software is provided as-is without warranties. Always test with small amounts first.
