Polymarket Bot ट्यूटोरियल · 32 में से अध्याय 3
अपना Polymarket bot stack चुनें: Python (py-clob-client 0.34.6), Node.js (@polymarket/clob-client-v2 v1.0.6), या Rust (कोई official SDK नहीं, ethers-rs पर build करें)। फायदे, नुकसान, latency, code samples.
यह अध्याय क्या कवर करता है
Language choice उतनी महत्वपूर्ण नहीं है जितना ज़्यादातर builders इसे मानते हैं। Polymarket हर language के लिए वही REST और WebSocket endpoints expose करता है; SDK का चुनाव मुख्यतः यह तय करता है कि आपको कितना glue code खुद लिखना पड़ेगा। Python और Node दोनों के official, maintained SDKs हैं; Rust के पास नहीं है, लेकिन hot path के लिए यह feasible है। यह अध्याय trade-offs समझाता है, हर language में वही "fetch order book" task दिखाता है ताकि difference साफ़ हो, और अंत में mixed-stack pattern पर खत्म होता है, जो ज़्यादातर production bots अंततः अपनाते हैं।
- Decision framework
- Python (default choice)
- Node.js (full-stack devs)
- Rust (latency-critical hot path)
- हर stack के लिए setup commands
- Code skeleton: 3 languages में order book fetch करें
- Stacks को कब mix करें (Python control plane + Rust hot path)
Decision framework
तीन सवाल stack choice का 90% तय कर देते हैं।
- क्या आपकी पहले से किसी language में strong skill है? अगर आप रोज़ Python लिखते हैं, bot Python में लिखें। अगर आप रोज़ TypeScript लिखते हैं, bot Node में लिखें। नीचे दिए गए SDK quality differences असली हैं, लेकिन किसी unfamiliar language से जूझने की लागत से छोटे हैं।
- क्या strategy latency-critical है? अगर आपकी edge 50ms से कम में react करने पर निर्भर है (5-minute crypto markets, news के दौरान market-making), तो hot path को Rust या Go से फायदा मिलता है। ज़्यादातर strategies को इसकी ज़रूरत नहीं होती।
- क्या आप एक से ज़्यादा strategy चलाएँगे? एक single Python process आराम से 10-20 markets संभाल सकता है। इससे आगे async Node या split-process Python बेहतर scale करता है।
पहले bot के लिए honest default Python है। सिर्फ़ तब बदलें जब कोई measured constraint मजबूर करे।
Python (default choice)
Python default इसलिए है क्योंकि इसका SDK सबसे complete है और iteration loop सबसे तेज़ है। py-clob-client version 0.34.6 (May 2026) पर उन सभी CLOB v2 endpoints को cover करता है जो matter करते हैं: market और limit orders, FOK/FAK/GTC variants, order book reads, balance/allowance reads, और web3.py के जरिए direct chain operations।
फायदे: mature SDK, pandas के साथ आसान data analysis, बड़ा community, on-chain reads के लिए web3.py। नुकसान: JavaScript की तुलना में async ergonomics awkward हैं, GIL multi-core speedups को सीमित करता है (I/O-bound bot में अक्सर matter नहीं करता), cold containers पर startup time धीमा है।
Recommended for: 80% builders. खासकर वे लोग जिनकी strategy में backtesting, statistical analysis, या execution के साथ-साथ data work शामिल है।
Node.js (full-stack devs)
Node.js दूसरा सबसे अच्छे तरीके से supported stack है। @polymarket/clob-client-v2 version 1.0.6 पर वही endpoints cover करता है जो Python SDK करता है, और पूरे stack में TypeScript types देता है। Async native और fast है; WebSocket handling बेहतरीन है।
फायदे: सबसे अच्छा async story, native TypeScript types, HTTP + WS के लिए बड़ा ecosystem, web dashboard के साथ same Node runtime पर आसान deploy। नुकसान: बड़े token IDs के लिए number precision में BigInt या string handling चाहिए (ERC-1155 IDs 256-bit हैं), pandas जैसे data tools कमज़ोर हैं।
Recommended for: वे builders जो पहले से JavaScript stack maintain करते हैं और एक ही runtime चाहते हैं। और वे लोग भी जो bot के साथ dashboard बना रहे हैं - bot core और Next.js dashboard के बीच types share करने से bugs की एक category खत्म हो जाती है।
Rust (latency-critical hot path)
Rust के लिए कोई official Polymarket SDK नहीं है। आपको V2 REST और WebSocket APIs के against सीधे reqwest (HTTP), tokio-tungstenite (WebSocket), और signing के लिए ethers-rs या alloy का उपयोग करके build करना होगा। यह Python की 30 मिनट की setup work के मुकाबले लगभग दो दिन का setup work है।
फायदे: JS subprocess के बिना native EIP-712 signing, sub-millisecond order construction, load के तहत deterministic memory profile, कोई GC pauses नहीं। नुकसान: SDK न होने का मतलब है कि आपको वह सब फिर से implement करना पड़ता है जो Python users को मुफ्त में मिलता है (clobToken ID parsing, response schema validation, salt/nonce management)। Latency में win tuned Python के मुकाबले 20-100ms का है, जो सिर्फ़ sub-second strategies में matter करता है।
Recommended for: market-making bot के hot path के लिए, या news-arb bot के trade-firing leg के लिए। लगभग कभी पूरा bot नहीं।
हर stack के लिए setup commands
Mainnet के against working signed order तक पहुँचने के लिए minimum commands (single CLOB v2 endpoint)।
Python:
python -m venv venv && source venv/bin/activate
pip install py-clob-client==0.34.6 web3 python-dotenv
# Set POLYGON_RPC, PRIVATE_KEY, POLY_FUNDER in .env
Node:
npm init -y
npm install @polymarket/[email protected] ethers dotenv
# Set POLYGON_RPC, PRIVATE_KEY, POLY_FUNDER in .env
Rust:
cargo new --bin pmt
cd pmt
cargo add tokio reqwest serde serde_json ethers alloy tungstenite tokio-tungstenite
# Hand-write signer + endpoint client; no SDK shortcut.
Time-to-first-order: ~10 min Python, ~15 min Node, ~4-8 hours Rust।
Code skeleton: 3 languages में order book fetch करें
वही task - Polymarket token के लिए order book fetch करना - हर stack में। तीनों वही CLOB v2 REST endpoint hit करते हैं।
Python (py-clob-client):
from py_clob_client.client import ClobClient
client = ClobClient(host="https://clob.polymarket.com", chain_id=137)
book = client.get_order_book("<token_id>")
print(book.bids[:3], book.asks[:3])
Node (@polymarket/clob-client-v2):
import { ClobClient } from "@polymarket/clob-client-v2";
const c = new ClobClient({ host: "https://clob.polymarket.com", chain: 137 });
const book = await c.getOrderBook("<token_id>");
console.log(book.bids.slice(0,3), book.asks.slice(0,3));
Rust (direct HTTP):
let url = format!("https://clob.polymarket.com/book?token_id={}", token);
let book: serde_json::Value = reqwest::get(&url).await?.json().await?;
println!("{:?} {:?}", &book["bids"][..3], &book["asks"][..3]);
तीनों में response shape वही है। Rust की cost बाकी हर जगह है - signing, order construction, error handling - read path में नहीं।
Stacks को कब mix करें (Python control plane + Rust hot path)
यह वह pattern है जिस पर कई production bots converge करते हैं: decisions से जुड़ी हर चीज़ के लिए Python, millisecond execution leg के लिए Rust।
Architecture: एक Python process market state read करता है, strategy logic चलाता है, और एक छोटा command file (जैसे {"action":"buy","token":"...","size":10,"price":0.45}) Unix socket पर लिखता है। एक Rust daemon उस socket पर listen करता है, order sign करता है, और उसे CLOB पर post करता है। Python process धीमा और convenient हो सकता है; Rust daemon तेज़ और minimal होता है।
Handoff key है: signed-order step को isolate करके, Python crash budget वापस मिल जाता है बिना latency sacrifice किए। हम production bots में बिल्कुल यही pattern इस्तेमाल करते हैं - Python intentions emit करता है, /tmp/clob.sock पर एक Node daemon signing handle करता है। Node version daemon sub-100ms के लिए ठीक है; Rust की असली value सिर्फ़ 50ms से नीचे मिलती है।












