@reefclaw/openclaw-plugin 0.1.47 → 0.1.49

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 (43) hide show
  1. package/bridge/bridge.d.ts +39 -0
  2. package/bridge/bridge.js +229 -20
  3. package/bridge/gateway/heartbeat-cron.d.ts +64 -0
  4. package/bridge/gateway/heartbeat-cron.js +153 -3
  5. package/bridge/heartbeat-runs.d.ts +6 -0
  6. package/bridge/heartbeat-runs.js +43 -1
  7. package/bridge/index.js +3 -0
  8. package/bridge/provider.d.ts +12 -0
  9. package/bridge/providers/connector-update.js +20 -2
  10. package/bridge/providers/gateway.d.ts +21 -0
  11. package/bridge/providers/gateway.js +121 -9
  12. package/bridge/shock-wake.js +12 -2
  13. package/bridge/types.d.ts +17 -0
  14. package/bridge/utils/skill-version.d.ts +6 -0
  15. package/bridge/utils/skill-version.js +10 -0
  16. package/bridge/utils/webapp-edge.d.ts +145 -0
  17. package/bridge/utils/webapp-edge.js +366 -0
  18. package/config/agent-config-client.js +18 -2
  19. package/config/agent-config-poller.d.ts +4 -0
  20. package/config/agent-config-poller.js +46 -6
  21. package/http/webapp-edge.d.ts +116 -0
  22. package/http/webapp-edge.js +313 -0
  23. package/index.js +7 -0
  24. package/ingest/position-decisions-client.js +28 -7
  25. package/ingest/readiness-reporter.d.ts +13 -0
  26. package/ingest/readiness-reporter.js +78 -8
  27. package/ingest/trade-store-client.js +25 -4
  28. package/openclaw.plugin.json +1 -1
  29. package/package.json +1 -1
  30. package/release-integrity.json +10 -0
  31. package/release-notes.json +3 -1
  32. package/signals/stop-rules.d.ts +13 -0
  33. package/signals/stop-rules.js +35 -6
  34. package/signals/strategy-adapter.js +25 -6
  35. package/skills/reefclaw/SKILL.md +1 -1
  36. package/tools/assessment-validation.d.ts +10 -2
  37. package/tools/assessment-validation.js +19 -5
  38. package/tools/create-order.d.ts +4 -0
  39. package/tools/create-order.js +15 -0
  40. package/tools/get-market-intel.d.ts +3 -0
  41. package/tools/get-market-intel.js +24 -1
  42. package/tools/intel-cache.d.ts +14 -0
  43. package/tools/intel-cache.js +59 -0
@@ -146,3 +146,62 @@ export const __testing__ = {
146
146
  symbolFactCache.clear();
147
147
  },
148
148
  };
149
+ /** Last-known-good ATR per intel symbol. The fact cache is only 30 s and the
150
+ * LLM's gap between scan_pairs and create_order is usually longer, so most
151
+ * entries would miss it and race a network fetch; ATR(14) on 1h bars barely
152
+ * moves in 30 minutes, so a recent value is a better floor input than none. */
153
+ const atrLastKnownGood = new Map();
154
+ const ATR_LKG_TTL_MS = 30 * 60_000;
155
+ /** Give the fact fetch this long before falling back to the last-known-good
156
+ * value; the fetch keeps running and warms the cache for the next call. */
157
+ const ATR_FETCH_BUDGET_MS = 1_500;
158
+ export function _resetAtrLastKnownGoodForTests() {
159
+ atrLastKnownGood.clear();
160
+ }
161
+ /** ATR(14) for the symbol (price units), for create_order's stop-distance
162
+ * floor. Venue-aware symbol resolution mirrors get_setup_detail (the raw
163
+ * 'AVAX/USDC' form never hits the HL_ cache key). Order of preference:
164
+ * a fact returned within the budget → its atr14 (and remember it);
165
+ * otherwise the last-known-good value if younger than 30 min; otherwise
166
+ * null — the caller fails open to the fixed 30 bps floor. Never throws. */
167
+ export async function readAtr14FromFacts(rawSymbol, deps, opts = {}) {
168
+ const now = opts.now ?? Date.now;
169
+ const budgetMs = opts.budgetMs ?? ATR_FETCH_BUDGET_MS;
170
+ const getFact = opts.getFact ?? getFactBySymbolCached;
171
+ let symbol;
172
+ try {
173
+ symbol = (deps.venue ?? 'binance') === 'hyperliquid'
174
+ ? resolveIntelSymbol(deps, rawSymbol)
175
+ : String(rawSymbol ?? '').toUpperCase().replace(/[^A-Z0-9]/g, '');
176
+ }
177
+ catch {
178
+ return null;
179
+ }
180
+ const fromLkg = () => {
181
+ const lkg = atrLastKnownGood.get(symbol);
182
+ return lkg && now() - lkg.at <= ATR_LKG_TTL_MS ? lkg.atr : null;
183
+ };
184
+ try {
185
+ const fetch = Promise.resolve().then(() => getFact(symbol, deps)).then((fact) => {
186
+ if ('error' in fact)
187
+ return null;
188
+ const raw = fact.indicators?.atr14;
189
+ const n = typeof raw === 'number' ? raw : typeof raw === 'string' ? Number(raw) : Number.NaN;
190
+ if (!Number.isFinite(n) || n <= 0)
191
+ return null;
192
+ atrLastKnownGood.set(symbol, { atr: n, at: now() });
193
+ return n;
194
+ }).catch(() => null);
195
+ let timer;
196
+ const budget = new Promise((resolve) => { timer = setTimeout(() => resolve('timeout'), budgetMs); timer.unref?.(); });
197
+ const raced = await Promise.race([fetch, budget]);
198
+ if (timer)
199
+ clearTimeout(timer);
200
+ if (raced === 'timeout')
201
+ return fromLkg();
202
+ return raced ?? fromLkg();
203
+ }
204
+ catch {
205
+ return fromLkg();
206
+ }
207
+ }