npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

pmarket-cli

v1.0.0

Published

CLI tool to trade on Polymarket

Downloads

69

Readme

pmarket-cli

npm version Command line interface for Polymarket.


Features

  • 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

Installation

Requires Node.js 22.0.0 or higher

npm i pmarket-cli -g

Prerequisites

⚠️ You MUST have USDC.e (Bridged USDC) in your wallet

This 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.


Setup

Quick Start (3 steps)

  1. Ensure you have USDC.e in your wallet (see Prerequisites above)

  2. Initialize with your private key:

pmarket-cli -i YOUR_PRIVATE_KEY

How to export your MetaMask private key

  1. Set USDC allowance for the exchange contracts:
pmarket-cli -a 500

This 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

Optional: Generate API Keys Manually

If you want to see or regenerate your API keys:

pmarket-cli -k

The credentials are automatically saved to ~/.pmarket-cli/credentials.json.


Usage

Refresh Cache

Fetch fresh market data and update the local cache:

pmarket-cli -r

List Markets

Search for markets matching a filter. Uses cached data (refreshes automatically if cache is expired).

pmarket-cli -l "Bitcoin"

Buy Tokens

pmarket-cli -b <token_id> <size> <price>

Example: Buy 60 shares at price $0.50:

pmarket-cli -b 12110463059584809904811790486163860991533989713640269122405796144537637099628 60 0.5

Sell Tokens

pmarket-cli -s <token_id> <size> <price>

Example: Sell 60 shares at price $0.50:

pmarket-cli -s 12110463059584809904811790486163860991533989713640269122405796144537637099628 60 0.5

Show Positions

Display your current token positions with P&L:

pmarket-cli -p

Set USDC Allowance

Allow Polymarket's exchange contracts to spend your USDC.e:

pmarket-cli -a 500

This 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.

Show Order Book

pmarket-cli -o <token_id>

Cancel All Orders

pmarket-cli -c

Redeem Winnings

Claim USDC.e from resolved markets where you hold winning positions:

pmarket-cli -w

This 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

Get/Generate API Keys

pmarket-cli -k

Usage Examples

pmarket-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.
pmarket-cli -b 12110463059584809904811790486163860991533989713640269122405796144537637099628 60 0.5

Response

{
  errorMsg: '',
  orderID: '0x6f89228a046c2cda1beb604599bda10c6acab735e2d8fdd7208754575f88dae0',
  status: 'live',
  success: true
}
pmarket-cli -s 12110463059584809904811790486163860991533989713640269122405796144537637099628 60 0.5

Response

{
  "success": true,
  "errorMsg": "",
  "orderID": "0x556d3864c64d851462b2f378f5e6dcec7d31ba1632dfe44bfdcaa3cc685b45cc",
  "status": "matched"
}
pmarket-cli -p

Response

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.
pmarket-cli -o 12110463059584809904811790486163860991533989713640269122405796144537637099628

Response

{
  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' },
    ...
  ]
}
pmarket-cli -w

Response

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.

Configuration Files

All configuration is stored in ~/.pmarket-cli/:

| File | Purpose | |------|---------| | config.json | Your private key | | 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.

Custom Config Directory

You can override the config directory using the PMARKET_CONFIG_DIR environment variable:

PMARKET_CONFIG_DIR=/path/to/custom/dir pmarket-cli -l "Bitcoin"

Development

npm install
npm run build
npm test
node dist/main.js -l "Bitcoin"

Project Structure

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
    └── ...

Issues

Please use the Issue Tracker to report any issues or bugs.


License

This project is licensed under the MIT License.