opencandle 0.11.1 → 0.13.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/README.md +50 -186
- package/dist/analysts/contracts.js +0 -1
- package/dist/analysts/orchestrator.js +0 -1
- package/dist/cli-main.js +22 -15
- package/dist/cli-options.d.ts +4 -0
- package/dist/cli-options.js +33 -0
- package/dist/cli.js +8 -3
- package/dist/config.d.ts +4 -0
- package/dist/config.js +1 -1
- package/dist/doctor/cli-command.js +9 -5
- package/dist/doctor/render.js +0 -1
- package/dist/doctor/report.js +53 -11
- package/dist/gui/server/ask-user-bridge.d.ts +19 -0
- package/dist/gui/server/ask-user-bridge.js +55 -0
- package/dist/gui/server/automation-heartbeat.d.ts +25 -0
- package/dist/gui/server/automation-heartbeat.js +61 -0
- package/dist/gui/server/background-quotes.d.ts +39 -0
- package/dist/gui/server/background-quotes.js +71 -0
- package/dist/gui/server/chat-event-adapter.d.ts +16 -0
- package/dist/gui/server/chat-event-adapter.js +388 -0
- package/dist/gui/server/gui-session-manager.d.ts +2 -0
- package/dist/gui/server/gui-session-manager.js +4 -0
- package/dist/gui/server/history-snapshot-store.d.ts +8 -0
- package/dist/gui/server/history-snapshot-store.js +43 -0
- package/dist/gui/server/http-routes.d.ts +71 -0
- package/dist/gui/server/http-routes.js +1033 -0
- package/dist/gui/server/invoke-tool.d.ts +47 -0
- package/dist/gui/server/invoke-tool.js +373 -0
- package/dist/gui/server/live-chat-event-adapter.d.ts +21 -0
- package/dist/gui/server/live-chat-event-adapter.js +224 -0
- package/dist/gui/server/local-session-coordinator.d.ts +26 -0
- package/dist/gui/server/local-session-coordinator.js +53 -0
- package/dist/gui/server/market-indices-api.d.ts +21 -0
- package/dist/gui/server/market-indices-api.js +26 -0
- package/dist/gui/server/market-indices-snapshot-store.d.ts +12 -0
- package/dist/gui/server/market-indices-snapshot-store.js +56 -0
- package/dist/gui/server/market-state-api.d.ts +250 -0
- package/dist/gui/server/market-state-api.js +597 -0
- package/dist/gui/server/model-setup.d.ts +55 -0
- package/dist/gui/server/model-setup.js +154 -0
- package/dist/gui/server/private-api-access.d.ts +6 -0
- package/dist/gui/server/private-api-access.js +53 -0
- package/dist/gui/server/projector.d.ts +49 -0
- package/dist/gui/server/projector.js +296 -0
- package/dist/gui/server/prompt-observation.d.ts +8 -0
- package/dist/gui/server/prompt-observation.js +43 -0
- package/dist/gui/server/quote-snapshot-store.d.ts +14 -0
- package/dist/gui/server/quote-snapshot-store.js +49 -0
- package/dist/gui/server/server.d.ts +1 -0
- package/dist/gui/server/server.js +262 -0
- package/dist/gui/server/session-actions.d.ts +60 -0
- package/dist/gui/server/session-actions.js +218 -0
- package/dist/gui/server/session-entry-wait.d.ts +27 -0
- package/dist/gui/server/session-entry-wait.js +129 -0
- package/dist/gui/server/session-list.d.ts +2 -0
- package/dist/gui/server/session-list.js +11 -0
- package/dist/gui/server/shutdown.d.ts +10 -0
- package/dist/gui/server/shutdown.js +29 -0
- package/dist/gui/server/tool-invoke-ack.d.ts +17 -0
- package/dist/gui/server/tool-invoke-ack.js +26 -0
- package/dist/gui/server/tool-metadata.d.ts +93 -0
- package/dist/gui/server/tool-metadata.js +148 -0
- package/dist/gui/server/websocket.d.ts +9 -0
- package/dist/gui/server/websocket.js +124 -0
- package/dist/gui/server/writer-lock.d.ts +1 -0
- package/dist/gui/server/writer-lock.js +1 -0
- package/dist/gui/server/ws-hub.d.ts +50 -0
- package/dist/gui/server/ws-hub.js +284 -0
- package/dist/gui/shared/chat-events.d.ts +174 -0
- package/dist/gui/shared/chat-events.js +13 -0
- package/dist/gui/shared/event-reducer.d.ts +3 -0
- package/dist/gui/shared/event-reducer.js +187 -0
- package/dist/index.js +0 -1
- package/dist/infra/cache.d.ts +4 -0
- package/dist/infra/cache.js +4 -1
- package/dist/infra/freshness.js +0 -1
- package/dist/infra/http-client.js +1 -2
- package/dist/infra/index.js +0 -1
- package/dist/infra/lse-byte-budget.d.ts +10 -0
- package/dist/infra/lse-byte-budget.js +47 -0
- package/dist/infra/market-calendar.js +0 -1
- package/dist/infra/native-dependencies.js +0 -1
- package/dist/infra/node-version.js +0 -1
- package/dist/infra/open-url.js +0 -1
- package/dist/infra/opencandle-paths.js +0 -1
- package/dist/infra/rate-limiter.js +1 -1
- package/dist/market-state/alert-conditions.js +0 -1
- package/dist/market-state/alert-runner.d.ts +1 -0
- package/dist/market-state/alert-runner.js +5 -4
- package/dist/market-state/daily-report.js +0 -1
- package/dist/market-state/local-automation-service.js +0 -1
- package/dist/market-state/notification-delivery.js +0 -1
- package/dist/market-state/resolve-for-mutation.js +0 -1
- package/dist/market-state/resolve.js +0 -1
- package/dist/market-state/service.d.ts +26 -21
- package/dist/market-state/service.js +175 -36
- package/dist/market-state/summaries.js +1 -13
- package/dist/memory/index.js +0 -1
- package/dist/memory/manager.js +0 -1
- package/dist/memory/preference-extractor.js +0 -1
- package/dist/memory/retrieval.js +0 -1
- package/dist/memory/sqlite.js +60 -11
- package/dist/memory/storage.js +0 -1
- package/dist/memory/tool-defaults.js +0 -1
- package/dist/memory/types.js +0 -1
- package/dist/monitor.js +0 -1
- package/dist/onboarding/connect.js +0 -1
- package/dist/onboarding/credential-interceptor.js +0 -1
- package/dist/onboarding/degradation-accumulator.js +0 -1
- package/dist/onboarding/prompt-user.d.ts +1 -1
- package/dist/onboarding/prompt-user.js +0 -1
- package/dist/onboarding/provider-status.js +0 -1
- package/dist/onboarding/providers.d.ts +16 -1
- package/dist/onboarding/providers.js +20 -1
- package/dist/onboarding/state.js +0 -1
- package/dist/onboarding/tool-helpers.js +0 -1
- package/dist/onboarding/tool-tags.js +0 -1
- package/dist/onboarding/validate-model-key.d.ts +17 -0
- package/dist/onboarding/validate-model-key.js +86 -0
- package/dist/onboarding/validation.js +8 -1
- package/dist/pi/opencandle-extension.d.ts +2 -1
- package/dist/pi/opencandle-extension.js +4 -4
- package/dist/pi/session-action-dedupe.js +0 -1
- package/dist/pi/session-storage.js +0 -1
- package/dist/pi/session-writer-lock.js +0 -1
- package/dist/pi/session.d.ts +2 -3
- package/dist/pi/session.js +7 -6
- package/dist/pi/setup.d.ts +4 -2
- package/dist/pi/setup.js +60 -61
- package/dist/pi/tool-adapter.js +0 -1
- package/dist/pi/tui-session-coordinator.js +0 -1
- package/dist/prompts/context-builder.js +1 -2
- package/dist/prompts/disclaimer.js +0 -1
- package/dist/prompts/policy-cards.js +0 -1
- package/dist/prompts/sections.js +0 -1
- package/dist/prompts/symbol-preflight.js +0 -1
- package/dist/prompts/workflow-prompts.js +16 -15
- package/dist/providers/alpha-vantage.js +2 -3
- package/dist/providers/coingecko.js +0 -1
- package/dist/providers/errors.js +0 -1
- package/dist/providers/exa-search.js +11 -10
- package/dist/providers/external-tool-command.js +0 -1
- package/dist/providers/external-tool-error.js +0 -1
- package/dist/providers/fear-greed.js +0 -1
- package/dist/providers/finnhub.js +0 -1
- package/dist/providers/fred.js +0 -1
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.js +1 -1
- package/dist/providers/lse.d.ts +35 -0
- package/dist/providers/lse.js +284 -0
- package/dist/providers/polymarket.js +22 -6
- package/dist/providers/provider-credential-error.js +0 -1
- package/dist/providers/reddit-cli.js +0 -1
- package/dist/providers/reddit.js +0 -1
- package/dist/providers/sec-edgar.js +0 -1
- package/dist/providers/tradingview.js +1 -2
- package/dist/providers/twitter-cli.js +0 -1
- package/dist/providers/twitter.js +0 -1
- package/dist/providers/web-search.js +15 -12
- package/dist/providers/with-fallback.js +0 -1
- package/dist/providers/wrap-provider.js +1 -1
- package/dist/providers/yahoo-finance.js +68 -4
- package/dist/routing/classify-intent.js +0 -1
- package/dist/routing/defaults.js +0 -1
- package/dist/routing/entity-extractor.js +2 -3
- package/dist/routing/fund-symbols.js +0 -1
- package/dist/routing/horizon.js +0 -1
- package/dist/routing/index.js +0 -1
- package/dist/routing/legacy-rule-router.js +0 -1
- package/dist/routing/planning.js +0 -1
- package/dist/routing/route-manifest.js +1 -1
- package/dist/routing/router-llm-client.d.ts +2 -2
- package/dist/routing/router-llm-client.js +0 -1
- package/dist/routing/router-prompt.js +0 -1
- package/dist/routing/router-types.js +0 -1
- package/dist/routing/router.js +9 -3
- package/dist/routing/slot-resolver.js +0 -1
- package/dist/routing/symbol-disambiguator.js +0 -1
- package/dist/routing/turn-context.js +0 -1
- package/dist/routing/types.js +0 -1
- package/dist/runtime/answer-contracts.js +0 -1
- package/dist/runtime/artifact-contracts.js +0 -1
- package/dist/runtime/evidence.d.ts +1 -0
- package/dist/runtime/evidence.js +1 -2
- package/dist/runtime/numeric-claims.js +0 -1
- package/dist/runtime/planning-evidence.js +0 -1
- package/dist/runtime/prompt-step.js +0 -1
- package/dist/runtime/provider-tracker.js +0 -1
- package/dist/runtime/run-context.js +0 -1
- package/dist/runtime/session-coordinator.d.ts +2 -2
- package/dist/runtime/session-coordinator.js +2 -3
- package/dist/runtime/session-title.js +0 -1
- package/dist/runtime/tool-defaults-wrapper.js +0 -1
- package/dist/runtime/validation.js +0 -1
- package/dist/runtime/workflow-events.js +0 -1
- package/dist/runtime/workflow-runner.d.ts +1 -0
- package/dist/runtime/workflow-runner.js +8 -3
- package/dist/runtime/workflow-types.js +0 -1
- package/dist/sentiment/adapters/finnhub.js +0 -1
- package/dist/sentiment/adapters/reddit.js +0 -1
- package/dist/sentiment/adapters/twitter.js +0 -1
- package/dist/sentiment/adapters/web.js +0 -1
- package/dist/sentiment/index.js +4 -2
- package/dist/sentiment/insights.js +0 -1
- package/dist/sentiment/keywords.js +0 -1
- package/dist/sentiment/pipeline.js +0 -1
- package/dist/sentiment/scorer.js +0 -1
- package/dist/sentiment/store.js +0 -1
- package/dist/sentiment/trends.js +0 -1
- package/dist/sentiment/types.js +0 -1
- package/dist/system-prompt.js +0 -1
- package/dist/tool-kit.js +0 -1
- package/dist/tools/fundamentals/company-overview.d.ts +1 -1
- package/dist/tools/fundamentals/company-overview.js +2 -1
- package/dist/tools/fundamentals/comps.js +6 -4
- package/dist/tools/fundamentals/dcf.js +37 -9
- package/dist/tools/fundamentals/earnings.d.ts +1 -1
- package/dist/tools/fundamentals/earnings.js +2 -1
- package/dist/tools/fundamentals/financials.js +88 -9
- package/dist/tools/fundamentals/sec-filings.js +0 -1
- package/dist/tools/index.d.ts +121 -2
- package/dist/tools/index.js +3 -1
- package/dist/tools/interaction/ask-user.js +11 -1
- package/dist/tools/macro/event-probabilities.js +0 -1
- package/dist/tools/macro/fear-greed.d.ts +1 -1
- package/dist/tools/macro/fear-greed.js +0 -1
- package/dist/tools/macro/fred-data.d.ts +1 -1
- package/dist/tools/macro/fred-data.js +2 -1
- package/dist/tools/market/crypto-history.js +0 -1
- package/dist/tools/market/crypto-price.d.ts +2 -2
- package/dist/tools/market/crypto-price.js +0 -1
- package/dist/tools/market/price-comparison.d.ts +30 -0
- package/dist/tools/market/price-comparison.js +202 -0
- package/dist/tools/market/screen-stocks.js +0 -1
- package/dist/tools/market/search-ticker.js +1 -2
- package/dist/tools/market/stock-history.d.ts +18 -3
- package/dist/tools/market/stock-history.js +132 -18
- package/dist/tools/market/stock-quote.d.ts +2 -2
- package/dist/tools/market/stock-quote.js +0 -1
- package/dist/tools/options/greeks.js +0 -1
- package/dist/tools/options/option-chain.d.ts +2 -2
- package/dist/tools/options/option-chain.js +0 -1
- package/dist/tools/portfolio/alerts.d.ts +2 -1
- package/dist/tools/portfolio/alerts.js +228 -2
- package/dist/tools/portfolio/correlation.d.ts +1 -1
- package/dist/tools/portfolio/correlation.js +23 -5
- package/dist/tools/portfolio/daily-report.js +0 -1
- package/dist/tools/portfolio/holdings-overlap.js +0 -1
- package/dist/tools/portfolio/notifications.js +0 -1
- package/dist/tools/portfolio/risk-analysis.d.ts +2 -2
- package/dist/tools/portfolio/risk-analysis.js +0 -1
- package/dist/tools/portfolio/tracker.d.ts +3 -1
- package/dist/tools/portfolio/tracker.js +57 -10
- package/dist/tools/portfolio/watchlist.d.ts +3 -6
- package/dist/tools/portfolio/watchlist.js +101 -110
- package/dist/tools/sentiment/insight-format.js +0 -1
- package/dist/tools/sentiment/query-match.js +0 -1
- package/dist/tools/sentiment/reddit-sentiment.js +0 -1
- package/dist/tools/sentiment/sentiment-summary.js +8 -4
- package/dist/tools/sentiment/sentiment-trend.d.ts +5 -1
- package/dist/tools/sentiment/sentiment-trend.js +6 -2
- package/dist/tools/sentiment/twitter-sentiment.js +0 -1
- package/dist/tools/sentiment/untrusted-text.js +0 -1
- package/dist/tools/sentiment/web-search.d.ts +1 -1
- package/dist/tools/sentiment/web-search.js +0 -1
- package/dist/tools/sentiment/web-sentiment.js +0 -1
- package/dist/tools/technical/backtest.js +0 -1
- package/dist/tools/technical/indicators.js +0 -1
- package/dist/types/fundamentals.js +0 -1
- package/dist/types/index.js +0 -1
- package/dist/types/macro.js +0 -1
- package/dist/types/market.d.ts +8 -0
- package/dist/types/market.js +0 -1
- package/dist/types/options.js +0 -1
- package/dist/types/portfolio.js +0 -1
- package/dist/types/prediction-markets.js +0 -1
- package/dist/types/sentiment.js +0 -1
- package/dist/workflows/compare-assets.js +0 -1
- package/dist/workflows/index.js +0 -1
- package/dist/workflows/options-screener.js +0 -1
- package/dist/workflows/portfolio-builder.js +0 -1
- package/gui/web/dist/assets/CatalogOverlay-Cy8Fq0fn.js +1 -0
- package/gui/web/dist/assets/allocation-donut-DgBRIKCk.js +52 -0
- package/gui/web/dist/assets/index-DIlFyIOO.js +66 -0
- package/gui/web/dist/assets/index-DS4jESOB.css +2 -0
- package/gui/web/dist/assets/market-chart-DammaCjH.js +1 -0
- package/gui/web/dist/assets/utils-CnADgYgh.js +1 -0
- package/gui/web/dist/index.html +3 -2
- package/package.json +23 -26
- package/dist/analysts/contracts.js.map +0 -1
- package/dist/analysts/orchestrator.js.map +0 -1
- package/dist/cli-main.js.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/doctor/cli-command.js.map +0 -1
- package/dist/doctor/render.js.map +0 -1
- package/dist/doctor/report.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/infra/cache.js.map +0 -1
- package/dist/infra/freshness.js.map +0 -1
- package/dist/infra/http-client.js.map +0 -1
- package/dist/infra/index.js.map +0 -1
- package/dist/infra/market-calendar.js.map +0 -1
- package/dist/infra/native-dependencies.js.map +0 -1
- package/dist/infra/node-version.js.map +0 -1
- package/dist/infra/open-url.js.map +0 -1
- package/dist/infra/opencandle-paths.js.map +0 -1
- package/dist/infra/rate-limiter.js.map +0 -1
- package/dist/market-state/alert-conditions.js.map +0 -1
- package/dist/market-state/alert-runner.js.map +0 -1
- package/dist/market-state/daily-report.js.map +0 -1
- package/dist/market-state/local-automation-service.js.map +0 -1
- package/dist/market-state/notification-delivery.js.map +0 -1
- package/dist/market-state/resolve-for-mutation.js.map +0 -1
- package/dist/market-state/resolve.js.map +0 -1
- package/dist/market-state/service.js.map +0 -1
- package/dist/market-state/summaries.js.map +0 -1
- package/dist/memory/index.js.map +0 -1
- package/dist/memory/manager.js.map +0 -1
- package/dist/memory/preference-extractor.js.map +0 -1
- package/dist/memory/retrieval.js.map +0 -1
- package/dist/memory/sqlite.js.map +0 -1
- package/dist/memory/storage.js.map +0 -1
- package/dist/memory/tool-defaults.js.map +0 -1
- package/dist/memory/types.js.map +0 -1
- package/dist/monitor.js.map +0 -1
- package/dist/onboarding/connect.js.map +0 -1
- package/dist/onboarding/credential-interceptor.js.map +0 -1
- package/dist/onboarding/degradation-accumulator.js.map +0 -1
- package/dist/onboarding/prompt-user.js.map +0 -1
- package/dist/onboarding/provider-status.js.map +0 -1
- package/dist/onboarding/providers.js.map +0 -1
- package/dist/onboarding/state.js.map +0 -1
- package/dist/onboarding/tool-helpers.js.map +0 -1
- package/dist/onboarding/tool-tags.js.map +0 -1
- package/dist/onboarding/validation.js.map +0 -1
- package/dist/pi/opencandle-extension.js.map +0 -1
- package/dist/pi/session-action-dedupe.js.map +0 -1
- package/dist/pi/session-storage.js.map +0 -1
- package/dist/pi/session-writer-lock.js.map +0 -1
- package/dist/pi/session.js.map +0 -1
- package/dist/pi/setup.js.map +0 -1
- package/dist/pi/tool-adapter.js.map +0 -1
- package/dist/pi/tui-session-coordinator.js.map +0 -1
- package/dist/prompts/context-builder.js.map +0 -1
- package/dist/prompts/disclaimer.js.map +0 -1
- package/dist/prompts/policy-cards.js.map +0 -1
- package/dist/prompts/sections.js.map +0 -1
- package/dist/prompts/symbol-preflight.js.map +0 -1
- package/dist/prompts/workflow-prompts.js.map +0 -1
- package/dist/providers/alpha-vantage.js.map +0 -1
- package/dist/providers/coingecko.js.map +0 -1
- package/dist/providers/errors.js.map +0 -1
- package/dist/providers/exa-search.js.map +0 -1
- package/dist/providers/external-tool-command.js.map +0 -1
- package/dist/providers/external-tool-error.js.map +0 -1
- package/dist/providers/fear-greed.js.map +0 -1
- package/dist/providers/finnhub.js.map +0 -1
- package/dist/providers/fred.js.map +0 -1
- package/dist/providers/index.js.map +0 -1
- package/dist/providers/polymarket.js.map +0 -1
- package/dist/providers/provider-credential-error.js.map +0 -1
- package/dist/providers/reddit-cli.js.map +0 -1
- package/dist/providers/reddit.js.map +0 -1
- package/dist/providers/sec-edgar.js.map +0 -1
- package/dist/providers/tradingview.js.map +0 -1
- package/dist/providers/twitter-cli.js.map +0 -1
- package/dist/providers/twitter.js.map +0 -1
- package/dist/providers/web-search.js.map +0 -1
- package/dist/providers/with-fallback.js.map +0 -1
- package/dist/providers/wrap-provider.js.map +0 -1
- package/dist/providers/yahoo-finance.js.map +0 -1
- package/dist/routing/classify-intent.js.map +0 -1
- package/dist/routing/defaults.js.map +0 -1
- package/dist/routing/entity-extractor.js.map +0 -1
- package/dist/routing/fund-symbols.js.map +0 -1
- package/dist/routing/horizon.js.map +0 -1
- package/dist/routing/index.js.map +0 -1
- package/dist/routing/legacy-rule-router.js.map +0 -1
- package/dist/routing/planning.js.map +0 -1
- package/dist/routing/route-manifest.js.map +0 -1
- package/dist/routing/router-llm-client.js.map +0 -1
- package/dist/routing/router-prompt.js.map +0 -1
- package/dist/routing/router-types.js.map +0 -1
- package/dist/routing/router.js.map +0 -1
- package/dist/routing/slot-resolver.js.map +0 -1
- package/dist/routing/symbol-disambiguator.js.map +0 -1
- package/dist/routing/turn-context.js.map +0 -1
- package/dist/routing/types.js.map +0 -1
- package/dist/runtime/answer-contracts.js.map +0 -1
- package/dist/runtime/artifact-contracts.js.map +0 -1
- package/dist/runtime/evidence.js.map +0 -1
- package/dist/runtime/numeric-claims.js.map +0 -1
- package/dist/runtime/planning-evidence.js.map +0 -1
- package/dist/runtime/prompt-step.js.map +0 -1
- package/dist/runtime/provider-tracker.js.map +0 -1
- package/dist/runtime/run-context.js.map +0 -1
- package/dist/runtime/session-coordinator.js.map +0 -1
- package/dist/runtime/session-title.js.map +0 -1
- package/dist/runtime/tool-defaults-wrapper.js.map +0 -1
- package/dist/runtime/validation.js.map +0 -1
- package/dist/runtime/workflow-events.js.map +0 -1
- package/dist/runtime/workflow-runner.js.map +0 -1
- package/dist/runtime/workflow-types.js.map +0 -1
- package/dist/sentiment/adapters/finnhub.js.map +0 -1
- package/dist/sentiment/adapters/reddit.js.map +0 -1
- package/dist/sentiment/adapters/twitter.js.map +0 -1
- package/dist/sentiment/adapters/web.js.map +0 -1
- package/dist/sentiment/index.js.map +0 -1
- package/dist/sentiment/insights.js.map +0 -1
- package/dist/sentiment/keywords.js.map +0 -1
- package/dist/sentiment/pipeline.js.map +0 -1
- package/dist/sentiment/scorer.js.map +0 -1
- package/dist/sentiment/store.js.map +0 -1
- package/dist/sentiment/trends.js.map +0 -1
- package/dist/sentiment/types.js.map +0 -1
- package/dist/system-prompt.js.map +0 -1
- package/dist/tool-kit.js.map +0 -1
- package/dist/tools/fundamentals/company-overview.js.map +0 -1
- package/dist/tools/fundamentals/comps.js.map +0 -1
- package/dist/tools/fundamentals/dcf.js.map +0 -1
- package/dist/tools/fundamentals/earnings.js.map +0 -1
- package/dist/tools/fundamentals/financials.js.map +0 -1
- package/dist/tools/fundamentals/sec-filings.js.map +0 -1
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/interaction/ask-user.js.map +0 -1
- package/dist/tools/macro/event-probabilities.js.map +0 -1
- package/dist/tools/macro/fear-greed.js.map +0 -1
- package/dist/tools/macro/fred-data.js.map +0 -1
- package/dist/tools/market/crypto-history.js.map +0 -1
- package/dist/tools/market/crypto-price.js.map +0 -1
- package/dist/tools/market/screen-stocks.js.map +0 -1
- package/dist/tools/market/search-ticker.js.map +0 -1
- package/dist/tools/market/stock-history.js.map +0 -1
- package/dist/tools/market/stock-quote.js.map +0 -1
- package/dist/tools/options/greeks.js.map +0 -1
- package/dist/tools/options/option-chain.js.map +0 -1
- package/dist/tools/portfolio/alerts.js.map +0 -1
- package/dist/tools/portfolio/correlation.js.map +0 -1
- package/dist/tools/portfolio/daily-report.js.map +0 -1
- package/dist/tools/portfolio/holdings-overlap.js.map +0 -1
- package/dist/tools/portfolio/notifications.js.map +0 -1
- package/dist/tools/portfolio/risk-analysis.js.map +0 -1
- package/dist/tools/portfolio/tracker.js.map +0 -1
- package/dist/tools/portfolio/watchlist.js.map +0 -1
- package/dist/tools/sentiment/insight-format.js.map +0 -1
- package/dist/tools/sentiment/query-match.js.map +0 -1
- package/dist/tools/sentiment/reddit-sentiment.js.map +0 -1
- package/dist/tools/sentiment/sentiment-summary.js.map +0 -1
- package/dist/tools/sentiment/sentiment-trend.js.map +0 -1
- package/dist/tools/sentiment/twitter-sentiment.js.map +0 -1
- package/dist/tools/sentiment/untrusted-text.js.map +0 -1
- package/dist/tools/sentiment/web-search.js.map +0 -1
- package/dist/tools/sentiment/web-sentiment.js.map +0 -1
- package/dist/tools/technical/backtest.js.map +0 -1
- package/dist/tools/technical/indicators.js.map +0 -1
- package/dist/types/fundamentals.js.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/types/macro.js.map +0 -1
- package/dist/types/market.js.map +0 -1
- package/dist/types/options.js.map +0 -1
- package/dist/types/portfolio.js.map +0 -1
- package/dist/types/prediction-markets.js.map +0 -1
- package/dist/types/sentiment.js.map +0 -1
- package/dist/workflows/compare-assets.js.map +0 -1
- package/dist/workflows/index.js.map +0 -1
- package/dist/workflows/options-screener.js.map +0 -1
- package/dist/workflows/portfolio-builder.js.map +0 -1
- package/gui/server/ask-user-bridge.ts +0 -89
- package/gui/server/automation-heartbeat.ts +0 -97
- package/gui/server/background-quotes.ts +0 -127
- package/gui/server/chat-event-adapter.ts +0 -294
- package/gui/server/gui-session-manager.ts +0 -5
- package/gui/server/http-routes.ts +0 -1201
- package/gui/server/invoke-tool.ts +0 -490
- package/gui/server/live-chat-event-adapter.ts +0 -243
- package/gui/server/local-session-coordinator.ts +0 -97
- package/gui/server/market-state-api.ts +0 -331
- package/gui/server/model-setup.ts +0 -254
- package/gui/server/package.json +0 -5
- package/gui/server/private-api-access.ts +0 -62
- package/gui/server/projector.ts +0 -392
- package/gui/server/prompt-observation.ts +0 -58
- package/gui/server/quote-snapshot-store.ts +0 -50
- package/gui/server/server.ts +0 -289
- package/gui/server/session-actions.ts +0 -323
- package/gui/server/session-entry-wait.ts +0 -179
- package/gui/server/shutdown.ts +0 -47
- package/gui/server/tool-invoke-ack.ts +0 -49
- package/gui/server/tool-metadata.ts +0 -167
- package/gui/server/websocket.ts +0 -138
- package/gui/server/writer-lock.ts +0 -1
- package/gui/server/ws-hub.ts +0 -403
- package/gui/shared/chat-events.ts +0 -165
- package/gui/shared/event-reducer.ts +0 -220
- package/gui/web/dist/assets/CatalogOverlay-DZ1niyQm.js +0 -1
- package/gui/web/dist/assets/index-D4F9AJnn.css +0 -2
- package/gui/web/dist/assets/index-DtqMMBTr.js +0 -65
- package/src/analysts/contracts.ts +0 -176
- package/src/analysts/orchestrator.ts +0 -244
- package/src/cli-main.ts +0 -510
- package/src/cli.ts +0 -17
- package/src/config.ts +0 -272
- package/src/doctor/cli-command.ts +0 -83
- package/src/doctor/render.ts +0 -37
- package/src/doctor/report.ts +0 -638
- package/src/index.ts +0 -5
- package/src/infra/cache.ts +0 -127
- package/src/infra/freshness.ts +0 -165
- package/src/infra/http-client.ts +0 -134
- package/src/infra/index.ts +0 -14
- package/src/infra/market-calendar.ts +0 -193
- package/src/infra/native-dependencies.ts +0 -84
- package/src/infra/node-version.ts +0 -23
- package/src/infra/open-url.ts +0 -28
- package/src/infra/opencandle-paths.ts +0 -53
- package/src/infra/rate-limiter.ts +0 -77
- package/src/market-state/alert-conditions.ts +0 -82
- package/src/market-state/alert-runner.ts +0 -863
- package/src/market-state/daily-report.ts +0 -237
- package/src/market-state/local-automation-service.ts +0 -162
- package/src/market-state/notification-delivery.ts +0 -158
- package/src/market-state/resolve-for-mutation.ts +0 -24
- package/src/market-state/resolve.ts +0 -112
- package/src/market-state/service.ts +0 -2208
- package/src/market-state/summaries.ts +0 -75
- package/src/memory/index.ts +0 -10
- package/src/memory/manager.ts +0 -190
- package/src/memory/preference-extractor.ts +0 -106
- package/src/memory/retrieval.ts +0 -71
- package/src/memory/sqlite.ts +0 -577
- package/src/memory/storage.ts +0 -195
- package/src/memory/tool-defaults.ts +0 -108
- package/src/memory/types.ts +0 -71
- package/src/monitor.ts +0 -123
- package/src/onboarding/connect.ts +0 -177
- package/src/onboarding/credential-interceptor.ts +0 -122
- package/src/onboarding/degradation-accumulator.ts +0 -77
- package/src/onboarding/prompt-user.ts +0 -85
- package/src/onboarding/provider-status.ts +0 -382
- package/src/onboarding/providers.ts +0 -442
- package/src/onboarding/state.ts +0 -216
- package/src/onboarding/tool-helpers.ts +0 -104
- package/src/onboarding/tool-tags.ts +0 -244
- package/src/onboarding/validation.ts +0 -152
- package/src/pi/opencandle-extension.ts +0 -1294
- package/src/pi/session-action-dedupe.ts +0 -155
- package/src/pi/session-storage.ts +0 -5
- package/src/pi/session-writer-lock.ts +0 -426
- package/src/pi/session.ts +0 -84
- package/src/pi/setup.ts +0 -399
- package/src/pi/tool-adapter.ts +0 -49
- package/src/pi/tui-session-coordinator.ts +0 -351
- package/src/prompts/context-builder.ts +0 -326
- package/src/prompts/disclaimer.ts +0 -9
- package/src/prompts/policy-cards.ts +0 -228
- package/src/prompts/sections.ts +0 -46
- package/src/prompts/symbol-preflight.ts +0 -80
- package/src/prompts/workflow-prompts.ts +0 -504
- package/src/providers/alpha-vantage.ts +0 -340
- package/src/providers/coingecko.ts +0 -95
- package/src/providers/errors.ts +0 -9
- package/src/providers/exa-search.ts +0 -375
- package/src/providers/external-tool-command.ts +0 -164
- package/src/providers/external-tool-error.ts +0 -20
- package/src/providers/fear-greed.ts +0 -45
- package/src/providers/finnhub.ts +0 -125
- package/src/providers/fred.ts +0 -83
- package/src/providers/index.ts +0 -17
- package/src/providers/polymarket.ts +0 -214
- package/src/providers/provider-credential-error.ts +0 -23
- package/src/providers/reddit-cli.ts +0 -286
- package/src/providers/reddit.ts +0 -106
- package/src/providers/sec-edgar.ts +0 -326
- package/src/providers/tradingview.ts +0 -399
- package/src/providers/twitter-cli.ts +0 -202
- package/src/providers/twitter.ts +0 -102
- package/src/providers/web-search.ts +0 -303
- package/src/providers/with-fallback.ts +0 -42
- package/src/providers/wrap-provider.ts +0 -105
- package/src/providers/yahoo-finance.ts +0 -984
- package/src/routing/classify-intent.ts +0 -380
- package/src/routing/defaults.ts +0 -29
- package/src/routing/entity-extractor.ts +0 -557
- package/src/routing/fund-symbols.ts +0 -58
- package/src/routing/horizon.ts +0 -7
- package/src/routing/index.ts +0 -70
- package/src/routing/legacy-rule-router.ts +0 -13
- package/src/routing/planning.ts +0 -829
- package/src/routing/route-manifest.ts +0 -308
- package/src/routing/router-llm-client.ts +0 -64
- package/src/routing/router-prompt.ts +0 -159
- package/src/routing/router-types.ts +0 -84
- package/src/routing/router.ts +0 -1332
- package/src/routing/slot-resolver.ts +0 -213
- package/src/routing/symbol-disambiguator.ts +0 -72
- package/src/routing/turn-context.ts +0 -108
- package/src/routing/types.ts +0 -77
- package/src/runtime/answer-contracts.ts +0 -693
- package/src/runtime/artifact-contracts.ts +0 -77
- package/src/runtime/evidence.ts +0 -78
- package/src/runtime/numeric-claims.ts +0 -108
- package/src/runtime/planning-evidence.ts +0 -597
- package/src/runtime/prompt-step.ts +0 -185
- package/src/runtime/provider-tracker.ts +0 -40
- package/src/runtime/run-context.ts +0 -32
- package/src/runtime/session-coordinator.ts +0 -1037
- package/src/runtime/session-title.ts +0 -60
- package/src/runtime/tool-defaults-wrapper.ts +0 -43
- package/src/runtime/validation.ts +0 -211
- package/src/runtime/workflow-events.ts +0 -77
- package/src/runtime/workflow-runner.ts +0 -182
- package/src/runtime/workflow-types.ts +0 -105
- package/src/sentiment/adapters/finnhub.ts +0 -49
- package/src/sentiment/adapters/reddit.ts +0 -65
- package/src/sentiment/adapters/twitter.ts +0 -36
- package/src/sentiment/adapters/web.ts +0 -44
- package/src/sentiment/index.ts +0 -49
- package/src/sentiment/insights.ts +0 -269
- package/src/sentiment/keywords.ts +0 -31
- package/src/sentiment/pipeline.ts +0 -91
- package/src/sentiment/scorer.ts +0 -89
- package/src/sentiment/store.ts +0 -260
- package/src/sentiment/trends.ts +0 -96
- package/src/sentiment/types.ts +0 -112
- package/src/system-prompt.ts +0 -115
- package/src/tool-kit.ts +0 -69
- package/src/tools/AGENTS.md +0 -36
- package/src/tools/fundamentals/company-overview.ts +0 -64
- package/src/tools/fundamentals/comps.ts +0 -180
- package/src/tools/fundamentals/dcf.ts +0 -447
- package/src/tools/fundamentals/earnings.ts +0 -57
- package/src/tools/fundamentals/financials.ts +0 -63
- package/src/tools/fundamentals/sec-filings.ts +0 -105
- package/src/tools/index.ts +0 -104
- package/src/tools/interaction/ask-user.ts +0 -93
- package/src/tools/macro/event-probabilities.ts +0 -141
- package/src/tools/macro/fear-greed.ts +0 -41
- package/src/tools/macro/fred-data.ts +0 -92
- package/src/tools/market/crypto-history.ts +0 -72
- package/src/tools/market/crypto-price.ts +0 -65
- package/src/tools/market/screen-stocks.ts +0 -290
- package/src/tools/market/search-ticker.ts +0 -254
- package/src/tools/market/stock-history.ts +0 -104
- package/src/tools/market/stock-quote.ts +0 -73
- package/src/tools/options/greeks.ts +0 -81
- package/src/tools/options/option-chain.ts +0 -134
- package/src/tools/portfolio/alerts.ts +0 -457
- package/src/tools/portfolio/correlation.ts +0 -189
- package/src/tools/portfolio/daily-report.ts +0 -107
- package/src/tools/portfolio/holdings-overlap.ts +0 -139
- package/src/tools/portfolio/notifications.ts +0 -45
- package/src/tools/portfolio/risk-analysis.ts +0 -173
- package/src/tools/portfolio/tracker.ts +0 -308
- package/src/tools/portfolio/watchlist.ts +0 -288
- package/src/tools/sentiment/insight-format.ts +0 -50
- package/src/tools/sentiment/query-match.ts +0 -117
- package/src/tools/sentiment/reddit-sentiment.ts +0 -403
- package/src/tools/sentiment/sentiment-summary.ts +0 -383
- package/src/tools/sentiment/sentiment-trend.ts +0 -75
- package/src/tools/sentiment/twitter-sentiment.ts +0 -287
- package/src/tools/sentiment/untrusted-text.ts +0 -21
- package/src/tools/sentiment/web-search.ts +0 -186
- package/src/tools/sentiment/web-sentiment.ts +0 -96
- package/src/tools/technical/backtest.ts +0 -336
- package/src/tools/technical/indicators.ts +0 -281
- package/src/types/fundamentals.ts +0 -47
- package/src/types/index.ts +0 -26
- package/src/types/macro.ts +0 -27
- package/src/types/market.ts +0 -46
- package/src/types/options.ts +0 -53
- package/src/types/portfolio.ts +0 -83
- package/src/types/prediction-markets.ts +0 -13
- package/src/types/sentiment.ts +0 -129
- package/src/workflows/compare-assets.ts +0 -89
- package/src/workflows/index.ts +0 -3
- package/src/workflows/options-screener.ts +0 -125
- package/src/workflows/portfolio-builder.ts +0 -63
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { Type } from "@sinclair/typebox";
|
|
2
2
|
import { getConfig } from "../../config.js";
|
|
3
|
+
import { buildFreshnessStamp, formatAsOfLine } from "../../infra/freshness.js";
|
|
4
|
+
import { isOverSoftThreshold } from "../../infra/lse-byte-budget.js";
|
|
3
5
|
import { getDailyHistory } from "../../providers/alpha-vantage.js";
|
|
6
|
+
import { getLseCandles, toLseTimeframe } from "../../providers/lse.js";
|
|
7
|
+
import { ProviderCredentialError } from "../../providers/provider-credential-error.js";
|
|
4
8
|
import { withFallback } from "../../providers/with-fallback.js";
|
|
5
9
|
import { wrapProvider } from "../../providers/wrap-provider.js";
|
|
6
10
|
import { getHistory } from "../../providers/yahoo-finance.js";
|
|
7
11
|
const DAILY_INTERVALS = new Set(["1d", "1wk", "1mo"]);
|
|
8
|
-
const HISTORY_RANGES = [
|
|
12
|
+
export const HISTORY_RANGES = [
|
|
9
13
|
"1d",
|
|
10
14
|
"5d",
|
|
11
15
|
"1mo",
|
|
@@ -18,7 +22,112 @@ const HISTORY_RANGES = [
|
|
|
18
22
|
"10y",
|
|
19
23
|
"max",
|
|
20
24
|
];
|
|
21
|
-
const HISTORY_INTERVALS = ["1m", "5m", "15m", "1h", "1d", "1wk", "1mo"];
|
|
25
|
+
export const HISTORY_INTERVALS = ["1m", "5m", "15m", "1h", "1d", "1wk", "1mo"];
|
|
26
|
+
function lseFallbackEligible(interval) {
|
|
27
|
+
return (toLseTimeframe(interval) !== undefined && !!getConfig().lseApiKey && !isOverSoftThreshold());
|
|
28
|
+
}
|
|
29
|
+
export function hasIntradayHistoryFallback(interval) {
|
|
30
|
+
return !DAILY_INTERVALS.has(interval) && lseFallbackEligible(interval);
|
|
31
|
+
}
|
|
32
|
+
export async function fetchHistoryWithFallback(symbol, range, interval) {
|
|
33
|
+
const apiKey = getConfig().alphaVantageApiKey;
|
|
34
|
+
const lseTimeframe = toLseTimeframe(interval);
|
|
35
|
+
const lseEligible = lseTimeframe !== undefined && lseFallbackEligible(interval);
|
|
36
|
+
const getLseHistory = async (timeframe) => {
|
|
37
|
+
let rows;
|
|
38
|
+
try {
|
|
39
|
+
const start = historyRangeToStart(range);
|
|
40
|
+
rows = await getLseCandles(symbol, timeframe, {
|
|
41
|
+
...(start === undefined ? {} : { start }),
|
|
42
|
+
order: "asc",
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (error instanceof ProviderCredentialError && error.provider === "lse") {
|
|
47
|
+
throw new Error(`LSE credential ${error.reason}`);
|
|
48
|
+
}
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
return rows.map((row) => {
|
|
52
|
+
// Verified UTC from a live 2026-07-14 1h capture: naive 08:00–23:00 bars
|
|
53
|
+
// match the 04:00–19:00 ET extended session. Treat naive values as UTC.
|
|
54
|
+
const utcTimestamp = /(?:Z|[+-]\d{2}:\d{2})$/i.test(row.ts) ? row.ts : `${row.ts}Z`;
|
|
55
|
+
const timestamp = Date.parse(utcTimestamp) / 1_000;
|
|
56
|
+
return {
|
|
57
|
+
date: row.ts.slice(0, 10),
|
|
58
|
+
...(Number.isFinite(timestamp) ? { timestamp } : {}),
|
|
59
|
+
open: row.open,
|
|
60
|
+
high: row.high,
|
|
61
|
+
low: row.low,
|
|
62
|
+
close: row.close,
|
|
63
|
+
volume: row.volume,
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
if (DAILY_INTERVALS.has(interval)) {
|
|
68
|
+
const yahooEntry = {
|
|
69
|
+
provider: "yahoo",
|
|
70
|
+
fn: () => getHistory(symbol, range, interval),
|
|
71
|
+
};
|
|
72
|
+
const entries = [yahooEntry];
|
|
73
|
+
if (apiKey) {
|
|
74
|
+
entries.push({
|
|
75
|
+
provider: "alphavantage",
|
|
76
|
+
fn: () => getDailyHistory(symbol, apiKey, range),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if (lseEligible && lseTimeframe !== undefined) {
|
|
80
|
+
entries.push({ provider: "lse", fn: () => getLseHistory(lseTimeframe) });
|
|
81
|
+
}
|
|
82
|
+
return entries.length === 1
|
|
83
|
+
? wrapProvider(yahooEntry.provider, yahooEntry.fn)
|
|
84
|
+
: withFallback(entries);
|
|
85
|
+
}
|
|
86
|
+
if (lseEligible && lseTimeframe !== undefined) {
|
|
87
|
+
return withFallback([
|
|
88
|
+
{ provider: "yahoo", fn: () => getHistory(symbol, range, interval) },
|
|
89
|
+
{ provider: "lse", fn: () => getLseHistory(lseTimeframe) },
|
|
90
|
+
]);
|
|
91
|
+
}
|
|
92
|
+
return wrapProvider("yahoo", () => getHistory(symbol, range, interval));
|
|
93
|
+
}
|
|
94
|
+
export function historyRangeToStart(range, now = new Date()) {
|
|
95
|
+
if (range === "max")
|
|
96
|
+
return undefined;
|
|
97
|
+
const start = new Date(now);
|
|
98
|
+
switch (range) {
|
|
99
|
+
case "1d":
|
|
100
|
+
start.setUTCDate(start.getUTCDate() - 1);
|
|
101
|
+
break;
|
|
102
|
+
case "5d":
|
|
103
|
+
start.setUTCDate(start.getUTCDate() - 5);
|
|
104
|
+
break;
|
|
105
|
+
case "1mo":
|
|
106
|
+
start.setUTCMonth(start.getUTCMonth() - 1);
|
|
107
|
+
break;
|
|
108
|
+
case "3mo":
|
|
109
|
+
start.setUTCMonth(start.getUTCMonth() - 3);
|
|
110
|
+
break;
|
|
111
|
+
case "6mo":
|
|
112
|
+
start.setUTCMonth(start.getUTCMonth() - 6);
|
|
113
|
+
break;
|
|
114
|
+
case "ytd":
|
|
115
|
+
return `${start.getUTCFullYear()}-01-01`;
|
|
116
|
+
case "1y":
|
|
117
|
+
start.setUTCFullYear(start.getUTCFullYear() - 1);
|
|
118
|
+
break;
|
|
119
|
+
case "2y":
|
|
120
|
+
start.setUTCFullYear(start.getUTCFullYear() - 2);
|
|
121
|
+
break;
|
|
122
|
+
case "5y":
|
|
123
|
+
start.setUTCFullYear(start.getUTCFullYear() - 5);
|
|
124
|
+
break;
|
|
125
|
+
case "10y":
|
|
126
|
+
start.setUTCFullYear(start.getUTCFullYear() - 10);
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
return start.toISOString().slice(0, 10);
|
|
130
|
+
}
|
|
22
131
|
const params = Type.Object({
|
|
23
132
|
symbol: Type.String({ description: "Stock ticker symbol (e.g. AAPL, MSFT)" }),
|
|
24
133
|
range: Type.Optional(Type.Union(HISTORY_RANGES.map((range) => Type.Literal(range)), {
|
|
@@ -37,21 +146,9 @@ export const stockHistoryTool = {
|
|
|
37
146
|
const symbol = args.symbol.toUpperCase();
|
|
38
147
|
const range = args.range ?? "6mo";
|
|
39
148
|
const interval = args.interval ?? "1d";
|
|
40
|
-
const
|
|
41
|
-
let result;
|
|
42
|
-
if (DAILY_INTERVALS.has(interval) && apiKey) {
|
|
43
|
-
// Daily or above — can fall back to Alpha Vantage
|
|
44
|
-
result = await withFallback([
|
|
45
|
-
{ provider: "yahoo", fn: () => getHistory(symbol, range, interval) },
|
|
46
|
-
{ provider: "alphavantage", fn: () => getDailyHistory(symbol, apiKey, range) },
|
|
47
|
-
]);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
// Intraday — no cross-provider fallback
|
|
51
|
-
result = await wrapProvider("yahoo", () => getHistory(symbol, range, interval));
|
|
52
|
-
}
|
|
149
|
+
const result = await fetchHistoryWithFallback(symbol, range, interval);
|
|
53
150
|
if (result.status === "unavailable") {
|
|
54
|
-
const intradayNote = !DAILY_INTERVALS.has(interval)
|
|
151
|
+
const intradayNote = !DAILY_INTERVALS.has(interval) && !hasIntradayHistoryFallback(interval)
|
|
55
152
|
? ` No alternate source for ${interval} data.`
|
|
56
153
|
: "";
|
|
57
154
|
return {
|
|
@@ -65,9 +162,16 @@ export const stockHistoryTool = {
|
|
|
65
162
|
};
|
|
66
163
|
}
|
|
67
164
|
const bars = result.data;
|
|
165
|
+
const freshness = buildFreshnessStamp({
|
|
166
|
+
asOf: bars.at(-1)?.timestamp ?? bars.at(-1)?.date,
|
|
167
|
+
stale: result.stale,
|
|
168
|
+
cached: result.cached,
|
|
169
|
+
cachedAt: result.stale ? result.timestamp : undefined,
|
|
170
|
+
});
|
|
68
171
|
const summary = [
|
|
69
172
|
`${symbol} — ${bars.length} bars (${range}, ${interval})`,
|
|
70
173
|
`Period: ${bars[0]?.date} to ${bars[bars.length - 1]?.date}`,
|
|
174
|
+
...(result.stale ? [`Data status: Stale cache. ${formatAsOfLine(freshness)}`] : []),
|
|
71
175
|
];
|
|
72
176
|
// Include last 10 bars as sample
|
|
73
177
|
const recent = bars.slice(-10);
|
|
@@ -75,7 +179,17 @@ export const stockHistoryTool = {
|
|
|
75
179
|
.map((b) => `${b.date} | O:${b.open.toFixed(2)} H:${b.high.toFixed(2)} L:${b.low.toFixed(2)} C:${b.close.toFixed(2)} V:${b.volume.toLocaleString()}`)
|
|
76
180
|
.join("\n");
|
|
77
181
|
const text = [...summary, "", "Recent bars:", table].join("\n");
|
|
78
|
-
return {
|
|
182
|
+
return {
|
|
183
|
+
content: [{ type: "text", text }],
|
|
184
|
+
details: result.stale
|
|
185
|
+
? {
|
|
186
|
+
bars,
|
|
187
|
+
provider: result.provider,
|
|
188
|
+
providerTimestamp: result.timestamp,
|
|
189
|
+
stale: true,
|
|
190
|
+
freshness,
|
|
191
|
+
}
|
|
192
|
+
: bars,
|
|
193
|
+
};
|
|
79
194
|
},
|
|
80
195
|
};
|
|
81
|
-
//# sourceMappingURL=stock-history.js.map
|
|
@@ -4,7 +4,7 @@ import type { StockQuote } from "../../types/market.js";
|
|
|
4
4
|
declare const params: import("@sinclair/typebox").TObject<{
|
|
5
5
|
symbol: import("@sinclair/typebox").TString;
|
|
6
6
|
}>;
|
|
7
|
-
export declare const stockQuoteTool: AgentTool<typeof params, StockQuote & {
|
|
7
|
+
export declare const stockQuoteTool: AgentTool<typeof params, (StockQuote & {
|
|
8
8
|
freshness: FreshnessStamp;
|
|
9
|
-
}>;
|
|
9
|
+
}) | null>;
|
|
10
10
|
export {};
|
|
@@ -6,7 +6,7 @@ declare const params: import("@sinclair/typebox").TObject<{
|
|
|
6
6
|
expiration: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
7
7
|
type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"call">, import("@sinclair/typebox").TLiteral<"put">, import("@sinclair/typebox").TLiteral<"CALL">, import("@sinclair/typebox").TLiteral<"PUT">]>>;
|
|
8
8
|
}>;
|
|
9
|
-
export declare const optionChainTool: AgentTool<typeof params, OptionsChain & {
|
|
9
|
+
export declare const optionChainTool: AgentTool<typeof params, (OptionsChain & {
|
|
10
10
|
freshness: FreshnessStamp;
|
|
11
|
-
}>;
|
|
11
|
+
}) | null>;
|
|
12
12
|
export {};
|
|
@@ -98,4 +98,3 @@ function formatContract(c) {
|
|
|
98
98
|
const itm = c.inTheMoney ? "*" : " ";
|
|
99
99
|
return `${itm}$${c.strike.toFixed(2)} | $${c.bid.toFixed(2)}/$${c.ask.toFixed(2)} | $${c.lastPrice.toFixed(2)} | ${c.volume} | ${c.openInterest} | ${(c.impliedVolatility * 100).toFixed(1)}% | ${c.greeks.delta.toFixed(3)} | ${c.greeks.gamma.toFixed(3)} | ${c.greeks.theta.toFixed(3)} | ${c.greeks.vega.toFixed(3)} | ${c.greeks.rho.toFixed(3)}`;
|
|
100
100
|
}
|
|
101
|
-
//# sourceMappingURL=option-chain.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
declare const params: import("@sinclair/typebox").TObject<{
|
|
3
|
-
action: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"create_price_above">, import("@sinclair/typebox").TLiteral<"create_price_below">, import("@sinclair/typebox").TLiteral<"create_price_above_sma">, import("@sinclair/typebox").TLiteral<"create_price_below_sma">, import("@sinclair/typebox").TLiteral<"create_rsi_above">, import("@sinclair/typebox").TLiteral<"create_rsi_below">, import("@sinclair/typebox").TLiteral<"create_volume_spike">, import("@sinclair/typebox").TLiteral<"create_percent_move_up">, import("@sinclair/typebox").TLiteral<"create_percent_move_down">, import("@sinclair/typebox").TLiteral<"create_sma_cross_above">, import("@sinclair/typebox").TLiteral<"create_sma_cross_below">, import("@sinclair/typebox").TLiteral<"set_enabled">, import("@sinclair/typebox").TLiteral<"list">, import("@sinclair/typebox").TLiteral<"status">, import("@sinclair/typebox").TLiteral<"check">]>;
|
|
3
|
+
action: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"create_price_above">, import("@sinclair/typebox").TLiteral<"create_price_below">, import("@sinclair/typebox").TLiteral<"create_price_above_sma">, import("@sinclair/typebox").TLiteral<"create_price_below_sma">, import("@sinclair/typebox").TLiteral<"create_rsi_above">, import("@sinclair/typebox").TLiteral<"create_rsi_below">, import("@sinclair/typebox").TLiteral<"create_volume_spike">, import("@sinclair/typebox").TLiteral<"create_percent_move_up">, import("@sinclair/typebox").TLiteral<"create_percent_move_down">, import("@sinclair/typebox").TLiteral<"create_sma_cross_above">, import("@sinclair/typebox").TLiteral<"create_sma_cross_below">, import("@sinclair/typebox").TLiteral<"set_enabled">, import("@sinclair/typebox").TLiteral<"update">, import("@sinclair/typebox").TLiteral<"delete">, import("@sinclair/typebox").TLiteral<"list">, import("@sinclair/typebox").TLiteral<"status">, import("@sinclair/typebox").TLiteral<"check">]>;
|
|
4
4
|
symbol: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
5
5
|
threshold: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
6
6
|
period: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
|
|
@@ -8,6 +8,7 @@ declare const params: import("@sinclair/typebox").TObject<{
|
|
|
8
8
|
slow_period: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
|
|
9
9
|
cooldown_seconds: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
|
|
10
10
|
id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
11
|
+
condition_action: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"create_price_above">, import("@sinclair/typebox").TLiteral<"create_price_below">, import("@sinclair/typebox").TLiteral<"create_price_above_sma">, import("@sinclair/typebox").TLiteral<"create_price_below_sma">, import("@sinclair/typebox").TLiteral<"create_rsi_above">, import("@sinclair/typebox").TLiteral<"create_rsi_below">, import("@sinclair/typebox").TLiteral<"create_volume_spike">, import("@sinclair/typebox").TLiteral<"create_percent_move_up">, import("@sinclair/typebox").TLiteral<"create_percent_move_down">, import("@sinclair/typebox").TLiteral<"create_sma_cross_above">, import("@sinclair/typebox").TLiteral<"create_sma_cross_below">]>>;
|
|
11
12
|
enabled: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
12
13
|
check_after_create: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
13
14
|
}>;
|
|
@@ -16,6 +16,7 @@ const ACTION_DESCRIPTION = [
|
|
|
16
16
|
"create_sma_cross_above/create_sma_cross_below for fast/slow SMA crossing alerts,",
|
|
17
17
|
"create_rsi_above/create_rsi_below for RSI alerts,",
|
|
18
18
|
"create_volume_spike for volume alerts, set_enabled to enable or disable an alert,",
|
|
19
|
+
"update to replace an alert rule definition, delete to remove a rule,",
|
|
19
20
|
"and status to inspect local runner/check history.",
|
|
20
21
|
"When the user asks to create an alert and check it now in the same request,",
|
|
21
22
|
"set check_after_create to true on the create action.",
|
|
@@ -34,6 +35,8 @@ const params = Type.Object({
|
|
|
34
35
|
Type.Literal("create_sma_cross_above"),
|
|
35
36
|
Type.Literal("create_sma_cross_below"),
|
|
36
37
|
Type.Literal("set_enabled"),
|
|
38
|
+
Type.Literal("update"),
|
|
39
|
+
Type.Literal("delete"),
|
|
37
40
|
Type.Literal("list"),
|
|
38
41
|
Type.Literal("status"),
|
|
39
42
|
Type.Literal("check"),
|
|
@@ -58,6 +61,21 @@ const params = Type.Object({
|
|
|
58
61
|
description: "Cooldown between repeated trigger events. Default: 3600",
|
|
59
62
|
})),
|
|
60
63
|
id: Type.Optional(Type.Number({ description: "Alert rule id for update actions" })),
|
|
64
|
+
condition_action: Type.Optional(Type.Union([
|
|
65
|
+
Type.Literal("create_price_above"),
|
|
66
|
+
Type.Literal("create_price_below"),
|
|
67
|
+
Type.Literal("create_price_above_sma"),
|
|
68
|
+
Type.Literal("create_price_below_sma"),
|
|
69
|
+
Type.Literal("create_rsi_above"),
|
|
70
|
+
Type.Literal("create_rsi_below"),
|
|
71
|
+
Type.Literal("create_volume_spike"),
|
|
72
|
+
Type.Literal("create_percent_move_up"),
|
|
73
|
+
Type.Literal("create_percent_move_down"),
|
|
74
|
+
Type.Literal("create_sma_cross_above"),
|
|
75
|
+
Type.Literal("create_sma_cross_below"),
|
|
76
|
+
], {
|
|
77
|
+
description: "Create-style alert condition action to use when updating an existing alert rule.",
|
|
78
|
+
})),
|
|
61
79
|
enabled: Type.Optional(Type.Boolean({ description: "Whether an alert rule is enabled" })),
|
|
62
80
|
check_after_create: Type.Optional(Type.Boolean({
|
|
63
81
|
description: "Set true only when the user asks to check/run alerts immediately after creating this alert in the same request.",
|
|
@@ -66,7 +84,7 @@ const params = Type.Object({
|
|
|
66
84
|
export const alertsTool = {
|
|
67
85
|
name: "manage_alerts",
|
|
68
86
|
label: "Alerts",
|
|
69
|
-
description: "Create, pause/resume, list, check, and inspect status for durable local alerts. Actions include create_price_above, create_price_below, create_price_above_sma, create_price_below_sma, create_rsi_above, create_rsi_below, create_volume_spike, create_percent_move_up, create_percent_move_down, create_sma_cross_above, create_sma_cross_below, set_enabled, list, status, and check. Local background monitoring runs only while an OpenCandle writer/monitor process is active; manual checks are always available. If the user asks to create an alert and check it now, use the create action with check_after_create=true.",
|
|
87
|
+
description: "Create, update, delete, pause/resume, list, check, and inspect status for durable local alerts. Actions include create_price_above, create_price_below, create_price_above_sma, create_price_below_sma, create_rsi_above, create_rsi_below, create_volume_spike, create_percent_move_up, create_percent_move_down, create_sma_cross_above, create_sma_cross_below, set_enabled, update, delete, list, status, and check. Local background monitoring runs only while an OpenCandle writer/monitor process is active; manual checks are always available. If the user asks to create an alert and check it now, use the create action with check_after_create=true.",
|
|
70
88
|
parameters: params,
|
|
71
89
|
async execute(_toolCallId, args) {
|
|
72
90
|
const db = initDefaultDatabase();
|
|
@@ -278,6 +296,62 @@ export const alertsTool = {
|
|
|
278
296
|
details: rule,
|
|
279
297
|
};
|
|
280
298
|
}
|
|
299
|
+
if (args.action === "update") {
|
|
300
|
+
if (args.id == null) {
|
|
301
|
+
throw new Error("id is required for update.");
|
|
302
|
+
}
|
|
303
|
+
const existing = service.listAlertRules().find((rule) => rule.id === args.id);
|
|
304
|
+
if (existing == null) {
|
|
305
|
+
return {
|
|
306
|
+
content: [
|
|
307
|
+
{
|
|
308
|
+
type: "text",
|
|
309
|
+
text: `Alert #${args.id} not found. Use the list action to see alert ids.`,
|
|
310
|
+
},
|
|
311
|
+
],
|
|
312
|
+
details: null,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
const conditionAction = args.condition_action ?? createActionFromRule(existing);
|
|
316
|
+
if (conditionAction == null) {
|
|
317
|
+
throw new Error(`Alert #${args.id} uses condition ${existing.conditionType}, which cannot be updated without condition_action.`);
|
|
318
|
+
}
|
|
319
|
+
const payload = await buildAlertRulePayload(service, conditionAction, args, existing);
|
|
320
|
+
if (payload.status === "needs_selection")
|
|
321
|
+
return candidateResult(payload.resolution, "alert");
|
|
322
|
+
const rule = service.updateAlertRule(args.id, {
|
|
323
|
+
...payload.input,
|
|
324
|
+
enabled: args.enabled,
|
|
325
|
+
});
|
|
326
|
+
return {
|
|
327
|
+
content: [
|
|
328
|
+
{
|
|
329
|
+
type: "text",
|
|
330
|
+
text: rule == null
|
|
331
|
+
? `Alert #${args.id} not found. Use the list action to see alert ids.`
|
|
332
|
+
: `Updated alert #${rule.id}.`,
|
|
333
|
+
},
|
|
334
|
+
],
|
|
335
|
+
details: rule,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
if (args.action === "delete") {
|
|
339
|
+
if (args.id == null) {
|
|
340
|
+
throw new Error("id is required for delete.");
|
|
341
|
+
}
|
|
342
|
+
const rule = service.deleteAlertRule(args.id);
|
|
343
|
+
return {
|
|
344
|
+
content: [
|
|
345
|
+
{
|
|
346
|
+
type: "text",
|
|
347
|
+
text: rule == null
|
|
348
|
+
? `Alert #${args.id} not found. Use the list action to see alert ids.`
|
|
349
|
+
: `Deleted alert #${rule.id}.`,
|
|
350
|
+
},
|
|
351
|
+
],
|
|
352
|
+
details: rule,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
281
355
|
const result = await checkAlerts(service);
|
|
282
356
|
return {
|
|
283
357
|
content: [{ type: "text", text: result.lines.join("\n") }],
|
|
@@ -289,6 +363,159 @@ export const alertsTool = {
|
|
|
289
363
|
}
|
|
290
364
|
},
|
|
291
365
|
};
|
|
366
|
+
async function buildAlertRulePayload(service, action, args, existing) {
|
|
367
|
+
const instrument = await resolveAlertInstrument(service, args.symbol, existing);
|
|
368
|
+
if (instrument.status === "needs_selection")
|
|
369
|
+
return instrument;
|
|
370
|
+
const existingCondition = conditionRecord(existing);
|
|
371
|
+
const cooldownSeconds = args.cooldown_seconds === undefined
|
|
372
|
+
? undefined
|
|
373
|
+
: validateCooldownSeconds(args.cooldown_seconds);
|
|
374
|
+
const base = {
|
|
375
|
+
scopeType: "instrument",
|
|
376
|
+
instrumentId: instrument.id,
|
|
377
|
+
conditionVersion: ALERT_CONDITION_VERSION,
|
|
378
|
+
cooldownSeconds,
|
|
379
|
+
};
|
|
380
|
+
if (action === "create_price_above" || action === "create_price_below") {
|
|
381
|
+
const threshold = numberInput(args.threshold, existingCondition, "threshold", "threshold");
|
|
382
|
+
const isAbove = action === "create_price_above";
|
|
383
|
+
return {
|
|
384
|
+
status: "ok",
|
|
385
|
+
input: {
|
|
386
|
+
...base,
|
|
387
|
+
conditionType: isAbove ? "price_crosses_above" : "price_crosses_below",
|
|
388
|
+
condition: isAbove ? priceCrossesAbove(threshold) : priceCrossesBelow(threshold),
|
|
389
|
+
timeframe: "quote",
|
|
390
|
+
},
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
if (action === "create_price_above_sma" || action === "create_price_below_sma") {
|
|
394
|
+
const period = validateLookbackPeriod(numberInput(args.period, existingCondition, "period", "period", 50), 200);
|
|
395
|
+
return {
|
|
396
|
+
status: "ok",
|
|
397
|
+
input: {
|
|
398
|
+
...base,
|
|
399
|
+
conditionType: "price_crosses_sma",
|
|
400
|
+
condition: priceCrossesSma(period, action === "create_price_above_sma" ? "above" : "below"),
|
|
401
|
+
timeframe: "1d",
|
|
402
|
+
},
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
if (action === "create_rsi_above" || action === "create_rsi_below") {
|
|
406
|
+
const threshold = numberInput(args.threshold, existingCondition, "threshold", "threshold");
|
|
407
|
+
const period = validateLookbackPeriod(numberInput(args.period, existingCondition, "period", "period", 14), 100);
|
|
408
|
+
return {
|
|
409
|
+
status: "ok",
|
|
410
|
+
input: {
|
|
411
|
+
...base,
|
|
412
|
+
conditionType: "rsi_threshold",
|
|
413
|
+
condition: rsiThreshold(period, threshold, action === "create_rsi_above" ? "above" : "below"),
|
|
414
|
+
timeframe: "1d",
|
|
415
|
+
},
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
if (action === "create_volume_spike") {
|
|
419
|
+
const period = validateLookbackPeriod(numberInput(args.period, existingCondition, "lookback_period", "period", 20), 100);
|
|
420
|
+
const multiplier = numberInput(args.threshold, existingCondition, "multiplier", "threshold", 2);
|
|
421
|
+
return {
|
|
422
|
+
status: "ok",
|
|
423
|
+
input: {
|
|
424
|
+
...base,
|
|
425
|
+
conditionType: "volume_spike",
|
|
426
|
+
condition: volumeSpike(period, multiplier),
|
|
427
|
+
timeframe: "1d",
|
|
428
|
+
},
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
if (action === "create_percent_move_up" || action === "create_percent_move_down") {
|
|
432
|
+
const threshold = numberInput(args.threshold, existingCondition, "percent", "threshold");
|
|
433
|
+
if (threshold <= 0) {
|
|
434
|
+
throw new Error("threshold must be greater than 0 for percent-move alert actions.");
|
|
435
|
+
}
|
|
436
|
+
return {
|
|
437
|
+
status: "ok",
|
|
438
|
+
input: {
|
|
439
|
+
...base,
|
|
440
|
+
conditionType: "percent_move",
|
|
441
|
+
condition: percentMove(action === "create_percent_move_up" ? "up" : "down", threshold),
|
|
442
|
+
timeframe: "1d",
|
|
443
|
+
},
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
const fastPeriod = numberInput(args.fast_period, existingCondition, "fast_period", "fast_period", 50);
|
|
447
|
+
const slowPeriod = numberInput(args.slow_period, existingCondition, "slow_period", "slow_period", 200);
|
|
448
|
+
if (!Number.isInteger(fastPeriod) || !Number.isInteger(slowPeriod)) {
|
|
449
|
+
throw new Error("fast_period and slow_period must be whole-number lookback periods for SMA-cross alert actions.");
|
|
450
|
+
}
|
|
451
|
+
if (fastPeriod <= 0 || slowPeriod <= 0) {
|
|
452
|
+
throw new Error("fast_period and slow_period must be greater than 0 for SMA-cross alert actions.");
|
|
453
|
+
}
|
|
454
|
+
if (fastPeriod >= slowPeriod) {
|
|
455
|
+
throw new Error("fast_period must be less than slow_period for SMA-cross alert actions.");
|
|
456
|
+
}
|
|
457
|
+
if (slowPeriod > 400) {
|
|
458
|
+
throw new Error("slow_period must be at most 400 so alert checks can evaluate it against the runner's 2y daily history window.");
|
|
459
|
+
}
|
|
460
|
+
return {
|
|
461
|
+
status: "ok",
|
|
462
|
+
input: {
|
|
463
|
+
...base,
|
|
464
|
+
conditionType: "sma_cross",
|
|
465
|
+
condition: smaCross(fastPeriod, slowPeriod, action === "create_sma_cross_above" ? "above" : "below"),
|
|
466
|
+
timeframe: "1d",
|
|
467
|
+
},
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
async function resolveAlertInstrument(service, symbol, existing) {
|
|
471
|
+
if (symbol) {
|
|
472
|
+
const resolution = await resolveInstrumentForMutation(symbol);
|
|
473
|
+
if (resolution.status === "needs_selection")
|
|
474
|
+
return { status: "needs_selection", resolution };
|
|
475
|
+
return { status: "ok", id: service.upsertInstrumentRecord(resolution.instrument).id };
|
|
476
|
+
}
|
|
477
|
+
if (existing?.instrumentId != null)
|
|
478
|
+
return { status: "ok", id: existing.instrumentId };
|
|
479
|
+
throw new Error("symbol is required for update when the existing alert is not instrument-scoped.");
|
|
480
|
+
}
|
|
481
|
+
function conditionRecord(rule) {
|
|
482
|
+
return typeof rule?.conditionJson === "object" && rule.conditionJson !== null
|
|
483
|
+
? rule.conditionJson
|
|
484
|
+
: {};
|
|
485
|
+
}
|
|
486
|
+
function numberInput(value, existing, existingKey, label, fallback) {
|
|
487
|
+
if (value !== undefined)
|
|
488
|
+
return value;
|
|
489
|
+
const existingValue = existing[existingKey];
|
|
490
|
+
if (typeof existingValue === "number")
|
|
491
|
+
return existingValue;
|
|
492
|
+
if (fallback !== undefined)
|
|
493
|
+
return fallback;
|
|
494
|
+
throw new Error(`${label} is required for update.`);
|
|
495
|
+
}
|
|
496
|
+
function createActionFromRule(rule) {
|
|
497
|
+
const condition = conditionRecord(rule);
|
|
498
|
+
const direction = condition.direction;
|
|
499
|
+
if (rule.conditionType === "price_crosses_above")
|
|
500
|
+
return "create_price_above";
|
|
501
|
+
if (rule.conditionType === "price_crosses_below")
|
|
502
|
+
return "create_price_below";
|
|
503
|
+
if (rule.conditionType === "price_crosses_sma") {
|
|
504
|
+
return direction === "below" ? "create_price_below_sma" : "create_price_above_sma";
|
|
505
|
+
}
|
|
506
|
+
if (rule.conditionType === "rsi_threshold") {
|
|
507
|
+
return direction === "below" ? "create_rsi_below" : "create_rsi_above";
|
|
508
|
+
}
|
|
509
|
+
if (rule.conditionType === "volume_spike")
|
|
510
|
+
return "create_volume_spike";
|
|
511
|
+
if (rule.conditionType === "percent_move") {
|
|
512
|
+
return direction === "down" ? "create_percent_move_down" : "create_percent_move_up";
|
|
513
|
+
}
|
|
514
|
+
if (rule.conditionType === "sma_cross") {
|
|
515
|
+
return direction === "below" ? "create_sma_cross_below" : "create_sma_cross_above";
|
|
516
|
+
}
|
|
517
|
+
return null;
|
|
518
|
+
}
|
|
292
519
|
function validateLookbackPeriod(period, maxPeriod) {
|
|
293
520
|
if (!Number.isInteger(period) || period <= 0) {
|
|
294
521
|
throw new Error("period must be a whole-number lookback period greater than 0 for indicator alert actions.");
|
|
@@ -354,4 +581,3 @@ async function createResultMaybeChecked(service, rule, createdText, checkAfterCr
|
|
|
354
581
|
},
|
|
355
582
|
};
|
|
356
583
|
}
|
|
357
|
-
//# sourceMappingURL=alerts.js.map
|
|
@@ -4,7 +4,7 @@ export declare function computeCorrelation(returnsA: number[], returnsB: number[
|
|
|
4
4
|
export declare function alignReturnsByDate(historiesBySymbol: Map<string, OHLCV[]>, minOverlap?: number): Map<string, number[]>;
|
|
5
5
|
declare const params: import("@sinclair/typebox").TObject<{
|
|
6
6
|
symbols: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
|
|
7
|
-
period: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<import("@sinclair/typebox").TLiteral<"
|
|
7
|
+
period: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<import("@sinclair/typebox").TLiteral<"1y" | "2y" | "6mo">[]>>;
|
|
8
8
|
}>;
|
|
9
9
|
export declare const correlationTool: AgentTool<typeof params>;
|
|
10
10
|
export {};
|
|
@@ -39,9 +39,16 @@ export function alignReturnsByDate(historiesBySymbol, minOverlap = DEFAULT_MIN_O
|
|
|
39
39
|
}
|
|
40
40
|
// Find common dates across all symbols
|
|
41
41
|
const symbols = [...historiesBySymbol.keys()];
|
|
42
|
-
const
|
|
42
|
+
const firstSymbol = symbols[0];
|
|
43
|
+
if (!firstSymbol) {
|
|
44
|
+
throw new Error("No histories available for correlation analysis.");
|
|
45
|
+
}
|
|
46
|
+
const firstDates = priceByDate.get(firstSymbol);
|
|
47
|
+
if (!firstDates) {
|
|
48
|
+
throw new Error(`Missing price history for ${firstSymbol}.`);
|
|
49
|
+
}
|
|
43
50
|
const commonDates = [...firstDates.keys()]
|
|
44
|
-
.filter((date) => symbols.every((s) => priceByDate.get(s)
|
|
51
|
+
.filter((date) => symbols.every((s) => priceByDate.get(s)?.has(date)))
|
|
45
52
|
.sort();
|
|
46
53
|
if (commonDates.length < minOverlap) {
|
|
47
54
|
throw new Error(`Insufficient date overlap for correlation: ${commonDates.length} common dates (need ${minOverlap}+). Symbols may trade on different exchanges or have sparse history.`);
|
|
@@ -50,7 +57,14 @@ export function alignReturnsByDate(historiesBySymbol, minOverlap = DEFAULT_MIN_O
|
|
|
50
57
|
const result = new Map();
|
|
51
58
|
for (const symbol of symbols) {
|
|
52
59
|
const dateMap = priceByDate.get(symbol);
|
|
53
|
-
|
|
60
|
+
if (!dateMap)
|
|
61
|
+
throw new Error(`Missing price history for ${symbol}.`);
|
|
62
|
+
const alignedCloses = commonDates.map((d) => {
|
|
63
|
+
const close = dateMap.get(d);
|
|
64
|
+
if (close === undefined)
|
|
65
|
+
throw new Error(`Missing close for ${symbol} on ${d}.`);
|
|
66
|
+
return close;
|
|
67
|
+
});
|
|
54
68
|
result.set(symbol, computeDailyReturns(alignedCloses));
|
|
55
69
|
}
|
|
56
70
|
return result;
|
|
@@ -116,7 +130,12 @@ export const correlationTool = {
|
|
|
116
130
|
matrix[a][b] = matrix[b][a];
|
|
117
131
|
}
|
|
118
132
|
else {
|
|
119
|
-
const
|
|
133
|
+
const returnsA = returnsBySymbol.get(a);
|
|
134
|
+
const returnsB = returnsBySymbol.get(b);
|
|
135
|
+
if (!returnsA || !returnsB) {
|
|
136
|
+
throw new Error(`Missing aligned returns for ${a}/${b}.`);
|
|
137
|
+
}
|
|
138
|
+
const r = computeCorrelation(returnsA, returnsB);
|
|
120
139
|
matrix[a][b] = r;
|
|
121
140
|
if (Math.abs(r) > 0.7 && a < b) {
|
|
122
141
|
warnings.push(`${a}/${b}: r=${r.toFixed(2)} — high correlation, concentration risk`);
|
|
@@ -151,4 +170,3 @@ export const correlationTool = {
|
|
|
151
170
|
};
|
|
152
171
|
},
|
|
153
172
|
};
|
|
154
|
-
//# sourceMappingURL=correlation.js.map
|
|
@@ -2,9 +2,9 @@ import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
|
2
2
|
import type { RiskMetrics } from "../../types/portfolio.js";
|
|
3
3
|
declare const params: import("@sinclair/typebox").TObject<{
|
|
4
4
|
symbol: import("@sinclair/typebox").TString;
|
|
5
|
-
period: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<import("@sinclair/typebox").TLiteral<"
|
|
5
|
+
period: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<import("@sinclair/typebox").TLiteral<"1y" | "2y" | "6mo">[]>>;
|
|
6
6
|
}>;
|
|
7
|
-
export declare const riskAnalysisTool: AgentTool<typeof params, RiskMetrics>;
|
|
7
|
+
export declare const riskAnalysisTool: AgentTool<typeof params, RiskMetrics | null>;
|
|
8
8
|
export declare function computeRiskMetrics(symbol: string, closes: number[]): RiskMetrics;
|
|
9
9
|
export declare function computeDailyReturns(prices: number[]): number[];
|
|
10
10
|
export declare function computeMaxDrawdown(prices: number[]): number;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
declare const params: import("@sinclair/typebox").TObject<{
|
|
3
|
-
action: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"add">, import("@sinclair/typebox").TLiteral<"update">, import("@sinclair/typebox").TLiteral<"remove">, import("@sinclair/typebox").TLiteral<"view">]>;
|
|
3
|
+
action: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"create">, import("@sinclair/typebox").TLiteral<"rename">, import("@sinclair/typebox").TLiteral<"add">, import("@sinclair/typebox").TLiteral<"update">, import("@sinclair/typebox").TLiteral<"remove">, import("@sinclair/typebox").TLiteral<"view">]>;
|
|
4
|
+
portfolio_name: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
5
|
+
new_portfolio_name: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
4
6
|
lot_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
|
|
5
7
|
symbol: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
6
8
|
shares: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|