@agenticmail/enterprise 0.5.442 → 0.5.443

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +3 -2
  3. package/dist/agent-tools-3MD7EPO6.js +14629 -0
  4. package/dist/agent-tools-62HGQYDL.js +14629 -0
  5. package/dist/agent-tools-BTUVVOWT.js +14629 -0
  6. package/dist/agent-tools-BV3JMJPN.js +14629 -0
  7. package/dist/agent-tools-JVNQ4RPM.js +14629 -0
  8. package/dist/agent-tools-LD7LELVT.js +14629 -0
  9. package/dist/agent-tools-NRKQ5NMW.js +14629 -0
  10. package/dist/agent-tools-OXZJOD4D.js +14629 -0
  11. package/dist/agent-tools-PT2ES6G5.js +14629 -0
  12. package/dist/agent-tools-SS335E2E.js +14629 -0
  13. package/dist/chunk-2ACTQSPC.js +1728 -0
  14. package/dist/chunk-2XZE5NT3.js +5387 -0
  15. package/dist/chunk-325NTNE6.js +2180 -0
  16. package/dist/chunk-3AHKVWCO.js +5387 -0
  17. package/dist/chunk-3L2N6LR2.js +7517 -0
  18. package/dist/chunk-3ZD3XOV6.js +1728 -0
  19. package/dist/chunk-44VXWYPE.js +2570 -0
  20. package/dist/chunk-4UOSUXFR.js +7529 -0
  21. package/dist/chunk-54SHHX2S.js +2180 -0
  22. package/dist/chunk-5DVY3CNK.js +1728 -0
  23. package/dist/chunk-5F5DGV63.js +5596 -0
  24. package/dist/chunk-6IUUOWZY.js +7526 -0
  25. package/dist/chunk-77LFFLQX.js +7526 -0
  26. package/dist/chunk-7BKNDBSA.js +2191 -0
  27. package/dist/chunk-7BS2XPLW.js +5359 -0
  28. package/dist/chunk-7GCSGDXQ.js +1636 -0
  29. package/dist/chunk-7IAI45PR.js +4735 -0
  30. package/dist/chunk-7QPZGO27.js +4976 -0
  31. package/dist/chunk-7S5XAXRD.js +4747 -0
  32. package/dist/chunk-AD6ZR3QD.js +5357 -0
  33. package/dist/chunk-AO556OXZ.js +2570 -0
  34. package/dist/chunk-APUWQHXC.js +7437 -0
  35. package/dist/chunk-BKSSHV6C.js +1728 -0
  36. package/dist/chunk-BMUNQHLU.js +1208 -0
  37. package/dist/chunk-BPF5DKUM.js +392 -0
  38. package/dist/chunk-CFR5OSMI.js +1220 -0
  39. package/dist/chunk-CM4GUHXP.js +1728 -0
  40. package/dist/chunk-CVFIM72Q.js +501 -0
  41. package/dist/chunk-DFXVJNKW.js +4734 -0
  42. package/dist/chunk-DJ7LHRL7.js +2214 -0
  43. package/dist/chunk-DJFI6NR6.js +1624 -0
  44. package/dist/chunk-DJHYV5VY.js +1624 -0
  45. package/dist/chunk-DYM4PQO3.js +4727 -0
  46. package/dist/chunk-DZ75RF35.js +1728 -0
  47. package/dist/chunk-E5H64U5H.js +472 -0
  48. package/dist/chunk-EOD4EGFI.js +1728 -0
  49. package/dist/chunk-EP74QR5B.js +4980 -0
  50. package/dist/chunk-FE2M4FV5.js +5273 -0
  51. package/dist/chunk-FUH6NWIX.js +7540 -0
  52. package/dist/chunk-G5ADHHAD.js +1728 -0
  53. package/dist/chunk-GAYLPSM7.js +7529 -0
  54. package/dist/chunk-GDAFZJTJ.js +7540 -0
  55. package/dist/chunk-GLAN2JBA.js +1636 -0
  56. package/dist/chunk-GNAEBGU7.js +4812 -0
  57. package/dist/chunk-HDDA2Q3Q.js +1728 -0
  58. package/dist/chunk-HG62FWWQ.js +7437 -0
  59. package/dist/chunk-HV5VIS5K.js +1624 -0
  60. package/dist/chunk-IEVA23WK.js +4976 -0
  61. package/dist/chunk-IFMZ2IYC.js +7540 -0
  62. package/dist/chunk-IN7VIORK.js +2641 -0
  63. package/dist/chunk-KAX3ZDP2.js +7529 -0
  64. package/dist/chunk-KECO53GP.js +1728 -0
  65. package/dist/chunk-KGZ74UMA.js +1728 -0
  66. package/dist/chunk-M2ZLRUMX.js +7540 -0
  67. package/dist/chunk-MKQWC6KF.js +5374 -0
  68. package/dist/chunk-MQ3JBGLU.js +1636 -0
  69. package/dist/chunk-MVB6JARX.js +7529 -0
  70. package/dist/chunk-N37MOOFE.js +2210 -0
  71. package/dist/chunk-NELCAZUQ.js +5357 -0
  72. package/dist/chunk-OPAO5QQS.js +1728 -0
  73. package/dist/chunk-OUHU3VW6.js +1728 -0
  74. package/dist/chunk-OWEXZVZ6.js +1728 -0
  75. package/dist/chunk-P4DHSJJY.js +7437 -0
  76. package/dist/chunk-Q7QA6MNJ.js +1728 -0
  77. package/dist/chunk-QKKTNPGV.js +7592 -0
  78. package/dist/chunk-REMMXZVU.js +7529 -0
  79. package/dist/chunk-RK3KATD4.js +4756 -0
  80. package/dist/chunk-RQ33L5T3.js +5374 -0
  81. package/dist/chunk-RU77F65Q.js +1728 -0
  82. package/dist/chunk-SAM3CVIU.js +5374 -0
  83. package/dist/chunk-SFMXIKWZ.js +1728 -0
  84. package/dist/chunk-SPZ5JBGW.js +1624 -0
  85. package/dist/chunk-TDOC6WSK.js +7529 -0
  86. package/dist/chunk-TPMT5WTW.js +5357 -0
  87. package/dist/chunk-TVXUR3PB.js +2180 -0
  88. package/dist/chunk-TZEEVEKG.js +5343 -0
  89. package/dist/chunk-U327O3ZR.js +7540 -0
  90. package/dist/chunk-ULD6C5DB.js +2180 -0
  91. package/dist/chunk-ULVRCJZV.js +5374 -0
  92. package/dist/chunk-UOCDOM2S.js +1624 -0
  93. package/dist/chunk-VINDZLLX.js +1636 -0
  94. package/dist/chunk-VODW5GJL.js +2180 -0
  95. package/dist/chunk-WEWL7Z3C.js +2180 -0
  96. package/dist/chunk-WG2MEMS6.js +5343 -0
  97. package/dist/chunk-WYV6QWOJ.js +1188 -0
  98. package/dist/chunk-X5AIAD77.js +1636 -0
  99. package/dist/chunk-XUETIRDV.js +2214 -0
  100. package/dist/chunk-XWSMX7RK.js +7529 -0
  101. package/dist/chunk-YUSYXHKB.js +1728 -0
  102. package/dist/chunk-ZC2RMHQD.js +5374 -0
  103. package/dist/chunk-ZDZQQGFG.js +5374 -0
  104. package/dist/chunk-ZJ2HCWKF.js +1728 -0
  105. package/dist/chunk-ZMKVEJKR.js +392 -0
  106. package/dist/cli-agent-2UFGFO24.js +2761 -0
  107. package/dist/cli-agent-5FPUCFPG.js +2761 -0
  108. package/dist/cli-agent-7AB6NIYQ.js +2761 -0
  109. package/dist/cli-agent-7CAFSYOM.js +2761 -0
  110. package/dist/cli-agent-7OVOINHR.js +2757 -0
  111. package/dist/cli-agent-AWKBFIRS.js +2761 -0
  112. package/dist/cli-agent-ES3XOPHJ.js +2757 -0
  113. package/dist/cli-agent-KPXZN5JK.js +2761 -0
  114. package/dist/cli-agent-LGTCFHGS.js +2757 -0
  115. package/dist/cli-agent-LLUYUHHF.js +2757 -0
  116. package/dist/cli-agent-NHZWYX5Q.js +2761 -0
  117. package/dist/cli-agent-TYUOTYCO.js +2757 -0
  118. package/dist/cli-agent-VQO6HI65.js +2757 -0
  119. package/dist/cli-agent-VV5JWRU7.js +2757 -0
  120. package/dist/cli-agent-Z5B23XED.js +2757 -0
  121. package/dist/cli-serve-2FLQXJW7.js +322 -0
  122. package/dist/cli-serve-34YFCCUX.js +322 -0
  123. package/dist/cli-serve-3NS6MNUS.js +322 -0
  124. package/dist/cli-serve-4PWFEPNA.js +322 -0
  125. package/dist/cli-serve-4VIBMXMT.js +322 -0
  126. package/dist/cli-serve-5ZUF5MGH.js +322 -0
  127. package/dist/cli-serve-6HGL56GB.js +322 -0
  128. package/dist/cli-serve-BBBWEKKW.js +322 -0
  129. package/dist/cli-serve-D2HQC4SB.js +322 -0
  130. package/dist/cli-serve-IKCMNUNM.js +322 -0
  131. package/dist/cli-serve-LTUKYMEF.js +322 -0
  132. package/dist/cli-serve-MIWI5PBE.js +322 -0
  133. package/dist/cli-serve-R6K4SZ3L.js +322 -0
  134. package/dist/cli-serve-RQIOBQGF.js +322 -0
  135. package/dist/cli-serve-S57ROYQ6.js +322 -0
  136. package/dist/cli-serve-WVSLOISY.js +322 -0
  137. package/dist/cli-serve-YKZSNR3P.js +322 -0
  138. package/dist/cli-serve-ZGKXWDMZ.js +322 -0
  139. package/dist/cli-serve-ZZOJWREY.js +322 -0
  140. package/dist/cli.js +3 -3
  141. package/dist/dashboard/components/utils.js +1 -1
  142. package/dist/dashboard/docs/polymarket.html +1 -1
  143. package/dist/dashboard/pages/polymarket.js +222 -80
  144. package/dist/index.js +10 -10
  145. package/dist/pipeline-C4C3ZF4X.js +15 -0
  146. package/dist/pipeline-DAF3EV7Q.js +15 -0
  147. package/dist/pipeline-MMESLRQG.js +15 -0
  148. package/dist/polymarket-3LGJSQZK.js +17 -0
  149. package/dist/polymarket-4OIWQFBO.js +17 -0
  150. package/dist/polymarket-AZEV7C6E.js +17 -0
  151. package/dist/polymarket-DBQYJC57.js +7 -0
  152. package/dist/polymarket-EVTKWLUO.js +7 -0
  153. package/dist/polymarket-GMKDVVQH.js +17 -0
  154. package/dist/polymarket-HZOAD4W4.js +17 -0
  155. package/dist/polymarket-PKGRF7ID.js +17 -0
  156. package/dist/polymarket-QUNR2H7U.js +17 -0
  157. package/dist/polymarket-TM624BN5.js +17 -0
  158. package/dist/polymarket-VT2EDGD7.js +17 -0
  159. package/dist/polymarket-W7B4TLP3.js +17 -0
  160. package/dist/polymarket-WS4VE6U7.js +7 -0
  161. package/dist/polymarket-runtime-772ADZJW.js +108 -0
  162. package/dist/polymarket-runtime-AIYHQKYQ.js +108 -0
  163. package/dist/polymarket-runtime-APJ5HW4Y.js +108 -0
  164. package/dist/polymarket-runtime-BX3ODZZD.js +108 -0
  165. package/dist/polymarket-runtime-ISD4CKKL.js +108 -0
  166. package/dist/polymarket-runtime-JU4PQZGJ.js +108 -0
  167. package/dist/polymarket-runtime-OFLBSPCK.js +108 -0
  168. package/dist/polymarket-runtime-POJRRWFS.js +108 -0
  169. package/dist/polymarket-runtime-XN5TVHU5.js +108 -0
  170. package/dist/polymarket-runtime-ZYFTKEJ4.js +108 -0
  171. package/dist/polymarket-watcher-2CKLTIXI.js +23 -0
  172. package/dist/polymarket-watcher-3C72X36B.js +23 -0
  173. package/dist/polymarket-watcher-IHRZ2URM.js +23 -0
  174. package/dist/polymarket-watcher-J7UWIN7I.js +23 -0
  175. package/dist/polymarket-watcher-M6CDW63Y.js +23 -0
  176. package/dist/polymarket-watcher-OSI73EDX.js +23 -0
  177. package/dist/polymarket-watcher-PN4JJV3V.js +23 -0
  178. package/dist/polymarket-watcher-PXK4NS5F.js +23 -0
  179. package/dist/polymarket-watcher-VDJ4SVHP.js +23 -0
  180. package/dist/polymarket-watcher-W4BV6JTG.js +23 -0
  181. package/dist/runtime-22E2WCL6.js +46 -0
  182. package/dist/runtime-7GYS4FQU.js +46 -0
  183. package/dist/runtime-BR6K3Q3N.js +46 -0
  184. package/dist/runtime-CTTRDVJ6.js +46 -0
  185. package/dist/runtime-GIIPTHK5.js +46 -0
  186. package/dist/runtime-HYAKLZWI.js +46 -0
  187. package/dist/runtime-IQ2KIV2L.js +50 -0
  188. package/dist/runtime-ISXECIAB.js +46 -0
  189. package/dist/runtime-IV4BY7S4.js +46 -0
  190. package/dist/runtime-O65GGHL2.js +46 -0
  191. package/dist/runtime-PKHEGQYK.js +50 -0
  192. package/dist/runtime-RFKPIFK4.js +46 -0
  193. package/dist/runtime-S35B6PIY.js +46 -0
  194. package/dist/runtime-WEZJ4YRK.js +46 -0
  195. package/dist/runtime-WLWB62ZI.js +46 -0
  196. package/dist/screener-FB47G4YX.js +26 -0
  197. package/dist/screener-WQVQO4WF.js +26 -0
  198. package/dist/server-6GWGIGBH.js +36 -0
  199. package/dist/server-7VZ6XXBC.js +36 -0
  200. package/dist/server-7XBTD3FW.js +36 -0
  201. package/dist/server-BN56IMC4.js +36 -0
  202. package/dist/server-GD6SPDER.js +36 -0
  203. package/dist/server-IJHU2FIK.js +36 -0
  204. package/dist/server-J5WZGZX3.js +36 -0
  205. package/dist/server-JVUH2E3H.js +36 -0
  206. package/dist/server-MYXWTXSE.js +36 -0
  207. package/dist/server-ORGV7O7L.js +36 -0
  208. package/dist/server-QPE3WVUQ.js +36 -0
  209. package/dist/server-SUBGS5BJ.js +36 -0
  210. package/dist/server-SWAYJTFF.js +36 -0
  211. package/dist/server-TFIWDU2H.js +36 -0
  212. package/dist/server-VH4W6LWW.js +36 -0
  213. package/dist/server-X5UMJJ3J.js +36 -0
  214. package/dist/server-XOK5LHNU.js +36 -0
  215. package/dist/server-ZLK24KFY.js +36 -0
  216. package/dist/server-ZNSQGCRM.js +36 -0
  217. package/dist/setup-32ZRMW7R.js +20 -0
  218. package/dist/setup-3WF7PBIS.js +20 -0
  219. package/dist/setup-4TM64QG4.js +20 -0
  220. package/dist/setup-5SGUMKN7.js +20 -0
  221. package/dist/setup-AGYKOCIU.js +20 -0
  222. package/dist/setup-EIP4IHZN.js +20 -0
  223. package/dist/setup-F5SAGQJJ.js +20 -0
  224. package/dist/setup-LMF76UUM.js +20 -0
  225. package/dist/setup-MA5QR3J4.js +20 -0
  226. package/dist/setup-MLIPR2U3.js +20 -0
  227. package/dist/setup-MLIZYTT6.js +20 -0
  228. package/dist/setup-OPVZ3GM7.js +20 -0
  229. package/dist/setup-PWFHUXOK.js +20 -0
  230. package/dist/setup-QF5GCTPE.js +20 -0
  231. package/dist/setup-SGF4OX3A.js +20 -0
  232. package/dist/setup-TLWKGWC6.js +20 -0
  233. package/dist/setup-TYCRH63P.js +20 -0
  234. package/dist/setup-USUBKTVX.js +20 -0
  235. package/dist/setup-VMNTNEB4.js +20 -0
  236. package/dist/shared-S5ROHYCX.js +69 -0
  237. package/dist/shared-TLWZZZSK.js +69 -0
  238. package/dist/system-prompts-7ZRL27FN.js +69 -0
  239. package/dist/system-prompts-CNXUF2AV.js +69 -0
  240. package/dist/system-prompts-SYGQRBRG.js +69 -0
  241. package/logs/cloudflared-error.log +4 -89
  242. package/logs/cloudflared-error__2026-03-11_00-00-00.log +289 -0
  243. package/package.json +1 -1
  244. package/logs/cloudflared-error__2026-03-06_00-00-00.log +0 -245
@@ -0,0 +1,392 @@
1
+ import {
2
+ CLOB_API,
3
+ GAMMA_API,
4
+ apiFetch,
5
+ parallelFetch,
6
+ parseMarket
7
+ } from "./chunk-E5H64U5H.js";
8
+
9
+ // src/polymarket-engines/screener.ts
10
+ function scoreLiquidity(m) {
11
+ if (m.liquidity >= 1e5) return 20;
12
+ if (m.liquidity >= 5e4) return 18;
13
+ if (m.liquidity >= 2e4) return 15;
14
+ if (m.liquidity >= 1e4) return 12;
15
+ if (m.liquidity >= 5e3) return 8;
16
+ if (m.liquidity >= 1e3) return 4;
17
+ return 1;
18
+ }
19
+ function scoreVolume(m) {
20
+ if (m.volume >= 1e6) return 20;
21
+ if (m.volume >= 5e5) return 18;
22
+ if (m.volume >= 1e5) return 15;
23
+ if (m.volume >= 5e4) return 12;
24
+ if (m.volume >= 1e4) return 8;
25
+ if (m.volume >= 1e3) return 4;
26
+ return 1;
27
+ }
28
+ function scoreSpread(ob) {
29
+ if (!ob) return 5;
30
+ if (ob.spreadPct <= 1) return 15;
31
+ if (ob.spreadPct <= 2) return 13;
32
+ if (ob.spreadPct <= 3) return 11;
33
+ if (ob.spreadPct <= 5) return 8;
34
+ if (ob.spreadPct <= 10) return 4;
35
+ return 1;
36
+ }
37
+ function scoreEdge(m, ob) {
38
+ const prices = m.outcomePrices;
39
+ if (prices.length < 2) return { score: 0, type: null };
40
+ const yesP = prices[0];
41
+ const noP = prices[1];
42
+ const overround = (yesP + noP - 1) * 100;
43
+ let score = 0;
44
+ let type = null;
45
+ if (Math.abs(overround) > 3) {
46
+ score += Math.min(10, Math.abs(overround));
47
+ type = overround > 0 ? "negative_ev_market" : "positive_ev_market";
48
+ }
49
+ if (yesP > 0.92 || yesP < 0.08) {
50
+ score += 5;
51
+ type = type || "extreme_price";
52
+ }
53
+ if (ob && Math.abs(ob.imbalance) > 0.4) {
54
+ score += Math.min(8, Math.abs(ob.imbalance) * 10);
55
+ type = type || (ob.imbalance > 0 ? "bid_pressure" : "ask_pressure");
56
+ }
57
+ if (yesP >= 0.35 && yesP <= 0.65) {
58
+ score += 5;
59
+ type = type || "contested";
60
+ }
61
+ return { score: Math.min(25, score), type };
62
+ }
63
+ function scoreTiming(m) {
64
+ if (!m.endDate) return 3;
65
+ const hoursToClose = (new Date(m.endDate).getTime() - Date.now()) / 36e5;
66
+ if (hoursToClose <= 0) return 0;
67
+ if (hoursToClose <= 6) return 10;
68
+ if (hoursToClose <= 24) return 8;
69
+ if (hoursToClose <= 72) return 6;
70
+ if (hoursToClose <= 168) return 4;
71
+ return 2;
72
+ }
73
+ function scoreMomentum(m) {
74
+ if (m.liquidity === 0) return 0;
75
+ const turnover = m.volume / m.liquidity;
76
+ if (turnover >= 10) return 10;
77
+ if (turnover >= 5) return 8;
78
+ if (turnover >= 2) return 6;
79
+ if (turnover >= 1) return 4;
80
+ return 2;
81
+ }
82
+ function getPriceLevel(yesPrice) {
83
+ if (yesPrice >= 0.9) return "extreme_yes";
84
+ if (yesPrice <= 0.1) return "extreme_no";
85
+ if (yesPrice >= 0.65) return "leaning_yes";
86
+ if (yesPrice <= 0.35) return "leaning_no";
87
+ return "contested";
88
+ }
89
+ async function analyzeOrderbook(tokenId) {
90
+ try {
91
+ const book = await apiFetch(`${CLOB_API}/book?token_id=${tokenId}`, 8e3);
92
+ if (!book?.bids?.length && !book?.asks?.length) return null;
93
+ const bids = (book.bids || []).slice(0, 10);
94
+ const asks = (book.asks || []).slice(0, 10);
95
+ const bestBid = parseFloat(bids[0]?.price || "0");
96
+ const bestAsk = parseFloat(asks[0]?.price || "1");
97
+ const spread = bestAsk - bestBid;
98
+ const midpoint = (bestAsk + bestBid) / 2;
99
+ const bidDepth = bids.slice(0, 5).reduce((s, l) => s + parseFloat(l.price || "0") * parseFloat(l.size || "0"), 0);
100
+ const askDepth = asks.slice(0, 5).reduce((s, l) => s + parseFloat(l.price || "0") * parseFloat(l.size || "0"), 0);
101
+ const totalDepth = bidDepth + askDepth;
102
+ const imbalance = totalDepth > 0 ? (bidDepth - askDepth) / totalDepth : 0;
103
+ return {
104
+ bestBid,
105
+ bestAsk,
106
+ spread,
107
+ spreadPct: midpoint > 0 ? spread / midpoint * 100 : 100,
108
+ midpoint,
109
+ bidDepth: Math.round(bidDepth),
110
+ askDepth: Math.round(askDepth),
111
+ imbalance: parseFloat(imbalance.toFixed(3)),
112
+ topBidSize: parseFloat(bids[0]?.size || "0"),
113
+ topAskSize: parseFloat(asks[0]?.size || "0"),
114
+ levels: Math.max(bids.length, asks.length)
115
+ };
116
+ } catch {
117
+ return null;
118
+ }
119
+ }
120
+ function generateRecommendation(m, scores, analysis) {
121
+ const yesP = m.outcomePrices[0] || 0.5;
122
+ const noP = m.outcomePrices[1] || 0.5;
123
+ let action = "watch";
124
+ let side = yesP <= 0.5 ? "YES" : "NO";
125
+ let confidence = Math.min(95, scores.total);
126
+ let reasoning = "";
127
+ let suggestedSize = "small";
128
+ let entryPrice = yesP <= 0.5 ? yesP : noP;
129
+ let targetExit = 0;
130
+ if (scores.total >= 70) {
131
+ if (analysis.priceLevel === "contested") {
132
+ if (analysis.orderbook && analysis.orderbook.imbalance > 0.2) {
133
+ action = "buy_yes";
134
+ side = "YES";
135
+ reasoning = "Contested market with strong bid-side pressure. Orderbook imbalance suggests upward price movement.";
136
+ } else if (analysis.orderbook && analysis.orderbook.imbalance < -0.2) {
137
+ action = "buy_no";
138
+ side = "NO";
139
+ reasoning = "Contested market with strong ask-side pressure. Orderbook suggests downward movement.";
140
+ } else {
141
+ action = "watch";
142
+ reasoning = "High-quality contested market but no clear directional signal from orderbook.";
143
+ }
144
+ suggestedSize = "medium";
145
+ } else if (analysis.priceLevel === "extreme_yes") {
146
+ action = "buy_yes";
147
+ side = "YES";
148
+ reasoning = `Market at ${(yesP * 100).toFixed(0)}% \u2014 strong consensus. Buying YES for likely resolution. ${analysis.hoursToClose && analysis.hoursToClose < 48 ? "Closing soon adds urgency." : ""}`;
149
+ suggestedSize = scores.total >= 80 ? "large" : "medium";
150
+ targetExit = 0.99;
151
+ } else if (analysis.priceLevel === "extreme_no") {
152
+ action = "buy_no";
153
+ side = "NO";
154
+ reasoning = `Market at ${(yesP * 100).toFixed(0)}% YES \u2014 strong NO consensus. Buying NO for likely resolution.`;
155
+ suggestedSize = scores.total >= 80 ? "large" : "medium";
156
+ targetExit = 0.99;
157
+ }
158
+ } else if (scores.total >= 50) {
159
+ if (scores.edge >= 10) {
160
+ action = analysis.overround < 0 ? "buy_yes" : "buy_no";
161
+ side = analysis.overround < 0 ? "YES" : "NO";
162
+ reasoning = `Edge detected: ${analysis.edgeType}. Overround ${analysis.overround.toFixed(1)}%.`;
163
+ suggestedSize = "small";
164
+ } else if (analysis.hoursToClose && analysis.hoursToClose < 24 && scores.volume >= 10) {
165
+ action = yesP > 0.7 ? "buy_yes" : yesP < 0.3 ? "buy_no" : "watch";
166
+ side = yesP > 0.5 ? "YES" : "NO";
167
+ reasoning = `Closing in ${analysis.hoursToClose.toFixed(0)}h with high volume. Price likely to converge to outcome.`;
168
+ suggestedSize = "small";
169
+ }
170
+ }
171
+ if (action === "watch") {
172
+ reasoning = reasoning || `Scores: liquidity=${scores.liquidity}, volume=${scores.volume}, spread=${scores.spread}, edge=${scores.edge}. No strong signal yet.`;
173
+ }
174
+ entryPrice = side === "YES" ? yesP : noP;
175
+ if (!targetExit) {
176
+ targetExit = side === "YES" ? Math.min(0.99, yesP + 0.1) : Math.min(0.99, noP + 0.1);
177
+ }
178
+ return { action, side, confidence, reasoning, suggestedSize, entryPrice, targetExit };
179
+ }
180
+ async function screenMarkets(opts = {}) {
181
+ const strategy = opts.strategy || "best_opportunities";
182
+ const limit = opts.limit || 15;
183
+ const fetchParams = {
184
+ active: "true",
185
+ closed: "false",
186
+ limit: "100"
187
+ };
188
+ switch (strategy) {
189
+ case "high_volume":
190
+ fetchParams.order = "volume";
191
+ fetchParams.ascending = "false";
192
+ break;
193
+ case "closing_soon": {
194
+ fetchParams.order = "end_date";
195
+ fetchParams.ascending = "true";
196
+ fetchParams.end_date_min = (/* @__PURE__ */ new Date()).toISOString();
197
+ fetchParams.limit = "200";
198
+ if (!opts.hoursToClose) opts.hoursToClose = 168;
199
+ break;
200
+ }
201
+ case "new_markets":
202
+ fetchParams.order = "startDate";
203
+ fetchParams.ascending = "false";
204
+ break;
205
+ default:
206
+ fetchParams.order = "volume";
207
+ fetchParams.ascending = "false";
208
+ break;
209
+ }
210
+ if (opts.categories?.length) fetchParams.tag = opts.categories[0];
211
+ if (opts.query) fetchParams.search = opts.query;
212
+ let allMarkets = [];
213
+ const fetches = [];
214
+ fetches.push((async () => {
215
+ try {
216
+ const raw = await apiFetch(`${GAMMA_API}/markets?${new URLSearchParams(fetchParams)}`);
217
+ if (Array.isArray(raw)) allMarkets.push(...raw);
218
+ } catch {
219
+ }
220
+ })());
221
+ fetches.push((async () => {
222
+ try {
223
+ const evParams = { active: "true", closed: "false", limit: "100", order: fetchParams.order || "volume", ascending: fetchParams.ascending || "false" };
224
+ if (opts.query) evParams.search = opts.query;
225
+ if (opts.categories?.length) evParams.tag_id = opts.categories[0];
226
+ const events = await apiFetch(`${GAMMA_API}/events?${new URLSearchParams(evParams)}`);
227
+ if (Array.isArray(events)) {
228
+ for (const ev of events) {
229
+ if (ev.markets && Array.isArray(ev.markets)) {
230
+ for (const m of ev.markets) {
231
+ if (m.active && !m.closed) allMarkets.push(m);
232
+ }
233
+ }
234
+ }
235
+ }
236
+ } catch {
237
+ }
238
+ })());
239
+ if (!opts.query && (strategy === "best_opportunities" || strategy === "high_volume")) {
240
+ fetches.push((async () => {
241
+ try {
242
+ const divEvParams = { active: "true", closed: "false", limit: "50", order: "liquidity", ascending: "false" };
243
+ const events2 = await apiFetch(`${GAMMA_API}/events?${new URLSearchParams(divEvParams)}`);
244
+ if (Array.isArray(events2)) {
245
+ for (const ev of events2) {
246
+ if (ev.markets && Array.isArray(ev.markets)) {
247
+ for (const m of ev.markets) {
248
+ if (m.active && !m.closed) allMarkets.push(m);
249
+ }
250
+ }
251
+ }
252
+ }
253
+ } catch {
254
+ }
255
+ })());
256
+ fetches.push((async () => {
257
+ try {
258
+ const diverseParams = { ...fetchParams, order: "liquidity", limit: "50" };
259
+ const raw2 = await apiFetch(`${GAMMA_API}/markets?${new URLSearchParams(diverseParams)}`);
260
+ if (Array.isArray(raw2)) allMarkets.push(...raw2);
261
+ } catch {
262
+ }
263
+ })());
264
+ }
265
+ await Promise.all(fetches);
266
+ if (allMarkets.length === 0) {
267
+ return { strategy, scanned: 0, qualified: 0, markets: [], summary: "No markets found" };
268
+ }
269
+ const seen = /* @__PURE__ */ new Set();
270
+ allMarkets = allMarkets.filter((m) => {
271
+ const key = m.conditionId || m.id;
272
+ if (seen.has(key)) return false;
273
+ seen.add(key);
274
+ return true;
275
+ });
276
+ if (opts.extraMarkets?.length) {
277
+ const existingIds = new Set(allMarkets.map((m) => m.conditionId || m.id));
278
+ for (const m of opts.extraMarkets) {
279
+ if (!existingIds.has(m.conditionId || m.id)) {
280
+ allMarkets.push(m);
281
+ existingIds.add(m.conditionId || m.id);
282
+ }
283
+ }
284
+ }
285
+ let parsed = allMarkets.map(parseMarket).filter((m) => {
286
+ if (!m.active || m.clobTokenIds.length === 0) return false;
287
+ if (m.endDate && new Date(m.endDate).getTime() < Date.now()) return false;
288
+ if (m.liquidity < 1) return false;
289
+ return true;
290
+ });
291
+ if (opts.minVolume) parsed = parsed.filter((m) => m.volume >= opts.minVolume);
292
+ if (opts.minLiquidity) parsed = parsed.filter((m) => m.liquidity >= opts.minLiquidity);
293
+ if (opts.hoursToClose) {
294
+ parsed = parsed.filter((m) => {
295
+ if (!m.endDate) return false;
296
+ const h = (new Date(m.endDate).getTime() - Date.now()) / 36e5;
297
+ return h > 0 && h <= opts.hoursToClose;
298
+ });
299
+ }
300
+ if (strategy === "contested") parsed = parsed.filter((m) => m.outcomePrices[0] >= 0.3 && m.outcomePrices[0] <= 0.7);
301
+ else if (strategy === "safe_bets") parsed = parsed.filter((m) => m.outcomePrices[0] >= 0.85 || m.outcomePrices[0] <= 0.15);
302
+ else if (strategy === "mispriced") parsed = parsed.filter((m) => Math.abs(m.outcomePrices.reduce((a, b) => a + b, 0) - 1) > 0.02);
303
+ parsed.sort((a, b) => b.volume * b.liquidity - a.volume * a.liquidity);
304
+ const topCandidates = parsed.slice(0, opts.includeOrderbook ? Math.min(30, parsed.length) : 0);
305
+ const orderbookMap = /* @__PURE__ */ new Map();
306
+ if (opts.includeOrderbook !== false && topCandidates.length > 0) {
307
+ const obResults = await parallelFetch(
308
+ topCandidates,
309
+ async (m) => {
310
+ const tokenId = m.clobTokenIds[0];
311
+ if (!tokenId) return { id: m.id, ob: null };
312
+ const ob = await analyzeOrderbook(tokenId);
313
+ return { id: m.id, ob };
314
+ },
315
+ 5
316
+ );
317
+ for (const r of obResults) orderbookMap.set(r.id, r.ob);
318
+ }
319
+ const scored = parsed.map((m) => {
320
+ const ob = orderbookMap.get(m.id) || null;
321
+ const liquidityScore = scoreLiquidity(m);
322
+ const volumeScore = scoreVolume(m);
323
+ const spreadScore = scoreSpread(ob);
324
+ const { score: edgeScore, type: edgeType } = scoreEdge(m, ob);
325
+ const timingScore = scoreTiming(m);
326
+ const momentumScore = scoreMomentum(m);
327
+ const total = liquidityScore + volumeScore + spreadScore + edgeScore + timingScore + momentumScore;
328
+ const yesP = m.outcomePrices[0] || 0.5;
329
+ const noP = m.outcomePrices[1] || 0.5;
330
+ const overround = (yesP + noP - 1) * 100;
331
+ const hoursToClose = m.endDate ? (new Date(m.endDate).getTime() - Date.now()) / 36e5 : null;
332
+ const scores = { total, liquidity: liquidityScore, volume: volumeScore, spread: spreadScore, edge: edgeScore, timing: timingScore, momentum: momentumScore };
333
+ const analysis = {
334
+ overround,
335
+ hoursToClose,
336
+ volumePerHour: m.startDate ? m.volume / Math.max(1, (Date.now() - new Date(m.startDate).getTime()) / 36e5) : 0,
337
+ priceLevel: getPriceLevel(yesP),
338
+ edgeType,
339
+ orderbook: ob || void 0
340
+ };
341
+ const recommendation = generateRecommendation(m, scores, analysis);
342
+ return { market: m, scores, analysis, recommendation };
343
+ });
344
+ switch (strategy) {
345
+ case "high_volume":
346
+ scored.sort((a, b) => b.market.volume - a.market.volume);
347
+ break;
348
+ case "closing_soon":
349
+ scored.sort((a, b) => (a.analysis.hoursToClose || 9999) - (b.analysis.hoursToClose || 9999));
350
+ break;
351
+ case "mispriced":
352
+ scored.sort((a, b) => b.scores.edge - a.scores.edge);
353
+ break;
354
+ case "safe_bets":
355
+ scored.sort((a, b) => {
356
+ const aConf = Math.max(a.market.outcomePrices[0], a.market.outcomePrices[1] || 0);
357
+ const bConf = Math.max(b.market.outcomePrices[0], b.market.outcomePrices[1] || 0);
358
+ return bConf - aConf;
359
+ });
360
+ break;
361
+ case "momentum":
362
+ scored.sort((a, b) => b.scores.momentum - a.scores.momentum);
363
+ break;
364
+ default:
365
+ scored.sort((a, b) => b.scores.total - a.scores.total);
366
+ }
367
+ let filtered = scored;
368
+ if (opts.maxPrice) filtered = filtered.filter((s) => s.recommendation.entryPrice <= opts.maxPrice);
369
+ if (opts.minEdgeScore) filtered = filtered.filter((s) => s.scores.edge >= opts.minEdgeScore);
370
+ if (opts.maxSpreadPct) filtered = filtered.filter((s) => !s.analysis.orderbook || s.analysis.orderbook.spreadPct <= opts.maxSpreadPct);
371
+ const final = filtered.slice(0, limit);
372
+ const actionable = final.filter((s) => s.recommendation.action !== "watch" && s.recommendation.action !== "avoid");
373
+ const summary = [
374
+ `Screened ${parsed.length} markets using "${strategy}" strategy.`,
375
+ `${final.length} passed filters.`,
376
+ actionable.length > 0 ? `${actionable.length} actionable: ${actionable.map((s) => `${s.recommendation.action} "${s.market.question.substring(0, 50)}" @ ${(s.recommendation.entryPrice * 100).toFixed(0)}\xA2`).join("; ")}` : "No strong signals right now \u2014 market conditions may be quiet."
377
+ ].join(" ");
378
+ return { strategy, scanned: parsed.length, qualified: final.length, markets: final, summary };
379
+ }
380
+
381
+ export {
382
+ scoreLiquidity,
383
+ scoreVolume,
384
+ scoreSpread,
385
+ scoreEdge,
386
+ scoreTiming,
387
+ scoreMomentum,
388
+ getPriceLevel,
389
+ analyzeOrderbook,
390
+ generateRecommendation,
391
+ screenMarkets
392
+ };