Files
mini_code/polymarket/购买1.0.py

49 lines
1.6 KiB
Python
Raw Normal View History

2026-01-04 02:53:24 +08:00
from py_clob_client import OrderArgs, OrderType, BalanceAllowanceParams, AssetType
2026-01-04 00:54:44 +08:00
from py_clob_client.client import ClobClient
2026-01-04 02:53:24 +08:00
# 使用代理钱包
client = ClobClient(
host="https://clob.polymarket.com",
key="0x78517b3a088e693e558177c19466c7fdad0458752618c306afcca8e440964a8a", # 你的主钱包私钥
chain_id=137,
signature_type=1, # Magic/Email 登录使用 1
funder="0xc859c04b0978Af007AcFD7178121E1666C8eB646" # 你的代理钱包地址
)
2026-01-04 00:54:44 +08:00
2026-01-04 02:53:24 +08:00
# 设置 API 凭据
client.set_api_creds(client.create_or_derive_api_creds())
2026-01-04 00:54:44 +08:00
2026-01-04 02:53:24 +08:00
params = BalanceAllowanceParams(
asset_type=AssetType.COLLATERAL,
signature_type=1,
)
print(client.get_balance_allowance(params))
2026-01-04 00:54:44 +08:00
2026-01-04 03:03:18 +08:00
from py_clob_client.clob_types import OpenOrderParams
# 1) 查当前 API key 下全部 open orders
orders = client.get_orders() # 或 client.get_orders(OpenOrderParams())
print("open orders:", len(orders))
print(orders[:5])
# 2) 只查某个 market 的 open orders
orders_m = client.get_orders(OpenOrderParams(market="你的market_id"))
print("open orders (market):", len(orders_m))
# 3) 只查某个 asset_id 的 open ordersYes/No token 各自一个 asset_id
orders_a = client.get_orders(OpenOrderParams(asset_id="你的asset_id"))
print("open orders (asset):", len(orders_a))
2026-01-04 00:54:44 +08:00
2026-01-04 02:53:24 +08:00
# # 获取所有活跃市场
# markets = client.get_markets()
2026-01-04 00:54:44 +08:00
2026-01-04 02:53:24 +08:00
# # 搜索特定主题
# for market in markets["data"]:
# print(market)
# if "Trump" in market['question']:
# print(f"市场:{market['question']}")
# print(f"Token ID (Yes): {market['tokens'][0]['token_id']}")
# print(f"Token ID (No): {market['tokens'][1]['token_id']}")