@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
|
@@ -211,26 +211,38 @@ export function lockedDisclosures(data: Pick<SupplyChainPayload, "says" | "names
|
|
|
211
211
|
|
|
212
212
|
/** Countries whose companies' own filings SPLC reads (docs/supply-chain.md, Coverage and limitations). */
|
|
213
213
|
const FILING_COUNTRIES = new Set(["US", "KR"]);
|
|
214
|
+
/**
|
|
215
|
+
* Where SPLC reads companies' own annual reports from the exchange: Hong
|
|
216
|
+
* Kong (HKEX), mainland China (cninfo) and Singapore (SGXNet), by the
|
|
217
|
+
* company's country or its listing's exchange. A few reports are read at a
|
|
218
|
+
* time, so a company there may not have had its report read yet.
|
|
219
|
+
*/
|
|
220
|
+
const REPORT_COUNTRIES = new Set(["HK", "CN", "SG"]);
|
|
221
|
+
const REPORT_EXCHANGES = new Set(["HKEX", "SSE", "SZSE", "SGX"]);
|
|
214
222
|
|
|
215
223
|
/**
|
|
216
224
|
* What a company with no disclosed relationship at all reads instead of an
|
|
217
225
|
* empty table. The server gives an entity's country as an ISO code (`US`,
|
|
218
226
|
* `KR`, `TW`) or none. A company in a country whose filings SPLC does not
|
|
219
227
|
* read names the markets it does; one whose country is not known is never
|
|
220
|
-
* said to be outside them.
|
|
221
|
-
* customer's filings name their suppliers.
|
|
222
|
-
* another company's supply chain ("fn SPLC
|
|
223
|
-
* there are relationships.
|
|
228
|
+
* said to be outside them. All but a US or Korean company point to the side
|
|
229
|
+
* that can still name it: a customer's filings name their suppliers.
|
|
230
|
+
* `command` is how the reader opens another company's supply chain ("fn SPLC
|
|
231
|
+
* AAPL" in the CLI). Null when there are relationships.
|
|
224
232
|
*/
|
|
225
233
|
export function supplyEmptyText(data: Pick<SupplyChainPayload, "symbol" | "entity" | "says" | "names" | "earlier">, command = (symbol: string) => `SPLC ${symbol}`): string | null {
|
|
226
234
|
if (data.says.length || data.names.length || data.earlier?.says.length || data.earlier?.names.length) return null;
|
|
227
235
|
const code = data.entity?.country?.trim().toUpperCase() ?? "";
|
|
228
236
|
const country = /^[A-Z]{2}$/.test(code) ? code : null;
|
|
237
|
+
const exchange = data.entity?.exchange?.trim().toUpperCase() ?? "";
|
|
229
238
|
const customerSide = `A customer's filings name its suppliers: try the customer's side, such as ${command("AAPL")}.`;
|
|
230
239
|
if (country && FILING_COUNTRIES.has(country)) return `No filing, announcement or call read so far names a relationship for ${data.symbol}.`;
|
|
240
|
+
if ((country && REPORT_COUNTRIES.has(country)) || REPORT_EXCHANGES.has(exchange)) {
|
|
241
|
+
return `No annual report, announcement or call read so far names a relationship for ${data.symbol}. ${customerSide}`;
|
|
242
|
+
}
|
|
231
243
|
if (!country) return `No filing, announcement or call read so far names a relationship for ${data.symbol}. ${customerSide}`;
|
|
232
|
-
return `No relationship for ${data.symbol}: SPLC reads US
|
|
233
|
-
+ `and none read so far names one. ${customerSide}`;
|
|
244
|
+
return `No relationship for ${data.symbol}: SPLC reads company filings from the US and Korea and annual reports from Hong Kong, mainland China `
|
|
245
|
+
+ `and Singapore, plus announcements and calls, and none read so far names one. ${customerSide}`;
|
|
234
246
|
}
|
|
235
247
|
|
|
236
248
|
/** The lock line of a free preview, in the same words in the pane and `fn SPLC`. */
|
|
@@ -141,6 +141,38 @@ export function thirteenFReadError(error: unknown): unknown {
|
|
|
141
141
|
);
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
+
/** What a 13F read says when Gloom Cloud was reached and its 13F source failed. */
|
|
145
|
+
export const THIRTEENF_SOURCE_UNAVAILABLE = "The 13F source is unavailable right now";
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* A 13F read the service answered with a failure of its own (a 5xx: the 13F
|
|
149
|
+
* source down and nothing stored to answer for it, or the service busy), in
|
|
150
|
+
* the app's words. It answered, so the connection is not what to check. A
|
|
151
|
+
* failure the service named otherwise (EDGAR's) and any other answer (a rate
|
|
152
|
+
* limit, a refused parameter) are as they came.
|
|
153
|
+
*/
|
|
154
|
+
function thirteenFSourceError(error: unknown): unknown {
|
|
155
|
+
if (!(error instanceof ApiRequestError) || error.status === undefined || error.status < 500) return error;
|
|
156
|
+
if (error.code && error.code !== "source_unavailable") return error;
|
|
157
|
+
return new ApiRequestError(THIRTEENF_SOURCE_UNAVAILABLE, error.status, error.retryAfterMs, "source_unavailable", error.details);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* When the copy Gloom Cloud answered from was read from the 13F source (ms),
|
|
162
|
+
* or null for a fresh answer. While the source is unavailable the service
|
|
163
|
+
* answers from a copy it stored, each row saying when it was read
|
|
164
|
+
* (`stored_as_of`); the oldest is the answer's.
|
|
165
|
+
*/
|
|
166
|
+
function storedCopyTime(value: unknown): number | null {
|
|
167
|
+
const rows = Array.isArray(value) ? value : [value];
|
|
168
|
+
let oldest = Number.POSITIVE_INFINITY;
|
|
169
|
+
for (const row of rows) {
|
|
170
|
+
const at = Date.parse(stringOrEmpty(asRecord(row).stored_as_of));
|
|
171
|
+
if (Number.isFinite(at)) oldest = Math.min(oldest, at);
|
|
172
|
+
}
|
|
173
|
+
return Number.isFinite(oldest) ? oldest : null;
|
|
174
|
+
}
|
|
175
|
+
|
|
144
176
|
async function fetchForms13F<T>(
|
|
145
177
|
path: string,
|
|
146
178
|
params: Record<string, string | number | undefined>,
|
|
@@ -184,22 +216,33 @@ async function fetchForms13F<T>(
|
|
|
184
216
|
} catch (cloudError) {
|
|
185
217
|
options.signal?.throwIfAborted();
|
|
186
218
|
const error = thirteenFReadError(cloudError);
|
|
187
|
-
if (options.cloudOnly) throw error;
|
|
219
|
+
if (options.cloudOnly) throw thirteenFSourceError(error);
|
|
188
220
|
const url = `${FORMS_13F_BASE_URL}${path}?${searchParams.toString()}`;
|
|
189
|
-
//
|
|
221
|
+
// A service that answered says what failed (its limit and when to ask again, its source being
|
|
222
|
+
// down); a direct read that cannot connect as well says less: the source is down, not this
|
|
223
|
+
// computer's connection.
|
|
224
|
+
const answered = !isNetworkFailure(error);
|
|
190
225
|
const response = await httpFetch(url, {
|
|
191
226
|
headers: { Accept: "application/json" },
|
|
192
227
|
signal: options.signal,
|
|
193
228
|
}).catch((fallbackError: unknown) => {
|
|
194
|
-
throw
|
|
229
|
+
throw answered ? thirteenFSourceError(error) : fallbackError;
|
|
195
230
|
});
|
|
196
231
|
if (!response.ok) {
|
|
197
232
|
if (isRateLimited(error)) throw error;
|
|
198
|
-
throw new ApiRequestError(`Forms13F ${response.status} for ${path}`, response.status);
|
|
233
|
+
throw thirteenFSourceError(new ApiRequestError(`Forms13F ${response.status} for ${path}`, response.status));
|
|
199
234
|
}
|
|
200
235
|
value = await response.json() as T;
|
|
201
236
|
}
|
|
202
237
|
options.signal?.throwIfAborted();
|
|
238
|
+
// The service's stored copy, while its 13F source is unavailable: said like a saved copy, and
|
|
239
|
+
// not kept as a fresh one, so the next read asks again.
|
|
240
|
+
const storedAt = storedCopyTime(value);
|
|
241
|
+
if (storedAt != null) {
|
|
242
|
+
if (current()) failedRefreshes.add(key);
|
|
243
|
+
options.onSavedCopy?.(storedAt);
|
|
244
|
+
return value;
|
|
245
|
+
}
|
|
203
246
|
if (current()) {
|
|
204
247
|
failedRefreshes.delete(key);
|
|
205
248
|
if (value != null && options.cache !== false) {
|
|
@@ -38,7 +38,8 @@ import {
|
|
|
38
38
|
import { usePaneTicker } from "../../../../state/app/context";
|
|
39
39
|
import { handleRefreshKey, useClampSelectedIndex } from "../../../../components/data-table/table-pane";
|
|
40
40
|
import { useBoundTicker, useTickerRequest } from "../../shared/ticker-request";
|
|
41
|
-
import { DAY_SO_FAR_TEXT, withSessionBar } from "../../../../time-series/session-bar";
|
|
41
|
+
import { DAY_SO_FAR_TEXT, requestedSessionBarSize, withSessionBar } from "../../../../time-series/session-bar";
|
|
42
|
+
import { RANGE_HISTORY_RESOLUTION, type ManualChartResolution } from "../../../../time-series/resolution";
|
|
42
43
|
import {
|
|
43
44
|
formingHistoryBar,
|
|
44
45
|
formingHistoryBarText,
|
|
@@ -130,7 +131,7 @@ interface HistoricalPriceTable {
|
|
|
130
131
|
gapNotices: string[];
|
|
131
132
|
}
|
|
132
133
|
|
|
133
|
-
function buildHistoricalPriceRows(points: PricePoint[], venue: string | undefined, now: number): HistoricalPriceTable {
|
|
134
|
+
function buildHistoricalPriceRows(points: PricePoint[], venue: string | undefined, now: number, requested: ManualChartResolution): HistoricalPriceTable {
|
|
134
135
|
const sorted = points
|
|
135
136
|
.flatMap((point, sourceIndex) => {
|
|
136
137
|
const date = pricePointDate(point);
|
|
@@ -139,7 +140,7 @@ function buildHistoricalPriceRows(points: PricePoint[], venue: string | undefine
|
|
|
139
140
|
}] : [];
|
|
140
141
|
})
|
|
141
142
|
.sort((left, right) => left.date.getTime() - right.date.getTime());
|
|
142
|
-
const size = historyBarSize(sorted.map((entry) => entry.date.getTime()));
|
|
143
|
+
const size = historyBarSize(sorted.map((entry) => entry.date.getTime()), requested);
|
|
143
144
|
const newestDate = sorted.at(-1)?.date.toISOString().slice(0, 10);
|
|
144
145
|
const forming = formingHistoryBar(size, newestDate, venue, now);
|
|
145
146
|
const dayToDate = size === "1d" && sorted.at(-1)?.partial === true;
|
|
@@ -271,16 +272,16 @@ export function HistoricalPricesPane({ focused, width, height }: PaneProps) {
|
|
|
271
272
|
// An index's uncounted 0 volume (^HSI's day built from its quote) is no volume, as `history` and HP's CSV leave it.
|
|
272
273
|
const instrumentType = quote?.instrumentType ?? financials?.quoteMetadata?.instrumentType;
|
|
273
274
|
const points = useMemo(
|
|
274
|
-
() => withSessionBar(data ?? [], quote, { now: Date.now(), venue }).map((point) => {
|
|
275
|
+
() => withSessionBar(data ?? [], quote, { now: Date.now(), venue, ...requestedSessionBarSize(data ?? [], RANGE_HISTORY_RESOLUTION[range]) }).map((point) => {
|
|
275
276
|
if (point.volume == null) return point;
|
|
276
277
|
const volume = indexBarVolume(point.volume, instrumentType);
|
|
277
278
|
return volume === point.volume ? point : { ...point, volume: undefined };
|
|
278
279
|
}),
|
|
279
|
-
[data, instrumentType, quote, venue],
|
|
280
|
+
[data, instrumentType, quote, range, venue],
|
|
280
281
|
);
|
|
281
282
|
const { rows, size, forming, dayToDate, newestDate, gapNotices } = useMemo(
|
|
282
|
-
() => buildHistoricalPriceRows(points, venue, Date.now()),
|
|
283
|
-
[points, venue],
|
|
283
|
+
() => buildHistoricalPriceRows(points, venue, Date.now(), RANGE_HISTORY_RESOLUTION[range]),
|
|
284
|
+
[points, range, venue],
|
|
284
285
|
);
|
|
285
286
|
const integrityNotice = priceHistoryIntegrityNotice(rows.filter((row) => row.point.integrity).length);
|
|
286
287
|
const wickNotice = useMemo(() => priceHistoryWickNotice(points.filter((point) => pricePointWickFlags(point).length > 0).length), [points]);
|
|
@@ -2,7 +2,7 @@ import { BAR_INTERVAL_LABELS } from "../../../../cli/history-rows";
|
|
|
2
2
|
import { periodToDateText } from "../../../../cli/pane-functions/freshness";
|
|
3
3
|
import { barLastSession, barPeriodToDate, type BarPeriod, type BarPeriodToDate } from "../../../../market-data/market/bar-period";
|
|
4
4
|
import { isIntradayDailyBar } from "../../../../market-data/market/period-return";
|
|
5
|
-
import { barSizeFromGap, medianBarGap } from "../../../../time-series/bar-spacing";
|
|
5
|
+
import { barSizeFromGap, medianBarGap, requestedBarSize } from "../../../../time-series/bar-spacing";
|
|
6
6
|
import type { TimeRange } from "../../../../time-series/range";
|
|
7
7
|
import { CHART_RESOLUTION_STEP_MS, type ManualChartResolution } from "../../../../time-series/resolution";
|
|
8
8
|
|
|
@@ -23,13 +23,16 @@ const INTRADAY_BELOW_MS = 0.8 * CHART_RESOLUTION_STEP_MS["1d"];
|
|
|
23
23
|
/**
|
|
24
24
|
* The bar size of a history, read from the usual spacing of its bars
|
|
25
25
|
* (medianBarGap), as `history` reads it, so the gap a holiday leaves does not
|
|
26
|
-
* make daily bars weekly. Daily when there is no gap to read.
|
|
26
|
+
* make daily bars weekly. Daily when there is no gap to read. Daily or longer
|
|
27
|
+
* bars asked for in a size (`requested`, the range's) are that size unless
|
|
28
|
+
* the bars show otherwise (requestedBarSize).
|
|
27
29
|
*/
|
|
28
|
-
export function historyBarSize(times: readonly number[]): HistoryBarSize {
|
|
30
|
+
export function historyBarSize(times: readonly number[], requested?: ManualChartResolution | null): HistoryBarSize {
|
|
29
31
|
const gap = medianBarGap(times);
|
|
30
|
-
if (gap == null) return "1d";
|
|
32
|
+
if (gap == null) return requested ?? "1d";
|
|
31
33
|
if (gap < INTRADAY_BELOW_MS) return INTRADAY_SIZES.find((size) => CHART_RESOLUTION_STEP_MS[size] === gap) ?? "intraday";
|
|
32
|
-
|
|
34
|
+
// Daily or longer bars of a range are the size it asks for: a thin listing's daily bars a week apart are not weekly.
|
|
35
|
+
return requested && isDailyOrLongerBar(requested) ? requestedBarSize(times, requested) : barSizeFromGap(gap);
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
/** Whether a bar of this size covers a day or more, so its date is a day and not a time. */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { FinancialStatement, TickerFinancials } from "../../../../types/financials";
|
|
2
|
+
import { ebitdaLacksDepreciation } from "../../../../utils/ebitda";
|
|
2
3
|
import { fiscalPeriodLabel, ttmPeriodLabel } from "../../../../utils/fiscal-period";
|
|
3
4
|
import { formatPerShareNumber } from "../../../../utils/reported-money";
|
|
4
5
|
import { hasNonIncomeStatementGap } from "../../../../utils/statement-gaps";
|
|
@@ -193,8 +194,11 @@ function formatFinancialGrowth(growth: number): string {
|
|
|
193
194
|
|
|
194
195
|
export function formatFinancialValue(
|
|
195
196
|
value: number | undefined,
|
|
196
|
-
row: Pick<FinancialTableRow, "format" | "divisor"
|
|
197
|
+
row: Pick<FinancialTableRow, "format" | "divisor"> & { key?: string },
|
|
198
|
+
statement?: FinancialStatement,
|
|
197
199
|
): string {
|
|
200
|
+
// EBITDA is operating income plus D&A: a period that reports no D&A has none, and its cell says why.
|
|
201
|
+
if ((value == null || !Number.isFinite(value)) && row.key === "ebitda" && ebitdaLacksDepreciation(statement)) return "no D&A";
|
|
198
202
|
if (value == null || !Number.isFinite(value)) return "—";
|
|
199
203
|
if (row.format === "eps") return formatPerShareNumber(value);
|
|
200
204
|
if (row.format === "percent") return `${formatNumber(value * 100, 1)}%`;
|
|
@@ -641,7 +645,7 @@ export function buildFinancialTableModel(
|
|
|
641
645
|
|| !canCompareFinancialRow(row, statement, previous, comparisonCurrency)
|
|
642
646
|
? undefined : computeGrowth(value, previousValue);
|
|
643
647
|
return {
|
|
644
|
-
...formatFinancialCell(formatFinancialValue(value, row), growth),
|
|
648
|
+
...formatFinancialCell(formatFinancialValue(value, row, statement), growth),
|
|
645
649
|
value,
|
|
646
650
|
growth,
|
|
647
651
|
semanticGrowth: semanticGrowthValue(growth, row.growthDirection),
|
|
@@ -385,7 +385,7 @@ export function ResolvedFinancialsTab({
|
|
|
385
385
|
const growth = (row.kind === "metric" && !row.showGrowth)
|
|
386
386
|
|| !canCompareFinancialRow(row, column.statement, previous, comparisonCurrency)
|
|
387
387
|
? undefined : computeGrowth(value, previousValue);
|
|
388
|
-
const formattedValue = formatFinancialValue(value, row);
|
|
388
|
+
const formattedValue = formatFinancialValue(value, row, column.statement);
|
|
389
389
|
const cell = formatFinancialCell(formattedValue, growth);
|
|
390
390
|
const growthColorValue = semanticGrowthValue(growth, row.growthDirection);
|
|
391
391
|
|
|
@@ -48,10 +48,10 @@ import { formatUtcTime } from "../../../utils/utc-time";
|
|
|
48
48
|
import { closeMoves } from "../../../utils/max-drawdown";
|
|
49
49
|
import { isYieldIndexSymbol } from "../../../tickers/index-roots";
|
|
50
50
|
import { parsePublicTickerKey } from "../../../utils/exchanges";
|
|
51
|
-
import { isPastPriceWindow, loadPriceWindowHistory, priceWindowText, readPriceWindow, type PriceWindow } from "../../../utils/price-window";
|
|
51
|
+
import { isPastPriceWindow, loadPriceWindowHistory, priceWindowInterval, priceWindowText, readPriceWindow, type PriceWindow } from "../../../utils/price-window";
|
|
52
52
|
import { historyCoverageNotice } from "../../../sources/history-coverage";
|
|
53
53
|
import { getChartResolutionLabel, isIntradayResolution, RANGE_HISTORY_RESOLUTION, type ManualChartResolution } from "../../../time-series/resolution";
|
|
54
|
-
import { DAY_SO_FAR_TEXT, withSessionBar } from "../../../time-series/session-bar";
|
|
54
|
+
import { DAY_SO_FAR_TEXT, requestedSessionBarSize, withSessionBar } from "../../../time-series/session-bar";
|
|
55
55
|
import { buildReturnRows, closedMarketNote, isTodayReturnRow, returnBaseCloseDay, type ReturnRange } from "./data-panes/returns-model";
|
|
56
56
|
import { periodBaseText } from "../../../market-data/market/period-return";
|
|
57
57
|
import { loadReturnSeries } from "./data-panes/returns-history";
|
|
@@ -417,7 +417,9 @@ export const historicalPricesHeadless: HeadlessPaneDefinition<"rows"> = {
|
|
|
417
417
|
// The venue whose sessions say whether a day, week or month is still running: the key's, or for a bare symbol its quote's.
|
|
418
418
|
const venue = exchange || quote?.listingExchangeName || quote?.exchangeName || undefined;
|
|
419
419
|
const now = Date.now();
|
|
420
|
-
|
|
420
|
+
// The bars the range or window asks for: a thin listing's daily bars a week or two apart are still daily.
|
|
421
|
+
const requested = window ? priceWindowInterval(window) : RANGE_HISTORY_RESOLUTION[range];
|
|
422
|
+
const points = withSessionBar(loaded, quote, { now, venue, ...requestedSessionBarSize(loaded, requested) });
|
|
421
423
|
// Providers serve float32 prices (4013.39990234 for 4013.4): the rows hold the decimal each is, as `history` does,
|
|
422
424
|
// a London line's cleaned in the pence it was priced in.
|
|
423
425
|
const priceDivisor = quotedPriceDivisor(quote);
|
|
@@ -436,7 +438,7 @@ export const historicalPricesHeadless: HeadlessPaneDefinition<"rows"> = {
|
|
|
436
438
|
};
|
|
437
439
|
}).sort((left, right) => left.date.localeCompare(right.date));
|
|
438
440
|
const notice = priceHistoryIntegrityNotice(rows.filter((row) => row.integrity).length);
|
|
439
|
-
const size = historyBarSize(rows.map((row) => Date.parse(row.date)));
|
|
441
|
+
const size = historyBarSize(rows.map((row) => Date.parse(row.date)), requested);
|
|
440
442
|
// A weekly or monthly bar whose period runs on is dated by how far it runs, as `history` dates it.
|
|
441
443
|
const forming = formingHistoryBar(size, rows.at(-1)?.date, venue, now);
|
|
442
444
|
// A complete one is dated by the day its last session closed, the day its close is from.
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
AUCTION_ARCHIVE_PAGE_SIZE, AUCTION_HISTORY_ALL, AUCTION_HISTORY_DAYS, AUCTION_HISTORY_START, auctionArchiveBoundary,
|
|
7
7
|
auctionWindowQuery, fetchTreasuryAuctions, type AuctionHistoryWindow, type AuctionQuery,
|
|
8
8
|
} from "./client";
|
|
9
|
-
import { mergeAuctionSources } from "./model";
|
|
9
|
+
import { isPendingAuction, mergeAuctionSources } from "./model";
|
|
10
10
|
import { DIRECT_LOOKBACK_DAYS, fetchDirectAuctions } from "./treasury-direct";
|
|
11
11
|
import type { TreasuryAuction } from "./types";
|
|
12
12
|
|
|
@@ -127,9 +127,12 @@ async function loadRecentBoard(
|
|
|
127
127
|
direct: { days: number; load: DirectLoader } | null,
|
|
128
128
|
from: () => string,
|
|
129
129
|
): Promise<TreasuryAuctionsResult> {
|
|
130
|
+
const directKey = direct && `direct:${direct.days}`;
|
|
131
|
+
const unchanged = force ? null : savedRecentBoard(fiscalKey, directKey, from());
|
|
132
|
+
if (unchanged) return unchanged;
|
|
130
133
|
const [primary, supplement] = await Promise.all([
|
|
131
134
|
answer(cache.load(fiscalKey, walk(FISCAL_DATA, fiscal), { force })),
|
|
132
|
-
direct ? answer(directCache.load(
|
|
135
|
+
direct && directKey ? answer(directCache.load(directKey, walk(TREASURY_DIRECT, () => direct.load(direct.days)), { force })) : null,
|
|
133
136
|
]);
|
|
134
137
|
if ("failed" in primary && (!supplement || "failed" in supplement)) throw primary.failed;
|
|
135
138
|
|
|
@@ -147,6 +150,37 @@ async function loadRecentBoard(
|
|
|
147
150
|
};
|
|
148
151
|
}
|
|
149
152
|
|
|
153
|
+
/** A New York day (YYYY-MM-DD): an auction closes on it and its results come out that afternoon. */
|
|
154
|
+
const newYorkDay = new Intl.DateTimeFormat("en-CA", { timeZone: "America/New_York", year: "numeric", month: "2-digit", day: "2-digit" });
|
|
155
|
+
|
|
156
|
+
/** An announced auction whose day has come in the last week: its results may be out by now. */
|
|
157
|
+
function comeDue(auction: TreasuryAuction, today: string, weekAgo: string): boolean {
|
|
158
|
+
return isPendingAuction(auction) && auction.auctionDate <= today && auction.auctionDate >= weekAgo;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* A command's recent board as an earlier run saved both sources' copies, while
|
|
163
|
+
* they are within the hour the app refreshes them in and no auction they list
|
|
164
|
+
* has come due since: results in do not change, so asking again could add only
|
|
165
|
+
* an auction announced within that hour, which the app waits as long for. A
|
|
166
|
+
* command otherwise asks both sources again (saved-copy-persistence.ts), a
|
|
167
|
+
* second or more each run; an auction due today is asked for until its
|
|
168
|
+
* results are in. The app's own cache already answers from a fresh copy, and
|
|
169
|
+
* keeps the failure of a refresh, so only a run that has read nothing yet
|
|
170
|
+
* (a command) looks here.
|
|
171
|
+
*/
|
|
172
|
+
function savedRecentBoard(fiscalKey: string, directKey: string | null, from: string, now = Date.now()): TreasuryAuctionsResult | null {
|
|
173
|
+
if (cache.get(fiscalKey)) return null;
|
|
174
|
+
const fiscal = cache.get(fiscalKey, { allowExpired: true });
|
|
175
|
+
const direct = directKey ? directCache.get(directKey, { allowExpired: true }) : null;
|
|
176
|
+
if (!fiscal || fiscal.stale || (directKey && (!direct || direct.stale))) return null;
|
|
177
|
+
const auctions = mergeAuctionSources(fiscal.data, direct?.data ?? [], from);
|
|
178
|
+
const today = newYorkDay.format(now);
|
|
179
|
+
const weekAgo = newYorkDay.format(now - 7 * 86_400_000);
|
|
180
|
+
if (auctions.some((auction) => comeDue(auction, today, weekAgo))) return null;
|
|
181
|
+
return { auctions, fetchedAt: Math.min(fiscal.fetchedAt, direct?.fetchedAt ?? Infinity), stale: false };
|
|
182
|
+
}
|
|
183
|
+
|
|
150
184
|
export async function loadTreasuryAuctions(
|
|
151
185
|
force = false,
|
|
152
186
|
loader: AuctionLoader = fetchTreasuryAuctions,
|
|
@@ -11,6 +11,8 @@ import { AUCTION_HISTORY_ALL, AUCTION_HISTORY_START, fetchTreasuryAuctions, type
|
|
|
11
11
|
import { loadTreasuryAuctions, type TreasuryAuctionsResult } from "./cache";
|
|
12
12
|
import { unansweredRefreshError } from "../../../data/saved-copies";
|
|
13
13
|
import type { TreasuryAuction } from "./types";
|
|
14
|
+
import { AUCTION_MARKETS, auctionSearchMarket, isAuctionMarket, loadHkTenders, type HkTendersResult } from "./hk";
|
|
15
|
+
import { hkTendersReport } from "./hk-headless";
|
|
14
16
|
import { FIXED_INCOME_VIEW_STATE } from "../fixed-income/model";
|
|
15
17
|
import {
|
|
16
18
|
AUCTION_HISTORY_WINDOWS,
|
|
@@ -141,21 +143,31 @@ const AFTER_NOTE = "Percentiles rank each auction against its tenor's previous 2
|
|
|
141
143
|
interface TreasuryAuctionsHeadlessDependencies {
|
|
142
144
|
load(args: HeadlessPaneLoadArgs, window: AuctionHistoryWindow): Promise<TreasuryAuctionsResult>;
|
|
143
145
|
curves(shown: readonly TreasuryAuction[], from: string | null): Promise<AuctionCurveRead>;
|
|
146
|
+
hk?(window: AuctionHistoryWindow): Promise<HkTendersResult>;
|
|
144
147
|
}
|
|
145
148
|
|
|
146
149
|
const defaultDependencies: TreasuryAuctionsHeadlessDependencies = {
|
|
147
150
|
load: (_args, window) => loadTreasuryAuctions(false, fetchTreasuryAuctions, window),
|
|
148
151
|
curves: (shown, from) => loadAuctionCurves(shown, from),
|
|
152
|
+
hk: (window) => loadHkTenders(false, window),
|
|
149
153
|
};
|
|
150
154
|
|
|
151
155
|
/** An empty table says what was searched, in which window, and what the search understands; another market's paper, what AUCT covers. */
|
|
152
156
|
function emptyNote(query: string, filter: AuctionFilter, historyDays: AuctionHistoryWindow): string {
|
|
153
|
-
if (namesOtherMarket(query))
|
|
157
|
+
if (namesOtherMarket(query)) {
|
|
158
|
+
return `AUCT covers US Treasury auctions and Hong Kong government paper tenders (--market hk); "${query.trim()}" is neither. Search by ${AUCTION_SEARCH_FIELDS}.`;
|
|
159
|
+
}
|
|
154
160
|
const searched = query.trim() ? `match "${query.trim()}"` : "found";
|
|
155
161
|
const group = filter === "all" ? "" : ` in the ${filter} group`;
|
|
156
162
|
return `No auctions ${searched}${group} in ${auctionHistoryPhrase(historyDays)}. Search by ${AUCTION_SEARCH_FIELDS}.`;
|
|
157
163
|
}
|
|
158
164
|
|
|
165
|
+
/** The market `--market` names; without it Hong Kong's when the search names its paper (`HK 10Y`, `EFB`), else the US. */
|
|
166
|
+
function marketOf(args: Pick<HeadlessPaneLoadArgs, "argument" | "options">) {
|
|
167
|
+
if (isAuctionMarket(args.options.market)) return args.options.market;
|
|
168
|
+
return auctionSearchMarket(typeof args.argument === "string" ? args.argument : "").market ?? "us";
|
|
169
|
+
}
|
|
170
|
+
|
|
159
171
|
export function createTreasuryAuctionsHeadless(
|
|
160
172
|
dependencies: TreasuryAuctionsHeadlessDependencies = defaultDependencies,
|
|
161
173
|
): HeadlessPaneDefinition<"rows"> {
|
|
@@ -165,7 +177,7 @@ export function createTreasuryAuctionsHeadless(
|
|
|
165
177
|
argument: {
|
|
166
178
|
kind: "free-text",
|
|
167
179
|
placeholder: "search",
|
|
168
|
-
description: "Optional search: security type, benchmark (10Y), term, CUSIP, or auction date (YYYY-MM-DD).",
|
|
180
|
+
description: "Optional search: security type, benchmark (10Y), term, CUSIP, or auction date (YYYY-MM-DD). HK, EFB or HKGB lists Hong Kong's tenders.",
|
|
169
181
|
optional: true,
|
|
170
182
|
},
|
|
171
183
|
options: [
|
|
@@ -179,9 +191,18 @@ export function createTreasuryAuctionsHeadless(
|
|
|
179
191
|
values: AUCTION_HISTORY_WINDOWS.map((days) => ({ value: String(days) })),
|
|
180
192
|
defaultValue: "120",
|
|
181
193
|
},
|
|
194
|
+
{
|
|
195
|
+
key: "market",
|
|
196
|
+
// No default: a search naming HK, EFB or RMB picks hk unless --market says otherwise.
|
|
197
|
+
description: "us (without it, unless the search names Hong Kong's paper): US Treasury auctions; hk: Hong Kong government paper tenders (EF Bills and Notes, HKSAR Government Bonds) from HKMA's Open API. A search naming HK, EFB, HKGB or RMB picks hk.",
|
|
198
|
+
type: "enum",
|
|
199
|
+
values: AUCTION_MARKETS.map((entry) => ({ value: entry.value })),
|
|
200
|
+
example: "--market hk",
|
|
201
|
+
pluginState: { pluginId: FIXED_INCOME_VIEW_STATE.treasuryAuctions, key: "market" },
|
|
202
|
+
},
|
|
182
203
|
{
|
|
183
204
|
key: "filter",
|
|
184
|
-
description: "Security type group.",
|
|
205
|
+
description: "Security type group (Hong Kong: bill is EF Bills, note EF Notes, bond Government Bonds).",
|
|
185
206
|
type: "enum",
|
|
186
207
|
values: [{ value: "all" }, { value: "bill" }, { value: "note" }, { value: "bond" }],
|
|
187
208
|
defaultValue: "all",
|
|
@@ -206,13 +227,28 @@ export function createTreasuryAuctionsHeadless(
|
|
|
206
227
|
},
|
|
207
228
|
],
|
|
208
229
|
columns: columnsFor("results", []),
|
|
230
|
+
// A search naming Hong Kong (`shot AUCT HK 10Y`) opens the pane on its market, as `fn` reads it.
|
|
231
|
+
shotState: (args) => marketOf(args) === "hk" ? { pluginState: { [FIXED_INCOME_VIEW_STATE.treasuryAuctions]: { market: "hk" } } } : {},
|
|
209
232
|
describe: (args) => {
|
|
210
233
|
const window = auctionHistoryWindow({ historyDays: args.options.historyDays });
|
|
211
|
-
|
|
234
|
+
const hk = marketOf(args) === "hk";
|
|
235
|
+
return `${hk ? "Hong Kong Tenders" : "Treasury Auctions"} | ${window === AUCTION_HISTORY_ALL ? "all" : `${window} days`} | ${String(args.options.filter)}`;
|
|
212
236
|
},
|
|
213
237
|
async load(args) {
|
|
214
238
|
const historyDays = auctionHistoryWindow({ historyDays: args.options.historyDays });
|
|
215
239
|
const filter = args.options.filter as AuctionFilter;
|
|
240
|
+
if (marketOf(args) === "hk") {
|
|
241
|
+
return {
|
|
242
|
+
...hkTendersReport(await (dependencies.hk ?? defaultDependencies.hk!)(historyDays), {
|
|
243
|
+
search: typeof args.argument === "string" ? args.argument : "",
|
|
244
|
+
filter,
|
|
245
|
+
window: historyDays,
|
|
246
|
+
view: args.options.view === "after" ? "after" : "results",
|
|
247
|
+
sort: typeof args.options.sort === "string" ? args.options.sort : null,
|
|
248
|
+
}),
|
|
249
|
+
appliedOptions: { market: "hk" },
|
|
250
|
+
};
|
|
251
|
+
}
|
|
216
252
|
const sortColumn = typeof args.options.sort === "string" ? auctionSortColumn(args.options.sort) : null;
|
|
217
253
|
// A sort by an after-view column is a request for that view.
|
|
218
254
|
const view: AuctionView = args.options.view === "after" || (sortColumn && isAfterColumn(sortColumn)) ? "after" : "results";
|
|
@@ -257,9 +293,11 @@ export function createTreasuryAuctionsHeadless(
|
|
|
257
293
|
size: auctionSize(auction),
|
|
258
294
|
...(after ? after.get(auction.id) : {}),
|
|
259
295
|
})),
|
|
296
|
+
appliedOptions: { market: "us" },
|
|
260
297
|
metadata: {
|
|
261
298
|
fetchedAt: result.fetchedAt,
|
|
262
299
|
stale: result.stale,
|
|
300
|
+
market: "us",
|
|
263
301
|
historyDays,
|
|
264
302
|
filter,
|
|
265
303
|
view,
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { HkTender } from "../../../api-client/hk-tenders";
|
|
2
|
+
import { unansweredRefreshError } from "../../../data/saved-copies";
|
|
3
|
+
import type { HeadlessPaneColumn, HeadlessPaneFreshness, HeadlessRowsResult } from "../../../types/headless";
|
|
4
|
+
import { AUCTION_HISTORY_ALL, type AuctionHistoryWindow } from "./client";
|
|
5
|
+
import {
|
|
6
|
+
DEFAULT_HK_SORT,
|
|
7
|
+
firstHkSortDirection,
|
|
8
|
+
formatHkAmount,
|
|
9
|
+
formatHkRate,
|
|
10
|
+
HK_SEARCH_FIELDS,
|
|
11
|
+
hkDateText,
|
|
12
|
+
hkRate,
|
|
13
|
+
hkSize,
|
|
14
|
+
hkSizeWorkedOut,
|
|
15
|
+
hkSortColumn,
|
|
16
|
+
hkTenderType,
|
|
17
|
+
hkWindowStart,
|
|
18
|
+
isSpread,
|
|
19
|
+
visibleHkTenders,
|
|
20
|
+
type HkTendersResult,
|
|
21
|
+
} from "./hk";
|
|
22
|
+
import { auctionHistoryPhrase, nextAuctionHistoryWindow, type AuctionFilter } from "./model";
|
|
23
|
+
|
|
24
|
+
const tender = (row: Record<string, unknown>) => row as unknown as HkTender;
|
|
25
|
+
const rate = (value: unknown, row: Record<string, unknown>) => formatHkRate(tender(row), value == null ? null : Number(value), "-");
|
|
26
|
+
/** The text says what a floating rate note's figure is, as a US FRN's does; the export keeps the number. */
|
|
27
|
+
const rateText = (value: unknown, row: Record<string, unknown>) => `${rate(value, row)}${value != null && isSpread(tender(row)) ? " spread" : ""}`;
|
|
28
|
+
|
|
29
|
+
const HK_COLUMNS: HeadlessPaneColumn[] = [
|
|
30
|
+
{ key: "date", header: "Date", description: "Issue day, the business day after the tender; a Government Bond's issue month, all HKMA's figures give." },
|
|
31
|
+
{ key: "type", header: "Type", description: "EFB: Exchange Fund Bills; EFN: Exchange Fund Notes; HKGB: Government Bond; FRN: its HONIA-indexed floating rate note." },
|
|
32
|
+
{ key: "term", header: "Term" },
|
|
33
|
+
{
|
|
34
|
+
key: "rate", header: "Rate", align: "right", format: rate, textFormat: rateText,
|
|
35
|
+
description: "Average accepted yield (an RMB bond's annualised); a floating rate note's spread over HONIA, in bp.",
|
|
36
|
+
},
|
|
37
|
+
{ key: "bidToCover", header: "B/C", align: "right", format: (value: unknown) => value == null ? "" : Number(value).toFixed(2) },
|
|
38
|
+
{
|
|
39
|
+
// Exports write the bare amount, each row's currency (HKD or CNH) beside it.
|
|
40
|
+
key: "size", header: "Size", align: "right", unitKey: "currency",
|
|
41
|
+
description: "A bond's amount allotted; EF paper's amount offered, worked out from its applications and over-subscription (≈).",
|
|
42
|
+
format: (value: unknown) => value == null ? "" : String(value),
|
|
43
|
+
textFormat: (value: unknown, row: Record<string, unknown>) =>
|
|
44
|
+
formatHkAmount(tender(row), value == null ? null : Number(value), "-", hkSizeWorkedOut(tender(row))),
|
|
45
|
+
},
|
|
46
|
+
{ key: "issue", header: "Issue", format: (value: unknown) => value == null ? "" : String(value) },
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
const HK_NOTE = "Hong Kong tenders are the Hong Kong Monetary Authority's tender figures from its Open API (Source: HKMA): "
|
|
50
|
+
+ "EF Bills and Notes and HKSAR institutional Government Bonds, dated by issue (a bond by its month). "
|
|
51
|
+
+ "EF paper's B/C is one plus HKMA's over-subscription, and its size the amount offered that implies (≈).";
|
|
52
|
+
|
|
53
|
+
const HK_FRESHNESS: HeadlessPaneFreshness = {
|
|
54
|
+
source: "HKMA", publisher: "Hong Kong Monetary Authority", status: "not-a-feed", basis: "monthly tender figures", observedKey: "date", oldest: null,
|
|
55
|
+
tradingDayMarket: "HK",
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/** An empty list says what was searched, in which window, and what the search understands. */
|
|
59
|
+
function emptyNote(search: string, filter: AuctionFilter, window: AuctionHistoryWindow): string {
|
|
60
|
+
const searched = search.trim() ? `match "${search.trim()}"` : "found";
|
|
61
|
+
const group = filter === "all" ? "" : ` in the ${filter} group`;
|
|
62
|
+
const phrase = window === AUCTION_HISTORY_ALL ? "every tender on record" : auctionHistoryPhrase(window);
|
|
63
|
+
return `No Hong Kong tenders ${searched}${group} in ${phrase}. Search by ${HK_SEARCH_FIELDS}.`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* HKMA publishes these figures a month at a time, after the tenders: how far
|
|
69
|
+
* each paper's run, so a missing recent tender reads as not published yet.
|
|
70
|
+
*/
|
|
71
|
+
function hkRunsToNote(runsTo: HkTendersResult["runsTo"]): string | null {
|
|
72
|
+
const parts = [
|
|
73
|
+
runsTo.efb && `${hkDateText(runsTo.efb)} for EF Bills`,
|
|
74
|
+
runsTo.efn && `${hkDateText(runsTo.efn)} for EF Notes`,
|
|
75
|
+
runsTo.hkgb && `${hkDateText(runsTo.hkgb)} for Government Bonds`,
|
|
76
|
+
].filter(Boolean);
|
|
77
|
+
return parts.length ? `HKMA publishes its tender figures monthly; they run to ${parts.join(", ")}.` : null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** `fn AUCT --market hk` (or a search naming Hong Kong's paper): HKMA's tender figures, in the AUCT report's shape. */
|
|
81
|
+
export function hkTendersReport(
|
|
82
|
+
result: HkTendersResult,
|
|
83
|
+
options: { search: string; filter: AuctionFilter; window: AuctionHistoryWindow; view: "results" | "after"; sort: string | null },
|
|
84
|
+
): HeadlessRowsResult {
|
|
85
|
+
const { search, filter, window } = options;
|
|
86
|
+
const sortColumn = options.sort ? hkSortColumn(options.sort) : null;
|
|
87
|
+
const sort = sortColumn ? { columnId: sortColumn, direction: firstHkSortDirection(sortColumn) } : DEFAULT_HK_SORT;
|
|
88
|
+
const from = hkWindowStart(window);
|
|
89
|
+
const tenders = visibleHkTenders(result.tenders, { filter, query: search, sort, from });
|
|
90
|
+
const next = nextAuctionHistoryWindow(window);
|
|
91
|
+
// A wider window adds rows only where the record goes back past this one's start.
|
|
92
|
+
const widerAdds = !!next && !!from && !!result.firstTender && result.firstTender < from;
|
|
93
|
+
const runsTo = hkRunsToNote(result.runsTo);
|
|
94
|
+
const notes = [
|
|
95
|
+
...(tenders.length === 0 ? [emptyNote(search, filter, window)] : []),
|
|
96
|
+
...(widerAdds ? [`Older tenders: use --history-days ${next}.`] : []),
|
|
97
|
+
...(options.view === "after" ? ["The after view ranks US Treasury auctions; Hong Kong tenders list their results."] : []),
|
|
98
|
+
...(options.sort && !sortColumn ? [`--sort ${options.sort} is a US Treasury column; Hong Kong tenders are listed newest first.`] : []),
|
|
99
|
+
...(tenders.length > 0 ? [HK_NOTE] : []),
|
|
100
|
+
...(runsTo ? [runsTo] : []),
|
|
101
|
+
];
|
|
102
|
+
return {
|
|
103
|
+
complete: !result.refreshError && !result.truncated,
|
|
104
|
+
errors: [unansweredRefreshError(result)].filter((error): error is string => !!error),
|
|
105
|
+
notes,
|
|
106
|
+
columns: HK_COLUMNS,
|
|
107
|
+
rowUnitKey: "currency",
|
|
108
|
+
rows: tenders.map((entry) => ({
|
|
109
|
+
...entry,
|
|
110
|
+
type: hkTenderType(entry),
|
|
111
|
+
rate: hkRate(entry),
|
|
112
|
+
size: hkSize(entry),
|
|
113
|
+
})),
|
|
114
|
+
freshness: HK_FRESHNESS,
|
|
115
|
+
metadata: {
|
|
116
|
+
fetchedAt: result.fetchedAt,
|
|
117
|
+
stale: result.stale,
|
|
118
|
+
market: "hk",
|
|
119
|
+
historyDays: window,
|
|
120
|
+
filter,
|
|
121
|
+
runsTo: result.runsTo,
|
|
122
|
+
firstTender: result.firstTender,
|
|
123
|
+
...(sortColumn ? { sort: options.sort } : {}),
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|