@gloom-sh/terminal 0.20.5 → 0.20.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/package.json +2 -1
- package/src/api-client/data.ts +10 -2
- package/src/api-client/fund-facts.ts +20 -4
- package/src/api-client/hk-tenders.ts +59 -0
- package/src/api-client/index.ts +1 -0
- package/src/api-client/socket.ts +4 -4
- package/src/api-client/types/econ.ts +20 -2
- package/src/app.tsx +18 -13
- package/src/architecture/floating-promise-allowlist.json +313 -0
- package/src/architecture/shortcut-labels-allowlist.json +1 -0
- package/src/cli/commands/market.ts +197 -57
- package/src/cli/commands/news-search.ts +22 -7
- package/src/cli/commands/overview.ts +12 -6
- package/src/cli/commands/search.ts +19 -3
- package/src/cli/commands/ticker.ts +3 -1
- package/src/cli/desktop-pane-shot.ts +61 -0
- package/src/cli/early-command.ts +2 -0
- package/src/cli/errors.ts +10 -1
- package/src/cli/fx-forward.ts +76 -12
- package/src/cli/fx-pair.ts +1 -1
- package/src/cli/fx-quote-rate.ts +23 -0
- package/src/cli/help.ts +1 -0
- package/src/cli/index-roots.ts +5 -4
- package/src/cli/index.ts +40 -3
- package/src/cli/known-gaps.ts +11 -8
- package/src/cli/listing-arg.ts +6 -4
- package/src/cli/options.ts +52 -3
- package/src/cli/output-file.ts +5 -3
- package/src/cli/pane-functions/catalog.ts +15 -0
- package/src/cli/pane-functions/dom.ts +4 -4
- package/src/cli/pane-functions/freshness.ts +38 -5
- package/src/cli/pane-functions/function-help.ts +4 -4
- package/src/cli/pane-functions/headless.ts +9 -4
- package/src/cli/pane-functions/index.ts +6 -4
- package/src/cli/pane-functions/resolver.ts +2 -2
- package/src/cli/pane-functions/screenshot-assessment.ts +16 -4
- package/src/cli/quote-answer.ts +57 -1
- package/src/cli/result.ts +38 -2
- package/src/cli/spreadsheet-hint.ts +7 -3
- package/src/cli/treasury-yields.ts +5 -3
- package/src/components/chart/composite/legend.tsx +40 -2
- package/src/components/command-bar/workflow/tickers.ts +2 -2
- package/src/components/data-table/view.tsx +9 -2
- package/src/components/ui/data-table/opentui/index.tsx +11 -4
- package/src/components/ui/data-table/opentui/model.ts +8 -6
- package/src/components/ui/data-table/types.ts +6 -1
- package/src/components/ui/table-layout.ts +38 -1
- package/src/docs/snapshot.json +58 -19
- package/src/i18n/es.ts +2 -0
- package/src/i18n/ja.ts +2 -0
- package/src/i18n/ko.ts +2 -0
- package/src/i18n/zh-cn.ts +2 -0
- package/src/i18n/zh-tw.ts +2 -0
- package/src/market-data/market/change-basis.ts +57 -12
- package/src/market-data/market/dated-previous-close.ts +184 -10
- package/src/market-data/market/freshness.ts +18 -6
- package/src/market-data/market/status.ts +9 -1
- package/src/market-data/published-nse-sessions.ts +16 -1
- package/src/market-data/quotes/contributions.ts +2 -0
- package/src/market-data/quotes/freshness.ts +15 -0
- package/src/market-data/quotes/listing-enterprise-value.ts +50 -0
- package/src/plugins/builtin/alerts/alert-engine.ts +15 -0
- package/src/plugins/builtin/alerts/cli.ts +22 -9
- package/src/plugins/builtin/alerts/headless.ts +1 -1
- package/src/plugins/builtin/alerts/index.tsx +5 -1
- package/src/plugins/builtin/alerts/metric-command.ts +1 -1
- package/src/plugins/builtin/alerts/metric-data.ts +15 -2
- package/src/plugins/builtin/backtest/headless.ts +1 -1
- package/src/plugins/builtin/cds/model.ts +0 -6
- package/src/plugins/builtin/chart-composer/formula.ts +16 -3
- package/src/plugins/builtin/chart-composer/headless-schema.ts +2 -0
- package/src/plugins/builtin/chart-composer/headless.ts +2 -1
- package/src/plugins/builtin/chart-composer/presets.ts +1 -0
- package/src/plugins/builtin/cloud/askg/pane.tsx +55 -13
- package/src/plugins/builtin/credit-boards/cdx-pane.tsx +20 -7
- package/src/plugins/builtin/credit-boards/client.ts +8 -0
- package/src/plugins/builtin/credit-boards/headless.ts +4 -1
- package/src/plugins/builtin/credit-boards/model.ts +58 -4
- package/src/plugins/builtin/credit-boards/series.ts +63 -6
- package/src/plugins/builtin/credit-boards/sovr-pane.tsx +3 -2
- package/src/plugins/builtin/credit-conditions/headless.ts +24 -6
- package/src/plugins/builtin/credit-conditions/index.tsx +1 -1
- package/src/plugins/builtin/credit-conditions/model.ts +12 -6
- package/src/plugins/builtin/credit-conditions/series.ts +2 -1
- package/src/plugins/builtin/econ/calendar-model.ts +41 -7
- package/src/plugins/builtin/econ/calendar-source.ts +7 -1
- package/src/plugins/builtin/econ/index.tsx +41 -8
- package/src/plugins/builtin/econ/types.ts +3 -0
- package/src/plugins/builtin/fixed-income/index.tsx +2 -0
- package/src/plugins/builtin/fx-matrix/index.tsx +44 -14
- package/src/plugins/builtin/help/keybindings-editor.tsx +6 -2
- package/src/plugins/builtin/holders/fund-holders.ts +22 -1
- package/src/plugins/builtin/holders/headless.ts +5 -4
- package/src/plugins/builtin/holders/pane.tsx +7 -3
- package/src/plugins/builtin/holders/report-header.ts +23 -0
- package/src/plugins/builtin/members/client.ts +1 -1
- package/src/plugins/builtin/members/headless.ts +2 -0
- package/src/plugins/builtin/members/model.ts +10 -8
- package/src/plugins/builtin/members/pane.tsx +4 -1
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +5 -2
- package/src/plugins/builtin/portfolio-list/cli/render.ts +86 -26
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +5 -1
- package/src/plugins/builtin/portfolio-list/headless.ts +2 -1
- package/src/plugins/builtin/portfolio-list/income.ts +46 -22
- package/src/plugins/builtin/portfolio-list/pane/data.ts +16 -6
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +5 -4
- package/src/plugins/builtin/portfolio-list/use-throttled-ticker-order.ts +40 -3
- package/src/plugins/builtin/research/headless-schema.ts +4 -3
- package/src/plugins/builtin/research/relative-valuation-columns.ts +145 -47
- package/src/plugins/builtin/research/relative-valuation-currency.ts +31 -0
- package/src/plugins/builtin/research/relative-valuation-headless.ts +25 -8
- package/src/plugins/builtin/research/relative-valuation-model.ts +40 -9
- package/src/plugins/builtin/research/relative-valuation-pane.tsx +3 -2
- package/src/plugins/builtin/research/relative-valuation-peers.ts +2 -2
- package/src/plugins/builtin/sec/fund-facts.ts +25 -5
- package/src/plugins/builtin/shared/report-freshness.ts +15 -6
- package/src/plugins/builtin/supply-chain/model.ts +18 -6
- package/src/plugins/builtin/thirteenf/api.ts +47 -4
- package/src/plugins/builtin/ticker-detail/data-panes/historical-prices.tsx +8 -7
- package/src/plugins/builtin/ticker-detail/data-panes/history-bars.ts +8 -5
- package/src/plugins/builtin/ticker-detail/financials/model.ts +6 -2
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +1 -1
- package/src/plugins/builtin/ticker-detail/headless.ts +6 -4
- package/src/plugins/builtin/treasury-auctions/cache.ts +36 -2
- package/src/plugins/builtin/treasury-auctions/headless.ts +42 -4
- package/src/plugins/builtin/treasury-auctions/hk-headless.ts +126 -0
- package/src/plugins/builtin/treasury-auctions/hk-view.tsx +347 -0
- package/src/plugins/builtin/treasury-auctions/hk.ts +363 -0
- package/src/plugins/builtin/treasury-auctions/index.tsx +14 -1
- package/src/plugins/builtin/treasury-auctions/model.ts +16 -8
- package/src/plugins/builtin/treasury-auctions/pane.tsx +45 -21
- package/src/portfolio/collection-name.ts +22 -0
- package/src/portfolio/column-values.ts +3 -0
- package/src/portfolio/valuation-basis.ts +23 -1
- package/src/renderers/dom/data-table/frozen-column.ts +3 -1
- package/src/renderers/dom/data-table/index.tsx +27 -9
- package/src/renderers/dom/data-table/row.tsx +2 -0
- package/src/renderers/electrobun/bun/desktop/backend.ts +27 -24
- package/src/renderers/electrobun/bun/desktop/detached-windows.ts +3 -3
- package/src/renderers/electrobun/bun/desktop/snapshot-commit.ts +77 -0
- package/src/renderers/electrobun/shared/protocol.ts +4 -0
- package/src/renderers/electrobun/view/backend-rpc.ts +3 -0
- package/src/renderers/electrobun/view/desktop/window/bridge.ts +3 -0
- package/src/sources/gloomberb-cloud/normalizers.ts +9 -5
- package/src/sources/provider-router/cache.ts +3 -1
- package/src/state/hooks/quote-streaming.ts +14 -6
- package/src/sync/controller.ts +17 -2
- package/src/sync/other-window-tabs.ts +32 -1
- package/src/sync/react.ts +4 -4
- package/src/tickers/instrument-kind.ts +22 -1
- package/src/tickers/search/index.ts +5 -0
- package/src/tickers/terminal-codes.ts +17 -5
- package/src/time-series/bar-spacing.ts +33 -0
- package/src/time-series/base-series.ts +21 -3
- package/src/time-series/chart-bounds.ts +31 -0
- package/src/time-series/field-catalog.ts +17 -0
- package/src/time-series/fundamentals/current-valuation.ts +244 -0
- package/src/time-series/fundamentals/historical-valuation.ts +99 -0
- package/src/time-series/fundamentals/metric-ids.ts +61 -0
- package/src/time-series/fundamentals/period-points.ts +104 -0
- package/src/time-series/fundamentals/quarterly-ttm.ts +220 -0
- package/src/time-series/fundamentals/series.ts +164 -0
- package/src/time-series/fundamentals/source-statements.ts +177 -0
- package/src/time-series/fundamentals/statement-fields.ts +154 -0
- package/src/time-series/fundamentals/statement-merge.ts +124 -0
- package/src/time-series/fundamentals/statement.ts +114 -0
- package/src/time-series/fundamentals/valuation-multiples.ts +50 -0
- package/src/time-series/fundamentals.ts +18 -1275
- package/src/time-series/ice-credit.ts +32 -6
- package/src/time-series/resolve.ts +9 -5
- package/src/time-series/session-bar.ts +78 -9
- package/src/time-series/studies/formula.ts +53 -10
- package/src/time-series/studies/pair.ts +18 -7
- package/src/time-series/studies/units.ts +49 -2
- package/src/time-series/types.ts +12 -0
- package/src/types/desktop-window.ts +2 -0
- package/src/types/financials.ts +15 -0
- package/src/types/headless.ts +8 -0
- package/src/utils/cli-output.ts +6 -3
- package/src/utils/debug-log.ts +29 -0
- package/src/utils/ebitda.ts +128 -0
- package/src/utils/format.ts +1 -1
- package/src/utils/shell-word.ts +13 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import { apiClient } from "../../../api-client";
|
|
2
|
+
import { ApiRequestError } from "../../../api-client/errors";
|
|
3
|
+
import type { HkTender, HkTendersPayload } from "../../../api-client/hk-tenders";
|
|
4
|
+
import type { DataTableColumn } from "../../../components";
|
|
5
|
+
import { dropColumnsToFit } from "../../../components/ui/table-layout";
|
|
6
|
+
import { createPluginCache, savedCopyForTransientFailure } from "../../../data/plugin-cache";
|
|
7
|
+
import { servedFromSavedCopy } from "../../../data/saved-copies";
|
|
8
|
+
import type { PluginPersistence } from "../../../types/plugin";
|
|
9
|
+
import { formatShortDate } from "../../../utils/datetime-format";
|
|
10
|
+
import { displayWidth, formatCompact } from "../../../utils/format";
|
|
11
|
+
import { compareSortValues, type SortDirection } from "../../../utils/sort-values";
|
|
12
|
+
import { AUCTION_HISTORY_ALL, type AuctionHistoryWindow } from "./client";
|
|
13
|
+
import type { AuctionFilter } from "./model";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Hong Kong government paper tenders in AUCT: Exchange Fund Bills and Notes
|
|
17
|
+
* and HKSAR institutional Government Bonds, from the Hong Kong Monetary
|
|
18
|
+
* Authority's Open API (its Monthly Statistical Bulletin's tender figures),
|
|
19
|
+
* served by Gloom Cloud (`/cloud/econ/hk-tenders`) and credited "Source: HKMA".
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
export type AuctionMarket = "us" | "hk";
|
|
23
|
+
|
|
24
|
+
export const AUCTION_MARKETS: ReadonlyArray<{ value: AuctionMarket; label: string }> = [
|
|
25
|
+
{ value: "us", label: "US" },
|
|
26
|
+
{ value: "hk", label: "HK" },
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
export const isAuctionMarket = (value: unknown): value is AuctionMarket => value === "us" || value === "hk";
|
|
30
|
+
|
|
31
|
+
/** Words that only pick the market: `AUCT HK 10Y` searches Hong Kong's paper for 10Y. */
|
|
32
|
+
const HK_MARKET_WORDS = /\b(hong\s*kong|hk|hkma|hksar)\b/gi;
|
|
33
|
+
/** Paper only Hong Kong issues: it picks the market and stays the search. */
|
|
34
|
+
const HK_PAPER_WORDS = /\b(efbs?|efns?|exchange\s+fund|hkgbs?|hkd|honia|rmb|cnh)\b/i;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The market a search names, and the search left once the words that only
|
|
38
|
+
* name the market are taken out: `HK 10Y` is Hong Kong's 10-year, `EFB` its
|
|
39
|
+
* bills. Null when it names none, so the market chosen stands.
|
|
40
|
+
*/
|
|
41
|
+
export function auctionSearchMarket(query: string): { market: AuctionMarket | null; search: string } {
|
|
42
|
+
const named = HK_MARKET_WORDS.test(query);
|
|
43
|
+
HK_MARKET_WORDS.lastIndex = 0;
|
|
44
|
+
const search = named ? query.replace(HK_MARKET_WORDS, " ").replace(/\s+/g, " ").trim() : query.trim();
|
|
45
|
+
return { market: named || HK_PAPER_WORDS.test(query) ? "hk" : null, search };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The table's short name for each kind of paper, and the detail's long one. */
|
|
49
|
+
const PAPER_TYPES: Record<HkTender["paper"], { type: string; name: string; filter: Exclude<AuctionFilter, "all"> }> = {
|
|
50
|
+
efb: { type: "EFB", name: "Exchange Fund Bills", filter: "bill" },
|
|
51
|
+
efn: { type: "EFN", name: "Exchange Fund Notes", filter: "note" },
|
|
52
|
+
hkgb: { type: "HKGB", name: "Government Bond", filter: "bond" },
|
|
53
|
+
"hkgb-frn": { type: "FRN", name: "Government floating rate note", filter: "bond" },
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const hkTenderType = (tender: HkTender) => PAPER_TYPES[tender.paper]?.type ?? tender.paper.toUpperCase();
|
|
57
|
+
export const hkTenderName = (tender: HkTender) => `${PAPER_TYPES[tender.paper]?.name ?? tender.paper}${tender.currency === "CNH" ? " (RMB)" : ""}`;
|
|
58
|
+
/** A tender's row id: its issue day, paper, currency and issue (an EF tender's tenor, HKMA naming no EF issue). */
|
|
59
|
+
export const hkTenderId = (tender: HkTender) => `${tender.date}|${tender.paper}|${tender.currency}|${tender.issue ?? tender.term}`;
|
|
60
|
+
|
|
61
|
+
/** HKMA's page documenting the dataset a tender came from, which `o` opens. */
|
|
62
|
+
const DATASET_PAGES: ReadonlyArray<[RegExp, string]> = [
|
|
63
|
+
[/^efb-/, "efbn/efbn-tender-results-efb"],
|
|
64
|
+
[/^efn-/, "efbn/efbn-tender-results-efn"],
|
|
65
|
+
[/^ibip-/, "gov-bond/tender-results-gov-bonds-ibip"],
|
|
66
|
+
[/^hkgb-hkd$/, "ibpgsbp/tender-results-gov-bonds-ibpgsbp-hkd"],
|
|
67
|
+
[/^hkgb-rmb$/, "ibpgsbp/tender-results-gov-bonds-ibpgsbp-rmb"],
|
|
68
|
+
];
|
|
69
|
+
export function hkDatasetPage(tender: HkTender): string | undefined {
|
|
70
|
+
const path = DATASET_PAGES.find(([pattern]) => pattern.test(tender.dataset))?.[1];
|
|
71
|
+
return path ? `https://apidocs.hkma.gov.hk/documentation/market-data-and-statistics/monthly-statistical-bulletin/${path}/` : undefined;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const monthName = new Intl.DateTimeFormat("en-US", { month: "short", year: "numeric", timeZone: "UTC" });
|
|
75
|
+
/** "Oct 28, 2026", or "May 2026" for a bond's issue month. */
|
|
76
|
+
export const hkDateText = (date: string) => date.length === 7
|
|
77
|
+
? Number.isFinite(Date.parse(`${date}-01T00:00:00Z`)) ? monthName.format(new Date(`${date}-01T00:00:00Z`)) : date
|
|
78
|
+
: formatShortDate(date, { utc: true, fallback: date });
|
|
79
|
+
|
|
80
|
+
/** What the search box understands in Hong Kong's tenders. */
|
|
81
|
+
export const HK_SEARCH_FIELDS = "paper (EFB, HKGB), tenor (3M, 10Y), issue, HKD or RMB, or date (YYYY-MM-DD)";
|
|
82
|
+
|
|
83
|
+
const paperWords = (words: readonly string[], papers: readonly HkTender["paper"][]) =>
|
|
84
|
+
words.map((word): [string, ReadonlySet<HkTender["paper"]>] => [word, new Set(papers)]);
|
|
85
|
+
const PAPER_WORDS: ReadonlyMap<string, ReadonlySet<HkTender["paper"]>> = new Map([
|
|
86
|
+
...paperWords(["bill", "bills", "efb", "efbs"], ["efb"]),
|
|
87
|
+
...paperWords(["note", "notes", "efn", "efns"], ["efn"]),
|
|
88
|
+
...paperWords(["bond", "bonds", "hkgb", "hkgbs", "government"], ["hkgb", "hkgb-frn"]),
|
|
89
|
+
...paperWords(["frn", "frns", "floating", "honia"], ["hkgb-frn"]),
|
|
90
|
+
]);
|
|
91
|
+
const CURRENCY_WORDS: ReadonlyMap<string, HkTender["currency"]> = new Map([["hkd", "HKD"], ["rmb", "CNH"], ["cnh", "CNH"], ["cny", "CNH"]]);
|
|
92
|
+
const TENOR = /^(\d{1,2}) ?-? ?(y|yr|yrs|years?|m|mo|mos|months?)$/;
|
|
93
|
+
|
|
94
|
+
/** A term's length in months: 3-Month is 3, 10-Year 120. */
|
|
95
|
+
const termMonths = (term: string) => {
|
|
96
|
+
const own = /^(\d+)-(Month|Year)$/.exec(term);
|
|
97
|
+
return own ? Number(own[1]) * (own[2] === "Year" ? 12 : 1) : null;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/** "3M" is the 3-Month bill; "1Y" the 12-Month bill as well as a 1-Year note. */
|
|
101
|
+
function matchesTenor(tender: HkTender, word: string): boolean | null {
|
|
102
|
+
const tenor = TENOR.exec(word);
|
|
103
|
+
if (!tenor) return null;
|
|
104
|
+
const count = Number(tenor[1]);
|
|
105
|
+
return termMonths(tender.term) === (tenor[2]![0] === "y" ? count * 12 : count);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function matchesWord(tender: HkTender, word: string): boolean {
|
|
109
|
+
const paper = PAPER_WORDS.get(word);
|
|
110
|
+
if (paper) return paper.has(tender.paper);
|
|
111
|
+
if (word === "exchange" || word === "fund") return tender.paper === "efb" || tender.paper === "efn";
|
|
112
|
+
const currency = CURRENCY_WORDS.get(word);
|
|
113
|
+
if (currency) return tender.currency === currency;
|
|
114
|
+
const tenor = matchesTenor(tender, word);
|
|
115
|
+
if (tenor != null) return tenor;
|
|
116
|
+
return tender.date.startsWith(word) || !!tender.issue?.toLowerCase().includes(word) || tender.term.toLowerCase().includes(word);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Every word of the search names the tender (`10Y RMB`, `EFB 2026-10`); words that only pick the market are left out. */
|
|
120
|
+
function matchesHkSearch(tender: HkTender, query: string): boolean {
|
|
121
|
+
const words = auctionSearchMarket(query).search.toLowerCase().split(/\s+/).filter(Boolean);
|
|
122
|
+
return words.every((word) => matchesWord(tender, word));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** A floating rate note's spread over HONIA, in bp, stands where another's yield does. */
|
|
126
|
+
const spreadBp = (value: number | null) => value == null ? null : Math.round(value * 1000) / 10;
|
|
127
|
+
|
|
128
|
+
/** The average accepted yield, or a floating rate note's spread in bp. */
|
|
129
|
+
export const hkRate = (tender: HkTender) => tender.averageYield ?? spreadBp(tender.spread);
|
|
130
|
+
export const isSpread = (tender: HkTender) => tender.averageYield == null && tender.spread != null;
|
|
131
|
+
|
|
132
|
+
/** `2.827%`, or `20.0bp` for a floating rate note's spread, as a US FRN's reads. */
|
|
133
|
+
export function formatHkRate(tender: HkTender, value: number | null, empty: string): string {
|
|
134
|
+
if (value == null) return empty;
|
|
135
|
+
return isSpread(tender) ? `${value.toFixed(1)}bp` : `${value.toFixed(3)}%`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** The size: a bond's amount allotted, EF paper's amount offered as worked out from its applications. */
|
|
139
|
+
export const hkSize = (tender: HkTender) => tender.allotted ?? tender.offered;
|
|
140
|
+
/** EF paper's size is worked out, so the table marks it about (≈). */
|
|
141
|
+
export const hkSizeWorkedOut = (tender: HkTender) => tender.allotted == null && tender.offered != null;
|
|
142
|
+
|
|
143
|
+
/** The amount in its currency: HK$66.3B, RMB750M; `≈HK$65.7B` for EF paper's worked-out size. */
|
|
144
|
+
export function formatHkAmount(tender: HkTender, value: number | null, empty = "—", about = false): string {
|
|
145
|
+
if (value == null) return empty;
|
|
146
|
+
return `${about ? "≈" : ""}${tender.currency === "CNH" ? "RMB" : "HK$"}${formatCompact(value)}`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export type HkColumnId = "date" | "type" | "term" | "rate" | "btc" | "size" | "cusip";
|
|
150
|
+
|
|
151
|
+
export interface HkColumn extends DataTableColumn {
|
|
152
|
+
id: HkColumnId;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export interface HkSortPreference {
|
|
156
|
+
columnId: HkColumnId;
|
|
157
|
+
direction: SortDirection;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export const DEFAULT_HK_SORT: HkSortPreference = { columnId: "date", direction: "desc" };
|
|
161
|
+
|
|
162
|
+
/** The order [ and ] step through the columns. */
|
|
163
|
+
export const HK_SORT_COLUMN_IDS: readonly HkColumnId[] = ["date", "type", "term", "rate", "btc", "size", "cusip"];
|
|
164
|
+
|
|
165
|
+
/** `--sort` and the pane's kept sort, by name: the US names that mean the same here. */
|
|
166
|
+
const HK_SORT_NAMES: ReadonlyArray<{ names: readonly string[]; column: HkColumnId }> = [
|
|
167
|
+
{ names: ["date"], column: "date" },
|
|
168
|
+
{ names: ["type"], column: "type" },
|
|
169
|
+
{ names: ["term"], column: "term" },
|
|
170
|
+
{ names: ["rate", "yield", "average", "avg"], column: "rate" },
|
|
171
|
+
{ names: ["btc", "b/c", "bid-to-cover", "bc"], column: "btc" },
|
|
172
|
+
{ names: ["size"], column: "size" },
|
|
173
|
+
{ names: ["cusip", "issue"], column: "cusip" },
|
|
174
|
+
];
|
|
175
|
+
|
|
176
|
+
/** The column a sort name means for Hong Kong's tenders; null for a US-only one (`indirect`, `btc-pctl`). */
|
|
177
|
+
export function hkSortColumn(name: string): HkColumnId | null {
|
|
178
|
+
const value = name.trim().toLowerCase();
|
|
179
|
+
return HK_SORT_NAMES.find((entry) => entry.names.includes(value))?.column ?? null;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export const hkSortName = (column: HkColumnId) => HK_SORT_NAMES.find((entry) => entry.column === column)!.names[0]!;
|
|
183
|
+
|
|
184
|
+
/** Text columns read best A to Z; every figure highest first. */
|
|
185
|
+
export const firstHkSortDirection = (column: HkColumnId): SortDirection =>
|
|
186
|
+
column === "type" || column === "term" || column === "cusip" ? "asc" : "desc";
|
|
187
|
+
|
|
188
|
+
/** A month (a Government Bond's issue) sorts after the days of that month. */
|
|
189
|
+
const sortDay = (date: string) => date.length === 7 ? `${date}-00` : date;
|
|
190
|
+
|
|
191
|
+
function hkSortValue(tender: HkTender, column: HkColumnId): number | string | null {
|
|
192
|
+
switch (column) {
|
|
193
|
+
case "date": return sortDay(tender.date);
|
|
194
|
+
case "type": return hkTenderType(tender);
|
|
195
|
+
case "term": return termMonths(tender.term);
|
|
196
|
+
case "rate": return hkRate(tender);
|
|
197
|
+
case "btc": return tender.bidToCover;
|
|
198
|
+
case "size": return hkSize(tender);
|
|
199
|
+
case "cusip": return tender.issue;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Figures that do not compare are ranked apart, in either direction: yields
|
|
205
|
+
* before floating rate notes' spreads, HK$ sizes before RMB ones.
|
|
206
|
+
*/
|
|
207
|
+
function hkSortGroup(tender: HkTender, column: HkColumnId): number {
|
|
208
|
+
if (column === "rate") return isSpread(tender) ? 1 : 0;
|
|
209
|
+
if (column === "size") return tender.currency === "CNH" ? 1 : 0;
|
|
210
|
+
return 0;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** Hong Kong's day, which a window counts back from: its tenders are dated in Hong Kong. */
|
|
214
|
+
const hongKongDay = new Intl.DateTimeFormat("en-CA", { timeZone: "Asia/Hong_Kong", year: "numeric", month: "2-digit", day: "2-digit" });
|
|
215
|
+
|
|
216
|
+
/** The first day a window lists, counted back from today in Hong Kong: null for ALL. */
|
|
217
|
+
export function hkWindowStart(window: AuctionHistoryWindow, now = Date.now()): string | null {
|
|
218
|
+
if (window === AUCTION_HISTORY_ALL) return null;
|
|
219
|
+
const today = Date.parse(`${hongKongDay.format(now)}T00:00:00Z`);
|
|
220
|
+
return new Date(today - window * 86_400_000).toISOString().slice(0, 10);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** A month row (a Government Bond's issue) is in a window that starts within or before its month. */
|
|
224
|
+
export const hkOnOrAfter = (date: string, from: string) => date.length === 7 ? date >= from.slice(0, 7) : date >= from;
|
|
225
|
+
|
|
226
|
+
/** The tenders a group, a search and a window keep, in the sort's order; ties keep the newest first. */
|
|
227
|
+
export function visibleHkTenders(
|
|
228
|
+
tenders: readonly HkTender[],
|
|
229
|
+
options: { filter: AuctionFilter; query: string; sort: HkSortPreference; from?: string | null },
|
|
230
|
+
): HkTender[] {
|
|
231
|
+
const { columnId, direction } = options.sort;
|
|
232
|
+
return tenders
|
|
233
|
+
.filter((tender) => (options.filter === "all" || PAPER_TYPES[tender.paper]?.filter === options.filter)
|
|
234
|
+
&& (!options.from || hkOnOrAfter(tender.date, options.from)) && matchesHkSearch(tender, options.query))
|
|
235
|
+
.sort((left, right) => hkSortGroup(left, columnId) - hkSortGroup(right, columnId)
|
|
236
|
+
|| compareSortValues(hkSortValue(left, columnId), hkSortValue(right, columnId), direction)
|
|
237
|
+
|| sortDay(right.date).localeCompare(sortDay(left.date)) || hkTenderId(left).localeCompare(hkTenderId(right)));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** The pane's columns, as wide as what they list; the issue closes the row where the pane has room for it. */
|
|
241
|
+
export function buildHkColumns(options: { showYear?: boolean; rows?: readonly HkTender[]; width?: number } = {}): HkColumn[] {
|
|
242
|
+
const { showYear = false, rows = [], width } = options;
|
|
243
|
+
const widest = (least: number, text: (tender: HkTender) => string) => Math.max(least, ...rows.map((tender) => displayWidth(text(tender))));
|
|
244
|
+
const columns: HkColumn[] = [
|
|
245
|
+
{ id: "date", label: "DATE", width: showYear ? 10 : 6, align: "left", title: "Issue day (a Government Bond's issue month): the business day after the tender" },
|
|
246
|
+
{ id: "type", label: "TYPE", width: 6, align: "left" },
|
|
247
|
+
{ id: "term", label: "TERM", width: widest(7, (tender) => tender.term), align: "left" },
|
|
248
|
+
{ id: "rate", label: "RATE", width: widest(6, (tender) => formatHkRate(tender, hkRate(tender), "—")), align: "right",
|
|
249
|
+
title: "Average accepted yield; a floating rate note's spread over HONIA, bp" },
|
|
250
|
+
{ id: "btc", label: "B/C", width: 5, align: "right" },
|
|
251
|
+
{ id: "size", label: "SIZE", width: widest(7, (tender) => formatHkAmount(tender, hkSize(tender), "—", hkSizeWorkedOut(tender))), align: "right",
|
|
252
|
+
title: "A bond's amount allotted; EF paper's amount offered, worked out from its applications (≈)" },
|
|
253
|
+
{ id: "cusip", label: "ISSUE", width: widest(5, (tender) => tender.issue ?? ""), align: "left", flexGrow: 1 },
|
|
254
|
+
];
|
|
255
|
+
if (width == null) return columns;
|
|
256
|
+
const shown = dropColumnsToFit(columns, width, ["cusip"]);
|
|
257
|
+
return shown.length === columns.length ? shown : shown.map((column) => ({ ...column, flexGrow: undefined }));
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const DATE = /^\d{4}-\d{2}(-\d{2})?$/;
|
|
261
|
+
const isNumber = (value: unknown) => typeof value === "number" && Number.isFinite(value);
|
|
262
|
+
const isNumberOrNull = (value: unknown) => value === null || isNumber(value);
|
|
263
|
+
|
|
264
|
+
/** A tender as this app reads it: one without its date, paper, term or figures as numbers is no tender. */
|
|
265
|
+
function readsAsTender(tender: HkTender): boolean {
|
|
266
|
+
return !!tender && typeof tender.date === "string" && DATE.test(tender.date) && tender.paper in PAPER_TYPES
|
|
267
|
+
&& (tender.issue === null || typeof tender.issue === "string") && (tender.currency === "HKD" || tender.currency === "CNH")
|
|
268
|
+
&& typeof tender.term === "string" && typeof tender.dataset === "string" && isNumber(tender.applied) && isNumber(tender.bidToCover)
|
|
269
|
+
&& [tender.allotted, tender.offered, tender.averageYield, tender.spread, tender.coupon].every(isNumberOrNull);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** What the HK market lists, and how far HKMA's figures run. */
|
|
273
|
+
export interface HkTendersBoard {
|
|
274
|
+
tenders: HkTender[];
|
|
275
|
+
/** The first issue Gloom Cloud's record holds: a wider window adds rows only past it. */
|
|
276
|
+
firstTender: string | null;
|
|
277
|
+
runsTo: HkTendersPayload["runsTo"];
|
|
278
|
+
/** The server held more tenders in the window than it sent. */
|
|
279
|
+
truncated: boolean;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** HKMA's tender figures not served yet: no route (404), an empty record (503), or an answer that says nothing. */
|
|
283
|
+
const HK_NOT_AVAILABLE = "Hong Kong tender results are not available yet";
|
|
284
|
+
|
|
285
|
+
/** The reply's board, or an error: a reply that is not the record is no board, never an empty one. */
|
|
286
|
+
function readHkBoard(payload: HkTendersPayload): HkTendersBoard {
|
|
287
|
+
if (!payload || payload.status !== "available" || !Array.isArray(payload.tenders)) throw new Error(HK_NOT_AVAILABLE);
|
|
288
|
+
return {
|
|
289
|
+
tenders: payload.tenders.filter(readsAsTender),
|
|
290
|
+
firstTender: typeof payload.firstTender === "string" ? payload.firstTender : null,
|
|
291
|
+
runsTo: {
|
|
292
|
+
efb: payload.runsTo?.efb ?? null,
|
|
293
|
+
efn: payload.runsTo?.efn ?? null,
|
|
294
|
+
hkgb: payload.runsTo?.hkgb ?? null,
|
|
295
|
+
},
|
|
296
|
+
truncated: payload.truncated === true,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** A failure that only says the figures are not there yet reads as that. */
|
|
301
|
+
function notAvailableYet(error: unknown): unknown {
|
|
302
|
+
const status = error instanceof ApiRequestError ? error.status : undefined;
|
|
303
|
+
const message = error instanceof Error ? error.message.trim() : "";
|
|
304
|
+
return status === 404 || status === 503 || !message ? new Error(HK_NOT_AVAILABLE) : error;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export interface HkTendersResult extends HkTendersBoard {
|
|
308
|
+
fetchedAt: number;
|
|
309
|
+
stale: boolean;
|
|
310
|
+
savedAt?: number;
|
|
311
|
+
refreshError?: string;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** HKMA adds its tender figures a month at a time; the server reads each dataset about twice a day. */
|
|
315
|
+
const HK_CACHE_POLICY = { staleMs: 60 * 60 * 1000, expireMs: 7 * 24 * 60 * 60 * 1000 } as const;
|
|
316
|
+
const hkCache = createPluginCache<HkTendersBoard>({
|
|
317
|
+
kind: "treasury-auctions",
|
|
318
|
+
source: "hk-tenders",
|
|
319
|
+
schemaVersion: 2,
|
|
320
|
+
policy: HK_CACHE_POLICY,
|
|
321
|
+
decode: (board) => {
|
|
322
|
+
if (!board || !Array.isArray(board.tenders)) throw new Error("Invalid cached tenders");
|
|
323
|
+
return board;
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
export function attachHkTendersPersistence(persistence: PluginPersistence): void {
|
|
328
|
+
hkCache.attach(persistence);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export function resetHkTendersPersistence(): void {
|
|
332
|
+
hkCache.reset();
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** Every tender on record: HKMA's figures start in the 1990s. */
|
|
336
|
+
const HK_RECORD_START = "1990-01-01";
|
|
337
|
+
/** As many as the server sends: a window never comes back cut. */
|
|
338
|
+
const HK_LIMIT = 10_000;
|
|
339
|
+
|
|
340
|
+
type HkTendersLoader = (from: string, limit: number) => Promise<HkTendersPayload>;
|
|
341
|
+
|
|
342
|
+
/** A window's tenders from Gloom Cloud, cached an hour; a saved copy answers a failure asking again may get past. */
|
|
343
|
+
export async function loadHkTenders(
|
|
344
|
+
force = false,
|
|
345
|
+
window: AuctionHistoryWindow,
|
|
346
|
+
loader: HkTendersLoader = (from, limit) => apiClient.getCloudHkTenders(from, limit),
|
|
347
|
+
): Promise<HkTendersResult> {
|
|
348
|
+
const from = hkWindowStart(window) ?? HK_RECORD_START;
|
|
349
|
+
const read = savedCopyForTransientFailure(await hkCache.load(`hk:${window}`, async () => {
|
|
350
|
+
try {
|
|
351
|
+
return readHkBoard(await loader(from, HK_LIMIT));
|
|
352
|
+
} catch (error) {
|
|
353
|
+
throw notAvailableYet(error);
|
|
354
|
+
}
|
|
355
|
+
}, { force }));
|
|
356
|
+
const result: HkTendersResult = {
|
|
357
|
+
...read.data,
|
|
358
|
+
fetchedAt: read.fetchedAt,
|
|
359
|
+
stale: read.stale,
|
|
360
|
+
...(read.refreshError ? { refreshError: read.refreshError } : {}),
|
|
361
|
+
};
|
|
362
|
+
return read.source === "stale-fallback" ? servedFromSavedCopy({ ...result, savedAt: read.fetchedAt }, read.fetchedAt) : result;
|
|
363
|
+
}
|
|
@@ -11,6 +11,7 @@ import { AUCTION_HISTORY_WINDOWS, auctionCommandRequest, auctionHistoryLabel } f
|
|
|
11
11
|
import { AUCTION_HISTORY_DAYS } from "./client";
|
|
12
12
|
import { createPublicPaneShare } from "../shared/public-pane";
|
|
13
13
|
import { treasuryAuctionsHeadless } from "./headless";
|
|
14
|
+
import { attachHkTendersPersistence, resetHkTendersPersistence } from "./hk";
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
let disposeConnections: Array<() => void> = [];
|
|
@@ -34,6 +35,7 @@ export function treasuryAuctionsSettings(): PaneSettingsDef {
|
|
|
34
35
|
export const treasuryAuctionsModule: PluginModule = {
|
|
35
36
|
setup(ctx) {
|
|
36
37
|
attachTreasuryAuctionsPersistence(ctx.persistence, ctx.connectionHealth);
|
|
38
|
+
attachHkTendersPersistence(ctx.persistence);
|
|
37
39
|
disposeConnections = [
|
|
38
40
|
ctx.connectionHealth.registerSource({
|
|
39
41
|
id: TREASURY_FISCAL_DATA_CONNECTION_ID,
|
|
@@ -58,6 +60,7 @@ export const treasuryAuctionsModule: PluginModule = {
|
|
|
58
60
|
for (const dispose of disposeConnections) dispose();
|
|
59
61
|
disposeConnections = [];
|
|
60
62
|
resetTreasuryAuctionsPersistence();
|
|
63
|
+
resetHkTendersPersistence();
|
|
61
64
|
},
|
|
62
65
|
|
|
63
66
|
paneTemplates: [
|
|
@@ -67,7 +70,7 @@ export const treasuryAuctionsModule: PluginModule = {
|
|
|
67
70
|
paneId: "treasury-auctions",
|
|
68
71
|
label: "Treasury Auctions",
|
|
69
72
|
description:
|
|
70
|
-
"Bill, note, bond and TIPS auction results since 1979, from Treasury Fiscal Data and TreasuryDirect: rate, stop-out versus median, bid-to-cover, bidder takedown and size; an after view ranks each auction against its tenor and shows the yield's moves after it. Search by benchmark (10Y) or CUSIP.",
|
|
73
|
+
"Bill, note, bond and TIPS auction results since 1979, from Treasury Fiscal Data and TreasuryDirect: rate, stop-out versus median, bid-to-cover, bidder takedown and size; an after view ranks each auction against its tenor and shows the yield's moves after it. Search by benchmark (10Y) or CUSIP. Hong Kong's EF Bills, EF Notes and Government Bond tenders too.",
|
|
71
74
|
keywords: [
|
|
72
75
|
"treasury",
|
|
73
76
|
"auction",
|
|
@@ -95,6 +98,16 @@ export const treasuryAuctionsModule: PluginModule = {
|
|
|
95
98
|
"cusip",
|
|
96
99
|
"reopening",
|
|
97
100
|
"issuance",
|
|
101
|
+
"hong kong",
|
|
102
|
+
"hk",
|
|
103
|
+
"hkma",
|
|
104
|
+
"exchange fund bills",
|
|
105
|
+
"exchange fund notes",
|
|
106
|
+
"efb",
|
|
107
|
+
"hkgb",
|
|
108
|
+
"hk government bonds",
|
|
109
|
+
"tender",
|
|
110
|
+
"tender results",
|
|
98
111
|
],
|
|
99
112
|
shortcut: { prefix: "AUCT", argKind: "text", argOptional: true, argPlaceholder: "search" },
|
|
100
113
|
headless: treasuryAuctionsHeadless,
|
|
@@ -4,6 +4,7 @@ import { displayWidth } from "../../../utils/format";
|
|
|
4
4
|
import { compareSortValues, type SortDirection } from "../../../utils/sort-values";
|
|
5
5
|
import { AUCTION_HISTORY_ALL, AUCTION_HISTORY_DAYS, AUCTION_HISTORY_START, type AuctionHistoryWindow } from "./client";
|
|
6
6
|
import type { TreasuryAuction } from "./types";
|
|
7
|
+
import { auctionSearchMarket, isAuctionMarket, type AuctionMarket } from "./hk";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* History windows, shortest first: 30 days to 10 years in days, then ALL,
|
|
@@ -109,7 +110,7 @@ export const AUCTION_SORT_NAMES: ReadonlyArray<{ value: string; column: AuctionC
|
|
|
109
110
|
{ value: "direct", column: "direct" },
|
|
110
111
|
{ value: "dealer", column: "dealer" },
|
|
111
112
|
{ value: "size", column: "size" },
|
|
112
|
-
{ value: "cusip", column: "cusip" },
|
|
113
|
+
{ value: "cusip", column: "cusip", aliases: ["issue"] },
|
|
113
114
|
{ value: "btc-pctl", column: "btcPctl", aliases: ["btc-percentile", "bc-pctl"] },
|
|
114
115
|
{ value: "indirect-pctl", column: "indirectPctl", aliases: ["indirect-percentile"] },
|
|
115
116
|
{ value: "dealer-pctl", column: "dealerPctl", aliases: ["dealer-percentile"] },
|
|
@@ -522,13 +523,15 @@ export function buildAuctionColumns(options: {
|
|
|
522
523
|
|
|
523
524
|
/**
|
|
524
525
|
* What `AUCT 10Y --history-days 3650` asks of the pane, typed in the command
|
|
525
|
-
* bar as it is to `fn AUCT`: the search, and the window, group, view
|
|
526
|
-
* given as flags (`--history-days`, `--historyDays` or `--history`;
|
|
527
|
-
* `--filter`, `--view`, `--sort`), each as `--flag value` or
|
|
528
|
-
* A flag whose value is not one of its own is left out
|
|
526
|
+
* bar as it is to `fn AUCT`: the search, and the window, market, group, view
|
|
527
|
+
* and sort given as flags (`--history-days`, `--historyDays` or `--history`;
|
|
528
|
+
* `--market`, `--filter`, `--view`, `--sort`), each as `--flag value` or
|
|
529
|
+
* `--flag=value`. A flag whose value is not one of its own is left out; a
|
|
530
|
+
* search naming Hong Kong (`HK 10Y`) picks its market and keeps the rest.
|
|
529
531
|
*/
|
|
530
532
|
function parseAuctionCommandArg(arg: string | undefined): {
|
|
531
533
|
search: string;
|
|
534
|
+
market?: AuctionMarket;
|
|
532
535
|
historyDays?: AuctionHistoryWindow;
|
|
533
536
|
filter?: AuctionFilter;
|
|
534
537
|
view?: "results" | "after";
|
|
@@ -550,6 +553,8 @@ function parseAuctionCommandArg(arg: string | undefined): {
|
|
|
550
553
|
if (name === "historydays" || name === "history") {
|
|
551
554
|
const window = auctionHistoryWindow({ historyDays: value });
|
|
552
555
|
if (value === AUCTION_HISTORY_ALL || String(window) === value) parsed.historyDays = window;
|
|
556
|
+
} else if (name === "market") {
|
|
557
|
+
if (isAuctionMarket(value)) parsed.market = value;
|
|
553
558
|
} else if (name === "filter") {
|
|
554
559
|
const filter = AUCTION_FILTERS.find((entry) => entry.value === value)?.value;
|
|
555
560
|
if (filter) parsed.filter = filter;
|
|
@@ -561,7 +566,10 @@ function parseAuctionCommandArg(arg: string | undefined): {
|
|
|
561
566
|
if (name) parsed.sort = name;
|
|
562
567
|
}
|
|
563
568
|
}
|
|
564
|
-
|
|
569
|
+
// A search naming Hong Kong's paper picks its market unless --market names one.
|
|
570
|
+
const named = auctionSearchMarket(words.join(" "));
|
|
571
|
+
parsed.market ??= named.market ?? undefined;
|
|
572
|
+
parsed.search = parsed.market === "hk" ? named.search : words.join(" ").trim();
|
|
565
573
|
return parsed;
|
|
566
574
|
}
|
|
567
575
|
|
|
@@ -575,9 +583,9 @@ export function auctionCommandRequest(arg: string | undefined): {
|
|
|
575
583
|
params: Record<string, string>;
|
|
576
584
|
settings: Record<string, string> | null;
|
|
577
585
|
} {
|
|
578
|
-
const { search, historyDays, filter, view, sort } = parseAuctionCommandArg(arg);
|
|
586
|
+
const { search, market, historyDays, filter, view, sort } = parseAuctionCommandArg(arg);
|
|
579
587
|
return {
|
|
580
|
-
params: { search, auctionView: view ?? "results", auctionSort: sort ?? "date", auctionFilter: filter ?? "all" },
|
|
588
|
+
params: { search, auctionMarket: market ?? "us", auctionView: view ?? "results", auctionSort: sort ?? "date", auctionFilter: filter ?? "all" },
|
|
581
589
|
settings: historyDays != null ? { historyDays: String(historyDays) } : null,
|
|
582
590
|
};
|
|
583
591
|
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
type DataTableCell,
|
|
12
12
|
type DataTableKeyEvent,
|
|
13
13
|
type DataTableRootKeyContext,
|
|
14
|
+
type QueryBarSelectFilter,
|
|
14
15
|
} from "../../../components";
|
|
15
16
|
import { loadingErrorFooterInfo, usePaneRefreshKey } from "../../../components/data-table/table-pane";
|
|
16
17
|
import { ageFooterSegment, savedCopyFooterInfo } from "../../../components/layout/pane/footer";
|
|
@@ -73,6 +74,8 @@ import {
|
|
|
73
74
|
TREASURY_AUCTIONS_PANE_ID,
|
|
74
75
|
type TreasuryAuction,
|
|
75
76
|
} from "./types";
|
|
77
|
+
import { AUCTION_MARKETS, isAuctionMarket, type AuctionMarket } from "./hk";
|
|
78
|
+
import { HkTendersView } from "./hk-view";
|
|
76
79
|
|
|
77
80
|
function formatRate(value: number | null): string {
|
|
78
81
|
return value == null ? "—" : `${value.toFixed(3)}%`;
|
|
@@ -267,16 +270,16 @@ function writeSort(sort: AuctionSortPreference): string | null {
|
|
|
267
270
|
/** A command's value for this pane's auctions tab, from `AUCT 7Y --view after` and the like. */
|
|
268
271
|
const auctionParam = (key: string) => (params: Readonly<Record<string, string>>) => params.view === "auctions" ? params[key] ?? null : null;
|
|
269
272
|
|
|
273
|
+
/**
|
|
274
|
+
* AUCT: US Treasury auctions, or Hong Kong's government paper tenders, by the
|
|
275
|
+
* Market choice in the query bar (`AUCT --market hk`, `AUCT HK 10Y`). The
|
|
276
|
+
* group, search, sort and window carry across.
|
|
277
|
+
*/
|
|
270
278
|
export function TreasuryAuctionsPane({ focused, width, height }: PaneProps) {
|
|
271
279
|
const historyDays = auctionHistoryWindow(usePaneInstance()?.settings);
|
|
272
|
-
const [
|
|
280
|
+
const [marketChoice, setMarket] = useCommandValue<string>(FIXED_INCOME_PANE_ID, "market", auctionParam("auctionMarket"), "us");
|
|
281
|
+
const market: AuctionMarket = isAuctionMarket(marketChoice) ? marketChoice : "us";
|
|
273
282
|
const [sortValue, setSortValue] = useCommandValue<string | null>(FIXED_INCOME_PANE_ID, "sortColumn", auctionParam("auctionSort"), null);
|
|
274
|
-
const sortPreference = useMemo(() => readSort(sortValue) ?? DEFAULT_AUCTION_SORT, [sortValue]);
|
|
275
|
-
const setSortPreference = useCallback((next: AuctionSortPreference | ((current: AuctionSortPreference) => AuctionSortPreference)) => {
|
|
276
|
-
setSortValue(writeSort(typeof next === "function" ? next(readSort(sortValue) ?? DEFAULT_AUCTION_SORT) : next));
|
|
277
|
-
}, [setSortValue, sortValue]);
|
|
278
|
-
// A sort by an after column shows the after view, as `fn AUCT --sort btc-pctl` does.
|
|
279
|
-
const view: AuctionView = viewChoice === "after" || isAfterColumn(sortPreference.columnId) ? "after" : "results";
|
|
280
283
|
const [filter, setFilter] = useCommandValue<AuctionFilter>(FIXED_INCOME_PANE_ID, "activeTab",
|
|
281
284
|
(params) => AUCTION_FILTERS.find((entry) => entry.value === auctionParam("auctionFilter")(params))?.value ?? null, "all");
|
|
282
285
|
// `AUCT 10Y` opens on that search, as `fn AUCT 10Y` reads it; a later `AUCT 5Y` replaces it.
|
|
@@ -286,6 +289,23 @@ export function TreasuryAuctionsPane({ focused, width, height }: PaneProps) {
|
|
|
286
289
|
(params) => params.view === "auctions" ? params.search ?? "" : null,
|
|
287
290
|
"",
|
|
288
291
|
);
|
|
292
|
+
const marketFilter = useMemo<QueryBarSelectFilter<string>>(() => ({
|
|
293
|
+
id: "market", label: "Market", value: market, options: AUCTION_MARKETS, onChange: setMarket, inline: true,
|
|
294
|
+
}), [market, setMarket]);
|
|
295
|
+
const shared = { focused, width, height, historyDays, filter, setFilter, searchQuery, setSearchQuery, sortValue, setSortValue, marketFilter };
|
|
296
|
+
return market === "hk" ? <HkTendersView {...shared} /> : <UsAuctionsView {...shared} />;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function UsAuctionsView({
|
|
300
|
+
focused, width, height, historyDays, filter, setFilter, searchQuery, setSearchQuery, sortValue, setSortValue, marketFilter,
|
|
301
|
+
}: Parameters<typeof HkTendersView>[0]) {
|
|
302
|
+
const [viewChoice, setView] = useCommandValue<string>(FIXED_INCOME_PANE_ID, "view", auctionParam("auctionView"), "results");
|
|
303
|
+
const sortPreference = useMemo(() => readSort(sortValue) ?? DEFAULT_AUCTION_SORT, [sortValue]);
|
|
304
|
+
const setSortPreference = useCallback((next: AuctionSortPreference | ((current: AuctionSortPreference) => AuctionSortPreference)) => {
|
|
305
|
+
setSortValue(writeSort(typeof next === "function" ? next(readSort(sortValue) ?? DEFAULT_AUCTION_SORT) : next));
|
|
306
|
+
}, [setSortValue, sortValue]);
|
|
307
|
+
// A sort by an after column shows the after view, as `fn AUCT --sort btc-pctl` does.
|
|
308
|
+
const view: AuctionView = viewChoice === "after" || isAfterColumn(sortPreference.columnId) ? "after" : "results";
|
|
289
309
|
// The after view reads more than it lists, until each listed tenor has its 24 before the oldest row
|
|
290
310
|
// (widerAfterWindow); the widening holds for one list, and a new search, group or window starts over.
|
|
291
311
|
const listKey = `${historyDays}|${filter}|${searchQuery}`;
|
|
@@ -356,7 +376,7 @@ export function TreasuryAuctionsPane({ focused, width, height }: PaneProps) {
|
|
|
356
376
|
const selectFilter = useCallback((next: AuctionFilter) => {
|
|
357
377
|
setFilter(next);
|
|
358
378
|
setDetailOpen(false);
|
|
359
|
-
}, []);
|
|
379
|
+
}, [setFilter]);
|
|
360
380
|
const cycleFilter = useCallback(() => {
|
|
361
381
|
setFilter(nextFilter(filter));
|
|
362
382
|
setDetailOpen(false);
|
|
@@ -461,11 +481,26 @@ export function TreasuryAuctionsPane({ focused, width, height }: PaneProps) {
|
|
|
461
481
|
variant: "bare",
|
|
462
482
|
});
|
|
463
483
|
const tabs = tabStrip && <Box height={1} flexShrink={0} overflow="hidden">{tabStrip}</Box>;
|
|
484
|
+
const queryBar = (
|
|
485
|
+
<QueryBar
|
|
486
|
+
width={width}
|
|
487
|
+
search={{
|
|
488
|
+
value: searchQuery,
|
|
489
|
+
onChange: setSearchQuery,
|
|
490
|
+
placeholder: "type, 10Y, CUSIP, or date",
|
|
491
|
+
focused: focused && !detailOpen,
|
|
492
|
+
...searchProps,
|
|
493
|
+
}}
|
|
494
|
+
filters={[marketFilter]}
|
|
495
|
+
view={{ value: view, options: VIEW_OPTIONS, onChange: selectView }}
|
|
496
|
+
/>
|
|
497
|
+
);
|
|
464
498
|
|
|
465
499
|
if (loading && auctions.length === 0) {
|
|
466
500
|
return (
|
|
467
501
|
<Box flexDirection="column" width={width} height={height}>
|
|
468
502
|
{tabs}
|
|
503
|
+
{queryBar}
|
|
469
504
|
<PaneStatusBody loading align="center" loadingLabel="Loading Treasury auctions..." />
|
|
470
505
|
</Box>
|
|
471
506
|
);
|
|
@@ -475,6 +510,7 @@ export function TreasuryAuctionsPane({ focused, width, height }: PaneProps) {
|
|
|
475
510
|
return (
|
|
476
511
|
<Box flexDirection="column" width={width} height={height}>
|
|
477
512
|
{tabs}
|
|
513
|
+
{queryBar}
|
|
478
514
|
<Box padding={1}>
|
|
479
515
|
<EmptyState status={error ? "error" : "empty"} title="Treasury auctions unavailable." message={error} />
|
|
480
516
|
</Box>
|
|
@@ -491,19 +527,7 @@ export function TreasuryAuctionsPane({ focused, width, height }: PaneProps) {
|
|
|
491
527
|
onBack={() => setDetailOpen(false)}
|
|
492
528
|
detailContent={selected ? <TreasuryAuctionDetail auction={selected} width={width} after={after?.get(selected.id)} /> : null}
|
|
493
529
|
detailTitle={selected ? `${selected.secType} ${selected.securityTerm}` : undefined}
|
|
494
|
-
rootBefore={
|
|
495
|
-
<QueryBar
|
|
496
|
-
width={width}
|
|
497
|
-
search={{
|
|
498
|
-
value: searchQuery,
|
|
499
|
-
onChange: setSearchQuery,
|
|
500
|
-
placeholder: "type, 10Y, CUSIP, or date",
|
|
501
|
-
focused: focused && !detailOpen,
|
|
502
|
-
...searchProps,
|
|
503
|
-
}}
|
|
504
|
-
view={{ value: view, options: VIEW_OPTIONS, onChange: selectView }}
|
|
505
|
-
/>
|
|
506
|
-
)}
|
|
530
|
+
rootBefore={queryBar}
|
|
507
531
|
onRootKeyDown={handleRootKeyDown}
|
|
508
532
|
onDetailKeyDown={handlePaneKey}
|
|
509
533
|
selection={{
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { ShortcutArgError } from "../types/plugin";
|
|
2
|
+
import { listingSuffixVenue } from "../sources/listing-symbols";
|
|
3
|
+
import { canonicalExchange, canonicalTickerKey, parsePublicTickerKey } from "../utils/exchanges";
|
|
4
|
+
import { listingAbroadVenue } from "../utils/sec";
|
|
2
5
|
|
|
3
6
|
/** Collections an unknown-name error lists, so the caller can retry with one. */
|
|
4
7
|
const LISTED_COLLECTIONS = 12;
|
|
@@ -33,6 +36,25 @@ export function findNamedCollection<T extends { id: string; name: string }>(
|
|
|
33
36
|
* first 60 are read.` Every function's list argument, in `fn` and in the
|
|
34
37
|
* command bar, reads a watchlist's name here.
|
|
35
38
|
*/
|
|
39
|
+
/**
|
|
40
|
+
* What a saved ticker is read as in a function's list: its symbol, with its
|
|
41
|
+
* venue for a listing abroad (ASML:AMS, 2330:TWSE), as the same symbols typed
|
|
42
|
+
* read. A bare `ASML` is the US line, so a watchlist read as `ASML`, `2330`
|
|
43
|
+
* compared the wrong listings and exported keys a join collided on. A symbol
|
|
44
|
+
* that names its venue reads by the one code RV and `compare` print: ASML:XAMS
|
|
45
|
+
* as ASML:AMS, a vendor's 2330.TW as 2330:TWSE. US listings and venues with
|
|
46
|
+
* no home market (futures, currencies, coins) stay bare.
|
|
47
|
+
*/
|
|
48
|
+
export function watchlistMemberSymbol(metadata: { ticker: string; exchange?: string | null }): string {
|
|
49
|
+
const { ticker } = metadata;
|
|
50
|
+
if (parsePublicTickerKey(ticker).exchange) return canonicalTickerKey(ticker);
|
|
51
|
+
const suffixed = listingSuffixVenue(ticker, metadata.exchange ?? undefined);
|
|
52
|
+
if (suffixed) return `${suffixed.symbol}:${suffixed.exchange}`;
|
|
53
|
+
const exchange = canonicalExchange(metadata.exchange ?? undefined);
|
|
54
|
+
const key = exchange ? `${ticker}:${exchange}` : ticker;
|
|
55
|
+
return listingAbroadVenue(key) ? key : ticker;
|
|
56
|
+
}
|
|
57
|
+
|
|
36
58
|
export function readWatchlistArgument(
|
|
37
59
|
typed: string,
|
|
38
60
|
watchlist: { name: string },
|
|
@@ -68,6 +68,7 @@ import {
|
|
|
68
68
|
import {
|
|
69
69
|
getPortfolioValuationDisplay,
|
|
70
70
|
getPortfolioValuationTime,
|
|
71
|
+
valuesAtNominalPrice,
|
|
71
72
|
valuesAtSettlement,
|
|
72
73
|
type PortfolioValuationBasis,
|
|
73
74
|
} from "./valuation-basis";
|
|
@@ -773,6 +774,8 @@ export function getColumnValue(
|
|
|
773
774
|
// In UTC, as the header says; a close the venue's calendar gives no hour for is dated by its day.
|
|
774
775
|
// An export writes the date with it, as ISO: 16:49 alone says nothing of which day.
|
|
775
776
|
const iso = new Date(time.time).toISOString();
|
|
777
|
+
// A price nothing traded at says so; its export keeps the day of the session it is the venue's price for.
|
|
778
|
+
if (valuesAtNominalPrice(quote, positionMetrics, ctx.valuationBasis)) return { text: "nominal", color: colors.warning, value: iso.slice(0, 10) };
|
|
776
779
|
return {
|
|
777
780
|
// Every row names its day: a bare 00:47 beside Fri 21:00 reads as the same evening.
|
|
778
781
|
text: time.dateOnly ? formatShortDate(time.time, MONTH_DAY) : formatFeedTime(time.time, ctx.now, "—", { utc: true, dayToday: true }),
|