Polymarket Bot Tutorial · Chapter 10 of 32
Bot builders के लिए Polymarket order types का explanation: Fill-or-Kill (FOK), Fill-and-Kill (FAK), Good-til-Cancelled (GTC), और limit-vs-market trade-offs. Production-grade decision rules के साथ।
यह chapter क्या cover करता है
Order-type confusion नए bot builders के लिए bug का सबसे महँगा class है। जहाँ GTC चाहिए था वहाँ FOK भेजने से missed entries होती हैं; जहाँ FOK चाहिए था वहाँ GTC भेजने से resting orders रह जाते हैं जो hours बाद बहुत खराब prices पर fill होते हैं। यह chapter decision tree है और production defaults हैं जो हजारों orders के across टिके रहे हैं।
- Quick decision tree
- FOK: जब आपको fill या skip करना हो
- FAK: जब partials acceptable हों
- GTC: जब आप book पर rest करना चाहते हों
- Limit vs market और spread tax
- हमारे production defaults (FOK buys, GTC sells)
- Code: each order type place करें
Quick decision tree
हर order placement को तीन सवाल decide करते हैं।
- क्या आपको अभी guaranteed fill चाहिए, और अगर अभी नहीं मिल सकता तो बिल्कुल नहीं? → FOK.
- क्या आप अभी जितना fill मिल सके उतना चाहते हैं, partials accept करते हैं, और resting order नहीं चाहते? → FAK.
- क्या आप अपनी price पर book पर rest करना चाहते हैं और किसी को अपने पास आने का इंतज़ार करना चाहते हैं? → GTC.
बस इतना ही। Order types के आसपास bot bugs का बड़ा हिस्सा #1 चुनने से आता है जबकि आपको #3 चाहिए था (एक "buy" "no position because the spread was too wide" में बदल जाता है) या #3 चुनने से जबकि आपको #1 चाहिए था (एक "buy" एक resting order में बदल जाता है जो hours बाद गलत समय पर fill होता है)।
FOK: जब आपको fill करना हो या skip करना हो
Fill-or-Kill पूरा order requested price या उससे बेहतर पर, तुरंत match करता है। अगर full size को तुरंत fill नहीं किया जा सकता, तो order reject हो जाता है और कुछ नहीं होता। कोई resting नहीं, कोई partial नहीं।
FOK का use करें: news-arbitrage entries के लिए (आपको सिर्फ news price पर enter करना है, 30s बाद market जहाँ होगा वहाँ नहीं); specific target पर take-profit exits के लिए जहाँ partials bookkeeping को muddle कर देंगे; किसी भी समय जब strategy atomic execution मानती हो।
Trade-off: FOK दूसरे order types की तुलना में ज़्यादा बार reject होता है, खासकर illiquid books पर। हमेशा fallback path रखें - strategy condition को re-evaluate करें और अगर अभी भी valid हो तो retry करें, या आगे बढ़ जाएँ।
FAK: जब partials acceptable हों
Fill-and-Kill (जिसे "immediate or cancel" भी कहा जाता है) अभी जितना fill कर सकता है उतना करता है, फिर unfilled remainder cancel कर देता है। आपको full size, partial, या zero मिल सकता है।
FAK का use करें: specific price ceiling के साथ market-buy के लिए (mid से N cents ऊपर तक ask lift करें); inventory urgently reduce करते समय sweep-the-book sells के लिए; किसी भी strategy के लिए जहाँ "some position is better than none"।
Operationally FOK से ज़्यादा tricky है क्योंकि next step तय करने से पहले bot को जानना होता है कि उसे 100% मिला या 30%। Fill response में filled_size field होती है - इसे हमेशा पढ़ें।
GTC: जब आप book पर rest करना चाहते हों
Good-til-Cancelled आपके price पर book पर तब तक rest करता है जब तक fill न हो जाए या आप cancel न करें। कोई timeout नहीं (v2 API में दूसरे order types में GTD होता है जिसमें expiry होती है)।
GTC का use करें: entry के ऊपर +Nc पर take-profit sells के लिए; entry के नीचे -Nc पर stop-loss sells के लिए (caveats के साथ - नीचे देखें); market-making के दोनों-sided quotes के लिए; किसी भी position के लिए जहाँ bot बेहतर price का इंतज़ार करने को तैयार हो।
कड़ा नियम: GTC के लिए ≥ 5 shares चाहिए. 5 shares से नीचे के orders CLOB द्वारा Size (X) lower than the minimum: 5 के साथ reject हो जाते हैं। जो bot 4-share GTC sell post करता है वह exit set करना silently fail कर देता है और position को resolution तक साथ ले जाता है। GTC post करने से पहले हमेशा inventory ≥ 5 check करें; छोटा हो तो FAK या ride-to-resolve पर fall back करें।
Limit vs market और spread tax
हर Polymarket order technically एक limit order है - यहाँ तक कि जिसे bots "market buy" कहते हैं, उसमें भी price ceiling specify होती है। फर्क यह है कि वह price best ask पर है या नहीं (effectively market order, book के खिलाफ fill होगा) या उससे नीचे है (book पर rest करेगा)।
Spread tax crossing की cost है - bid 0.45, ask 0.47, mid 0.46। एक round trip जो ask पर buy और bid पर sell करता है, वह प्रति share 2 cents pay करता है। 60% win-rate strategy पर +3c/-4c targets के साथ, वही 2c spread profit और loss के बीच फर्क है।
Maker pattern (bid पर या उससे नीचे GTC post करें, hit होने का इंतज़ार करें) spread को pay करने के बजाय collect करता है। Cost है uncertain fill - शायद आपको कभी hit न मिले। High-conviction trades के लिए spread pay करें। Passive accumulation के लिए book को work करें।
हमारे production defaults (FOK buys, GTC sells)
वह pattern जिस पर हमारे ज़्यादातर production bots converge करते हैं:
- Entries: ask + 0-2 cents पर FOK. अगर bot ने buy decide किया है, तो उसे अभी buy करना चाहिए या skip करना चाहिए। Entry order को rest करना शायद ही worth it होता है - buy decision को trigger करने वाली situation order के rest होने से ज़्यादा तेज़ बदलती है।
- Take-profit exits: target price पर GTC. Entry fill होने के तुरंत बाद post किया जाता है। हम market को अपने पास आने देते हैं; bid को नीचे chase नहीं करते। ≥ 5 shares के साथ।
- Stop-loss: case-by-case. धीरे चलने वाली strategies के लिए जहाँ price changes bounded हों, GTC काम करता है। तेज़-moving markets में GTC stop अगर price उसके through fly कर जाए तो fill नहीं होगा; हम option-D fashion में resolution तक ride करते हैं (memory: trader-gtc-sell.md)।
यह pattern conservative है - fewer fills, less slippage. एक अधिक aggressive variant FAK entries और FAK exits use करता है, partial fills accept करते हुए। एक चुनें और consistent रहें; trade के हिसाब से mix करने से confusion आता है।
Code: each order type place करें
Python में py-clob-client (v0.34.6) के साथ reference order placement.
from py_clob_client.client import ClobClient
from py_clob_client.clob_types import OrderArgs, OrderType
c = ClobClient(host="https://clob.polymarket.com", chain_id=137,
key=PRIVATE_KEY, signature_type=2, funder=PROXY)
c.set_api_creds(creds)
# FOK buy: fill 10 shares at price 0.45 or skip
args = OrderArgs(token_id=TOKEN, price=0.45, size=10, side="BUY")
resp = c.create_and_post_order(args, OrderType.FOK)
# FAK buy: take as much as you can at 0.45 or below
resp = c.create_and_post_order(args, OrderType.FAK)
# GTC sell: rest a sell at 0.85 for 10 shares
sell_args = OrderArgs(token_id=TOKEN, price=0.85, size=10, side="SELL")
resp = c.create_and_post_order(sell_args, OrderType.GTC)
@polymarket/clob-client-v2 के साथ Node में वही operations: OrderType.FOK को clob.OrderType.GTC आदि से replace करें; method createAndPostOrder है। negRisk flag (chapter 11) multi-outcome markets के लिए दूसरे argument में set होना चाहिए - इसे missing रखने पर request गलत exchange contract पर route हो जाती है।












