還沒有帳號?點擊這裡註冊 Polymarket 並完成入金,才能用錢包私鑰為訂單籤名、實際成交。
法律合規提醒:在使用 Polymarket 服務或 API 前,請確認您所在地區的法律規定。Polymarket 目前不支援比利時、法國、新加坡、泰國、中國大陸等地區,政策可能隨時變化。
Python 示例
Copy
import websocket
import json
def on_message(ws, message):
data = json.loads(message)
print(f"收到消息: {data}")
def on_open(ws):
# 訂閱市場
subscribe_msg = {
"type": "subscribe",
"channel": "market",
"market_id": "YOUR_MARKET_ID"
}
ws.send(json.dumps(subscribe_msg))
ws = websocket.WebSocketApp(
"wss://ws-subscriptions-clob.polymarket.com/ws/",
on_message=on_message,
on_open=on_open
)
ws.run_forever()
TypeScript 示例
Copy
import WebSocket from 'ws';
const ws = new WebSocket('wss://ws-subscriptions-clob.polymarket.com/ws/');
ws.on('open', () => {
// 訂閱市場
ws.send(JSON.stringify({
type: 'subscribe',
channel: 'market',
market_id: 'YOUR_MARKET_ID'
}));
});
ws.on('message', (data) => {
const message = JSON.parse(data.toString());
console.log('收到消息:', message);
});