pmxtjs
v2.49.1
Published
Unified prediction market data API - The ccxt for prediction markets
Downloads
20,259
Maintainers
Readme
pmxtjs
A unified TypeScript/Node.js SDK for prediction markets — The ccxt for prediction markets.
Note: Use with a PMXT API key (hosted, recommended) or self-host the sidecar locally. Get a key at pmxt.dev/dashboard.
Installation
npm install pmxtjsQuick Start
Get your API key at pmxt.dev/dashboard. For reads, only pmxtApiKey and walletAddress are required.
import { Polymarket } from "pmxtjs";
// Reads — pmxtApiKey + walletAddress only
const client = new Polymarket({
pmxtApiKey: "pmxt_live_...",
walletAddress: "0xYourWalletAddress",
});
// Search for markets
const markets = await client.fetchMarkets({ query: "Trump" });
console.log(markets[0].title);
// Get outcome details
const outcome = markets[0].outcomes[0];
console.log(`${outcome.label}: ${(outcome.price * 100).toFixed(1)}%`);
// Fetch historical data (use outcome.outcomeId!)
const candles = await client.fetchOHLCV(outcome.outcomeId, {
resolution: '1d',
limit: 30,
});
// Get current order book
const orderBook = await client.fetchOrderBook(outcome.outcomeId);
const spread = orderBook.asks[0].price - orderBook.bids[0].price;
console.log(`Spread: ${(spread * 100).toFixed(2)}%`);
// Account reads
const positions = await client.fetchPositions();
const balance = await client.fetchBalance();How it works (hosted)
When you pass pmxtApiKey, the SDK talks to PMXT's hosted services: catalog requests go to api.pmxt.dev, trading requests go to trade.pmxt.dev. The SDK does not spawn a local process. For Polymarket and Opinion, PMXT's PreFundedEscrow handles custody — you sign orders with your own key, PMXT settles on-chain.
How it works (self-hosted)
Omit pmxtApiKey to use the local sidecar. Install pmxt-core from npm and supply venue credentials directly. See Self-hosted trading (advanced) below.
Core Methods
Market Data
fetchMarkets(params?)- Get active markets// Fetch recent markets await poly.fetchMarkets({ limit: 20, sort: 'volume' }); // Search by text await poly.fetchMarkets({ query: 'Fed rates', limit: 10 }); // Fetch by slug/ticker await poly.fetchMarkets({ slug: 'who-will-trump-nominate-as-fed-chair' });fetchEvents(params?)- Get events (groups of related markets)await poly.fetchEvents({ query: 'Fed Chair', limit: 5 });filterMarkets(markets, query)- Filter markets by keywordconst events = await poly.fetchEvents({ query: 'Fed Chair' }); const warsh = poly.filterMarkets(events[0].markets, 'Kevin Warsh')[0];
Deep-Dive Methods
fetchOHLCV(outcomeId, params)- Get historical price candlesfetchOrderBook(outcomeId)- Get current bids/asksfetchTrades(outcomeId, params)- Get trade history
Helper Methods
getExecutionPrice(orderBook, side, amount)- Calculate volume-weighted average pricegetExecutionPriceDetailed(orderBook, side, amount)- Get detailed execution info
Trading
Hosted trading (recommended)
With a PMXT API key, pass pmxtApiKey, walletAddress, and privateKey. The SDK auto-wraps your key into an EthersSigner and PMXT settles the order on-chain.
Polymarket:
import { Polymarket } from "pmxtjs";
const trader = new Polymarket({
pmxtApiKey: "pmxt_live_...",
walletAddress: "0xYourWalletAddress",
privateKey: "0xYourPrivateKey",
});
const balance = await trader.fetchBalance();
console.log(`Available: $${balance[0].available}`);
const order = await trader.createOrder({
marketId: "market-uuid",
outcomeId: "outcome-uuid",
side: "buy",
type: "market",
amount: 5.0,
denom: "usdc",
slippage_pct: 30.0,
} as any);
console.log(`Order status: ${order.status}`);Opinion:
import { Opinion } from "pmxtjs";
const trader = new Opinion({
pmxtApiKey: "pmxt_live_...",
walletAddress: "0xYourWalletAddress",
privateKey: "0xYourPrivateKey",
});See the full hosted trading guide for venue support, custody model, and limits.
Self-hosted trading (advanced)
When self-hosting, supply venue credentials directly — no pmxtApiKey. The SDK spawns a local sidecar process.
Polymarket:
const poly = new pmxt.Polymarket({
privateKey: process.env.POLYMARKET_PRIVATE_KEY,
proxyAddress: process.env.POLYMARKET_PROXY_ADDRESS, // Optional
// signatureType: 'gnosis-safe' (default)
});Kalshi:
const kalshi = new pmxt.Kalshi({
apiKey: process.env.KALSHI_API_KEY,
privateKey: process.env.KALSHI_PRIVATE_KEY
});Limitless:
const limitless = new pmxt.Limitless({
privateKey: process.env.LIMITLESS_PRIVATE_KEY
});Trading Methods
createOrder(params)- Place a new order// Using outcome shorthand (recommended) await poly.createOrder({ outcome: market.yes, side: 'buy', type: 'limit', amount: 10, price: 0.55 });cancelOrder(orderId)- Cancel an open orderfetchOrder(orderId)- Get order detailsfetchOpenOrders(marketId?)- Get all open orders
Account Methods
fetchBalance()- Get account balancefetchPositions()- Get current positions
Documentation
For complete API documentation and examples, see:
Important Notes
- Use
outcome.outcomeId, notmarket.marketIdfor deep-dive methods (fetchOHLCV, fetchOrderBook, fetchTrades) - Prices are 0.0 to 1.0 (multiply by 100 for percentages)
- Timestamps are Unix milliseconds
- Volumes are in USD
License
MIT
