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% तय कर देते हैं।

  1. क्या आपकी पहले से किसी language में strong skill है? अगर आप रोज़ Python लिखते हैं, bot Python में लिखें। अगर आप रोज़ TypeScript लिखते हैं, bot Node में लिखें। नीचे दिए गए SDK quality differences असली हैं, लेकिन किसी unfamiliar language से जूझने की लागत से छोटे हैं।
  2. क्या strategy latency-critical है? अगर आपकी edge 50ms से कम में react करने पर निर्भर है (5-minute crypto markets, news के दौरान market-making), तो hot path को Rust या Go से फायदा मिलता है। ज़्यादातर strategies को इसकी ज़रूरत नहीं होती।
  3. क्या आप एक से ज़्यादा 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 से नीचे मिलती है।

अक्सर पूछे जाने वाले प्रश्न

क्या py-clob-client Polymarket V2 के साथ compatible है?
हाँ। py-clob-client 0.34.6 (May 2026 तक हमारे VPS पर production में चल रहा version) V2-compatible है और pUSD collateral migration के साथ काम करता है। Package "pip install py-clob-client" से install किया जाता है।
Polymarket का official Node.js SDK कौन सा है?
@polymarket/clob-client-v2 (अभी May 2026 के अनुसार v1.0.6)। Package name में "v2" महत्वपूर्ण है - पुराना @polymarket/clob-client package V1 है और नए projects के लिए recommended नहीं है। "npm install @polymarket/clob-client-v2" से install करें।
क्या Polymarket का official Rust SDK है?
नहीं। May 2026 तक Polymarket का कोई official Rust SDK नहीं है। Rust users सीधे V2 REST और WebSocket APIs के against ethers-rs (EIP-712 signing के लिए) और reqwest या hyper (HTTP/WS के लिए) का उपयोग करके build करते हैं। यह ज़्यादा code है, लेकिन market making के लिए latency और concurrency के फायदे matter करते हैं।
क्या मैं Polymarket bot के लिए Go इस्तेमाल कर सकता हूँ?
हाँ, technically - Go के पास अच्छे HTTP और Ethereum libraries हैं (go-ethereum)। कोई official Go SDK नहीं है, इसलिए आपको REST API के against build करना होगा। हम Polymarket bots के लिए Go को Python या Node.js जितना commonly इस्तेमाल होते नहीं देखते, लेकिन यह पूरी तरह feasible है।
अगर मुझे Python और Node.js दोनों आते हैं, तो कौन सा इस्तेमाल करूँ?
अगर आपकी strategy research-heavy है तो Python (pandas, NumPy, scikit-learn)। अगर आपकी strategy real-time / event-driven है और आप same language client और server चाहते हैं तो Node.js। दोनों वही CLOB endpoints तक पहुँचते हैं; दोनों किसी भी non-HFT strategy के लिए पर्याप्त तेज़ हैं।
क्या Node SDK के लिए TypeScript ज़रूरी है?
ज़रूरी नहीं, लेकिन recommended है। @polymarket/clob-client-v2 के साथ TypeScript types आते हैं, और compile time पर type errors पकड़ लेना EIP-712 signature payloads या order types गलत होने पर बहुत debugging बचाता है।
Polymarket bot कितना तेज़ होना चाहिए?
ज़्यादातर strategies के लिए milliseconds काफी हैं, microseconds नहीं। Sports microstructure और market making को sub-100ms से फायदा मिलता है; news arbitrage 500-1000ms तक tolerate कर सकती है। Strategy logic के लिए Python इस्तेमाल करें, और hot path के लिए केवल तभी Rust पर जाएँ जब latency profiling साबित करे कि यह आपके edge के लिए ज़रूरी है।