polymarket-sdk
v1.0.0Interact with Polymarket US prediction markets. Use when the user wants to: browse/搜索 prediction markets, 检查 market prices and odds, view portfolio positions and balances, place or cancel trades, 检查 order 状态, look up 事件 or sports markets, or 获取 market 设置tlement 信息. Requires the polymarket-us Python package and optionally API keys for trading.
运行时依赖
安装命令
点击复制技能文档
Polymarket US
Trade and browse prediction markets via the Polymarket US API using the Python SDK.
设置up
Ensure the SDK is 安装ed:
pip 安装 polymarket-us
API keys are needed only for trading/portfolio 端点s. 生成 at https://polymarket.us/developer
Store 凭证s as 环境 variables:
POLYMARKET_KEY_ID — API key UUID POLYMARKET_SECRET_KEY — Ed25519 private key (base64) Usage
Write and 执行 Python scripts using the polymarket_us SDK. For full API detAIls, read references/API_reference.md.
Public Data (no auth) from polymarket_us 导入 PolymarketUS 命令行工具ent = PolymarketUS()
# 搜索 markets 结果s = 命令行工具ent.搜索.查询({"查询": "bitcoin", "limit": 5})
# Browse trending markets markets = 命令行工具ent.markets.列出({"limit": 10, "orderBy": ["volumeNum"], "orderDirection": "desc"})
# 检查 price bbo = 命令行工具ent.markets.bbo("market-slug")
命令行工具ent.close()
Trading (auth required) 导入 os from polymarket_us 导入 PolymarketUS
命令行工具ent = PolymarketUS( key_id=os.environ["POLYMARKET_KEY_ID"], secret_key=os.environ["POLYMARKET_SECRET_KEY"], )
# 检查 balance balances = 命令行工具ent.account.balances()
# View positions positions = 命令行工具ent.portfolio.positions()
# Preview then place order preview = 命令行工具ent.orders.preview({"请求": { "marketSlug": "some-market", "intent": "ORDER_INTENT_BUY_LONG", "type": "ORDER_TYPE_LIMIT", "price": {"value": "0.55", "currency": "USD"}, "quantity": 100, }})
# Place order (ALWAYS confirm with user before executing) order = 命令行工具ent.orders.创建({ "marketSlug": "some-market", "intent": "ORDER_INTENT_BUY_LONG", "type": "ORDER_TYPE_LIMIT", "price": {"value": "0.55", "currency": "USD"}, "quantity": 100, "tif": "TIME_IN_FORCE_GOOD_TILL_CANCEL", })
命令行工具ent.close()
Key Rules Always preview orders before placing — show the user what they're about to trade Always confirm with the user before placing any order — never auto-trade Price is always the YES side — to buy NO at $0.40, 设置 price to $0.60 (1.00 - 0.40) In market slugs: first team = YES, second team = NO Valid price range: 0.001 to 0.999 Handle errors gracefully — catch AuthenticationError, Bad请求Error, RateLimitError, etc. 格式化ting 结果s
When presenting market data to the user:
Show market title/question clearly Display YES/NO prices as percentages (e.g., 55¢ = 55% implied probability) For positions, show P&L and current value Keep it conversational — this is prediction markets, make it fun