{"id":35840726,"url":"https://github.com/roswelly/polymarket-trading-bot","last_synced_at":"2026-01-08T03:05:36.059Z","repository":{"id":301320075,"uuid":"1005433966","full_name":"roswelly/polymarket-trading-bot","owner":"roswelly","description":"polymarket trading bot - Interactive CLI and automated  polymarket arbitrage trading bot with real-time monitoring and risk controls.","archived":false,"fork":false,"pushed_at":"2025-12-29T16:07:31.000Z","size":68,"stargazers_count":132,"open_issues_count":0,"forks_count":105,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-01T20:32:15.069Z","etag":null,"topics":["arbitrage-bot","polymarket-arbitrage-bot","polymarket-trading-bot","trading-bot"],"latest_commit_sha":null,"homepage":"https://polymarket.com","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/roswelly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-06-20T08:15:27.000Z","updated_at":"2025-12-31T12:16:53.000Z","dependencies_parsed_at":"2025-06-26T09:38:13.791Z","dependency_job_id":null,"html_url":"https://github.com/roswelly/polymarket-trading-bot","commit_stats":null,"previous_names":["caterpillardev/confidential-balance","roswelly/confidential-spl-token","roswelly/polymarket-trading-bot"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/roswelly/polymarket-trading-bot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roswelly%2Fpolymarket-trading-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roswelly%2Fpolymarket-trading-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roswelly%2Fpolymarket-trading-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roswelly%2Fpolymarket-trading-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/roswelly","download_url":"https://codeload.github.com/roswelly/polymarket-trading-bot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roswelly%2Fpolymarket-trading-bot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28240574,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2026-01-08T02:00:06.591Z","response_time":241,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arbitrage-bot","polymarket-arbitrage-bot","polymarket-trading-bot","trading-bot"],"created_at":"2026-01-08T03:03:12.422Z","updated_at":"2026-01-08T03:05:36.043Z","avatar_url":"https://github.com/roswelly.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Polymarket Trading Bot | Polymarket Arbitrage Bot\n\nA TypeScript-based trading bot for Polymarket prediction markets on Polygon. This bot provides both interactive and automated trading capabilities with comprehensive market analysis, order management, and risk controls.\n\n## Features\n\n- **Interactive Trading Interface**: Command-line menu for manual trading operations\n- **Automated Trading**: Real-time price monitoring and automated trade execution\n- **Market Discovery**: Automatic Bitcoin market detection and search\n- **Price Analysis**: Real-time bid/ask, midpoint, and spread calculations\n- **Order Management**: Market orders, limit orders, and order cancellation\n- **Balance Monitoring**: USDC and MATIC balance checking with trading readiness validation\n- **Allowance Management**: Token allowance checking and approval\n- **WebSocket Integration**: Real-time price feeds from external sources and Polymarket\n- **Risk Management**: Configurable stop-loss and take-profit orders\n- **Read-Only Mode**: Safe exploration without private key\n\n## Prerequisites\n\n- Node.js (v16 or higher)\n- npm or yarn\n- A Polygon wallet with USDC and MATIC\n- Polymarket account (optional for read-only mode)\n\n## Installation\n\n1. Clone the repository:\n```bash\ngit clone \u003crepository-url\u003e\ncd confidential-spl-token\n```\n\n2. Install dependencies:\n```bash\nnpm install\n```\n\n3. Create a `.env` file in the root directory:\n```bash\ncp .env.example .env\n```\n\n4. Configure your environment variables (see Configuration section)\n\n## Configuration\n\nCreate a `.env` file with the following variables:\n\n### Required (for trading)\n```env\nPRIVATE_KEY=0xYourPrivateKeyHere\n```\n\n### Optional\n```env\n# API Endpoints\nCLOB_API_URL=https://clob.polymarket.com\nPOLYGON_RPC_URL=https://polygon-rpc.com\nPOLYGON_CHAIN_ID=137\nGAMMA_API_URL=https://gamma-api.polymarket.com\n\n# WebSocket Endpoints\nSOFTWARE_WS_URL=ws://45.130.166.119:5001\nPOLYMARKET_WS_URL=wss://ws-subscriptions-clob.polymarket.com/ws/market\n\n# Trading Parameters\nPRICE_DIFFERENCE_THRESHOLD=0.015\nSTOP_LOSS_AMOUNT=0.005\nTAKE_PROFIT_AMOUNT=0.01\nTRADE_COOLDOWN=30\nDEFAULT_TRADE_AMOUNT=5.0\n\n# Balance Requirements\nMIN_USDC_BALANCE=5.0\nMIN_MATIC_BALANCE=0.05\n\n# Logging\nLOG_LEVEL=INFO\nLOG_TO_FILE=false\n\n# WebSocket Reconnection\nMAX_RECONNECT_ATTEMPTS=10\nBASE_RECONNECT_DELAY=5000\nMAX_RECONNECT_DELAY=60000\n```\n\n## Usage\n\n### Interactive Mode\n\nStart the interactive trading bot:\n```bash\nnpm run dev\n```\n\nThe bot will display a menu with the following options:\n\n**With Private Key (Full Mode):**\n1. Show Credentials\n2. Check Balances (USDC + MATIC)\n3. Check Allowance\n4. Set Allowance\n5. Find Current Bitcoin Market\n6. Get Price Data (Bid/Ask)\n7. Place Market Order\n8. Place Limit Order\n9. View Open Orders\n10. Cancel Order\n0. Exit\n\n**Without Private Key (Read-Only Mode):**\n5. Find Current Bitcoin Market\n6. Get Price Data (Bid/Ask)\n0. Exit\n\n### Automated Trading\n\nStart the automated trading bot:\n```bash\nnpm run auto-trade\n```\n\nThe automated bot will:\n- Connect to price feeds via WebSocket\n- Monitor price differences between software predictions and Polymarket\n- Execute trades when threshold is met\n- Automatically place stop-loss and take-profit orders\n- Monitor balances periodically\n\n### Utility Scripts\n\n```bash\n# Check wallet balances\nnpm run check-balance\n\n# Generate API credentials\nnpm run gen-creds\n\n# Check/set token allowance\nnpm run allowance\n\n# Get bid/ask prices for a token\nnpm run bid-ask \u003ctoken_id\u003e\n\n# Find markets\nnpm run market\n\n# Place orders (example usage)\nnpm run order\n```\n\n## Project Structure\n\n```\nconfidential-spl-token/\n├── src/\n│   ├── main.ts                 # Interactive CLI bot\n│   ├── auto_trading_bot.ts    # Automated trading bot\n│   ├── generate_credentials.ts # CLOB API credential generator\n│   ├── credential_generator.ts # Credential utility\n│   ├── balance_checker.ts     # Balance checking\n│   ├── check_balance.ts       # Standalone balance checker\n│   ├── allowance.ts           # Token allowance management\n│   ├── bid_asker.ts           # Price data fetcher\n│   ├── market_finder.ts       # Market discovery\n│   ├── market_order.ts        # Order execution\n│   ├── logger.ts              # Logging utility\n│   └── config.ts              # Configuration management\n├── package.json\n├── tsconfig.json\n└── .env                        # Environment variables (not in repo)\n```\n\n## Getting Started\n\n### 1. Generate API Credentials\n\nFirst, generate your Polymarket CLOB API credentials:\n```bash\nnpm run gen-creds\n```\n\nThis will create a `.credentials.json` file with your API keys.\n\n### 2. Check Your Balance\n\nVerify you have sufficient funds:\n```bash\nnpm run check-balance\n```\n\nYou need:\n- At least $5.00 USDC for trading\n- At least 0.05 MATIC for gas fees\n\n### 3. Set Token Allowance\n\nBefore trading, approve USDC spending:\n```bash\nnpm run allowance\n```\n\nOr use the interactive menu (option 4).\n\n### 4. Start Trading\n\n**Interactive Mode:**\n```bash\nnpm run dev\n```\n\n**Automated Mode:**\n```bash\nnpm run auto-trade\n```\n\n## Security\n\n⚠️ **IMPORTANT SECURITY NOTES:**\n\n1. **Never commit your `.env` file** - It contains your private key\n2. **Never commit `.credentials.json`** - It contains API keys\n3. **Keep your private key secure** - Anyone with access can control your wallet\n4. **Use a dedicated trading wallet** - Don't use your main wallet\n5. **Start with small amounts** - Test thoroughly before larger trades\n6. **Review all transactions** - Verify before confirming trades\n\nThe `.gitignore` file is configured to exclude sensitive files.\n\n## Trading Strategy (Automated Bot)\n\nThe automated bot implements an arbitrage strategy:\n\n1. **Price Monitoring**: Continuously monitors prices from:\n   - External software WebSocket feed\n   - Polymarket market data\n\n2. **Opportunity Detection**: Detects when price difference exceeds threshold\n\n3. **Trade Execution**:\n   - Places market buy order\n   - Sets take-profit order (default: +$0.01)\n   - Sets stop-loss order (default: -$0.005)\n\n4. **Risk Management**:\n   - Cooldown between trades (default: 30 seconds)\n   - Balance monitoring\n   - Automatic reconnection on WebSocket failures\n\n## Troubleshooting\n\n### \"Private key not provided\"\n- Ensure `PRIVATE_KEY` is set in your `.env` file\n- Check that the private key starts with `0x`\n\n### \"Insufficient funds\"\n- Fund your wallet with USDC on Polygon\n- Ensure you have MATIC for gas fees\n- Use `npm run check-balance` to verify\n\n### \"RPC is not valid\"\n- Check your internet connection\n- Verify `POLYGON_RPC_URL` is correct\n- Try a different RPC endpoint\n\n### WebSocket connection issues\n- Check firewall settings\n- Verify WebSocket URLs are correct\n- The bot will automatically retry with exponential backoff\n\n### \"Allowance insufficient\"\n- Run `npm run allowance` to set allowance\n- Or use the interactive menu (option 4)\n- You can set \"max\" for unlimited allowance\n\n## Development\n\n### Build\n```bash\nnpm run build\n```\n\n### Run compiled version\n```bash\nnpm start\n```\n\n### TypeScript Configuration\nThe project uses TypeScript with strict mode enabled. Configuration is in `tsconfig.json`.\n\n## Dependencies\n\n- `@polymarket/clob-client` - Polymarket CLOB API client\n- `ethers` / `@ethersproject/*` - Blockchain interaction\n- `axios` - HTTP requests\n- `ws` - WebSocket connections\n- `dotenv` - Environment variable management\n\n## License\n\nISC\n\n## Disclaimer\n\nThis software is provided as-is for educational and research purposes. Trading cryptocurrencies and prediction markets involves substantial risk. Always:\n\n- Test thoroughly with small amounts\n- Understand the risks involved\n- Never trade more than you can afford to lose\n- Review all code before using with real funds\n- Use at your own risk\n\nThe authors are not responsible for any losses incurred from using this software.\n\n## Support\n\nFor issues, questions, or contributions, please open an issue on the repository.\n\n---\n\n**Happy Trading! 🚀**\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froswelly%2Fpolymarket-trading-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froswelly%2Fpolymarket-trading-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froswelly%2Fpolymarket-trading-bot/lists"}