Alright, let's get this lesson written.
Assalam-o-Alaikum, future bot masters. Umeed hai sab khairiyat se honge.
Pichle lesson mein humne basics cover kiye. Aaj اصل a-sil game shuru hogi. Sab se bara masla jo naye traders face karte hain woh strategy nahi, market selection hai. Aapke paas duniya ki best strategy ho, agar aap ne ghalat market mein trade laga di, tou you're stuck. Paisa ban'na tou door, asal paisa bhi phans jaata hai.
This is the most important lesson in this entire module. Isko aagay peechay se samajh lo. Yeh samajh gaye tou 80% logon se aagay nikal jaoge. Chalo shuru karte hain.
Scene on karo: Aap Karachi Stock Exchange (PSX) pe ho. Aap ne ek choti si company ka share khareed liya, suni sunai tip pe. Share upar chala gaya, paper pe aap profit mein ho. Ab aap bechne jaate ho... aur koi khareedar hi nahi hai. Buyer hai bhi tou itne kam price pe ke aapka profit loss mein badal jaye. You're trapped.
This is called an illiquid market.
Polymarket pe bhi same scene hota hai. Ek market mein laakhon dollar ka volume ho sakta hai, aur doosri mein sirf chand hazar.
Yaad rakho, hamara bot choti choti trades lega, lekin tezi se. Agar exit nahi mila, poora system fail ho jayega. Hamare scanner.py ka pehla kaam hi yehi hai ke woh aisi markets ko filter out kar de jahan volume aur liquidity kam ho.
Code Example: Fetching Basic Market Stats
Hum Polymarket ki (undocumented) GQL API use kar sakte hain, ya unke data se bani kisi 3rd party API ko hit kar sakte hain. For simplicity, maante hain ke hamare paas ek endpoint hai jo saari active markets ka data deta hai.
import requests
import json
# Note: This is a conceptual URL. Real implementation uses GQL.
# Hamare 'scanner.py' mein aisi hi logic hai.
API_URL = "https://api.polymarket.com/markets" # Fictional endpoint for this example
def get_active_markets():
"""Polymarket se active markets ka data uthao."""
try:
# Headers zaroori hain to mimic a real browser
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
}
response = requests.get(API_URL, headers=headers)
response.raise_for_status() # Agar koi error ho (like 404, 500) to exception raise karega
markets = response.json()
print(f"Total {len(markets)} markets fetched.")
return markets
except requests.exceptions.RequestException as e:
print(f"API se data fetch karne mein masla hua: {e}")
return None
# Example usage (isko run karne ke liye aapko real API/data source chahiye hoga)
# For now, let's create a dummy market list.
dummy_markets = [
{
"id": "market-1",
"question": "Will Pakistan win the next T20 against India?",
"volume24hr": "55000.50",
"liquidity": "150000.75",
"outcomePrices": "[\"0.65\", \"0.35\"]"
},
{
"id": "market-2",
"question": "Will a new political party be registered in Sindh by August?",
"volume24hr": "1250.20",
"liquidity": "3000.00",
"outcomePrices": "[\"0.10\", \"0.90\"]"
}
]
# Let's check the volume of the first dummy market
pak_vs_ind_market = dummy_markets[0]
volume = float(pak_vs_ind_market.get('volume24hr', 0))
print(f"Pakistan vs India market ka 24hr volume: ${volume:,.2f}")
sindh_politics_market = dummy_markets[1]
volume = float(sindh_politics_market.get('volume24hr', 0))
print(f"Sindh politics market ka 24hr volume: ${volume:,.2f}")
Output se saaf zahir hai ke cricket market mein trade karna aasan hoga, jabke politics wali market illiquid hai. Wahan phansne ka chance zyada hai.
score_market Function: Hamara Secret WeaponAb aate hain asal cheez pe. Hamare bot ko decision lena hai: "Should I trade this market or not?" Iske liye humne ek scoring function banaya hai. Yeh function hamari strategies/theta_sniper.py file ka dil hai. Yeh market ke different parameters ko dekhta hai aur usko 0 se 100 ke darmiyan score deta hai.
Let's break down the exact code jo hamara bot use karta hai:
def score_market(market):
"""Market ko score karo — trade karna chahiye ya nahi?"""
import json
# Step 1: Data Safai - API se data string mein aa sakta hai
prices = market.get('outcomePrices', '[0,0]')
if isinstance(prices, str):
prices = json.loads(prices)
yes_price = float(prices[0]) * 100 # Price ko cents mein convert karna
volume = float(market.get('volume24hr', 0))
liquidity = float(market.get('liquidity', 0))
score = 0
reasons = [] # Hum reasons bhi track karte hain for logging/debugging
# Step 2: Volume Check - Kya is market se nikalna aasan hoga?
# Minimum $3000/day for liquid exits. Isse kam mein risk hai.
if volume >= 3000:
score += 30
reasons.append(f'Good volume: ${volume:,.0f}')
else:
# Score nahi milega, aur hum note kar lenge ke volume kam hai
reasons.append(f'LOW volume: ${volume:,.0f} — EXIT mushkil hoga')
# Step 3: Price Sweet Spot - Theta strategy ke liye best range
# 60-95% is where theta works best. High probability, but still has premium.
if 60 <= yes_price <= 95:
score += 40 # Sab se zyada weightage isko diya hai
reasons.append(f'Price sweet spot: {yes_price:.1f}c')
elif yes_price > 95:
reasons.append(f'Too expensive: {yes_price:.1f}c — 95c risk for 5c reward. Not worth it.')
elif yes_price < 60:
reasons.append(f'Too risky: {yes_price:.1f}c — Probability hamare favor mein nahi hai.')
# Step 4: Liquidity Check - Market kitni "gehri" hai?
# Kam se kam $10,000 ki liquidity honi chahiye taake hamari trade price ko zyada na hilaye.
if liquidity >= 10000:
score += 30
reasons.append(f'Deep liquidity: ${liquidity:,.0f}')
else:
reasons.append(f'Thin liquidity: ${liquidity:,.0f} — Slippage ka khatra hai.')
# Final Decision: Agar score 70 se upar hai, tabhi tradeable hai
return {'score': score, 'reasons': reasons, 'tradeable': score >= 70}
# Chalo isko dummy data pe test karte hain
print("--- Testing Market 1 (Cricket) ---")
result1 = score_market(dummy_markets[0])
print(json.dumps(result1, indent=2))
print("\n--- Testing Market 2 (Politics) ---")
result2 = score_market(dummy_markets[1])
print(json.dumps(result2, indent=2))
Output Breakdown:
--- Testing Market 1 (