(wallet: string, limit = 100)
| 396 | } |
| 397 | |
| 398 | export async function fetchTraderActivity(wallet: string, limit = 100): Promise<TraderActivity[]> { |
| 399 | try { |
| 400 | const res = await rateLimitedFetch( |
| 401 | `${DATA_API_BASE}/activity?user=${wallet}&limit=${limit}` |
| 402 | ); |
| 403 | if (!res.ok) return []; |
| 404 | const data = await res.json(); |
| 405 | const items = Array.isArray(data) ? data : data.activity || data.data || []; |
| 406 | return items.map((a: ActivityApiEntry) => { |
| 407 | let ts = a.timestamp; |
| 408 | if (typeof ts === "number") { |
| 409 | ts = ts < 1e12 ? new Date(ts * 1000).toISOString() : new Date(ts).toISOString(); |
| 410 | } |
| 411 | const rawType = String(a.type || a.action || "TRADE").toUpperCase(); |
| 412 | const type = (["TRADE", "SPLIT", "MERGE", "REDEEM"].includes(rawType) ? rawType : "TRADE") as TraderActivity["type"]; |
| 413 | return { |
| 414 | timestamp: String(ts || new Date().toISOString()), |
| 415 | type, |
| 416 | title: String(a.title || a.marketTitle || a.question || ""), |
| 417 | outcome: String(a.outcome || ""), |
| 418 | side: String(a.side || "BUY").toUpperCase() === "SELL" ? "SELL" : "BUY", |
| 419 | size: parseFloat(String(a.size || a.shares || 0)), |
| 420 | usdcSize: parseFloat(String(a.usdcSize || a.amount || 0)) || parseFloat(String(a.size || 0)) * parseFloat(String(a.price || 0)), |
| 421 | price: parseFloat(String(a.price || 0)), |
| 422 | transactionHash: String(a.transactionHash || a.txHash || a.hash || ""), |
| 423 | }; |
| 424 | }); |
| 425 | } catch (err) { |
| 426 | console.error(`[smartMoney] Trader activity fetch error for ${wallet}:`, err); |
| 427 | return []; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | export async function fetchTraderValue(wallet: string): Promise<number> { |
| 432 | try { |
no test coverage detected