@gloom-sh/terminal 0.20.18 → 0.20.19
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/package.json +1 -1
- package/src/api-client/cot.ts +5 -6
- package/src/api-client/data.ts +11 -1
- package/src/api-client/index.ts +1 -0
- package/src/api-client/request.ts +162 -40
- package/src/api-client/types/news.ts +45 -0
- package/src/api-client/types/world-venues.ts +9 -0
- package/src/app.tsx +4 -2
- package/src/architecture/floating-promise-allowlist.json +1 -1
- package/src/cli/commands/market.ts +53 -17
- package/src/cli/commands/ticker.ts +13 -6
- package/src/cli/context.ts +8 -0
- package/src/cli/desktop-pane-shot-browser.ts +3 -1
- package/src/cli/desktop-pane-shot-view.ts +0 -1
- package/src/cli/desktop-pane-shot.ts +204 -43
- package/src/cli/errors.ts +3 -9
- package/src/cli/exit-codes.ts +1 -1
- package/src/cli/glossary.ts +1 -1
- package/src/cli/help.ts +1 -1
- package/src/cli/history-rows.ts +2 -2
- package/src/cli/index.ts +1 -1
- package/src/cli/listing-arg.ts +87 -23
- package/src/cli/pane-functions/catalog-snapshot.json +17 -6
- package/src/cli/pane-functions/dom.ts +30 -2
- package/src/cli/pane-functions/freshness.ts +23 -4
- package/src/cli/pane-functions/function-help.ts +3 -3
- package/src/cli/pane-functions/headless.ts +9 -1
- package/src/cli/pane-functions/index.ts +77 -10
- package/src/cli/pane-functions/report-notices.ts +10 -0
- package/src/cli/pane-functions/resolver.ts +3 -2
- package/src/cli/pane-functions/screenshot-assessment.ts +10 -5
- package/src/cli/pane-functions/screenshot-data-evidence.ts +7 -15
- package/src/cli/pane-functions/screenshot-payload.ts +24 -10
- package/src/cli/pane-functions/screenshot-render.ts +21 -8
- package/src/cli/pane-functions/screenshot-types.ts +9 -0
- package/src/cli/quote-answer.ts +1 -1
- package/src/cli/result.ts +17 -0
- package/src/cli/scroll-truncation.ts +7 -2
- package/src/cli/ticker-resolution.ts +1 -1
- package/src/cli/unreachable.ts +21 -0
- package/src/components/chart/composite/drawing-store.ts +11 -7
- package/src/components/chart/composite/format.ts +1 -0
- package/src/components/chart/composite/legend.tsx +5 -2
- package/src/components/chart/composite/panel-surface/plot-gestures.ts +9 -2
- package/src/components/chart/composite/panel-surface.tsx +1 -1
- package/src/components/chart/composite/tools.ts +164 -39
- package/src/components/chart-table/header.tsx +2 -2
- package/src/components/chart-table/layout.ts +5 -6
- package/src/components/command-bar/routes/root/runtime.ts +11 -3
- package/src/components/command-bar/routes/ticker-search/results.ts +5 -0
- package/src/components/command-bar/selection-runtime.ts +29 -5
- package/src/components/command-bar/surface/index.tsx +4 -1
- package/src/components/command-bar/workflow/alert.ts +13 -5
- package/src/components/layout/pane/footer/model.ts +10 -2
- package/src/components/layout/pane/status-footer.ts +24 -0
- package/src/components/price-performance.tsx +26 -8
- package/src/components/reader/article-reader.tsx +12 -5
- package/src/components/ui/data-table/opentui/index.tsx +7 -0
- package/src/components/ui/table-layout.ts +32 -1
- package/src/market-data/ah-pair.ts +19 -0
- package/src/market-data/coordinator/entries.ts +6 -4
- package/src/market-data/coordinator/index.ts +14 -3
- package/src/market-data/futures-board.ts +36 -29
- package/src/market-data/futures-contract.ts +37 -1
- package/src/market-data/market/change-basis.ts +9 -0
- package/src/market-data/market/status.ts +40 -4
- package/src/market-data/performance.ts +127 -32
- package/src/market-data/quotes/time.ts +5 -2
- package/src/news/types.ts +28 -0
- package/src/notifications/app-badge.ts +2 -3
- package/src/notifications/app-notifier.ts +5 -0
- package/src/plugins/builtin/alerts/cli.ts +65 -18
- package/src/plugins/builtin/alerts/command.ts +39 -9
- package/src/plugins/builtin/alerts/event-rows.ts +9 -3
- package/src/plugins/builtin/alerts/events-pane.tsx +16 -10
- package/src/plugins/builtin/alerts/headless.ts +12 -6
- package/src/plugins/builtin/alerts/index.tsx +60 -8
- package/src/plugins/builtin/alerts/option-contract.ts +197 -0
- package/src/plugins/builtin/alerts/price.ts +30 -5
- package/src/plugins/builtin/alerts/pro-rules.ts +62 -0
- package/src/plugins/builtin/alerts/research-builder.ts +5 -10
- package/src/plugins/builtin/analytics/account-returns.ts +1 -1
- package/src/plugins/builtin/analytics/pane-model.ts +2 -2
- package/src/plugins/builtin/analytics/risk-client.ts +1 -1
- package/src/plugins/builtin/buildout/company/pane.tsx +4 -14
- package/src/plugins/builtin/catalysts/model.ts +2 -1
- package/src/plugins/builtin/chart-composer/chart-spec.ts +5 -0
- package/src/plugins/builtin/chart-composer/cli-options.ts +5 -3
- package/src/plugins/builtin/chart-composer/headless-schema.ts +14 -10
- package/src/plugins/builtin/chart-composer/headless.ts +2 -0
- package/src/plugins/builtin/chart-composer/index.tsx +17 -5
- package/src/plugins/builtin/chart-composer/pane.tsx +14 -4
- package/src/plugins/builtin/chart-composer/viewport-labels.ts +2 -17
- package/src/plugins/builtin/chat/controller/notifications.ts +1 -0
- package/src/plugins/builtin/chat/index.tsx +0 -1
- package/src/plugins/builtin/commodities-energy/index.tsx +1 -1
- package/src/plugins/builtin/company-kpis/headless.ts +1 -1
- package/src/plugins/builtin/company-kpis/model.ts +21 -9
- package/src/plugins/builtin/congress-trades/model.ts +9 -5
- package/src/plugins/builtin/cot/client.ts +2 -3
- package/src/plugins/builtin/cot/headless.ts +16 -16
- package/src/plugins/builtin/cot/index.tsx +6 -6
- package/src/plugins/builtin/cot/model.ts +25 -5
- package/src/plugins/builtin/cot/pane.tsx +11 -6
- package/src/plugins/builtin/cot/series.ts +11 -8
- package/src/plugins/builtin/cpi/model.ts +15 -4
- package/src/plugins/builtin/cpi/pane.tsx +29 -7
- package/src/plugins/builtin/doe/model.ts +30 -0
- package/src/plugins/builtin/doe/pane.tsx +8 -2
- package/src/plugins/builtin/earnings/board-table.ts +9 -4
- package/src/plugins/builtin/earnings/headless.ts +10 -3
- package/src/plugins/builtin/earnings/history-table.ts +4 -2
- package/src/plugins/builtin/earnings-calls/calendar.tsx +4 -3
- package/src/plugins/builtin/earnings-ripple/pane.tsx +2 -2
- package/src/plugins/builtin/econ/index.tsx +4 -2
- package/src/plugins/builtin/futures/model.ts +14 -1
- package/src/plugins/builtin/futures/series.ts +1 -8
- package/src/plugins/builtin/fx-matrix/index.tsx +2 -2
- package/src/plugins/builtin/insider/detail.tsx +36 -7
- package/src/plugins/builtin/insider/filing-stories.ts +110 -0
- package/src/plugins/builtin/insider/headless.ts +37 -2
- package/src/plugins/builtin/insider/index.tsx +79 -10
- package/src/plugins/builtin/insider/model.ts +43 -5
- package/src/plugins/builtin/ipo-calendar/client.ts +11 -1
- package/src/plugins/builtin/ipo-calendar/model.ts +3 -7
- package/src/plugins/builtin/jobs/headless.ts +2 -1
- package/src/plugins/builtin/jobs/model.ts +6 -0
- package/src/plugins/builtin/jobs/pane.tsx +8 -3
- package/src/plugins/builtin/news/wire/news/detail-view.tsx +118 -10
- package/src/plugins/builtin/news/wire/news/story-evidence.ts +178 -0
- package/src/plugins/builtin/options/analytics.ts +1 -1
- package/src/plugins/builtin/options/view.tsx +18 -11
- package/src/plugins/builtin/options-positioning/model.ts +11 -0
- package/src/plugins/builtin/options-positioning/pane.tsx +22 -1
- package/src/plugins/builtin/options-scenario/client.ts +49 -8
- package/src/plugins/builtin/options-scenario/headless.ts +7 -3
- package/src/plugins/builtin/options-scenario/model.ts +33 -2
- package/src/plugins/builtin/options-scenario/pane.tsx +3 -4
- package/src/plugins/builtin/perps/cascade.ts +4 -3
- package/src/plugins/builtin/perps/markets-section.tsx +5 -2
- package/src/plugins/builtin/perps/model.ts +4 -3
- package/src/plugins/builtin/portfolio-list/table.tsx +3 -2
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +29 -14
- package/src/plugins/builtin/research/event-model.ts +12 -6
- package/src/plugins/builtin/research-search/index.tsx +3 -1
- package/src/plugins/builtin/scanner/denied.tsx +16 -4
- package/src/plugins/builtin/scanner/flow-pane.tsx +1 -1
- package/src/plugins/builtin/scanner/hilo-pane.tsx +1 -1
- package/src/plugins/builtin/sec/filing-display.tsx +14 -2
- package/src/plugins/builtin/sec/headless.ts +42 -4
- package/src/plugins/builtin/sec/index.tsx +21 -1
- package/src/plugins/builtin/sectors/sector-model.ts +1 -1
- package/src/plugins/builtin/shared/earnings-report.ts +32 -3
- package/src/plugins/builtin/shared/options-pro-copy.ts +34 -0
- package/src/plugins/builtin/shared/statement-currency.ts +23 -0
- package/src/plugins/builtin/shared/ticker-surface.ts +1 -1
- package/src/plugins/builtin/supply-chain/pane.tsx +4 -3
- package/src/plugins/builtin/themes/headless.ts +4 -4
- package/src/plugins/builtin/themes/model.ts +11 -8
- package/src/plugins/builtin/themes/pane.tsx +2 -2
- package/src/plugins/builtin/ticker-detail/financials/model.ts +22 -32
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +7 -9
- package/src/plugins/builtin/ticker-detail/headless-schema.ts +2 -0
- package/src/plugins/builtin/ticker-detail/headless.ts +28 -12
- package/src/plugins/builtin/ticker-detail/overview/board-lot.ts +21 -0
- package/src/plugins/builtin/ticker-detail/overview/model.ts +11 -1
- package/src/plugins/builtin/ticker-detail/overview/pane.tsx +4 -0
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +61 -13
- package/src/plugins/builtin/volatility/pane.tsx +3 -3
- package/src/plugins/builtin/world-venue-map/headless.ts +4 -2
- package/src/plugins/builtin/world-venue-map/model.ts +6 -1
- package/src/plugins/builtin/world-venue-map/venue-header.tsx +5 -3
- package/src/plugins/catalog-browser.ts +10 -1
- package/src/renderers/browser/activity.ts +16 -0
- package/src/renderers/browser/app-badge-host.ts +14 -0
- package/src/renderers/browser/main.tsx +5 -0
- package/src/renderers/browser/notifications.ts +103 -0
- package/src/renderers/browser/ui-host.tsx +4 -0
- package/src/renderers/dom/data-table/index.tsx +27 -4
- package/src/renderers/electrobun/view/http-fetch.ts +3 -2
- package/src/sources/gloomberb-cloud/index.ts +8 -6
- package/src/sources/gloomberb-cloud/news.ts +35 -0
- package/src/sources/provider-errors.ts +34 -7
- package/src/sources/provider-router/history.ts +32 -6
- package/src/time-series/base-series.ts +39 -6
- package/src/time-series/chart-seed.ts +2 -2
- package/src/time-series/history-quality.ts +4 -1
- package/src/time-series/hooks.ts +2 -0
- package/src/time-series/price-comparison.ts +17 -23
- package/src/time-series/reporting.ts +1 -1
- package/src/time-series/resolution.ts +13 -0
- package/src/time-series/resolve-context.ts +6 -0
- package/src/time-series/resolve.ts +39 -2
- package/src/time-series/types.ts +2 -1
- package/src/types/financials.ts +9 -1
- package/src/types/headless.ts +1 -0
- package/src/types/issuer-listings.ts +2 -0
- package/src/types/plugin-notifications.ts +3 -0
- package/src/types/price-history.ts +6 -4
- package/src/ui/host.tsx +2 -0
- package/src/utils/exchange-announcements.ts +7 -2
- package/src/utils/fundamentals.ts +40 -0
- package/src/utils/network-failure.ts +2 -0
- package/src/utils/price-history-integrity.ts +9 -1
|
@@ -15,6 +15,8 @@ import { localTimeSuffix } from "../../../utils/utc-time";
|
|
|
15
15
|
import { resolvePersistedCloudSessionToken } from "../../../cli/pane-functions/cloud-session";
|
|
16
16
|
import type { ConfigContext } from "../../../cli/types";
|
|
17
17
|
import { checkedWhenSignedIn, NEEDS_SIGN_IN, needsSignInNote } from "./event-rows";
|
|
18
|
+
import { checkedOnlyWithPro, checksProRules, NEEDS_PRO, needsProNote, savedWithoutProNote } from "./pro-rules";
|
|
19
|
+
import { OCC_CONTRACT, occContractExample, occFormText, parseLooseOptionContract, resolveLooseOptionContract, type LooseOptionContract } from "./option-contract";
|
|
18
20
|
import { CLI_COMMAND_GROUPS } from "../../../cli/help";
|
|
19
21
|
import { dryRunNote } from "../../../cli/helpers";
|
|
20
22
|
import { requireArg, takeOption } from "../../../cli/commands/command-utils";
|
|
@@ -57,7 +59,7 @@ import { MAX_EVENT_ALERTS, eventAlertTarget, toggleEventAlert, writeEventAlertSt
|
|
|
57
59
|
import { alertKindLabel, fetchAlertHistory, ruleStateText, type AlertRuleState } from "./history";
|
|
58
60
|
import { apiClient } from "../../../api-client";
|
|
59
61
|
import { IV_LEVEL_CHECKS_KEY, ivLevelCheckText, readIvLevelChecks, rearmIvLevelAlert, type IvLevelCheck } from "./iv-level";
|
|
60
|
-
import { isPenceLevel, parseAlertPrice, readAlertLevel } from "./price";
|
|
62
|
+
import { isDollarMark, isPenceLevel, parseAlertPrice, readAlertLevel } from "./price";
|
|
61
63
|
import { commodityFutureNote, farTargetMessage, levelInQuoteUnit } from "./quotes";
|
|
62
64
|
import { isPenceQuotedLine } from "../../../market-data/market/format";
|
|
63
65
|
import { MACRO_EVENT_NAMES, createResearchAlert, formatPremium, ivLevelUnitError, parseAmount, parseIvLevel } from "./research-builder";
|
|
@@ -127,8 +129,11 @@ export type AlertAddRequest =
|
|
|
127
129
|
| { kind: "flow"; symbol: string | null; premium: number; side: "any" | "calls" | "puts"; print: "any" | "sweep" | "block" }
|
|
128
130
|
/** The symbol's 30-day ATM IV (`atm`, in %) or 25-delta risk reversal (`rr`, in vol points) above or below a level, checked by the running app. */
|
|
129
131
|
| { kind: "iv_level"; symbol: string; metric: IvLevelMetric; direction: "above" | "below"; level: number }
|
|
130
|
-
/**
|
|
131
|
-
|
|
132
|
+
/**
|
|
133
|
+
* One OCC contract's IV rising by `points`. A contract typed loosely (`SPY 680C 11/19`) carries what it was
|
|
134
|
+
* read as (`loose`), for the chain to name the one listed contract it is before the rule is made.
|
|
135
|
+
*/
|
|
136
|
+
| { kind: "iv_spike"; contract: string; points: number; loose?: LooseOptionContract }
|
|
132
137
|
/** The rest of what Add Event Alert offers: 52-week range, unusual volume, filings, insiders, short interest and more. */
|
|
133
138
|
| RuleAddRequest;
|
|
134
139
|
|
|
@@ -274,6 +279,8 @@ export function parseAlertAddArgs(
|
|
|
274
279
|
if (country !== undefined) throw new Error(COUNTRY_RULE);
|
|
275
280
|
if (days !== undefined) throw new Error("--days is for earnings and calendar event alerts, not price alerts.");
|
|
276
281
|
if (third === undefined) throw new Error(ADD_USAGE);
|
|
282
|
+
// A dollar mark the shell split from its price (`$ 757.75`, `757.75 USD`) is part of it.
|
|
283
|
+
if (rest.length === 1 && (isDollarMark(third) || isDollarMark(rest[0]!))) return parseAlertAddArgs([first, second, `${third} ${rest[0]}`], days, exchange, country, benchmark, watchlist);
|
|
277
284
|
const retype = (price: number) => retypeCommand(first, condition, price, exchange);
|
|
278
285
|
// `81 000` without quotes arrives as 81 and a stray 000; neither reading is taken for granted.
|
|
279
286
|
const spaced = rest.length > 0 && LEADING_GROUP.test(third) ? parsePastedNumber([third, ...rest].join(" ")) : null;
|
|
@@ -290,9 +297,17 @@ export function parseAlertAddArgs(
|
|
|
290
297
|
...(thousandsDot ? { thousandsDot: { ...thousandsDot, text: third.trim() } } : {}) };
|
|
291
298
|
}
|
|
292
299
|
|
|
293
|
-
const OCC_CONTRACT = /^(?:O:)?[A-Z.]{1,6}\d{6}[CP]\d{8}$/i;
|
|
294
300
|
const LEVEL_DIRECTIONS = ["above", "below"] as const;
|
|
295
301
|
|
|
302
|
+
/** An IV spike's rise in vol points, with the unit or without it (`5`, `5 pts`), refused with its range when it does not read. */
|
|
303
|
+
function readSpikePoints(typed: string, contract: string): number {
|
|
304
|
+
const value = typed && !/%/.test(typed) ? parseIvLevel(typed) : Number.NaN;
|
|
305
|
+
if (!Number.isFinite(value) || value < 0.1 || value > 100) {
|
|
306
|
+
throw new Error(`An IV spike is a rise of 0.1 to 100 vol points: gloom alerts add ${/\s/.test(contract) ? `"${contract}"` : contract} iv spike 5.`);
|
|
307
|
+
}
|
|
308
|
+
return value;
|
|
309
|
+
}
|
|
310
|
+
|
|
296
311
|
/** A level typed for an IV level rule, with its unit or without (`50`, `50%`, `-5.5 pts`), refused with its unit and range when it does not read. */
|
|
297
312
|
function readLevel(metric: IvLevelMetric, typed: string | undefined, symbol: string): number {
|
|
298
313
|
const word = metric === "atm" ? "iv" : "rr";
|
|
@@ -321,6 +336,21 @@ function parseResearchAddArgs(args: readonly string[]): ResearchAddRequest | nul
|
|
|
321
336
|
const word = (value: string | undefined) => value?.toLowerCase() ?? "";
|
|
322
337
|
const isCondition = (value: string | undefined) => (CONDITIONS as readonly string[]).includes(word(value)) || word(value) === "earnings";
|
|
323
338
|
const lead = word(first);
|
|
339
|
+
// `<contract> iv spike <points>`, the contract typed as OCC writes it or loosely, over one word or several
|
|
340
|
+
// (`SPY 680C 11/19`, `SPY241119C680`), read against the listed chain once the command runs.
|
|
341
|
+
const spikeAt = args.findIndex((arg, index) => index > 0 && word(arg) === "iv" && word(args[index + 1]) === "spike");
|
|
342
|
+
if (spikeAt > 0 && !(spikeAt === 1 && OCC_CONTRACT.test(first.trim()))) {
|
|
343
|
+
const typed = args.slice(0, spikeAt).join(" ").trim();
|
|
344
|
+
const points = readSpikePoints(args.slice(spikeAt + 2).join(" "), typed);
|
|
345
|
+
if (OCC_CONTRACT.test(typed.replace(/\s+/g, ""))) return { kind: "iv_spike", contract: typed.replace(/\s+/g, "").toUpperCase(), points };
|
|
346
|
+
const loose = parseLooseOptionContract(typed);
|
|
347
|
+
if (!loose) {
|
|
348
|
+
// A ticker alone has an IV level to follow, not one contract's spike.
|
|
349
|
+
const level = /^[A-Z.^=:-]+$/i.test(typed) ? ` For ${typed.toUpperCase()}'s 30-day ATM IV, add a level: gloom alerts add ${typed.toUpperCase()} iv above 50.` : "";
|
|
350
|
+
throw new Error(`"${typed}" is not an option contract. ${occFormText(occContractExample())}: gloom alerts add ${occContractExample()} iv spike 5.${level}`);
|
|
351
|
+
}
|
|
352
|
+
return { kind: "iv_spike", contract: typed, points, loose };
|
|
353
|
+
}
|
|
324
354
|
const [symbol, kind, tail] = (lead === "news" || lead === "flow") && !isCondition(second)
|
|
325
355
|
? [null, lead, args.slice(1)] as const
|
|
326
356
|
: [first, word(second), args.slice(2)] as const;
|
|
@@ -350,13 +380,7 @@ function parseResearchAddArgs(args: readonly string[]): ResearchAddRequest | nul
|
|
|
350
380
|
if (kind !== "iv" || word(third) !== "spike") {
|
|
351
381
|
throw new Error(`An option contract takes an IV spike in vol points: gloom alerts add ${symbol.toUpperCase()} iv spike 5. For a level, name the underlying: alerts add ${symbol.replace(/^O:/i, "").match(/^[A-Z.]+/i)![0]!.toUpperCase()} iv above 50.`);
|
|
352
382
|
}
|
|
353
|
-
|
|
354
|
-
const typed = rest.join(" ");
|
|
355
|
-
const value = typed && !/%/.test(typed) ? parseIvLevel(typed) : Number.NaN;
|
|
356
|
-
if (!Number.isFinite(value) || value < 0.1 || value > 100) {
|
|
357
|
-
throw new Error(`An IV spike is a rise of 0.1 to 100 vol points: gloom alerts add ${symbol.toUpperCase()} iv spike 5.`);
|
|
358
|
-
}
|
|
359
|
-
return { kind: "iv_spike", contract: symbol.toUpperCase(), points: value };
|
|
383
|
+
return { kind: "iv_spike", contract: symbol.toUpperCase(), points: readSpikePoints(rest.join(" "), symbol.toUpperCase()) };
|
|
360
384
|
}
|
|
361
385
|
const metric: IvLevelMetric = kind === "iv" ? "atm" : "rr";
|
|
362
386
|
const direction = word(third);
|
|
@@ -551,12 +575,16 @@ function priceRow(alert: AlertRule): AlertListRow {
|
|
|
551
575
|
|
|
552
576
|
function eventRow(
|
|
553
577
|
rule: EventAlertRule, now: number, eventDate: string | null | undefined, check?: IvLevelCheck, cloud?: CloudRuleStates, signedIn = true,
|
|
578
|
+
pro = signedIn,
|
|
554
579
|
): AlertListRow {
|
|
555
580
|
const scheduled = readScheduledRule(rule);
|
|
556
581
|
if (!scheduled) {
|
|
557
582
|
const triggered = rule.status === "active" && rule.triggeredAt ? "triggered" : rule.status;
|
|
558
|
-
//
|
|
559
|
-
|
|
583
|
+
// Without Pro, nothing checks options flow or an IV spike, signed in or not: it waits on Pro. Signed out,
|
|
584
|
+
// nothing checks any other rule only a signed-in account gets checked: it waits on a sign-in, not on its event.
|
|
585
|
+
const status = triggered !== "active" ? triggered
|
|
586
|
+
: !pro && checkedOnlyWithPro(rule) ? NEEDS_PRO
|
|
587
|
+
: !signedIn && checkedWhenSignedIn(rule) ? NEEDS_SIGN_IN : triggered;
|
|
560
588
|
// An IV level is read by this app, so its last reading is this device's; Gloom Cloud reads the rest.
|
|
561
589
|
const state = cloud?.states.get(rule.id);
|
|
562
590
|
const reading = rule.kind === "iv_level" ? {
|
|
@@ -1044,6 +1072,17 @@ export const alertsCliCommand: CliCommandDef = {
|
|
|
1044
1072
|
let read = [...priced?.notes ?? [], ...coinNote ? [coinNote] : [], ...futureNote ? [futureNote] : [], ...seriesNote ? [seriesNote] : [], ...benchmarkNotes, ...penceNote ? [penceNote] : []];
|
|
1045
1073
|
let newEventRule: EventAlertRule | null = null;
|
|
1046
1074
|
let newResearchRule: EventAlertRule | null = null;
|
|
1075
|
+
// A contract typed loosely is the one listed contract it names, read from the chain; one past its expiry is
|
|
1076
|
+
// kept as typed, for the rule to refuse it as expired.
|
|
1077
|
+
if (research?.kind === "iv_spike" && research.loose) {
|
|
1078
|
+
const { loose, contract: typedContract } = research;
|
|
1079
|
+
const resolved = await withMarketData(ctx, (market) => resolveLooseOptionContract(typedContract, loose, (expiration) => {
|
|
1080
|
+
if (!market.dataProvider.getOptionsChain) throw new Error(`Option chains cannot be read here to find ${typedContract}.`);
|
|
1081
|
+
return market.dataProvider.getOptionsChain(loose.root, "", expiration);
|
|
1082
|
+
}, now)).catch(failWith);
|
|
1083
|
+
research.contract = resolved.contract;
|
|
1084
|
+
if (resolved.readAs) read = [...read, resolved.readAs];
|
|
1085
|
+
}
|
|
1047
1086
|
if (research) {
|
|
1048
1087
|
const typed = priceListing?.exchange ? canonicalExchange(priceListing.exchange) : "";
|
|
1049
1088
|
const { kind, values } = researchFormValues(
|
|
@@ -1164,11 +1203,15 @@ export const alertsCliCommand: CliCommandDef = {
|
|
|
1164
1203
|
const [{ dates, warnings }, cloud] = await Promise.all([listEventDates(events.rules, now, lookup), cloudRuleStates(events.rules, session)]);
|
|
1165
1204
|
const rows = [
|
|
1166
1205
|
...alerts.map(priceRow),
|
|
1167
|
-
...events.rules.map((rule) => eventRow(rule, now, dates.has(rule.id) ? dates.get(rule.id) : rule.eventDate, checks[rule.id], cloud, !!session
|
|
1206
|
+
...events.rules.map((rule) => eventRow(rule, now, dates.has(rule.id) ? dates.get(rule.id) : rule.eventDate, checks[rule.id], cloud, !!session,
|
|
1207
|
+
checksProRules(!!session, apiClient.getCurrentUser()))),
|
|
1168
1208
|
];
|
|
1169
1209
|
const waiting = rows.filter((row) => row.status === NEEDS_SIGN_IN).length;
|
|
1210
|
+
// The Pro note `alerts add` prints, once for the list: options flow and IV spikes are checked only with Pro.
|
|
1211
|
+
const proRules = events.rules.filter(checkedOnlyWithPro);
|
|
1170
1212
|
const allWarnings = [...(alertsError ? [alertsError] : []), ...(events.error ? [events.error] : []), ...warnings, ...cloud.warning ? [cloud.warning] : [],
|
|
1171
|
-
...waiting ? [needsSignInNote(waiting)] : []
|
|
1213
|
+
...waiting ? [needsSignInNote(waiting)] : [],
|
|
1214
|
+
...proRules.length ? [needsProNote(proRules, rows.filter((row) => row.status === NEEDS_PRO).length)] : []];
|
|
1172
1215
|
ctx.printResult({ data: rows, ...(allWarnings.length ? { warnings: allWarnings } : {}) }, {
|
|
1173
1216
|
rows: (data) => data.map(textRow),
|
|
1174
1217
|
textColumns: [
|
|
@@ -1342,11 +1385,15 @@ export const alertsCliCommand: CliCommandDef = {
|
|
|
1342
1385
|
record("created", rule);
|
|
1343
1386
|
const delivery = research ? researchDelivery(research.kind) : ruleDelivery(formRule!.event);
|
|
1344
1387
|
// Saved signed out, it waits on a sign-in, and `alerts list` and ALRT say so until there is one.
|
|
1345
|
-
|
|
1346
|
-
const
|
|
1388
|
+
// Options flow and an IV spike wait on Pro, which a free sign-in does not bring.
|
|
1389
|
+
const session = savedSession(config);
|
|
1390
|
+
const needsPro = checkedOnlyWithPro(rule) && !checksProRules(!!session, apiClient.getCurrentUser());
|
|
1391
|
+
const needsSignIn = !needsPro && checkedWhenSignedIn(rule) && !session;
|
|
1392
|
+
const signIn = needsPro ? savedWithoutProNote(rule) : needsSignIn
|
|
1347
1393
|
? " It needs sign-in: nothing checks it while you are signed out. Open the app (gloom) and log in or sign up free from the command bar (Ctrl+P, Log In or Sign Up)."
|
|
1348
1394
|
: "";
|
|
1349
|
-
ctx.printResult({ data: { changed: !ctx.cliOptions.dryRun, dryRun: ctx.cliOptions.dryRun, alert: rule,
|
|
1395
|
+
ctx.printResult({ data: { changed: !ctx.cliOptions.dryRun, dryRun: ctx.cliOptions.dryRun, alert: rule,
|
|
1396
|
+
...needsPro ? { status: NEEDS_PRO } : needsSignIn ? { status: NEEDS_SIGN_IN } : {} },
|
|
1350
1397
|
...(read.length > 0 ? { warnings: read } : {}) }, {
|
|
1351
1398
|
text: (data) => `Added alert ${data.alert.id}: ${alertKindLabel(rule.kind)} ${eventAlertTarget(rule)} (${delivery}).${signIn}${dryRunNote(data.dryRun)}`,
|
|
1352
1399
|
});
|
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
import { metricFormInput, metricShortcut, parseMetricAlert } from "./metric-command";
|
|
2
2
|
import { isRelativeMetric, type AlertMetric } from "./metric-model";
|
|
3
3
|
import type { AlertCondition } from "./types";
|
|
4
|
-
import { isPenceLevel, readAlertLevel, readAlertPrice } from "./price";
|
|
4
|
+
import { isPenceLevel, parseAlertPrice, readAlertLevel, readAlertPrice } from "./price";
|
|
5
5
|
import { normalizeAlertSymbol } from "./quotes";
|
|
6
6
|
import { moveCondition, parseMovePercent } from "./move";
|
|
7
|
+
import type { WizardStep } from "../../../types/plugin";
|
|
8
|
+
|
|
9
|
+
/** Add Alert's kind for a move from the previous close, beside a price level. */
|
|
10
|
+
export const MOVE_KIND_CHOICE = { value: "move", label: "Move from previous close" };
|
|
11
|
+
|
|
12
|
+
/** The move kind's fields: which way, and how far in percent, as `alerts add QQQ moves 5%` names them. */
|
|
13
|
+
export const moveWizardFields: WizardStep[] = [
|
|
14
|
+
{ key: "move:condition", label: "Direction", type: "select", defaultValue: "crosses", dependsOn: { key: "kind", value: "move" },
|
|
15
|
+
options: [{ label: "Either way", value: "crosses" }, { label: "Up", value: "above" }, { label: "Down", value: "below" }] },
|
|
16
|
+
{ key: "move:percent", label: "Move (%)", type: "number", placeholder: "3", dependsOn: { key: "kind", value: "move" } },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const MOVE_PERCENT_RULE = "A move is a percent from the previous close, above 0 and up to 100";
|
|
7
20
|
|
|
8
21
|
export interface AlertCommandInput {
|
|
9
22
|
symbol: string;
|
|
10
23
|
condition: AlertCondition;
|
|
24
|
+
/** The level, or for a move (`move`) the percent from the previous close. */
|
|
11
25
|
price: number;
|
|
26
|
+
/** A move from the previous close (`QQQ moves 5%`): `condition` is either way (crosses), up (above) or down (below). */
|
|
27
|
+
move?: true;
|
|
12
28
|
/** Typed in pence (`70p`): `price` is in pounds, for a London line quoted in pence. */
|
|
13
29
|
pence?: true;
|
|
14
30
|
metric?: AlertMetric;
|
|
@@ -47,7 +63,9 @@ export function parseAlertShortcutValues(
|
|
|
47
63
|
const activeTicker = normalizeAlertSymbol(context?.activeTicker);
|
|
48
64
|
return activeTicker ? { symbol: activeTicker } : {};
|
|
49
65
|
}
|
|
50
|
-
|
|
66
|
+
// The price is the rest of the line, as one: `$ 757.75`, `1 000.50` and `757.75 USD` read as `alerts add` reads them quoted.
|
|
67
|
+
const priceText = parts.slice(2).join(" ");
|
|
68
|
+
if (parts.length > 3 && !isPenceLevel(priceText) && parseAlertPrice(priceText).kind === "invalid") {
|
|
51
69
|
throw new Error("Use SA SYMBOL above|below|crosses PRICE.");
|
|
52
70
|
}
|
|
53
71
|
|
|
@@ -57,9 +75,12 @@ export function parseAlertShortcutValues(
|
|
|
57
75
|
|
|
58
76
|
if (parts[1]) {
|
|
59
77
|
const condition = parseAlertCondition(parts[1]);
|
|
60
|
-
// A move from the previous close
|
|
61
|
-
|
|
62
|
-
|
|
78
|
+
// A move from the previous close, as `alerts add` takes it: `QQQ moves 5%`, `QQQ up 3`, `QQQ down 2%`.
|
|
79
|
+
const move = condition ? null : moveCondition(parts[1]);
|
|
80
|
+
if (move) {
|
|
81
|
+
const typed = parts.slice(2).join(" ");
|
|
82
|
+
if (typed && parseMovePercent(typed) == null) throw new Error(`${MOVE_PERCENT_RULE}, not "${typed}".`);
|
|
83
|
+
return { ...values, kind: "move", "move:condition": move, ...typed ? { "move:percent": String(parseMovePercent(typed)) } : {} };
|
|
63
84
|
}
|
|
64
85
|
if (!condition) {
|
|
65
86
|
throw new Error("Use above, below, crosses, >, <, or x.");
|
|
@@ -67,9 +88,9 @@ export function parseAlertShortcutValues(
|
|
|
67
88
|
values.condition = condition;
|
|
68
89
|
}
|
|
69
90
|
|
|
70
|
-
// The price reads as `alerts add` reads it: 81k is 81000, 81,000 asks which was meant, and text that is no
|
|
71
|
-
// `70p`, pence on a London line, stays as typed for the add to hold to its line.
|
|
72
|
-
if (
|
|
91
|
+
// The price reads as `alerts add` reads it: 81k is 81000, 81,000 asks which was meant ($81,000 does not), and text that is no
|
|
92
|
+
// number says what to type. `70p`, pence on a London line, stays as typed for the add to hold to its line.
|
|
93
|
+
if (priceText) values.price = isPenceLevel(priceText) ? (readAlertLevel(priceText), priceText.trim()) : String(readAlertPrice(priceText));
|
|
73
94
|
|
|
74
95
|
return values;
|
|
75
96
|
}
|
|
@@ -86,13 +107,22 @@ export function parseAlertCommandValues(
|
|
|
86
107
|
};
|
|
87
108
|
}
|
|
88
109
|
|
|
110
|
+
if (values?.kind === "move") {
|
|
111
|
+
const symbol = values.symbol?.trim().toUpperCase();
|
|
112
|
+
const condition = parseAlertCondition(values["move:condition"]) ?? "crosses";
|
|
113
|
+
const typed = values["move:percent"]?.trim();
|
|
114
|
+
if (!symbol || !typed) return null;
|
|
115
|
+
const percent = parseMovePercent(typed);
|
|
116
|
+
if (percent == null) throw new Error(`${MOVE_PERCENT_RULE}, not "${typed}".`);
|
|
117
|
+
return { symbol, condition, price: percent, move: true };
|
|
118
|
+
}
|
|
89
119
|
const metric = values ? metricFormInput(values) : null;
|
|
90
120
|
if (metric) return metric;
|
|
91
121
|
const symbol = values?.symbol?.trim().toUpperCase();
|
|
92
122
|
const condition = parseAlertCondition(values?.condition);
|
|
93
123
|
const priceStr = values?.price?.trim();
|
|
94
124
|
if (!symbol || !condition || !priceStr) return null;
|
|
95
|
-
return { symbol, condition, ...readAlertLevel(priceStr
|
|
125
|
+
return { symbol, condition, ...readAlertLevel(priceStr) };
|
|
96
126
|
}
|
|
97
127
|
|
|
98
128
|
/** A move rule's edit read: `GBPUSD=X moves 0.5%`, `HSBA:LSE down 3`, as `alerts add` takes it. Null for another form. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { eventAlertTarget, releaseTimeOn, type EventAlertRule } from "./events";
|
|
2
2
|
import { timeZoneCity, zonedClock } from "../../../utils/utc-time";
|
|
3
3
|
import { readScheduledRule, scheduledAlertStatus, scheduledToday } from "./scheduled";
|
|
4
|
+
import { checkedOnlyWithPro } from "./pro-rules";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Earnings, macro and calendar event rules name the event day they wait for,
|
|
@@ -40,16 +41,21 @@ export function needsSignInNote(count: number): string {
|
|
|
40
41
|
+ "Open the app (gloom) and log in or sign up free from the command bar (Ctrl+P, Log In or Sign Up).";
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
/** The words a rule's state is written in on the Events tab. */
|
|
45
|
+
export type RuleState = "Active" | "Paused" | "Alerted" | "Needs sign-in" | "Needs Pro";
|
|
46
|
+
|
|
43
47
|
/**
|
|
44
48
|
* The state word the Events tab shows: a scheduled rule is Alerted once it has gone off for its coming
|
|
45
|
-
* event, an IV level once its level was reached, until it is re-armed.
|
|
46
|
-
*
|
|
49
|
+
* event, an IV level once its level was reached, until it is re-armed. A waiting Pro rule (options flow, an
|
|
50
|
+
* IV spike) needs Pro without an account that has it (`pro`), signed out too: a free sign-in would not
|
|
51
|
+
* arm it. Signed out, any other waiting rule only a signed-in account gets checked needs sign-in.
|
|
47
52
|
*/
|
|
48
|
-
export function ruleState(rule: EventAlertRule, now: number = Date.now(), signedIn = true
|
|
53
|
+
export function ruleState(rule: EventAlertRule, now: number = Date.now(), signedIn = true, pro = signedIn): RuleState {
|
|
49
54
|
const scheduled = readScheduledRule(rule);
|
|
50
55
|
const status = scheduled ? scheduledAlertStatus(rule, scheduled.leadDays, scheduledToday(scheduled.target, now), scheduled.trigger)
|
|
51
56
|
: rule.status === "active" && rule.kind === "iv_level" && rule.triggeredAt ? "triggered" : rule.status;
|
|
52
57
|
if (status === "paused") return "Paused";
|
|
53
58
|
if (status === "triggered") return "Alerted";
|
|
59
|
+
if (!pro && checkedOnlyWithPro(rule)) return "Needs Pro";
|
|
54
60
|
return !signedIn && checkedWhenSignedIn(rule) ? "Needs sign-in" : "Active";
|
|
55
61
|
}
|
|
@@ -26,7 +26,8 @@ import {
|
|
|
26
26
|
updateEventAlerts,
|
|
27
27
|
type EventAlertRule,
|
|
28
28
|
} from "./events";
|
|
29
|
-
import { ruleState, ruleTarget } from "./event-rows";
|
|
29
|
+
import { ruleState, ruleTarget, type RuleState } from "./event-rows";
|
|
30
|
+
import { checksProRules, proRuleStatus } from "./pro-rules";
|
|
30
31
|
import { relativeTime } from "./format";
|
|
31
32
|
import { alertKindLabel, fetchAlertHistory, ruleStateText } from "./history";
|
|
32
33
|
import { isResearchAlertKind } from "./research-rules";
|
|
@@ -42,14 +43,14 @@ import { alertTarget, alertViewHints, eventRuleSubject, useOpenAlertTarget } fro
|
|
|
42
43
|
import { FIRED_LOG_KEY } from "./fired-log";
|
|
43
44
|
import { withAlertChange } from "./alert-log";
|
|
44
45
|
|
|
45
|
-
const columnsFor = (width: number, lastCheck: boolean,
|
|
46
|
+
const columnsFor = (width: number, lastCheck: boolean, waiting: RuleState | null): DataTableColumn[] => [
|
|
46
47
|
{ id: "kind", label: "Event", width: 15, align: "left" },
|
|
47
48
|
{ id: "target", label: "Following", width: 28, flexGrow: 1, align: "left" },
|
|
48
49
|
...(lastCheck && width >= 96
|
|
49
50
|
? [{ id: "last", label: "Last check", width: 34, align: "left" as const }]
|
|
50
51
|
: []),
|
|
51
|
-
// Wide enough to say "Needs sign-in" only when a row does.
|
|
52
|
-
{ id: "status", label: "State", width:
|
|
52
|
+
// Wide enough to say "Needs sign-in" or "Needs Pro" only when a row does.
|
|
53
|
+
{ id: "status", label: "State", width: Math.max(8, waiting?.length ?? 0), align: "left" },
|
|
53
54
|
{ id: "created", label: "Since", width: 10, align: "left" },
|
|
54
55
|
];
|
|
55
56
|
|
|
@@ -108,7 +109,10 @@ export function EventAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
108
109
|
const access = usePlanAccess();
|
|
109
110
|
// A saved session counts before its account has loaded, so a signed-in start does not flash "Needs sign-in".
|
|
110
111
|
const signedIn = access.signedIn || !!apiClient.getSessionToken();
|
|
111
|
-
|
|
112
|
+
// Options flow and an IV spike are checked only with Pro: a free account, signed in or not, waits on Pro.
|
|
113
|
+
const pro = checksProRules(signedIn, apiClient.getCurrentUser());
|
|
114
|
+
const shownStates = new Set(rules.map((rule) => ruleState(rule, now, signedIn, pro)));
|
|
115
|
+
const waiting: RuleState | null = shownStates.has("Needs sign-in") ? "Needs sign-in" : shownStates.has("Needs Pro") ? "Needs Pro" : null;
|
|
112
116
|
const openTarget = useOpenAlertTarget();
|
|
113
117
|
const selectedTarget = useMemo(() => selectedRule ? alertTarget(eventRuleSubject(selectedRule)) : null, [selectedRule]);
|
|
114
118
|
const session = useResearchCloudSession();
|
|
@@ -120,7 +124,7 @@ export function EventAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
120
124
|
[history.data],
|
|
121
125
|
);
|
|
122
126
|
// An IV level is read by this app, so its last reading needs no session.
|
|
123
|
-
const columns = columnsFor(width, (hasResearch && !!history.data) || rules.some((rule) => rule.kind === "iv_level"),
|
|
127
|
+
const columns = columnsFor(width, (hasResearch && !!history.data) || rules.some((rule) => rule.kind === "iv_level"), waiting);
|
|
124
128
|
const add = useCallback(
|
|
125
129
|
() => openPluginCommandWorkflow("set-event-alert"),
|
|
126
130
|
[openPluginCommandWorkflow],
|
|
@@ -167,6 +171,8 @@ export function EventAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
167
171
|
const status =
|
|
168
172
|
error ??
|
|
169
173
|
(selectedRule?.kind === "catalyst" ? catalystStatus : null) ??
|
|
174
|
+
// A Pro rule nothing checks says so while it is selected, and what is free beside it.
|
|
175
|
+
(selectedRule && ruleState(selectedRule, now, signedIn, pro) === "Needs Pro" ? proRuleStatus(selectedRule) : null) ??
|
|
170
176
|
sync.error ??
|
|
171
177
|
(sync.phase === "disabled"
|
|
172
178
|
? "Cloud sync disabled"
|
|
@@ -227,9 +233,9 @@ export function EventAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
227
233
|
// An IV level that could not be read says so on its own row: No data in State, the reason in Last check.
|
|
228
234
|
const check = rule.kind === "iv_level" ? checks[rule.id] : undefined;
|
|
229
235
|
const unread = rule.kind === "iv_level" && rule.status === "active" && !rule.triggeredAt && check?.value === null;
|
|
230
|
-
const state = ruleState(rule, now, signedIn);
|
|
231
|
-
// A rule nothing checks while signed out says so in its State, in the warning tone.
|
|
232
|
-
const
|
|
236
|
+
const state = ruleState(rule, now, signedIn, pro);
|
|
237
|
+
// A rule nothing checks while signed out, or without Pro, says so in its State, in the warning tone.
|
|
238
|
+
const waits = (state === "Needs sign-in" || state === "Needs Pro") && column.id === "status";
|
|
233
239
|
return {
|
|
234
240
|
text:
|
|
235
241
|
column.id === "kind"
|
|
@@ -249,7 +255,7 @@ export function EventAlertsPane({ focused, width, height }: PaneProps) {
|
|
|
249
255
|
? colors.selectedText
|
|
250
256
|
: unread && (column.id === "status" || column.id === "last")
|
|
251
257
|
? colors.negative
|
|
252
|
-
:
|
|
258
|
+
: waits
|
|
253
259
|
? colors.warning
|
|
254
260
|
: rule.status === "paused"
|
|
255
261
|
? colors.textMuted
|
|
@@ -13,6 +13,7 @@ import type { PaneLock } from "../../../types/plugin";
|
|
|
13
13
|
import { refusedLock } from "../shared/cloud-denied";
|
|
14
14
|
import { ALERT_TABS, ALERTS_PLUGIN_ID } from "./constants";
|
|
15
15
|
import { eventWhen, needsSignInNote, ruleState } from "./event-rows";
|
|
16
|
+
import { checkedOnlyWithPro, checksProRules, needsProNote } from "./pro-rules";
|
|
16
17
|
import { readerTimeZone } from "../../../utils/utc-time";
|
|
17
18
|
import { eventAlertTarget, type EventAlertRule } from "./events";
|
|
18
19
|
import {
|
|
@@ -149,7 +150,7 @@ function pricesResult(alerts: readonly AlertRule[], error: string | null, events
|
|
|
149
150
|
}
|
|
150
151
|
|
|
151
152
|
/** An event alert as the Events table lists it: a scheduled one with its event date and lead time apart. */
|
|
152
|
-
function eventRow(rule: EventAlertRule, now: number, checks: Record<string, IvLevelCheck>, signedIn: boolean, readerZone: string | null = null): HeadlessPaneRow {
|
|
153
|
+
function eventRow(rule: EventAlertRule, now: number, checks: Record<string, IvLevelCheck>, signedIn: boolean, pro: boolean, readerZone: string | null = null): HeadlessPaneRow {
|
|
153
154
|
const scheduled = readScheduledRule(rule);
|
|
154
155
|
return {
|
|
155
156
|
id: rule.id,
|
|
@@ -160,7 +161,7 @@ function eventRow(rule: EventAlertRule, now: number, checks: Record<string, IvLe
|
|
|
160
161
|
eventDate: scheduled && rule.eventDate ? eventWhen(rule, readerZone) : null,
|
|
161
162
|
leadDays: scheduled?.leadDays ?? null,
|
|
162
163
|
...(scheduled?.trigger === "results" ? { when: "results" } : {}),
|
|
163
|
-
state: ruleState(rule, now, signedIn),
|
|
164
|
+
state: ruleState(rule, now, signedIn, pro),
|
|
164
165
|
since: new Date(rule.createdAt).toISOString().slice(0, 10),
|
|
165
166
|
// An IV level's last reading, or why there was none, on its own row.
|
|
166
167
|
...rule.kind === "iv_level" ? { lastCheck: ivLevelCheckText(rule, checks[rule.id]) } : {},
|
|
@@ -168,20 +169,25 @@ function eventRow(rule: EventAlertRule, now: number, checks: Record<string, IvLe
|
|
|
168
169
|
}
|
|
169
170
|
|
|
170
171
|
function eventsResult(
|
|
171
|
-
rules: readonly EventAlertRule[], error: string | null, checks: Record<string, IvLevelCheck>, signedIn: boolean,
|
|
172
|
+
rules: readonly EventAlertRule[], error: string | null, checks: Record<string, IvLevelCheck>, signedIn: boolean, pro: boolean,
|
|
173
|
+
readerZone: string | null = null,
|
|
172
174
|
): HeadlessRowsResult {
|
|
173
175
|
const now = Date.now();
|
|
174
176
|
const checked = rules.some((rule) => rule.kind === "iv_level");
|
|
175
|
-
const rows = [...rules].sort((a, b) => b.createdAt - a.createdAt).map((rule) => eventRow(rule, now, checks, signedIn, readerZone));
|
|
177
|
+
const rows = [...rules].sort((a, b) => b.createdAt - a.createdAt).map((rule) => eventRow(rule, now, checks, signedIn, pro, readerZone));
|
|
176
178
|
// Signed out, the rules only a signed-in account gets checked say so on their rows, and once what to do.
|
|
177
179
|
const waiting = rows.filter((row) => row.state === "Needs sign-in").length;
|
|
180
|
+
// Options flow and IV spikes are checked only with Pro, which their rows say without it; the list says it once either way.
|
|
181
|
+
const proRules = rules.filter(checkedOnlyWithPro);
|
|
182
|
+
const notes = [...waiting ? [needsSignInNote(waiting)] : [],
|
|
183
|
+
...proRules.length ? [needsProNote(proRules, rows.filter((row) => row.state === "Needs Pro").length)] : []];
|
|
178
184
|
return {
|
|
179
185
|
// A Last check column only when an IV level rule has a reading to show.
|
|
180
186
|
columns: checked ? [...EVENT_COLUMNS.slice(0, -2), { key: "lastCheck", header: "Last check" }, ...EVENT_COLUMNS.slice(-2)] : EVENT_COLUMNS,
|
|
181
187
|
rows,
|
|
182
188
|
empty: "No event alerts. Add one with gloom alerts add CRWV earnings --days 3, gloom alerts add CPI --days 1 or gloom alerts add CN PMI.",
|
|
183
189
|
...(error ? { errors: [error], complete: false } : {}),
|
|
184
|
-
...(
|
|
190
|
+
...(notes.length ? { notes } : {}),
|
|
185
191
|
};
|
|
186
192
|
}
|
|
187
193
|
|
|
@@ -276,7 +282,7 @@ export const alertsHeadless: HeadlessPaneDefinition<"rows"> = {
|
|
|
276
282
|
const { alerts, alertsError, events } = readAlertStores(ctx.config);
|
|
277
283
|
return tab === "events"
|
|
278
284
|
? eventsResult(events.rules, events.error, readIvLevelChecks(ctx.readDeviceState?.(ALERTS_PLUGIN_ID, IV_LEVEL_CHECKS_KEY)), !!ctx.apiClient.getSessionToken?.(),
|
|
279
|
-
readerTimeZone(ctx.config.timezone))
|
|
285
|
+
checksProRules(!!ctx.apiClient.getSessionToken?.(), ctx.apiClient.getCurrentUser?.()), readerTimeZone(ctx.config.timezone))
|
|
280
286
|
// A move rule with this device's last reading of it, and whether it went off this session.
|
|
281
287
|
: pricesResult(withMoveChecks(alerts, readMoveChecks(ctx.readDeviceState?.(ALERTS_PLUGIN_ID, MOVE_CHECKS_KEY))), alertsError, events.rules.length);
|
|
282
288
|
},
|
|
@@ -9,6 +9,9 @@ import { alertChangeEntry, createFiredAlertRecorder, firedAlertTime, quoteSource
|
|
|
9
9
|
import { checkIvLevelAlertsNow, startIvLevelAlerts } from "./iv-level";
|
|
10
10
|
import { logFailure } from "../../../utils/log-failure";
|
|
11
11
|
import { RESEARCH_FORM_KINDS, RESEARCH_LABELS, researchWizardFields, createResearchAlert } from "./research-builder";
|
|
12
|
+
import { checkedOnlyWithPro, checksProRules, savedWithoutProNote } from "./pro-rules";
|
|
13
|
+
import { OCC_CONTRACT, parseLooseOptionContract, resolveLooseOptionContract } from "./option-contract";
|
|
14
|
+
import { apiClient } from "../../../api-client";
|
|
12
15
|
import { newYorkToday } from "../earnings/board-model";
|
|
13
16
|
import { checkScheduledEventAlertsNow, startScheduledEventAlerts } from "./scheduled-check";
|
|
14
17
|
import { scheduledEventSources } from "./scheduled-sources";
|
|
@@ -37,6 +40,8 @@ import {
|
|
|
37
40
|
sameLevelRule,
|
|
38
41
|
} from "./alert-engine";
|
|
39
42
|
import {
|
|
43
|
+
MOVE_KIND_CHOICE,
|
|
44
|
+
moveWizardFields,
|
|
40
45
|
parseAlertCommandValues,
|
|
41
46
|
parseAlertShortcutValues,
|
|
42
47
|
} from "./command";
|
|
@@ -63,7 +68,8 @@ import {
|
|
|
63
68
|
import { createAlertQuoteStream, readStreamedAlertQuote, type AlertQuoteStream } from "./live";
|
|
64
69
|
import { alertPriceText } from "./price-text";
|
|
65
70
|
import { isPenceQuotedLine } from "../../../market-data/market/format";
|
|
66
|
-
import { judgeMove, moveBasisText, moveFiredText } from "./move";
|
|
71
|
+
import { judgeMove, moveBasisText, moveFiredText, MOVE_DELIVERY } from "./move";
|
|
72
|
+
import { MOVE_REARM, moveNowText, planMoveAlerts } from "./cli-move";
|
|
67
73
|
import { alertListing, readingSessionWords } from "./format";
|
|
68
74
|
import type { AlertRule } from "./types";
|
|
69
75
|
|
|
@@ -227,8 +233,8 @@ export const alertsPlugin: GloomPlugin = {
|
|
|
227
233
|
ctx.registerCommand({
|
|
228
234
|
id: "set-alert",
|
|
229
235
|
label: "Add Alert",
|
|
230
|
-
description: "Create a price, valuation or daily technical alert",
|
|
231
|
-
keywords: ["add", "set", "alert", "pe", "ps", "rsi", "moving average", "valuation", "price", "trigger", "notify", "alarm", "watch"],
|
|
236
|
+
description: "Create a price, move, valuation or daily technical alert",
|
|
237
|
+
keywords: ["add", "set", "alert", "move", "previous close", "pe", "ps", "rsi", "moving average", "valuation", "price", "trigger", "notify", "alarm", "watch"],
|
|
232
238
|
category: "data",
|
|
233
239
|
shortcut: "SA",
|
|
234
240
|
shortcutArg: {
|
|
@@ -238,7 +244,8 @@ export const alertsPlugin: GloomPlugin = {
|
|
|
238
244
|
},
|
|
239
245
|
wizardLayout: "form",
|
|
240
246
|
wizard: [
|
|
241
|
-
|
|
247
|
+
// A move from the previous close sits beside a price level: both are checked on the listing's quotes.
|
|
248
|
+
{ key: "kind", label: "Kind", type: "select", defaultValue: "price", options: [METRIC_CHOICES[0]!, MOVE_KIND_CHOICE, ...METRIC_CHOICES.slice(1)] },
|
|
242
249
|
{
|
|
243
250
|
key: "symbol",
|
|
244
251
|
label: "Symbol",
|
|
@@ -263,6 +270,7 @@ export const alertsPlugin: GloomPlugin = {
|
|
|
263
270
|
placeholder: "200.00",
|
|
264
271
|
type: "number",
|
|
265
272
|
},
|
|
273
|
+
...moveWizardFields,
|
|
266
274
|
...metricWizardFields,
|
|
267
275
|
],
|
|
268
276
|
async execute(values) {
|
|
@@ -279,7 +287,7 @@ export const alertsPlugin: GloomPlugin = {
|
|
|
279
287
|
});
|
|
280
288
|
notes.push(...found.notes);
|
|
281
289
|
const key = found.listing.key.toUpperCase();
|
|
282
|
-
return { key, quote: alertQuote(found.quote, key) };
|
|
290
|
+
return { key, exchange: found.listing.exchange, quote: alertQuote(found.quote, key) };
|
|
283
291
|
};
|
|
284
292
|
let resolved: Awaited<ReturnType<typeof quoteFor>>;
|
|
285
293
|
try {
|
|
@@ -287,13 +295,41 @@ export const alertsPlugin: GloomPlugin = {
|
|
|
287
295
|
} catch (error) {
|
|
288
296
|
// XLK/SPY is a listing first; only one the service says is no ticker is the ratio of the two, as `alerts add` reads it.
|
|
289
297
|
// A timeout stays a timeout, and BTC/USD, BRK/B or EUR/USD, one listing written with a slash, keeps its own answer.
|
|
290
|
-
const pair = !input.metric && /^[^/\s]+\/[^/\s]+$/.test(input.symbol) && notATickerSymbol(error instanceof Error ? error.message : String(error))
|
|
298
|
+
const pair = !input.metric && !input.move && /^[^/\s]+\/[^/\s]+$/.test(input.symbol) && notATickerSymbol(error instanceof Error ? error.message : String(error))
|
|
291
299
|
&& !slashSpellsListing(input.symbol) ? parseMetricAlert(`${input.symbol} ratio ${input.condition} ${input.price}`) : null;
|
|
292
300
|
if (!pair) throw error;
|
|
293
301
|
input = pair;
|
|
294
302
|
resolved = await quoteFor(pair.symbol);
|
|
295
303
|
}
|
|
296
304
|
const { key: symbol, quote } = resolved;
|
|
305
|
+
// A move from the previous close is made as `alerts add` makes one: its first reading is the quote it was read on.
|
|
306
|
+
if (input.move) {
|
|
307
|
+
const now = Date.now();
|
|
308
|
+
const exchange = resolved.exchange ? canonicalExchange(resolved.exchange) : canonicalExchange(quote.listingExchangeName || quote.exchangeName);
|
|
309
|
+
const saved = loadJudgedAlerts();
|
|
310
|
+
const plan = planMoveAlerts({ kind: "move", symbols: [input.symbol], condition: input.condition, percent: input.price },
|
|
311
|
+
[{ input: input.symbol, listing: { symbol, ...exchange ? { exchange } : {} }, quote }], saved, now);
|
|
312
|
+
const existing = plan.existing[0]?.alert;
|
|
313
|
+
if (existing) {
|
|
314
|
+
throw new Error(`${formatAlertDescription(existing)} already exists (alert ${existing.id})${existing.status === "triggered"
|
|
315
|
+
? "; it went off this session and arms again in the next" : ""}. Nothing was added.`);
|
|
316
|
+
}
|
|
317
|
+
const alert = plan.added[0];
|
|
318
|
+
if (!alert) throw new Error(plan.failed[0]?.error ?? "No move alert was added.");
|
|
319
|
+
const alerts = [...saved, alert];
|
|
320
|
+
await saveAlerts(ctx, alerts, "price");
|
|
321
|
+
// Its readings stay on this device, beside the rules, as the checks keep them.
|
|
322
|
+
saveMoveChecks(alerts);
|
|
323
|
+
recordFired(alertChangeEntry("created", alertLogRule(alert)));
|
|
324
|
+
alertStream?.sync();
|
|
325
|
+
const reading = moveNowText(alert, now);
|
|
326
|
+
ctx.notify({
|
|
327
|
+
body: [`Alert set: ${formatAlertDescription(alert)} (${MOVE_REARM})${reading ? `, ${reading}` : ""}.`, MOVE_DELIVERY,
|
|
328
|
+
...notes.map((note) => /[.?!]$/.test(note) ? note : `${note}.`)].join(" "),
|
|
329
|
+
type: "success",
|
|
330
|
+
});
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
297
333
|
let metric = input.metric;
|
|
298
334
|
if (metric && isRelativeMetric(metric)) {
|
|
299
335
|
const reference = (await quoteFor(benchmarkKey(metric))).quote;
|
|
@@ -379,7 +415,9 @@ export const alertsPlugin: GloomPlugin = {
|
|
|
379
415
|
type: "select",
|
|
380
416
|
// Earnings first, as the command describes itself: an alert anyone can add for any US listing.
|
|
381
417
|
defaultValue: "earnings_date",
|
|
382
|
-
|
|
418
|
+
// Options flow and IV spikes are checked only with Pro, and say so before one is chosen.
|
|
419
|
+
options: [...RESEARCH_FORM_KINDS.map((value) => ({ value, label: checkedOnlyWithPro({ kind: value }) ? `${RESEARCH_LABELS[value]} (Pro)` : RESEARCH_LABELS[value] })),
|
|
420
|
+
...EVENT_ALERT_TEMPLATES.map((entry) => ({ label: entry.label, value: entry.id }))],
|
|
383
421
|
},
|
|
384
422
|
...EVENT_ALERT_TEMPLATES.filter((entry) => entry.field != null).map((entry) => ({
|
|
385
423
|
key: entry.id,
|
|
@@ -412,6 +450,17 @@ export const alertsPlugin: GloomPlugin = {
|
|
|
412
450
|
});
|
|
413
451
|
if (abroad.exchange) throw new Error(earningsUsOnlyMessage(`${abroad.symbol}:${abroad.exchange}`));
|
|
414
452
|
}
|
|
453
|
+
// A contract typed loosely (`SPY 680C 11/19`) is the one listed contract it names, as `alerts add` reads it.
|
|
454
|
+
const typedContract = event === "iv_spike" ? String(values["iv_spike:contract"] ?? "").trim() : "";
|
|
455
|
+
const looseContract = typedContract && !OCC_CONTRACT.test(typedContract) ? parseLooseOptionContract(typedContract) : null;
|
|
456
|
+
const notes: string[] = [];
|
|
457
|
+
if (looseContract) {
|
|
458
|
+
const getChain = ctx.marketData.getOptionsChain?.bind(ctx.marketData);
|
|
459
|
+
if (!getChain) throw new Error(`Option chains cannot be read here to find ${typedContract}.`);
|
|
460
|
+
const resolved = await resolveLooseOptionContract(typedContract, looseContract, (expiration) => getChain(looseContract.root, "", expiration), Date.now());
|
|
461
|
+
values = { ...values, "iv_spike:contract": resolved.contract };
|
|
462
|
+
if (resolved.readAs) notes.push(resolved.readAs);
|
|
463
|
+
}
|
|
415
464
|
let rule = isResearchAlertKind(event) ? createResearchAlert(event, values) : createEventAlert(event, values?.[event] || "");
|
|
416
465
|
const target = scheduled ? readScheduledRule(rule)?.target : null;
|
|
417
466
|
if (target) {
|
|
@@ -437,7 +486,10 @@ export const alertsPlugin: GloomPlugin = {
|
|
|
437
486
|
const key = eventAlertStoreKey(rule);
|
|
438
487
|
await ctx.configState.set(key, updateEventAlerts(ctx.configState.get<string>(key), (rules) => [...rules, rule]));
|
|
439
488
|
recordFired(alertChangeEntry("created", alertLogRule(rule)));
|
|
440
|
-
|
|
489
|
+
// Saved without Pro, a Pro rule waits on it, as its form said and its row reads (Needs Pro).
|
|
490
|
+
const signedIn = !!apiClient.getSessionToken() || !!apiClient.getCurrentUser();
|
|
491
|
+
const waitsOnPro = checkedOnlyWithPro(rule) && !checksProRules(signedIn, apiClient.getCurrentUser());
|
|
492
|
+
ctx.notify({ body: [`Event alert saved.${waitsOnPro ? savedWithoutProNote(rule) : ""}`, ...notes].join(" "), type: "success" });
|
|
441
493
|
if (scheduled) checkScheduledEventAlertsNow();
|
|
442
494
|
if (rule.kind === "iv_level") checkIvLevelAlertsNow();
|
|
443
495
|
},
|