gloomberb 0.20.13 → 0.20.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/package.json +2 -1
  2. package/patches/@opentui%2Fcore@0.3.2.patch +22 -4
  3. package/src/account/auth-dialog.tsx +22 -4
  4. package/src/account/auth-form.tsx +6 -1
  5. package/src/account/checkout-handoff.tsx +7 -14
  6. package/src/account/device-signin-dialog.tsx +35 -24
  7. package/src/api-client/crypto-markets.ts +10 -0
  8. package/src/api-client/errors.ts +3 -1
  9. package/src/api-client/money-markets.ts +7 -0
  10. package/src/api-client/request.ts +12 -2
  11. package/src/architecture/floating-promise-allowlist.json +0 -1
  12. package/src/brokers/signed-in/sign-in-dialog.tsx +38 -38
  13. package/src/cli/commands/market.ts +95 -23
  14. package/src/cli/commands/overview.ts +18 -4
  15. package/src/cli/errors.ts +3 -1
  16. package/src/cli/freshness.ts +7 -2
  17. package/src/cli/glossary.ts +10 -5
  18. package/src/cli/helpers.ts +8 -16
  19. package/src/cli/history-export.ts +4 -0
  20. package/src/cli/known-gaps.ts +2 -2
  21. package/src/cli/listing-arg.ts +79 -11
  22. package/src/cli/not-a-ticker.ts +4 -0
  23. package/src/cli/pane-functions/catalog.ts +29 -8
  24. package/src/cli/pane-functions/headless.ts +5 -2
  25. package/src/cli/pane-functions/options.ts +7 -0
  26. package/src/cli/pane-functions/resolver.ts +61 -15
  27. package/src/cli/result.ts +22 -4
  28. package/src/cli/symbol-args.ts +5 -3
  29. package/src/cli/symbol-list.ts +23 -10
  30. package/src/cli/symbol-rows.ts +135 -3
  31. package/src/cli/treasury-yields.ts +15 -1
  32. package/src/components/chart/composite/format.ts +2 -1
  33. package/src/components/chart/composite/panel-surface/axis-markers.ts +133 -0
  34. package/src/components/chart/composite/panel-surface/level-labels.tsx +78 -0
  35. package/src/components/chart/composite/panel-surface/overlays.ts +108 -0
  36. package/src/components/chart/composite/panel-surface/pan-coast.ts +54 -0
  37. package/src/components/chart/composite/panel-surface/panel-cursor.tsx +138 -0
  38. package/src/components/chart/composite/panel-surface/panel-levels.ts +47 -0
  39. package/src/components/chart/composite/panel-surface/plot-gestures.ts +403 -0
  40. package/src/components/chart/composite/panel-surface/plot-pointer.ts +65 -0
  41. package/src/components/chart/composite/panel-surface/plot-wheel.ts +102 -0
  42. package/src/components/chart/composite/panel-surface/pointer.ts +12 -0
  43. package/src/components/chart/composite/panel-surface/props.ts +79 -0
  44. package/src/components/chart/composite/panel-surface/tool-readout.ts +151 -0
  45. package/src/components/chart/composite/panel-surface/value-axis-gestures.ts +152 -0
  46. package/src/components/chart/composite/panel-surface.tsx +81 -1177
  47. package/src/components/command-bar/commands/collection-list.ts +1 -0
  48. package/src/components/command-bar/routes/root/results.ts +3 -2
  49. package/src/components/command-bar/routes/root/runtime.ts +3 -2
  50. package/src/components/command-bar/routes/root/selection.ts +3 -2
  51. package/src/components/command-bar/routes/root/shortcuts.ts +15 -0
  52. package/src/components/layout/pane/title.ts +10 -4
  53. package/src/components/pane-settings-dialog/tui.tsx +6 -3
  54. package/src/components/pane-settings-dialog.tsx +2 -1
  55. package/src/components/pane-template-wizard.tsx +2 -0
  56. package/src/components/ui/choice-dialog.tsx +1 -1
  57. package/src/components/ui/confirm-dialog.tsx +3 -2
  58. package/src/components/ui/frame.tsx +7 -3
  59. package/src/components/ui/icon.tsx +4 -2
  60. package/src/components/ui/list-view.tsx +8 -0
  61. package/src/components/ui/number-prompt-dialog.tsx +2 -1
  62. package/src/components/use-pane-notice-footer.tsx +3 -1
  63. package/src/docs/snapshot.json +2 -2
  64. package/src/i18n/es.ts +1 -0
  65. package/src/i18n/ja.ts +1 -0
  66. package/src/i18n/ko.ts +1 -0
  67. package/src/i18n/zh-cn.ts +1 -0
  68. package/src/i18n/zh-tw.ts +1 -0
  69. package/src/market-data/market/format.ts +35 -1
  70. package/src/market-data/quotes/contributions.ts +13 -0
  71. package/src/market-data/quotes/export-identity.ts +36 -1
  72. package/src/market-data/quotes/resolution.ts +16 -0
  73. package/src/plugins/builtin/account-management/password-dialog.tsx +2 -2
  74. package/src/plugins/builtin/analytics/risk-client.ts +12 -2
  75. package/src/plugins/builtin/analytics/risk-headless.ts +66 -6
  76. package/src/plugins/builtin/analytics/risk-math.ts +23 -6
  77. package/src/plugins/builtin/analytics/risk-model.ts +20 -9
  78. package/src/plugins/builtin/analytics/risk-pane.tsx +2 -2
  79. package/src/plugins/builtin/chart-composer/catalog-inventory.ts +5 -2
  80. package/src/plugins/builtin/chart-composer/editor.tsx +1 -0
  81. package/src/plugins/builtin/chart-composer/pane.tsx +1 -1
  82. package/src/plugins/builtin/chart-composer/quick-add.tsx +4 -1
  83. package/src/plugins/builtin/chart-composer/series-catalog.ts +17 -1
  84. package/src/plugins/builtin/cloud/plugin.tsx +2 -0
  85. package/src/plugins/builtin/cloud/thesis/module.tsx +2 -0
  86. package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +6 -2
  87. package/src/plugins/builtin/cpi/headless.ts +6 -1
  88. package/src/plugins/builtin/cpi/model.ts +17 -0
  89. package/src/plugins/builtin/cpi/pane.tsx +3 -1
  90. package/src/plugins/builtin/crypto-board/client.ts +6 -1
  91. package/src/plugins/builtin/crypto-board/headless.ts +10 -2
  92. package/src/plugins/builtin/crypto-board/model.ts +89 -11
  93. package/src/plugins/builtin/crypto-board/pane.tsx +20 -5
  94. package/src/plugins/builtin/dividend-yield/client.ts +24 -2
  95. package/src/plugins/builtin/dividend-yield/headless.ts +4 -2
  96. package/src/plugins/builtin/dividend-yield/ranking.ts +2 -1
  97. package/src/plugins/builtin/dividend-yield/view.ts +5 -1
  98. package/src/plugins/builtin/earnings/history-table.ts +8 -0
  99. package/src/plugins/builtin/earnings-ripple/index.tsx +2 -0
  100. package/src/plugins/builtin/econ/calendar-model.ts +17 -1
  101. package/src/plugins/builtin/econ/fred-catalog.ts +33 -4
  102. package/src/plugins/builtin/econ-statistics/headless.ts +21 -0
  103. package/src/plugins/builtin/macro-day/headless.ts +21 -10
  104. package/src/plugins/builtin/macro-day/model.ts +40 -3
  105. package/src/plugins/builtin/macro-day/pane.tsx +26 -8
  106. package/src/plugins/builtin/macro-day/releases.ts +24 -1
  107. package/src/plugins/builtin/money-markets/client.ts +4 -1
  108. package/src/plugins/builtin/money-markets/headless.ts +15 -4
  109. package/src/plugins/builtin/money-markets/index.tsx +1 -1
  110. package/src/plugins/builtin/money-markets/pane.tsx +7 -1
  111. package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +4 -2
  112. package/src/plugins/builtin/portfolio-list/cli/period-report.ts +61 -11
  113. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +11 -3
  114. package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +2 -0
  115. package/src/plugins/builtin/portfolio-list/headless.ts +33 -6
  116. package/src/plugins/builtin/portfolio-list/pane/index.tsx +5 -3
  117. package/src/plugins/builtin/portfolio-list/pane/period-pnl.ts +24 -6
  118. package/src/plugins/builtin/portfolio-list/period-pnl.ts +16 -1
  119. package/src/plugins/builtin/portfolio-list/summary/index.tsx +4 -1
  120. package/src/plugins/builtin/portfolio-list/summary/totals.ts +6 -4
  121. package/src/plugins/builtin/portfolio-list/table.tsx +25 -15
  122. package/src/plugins/builtin/shared/cloud-upgrade.ts +4 -2
  123. package/src/plugins/builtin/shared/cpi-year-gap.ts +67 -0
  124. package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +45 -2
  125. package/src/plugins/builtin/ticker-detail/headless.ts +26 -1
  126. package/src/plugins/builtin/ticker-detail/overview/components.tsx +4 -5
  127. package/src/plugins/builtin/ticker-detail/overview/model.ts +4 -1
  128. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +10 -2
  129. package/src/portfolio/collection-name.ts +2 -1
  130. package/src/portfolio/column-values.ts +14 -4
  131. package/src/portfolio/listed-symbol.ts +4 -2
  132. package/src/portfolio/period-pnl.ts +51 -1
  133. package/src/renderers/dom/dialog-host.tsx +5 -5
  134. package/src/renderers/electrobun/view/remote/capability-invoker.ts +1 -1
  135. package/src/renderers/opentui/dialog-host.tsx +3 -4
  136. package/src/sources/gloomberb-cloud/normalizers.ts +5 -0
  137. package/src/sources/provider-router/history.ts +5 -2
  138. package/src/test-support/plugin-persistence.ts +12 -0
  139. package/src/tickers/company-name-listing.ts +4 -3
  140. package/src/tickers/company-name.ts +19 -1
  141. package/src/tickers/instrument-coverage.ts +27 -0
  142. package/src/tickers/search/home-listing.ts +38 -1
  143. package/src/tickers/search/index.ts +3 -2
  144. package/src/tickers/search/ranking.ts +21 -2
  145. package/src/time-series/base-series.ts +4 -0
  146. package/src/time-series/types.ts +5 -2
  147. package/src/types/financials.ts +13 -0
  148. package/src/types/headless.ts +2 -0
  149. package/src/ui/dialog-stack.ts +17 -0
  150. package/src/ui/dialog.tsx +6 -2
  151. package/src/utils/crypto-pair.ts +9 -0
  152. package/src/utils/exchanges.ts +13 -0
  153. package/src/utils/financial-statements.ts +60 -3
  154. package/src/utils/futures-generic.ts +14 -0
  155. package/src/utils/trailing-dividend.ts +13 -3
@@ -1,4 +1,5 @@
1
1
  import { futuresContractByWord } from "../market-data/futures-board";
2
+ import { venueOfDatedContract } from "../utils/futures-generic";
2
3
  import { notATickerSymbol } from "../sources/provider-errors";
3
4
  import { renamedListingFor, renamedListingHint } from "../tickers/renamed-listings";
4
5
  import { boardCoinFor } from "./board-coins";
@@ -58,6 +59,9 @@ export function withSearchHints(text: string, args: readonly string[], isFredSer
58
59
  if (renamed) return `${sentence} ${renamedListingHint(renamed)}`;
59
60
  const coin = boardCoinFor(id);
60
61
  if (coin) return `${sentence} Did you mean ${coin.symbol}${coin.name && coin.name.toUpperCase() !== coin.symbol ? ` (${coin.name})` : ""}?`;
62
+ // A dated contract typed without its venue (ZQZ26) is quoted with it: ZQZ26.CBT, as WIRP prints it.
63
+ const contract = venueOfDatedContract(id);
64
+ if (contract) return `${sentence} Did you mean ${contract}?`;
61
65
  const tenor = treasuryYieldTenor(typed);
62
66
  // A currency's name (`yen`) is its rate and its pair, not a ticker search could find; a commodity's word
63
67
  // (`oil`, `brent`) is its future, which no search for the word finds first.
@@ -1,4 +1,6 @@
1
+ import type { TickerRecord } from "../../types/ticker";
1
2
  import { logFailure } from "../../utils/log-failure";
3
+ import { shellWord } from "../../utils/shell-word";
2
4
  import { commands as builtInCommands, getCommandPrefixes } from "../../components/command-bar/commands/registry";
3
5
  import type { HeadlessPaneDefinition, PaneDef, PaneTemplateCreateOptions, PaneTemplateDef } from "../../types/plugin";
4
6
  import type { MarketContext } from "../types";
@@ -297,6 +299,7 @@ async function buildTemplateCatalogEntry(
297
299
  pane: PaneDef,
298
300
  context: MarketContext | null,
299
301
  token: string,
302
+ listName?: string | null,
300
303
  ): Promise<PaneCatalogEntry> {
301
304
  const sampleArg = sampleArgForTemplate(template);
302
305
  const createOptions: PaneTemplateCreateOptions | undefined = buildCreateOptions(template, sampleArg);
@@ -326,7 +329,7 @@ async function buildTemplateCatalogEntry(
326
329
  aliases: [...(template.shortcut?.aliases ?? [])],
327
330
  argKind: argument.kind,
328
331
  argPlaceholder: argument.placeholder,
329
- ...context ? argExamples(headless, context, pane) : null,
332
+ ...context ? argExamples(headless, context, pane, listName) : null,
330
333
  ...(headless?.argument.kind === "tickers" && template.shortcut?.argKind === "ticker"
331
334
  ? { shotArgument: argumentHint({ argKind: "ticker", argPlaceholder: template.shortcut.argPlaceholder }) } : {}),
332
335
  keywords: template.keywords ?? [],
@@ -337,19 +340,34 @@ async function buildTemplateCatalogEntry(
337
340
 
338
341
  /**
339
342
  * The arguments a function's examples show past its placeholder: its own, and
340
- * for a list of more than two symbols, a watchlist's name, which stands for
341
- * its symbols (the reader's first watchlist).
343
+ * for a list of more than two symbols, a list's name, which stands for its
344
+ * symbols: the reader's first watchlist or portfolio that holds any
345
+ * (`listName`), so the example runs as printed.
342
346
  */
343
- function argExamples(headless: HeadlessPaneDefinition | undefined, context: MarketContext, pane?: PaneDef): { argExamples: readonly string[] } | null {
347
+ function argExamples(
348
+ headless: HeadlessPaneDefinition | undefined,
349
+ context: MarketContext,
350
+ pane?: PaneDef,
351
+ listName: string | null = context.config.watchlists[0]?.name ?? "Watchlist",
352
+ ): { argExamples: readonly string[] } | null {
344
353
  // A rendered view's own examples (VIEW's spec) stand where a headless model would give them.
345
354
  const own = headless?.argument.examples ?? pane?.reportArgument?.examples ?? [];
346
355
  const argument = headless?.argument;
347
356
  const list = (argument?.kind === "symbol-list" || argument?.kind === "tickers") && (argument.maximum == null || argument.maximum > 2);
348
- const name = context.config.watchlists[0]?.name ?? "Watchlist";
349
- const examples = list ? [...own, /^[\w.-]+$/.test(name) ? name : `'${name.replace(/'/g, "'\\''")}'`] : own;
357
+ const examples = list && listName ? [...own, shellWord(listName)] : own;
350
358
  return examples.length > 0 ? { argExamples: examples } : null;
351
359
  }
352
360
 
361
+ /** The first watchlist, else portfolio, that holds a symbol: the list a function's example names. Null when none does. */
362
+ async function exampleListName(context: MarketContext): Promise<string | null> {
363
+ const tickers = await Promise.resolve().then(() => context.store.loadAllTickers())
364
+ .catch(logFailure("cli-catalog", "Read the lists for an example failed", [] as TickerRecord[]));
365
+ const watchlist = context.config.watchlists.find((list) => tickers.some((ticker) => ticker.metadata.watchlists.includes(list.id)));
366
+ const portfolio = watchlist ? null : context.config.portfolios.find((list) => tickers.some((ticker) => ticker.metadata.portfolios.includes(list.id)
367
+ || ticker.metadata.positions.some((position) => position.portfolio === list.id && position.shares !== 0)));
368
+ return (watchlist ?? portfolio)?.name ?? null;
369
+ }
370
+
353
371
  /**
354
372
  * The functions `gloom catalog` and search list. An unlisted one (`listed:
355
373
  * false`) is left out, and its pane is not listed in its place; `unlisted`
@@ -363,6 +381,8 @@ export async function buildPaneCatalogEntries(
363
381
  { unlisted = false, appPanes = false }: { unlisted?: boolean; appPanes?: boolean } = {},
364
382
  ): Promise<PaneCatalogEntry[]> {
365
383
  const entries: PaneCatalogEntry[] = [];
384
+ // Read once, when an example first needs it.
385
+ let listName: Promise<string | null> | undefined;
366
386
  const templatedPaneIds = new Set<string>();
367
387
  const codedPaneIds = new Set([...registry.paneTemplates.values()]
368
388
  .filter((template) => template.shortcut?.prefix && template.listed !== false)
@@ -377,7 +397,8 @@ export async function buildPaneCatalogEntries(
377
397
  if (!forUsers && !unlisted && !appPanes) continue;
378
398
  // A template only the UI audits list keeps the id an older catalog listed it by, so a base and a head picture it under one name.
379
399
  const token = forUsers || unlisted ? paneFunctionCode(template, pane, registry) : template.id;
380
- entries.push(await buildTemplateCatalogEntry(template, pane, context, token));
400
+ listName ??= context ? exampleListName(context) : Promise.resolve(null);
401
+ entries.push(await buildTemplateCatalogEntry(template, pane, context, token, await listName));
381
402
  }
382
403
 
383
404
  for (const pane of registry.panes.values()) {
@@ -394,7 +415,7 @@ export async function buildPaneCatalogEntries(
394
415
  aliases,
395
416
  argKind: argument.kind,
396
417
  argPlaceholder: argument.placeholder,
397
- ...context ? argExamples(pane.headless, context, pane) : null,
418
+ ...context ? argExamples(pane.headless, context, pane, await (listName ??= exampleListName(context))) : null,
398
419
  keywords: [],
399
420
  defaultSettings: {},
400
421
  capability: getPaneFunctionCapability(undefined, pane),
@@ -867,8 +867,11 @@ export function headlessReportTables(
867
867
  const columns = displayedColumns(columnsFor(rowsResult.rows, rowsResult.columns, definition.columns));
868
868
  const rowIdentities = rowIdentitiesOf(rowsResult.rows, rowsResult);
869
869
  const own = exportRowsTable(title, columns, rowsResult.rows, { status: true, ...(rowsResult.rowUnitKey ? { rowUnitKey: rowsResult.rowUnitKey } : {}) });
870
- const interval = rowsResult.interval?.trim();
871
- tables = [{ ...own, ...(rowIdentities ? { rowIdentities } : {}), ...(interval ? { identity: { interval } } : {}) }, ...(rowsResult.exportTables ?? []).map((extra) => {
870
+ const ownIdentity = {
871
+ ...(rowsResult.unit?.trim() ? { currencyOrUnit: rowsResult.unit.trim() } : {}),
872
+ ...(rowsResult.interval?.trim() ? { interval: rowsResult.interval.trim() } : {}),
873
+ };
874
+ tables = [{ ...own, ...(rowIdentities ? { rowIdentities } : {}), ...(Object.keys(ownIdentity).length > 0 ? { identity: ownIdentity } : {}) }, ...(rowsResult.exportTables ?? []).map((extra) => {
872
875
  const identity = {
873
876
  ...(extra.unit?.trim() ? { currencyOrUnit: extra.unit.trim() } : {}),
874
877
  ...(extra.interval?.trim() ? { interval: extra.interval.trim() } : {}),
@@ -67,6 +67,11 @@ export interface ParsedPaneFunctionArgs {
67
67
  * pair with no options of its own): an export still has a row for each, its reason in the status column.
68
68
  */
69
69
  refusedListings?: Array<{ symbol: string; reason: string }>;
70
+ /**
71
+ * The argument's words as the shell passed them, when one holds a space: it was quoted (`fn G "VOD LN"`), so
72
+ * its words are one entry, not several typed apart (`fn G AAPL MSFT`). `arg` joins them either way.
73
+ */
74
+ quotedWords?: string[];
70
75
  }
71
76
 
72
77
  export interface ParsedPaneCatalogArgs {
@@ -227,6 +232,7 @@ export function parsePaneFunctionArgs(
227
232
 
228
233
  const target = positionals[0]?.trim() ?? "";
229
234
  const arg = positionals.slice(1).join(" ").trim();
235
+ const quoted = positionals.slice(1).some((word) => /\s/.test(word.trim()));
230
236
  // The outer CLI parser consumes --limit and --tail before fn/shot sees its arguments.
231
237
  // Restore them for the pane's own schema and loader, including bounds checks,
232
238
  // so a function without a tail option says so instead of ignoring it.
@@ -239,6 +245,7 @@ export function parsePaneFunctionArgs(
239
245
  ...(explain ? { explain } : {}),
240
246
  ...(strict ? { strict } : {}),
241
247
  ...(shotOnly.length > 0 ? { shotOnly } : {}),
248
+ ...(quoted ? { quotedWords: positionals.slice(1) } : {}),
242
249
  };
243
250
  }
244
251
 
@@ -9,13 +9,14 @@ import type {
9
9
  } from "../../types/plugin";
10
10
  import { applyChartComposerCapabilityOptions } from "../../plugins/builtin/chart-composer/cli-options";
11
11
  import { parseChartSpec } from "../../plugins/builtin/chart-composer/chart-spec";
12
+ import { CHART_COMPOSER_TEMPLATE_ID } from "../../plugins/builtin/chart-composer/catalog-inventory";
12
13
  import { normalizeTickerInput } from "../../tickers/search";
13
14
  import { slugifyName } from "../../utils/slugify";
14
15
  import { fredSeriesArgument } from "../../series/fred-argument";
15
16
  import {
16
17
  type CliListing, listCoinNotes, ListingArgError, listingInstrument, listingReadNotes, MAX_CHOICE_LOOKUPS, resolveCliListing, usListingsOnlyMessage,
17
18
  } from "../listing-arg";
18
- import { uncoveredInstrumentKind, uncoveredInstrumentMessage } from "../../tickers/instrument-coverage";
19
+ import { uncoveredInstrumentKind, uncoveredInstrumentMessage, uncoveredInstrumentsMessage } from "../../tickers/instrument-coverage";
19
20
  import { uncoveredInstrumentCommand } from "../uncovered-instrument";
20
21
  import { listingAbroadVenue } from "../../utils/sec";
21
22
  import { splitSymbolArgs, stripStrayEdges } from "../symbol-args";
@@ -27,7 +28,7 @@ import { readTerminalCodeArg } from "../../tickers/company-name-listing";
27
28
  import { unknownBloombergMarket, unreadBloombergCode } from "../../tickers/terminal-codes";
28
29
  import { notATickerWords } from "../company-name-hint";
29
30
  import type { MarketContext } from "../types";
30
- import { findWatchlist } from "../helpers";
31
+ import { shellWord } from "../../utils/shell-word";
31
32
  import { readWatchlistArgument, watchlistMemberSymbol } from "../../portfolio/collection-name";
32
33
  import {
33
34
  buildPaneFunctionLookup,
@@ -225,6 +226,8 @@ export async function applyListingArgument(
225
226
  ): Promise<ParsedPaneFunctionArgs> {
226
227
  const found = args.target ? findPaneFunction(registry, args.target) : null;
227
228
  if (!found?.pane || !args.arg) return args;
229
+ // G's series are text (`fn G AAPL MSFT` is two), but a quoted terminal code in them is one listing.
230
+ if (found.template?.id === CHART_COMPOSER_TEMPLATE_ID) return withChartTerminalCodes(args, context);
228
231
  const headless = getHeadlessPaneDefinition(found.template, found.pane);
229
232
  const kind = headless?.argument.kind ?? found.template?.shortcut?.argKind;
230
233
  const takesOneTicker = kind === "ticker";
@@ -233,7 +236,7 @@ export async function applyListingArgument(
233
236
  if (!(takesOneTicker || takesList) || getPaneFunctionCapability(found.template, found.pane).options.some((option) => option.key === "exchange")) {
234
237
  return args;
235
238
  }
236
- // A watchlist's name stands for its symbols, as saved (`fn SIW HY3`).
239
+ // A watchlist's or a portfolio's name stands for its symbols, as saved (`fn SIW HY3`, `fn RIPL "Pension Book"`).
237
240
  const watchlist = takesList ? await watchlistArgument(args.arg, context, headless?.argument.maximum) : null;
238
241
  if (watchlist) args = { ...args, arg: watchlist.symbols.join(", ") };
239
242
  // A function that reads FRED series (MDAY) gets FRED:T10Y2Y as typed; any other is told it is no listing.
@@ -299,7 +302,10 @@ export async function applyListingArgument(
299
302
  if (listings.length === 0) {
300
303
  throw new ListingArgError(answers.map((answer) => answer.message).join("\n"), answers.map((answer) => answer.details).join("\n"));
301
304
  }
302
- notes.push(...answers.map((answer) => `${answer.message} ${answer.details}`));
305
+ // Several are said in one line (a portfolio's futures and funds), each one's own command left out.
306
+ notes.push(...outside.length > 1
307
+ ? [uncoveredInstrumentsMessage(token, covered, outside.map(({ instrument }) => instrument))]
308
+ : answers.map((answer) => `${answer.message} ${answer.details}`));
303
309
  refused.push(...outside.map(({ listing }, index) => ({ symbol: listing.key, reason: answers[index]!.message })));
304
310
  }
305
311
  }
@@ -348,10 +354,39 @@ export async function applyListingArgument(
348
354
  }
349
355
 
350
356
  /**
351
- * The symbols of the watchlist a list argument names (case aside), as saved,
352
- * at most the function's `maximum` of them, with the note that says the name
353
- * was read as that watchlist (`readWatchlistArgument`). Null when the
354
- * argument names no watchlist, or one with nothing in it.
357
+ * A chart's series typed in quotes that is a terminal's code for one listing
358
+ * (`fn G "VOD LN"`, `"MC FP Equity"`) is that listing, as `quote`, `history`,
359
+ * HP and GP read it, and says so: its words are not two series (VOD on NASDAQ
360
+ * and LN, a ticker that stopped trading in 2020). So is each such entry of a
361
+ * quoted list (`"VOD LN, MC FP"`). Words typed apart (`fn G AAPL MSFT`) are a
362
+ * series each, and a qualified symbol (VOD:LSE) is read as written.
363
+ */
364
+ async function withChartTerminalCodes(args: ParsedPaneFunctionArgs, context: MarketContext): Promise<ParsedPaneFunctionArgs> {
365
+ if (!args.quotedWords) return args;
366
+ const notes: string[] = [];
367
+ const readEntry = async (entry: string) => {
368
+ const typed = entry.trim();
369
+ const code = /\s/.test(typed) ? await readTerminalCodeArg(context.dataProvider, typed) : null;
370
+ if (!code) return entry;
371
+ notes.push(`Read "${typed}" as ${code.key}.`);
372
+ return entry.replace(typed, code.key);
373
+ };
374
+ const words = await Promise.all(args.quotedWords.map(async (word) => /\s/.test(word.trim())
375
+ ? (await Promise.all(word.split(/([;,\n])/).map((part, index) => index % 2 === 1 ? part : readEntry(part)))).join("")
376
+ : word));
377
+ if (notes.length === 0) return args;
378
+ return { ...args, arg: words.join(" ").trim(), listingNotes: [...args.listingNotes ?? [], ...notes] };
379
+ }
380
+
381
+ /**
382
+ * The symbols of the watchlist or portfolio a list argument names by its name
383
+ * (case aside), as saved, a portfolio's holdings being what it holds now, at
384
+ * most the function's `maximum` of them, with the note that says the name was
385
+ * read as that list (`readWatchlistArgument`). A list's id is no name: `main`
386
+ * is the default portfolio's id and a ticker too. Null when the argument names
387
+ * neither, or names an empty list a ticker could be named as (an empty
388
+ * watchlist named AI reads AI); an empty list's name of several words fails,
389
+ * saying so.
355
390
  */
356
391
  async function watchlistArgument(
357
392
  arg: string,
@@ -359,13 +394,24 @@ async function watchlistArgument(
359
394
  maximum: number | undefined,
360
395
  ): Promise<{ symbols: string[]; notes: string[] } | null> {
361
396
  if (/[,;\t\n]/.test(arg)) return null;
362
- const watchlist = findWatchlist(context.config, arg);
363
- if (!watchlist) return null;
364
- const symbols = (await context.store.loadAllTickers())
365
- .filter((ticker) => ticker.metadata.watchlists.includes(watchlist.id))
366
- .map((ticker) => watchlistMemberSymbol(ticker.metadata));
367
- if (symbols.length === 0) return null;
368
- const read = readWatchlistArgument(arg, watchlist, symbols, maximum);
397
+ const wanted = arg.trim().toLowerCase();
398
+ const named = <T extends { name: string }>(lists: readonly T[]) => lists.find((list) => list.name.trim().toLowerCase() === wanted) ?? null;
399
+ const watchlist = named(context.config.watchlists);
400
+ const portfolio = watchlist ? null : named(context.config.portfolios);
401
+ const list = watchlist ?? portfolio;
402
+ if (!list) return null;
403
+ const members = (await context.store.loadAllTickers()).filter((ticker) => watchlist
404
+ ? ticker.metadata.watchlists.includes(watchlist.id)
405
+ : ticker.metadata.portfolios.includes(portfolio!.id)
406
+ || ticker.metadata.positions.some((position) => position.portfolio === portfolio!.id && position.shares !== 0));
407
+ const symbols = [...new Set(members.map((ticker) => watchlistMemberSymbol(ticker.metadata)))];
408
+ const kind = watchlist ? "watchlist" : "portfolio";
409
+ if (symbols.length === 0) {
410
+ if (!/\s/.test(arg.trim())) return null;
411
+ throw new ListingArgError(`${kind === "watchlist" ? "Watchlist" : "Portfolio"} "${list.name}" is empty, so there is nothing to read.`,
412
+ `Add symbols with gloom ${kind} add ${shellWord(list.name)} AAPL, or type tickers.`);
413
+ }
414
+ const read = readWatchlistArgument(arg, list, symbols, maximum, kind);
369
415
  return { symbols: read.symbols, notes: [read.note] };
370
416
  }
371
417
 
package/src/cli/result.ts CHANGED
@@ -156,6 +156,12 @@ export interface CliResultRenderOptions<T = unknown, Row = Record<string, unknow
156
156
  * without a reason here, named as `<header>: not available`.
157
157
  */
158
158
  exportStatus?: (row: Row) => string | null | undefined;
159
+ /**
160
+ * Row fields a report gained after its columns were set: CSV writes them
161
+ * last, after `retrieved_at`, and NDJSON ends each row with them, so no
162
+ * column an earlier export had moves.
163
+ */
164
+ exportAppendedKeys?: readonly string[];
159
165
  }
160
166
 
161
167
  interface CliResultJsonEnvelope<T> extends Omit<CliResult<T>, "freshness" | "exportFreshness" | "failure"> {
@@ -378,11 +384,16 @@ function renderCsv<Row extends Record<string, unknown>>(
378
384
  dating?: (row: Row) => string[],
379
385
  /** When the data was retrieved, which an undated export's rows end with (`retrieved_at`). */
380
386
  retrieved?: string,
387
+ /** Keys written after every other column (`exportAppendedKeys`), in this order. */
388
+ appendedKeys: readonly string[] = [],
381
389
  ): string {
382
- const resolvedColumns = columns && columns.length > 0
390
+ const allColumns = columns && columns.length > 0
383
391
  ? columns
384
392
  : inferColumns(rows as Record<string, unknown>[]) as CliResultColumn<Row>[];
393
+ const resolvedColumns = allColumns.filter((column) => !appendedKeys.includes(column.key));
394
+ const appended = appendedKeys.flatMap((key) => allColumns.filter((column) => column.key === key));
385
395
  const headers = resolvedColumns.map((column) => column.header);
396
+ const cell = (value: unknown) => isNonFiniteNumber(value) ? "" : typeof value === "number" ? exportNumber(value) : value;
386
397
  // A dated export's own `released` column keeps its values; the others close the row.
387
398
  const datingAdded = dating
388
399
  ? EXPORT_DATING_COLUMNS.flatMap((column, index) => headers.includes(column) ? [] : [index]) : [];
@@ -394,17 +405,19 @@ function renderCsv<Row extends Record<string, unknown>>(
394
405
  ...identity ? EXPORT_IDENTITY_COLUMNS : [],
395
406
  ...datingAdded.map((index) => EXPORT_DATING_COLUMNS[index]!),
396
407
  ...retrieval ? [EXPORT_RETRIEVAL_COLUMN] : [],
408
+ ...appended.map((column) => column.header),
397
409
  ],
398
410
  ...rows.map((row) => {
399
411
  const values = resolvedColumns.map((column) => (column.value ? column.value(row) : row[column.key]));
400
412
  const blanked = resolvedColumns.flatMap((column, index) => isNonFiniteNumber(values[index]) ? [column.header] : []);
401
413
  const datingCells = dating?.(row) ?? [];
402
414
  return [
403
- ...values.map((value) => isNonFiniteNumber(value) ? "" : typeof value === "number" ? exportNumber(value) : value),
415
+ ...values.map(cell),
404
416
  ...status ? [exportStatusText(status(row), blanked)] : [],
405
417
  ...identity?.(row) ?? [],
406
418
  ...datingAdded.map((index) => datingCells[index] ?? ""),
407
419
  ...retrieval ? [retrieved] : [],
420
+ ...appended.map((column) => cell(column.value ? column.value(row) : row[column.key])),
408
421
  ];
409
422
  }),
410
423
  ]);
@@ -587,13 +600,17 @@ function serializeCliRows<T, Row extends Record<string, unknown>>(
587
600
  // An undated row says when it was retrieved last, as CSV's `retrieved_at` does.
588
601
  const retrieval = !renderOptions.exportDated && !(EXPORT_RETRIEVAL_COLUMN in fields)
589
602
  ? { [EXPORT_RETRIEVAL_COLUMN]: exportRetrievalCell(cited) } : {};
590
- return JSON.stringify({ ...fields, ...exportIdentityFields(cited, identity), ...dating, ...retrieval }, exportJsonValue);
603
+ // Fields a report gained later end the row, as they end a CSV row.
604
+ const appended = Object.fromEntries((renderOptions.exportAppendedKeys ?? []).flatMap((key) => key in fields ? [[key, fields[key]]] : []));
605
+ const own = Object.fromEntries(Object.entries(fields).filter(([key]) => !(key in appended)));
606
+ return JSON.stringify({ ...own, ...exportIdentityFields(cited, identity), ...dating, ...retrieval, ...appended }, exportJsonValue);
591
607
  }).join("\n");
592
608
  }
593
609
  if (options.format === "csv") {
594
610
  // The rows a window cut say so after them, as text and JSON do: a script has no other way to know.
595
611
  const cutNote = window.note ? [`note: ${window.note}`] : [];
596
- if (!cited) return withCsvFooter(renderCsv(rows as Row[], renderOptions.columns, undefined, status), cutNote);
612
+ const appended = renderOptions.exportAppendedKeys ?? [];
613
+ if (!cited) return withCsvFooter(renderCsv(rows as Row[], renderOptions.columns, undefined, status, undefined, undefined, appended), cutNote);
597
614
  const csv = renderCsv(
598
615
  rows as Row[],
599
616
  renderOptions.columns,
@@ -601,6 +618,7 @@ function serializeCliRows<T, Row extends Record<string, unknown>>(
601
618
  status,
602
619
  renderOptions.exportDated ? (row) => exportDatingCells(cited, rowIdentity(row, renderOptions.exportIdentity)) : undefined,
603
620
  exportRetrievalCell(cited),
621
+ appended,
604
622
  );
605
623
  return withCsvFooter(csv, [...exportSourceLines(cited), ...cutNote, ...(renderOptions.exportNotes ?? []).map((note) => `note: ${note}`)]);
606
624
  }
@@ -136,10 +136,12 @@ export function symbolInputKey(symbol: string): string {
136
136
 
137
137
  /**
138
138
  * How a command's symbol list spots one security typed twice: `symbolInputKey`,
139
- * with a share class written with a dot or a dash as one (BRK.B and BRK-B).
139
+ * with a share class written with a dot, a dash or, as a broker writes it, a
140
+ * slash as one (BRK.B, BRK-B and BRK/B). One letter before a slash is no
141
+ * symbol's (N/A, P/E).
140
142
  */
141
- function securityInputKey(symbol: string): string {
142
- return symbolInputKey(symbol).replace(/-/g, ".");
143
+ export function securityInputKey(symbol: string): string {
144
+ return symbolInputKey(symbol).replace(/-/g, ".").replace(/^([A-Z]{2,5})\/([A-Z])$/, "$1.$2");
143
145
  }
144
146
 
145
147
  /** The securities of a symbol list, each once, in the first spelling typed: `AAPL aapl BRK.B BRK-B` is AAPL and BRK.B. */
@@ -221,6 +221,8 @@ interface SymbolText {
221
221
  entries?: true;
222
222
  /** A first row read as a header in words no header list knows (`Hisse,Adet,Maliyet`), skipped and named. */
223
223
  header?: string[];
224
+ /** Each symbol is a line of the text, whole: a list of one entry a line, as a sheet's column pastes. */
225
+ lines?: true;
224
226
  }
225
227
 
226
228
  /** Words a sheet writes where a value is missing, beside the marks isJunkCell knows (`N/A`, `-`, `—`). */
@@ -296,7 +298,7 @@ export function parseSymbolText(text: string): SymbolText {
296
298
  const cleaned = records.map((cells) => cells.map((cell) => stripStrayEdges(cell).text));
297
299
  const figures = cleaned.some((cells) => cells.some((cell, index) => index > 0 && isFigure(cell)));
298
300
  // Lines split by spaces alone are entries, unless figures sit beside the symbols.
299
- if (!delimited && !figures) return { symbols: records.map((cells) => cells.join(" ")), ignored: [], entries: true };
301
+ if (!delimited && !figures) return { symbols: records.map((cells) => cells.join(" ")), ignored: [], entries: true, lines: true };
300
302
  // A grid of symbols: a terminal's code is one cell (`CZR US Equity`), and so is a numeric code among tickers (`2007`).
301
303
  const codes = symbolColumns(cleaned);
302
304
  const grid = numericCodeGrid(cleaned) || cleaned.every((cells) => cells.every((cell, index) => (
@@ -479,13 +481,15 @@ export async function readSymbolList(source: SymbolListSource): Promise<{ symbol
479
481
  const code = (error as NodeJS.ErrnoException).code;
480
482
  throw new SymbolListError(code === "ENOENT" ? `No file at ${source.file}.` : `Could not read ${source.file}: ${error instanceof Error ? error.message : String(error)}`);
481
483
  }
482
- typedForms.push(...typedLines(text));
483
- await addCells(parseSymbolText(foldTypedText(text)));
484
+ const parsed = parseSymbolText(foldTypedText(text));
485
+ typedForms.push(...typedLines(text, !!parsed.lines));
486
+ await addCells(parsed);
484
487
  }
485
488
  if (wantsStdin || (typed.length === 0 && source.file == null && (source.stdinPiped ?? stdinIsPiped()))) {
486
489
  const text = await readStdin();
487
- typedForms.push(...typedLines(text));
488
- await addCells(parseSymbolText(foldTypedText(text)));
490
+ const parsed = parseSymbolText(foldTypedText(text));
491
+ typedForms.push(...typedLines(text, !!parsed.lines));
492
+ await addCells(parsed);
489
493
  }
490
494
  // A number where a symbol goes (a line of prices, a typed 1.899) is left out with those typed beside a symbol.
491
495
  const numbers = [...figures, ...collected.filter(isNumberCell)];
@@ -498,17 +502,26 @@ export interface TypedForm {
498
502
  typed: string;
499
503
  /** The entry the line reads as, its repeats' key (`symbolInputKey`): `USDJPY` and `usdjpy` are both `USDJPY`'s. */
500
504
  key: string;
505
+ /**
506
+ * A line of a list of one entry a line, which has a row whatever it reads as, so the rows line up with the
507
+ * sheet's: a blank one (`typed` empty), or one no entry was read from (`N/A`, a number).
508
+ */
509
+ ownRow?: true;
501
510
  }
502
511
 
503
512
  /**
504
513
  * Each line of a list's text that is one entry, as typed and in order, an exact repeat too, with the key of the entry
505
514
  * it reads as: so a command can give every line its row and say which line of a sheet each row is, where several
506
- * were read as one entry.
515
+ * were read as one entry. In a list of one entry a line (`everyLine`), every line up to the last that holds
516
+ * anything is one, a blank line too; a comment (`# held since 2019`) is none.
507
517
  */
508
- function typedLines(text: string): TypedForm[] {
509
- return text.split(/\r?\n/).flatMap((line) => {
510
- const typed = line.trim();
511
- const key = symbolInputKey(stripStrayEdges(foldTypedText(typed)).text);
518
+ function typedLines(text: string, everyLine: boolean): TypedForm[] {
519
+ const lines = text.replace(/^\uFEFF/, "").split(/\r?\n/).map((line) => line.trim());
520
+ const last = lines.findLastIndex(Boolean);
521
+ return lines.slice(0, last + 1).flatMap((typed) => {
522
+ // The list reads a line's words with one space between them (`MC FP Equity` is MC FP Equity), so its key does too.
523
+ const key = symbolInputKey(stripStrayEdges(foldTypedText(typed)).text.replace(/\s+/g, " "));
524
+ if (everyLine && !isComment(typed)) return [{ typed, key, ownRow: true as const }];
512
525
  if (!typed || !key) return [];
513
526
  return [{ typed, key }];
514
527
  });
@@ -21,7 +21,10 @@ import { isVenueAbroad } from "../tickers/listing-fate";
21
21
  import { serviceMarkedOtherListing } from "../tickers/company-name-listing";
22
22
  import { companyNameCase, sameCompany, shortCompanyName } from "../tickers/company-name";
23
23
  import { tickerHasListingSuffix } from "../sources/listing-symbols";
24
- import { canonicalExchange, exchangeLabel, isUsListingExchange, resolveExchangeTimeZone } from "../utils/exchanges";
24
+ import { canonicalExchange, exchangeLabel, isUsListingExchange, parsePublicTickerKey, resolveExchangeTimeZone, storedKeyListing } from "../utils/exchanges";
25
+ import { resolveTickerInstrumentKind } from "../tickers/instrument-kind";
26
+ import { futuresGenericListing, parseFuturesGeneric } from "../utils/futures-generic";
27
+ import { isProviderBusy, isRateLimited, isSourceFailure, isTransientServiceFailure } from "../sources/provider-errors";
25
28
  import { isCurrencyPairListing } from "../utils/fx-market-hours";
26
29
  import { isCurrencyCode } from "../utils/currency-pair";
27
30
  import { logFailure } from "../utils/log-failure";
@@ -412,6 +415,109 @@ export interface BulkSymbolsOptions {
412
415
  symbols: readonly string[];
413
416
  exchange: string | undefined;
414
417
  store: TickerSource;
418
+ /** Whether a saved row is in the list added to: its venues are where a bare symbol that read as a future is looked for first. */
419
+ member?: (ticker: TickerRecord) => boolean;
420
+ /** How long the list's venues have to answer for such a symbol; `LOOKUP_TIMEOUT_MS` (5 s) unless set. */
421
+ venueWaitMs?: number;
422
+ }
423
+
424
+ /** A row that is a futures contract: a generic (ES3 on CME, the E-mini's third) or a dated or continuous one. */
425
+ function isFutureRow(ticker: TickerRecord): boolean {
426
+ return resolveTickerInstrumentKind(ticker) === "future" || !!futuresGenericListing(ticker.metadata.ticker, ticker.metadata.exchange);
427
+ }
428
+
429
+ /**
430
+ * The venues a list's listings trade on (its `members`, and the securities
431
+ * `added` beside), other than the US's: SGX and HKEX for a book of DBS and
432
+ * Tencent. Empty when the list holds a future, which makes a bare symbol's
433
+ * future a fair reading.
434
+ */
435
+ function listVenues(members: readonly TickerRecord[], added: readonly TickerRecord[] = []): string[] {
436
+ if (members.some(isFutureRow)) return [];
437
+ const venues = [...members, ...added.filter((ticker) => !isFutureRow(ticker))].flatMap((ticker) => {
438
+ const { exchange } = storedKeyListing(ticker.metadata.ticker, ticker.metadata.exchange);
439
+ const venue = canonicalExchange(exchange);
440
+ return venue && !isUsListingExchange(venue) && !UNVENUED.has(venue) && !isCurrencyPairListing(ticker.metadata.ticker, venue) ? [venue] : [];
441
+ });
442
+ return [...new Set(venues)];
443
+ }
444
+
445
+ /**
446
+ * A bare symbol a security could be listed as (ES3, D05), not a future's own
447
+ * spelling: never a continuous symbol (ES=F), a dated contract (ESZ6, CLZ26),
448
+ * a front generic (NQ1, ES1, how a future is typed) or a generic with a roll
449
+ * or an adjustment (CL2F5, ES3R).
450
+ */
451
+ function securityShaped(symbol: string): boolean {
452
+ if (!/^[A-Z0-9]{1,6}$/.test(symbol)) return false;
453
+ if (/^[A-Z0-9]{1,4}[FGHJKMNQUVXZ]\d{1,2}$/.test(symbol) && !/^\d+$/.test(symbol)) return false;
454
+ const generic = parseFuturesGeneric(symbol);
455
+ return !generic || (generic.position > 1 && generic.ticker === `${generic.prefix}${generic.position}`);
456
+ }
457
+
458
+ /** A lookup that did not answer (busy, timed out, at its request limit), which says nothing of whether the venue lists it. */
459
+ function unansweredLookup(error: unknown): boolean {
460
+ return isProviderBusy(error) || isTransientServiceFailure(error) || isSourceFailure(error) || isRateLimited(error);
461
+ }
462
+
463
+ /**
464
+ * A bare symbol that read as a future while the list's listings trade on a
465
+ * venue that lists the symbol as a security is that listing: ES3 in a book
466
+ * of DBS and OCBC on SGX is the Straits Times fund there, not the E-mini's
467
+ * third generic on CME. The list's venues are asked at once, under one
468
+ * deadline; one that is busy or does not answer in time makes the add ask
469
+ * which is meant (`ListingChoiceError`) rather than guess another asset class.
470
+ * Each venue's lookup is staged on its own and only the one kept is staged
471
+ * for the commit, so a lookup that finishes late saves nothing.
472
+ */
473
+ async function keepListVenue(
474
+ lookup: CliTickerResolution,
475
+ venues: readonly string[],
476
+ { exchange, staged, dataProvider, retry, waitMs = LOOKUP_TIMEOUT_MS }: {
477
+ exchange: string | undefined; staged: StagedTickerRepository; dataProvider: DataProvider; retry?: CliTickerOptions["retry"]; waitMs?: number;
478
+ },
479
+ ): Promise<CliTickerResolution> {
480
+ if (lookup.error || exchange || venues.length === 0) return lookup;
481
+ const typed = parsePublicTickerKey(symbolInputKey(lookup.input));
482
+ if (typed.exchange || !securityShaped(typed.symbol.toUpperCase()) || !isFutureRow(lookup.ticker)) return lookup;
483
+ const future = savedListingName(lookup.ticker);
484
+ // Dropped first, so the venue's listing is saved under its own symbol (ES3:SGX as ES3, not ES3:XSES); an add of
485
+ // the future after all saves it again.
486
+ staged.discard(lookup.ticker.metadata.ticker);
487
+ let timer: ReturnType<typeof setTimeout> | undefined;
488
+ const deadline = new Promise<"late">((resolve) => { timer = setTimeout(() => resolve("late"), waitMs); });
489
+ type Answer = { venue: string; key: string; layer: StagedTickerRepository; found: CliTicker | null; unanswered: boolean };
490
+ const answers = await Promise.all(venues.map(async (venue): Promise<Answer> => {
491
+ const key = `${typed.symbol}:${venue}`;
492
+ const layer = new StagedTickerRepository(staged);
493
+ const asked = resolveCliTicker(key, layer, dataProvider, undefined, { retry, changes: false }).then(
494
+ (found) => ({ venue, key, layer, found, unanswered: false }),
495
+ // Not listed there: the future stands. Busy or failed: the venue did not answer.
496
+ (error: unknown) => ({ venue, key, layer, found: null, unanswered: unansweredLookup(error) }),
497
+ );
498
+ const answer = await Promise.race([asked, deadline]);
499
+ return answer === "late" ? { venue, key, layer, found: null, unanswered: true } : answer;
500
+ })).finally(() => clearTimeout(timer));
501
+ const listed = answers.find((answer) => answer.found && !isFutureRow(answer.found.ticker));
502
+ if (listed?.found) {
503
+ // Only the listing kept is staged; the other venues' lookups, late ones included, are dropped.
504
+ await listed.layer.commit();
505
+ const note = `${typed.symbol} -> ${listed.venue}, the list's venue (not the ${future.exchange || "futures"} future)`;
506
+ return { input: lookup.input, ...listed.found, notes: [note, ...listed.found.notes] };
507
+ }
508
+ const unanswered = answers.filter((answer) => answer.unanswered).map((answer) => answer.key);
509
+ if (unanswered.length === 0) return lookup;
510
+ const choices = [...unanswered.map((key) => ({ key, name: null })), { key: future.key, name: future.name }];
511
+ return {
512
+ input: lookup.input,
513
+ error: new ListingChoiceError(
514
+ `${typed.symbol} may be ${unanswered.join(" or ")}, on the list's venue, which did not answer, or the ${future.exchange || "futures"} future ${future.key}; name the listing`,
515
+ choices.map((choice) => ` ${choice.key}${choice.name ? ` ${choice.name}` : ""}`).join("\n"),
516
+ choices,
517
+ choices.length,
518
+ null,
519
+ ),
520
+ };
415
521
  }
416
522
 
417
523
  type AddTicker = (ticker: TickerRecord) => { changed: boolean; ticker: TickerRecord };
@@ -493,6 +599,8 @@ export async function addSymbols({
493
599
  failure,
494
600
  suggest,
495
601
  dryRun = false,
602
+ member,
603
+ venueWaitMs,
496
604
  }: BulkSymbolsOptions & {
497
605
  dataProvider: DataProvider;
498
606
  /** Told when requests failed and the symbols that failed are about to be looked up again. */
@@ -516,7 +624,11 @@ export async function addSymbols({
516
624
  }): Promise<SymbolRow[]> {
517
625
  const staged = new StagedTickerRepository(store);
518
626
  const rejected = new Map(symbols.map((input) => [input, reject?.(input) ?? null] as const));
519
- const resolutions = await resolveTickersForCli(symbols.filter((input) => !rejected.get(input)), staged, dataProvider, exchange, { onRetry, onProgress, retry, askWhenAmbiguous });
627
+ const members = member ? (await store.loadAllTickers()).filter(member) : [];
628
+ const looked = await resolveTickersForCli(symbols.filter((input) => !rejected.get(input)), staged, dataProvider, exchange, { onRetry, onProgress, retry, askWhenAmbiguous });
629
+ // The list's venues, with those of the symbols added beside: a US, HKEX and SGX add keeps a bare ES3 on SGX.
630
+ const venues = listVenues(members, looked.flatMap((resolution) => resolution.error ? [] : [resolution.ticker]));
631
+ const resolutions = await Promise.all(looked.map((resolution) => keepListVenue(resolution, venues, { exchange, staged, dataProvider, retry, waitMs: venueWaitMs })));
520
632
  const resolved = new Map(resolutions.map((resolution) => [resolution.input, resolution] as const));
521
633
  const rows: SymbolRow[] = [];
522
634
  // Listings a symbol of this list was added to, which a later symbol's choice must not drop.
@@ -535,6 +647,24 @@ export async function addSymbols({
535
647
  return suggest ? withSuggestions(rows, staged, dataProvider) : rows;
536
648
  }
537
649
 
650
+ /**
651
+ * `resolveCliTicker` for a symbol a list takes outside an add (`portfolio
652
+ * position set`): a bare symbol that read as a future keeps the list's venue,
653
+ * or asks, as an add does (`keepListVenue`). Saves the listing it settles on.
654
+ */
655
+ export async function resolveListTicker(
656
+ symbol: string,
657
+ { store, dataProvider, exchange, member }: { store: TickerSource; dataProvider: DataProvider; exchange: string | undefined; member: BulkSymbolsOptions["member"] },
658
+ ): Promise<CliTicker> {
659
+ const staged = new StagedTickerRepository(store);
660
+ const looked: CliTickerResolution = { input: symbol, ...await resolveCliTicker(symbol, staged, dataProvider, exchange) };
661
+ const members = member ? (await store.loadAllTickers()).filter(member) : [];
662
+ const kept = await keepListVenue(looked, listVenues(members), { exchange, staged, dataProvider });
663
+ if (kept.error) throw kept.error;
664
+ await staged.commit();
665
+ return kept;
666
+ }
667
+
538
668
  /**
539
669
  * One symbol added as a symbol of a list is (`settleAdd`), for `watchlist add`
540
670
  * and `portfolio add` given one: a match a list would leave for a choice is
@@ -545,7 +675,7 @@ export async function addSymbols({
545
675
  */
546
676
  export async function addSymbol(
547
677
  input: string,
548
- { exchange, store, dataProvider, reject, retry, dryRun = false, add }: {
678
+ { exchange, store, dataProvider, reject, retry, dryRun = false, add, member }: {
549
679
  exchange: string | undefined;
550
680
  store: TickerSource;
551
681
  dataProvider: DataProvider;
@@ -553,6 +683,7 @@ export async function addSymbol(
553
683
  retry?: CliTickerOptions["retry"];
554
684
  dryRun?: boolean;
555
685
  add: AddTicker;
686
+ member?: BulkSymbolsOptions["member"];
556
687
  },
557
688
  ): Promise<AddOutcome & { lookup: CliTicker | null }> {
558
689
  const refusal = reject?.(input);
@@ -565,6 +696,7 @@ export async function addSymbol(
565
696
  } catch (caught) {
566
697
  lookup = { input, error: caught instanceof Error ? caught : new Error(String(caught)) };
567
698
  }
699
+ if (member) lookup = await keepListVenue(lookup, listVenues((await store.loadAllTickers()).filter(member)), { exchange, staged, dataProvider, retry });
568
700
  const outcome = await settleAdd(input, lookup, staged, dataProvider, add, new Set());
569
701
  if (!dryRun) await staged.commit();
570
702
  return { ...outcome, lookup: lookup.error ? null : lookup };