-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharbitrage_detector.js
More file actions
146 lines (121 loc) · 5.89 KB
/
Copy patharbitrage_detector.js
File metadata and controls
146 lines (121 loc) · 5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env node
const https = require('https');
// Polymarket API endpoints
const POLYMARKET_API = 'https://gamma-api.polymarket.com';
async function fetchJSON(url) {
return new Promise((resolve, reject) => {
https.get(url, (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
try {
resolve(JSON.parse(data));
} catch (e) {
reject(e);
}
});
}).on('error', reject);
});
}
async function findEndgameArbitrage() {
console.log('🎯 SCANNING FOR ENDGAME ARBITRAGE OPPORTUNITIES');
console.log('=' .repeat(60));
try {
// Get active markets
console.log('📊 Fetching active markets...');
const markets = await fetchJSON(`${POLYMARKET_API}/markets?active=true&limit=50`);
if (!markets || !markets.data) {
console.log('❌ No market data received');
return;
}
console.log(`📈 Found ${markets.data.length} active markets`);
const opportunities = [];
const now = Date.now();
const HOUR = 60 * 60 * 1000;
const DAY = 24 * HOUR;
for (const market of markets.data) {
// Check if market ends soon (within 48 hours)
const endTime = new Date(market.end_date_iso).getTime();
const timeLeft = endTime - now;
if (timeLeft > 0 && timeLeft < 2 * DAY) {
// Get market books/prices
const bookUrl = `${POLYMARKET_API}/book?token_id=${market.tokens[0].token_id}`;
try {
const book = await fetchJSON(bookUrl);
if (book && book.bids && book.asks && book.bids.length > 0) {
const bestBid = parseFloat(book.bids[0].price);
const bestAsk = parseFloat(book.asks[0].price);
// Look for high-probability positions (>90% chance)
if (bestBid > 0.90) {
const hoursLeft = Math.round(timeLeft / HOUR);
const potential = (1.0 - bestBid) / bestBid;
const annualized = potential * (365 * 24 / hoursLeft);
opportunities.push({
market: market.question,
probability: (bestBid * 100).toFixed(1),
price: bestBid.toFixed(3),
potential: (potential * 100).toFixed(1),
annualized: (annualized * 100).toFixed(0),
hoursLeft: hoursLeft,
volume: market.volume_24hr || 0,
token_id: market.tokens[0].token_id
});
}
}
} catch (bookError) {
console.log(`⚠️ Could not get book for: ${market.question.slice(0, 50)}...`);
}
// Small delay to avoid rate limiting
await new Promise(resolve => setTimeout(resolve, 200));
}
}
// Sort by potential return
opportunities.sort((a, b) => parseFloat(b.potential) - parseFloat(a.potential));
console.log(`\\n🔍 FOUND ${opportunities.length} ENDGAME OPPORTUNITIES:`);
console.log('=' .repeat(60));
if (opportunities.length === 0) {
console.log('😞 No high-probability opportunities found at this time');
console.log('💡 Try running again later - opportunities appear throughout the day');
} else {
opportunities.slice(0, 10).forEach((opp, i) => {
console.log(`${i + 1}. ${opp.market.slice(0, 70)}`);
console.log(` 💰 Price: $${opp.price} (${opp.probability}% probability)`);
console.log(` 📈 Potential: ${opp.potential}% return in ${opp.hoursLeft}h`);
console.log(` 📊 Annualized: ${opp.annualized}% APY`);
console.log(` 📚 24h Volume: $${opp.volume.toLocaleString()}`);
console.log(` 🔗 Token ID: ${opp.token_id}`);
console.log('');
});
}
console.log('\\n🚀 NEXT STEPS:');
console.log('1. Pick opportunity with good volume (>$1000 24h)');
console.log('2. Manually execute trade on Polymarket.com');
console.log('3. Monitor until resolution');
console.log('4. Collect profits! 💰');
} catch (error) {
console.error('❌ Error scanning markets:', error.message);
console.log('\\n💡 This might be due to:');
console.log('- API rate limiting (try again in a minute)');
console.log('- Network connectivity issues');
console.log('- Polymarket API changes');
}
}
async function checkCrossMarketArbitrage() {
console.log('\\n🌉 CHECKING CROSS-PLATFORM ARBITRAGE');
console.log('=' .repeat(40));
console.log('⚠️ Cross-platform detection requires Kalshi API access');
console.log('📝 For now, manually check EventArb.com for opportunities');
console.log('🔗 https://eventarb.com');
}
// Main execution
async function main() {
console.log('🤖 POLYMARKET ARBITRAGE OPPORTUNITY SCANNER');
console.log('Launch time:', new Date().toISOString());
console.log('Wallet: 0x4365F3339e8Aef1EdD95916DBF57949012E8B6f2\\n');
await findEndgameArbitrage();
await checkCrossMarketArbitrage();
console.log('\\n✅ Scan complete! Re-run this script periodically for new opportunities.');
}
if (require.main === module) {
main().catch(console.error);
}