This project provides a robust, automated trading bot for Polymarket, the world's leading prediction market. Built with JavaScript (Node.js) and the official Polymarket CLOB (Central Limit Order Book) Client, this script enables developers and traders to programmatically enter and exit positions based on custom strategies.
It is designed as a foundational template for algorithmic trading on prediction markets, featuring secure wallet authentication, limit order management, and a modular architecture for implementing sophisticated Entry and Exit logic.
- Algorithmic Betting: Automate your betting strategy based on real-time probabilities.
- Market Making: Provide liquidity to specific outcome tokens.
- Arbitrage: Detect and exploit price inefficiencies.
- Copy Trading: Adapt the logic to mirror other successful wallets.
- Direct CLOB Integration: Interacts directly with the Polymarket exchange for low-latency execution.
- Entry & Exit Logic: Modular functions to define exact conditions for buying and selling shares.
- Secure Authentication: Uses local environment variables to manage private keys securely.
- Verification Support: Includes syntax checking and error handling for reliable operation.
- Node.js (v18 or higher recommended)
- A Polygon-compatible wallet (e.g., MetaMask) with:
- MATIC for gas fees.
- USDC (Polygon) for trading capital.
- A Polymarket account (your wallet must be connected to Polymarket).
- Clone the repository or download the source code.
- Navigate to the project directory.
cd polymarket-trading-bot - Install the required dependencies.
npm install
- Locate the
env.examplefile in the root directory. - Rename it to
.env.mv env.example .env
- Open
.envin a text editor and add your wallet Private Key.Note: Ensure this key is kept private. Do not commit your .env file to version control.PRIVATE_KEY=your_private_key_here
To start the bot, run the following command in your terminal:
node index.jsThe script will initialize the CLOB client, derive your API credentials, and begin executing the logic defined in index.js.
Modify strategy.js to implement your custom logic.
shouldEnter(marketData): Define conditions to buy shares (e.g., "Price < 0.30").shouldExit(positionData, marketData): Define conditions to sell shares (e.g., "Profit > 15%").
Edit index.js to configure:
MARKET_ID: The Token ID of the specific outcome you wish to trade.SHARE_AMOUNT: The size of the order to place.ENTRY_PRICE/EXIT_PRICE: The limit prices for your orders.
This software is for educational purposes only. Trading prediction markets involves significant risk. You are solely responsible for any financial losses incurred while using this software. Always test with small amounts before scaling up.