opencandle 0.4.0 → 0.6.0
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.
- package/LICENSE +1 -1
- package/README.md +186 -117
- package/dist/analysts/contracts.d.ts +1 -3
- package/dist/analysts/contracts.js +1 -11
- package/dist/analysts/contracts.js.map +1 -1
- package/dist/analysts/orchestrator.d.ts +1 -3
- package/dist/analysts/orchestrator.js +1 -26
- package/dist/analysts/orchestrator.js.map +1 -1
- package/dist/cli.js +32 -8
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +19 -3
- package/dist/config.js +69 -3
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/infra/browser.d.ts +1 -3
- package/dist/infra/browser.js +4 -2
- package/dist/infra/browser.js.map +1 -1
- package/dist/infra/cache.d.ts +8 -11
- package/dist/infra/cache.js +17 -15
- package/dist/infra/cache.js.map +1 -1
- package/dist/infra/http-client.d.ts +4 -1
- package/dist/infra/http-client.js +59 -6
- package/dist/infra/http-client.js.map +1 -1
- package/dist/infra/index.d.ts +3 -3
- package/dist/infra/index.js +3 -3
- package/dist/infra/index.js.map +1 -1
- package/dist/infra/native-dependencies.js +2 -2
- package/dist/infra/native-dependencies.js.map +1 -1
- package/dist/infra/node-version.js.map +1 -1
- package/dist/infra/opencandle-paths.d.ts +0 -3
- package/dist/infra/opencandle-paths.js +4 -11
- package/dist/infra/opencandle-paths.js.map +1 -1
- package/dist/infra/rate-limiter.d.ts +4 -0
- package/dist/infra/rate-limiter.js +17 -10
- package/dist/infra/rate-limiter.js.map +1 -1
- package/dist/market-state/alert-conditions.d.ts +34 -0
- package/dist/market-state/alert-conditions.js +23 -0
- package/dist/market-state/alert-conditions.js.map +1 -0
- package/dist/market-state/alert-runner.d.ts +55 -0
- package/dist/market-state/alert-runner.js +634 -0
- package/dist/market-state/alert-runner.js.map +1 -0
- package/dist/market-state/daily-report.d.ts +26 -0
- package/dist/market-state/daily-report.js +179 -0
- package/dist/market-state/daily-report.js.map +1 -0
- package/dist/market-state/local-automation-service.d.ts +25 -0
- package/dist/market-state/local-automation-service.js +119 -0
- package/dist/market-state/local-automation-service.js.map +1 -0
- package/dist/market-state/notification-delivery.d.ts +14 -0
- package/dist/market-state/notification-delivery.js +139 -0
- package/dist/market-state/notification-delivery.js.map +1 -0
- package/dist/market-state/resolve-for-mutation.d.ts +10 -0
- package/dist/market-state/resolve-for-mutation.js +15 -0
- package/dist/market-state/resolve-for-mutation.js.map +1 -0
- package/dist/market-state/resolve.d.ts +14 -0
- package/dist/market-state/resolve.js +89 -0
- package/dist/market-state/resolve.js.map +1 -0
- package/dist/market-state/service.d.ts +527 -0
- package/dist/market-state/service.js +1099 -0
- package/dist/market-state/service.js.map +1 -0
- package/dist/memory/index.d.ts +7 -7
- package/dist/memory/index.js +6 -6
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/manager.d.ts +9 -0
- package/dist/memory/manager.js +39 -22
- package/dist/memory/manager.js.map +1 -1
- package/dist/memory/retrieval.js +7 -4
- package/dist/memory/retrieval.js.map +1 -1
- package/dist/memory/sqlite.js +385 -3
- package/dist/memory/sqlite.js.map +1 -1
- package/dist/memory/storage.d.ts +3 -2
- package/dist/memory/storage.js +1 -2
- package/dist/memory/storage.js.map +1 -1
- package/dist/memory/tool-defaults.js +64 -28
- package/dist/memory/tool-defaults.js.map +1 -1
- package/dist/memory/types.js +4 -0
- package/dist/memory/types.js.map +1 -1
- package/dist/monitor.d.ts +2 -0
- package/dist/monitor.js +104 -0
- package/dist/monitor.js.map +1 -0
- package/dist/onboarding/connect.js +4 -6
- package/dist/onboarding/connect.js.map +1 -1
- package/dist/onboarding/credential-interceptor.js +1 -1
- package/dist/onboarding/credential-interceptor.js.map +1 -1
- package/dist/onboarding/degradation-accumulator.js +1 -3
- package/dist/onboarding/degradation-accumulator.js.map +1 -1
- package/dist/onboarding/providers.js +3 -16
- package/dist/onboarding/providers.js.map +1 -1
- package/dist/onboarding/state.js.map +1 -1
- package/dist/onboarding/tool-helpers.js +1 -1
- package/dist/onboarding/tool-helpers.js.map +1 -1
- package/dist/onboarding/tool-tags.js +6 -4
- package/dist/onboarding/tool-tags.js.map +1 -1
- package/dist/onboarding/validation.js +1 -1
- package/dist/onboarding/validation.js.map +1 -1
- package/dist/pi/opencandle-extension.d.ts +8 -0
- package/dist/pi/opencandle-extension.js +637 -59
- package/dist/pi/opencandle-extension.js.map +1 -1
- package/dist/pi/session.d.ts +1 -1
- package/dist/pi/session.js +3 -1
- package/dist/pi/session.js.map +1 -1
- package/dist/pi/setup.js +17 -2
- package/dist/pi/setup.js.map +1 -1
- package/dist/pi/tool-adapter.js +5 -2
- package/dist/pi/tool-adapter.js.map +1 -1
- package/dist/prompts/context-builder.d.ts +18 -3
- package/dist/prompts/context-builder.js +117 -18
- package/dist/prompts/context-builder.js.map +1 -1
- package/dist/prompts/disclaimer.js +1 -1
- package/dist/prompts/disclaimer.js.map +1 -1
- package/dist/prompts/policy-cards.d.ts +13 -0
- package/dist/prompts/policy-cards.js +197 -0
- package/dist/prompts/policy-cards.js.map +1 -0
- package/dist/prompts/sections.d.ts +1 -1
- package/dist/prompts/sections.js +3 -3
- package/dist/prompts/sections.js.map +1 -1
- package/dist/prompts/symbol-preflight.d.ts +20 -0
- package/dist/prompts/symbol-preflight.js +49 -0
- package/dist/prompts/symbol-preflight.js.map +1 -0
- package/dist/prompts/workflow-prompts.d.ts +1 -1
- package/dist/prompts/workflow-prompts.js +209 -19
- package/dist/prompts/workflow-prompts.js.map +1 -1
- package/dist/providers/alpha-vantage.d.ts +1 -1
- package/dist/providers/alpha-vantage.js +49 -8
- package/dist/providers/alpha-vantage.js.map +1 -1
- package/dist/providers/coingecko.js +1 -1
- package/dist/providers/coingecko.js.map +1 -1
- package/dist/providers/errors.d.ts +5 -0
- package/dist/providers/errors.js +11 -0
- package/dist/providers/errors.js.map +1 -0
- package/dist/providers/exa-search.d.ts +2 -2
- package/dist/providers/exa-search.js +19 -11
- package/dist/providers/exa-search.js.map +1 -1
- package/dist/providers/fear-greed.js +1 -1
- package/dist/providers/fear-greed.js.map +1 -1
- package/dist/providers/finnhub.js +3 -5
- package/dist/providers/finnhub.js.map +1 -1
- package/dist/providers/fred.js +2 -2
- package/dist/providers/fred.js.map +1 -1
- package/dist/providers/index.d.ts +7 -6
- package/dist/providers/index.js +6 -5
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/reddit.js +2 -2
- package/dist/providers/reddit.js.map +1 -1
- package/dist/providers/sec-edgar.d.ts +9 -1
- package/dist/providers/sec-edgar.js +181 -6
- package/dist/providers/sec-edgar.js.map +1 -1
- package/dist/providers/tradingview.d.ts +47 -0
- package/dist/providers/tradingview.js +275 -0
- package/dist/providers/tradingview.js.map +1 -0
- package/dist/providers/twitter.js +6 -8
- package/dist/providers/twitter.js.map +1 -1
- package/dist/providers/web-search.js +26 -12
- package/dist/providers/web-search.js.map +1 -1
- package/dist/providers/with-fallback.js +4 -2
- package/dist/providers/with-fallback.js.map +1 -1
- package/dist/providers/wrap-provider.d.ts +2 -3
- package/dist/providers/wrap-provider.js +14 -8
- package/dist/providers/wrap-provider.js.map +1 -1
- package/dist/providers/yahoo-finance.d.ts +3 -1
- package/dist/providers/yahoo-finance.js +226 -11
- package/dist/providers/yahoo-finance.js.map +1 -1
- package/dist/routing/classify-intent.d.ts +9 -0
- package/dist/routing/classify-intent.js +153 -3
- package/dist/routing/classify-intent.js.map +1 -1
- package/dist/routing/defaults.d.ts +1 -1
- package/dist/routing/defaults.js +3 -3
- package/dist/routing/defaults.js.map +1 -1
- package/dist/routing/entity-extractor.d.ts +2 -0
- package/dist/routing/entity-extractor.js +377 -26
- package/dist/routing/entity-extractor.js.map +1 -1
- package/dist/routing/fund-symbols.d.ts +2 -0
- package/dist/routing/fund-symbols.js +55 -0
- package/dist/routing/fund-symbols.js.map +1 -0
- package/dist/routing/horizon.d.ts +1 -0
- package/dist/routing/horizon.js +10 -0
- package/dist/routing/horizon.js.map +1 -0
- package/dist/routing/index.d.ts +12 -6
- package/dist/routing/index.js +8 -4
- package/dist/routing/index.js.map +1 -1
- package/dist/routing/legacy-rule-router.d.ts +9 -0
- package/dist/routing/legacy-rule-router.js +12 -0
- package/dist/routing/legacy-rule-router.js.map +1 -0
- package/dist/routing/planning.d.ts +54 -0
- package/dist/routing/planning.js +562 -0
- package/dist/routing/planning.js.map +1 -0
- package/dist/routing/route-manifest.d.ts +35 -0
- package/dist/routing/route-manifest.js +242 -0
- package/dist/routing/route-manifest.js.map +1 -0
- package/dist/routing/router-llm-client.js.map +1 -1
- package/dist/routing/router-prompt.js +46 -45
- package/dist/routing/router-prompt.js.map +1 -1
- package/dist/routing/router-types.d.ts +10 -0
- package/dist/routing/router.d.ts +1 -0
- package/dist/routing/router.js +572 -13
- package/dist/routing/router.js.map +1 -1
- package/dist/routing/slot-resolver.d.ts +1 -1
- package/dist/routing/slot-resolver.js +45 -7
- package/dist/routing/slot-resolver.js.map +1 -1
- package/dist/routing/symbol-disambiguator.d.ts +11 -0
- package/dist/routing/symbol-disambiguator.js +52 -0
- package/dist/routing/symbol-disambiguator.js.map +1 -0
- package/dist/routing/turn-context.d.ts +44 -0
- package/dist/routing/turn-context.js +45 -0
- package/dist/routing/turn-context.js.map +1 -0
- package/dist/routing/types.d.ts +15 -1
- package/dist/runtime/answer-contracts.d.ts +82 -0
- package/dist/runtime/answer-contracts.js +442 -0
- package/dist/runtime/answer-contracts.js.map +1 -0
- package/dist/runtime/artifact-contracts.d.ts +14 -0
- package/dist/runtime/artifact-contracts.js +57 -0
- package/dist/runtime/artifact-contracts.js.map +1 -0
- package/dist/runtime/planning-evidence.d.ts +99 -0
- package/dist/runtime/planning-evidence.js +466 -0
- package/dist/runtime/planning-evidence.js.map +1 -0
- package/dist/runtime/prompt-step.d.ts +1 -9
- package/dist/runtime/prompt-step.js +0 -10
- package/dist/runtime/prompt-step.js.map +1 -1
- package/dist/runtime/run-context.d.ts +5 -2
- package/dist/runtime/run-context.js +8 -1
- package/dist/runtime/run-context.js.map +1 -1
- package/dist/runtime/session-coordinator.d.ts +29 -3
- package/dist/runtime/session-coordinator.js +204 -31
- package/dist/runtime/session-coordinator.js.map +1 -1
- package/dist/runtime/session-title.d.ts +14 -0
- package/dist/runtime/session-title.js +50 -0
- package/dist/runtime/session-title.js.map +1 -0
- package/dist/runtime/tool-defaults-wrapper.js +1 -3
- package/dist/runtime/tool-defaults-wrapper.js.map +1 -1
- package/dist/runtime/validation.js.map +1 -1
- package/dist/runtime/workflow-events.js.map +1 -1
- package/dist/runtime/workflow-runner.d.ts +3 -3
- package/dist/runtime/workflow-runner.js +1 -1
- package/dist/runtime/workflow-runner.js.map +1 -1
- package/dist/sentiment/adapters/finnhub.d.ts +1 -1
- package/dist/sentiment/adapters/finnhub.js +6 -1
- package/dist/sentiment/adapters/finnhub.js.map +1 -1
- package/dist/sentiment/adapters/reddit.d.ts +2 -2
- package/dist/sentiment/adapters/twitter.d.ts +1 -1
- package/dist/sentiment/adapters/web.d.ts +1 -1
- package/dist/sentiment/index.d.ts +9 -11
- package/dist/sentiment/index.js +9 -20
- package/dist/sentiment/index.js.map +1 -1
- package/dist/sentiment/keywords.js +26 -4
- package/dist/sentiment/keywords.js.map +1 -1
- package/dist/sentiment/pipeline.d.ts +2 -2
- package/dist/sentiment/pipeline.js +1 -1
- package/dist/sentiment/pipeline.js.map +1 -1
- package/dist/sentiment/scorer.js +1 -1
- package/dist/sentiment/store.d.ts +1 -1
- package/dist/sentiment/store.js +1 -1
- package/dist/sentiment/store.js.map +1 -1
- package/dist/sentiment/trends.d.ts +1 -1
- package/dist/sentiment/trends.js.map +1 -1
- package/dist/sentiment/types.js.map +1 -1
- package/dist/system-prompt.js +7 -3
- package/dist/system-prompt.js.map +1 -1
- package/dist/tool-kit.d.ts +7 -7
- package/dist/tool-kit.js +4 -4
- package/dist/tool-kit.js.map +1 -1
- package/dist/tools/fundamentals/company-overview.js +12 -7
- package/dist/tools/fundamentals/company-overview.js.map +1 -1
- package/dist/tools/fundamentals/comps.js +19 -10
- package/dist/tools/fundamentals/comps.js.map +1 -1
- package/dist/tools/fundamentals/dcf.js +24 -12
- package/dist/tools/fundamentals/dcf.js.map +1 -1
- package/dist/tools/fundamentals/earnings.js +9 -4
- package/dist/tools/fundamentals/earnings.js.map +1 -1
- package/dist/tools/fundamentals/financials.js +9 -4
- package/dist/tools/fundamentals/financials.js.map +1 -1
- package/dist/tools/fundamentals/sec-filings.d.ts +1 -0
- package/dist/tools/fundamentals/sec-filings.js +36 -4
- package/dist/tools/fundamentals/sec-filings.js.map +1 -1
- package/dist/tools/index.d.ts +23 -18
- package/dist/tools/index.js +53 -38
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/interaction/ask-user.js +15 -3
- package/dist/tools/interaction/ask-user.js.map +1 -1
- package/dist/tools/interaction/twitter-login.js +13 -3
- package/dist/tools/interaction/twitter-login.js.map +1 -1
- package/dist/tools/macro/fear-greed.js +1 -1
- package/dist/tools/macro/fear-greed.js.map +1 -1
- package/dist/tools/macro/fred-data.d.ts +1 -1
- package/dist/tools/macro/fred-data.js +44 -9
- package/dist/tools/macro/fred-data.js.map +1 -1
- package/dist/tools/market/crypto-history.js +21 -3
- package/dist/tools/market/crypto-history.js.map +1 -1
- package/dist/tools/market/crypto-price.js +4 -2
- package/dist/tools/market/crypto-price.js.map +1 -1
- package/dist/tools/market/screen-stocks.d.ts +18 -0
- package/dist/tools/market/screen-stocks.js +252 -0
- package/dist/tools/market/screen-stocks.js.map +1 -0
- package/dist/tools/market/search-ticker.js +161 -9
- package/dist/tools/market/search-ticker.js.map +1 -1
- package/dist/tools/market/stock-history.d.ts +2 -2
- package/dist/tools/market/stock-history.js +27 -8
- package/dist/tools/market/stock-history.js.map +1 -1
- package/dist/tools/market/stock-quote.js +6 -4
- package/dist/tools/market/stock-quote.js.map +1 -1
- package/dist/tools/options/greeks.js +1 -2
- package/dist/tools/options/greeks.js.map +1 -1
- package/dist/tools/options/option-chain.js +27 -9
- package/dist/tools/options/option-chain.js.map +1 -1
- package/dist/tools/portfolio/alerts.d.ts +15 -0
- package/dist/tools/portfolio/alerts.js +357 -0
- package/dist/tools/portfolio/alerts.js.map +1 -0
- package/dist/tools/portfolio/correlation.d.ts +1 -1
- package/dist/tools/portfolio/correlation.js +34 -14
- package/dist/tools/portfolio/correlation.js.map +1 -1
- package/dist/tools/portfolio/daily-report.d.ts +8 -0
- package/dist/tools/portfolio/daily-report.js +83 -0
- package/dist/tools/portfolio/daily-report.js.map +1 -0
- package/dist/tools/portfolio/holdings-overlap.d.ts +8 -0
- package/dist/tools/portfolio/holdings-overlap.js +112 -0
- package/dist/tools/portfolio/holdings-overlap.js.map +1 -0
- package/dist/tools/portfolio/notifications.d.ts +7 -0
- package/dist/tools/portfolio/notifications.js +43 -0
- package/dist/tools/portfolio/notifications.js.map +1 -0
- package/dist/tools/portfolio/predictions.d.ts +12 -6
- package/dist/tools/portfolio/predictions.js +338 -88
- package/dist/tools/portfolio/predictions.js.map +1 -1
- package/dist/tools/portfolio/risk-analysis.d.ts +1 -1
- package/dist/tools/portfolio/risk-analysis.js +46 -7
- package/dist/tools/portfolio/risk-analysis.js.map +1 -1
- package/dist/tools/portfolio/tracker.d.ts +4 -3
- package/dist/tools/portfolio/tracker.js +247 -102
- package/dist/tools/portfolio/tracker.js.map +1 -1
- package/dist/tools/portfolio/watchlist.d.ts +6 -4
- package/dist/tools/portfolio/watchlist.js +209 -101
- package/dist/tools/portfolio/watchlist.js.map +1 -1
- package/dist/tools/sentiment/reddit-sentiment.js +24 -11
- package/dist/tools/sentiment/reddit-sentiment.js.map +1 -1
- package/dist/tools/sentiment/sentiment-summary.js +71 -14
- package/dist/tools/sentiment/sentiment-summary.js.map +1 -1
- package/dist/tools/sentiment/sentiment-trend.d.ts +1 -1
- package/dist/tools/sentiment/sentiment-trend.js +12 -2
- package/dist/tools/sentiment/sentiment-trend.js.map +1 -1
- package/dist/tools/sentiment/twitter-sentiment.js +13 -6
- package/dist/tools/sentiment/twitter-sentiment.js.map +1 -1
- package/dist/tools/sentiment/untrusted-text.d.ts +2 -0
- package/dist/tools/sentiment/untrusted-text.js +17 -0
- package/dist/tools/sentiment/untrusted-text.js.map +1 -0
- package/dist/tools/sentiment/web-search.js +37 -12
- package/dist/tools/sentiment/web-search.js.map +1 -1
- package/dist/tools/sentiment/web-sentiment.js +16 -4
- package/dist/tools/sentiment/web-sentiment.js.map +1 -1
- package/dist/tools/technical/backtest.d.ts +3 -3
- package/dist/tools/technical/backtest.js +65 -44
- package/dist/tools/technical/backtest.js.map +1 -1
- package/dist/tools/technical/indicators.js +24 -8
- package/dist/tools/technical/indicators.js.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.js.map +1 -1
- package/dist/types/market.d.ts +1 -0
- package/dist/types/options.d.ts +10 -0
- package/dist/types/portfolio.d.ts +41 -4
- package/dist/workflows/compare-assets.d.ts +0 -3
- package/dist/workflows/compare-assets.js +55 -10
- package/dist/workflows/compare-assets.js.map +1 -1
- package/dist/workflows/index.d.ts +3 -4
- package/dist/workflows/index.js +3 -3
- package/dist/workflows/index.js.map +1 -1
- package/dist/workflows/options-screener.d.ts +0 -3
- package/dist/workflows/options-screener.js +88 -14
- package/dist/workflows/options-screener.js.map +1 -1
- package/dist/workflows/portfolio-builder.d.ts +0 -3
- package/dist/workflows/portfolio-builder.js +7 -11
- package/dist/workflows/portfolio-builder.js.map +1 -1
- package/gui/server/ask-user-bridge.ts +82 -0
- package/gui/server/automation-heartbeat.ts +97 -0
- package/gui/server/background-quotes.ts +97 -1
- package/gui/server/chat-event-adapter.ts +32 -10
- package/gui/server/chat-run-session.ts +16 -0
- package/gui/server/gui-session-manager.ts +5 -0
- package/gui/server/invoke-tool.ts +144 -1
- package/gui/server/live-chat-event-adapter.ts +21 -6
- package/gui/server/market-state-api.ts +315 -0
- package/gui/server/model-setup.ts +149 -2
- package/gui/server/private-api-access.ts +62 -0
- package/gui/server/projector.ts +58 -11
- package/gui/server/prompt-observation.ts +58 -0
- package/gui/server/quote-snapshot-store.ts +50 -0
- package/gui/server/server.ts +236 -376
- package/gui/server/session-actions.ts +186 -1
- package/gui/server/session-entry-wait.ts +81 -0
- package/gui/server/shutdown.ts +47 -0
- package/gui/server/tool-invoke-ack.ts +49 -0
- package/gui/server/tool-metadata.ts +23 -10
- package/gui/server/websocket.ts +13 -3
- package/gui/server/writer-lock.ts +6 -2
- package/gui/server/ws-hub.ts +292 -0
- package/gui/shared/chat-events.ts +16 -1
- package/gui/shared/event-reducer.ts +24 -6
- package/gui/web/dist/assets/CatalogOverlay-eJ2cBk33.js +1 -0
- package/gui/web/dist/assets/index-2KZtKBmu.css +1 -0
- package/gui/web/dist/assets/index-CveNgtDg.js +69 -0
- package/gui/web/dist/index.html +2 -2
- package/package.json +22 -12
- package/src/analysts/contracts.ts +10 -23
- package/src/analysts/orchestrator.ts +8 -43
- package/src/cli.ts +37 -13
- package/src/config.ts +99 -7
- package/src/index.ts +1 -1
- package/src/infra/browser.ts +4 -2
- package/src/infra/cache.ts +41 -30
- package/src/infra/http-client.ts +72 -6
- package/src/infra/index.ts +7 -10
- package/src/infra/native-dependencies.ts +8 -3
- package/src/infra/node-version.ts +3 -1
- package/src/infra/opencandle-paths.ts +3 -14
- package/src/infra/rate-limiter.ts +32 -20
- package/src/market-state/alert-conditions.ts +82 -0
- package/src/market-state/alert-runner.ts +863 -0
- package/src/market-state/daily-report.ts +247 -0
- package/src/market-state/local-automation-service.ts +162 -0
- package/src/market-state/notification-delivery.ts +158 -0
- package/src/market-state/resolve-for-mutation.ts +24 -0
- package/src/market-state/resolve.ts +112 -0
- package/src/market-state/service.ts +2344 -0
- package/src/memory/index.ts +7 -7
- package/src/memory/manager.ts +57 -26
- package/src/memory/retrieval.ts +8 -7
- package/src/memory/sqlite.ts +407 -6
- package/src/memory/storage.ts +8 -17
- package/src/memory/tool-defaults.ts +60 -39
- package/src/memory/types.ts +7 -3
- package/src/monitor.ts +121 -0
- package/src/onboarding/connect.ts +10 -33
- package/src/onboarding/credential-interceptor.ts +3 -15
- package/src/onboarding/degradation-accumulator.ts +1 -3
- package/src/onboarding/providers.ts +9 -40
- package/src/onboarding/state.ts +4 -15
- package/src/onboarding/tool-helpers.ts +2 -9
- package/src/onboarding/tool-tags.ts +6 -6
- package/src/onboarding/validation.ts +14 -20
- package/src/pi/opencandle-extension.ts +795 -120
- package/src/pi/session.ts +7 -5
- package/src/pi/setup.ts +61 -33
- package/src/pi/tool-adapter.ts +5 -2
- package/src/prompts/context-builder.ts +143 -21
- package/src/prompts/disclaimer.ts +1 -1
- package/src/prompts/policy-cards.ts +220 -0
- package/src/prompts/sections.ts +4 -4
- package/src/prompts/symbol-preflight.ts +80 -0
- package/src/prompts/workflow-prompts.ts +231 -28
- package/src/providers/alpha-vantage.ts +82 -40
- package/src/providers/coingecko.ts +2 -5
- package/src/providers/errors.ts +9 -0
- package/src/providers/exa-search.ts +24 -22
- package/src/providers/fear-greed.ts +1 -1
- package/src/providers/finnhub.ts +7 -6
- package/src/providers/fred.ts +3 -3
- package/src/providers/index.ts +14 -6
- package/src/providers/reddit.ts +17 -6
- package/src/providers/sec-edgar.ts +235 -5
- package/src/providers/tradingview.ts +399 -0
- package/src/providers/twitter.ts +6 -8
- package/src/providers/web-search.ts +30 -20
- package/src/providers/with-fallback.ts +8 -7
- package/src/providers/wrap-provider.ts +15 -10
- package/src/providers/yahoo-finance.ts +292 -20
- package/src/routing/classify-intent.ts +186 -4
- package/src/routing/defaults.ts +4 -4
- package/src/routing/entity-extractor.ts +428 -28
- package/src/routing/fund-symbols.ts +58 -0
- package/src/routing/horizon.ts +7 -0
- package/src/routing/index.ts +60 -16
- package/src/routing/legacy-rule-router.ts +13 -0
- package/src/routing/planning.ts +823 -0
- package/src/routing/route-manifest.ts +309 -0
- package/src/routing/router-llm-client.ts +4 -4
- package/src/routing/router-prompt.ts +52 -52
- package/src/routing/router-types.ts +18 -0
- package/src/routing/router.ts +717 -20
- package/src/routing/slot-resolver.ts +75 -14
- package/src/routing/symbol-disambiguator.ts +72 -0
- package/src/routing/turn-context.ts +108 -0
- package/src/routing/types.ts +15 -1
- package/src/runtime/answer-contracts.ts +672 -0
- package/src/runtime/artifact-contracts.ts +77 -0
- package/src/runtime/planning-evidence.ts +682 -0
- package/src/runtime/prompt-step.ts +1 -16
- package/src/runtime/run-context.ts +12 -2
- package/src/runtime/session-coordinator.ts +297 -56
- package/src/runtime/session-title.ts +60 -0
- package/src/runtime/tool-defaults-wrapper.ts +1 -3
- package/src/runtime/validation.ts +1 -4
- package/src/runtime/workflow-events.ts +7 -7
- package/src/runtime/workflow-runner.ts +5 -11
- package/src/sentiment/adapters/finnhub.ts +7 -2
- package/src/sentiment/adapters/reddit.ts +2 -2
- package/src/sentiment/adapters/twitter.ts +1 -1
- package/src/sentiment/adapters/web.ts +1 -1
- package/src/sentiment/index.ts +16 -26
- package/src/sentiment/keywords.ts +26 -4
- package/src/sentiment/pipeline.ts +15 -4
- package/src/sentiment/scorer.ts +1 -1
- package/src/sentiment/store.ts +2 -2
- package/src/sentiment/trends.ts +9 -3
- package/src/sentiment/types.ts +5 -4
- package/src/system-prompt.ts +7 -3
- package/src/tool-kit.ts +10 -9
- package/src/tools/fundamentals/company-overview.ts +20 -10
- package/src/tools/fundamentals/comps.ts +69 -56
- package/src/tools/fundamentals/dcf.ts +146 -96
- package/src/tools/fundamentals/earnings.ts +17 -7
- package/src/tools/fundamentals/financials.ts +17 -8
- package/src/tools/fundamentals/sec-filings.ts +52 -8
- package/src/tools/index.ts +53 -38
- package/src/tools/interaction/ask-user.ts +22 -10
- package/src/tools/interaction/twitter-login.ts +17 -5
- package/src/tools/macro/fear-greed.ts +2 -2
- package/src/tools/macro/fred-data.ts +80 -42
- package/src/tools/market/crypto-history.ts +25 -4
- package/src/tools/market/crypto-price.ts +7 -7
- package/src/tools/market/screen-stocks.ts +279 -0
- package/src/tools/market/search-ticker.ts +219 -18
- package/src/tools/market/stock-history.ts +38 -13
- package/src/tools/market/stock-quote.ts +11 -8
- package/src/tools/options/greeks.ts +5 -6
- package/src/tools/options/option-chain.ts +47 -18
- package/src/tools/portfolio/alerts.ts +457 -0
- package/src/tools/portfolio/correlation.ts +48 -21
- package/src/tools/portfolio/daily-report.ts +101 -0
- package/src/tools/portfolio/holdings-overlap.ts +139 -0
- package/src/tools/portfolio/notifications.ts +45 -0
- package/src/tools/portfolio/predictions.ts +407 -107
- package/src/tools/portfolio/risk-analysis.ts +47 -8
- package/src/tools/portfolio/tracker.ts +271 -110
- package/src/tools/portfolio/watchlist.ts +251 -116
- package/src/tools/sentiment/reddit-sentiment.ts +51 -25
- package/src/tools/sentiment/sentiment-summary.ts +116 -35
- package/src/tools/sentiment/sentiment-trend.ts +24 -7
- package/src/tools/sentiment/twitter-sentiment.ts +23 -16
- package/src/tools/sentiment/untrusted-text.ts +21 -0
- package/src/tools/sentiment/web-search.ts +52 -16
- package/src/tools/sentiment/web-sentiment.ts +27 -11
- package/src/tools/technical/backtest.ts +78 -47
- package/src/tools/technical/indicators.ts +40 -17
- package/src/types/index.ts +8 -3
- package/src/types/market.ts +1 -0
- package/src/types/options.ts +17 -0
- package/src/types/portfolio.ts +46 -4
- package/src/types/sentiment.ts +2 -2
- package/src/workflows/compare-assets.ts +67 -19
- package/src/workflows/index.ts +3 -4
- package/src/workflows/options-screener.ts +98 -22
- package/src/workflows/portfolio-builder.ts +40 -29
- package/dist/runtime/index.d.ts +0 -16
- package/dist/runtime/index.js +0 -10
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/provider-ids.d.ts +0 -14
- package/dist/runtime/provider-ids.js +0 -14
- package/dist/runtime/provider-ids.js.map +0 -1
- package/dist/workflows/types.d.ts +0 -4
- package/dist/workflows/types.js +0 -2
- package/dist/workflows/types.js.map +0 -1
- package/gui/web/dist/assets/CatalogOverlay-D1ImSJTe.js +0 -1
- package/gui/web/dist/assets/index-DBrWq43L.css +0 -1
- package/gui/web/dist/assets/index-RflHaj0y.js +0 -67
- package/src/runtime/index.ts +0 -55
- package/src/runtime/provider-ids.ts +0 -15
- package/src/workflows/types.ts +0 -4
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
import { canUseTradingViewQuote, getQuotes } from "../providers/tradingview.js";
|
|
2
|
+
import { wrapProvider } from "../providers/wrap-provider.js";
|
|
3
|
+
import { getHistory, getQuote } from "../providers/yahoo-finance.js";
|
|
4
|
+
import { computeRSI, computeSMA } from "../tools/technical/indicators.js";
|
|
5
|
+
import { ALERT_CONDITION_VERSION } from "./alert-conditions.js";
|
|
6
|
+
import { isZeroFilledQuote } from "./resolve.js";
|
|
7
|
+
export class AlertProviderBudget {
|
|
8
|
+
state = new Map();
|
|
9
|
+
failureThreshold;
|
|
10
|
+
backoffMs;
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
this.failureThreshold = options.failureThreshold ?? 2;
|
|
13
|
+
this.backoffMs = options.backoffMs ?? 5 * 60_000;
|
|
14
|
+
}
|
|
15
|
+
unavailableReason(provider, now) {
|
|
16
|
+
const current = this.state.get(provider);
|
|
17
|
+
if (current == null || current.openUntilMs <= new Date(now).getTime())
|
|
18
|
+
return null;
|
|
19
|
+
return `${provider} provider_budget_exhausted until ${new Date(current.openUntilMs).toISOString()}${current.reason ? ` (${current.reason})` : ""}`;
|
|
20
|
+
}
|
|
21
|
+
recordSuccess(provider) {
|
|
22
|
+
this.state.delete(provider);
|
|
23
|
+
}
|
|
24
|
+
recordFailure(provider, reason, now) {
|
|
25
|
+
const current = this.state.get(provider) ?? { failureCount: 0, openUntilMs: 0 };
|
|
26
|
+
const nextFailureCount = current.failureCount + 1;
|
|
27
|
+
this.state.set(provider, {
|
|
28
|
+
failureCount: nextFailureCount,
|
|
29
|
+
openUntilMs: nextFailureCount >= this.failureThreshold ? new Date(now).getTime() + this.backoffMs : 0,
|
|
30
|
+
reason,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
reset() {
|
|
34
|
+
this.state.clear();
|
|
35
|
+
}
|
|
36
|
+
snapshot(now) {
|
|
37
|
+
const nowMs = new Date(now).getTime();
|
|
38
|
+
return Object.fromEntries([...this.state.entries()].map(([provider, state]) => [
|
|
39
|
+
provider,
|
|
40
|
+
{
|
|
41
|
+
state: state.openUntilMs > nowMs ? "open" : "available",
|
|
42
|
+
failureCount: state.failureCount,
|
|
43
|
+
...(state.openUntilMs > nowMs
|
|
44
|
+
? { openUntil: new Date(state.openUntilMs).toISOString() }
|
|
45
|
+
: {}),
|
|
46
|
+
...(state.reason ? { reason: state.reason } : {}),
|
|
47
|
+
},
|
|
48
|
+
]));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export const defaultAlertProviderBudget = new AlertProviderBudget();
|
|
52
|
+
export const defaultAlertRunnerProviders = {
|
|
53
|
+
async getTradingViewQuotes(symbols) {
|
|
54
|
+
const result = await wrapProvider("tradingview", () => getQuotes(symbols));
|
|
55
|
+
if (result.status === "unavailable")
|
|
56
|
+
throw new Error(result.reason);
|
|
57
|
+
if (result.stale)
|
|
58
|
+
throw new Error("provider returned stale market data");
|
|
59
|
+
return result.data.map((quote) => ({
|
|
60
|
+
symbol: quote.requestedSymbol,
|
|
61
|
+
value: quote.price,
|
|
62
|
+
sourceProvider: "tradingview",
|
|
63
|
+
observedAt: result.timestamp,
|
|
64
|
+
providerDataAt: null,
|
|
65
|
+
cacheStatus: result.stale ? "stale" : "live",
|
|
66
|
+
dataDelayMs: 15 * 60_000,
|
|
67
|
+
caveat: quote.dataCaveat,
|
|
68
|
+
}));
|
|
69
|
+
},
|
|
70
|
+
async getYahooQuote(symbol) {
|
|
71
|
+
const result = await wrapProvider("yahoo", () => getQuote(symbol));
|
|
72
|
+
if (result.status === "unavailable")
|
|
73
|
+
throw new Error(result.reason);
|
|
74
|
+
if (result.stale)
|
|
75
|
+
throw new Error("provider returned stale market data");
|
|
76
|
+
if (isZeroFilledQuote(result.data))
|
|
77
|
+
throw new Error("Yahoo returned no valid market data.");
|
|
78
|
+
return {
|
|
79
|
+
symbol,
|
|
80
|
+
value: result.data.price,
|
|
81
|
+
sourceProvider: "yahoo",
|
|
82
|
+
observedAt: result.timestamp,
|
|
83
|
+
providerDataAt: new Date(result.data.timestamp).toISOString(),
|
|
84
|
+
cacheStatus: "live",
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
async getHistory(symbol, range, interval) {
|
|
88
|
+
const result = await wrapProvider("yahoo", () => getHistory(symbol, range, interval));
|
|
89
|
+
if (result.status === "unavailable")
|
|
90
|
+
throw new Error(result.reason);
|
|
91
|
+
if (result.stale)
|
|
92
|
+
throw new Error("provider returned stale market data");
|
|
93
|
+
return result.data;
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
export async function runAlertChecks(service, options) {
|
|
97
|
+
const now = options.now ?? new Date().toISOString();
|
|
98
|
+
const providerBudget = options.providerBudget ?? defaultAlertProviderBudget;
|
|
99
|
+
const historyCache = new Map();
|
|
100
|
+
const run = service.startAlertCheckRun({
|
|
101
|
+
ownerId: options.ownerId,
|
|
102
|
+
triggerType: options.triggerType,
|
|
103
|
+
startedAt: now,
|
|
104
|
+
});
|
|
105
|
+
let triggered = 0;
|
|
106
|
+
let unavailable = 0;
|
|
107
|
+
const lines = [];
|
|
108
|
+
try {
|
|
109
|
+
const rules = service
|
|
110
|
+
.listAlertRules()
|
|
111
|
+
.filter((rule) => rule.enabled && rule.status === "active" && isDue(rule, now));
|
|
112
|
+
const runnable = rules.flatMap((rule) => {
|
|
113
|
+
if (rule.conditionVersion !== ALERT_CONDITION_VERSION) {
|
|
114
|
+
unavailable++;
|
|
115
|
+
lines.push(`#${rule.id}: needs review (unsupported condition version ${rule.conditionVersion})`);
|
|
116
|
+
return [];
|
|
117
|
+
}
|
|
118
|
+
if (rule.instrumentId == null) {
|
|
119
|
+
unavailable++;
|
|
120
|
+
lines.push(`#${rule.id}: unavailable instrument`);
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
const instrument = service.getInstrument(rule.instrumentId);
|
|
124
|
+
if (instrument == null) {
|
|
125
|
+
unavailable++;
|
|
126
|
+
lines.push(`#${rule.id}: unavailable instrument`);
|
|
127
|
+
return [];
|
|
128
|
+
}
|
|
129
|
+
return [{ rule, instrument }];
|
|
130
|
+
});
|
|
131
|
+
const priceRules = runnable.filter(({ rule }) => rule.conditionType === "price_crosses_above" ||
|
|
132
|
+
rule.conditionType === "price_crosses_below");
|
|
133
|
+
const quoteObservations = await loadPriceObservations(priceRules, options.providers, providerBudget, now);
|
|
134
|
+
for (const item of runnable) {
|
|
135
|
+
const observationKey = isPriceRule(item.rule)
|
|
136
|
+
? quoteObservationKey(item.instrument.symbol, allowsDelayedObservation(item.rule))
|
|
137
|
+
: item.instrument.symbol;
|
|
138
|
+
const observation = isPriceRule(item.rule)
|
|
139
|
+
? quoteObservations.observations.get(observationKey)
|
|
140
|
+
: await loadHistoricalObservation(item, options.providers, providerBudget, historyCache, now);
|
|
141
|
+
if (!observation) {
|
|
142
|
+
const reason = quoteObservations.unavailableReasons.get(observationKey) ??
|
|
143
|
+
quoteObservations.unavailableReasons.get(item.instrument.symbol) ??
|
|
144
|
+
`no provider observation for ${item.instrument.symbol}`;
|
|
145
|
+
unavailable++;
|
|
146
|
+
service.recordAlertUnavailable({
|
|
147
|
+
ruleId: item.rule.id,
|
|
148
|
+
instrumentId: item.instrument.id,
|
|
149
|
+
reason,
|
|
150
|
+
checkedAt: now,
|
|
151
|
+
});
|
|
152
|
+
lines.push(`${item.instrument.symbol}: unavailable (${reason})`);
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
const previous = lastObservedValue(item.rule);
|
|
156
|
+
const conditionState = conditionIsTrue(item.rule, observation.value) ? "true" : "false";
|
|
157
|
+
const shouldTrigger = conditionState === "true" &&
|
|
158
|
+
previous != null &&
|
|
159
|
+
crosses(item.rule, previous, observation.value) &&
|
|
160
|
+
outsideCooldown(item.rule, now);
|
|
161
|
+
const observed = {
|
|
162
|
+
value: observation.value,
|
|
163
|
+
field: observationField(item.rule),
|
|
164
|
+
at: now,
|
|
165
|
+
observedAt: now,
|
|
166
|
+
providerDataAt: observation.providerDataAt ?? null,
|
|
167
|
+
sourceProvider: observation.sourceProvider,
|
|
168
|
+
cacheStatus: observation.cacheStatus,
|
|
169
|
+
dataDelayMs: observation.dataDelayMs ?? null,
|
|
170
|
+
caveat: observation.caveat ?? null,
|
|
171
|
+
};
|
|
172
|
+
const result = service.recordAlertEvaluationResult({
|
|
173
|
+
ruleId: item.rule.id,
|
|
174
|
+
observed,
|
|
175
|
+
checkedAt: now,
|
|
176
|
+
conditionState,
|
|
177
|
+
trigger: shouldTrigger
|
|
178
|
+
? {
|
|
179
|
+
instrumentId: item.instrument.id,
|
|
180
|
+
title: `${item.instrument.symbol} alert triggered`,
|
|
181
|
+
message: alertTriggerMessage(item.instrument.symbol, item.rule, observation.value),
|
|
182
|
+
triggeredAt: now,
|
|
183
|
+
observedAt: now,
|
|
184
|
+
providerDataAt: observation.providerDataAt ?? null,
|
|
185
|
+
sourceProvider: observation.sourceProvider,
|
|
186
|
+
cacheStatus: observation.cacheStatus,
|
|
187
|
+
dataDelayMs: observation.dataDelayMs ?? null,
|
|
188
|
+
triggerSource: options.triggerType,
|
|
189
|
+
dedupeKey: alertDedupeKey(item.rule, observation, options.triggerType),
|
|
190
|
+
status: options.triggerType === "resume" ? "triggered_late" : "triggered",
|
|
191
|
+
}
|
|
192
|
+
: undefined,
|
|
193
|
+
});
|
|
194
|
+
if (result.triggered) {
|
|
195
|
+
triggered++;
|
|
196
|
+
lines.push(`TRIGGERED: ${item.instrument.symbol} — ${alertTriggerMessage(item.instrument.symbol, item.rule, observation.value)}${observationSourceSuffix(observation)}`);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
lines.push(`${item.instrument.symbol}: ${previous == null ? "seeded" : "checked"} — observed ${observation.value.toFixed(2)} vs ${conditionTargetLabel(item.rule)} (condition ${conditionState})${observationSourceSuffix(observation)}`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
service.completeAlertCheckRun(run.id, {
|
|
203
|
+
completedAt: now,
|
|
204
|
+
status: "completed",
|
|
205
|
+
checkedCount: rules.length,
|
|
206
|
+
triggeredCount: triggered,
|
|
207
|
+
unavailableCount: unavailable,
|
|
208
|
+
providerStatus: {
|
|
209
|
+
checkedSymbols: runnable.map((item) => item.instrument.symbol),
|
|
210
|
+
unavailableReasons: Object.fromEntries(quoteObservations.unavailableReasons),
|
|
211
|
+
providerBudget: providerBudget.snapshot(now),
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
return { checked: rules.length, triggered, unavailable, runId: run.id, lines };
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
service.completeAlertCheckRun(run.id, {
|
|
218
|
+
completedAt: now,
|
|
219
|
+
status: "failed",
|
|
220
|
+
checkedCount: 0,
|
|
221
|
+
triggeredCount: triggered,
|
|
222
|
+
unavailableCount: unavailable,
|
|
223
|
+
error: { message: error instanceof Error ? error.message : String(error) },
|
|
224
|
+
});
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
async function loadPriceObservations(rules, providers, providerBudget, now) {
|
|
229
|
+
const symbols = [...new Set(rules.map(({ instrument }) => instrument.symbol))].sort();
|
|
230
|
+
const tradingViewSymbols = symbols.filter((symbol) => canUseTradingViewQuote(symbol) &&
|
|
231
|
+
rules.some(({ rule, instrument }) => instrument.symbol === symbol && allowsDelayedObservation(rule)));
|
|
232
|
+
const yahooSymbols = new Set(symbols.filter((symbol) => !canUseTradingViewQuote(symbol) ||
|
|
233
|
+
rules.some(({ rule, instrument }) => instrument.symbol === symbol && !allowsDelayedObservation(rule))));
|
|
234
|
+
const observations = new Map();
|
|
235
|
+
const unavailableReasons = new Map();
|
|
236
|
+
if (tradingViewSymbols.length > 0) {
|
|
237
|
+
const budgetReason = providerBudget.unavailableReason("tradingview", now);
|
|
238
|
+
if (budgetReason) {
|
|
239
|
+
for (const symbol of tradingViewSymbols) {
|
|
240
|
+
yahooSymbols.add(symbol);
|
|
241
|
+
unavailableReasons.set(symbol, budgetReason);
|
|
242
|
+
unavailableReasons.set(quoteObservationKey(symbol, true), budgetReason);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
try {
|
|
247
|
+
for (const quote of await providers.getTradingViewQuotes(tradingViewSymbols)) {
|
|
248
|
+
if (quote.cacheStatus === "stale") {
|
|
249
|
+
unavailableReasons.set(quoteObservationKey(quote.symbol, true), "TradingView returned stale market data");
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
observations.set(quoteObservationKey(quote.symbol, true), normalizeObservation(quote, now));
|
|
253
|
+
}
|
|
254
|
+
providerBudget.recordSuccess("tradingview");
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
const reason = error instanceof Error ? error.message : "TradingView unavailable";
|
|
258
|
+
providerBudget.recordFailure("tradingview", reason, now);
|
|
259
|
+
for (const symbol of tradingViewSymbols) {
|
|
260
|
+
yahooSymbols.add(symbol);
|
|
261
|
+
unavailableReasons.set(symbol, reason);
|
|
262
|
+
unavailableReasons.set(quoteObservationKey(symbol, true), reason);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
for (const symbol of tradingViewSymbols) {
|
|
268
|
+
if (!observations.has(quoteObservationKey(symbol, true)))
|
|
269
|
+
yahooSymbols.add(symbol);
|
|
270
|
+
}
|
|
271
|
+
const yahooSymbolList = [...yahooSymbols];
|
|
272
|
+
const yahooBudgetReason = providerBudget.unavailableReason("yahoo", now);
|
|
273
|
+
if (yahooBudgetReason) {
|
|
274
|
+
for (const symbol of yahooSymbolList) {
|
|
275
|
+
const prior = unavailableReasons.get(symbol);
|
|
276
|
+
unavailableReasons.set(symbol, prior ? `${prior}; ${yahooBudgetReason}` : yahooBudgetReason);
|
|
277
|
+
unavailableReasons.set(quoteObservationKey(symbol, false), yahooBudgetReason);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
const yahooResults = await Promise.allSettled(yahooSymbolList.map((symbol) => providers.getYahooQuote(symbol)));
|
|
282
|
+
for (const [index, result] of yahooResults.entries()) {
|
|
283
|
+
const symbol = yahooSymbolList[index];
|
|
284
|
+
if (symbol == null)
|
|
285
|
+
continue;
|
|
286
|
+
if (result.status === "fulfilled") {
|
|
287
|
+
const normalized = normalizeObservation(result.value, now);
|
|
288
|
+
observations.set(quoteObservationKey(symbol, false), normalized);
|
|
289
|
+
if (!observations.has(quoteObservationKey(symbol, true))) {
|
|
290
|
+
observations.set(quoteObservationKey(symbol, true), normalized);
|
|
291
|
+
}
|
|
292
|
+
unavailableReasons.delete(symbol);
|
|
293
|
+
unavailableReasons.delete(quoteObservationKey(symbol, false));
|
|
294
|
+
unavailableReasons.delete(quoteObservationKey(symbol, true));
|
|
295
|
+
providerBudget.recordSuccess("yahoo");
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
const prior = unavailableReasons.get(symbol);
|
|
299
|
+
const reason = result.reason instanceof Error ? result.reason.message : "Yahoo unavailable";
|
|
300
|
+
if (isProviderWideFailure(reason))
|
|
301
|
+
providerBudget.recordFailure("yahoo", reason, now);
|
|
302
|
+
const mergedReason = prior ? `${prior}; Yahoo fallback unavailable: ${reason}` : reason;
|
|
303
|
+
unavailableReasons.set(symbol, mergedReason);
|
|
304
|
+
unavailableReasons.set(quoteObservationKey(symbol, false), reason);
|
|
305
|
+
if (!observations.has(quoteObservationKey(symbol, true))) {
|
|
306
|
+
const delayedKey = quoteObservationKey(symbol, true);
|
|
307
|
+
const delayedPrior = unavailableReasons.get(delayedKey);
|
|
308
|
+
unavailableReasons.set(delayedKey, delayedPrior ? `${delayedPrior}; Yahoo fallback unavailable: ${reason}` : mergedReason);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return { observations, unavailableReasons };
|
|
314
|
+
}
|
|
315
|
+
async function loadHistoricalObservation(item, providers, providerBudget, historyCache, now) {
|
|
316
|
+
try {
|
|
317
|
+
if (item.rule.conditionType === "price_crosses_sma") {
|
|
318
|
+
const condition = item.rule.conditionJson;
|
|
319
|
+
const period = typeof condition.period === "number" ? condition.period : 50;
|
|
320
|
+
const bars = await loadHistory(item.instrument.symbol, "1y", "1d", providers, providerBudget, historyCache, now);
|
|
321
|
+
const closes = bars.map((bar) => bar.close);
|
|
322
|
+
const sma = computeSMA(closes, period);
|
|
323
|
+
const latestClose = closes.at(-1);
|
|
324
|
+
const latestSma = sma.at(-1);
|
|
325
|
+
if (latestClose == null || latestSma == null)
|
|
326
|
+
return null;
|
|
327
|
+
return historicalObservation(item.instrument.symbol, latestClose - latestSma, bars.at(-1)?.date ?? null, now);
|
|
328
|
+
}
|
|
329
|
+
if (item.rule.conditionType === "percent_move") {
|
|
330
|
+
const bars = await loadHistory(item.instrument.symbol, "5d", "1d", providers, providerBudget, historyCache, now);
|
|
331
|
+
const latest = bars.at(-1);
|
|
332
|
+
const prior = bars.at(-2);
|
|
333
|
+
if (latest == null || prior == null || prior.close === 0)
|
|
334
|
+
return null;
|
|
335
|
+
const move = (latest.close / prior.close - 1) * 100;
|
|
336
|
+
return historicalObservation(item.instrument.symbol, roundObservation(move), latest.date, now);
|
|
337
|
+
}
|
|
338
|
+
if (item.rule.conditionType === "sma_cross") {
|
|
339
|
+
const condition = item.rule.conditionJson;
|
|
340
|
+
const fastPeriod = typeof condition.fast_period === "number" ? condition.fast_period : 50;
|
|
341
|
+
const slowPeriod = typeof condition.slow_period === "number" ? condition.slow_period : 200;
|
|
342
|
+
const bars = await loadHistory(item.instrument.symbol, "2y", "1d", providers, providerBudget, historyCache, now);
|
|
343
|
+
const closes = bars.map((bar) => bar.close);
|
|
344
|
+
const fast = computeSMA(closes, fastPeriod).at(-1);
|
|
345
|
+
const slow = computeSMA(closes, slowPeriod).at(-1);
|
|
346
|
+
if (fast == null || slow == null)
|
|
347
|
+
return null;
|
|
348
|
+
return historicalObservation(item.instrument.symbol, roundObservation(fast - slow), bars.at(-1)?.date ?? null, now);
|
|
349
|
+
}
|
|
350
|
+
if (item.rule.conditionType === "rsi_threshold") {
|
|
351
|
+
const condition = item.rule.conditionJson;
|
|
352
|
+
const period = typeof condition.period === "number" ? condition.period : 14;
|
|
353
|
+
const bars = await loadHistory(item.instrument.symbol, "6mo", "1d", providers, providerBudget, historyCache, now);
|
|
354
|
+
const rsi = computeRSI(bars.map((bar) => bar.close), period);
|
|
355
|
+
const latestRsi = rsi.at(-1);
|
|
356
|
+
if (latestRsi == null)
|
|
357
|
+
return null;
|
|
358
|
+
return historicalObservation(item.instrument.symbol, latestRsi, bars.at(-1)?.date ?? null, now);
|
|
359
|
+
}
|
|
360
|
+
if (item.rule.conditionType === "volume_spike") {
|
|
361
|
+
const condition = item.rule.conditionJson;
|
|
362
|
+
const period = typeof condition.lookback_period === "number" ? condition.lookback_period : 20;
|
|
363
|
+
const bars = await loadHistory(item.instrument.symbol, "6mo", "1d", providers, providerBudget, historyCache, now);
|
|
364
|
+
const latest = bars.at(-1);
|
|
365
|
+
const prior = bars.slice(Math.max(0, bars.length - 1 - period), bars.length - 1);
|
|
366
|
+
if (latest == null || prior.length < period)
|
|
367
|
+
return null;
|
|
368
|
+
const averageVolume = prior.reduce((sum, bar) => sum + bar.volume, 0) / prior.length;
|
|
369
|
+
if (averageVolume <= 0)
|
|
370
|
+
return null;
|
|
371
|
+
return historicalObservation(item.instrument.symbol, latest.volume / averageVolume, latest.date, now);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
catch {
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
379
|
+
function loadHistory(symbol, range, interval, providers, providerBudget, historyCache, now) {
|
|
380
|
+
const budgetReason = providerBudget.unavailableReason("yahoo", now);
|
|
381
|
+
if (budgetReason)
|
|
382
|
+
return Promise.reject(new Error(budgetReason));
|
|
383
|
+
const key = `${symbol}:${range}:${interval}`;
|
|
384
|
+
const cached = historyCache.get(key);
|
|
385
|
+
if (cached)
|
|
386
|
+
return cached;
|
|
387
|
+
const promise = providers
|
|
388
|
+
.getHistory(symbol, range, interval)
|
|
389
|
+
.then((bars) => {
|
|
390
|
+
providerBudget.recordSuccess("yahoo");
|
|
391
|
+
return bars;
|
|
392
|
+
})
|
|
393
|
+
.catch((error) => {
|
|
394
|
+
const reason = error instanceof Error ? error.message : "Yahoo history unavailable";
|
|
395
|
+
if (isProviderWideFailure(reason))
|
|
396
|
+
providerBudget.recordFailure("yahoo", reason, now);
|
|
397
|
+
throw error;
|
|
398
|
+
});
|
|
399
|
+
historyCache.set(key, promise);
|
|
400
|
+
return promise;
|
|
401
|
+
}
|
|
402
|
+
function isProviderWideFailure(reason) {
|
|
403
|
+
const normalized = reason.toLowerCase();
|
|
404
|
+
return (normalized.includes("429") ||
|
|
405
|
+
normalized.includes("rate limit") ||
|
|
406
|
+
normalized.includes("too many requests") ||
|
|
407
|
+
normalized.includes("provider_budget_exhausted") ||
|
|
408
|
+
normalized.includes("timeout") ||
|
|
409
|
+
normalized.includes("timed out") ||
|
|
410
|
+
normalized.includes("network") ||
|
|
411
|
+
normalized.includes("fetch failed") ||
|
|
412
|
+
normalized.includes("econn") ||
|
|
413
|
+
normalized.includes("enotfound"));
|
|
414
|
+
}
|
|
415
|
+
function historicalObservation(symbol, value, providerDataAt, now) {
|
|
416
|
+
return {
|
|
417
|
+
symbol,
|
|
418
|
+
value,
|
|
419
|
+
sourceProvider: "yahoo",
|
|
420
|
+
observedAt: now,
|
|
421
|
+
providerDataAt,
|
|
422
|
+
cacheStatus: "live",
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
function observationField(rule) {
|
|
426
|
+
if (rule.conditionType === "rsi_threshold")
|
|
427
|
+
return "rsi";
|
|
428
|
+
if (rule.conditionType === "volume_spike")
|
|
429
|
+
return "volume_ratio";
|
|
430
|
+
if (rule.conditionType === "price_crosses_sma")
|
|
431
|
+
return "price_sma_spread";
|
|
432
|
+
if (rule.conditionType === "percent_move")
|
|
433
|
+
return "percent_move";
|
|
434
|
+
if (rule.conditionType === "sma_cross")
|
|
435
|
+
return "sma_spread";
|
|
436
|
+
return "last_price";
|
|
437
|
+
}
|
|
438
|
+
function conditionTargetLabel(rule) {
|
|
439
|
+
const c = (rule.conditionJson ?? {});
|
|
440
|
+
switch (rule.conditionType) {
|
|
441
|
+
case "price_crosses_above":
|
|
442
|
+
return `above ${Number(c.threshold).toFixed(2)}`;
|
|
443
|
+
case "price_crosses_below":
|
|
444
|
+
return `below ${Number(c.threshold).toFixed(2)}`;
|
|
445
|
+
case "rsi_threshold":
|
|
446
|
+
return `RSI ${c.direction === "below" ? "below" : "above"} ${c.threshold} (${c.period}-day)`;
|
|
447
|
+
case "percent_move":
|
|
448
|
+
return `${c.direction === "down" ? "down" : "up"} ${c.percent}% in ${c.window ?? "1d"}`;
|
|
449
|
+
case "price_crosses_sma":
|
|
450
|
+
return `price ${c.direction === "below" ? "below" : "above"} ${c.period}-day SMA`;
|
|
451
|
+
case "sma_cross":
|
|
452
|
+
return `${c.fast_period}-day SMA ${c.direction === "below" ? "below" : "above"} ${c.slow_period}-day SMA`;
|
|
453
|
+
case "volume_spike":
|
|
454
|
+
return `${c.multiplier}x the ${c.lookback_period}-day average volume`;
|
|
455
|
+
default:
|
|
456
|
+
return rule.conditionType;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
function observationSourceSuffix(observation) {
|
|
460
|
+
const delay = observation.dataDelayMs != null && observation.dataDelayMs > 0
|
|
461
|
+
? `, ~${Math.round(observation.dataDelayMs / 60_000)}m delayed`
|
|
462
|
+
: "";
|
|
463
|
+
return ` [${observation.sourceProvider}${delay}]`;
|
|
464
|
+
}
|
|
465
|
+
function alertTriggerMessage(symbol, rule, value) {
|
|
466
|
+
if (rule.conditionType === "rsi_threshold") {
|
|
467
|
+
const direction = rule.conditionJson.direction;
|
|
468
|
+
const directionText = direction === "above" ? "above" : "below";
|
|
469
|
+
return `${symbol} RSI ${directionText} threshold at ${value.toFixed(2)}`;
|
|
470
|
+
}
|
|
471
|
+
if (rule.conditionType === "volume_spike") {
|
|
472
|
+
return `${symbol} volume spike at ${value.toFixed(2)}x average volume`;
|
|
473
|
+
}
|
|
474
|
+
if (rule.conditionType === "price_crosses_sma") {
|
|
475
|
+
return `${symbol} price/SMA spread at ${formatSignedCurrency(value)}`;
|
|
476
|
+
}
|
|
477
|
+
if (rule.conditionType === "percent_move") {
|
|
478
|
+
const direction = rule.conditionJson.direction === "down" ? "down" : "up";
|
|
479
|
+
return `${symbol} percent move ${direction} ${Math.abs(value).toFixed(2)}%`;
|
|
480
|
+
}
|
|
481
|
+
if (rule.conditionType === "sma_cross") {
|
|
482
|
+
const direction = rule.conditionJson.direction === "below" ? "below" : "above";
|
|
483
|
+
return `${symbol} fast SMA crossed ${direction} slow SMA at ${formatSignedCurrency(value)}`;
|
|
484
|
+
}
|
|
485
|
+
return `${symbol} ${rule.conditionType} at $${value.toFixed(2)}`;
|
|
486
|
+
}
|
|
487
|
+
function formatSignedCurrency(value) {
|
|
488
|
+
return `${value >= 0 ? "+" : "-"}$${Math.abs(value).toFixed(2)}`;
|
|
489
|
+
}
|
|
490
|
+
function roundObservation(value) {
|
|
491
|
+
return Math.round(value * 10_000) / 10_000;
|
|
492
|
+
}
|
|
493
|
+
function normalizeObservation(observation, now) {
|
|
494
|
+
return {
|
|
495
|
+
...observation,
|
|
496
|
+
symbol: observation.symbol.toUpperCase(),
|
|
497
|
+
observedAt: observation.observedAt || now,
|
|
498
|
+
cacheStatus: observation.cacheStatus ?? "live",
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
function isDue(rule, now) {
|
|
502
|
+
return (rule.nextCheckAt == null || new Date(rule.nextCheckAt).getTime() <= new Date(now).getTime());
|
|
503
|
+
}
|
|
504
|
+
function isPriceRule(rule) {
|
|
505
|
+
return (rule.conditionType === "price_crosses_above" || rule.conditionType === "price_crosses_below");
|
|
506
|
+
}
|
|
507
|
+
function allowsDelayedObservation(rule) {
|
|
508
|
+
const condition = rule.conditionJson;
|
|
509
|
+
return condition.allow_delayed !== false && condition.allowDelayed !== false;
|
|
510
|
+
}
|
|
511
|
+
function quoteObservationKey(symbol, delayedAllowed) {
|
|
512
|
+
return `${symbol.toUpperCase()}:${delayedAllowed ? "delayed-ok" : "fresh-only"}`;
|
|
513
|
+
}
|
|
514
|
+
function lastObservedValue(rule) {
|
|
515
|
+
const observed = rule.lastObservedJson;
|
|
516
|
+
return typeof observed?.value === "number" ? observed.value : null;
|
|
517
|
+
}
|
|
518
|
+
function conditionIsTrue(rule, current) {
|
|
519
|
+
const condition = rule.conditionJson;
|
|
520
|
+
if (rule.conditionType === "price_crosses_above") {
|
|
521
|
+
return typeof condition.threshold === "number" && current > condition.threshold;
|
|
522
|
+
}
|
|
523
|
+
if (rule.conditionType === "price_crosses_below") {
|
|
524
|
+
return typeof condition.threshold === "number" && current < condition.threshold;
|
|
525
|
+
}
|
|
526
|
+
if (rule.conditionType === "price_crosses_sma") {
|
|
527
|
+
const direction = rule.conditionJson.direction;
|
|
528
|
+
if (direction === "above")
|
|
529
|
+
return current > 0;
|
|
530
|
+
if (direction === "below")
|
|
531
|
+
return current < 0;
|
|
532
|
+
}
|
|
533
|
+
if (rule.conditionType === "percent_move") {
|
|
534
|
+
const percent = rule.conditionJson.percent;
|
|
535
|
+
if (typeof percent !== "number")
|
|
536
|
+
return false;
|
|
537
|
+
const direction = rule.conditionJson.direction;
|
|
538
|
+
if (direction === "up")
|
|
539
|
+
return current > percent;
|
|
540
|
+
if (direction === "down")
|
|
541
|
+
return current < -percent;
|
|
542
|
+
}
|
|
543
|
+
if (rule.conditionType === "sma_cross") {
|
|
544
|
+
const direction = rule.conditionJson.direction;
|
|
545
|
+
if (direction === "above")
|
|
546
|
+
return current > 0;
|
|
547
|
+
if (direction === "below")
|
|
548
|
+
return current < 0;
|
|
549
|
+
}
|
|
550
|
+
if (rule.conditionType === "rsi_threshold") {
|
|
551
|
+
if (typeof condition.threshold !== "number")
|
|
552
|
+
return false;
|
|
553
|
+
const direction = rule.conditionJson.direction;
|
|
554
|
+
if (direction === "above")
|
|
555
|
+
return current > condition.threshold;
|
|
556
|
+
if (direction === "below")
|
|
557
|
+
return current < condition.threshold;
|
|
558
|
+
}
|
|
559
|
+
if (rule.conditionType === "volume_spike") {
|
|
560
|
+
const multiplier = rule.conditionJson.multiplier;
|
|
561
|
+
return typeof multiplier === "number" && current > multiplier;
|
|
562
|
+
}
|
|
563
|
+
return false;
|
|
564
|
+
}
|
|
565
|
+
function crosses(rule, previous, current) {
|
|
566
|
+
const condition = rule.conditionJson;
|
|
567
|
+
if (rule.conditionType === "price_crosses_above") {
|
|
568
|
+
return (typeof condition.threshold === "number" &&
|
|
569
|
+
previous <= condition.threshold &&
|
|
570
|
+
current > condition.threshold);
|
|
571
|
+
}
|
|
572
|
+
if (rule.conditionType === "price_crosses_below") {
|
|
573
|
+
return (typeof condition.threshold === "number" &&
|
|
574
|
+
previous >= condition.threshold &&
|
|
575
|
+
current < condition.threshold);
|
|
576
|
+
}
|
|
577
|
+
if (rule.conditionType === "price_crosses_sma") {
|
|
578
|
+
const direction = rule.conditionJson.direction;
|
|
579
|
+
if (direction === "above")
|
|
580
|
+
return previous <= 0 && current > 0;
|
|
581
|
+
if (direction === "below")
|
|
582
|
+
return previous >= 0 && current < 0;
|
|
583
|
+
}
|
|
584
|
+
if (rule.conditionType === "percent_move") {
|
|
585
|
+
const percent = rule.conditionJson.percent;
|
|
586
|
+
if (typeof percent !== "number")
|
|
587
|
+
return false;
|
|
588
|
+
const direction = rule.conditionJson.direction;
|
|
589
|
+
if (direction === "up")
|
|
590
|
+
return previous <= percent && current > percent;
|
|
591
|
+
if (direction === "down")
|
|
592
|
+
return previous >= -percent && current < -percent;
|
|
593
|
+
}
|
|
594
|
+
if (rule.conditionType === "sma_cross") {
|
|
595
|
+
const direction = rule.conditionJson.direction;
|
|
596
|
+
if (direction === "above")
|
|
597
|
+
return previous <= 0 && current > 0;
|
|
598
|
+
if (direction === "below")
|
|
599
|
+
return previous >= 0 && current < 0;
|
|
600
|
+
}
|
|
601
|
+
if (rule.conditionType === "rsi_threshold") {
|
|
602
|
+
if (typeof condition.threshold !== "number")
|
|
603
|
+
return false;
|
|
604
|
+
const direction = rule.conditionJson.direction;
|
|
605
|
+
if (direction === "above")
|
|
606
|
+
return previous <= condition.threshold && current > condition.threshold;
|
|
607
|
+
if (direction === "below")
|
|
608
|
+
return previous >= condition.threshold && current < condition.threshold;
|
|
609
|
+
}
|
|
610
|
+
if (rule.conditionType === "volume_spike") {
|
|
611
|
+
const multiplier = rule.conditionJson.multiplier;
|
|
612
|
+
return typeof multiplier === "number" && previous <= multiplier && current > multiplier;
|
|
613
|
+
}
|
|
614
|
+
return false;
|
|
615
|
+
}
|
|
616
|
+
function outsideCooldown(rule, now) {
|
|
617
|
+
if (rule.lastTriggeredAt == null || rule.cooldownSeconds == null)
|
|
618
|
+
return true;
|
|
619
|
+
return (new Date(now).getTime() - new Date(rule.lastTriggeredAt).getTime() >=
|
|
620
|
+
rule.cooldownSeconds * 1000);
|
|
621
|
+
}
|
|
622
|
+
function alertDedupeKey(rule, observation, triggerType) {
|
|
623
|
+
const bucket = observation.observedAt.slice(0, 16);
|
|
624
|
+
return [
|
|
625
|
+
"alert",
|
|
626
|
+
rule.id,
|
|
627
|
+
rule.ruleRevision,
|
|
628
|
+
rule.armCycleId,
|
|
629
|
+
triggerType,
|
|
630
|
+
bucket,
|
|
631
|
+
observation.value,
|
|
632
|
+
].join(":");
|
|
633
|
+
}
|
|
634
|
+
//# sourceMappingURL=alert-runner.js.map
|