-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08_whale_tracker.cpp
More file actions
89 lines (71 loc) · 2.56 KB
/
08_whale_tracker.cpp
File metadata and controls
89 lines (71 loc) · 2.56 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
// Example 08: Whale Tracker — real-time monitoring of large trades.
//
// Uses RtdsClient (live trade feed) + DataClient (wallet stats) to detect
// whale activity — large bets from wallets with high P&L and win rate.
//
// This demonstrates how to build a PolyInsight-style tracker with the SDK.
// No authentication needed (all APIs are public/read-only).
//
// Run: ./08_whale_tracker
// Press Ctrl+C to stop.
#include <polymarket/rtds/rtds_client.hpp>
#include <polymarket/data/data_client.hpp>
#include <atomic>
#include <csignal>
#include <cstdio>
#include <string>
#include <thread>
using namespace polymarket;
static std::atomic<bool> running{true};
static void sigint_handler(int) { running = false; }
int main() {
std::signal(SIGINT, sigint_handler);
// Minimum trade volume (price * size) to alert on
constexpr double MIN_VOLUME = 500.0;
DataClient data;
RtdsClient rtds;
printf("=== Polymarket Whale Tracker ===\n");
printf("Monitoring trades > $%.0f...\n\n", MIN_VOLUME);
rtds.on_trade([&](RtdsTrade t) {
double volume = t.price * t.size;
if (volume < MIN_VOLUME) return;
// Print trade immediately
printf(">> %s %s $%.0f on \"%s\" (%.0f%% odds)\n",
t.side.c_str(), t.outcome.c_str(), volume,
t.title.c_str(), t.price * 100);
printf(" Wallet: %s\n", t.proxyWallet.c_str());
printf(" Tx: %s\n", t.transactionHash.c_str());
// Fetch wallet stats (cached 15 min by DataClient)
auto lb = data.leaderboard({}, {}, t.proxyWallet, "ALL");
if (lb && !lb->empty()) {
auto& entry = (*lb)[0];
printf(" PnL: $%.2f | Volume: $%.0f\n",
entry.pnl, entry.vol);
}
// Fetch trade count
auto traded = data.traded(t.proxyWallet);
if (traded) {
printf(" Trades: %d total\n", traded->traded);
if (traded->traded <= 10) {
printf(" *** NEW PLAYER (<=10 trades) ***\n");
}
}
printf("\n");
});
rtds.on_connect([]() {
printf("[connected to live trade feed]\n\n");
});
rtds.on_disconnect([](uint16_t code, const std::string& reason) {
printf("[disconnected: %u %s]\n", code, reason.c_str());
});
rtds.on_error([](const std::string& err) {
printf("[error: %s]\n", err.c_str());
});
rtds.connect();
// Wait for Ctrl+C
while (running) {
std::this_thread::sleep_for(std::chrono::seconds(1));
}
printf("\nShutting down...\n");
rtds.close();
}