Command line interface for Polymarket.
- List available markets with question filter (with SQLite caching)
- Buy tokens/shares
- Sell tokens/shares
- Set USDC allowance for all Polymarket exchange contracts
- Show order book for specific token
- Cancel all open orders
- Redeem winning positions from resolved markets
- Auto-generate API keys for Polymarket
Requires Node.js 22.0.0 or higher
npm i pmarket-cli -gThis is the most common issue! Polymarket uses USDC.e (bridged USDC), NOT native USDC.
| Token | Contract Address | Works with Polymarket? |
|---|---|---|
| USDC.e (Bridged) | 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174 |
✅ YES |
| USDC (Native) | 0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359 |
❌ NO |
If you have native USDC, you need to swap it for USDC.e on a DEX like Uniswap or QuickSwap.
You also need a small amount of MATIC for gas fees on Polygon.
-
Ensure you have USDC.e in your wallet (see Prerequisites above)
-
Initialize with your private key:
pmarket-cli -i YOUR_PRIVATE_KEYHow to export your MetaMask private key
- Set USDC allowance for the exchange contracts:
pmarket-cli -a 500This sets allowance for all three Polymarket contracts:
- CTFExchange (regular markets)
- NegRiskExchange (neg_risk markets)
- NegRiskAdapter (neg_risk markets)
That's it! The tool will:
- Validate your private key and show your wallet address
- Use a public Polygon RPC (
https://polygon-rpc.com) by default - Auto-generate and cache API credentials on first use
By default, pmarket-cli uses https://polygon-rpc.com. To use a different Polygon RPC provider, add rpcUrl to your config file (~/.pmarket-cli/config.json):
{
"privateKey": "your-private-key",
"rpcUrl": "https://polygon-bor-rpc.publicnode.com"
}This is useful if the default RPC is slow, rate-limited, or unreliable in your region.
If you want to see or regenerate your API keys:
pmarket-cli -kThe credentials are automatically saved to ~/.pmarket-cli/credentials.json.
Fetch fresh market data and update the local cache:
pmarket-cli -rSearch for markets matching a filter. Uses cached data (refreshes automatically if cache is expired).
pmarket-cli -l "Bitcoin"pmarket-cli -b <token_id> <size> <price>Example: Buy 60 shares at price $0.50:
pmarket-cli -b 12110463059584809904811790486163860991533989713640269122405796144537637099628 60 0.5pmarket-cli -s <token_id> <size> <price>Example: Sell 60 shares at price $0.50:
pmarket-cli -s 12110463059584809904811790486163860991533989713640269122405796144537637099628 60 0.5Display your current token positions with P&L:
pmarket-cli -pAllow Polymarket's exchange contracts to spend your USDC.e:
pmarket-cli -a 500This sets allowance for three contracts (required for all market types):
- CTFExchange:
0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E(regular markets) - NegRiskExchange:
0xC5d563A36AE78145C45a50134d48A1215220f80a(neg_risk markets) - NegRiskAdapter:
0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296(neg_risk markets)
Note: The command includes delays between transactions to avoid public RPC rate limits.
pmarket-cli -o <token_id>pmarket-cli -cClaim USDC.e from resolved markets where you hold winning positions:
pmarket-cli -wThis automatically:
- Finds all redeemable positions from resolved markets
- Redeems them via the appropriate contract (ConditionalTokens for standard markets, NegRiskAdapter for neg_risk markets)
- Returns USDC.e to your wallet
pmarket-cli -kList available markets with question filter
Commandpmarket-cli -l "Oscar"Response
[
{
yes: {
token_id: '32690616433410387308307813339600971589831744601462134742731346664328487681674',
outcome: 'Yes',
price: 0.645,
winner: false
},
no: {
token_id: '93520364131545158991271066783085167796254018656458248205265557269588037162187',
outcome: 'No',
price: 0.355,
winner: false
},
question: "Will 'Sing Sing' be nominated for Oscar for Best Picture?"
},
...
]
Found 14 market(s). Use -r flag to refresh cache.Buy token order
Commandpmarket-cli -b 12110463059584809904811790486163860991533989713640269122405796144537637099628 60 0.5Response
{
errorMsg: '',
orderID: '0x6f89228a046c2cda1beb604599bda10c6acab735e2d8fdd7208754575f88dae0',
status: 'live',
success: true
}Sell token order
Commandpmarket-cli -s 12110463059584809904811790486163860991533989713640269122405796144537637099628 60 0.5Response
{
"success": true,
"errorMsg": "",
"orderID": "0x556d3864c64d851462b2f378f5e6dcec7d31ba1632dfe44bfdcaa3cc685b45cc",
"status": "matched"
}Show positions
Commandpmarket-cli -pResponse
Fetching positions for 0x1234...
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ CURRENT POSITIONS │
├──────────────────────────────────────────────────────────────┬────────┬──────────┬──────────┬──────────┬────────┤
│ Market │ Side │ Size │ Price │ Value │ P&L │
├──────────────────────────────────────────────────────────────┼────────┼──────────┼──────────┼──────────┼────────┤
│ Will Bitcoin reach $100k by end of 2024? │ Yes │ 100.00 │ $0.65 │ $65.00 │ +$5.00 │
│ Will ETH flip BTC? │ No │ 50.00 │ $0.80 │ $40.00 │ -$2.00 │
├──────────────────────────────────────────────────────────────┴────────┴──────────┴──────────┼──────────┼────────┤
│ TOTAL │ $105.00 │ +$3.00 │
└─────────────────────────────────────────────────────────────────────────────────────────────┴──────────┴────────┘
2 position(s) found.Show order book for specific tokenId
Commandpmarket-cli -o 12110463059584809904811790486163860991533989713640269122405796144537637099628Response
{
market: '0x6f662d9d965d0b01d08ee284a58e1dd866296729801c0cdc6867459760bd33ab',
asset_id: '12110463059584809904811790486163860991533989713640269122405796144537637099628',
bids: [
{ price: '0.03', size: '100' },
{ price: '0.45', size: '200' },
...
],
asks: [
{ price: '0.99', size: '1000' },
{ price: '0.97', size: '100' },
...
]
}Redeem winning positions
Commandpmarket-cli -wResponse
Fetching redeemable positions for 0x1234...
Found 1 resolved market(s) with redeemable positions:
Will Bitcoin reach $100k by end of 2024?
Condition: 0xabc123...
Shares: Yes: 100.00
Redeeming positions...
Redeeming: Will Bitcoin reach $100k by end of 2024?
tx submitted: 0xdef456...
Confirmed (standard market)
Redeemed 1/1 market(s). USDC.e has been returned to your wallet.All configuration is stored in ~/.pmarket-cli/:
| File | Purpose |
|---|---|
config.json |
Private key and settings (e.g. rpcUrl) |
credentials.json |
Auto-generated API credentials |
cache.db |
SQLite cache for market data |
Note: Ensure you have at least 1GB of free disk space for the market cache.
You can override the config directory using the PMARKET_CONFIG_DIR environment variable:
PMARKET_CONFIG_DIR=/path/to/custom/dir pmarket-cli -l "Bitcoin"npm install
npm run build
npm test
node dist/main.js -l "Bitcoin"src/
├── main.ts # Entry point
├── program.ts # CLI argument parsing
├── services/
│ ├── config.service.ts # Configuration management
│ ├── polymarket.service.ts # Polymarket API interactions
│ ├── contract.service.ts # Ethereum contract interactions
│ └── cache.service.ts # SQLite caching
└── strategy/
├── context.ts # Strategy pattern context
├── list-strategy.ts # List markets command
├── buy-strategy.ts # Buy command
├── sell-strategy.ts # Sell command
├── redeem-strategy.ts # Redeem winnings command
└── ...
Please use the Issue Tracker to report any issues or bugs.
This project is licensed under the MIT License.