Python
同步、异步客户端和成交实时流。
GitHub pmwallets-python,PyPI pmwallets。 Python ≥ 3.10,同步与 asyncio 两种客户端。
shell
pip install pmwallets
python
import asyncio from pmwallets import AsyncClient, Client, FillStream, FileStateStore # synchronous REST with Client(api_key="pmw_...") as pmw: board = pmw.leaderboard(minWinLo=0.55, minEligible=30, style="taker", status="active", limit=50) cheap = pmw.leaderboard(bands=[0, 1], minWinLo=0.55) # address unlocks free or in the cheapest paid band (0 = free ... 5) pmw.subscribe(board["rows"][0]["entityId"], channels=["ws"]) # billed per entity per hour # every fill of every entity you follow async def main(): async with AsyncClient(api_key="pmw_...") as pmw: stream = FillStream( client=pmw, store=FileStateStore("stream.json"), # a restart resumes from the last saved cursor on_fill=lambda fill, meta: print(meta.source, fill["side"], fill["price"], fill["tokenId"]), ) await stream.run() asyncio.run(main())
| 作用 | |
|---|---|
Client / AsyncClient | 全部 REST 调用,名字与 Node 相同、改为下划线风格,见方法一览 |
FillStream | asyncio WebSocket,带重连与保活;发现断档并补回;去重;游标落盘 |
verify_webhook(raw_body, signature, secret) | 校验 x-pmw-signature(原始 body 的 HMAC-SHA256) |