@trdrs/quickcharts 5.11.1 → 5.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -82,6 +82,10 @@ interface SymbolInfo {
82
82
  dataStatus: DataStatus;
83
83
  /** ISO 4217 for a money-quoted symbol; absent when the quote unit is not a currency. */
84
84
  currencyCode?: string;
85
+ /** Whether a crypto or forex symbol writes itself as `BASE / QUOTE`. It does unless this is false, as for
86
+ * a contract whose ticker names it whole (`SOL-PERP`), which reads as its ticker and its name. A symbol
87
+ * of any other type is never a pair. */
88
+ pair?: boolean;
85
89
  /** The unit a non-currency symbol is quoted in, e.g. an energy or weight unit id. */
86
90
  unitId?: string;
87
91
  /** Decimal places for a volume value. 0 for a whole-contract market. */
@@ -1,4 +1,4 @@
1
- import { S as SymbolInfo } from './symbology-BfPxIJjT.js';
1
+ import { S as SymbolInfo } from './symbology-BlOYXHK2.js';
2
2
 
3
3
  /** The theme roles a mark may wear. A host names a meaning and the mode resolves the color, so a
4
4
  * mark stays readable when the viewer switches to light. */
@@ -95,6 +95,13 @@ interface SymbolRow {
95
95
  * without it keeps the name the feed sent instead. `resolve()` states the same fact for the
96
96
  * charted symbol, so a row and the legend that follows it agree. */
97
97
  currencyCode?: string;
98
+ /** Whether a crypto or forex market writes itself as `BASE / QUOTE`. It does unless this is false, as for
99
+ * a contract whose ticker names it whole (`SOL-PERP`), which reads as its ticker beside its name. A
100
+ * market of any other type is never a pair. `SymbolInfo.pair` states the same for the charted symbol. */
101
+ pair?: boolean;
102
+ /** The tag the row wears after its description: what the market is, where the feed states it apart
103
+ * from its type (`perp`, `spot`). A row without it wears its type. */
104
+ kind?: string;
98
105
  /** Rows that share a group are one instrument listed on several venues. The symbol search lists
99
106
  * them as one row, the first of them the feed lists, whose pill opens the others beneath it as
100
107
  * rows of their own. Each row picks its own market. A row with no group, or an empty one, is a
@@ -298,7 +305,9 @@ interface SymbolNames {
298
305
  * written as a slash pair (`BTC/USD`) needs no currency to say so. Before a symbol resolves there
299
306
  * is no pair to write, so the bare ticker stands on its own rather than guessing at a quote. A
300
307
  * market that is not a pair keeps the feed's own words: the short name as its title, the long
301
- * description beside its mark. */
308
+ * description beside its mark. A market the feed says is no pair (`pair: false`), such as a contract whose
309
+ * ticker names it whole (`SOL-PERP`), reads the same way: its ticker as its mark, written as the feed writes it (`SOL/USD` stays `SOL/USD`), its name
310
+ * beside it. */
302
311
  declare function symbolNames(symbol: SymbolInfo | SymbolRow | string): SymbolNames;
303
312
 
304
313
  export { type BarMark as B, type ChartDatafeed as C, type DatafeedSearchOptions as D, type FeedBar as F, type HistoryPage as H, type MarkIconId as M, type OlderPageVerdict as O, type PricesHandlers as P, type SymbolRow as S, type TimescaleMark as T, type SearchPage as a, type SearchClassNode as b, type BarsEvent as c, type DatafeedConfig as d, FeedUnavailableError as e, type MarkColor as f, type MarkColorPair as g, type MarkColorRole as h, type MarkLine as i, type MarkLineStyle as j, type MarkPlacement as k, type MarkShape as l, type SubscribeHandlers as m, type SymbolNames as n, type SymbolPrices as o, olderPageVerdict as p, bareTicker as q, symbolNames as s };
package/dist/symbols.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { n as SymbolNames, q as bareTicker, s as symbolNames } from './symbols-BNiSiVlq.js';
2
- import './symbology-BfPxIJjT.js';
1
+ export { n as SymbolNames, q as bareTicker, s as symbolNames } from './symbols-fn6-xJCO.js';
2
+ import './symbology-BlOYXHK2.js';
package/dist/symbols.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  bareTicker,
3
3
  symbolNames
4
- } from "./chunk-HXTXZZW2.js";
4
+ } from "./chunk-FFZAHL6J.js";
5
5
  export {
6
6
  bareTicker,
7
7
  symbolNames
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trdrs/quickcharts",
3
- "version": "5.11.1",
3
+ "version": "5.12.0",
4
4
  "description": "Quick Charts: a datafeed-driven charting library with drawings, indicators, layouts and replay over host-supplied data and storage ports.",
5
5
  "keywords": [
6
6
  "charts",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/symbology.ts","../src/priceFormatter.ts"],"sourcesContent":["// Quick Charts SYMBOLOGY — the display facts `ChartDatafeed.resolve` serves for one symbol, and the\n// only place a chart price display gets its precision from. The datafeed says how a market's prices\n// are WRITTEN on the chart; a host that trades keeps its own execution facts, and the display and\n// execution grids may differ.\n//\n// What lives here: identity, venue and type, supported resolutions, exchange timezone and session,\n// data status, currency and unit, volume precision, and the price-format facts. Every one is a\n// display fact. A host keeps its execution facts and its quote values (last, change, volume) on its\n// own side of the chart.\n//\n// This module is self-contained by the same rule as `datafeed.ts` — the contract must never drag a\n// backend SDK into the chart's dependency surface. It imports nothing.\n\n/** How one symbol's prices are WRITTEN, in five facts. Together they express\n * every supported form: decimal, pip, fractional, fraction of a fraction, and variable tick.\n *\n * - `pricescale` — price units per whole unit. 100 writes cents, 100000 writes FX pipettes,\n * 100000000 writes satoshis, 32 writes thirty-seconds. It alone sets the decimal column width.\n * - `minmov` — the smallest move, in those units. It declares the grid a price moves on; it never\n * widens or narrows the decimal column (ES at `{100, 25}` writes 4500.25, the same two decimals\n * as `{100, 1}`).\n * - `minmove2` — the further division of one `minmov` step for a fraction-of-a-fraction market:\n * 4 means quarters of a thirty-second.\n * - `fractional` — write the sub-unit part as a counted fraction (110'16) instead of decimals.\n * - `variableTickSize` — an ordered ladder of tick sizes by price band, written as a\n * space-separated string: alternating tick and upper bound, ending with the tick that applies\n * above the last bound. \"0.01 10 0.02 100 0.05\" means 0.01 below 10, 0.02 below 100, 0.05 at or\n * above 100. The band a price falls in is a DECLARED fact of the symbol, not a guess from its\n * magnitude. */\nexport interface PriceFormat {\n pricescale: number\n minmov: number\n minmove2?: number\n fractional?: boolean\n variableTickSize?: string\n}\n\n/** How live the served data is, in three states. `delayed_streaming` is a real\n * stream behind a delay, not a degraded `streaming`. */\nexport type DataStatus = 'streaming' | 'endofday' | 'delayed_streaming'\n\n/** The subsession ids a symbol may name. `regular` is the regular hours, the weekly `session` on a\n * split day and the hours inside the electronic trading day `session` states on an electronic day;\n * `premarket` and `postmarket` are the spans before and after it; `overnight` is the span from\n * post-market close to pre-market open; `extended` is the whole span from pre-market open through\n * post-market close, or the whole electronic trading day. */\nexport type SubsessionId = 'regular' | 'extended' | 'premarket' | 'postmarket' | 'overnight'\n\n/** One named session of a market with extended hours. `session`\n * uses the grammar of `SymbolInfo.session`; `sessionCorrections` uses the grammar of\n * `SymbolInfo.corrections` and lists only the days that shorten THIS subsession. `description`\n * is a label a feed may state; the chart labels a subsession by its `id` from its own catalog. */\nexport interface Subsession {\n id: SubsessionId\n session: string\n description?: string\n sessionCorrections?: string\n}\n\n/** Resolved metadata for ONE symbol: everything the chart needs to title it, page it, session it,\n * and write its prices.\n *\n * `timezone`, `session`, `sessionHolidays`, `corrections` and `subsessions` are the\n * exchange-hours facts and travel with the symbol. The chart's session model (`sessionModel.ts`)\n * is built from them alone: market state, session shading, the regular-hours filter and the\n * status popup all read what the feed said, and a feed that states no extended hours gets none. */\nexport interface SymbolInfo {\n /** The symbol the datafeed answers to on every later call. */\n ticker: string\n /** The short display identity, e.g. 'ESZ2026'. */\n name: string\n /** The long human description, e.g. 'E-mini S&P 500 Dec 2026'. */\n description: string\n /** The venue a UI attributes the symbol to. */\n exchange: string\n /** The venue that actually lists it, when it differs from `exchange`. */\n listedExchange: string\n /** The venue's own type token, e.g. 'futures', 'stock', 'crypto', 'forex'. */\n type: string\n /** The resolutions this symbol serves, as chart timeframe tokens ('1m', '4h', '1d', '1mo'). An\n * EMPTY list declares no restriction: the feed serves any token the grammar admits (a futures\n * or spread feed says exactly this), and the chart never reads it as \"serves nothing\". A finite\n * list is a promise the chart may enforce. */\n supportedResolutions: readonly string[]\n /** The exchange's IANA zone, e.g. 'America/New_York'. */\n timezone: string\n /** The session string, e.g. '1700-1600' or '0930-1600'. */\n session: string\n /** The session-holidays string: comma-separated 'YYYYMMDD' full closures. */\n sessionHolidays?: string\n /** The corrections string: `;`-separated `<session>:<dates>` entries, each a session in\n * the grammar of `session` that holds on the `,`-separated 'YYYYMMDD' trading days named. A\n * correction outranks a holiday on the same date. */\n corrections?: string\n /** The symbol's named sessions, for a market whose exchange keeps extended hours. Absent for a\n * market with one weekly session. A `regular` subsession that differs from `session` makes the\n * symbol an electronic day, whose `session` is the whole electronic trading day. */\n subsessions?: readonly Subsession[]\n dataStatus: DataStatus\n /** ISO 4217 for a money-quoted symbol; absent when the quote unit is not a currency. */\n currencyCode?: string\n /** The unit a non-currency symbol is quoted in, e.g. an energy or weight unit id. */\n unitId?: string\n /** Decimal places for a volume value. 0 for a whole-contract market. */\n volumePrecision: number\n format: PriceFormat\n}\n\n\n/** One band of a `variableTickSize` ladder: `size` is the tick that applies to prices strictly below\n * `below`, and the last band's `below` is `Infinity`. */\nexport interface TickBand {\n /** The tick size in this band. */\n size: number\n /** The exclusive upper bound of the band. */\n below: number\n}\n\n/** Parse the space-separated variable-tick ladder into ordered bands. Returns an\n * empty array for a string the grammar cannot read, which is how a caller tells \"no ladder\" from\n * \"a ladder I must honour\" without guessing at a half-parsed one. */\nexport function parseTickBands(variableTickSize: string): TickBand[] {\n const parts = variableTickSize.trim().split(/\\s+/).filter(Boolean)\n if (parts.length === 0 || parts.length % 2 === 0) return []\n const bands: TickBand[] = []\n for (let i = 0; i < parts.length; i += 2) {\n const size = Number(parts[i])\n if (!Number.isFinite(size) || size <= 0) return []\n const raw = parts[i + 1]\n if (raw === undefined) {\n bands.push({ size, below: Number.POSITIVE_INFINITY })\n break\n }\n const below = Number(raw)\n if (!Number.isFinite(below)) return []\n if (bands.length > 0 && below <= bands[bands.length - 1]!.below) return []\n bands.push({ size, below })\n }\n return bands\n}\n\n/** The band a price falls in, by the ladder's declared bounds (magnitude of the SYMBOL's own\n * declared ladder, never a generic magnitude rule). Negative prices read on their absolute value,\n * so a spread writes both sides in one column. */\nexport function tickBandFor(bands: readonly TickBand[], price: number): TickBand | null {\n const at = Math.abs(price)\n for (const band of bands) if (at < band.below) return band\n return bands.length > 0 ? bands[bands.length - 1]! : null\n}\n","// The one Quick Charts PRICE FORMATTER. Every price a chart writes comes through here: the price\n// scale, the OHLC legend, the crosshair, drawing labels, marks, indicator price plots and exported\n// image text, plus a host's own surfaces through the public factory. One resolved formatter per\n// symbol means a layout cannot draw one market's prices at another's precision.\n//\n// The rule that makes it trustworthy: PRECISION COMES FROM THE SYMBOL'S DECLARED FACTS, NEVER FROM\n// THE PRICE. There is no \"small numbers get more decimals\" branch anywhere below. A variable-tick\n// symbol does change width by price band, but the bands are a fact the datafeed declared, not a\n// guess the formatter made.\n//\n// Deterministic in the strict sense: the same `PriceFormat` and options always produce the same\n// string for the same number, on every machine and in every locale, because the only locale input\n// is the punctuation the caller passes (or asks to be derived once, at construction).\nimport { parseTickBands, tickBandFor, type PriceFormat, type TickBand } from './symbology'\n\n/** How a formatted price is punctuated. A price localizes the decimal sign only, so\n * `groupSign` defaults to '' (no thousands separator) and a host that wants grouping asks for it\n * explicitly. */\nexport interface NumericPunctuation {\n /** What separates the whole part from the decimals. Default '.', or the locale's sign when a\n * `locale` is given. */\n decimalSign?: string\n /** What separates thousands in the whole part. Default '': a price is written ungrouped, because\n * a grouped price is harder to compare against the axis beside it. */\n groupSign?: string\n}\n\nexport interface PriceFormatterOptions {\n /** A BCP 47 tag used ONCE, at construction, to derive the decimal sign. Anything explicit in\n * `numericPunctuation` wins over it. */\n locale?: string\n numericPunctuation?: NumericPunctuation\n}\n\n/** A resolved formatter for one symbol. `format` and `parse` are exact inverses over every price\n * that lands on the symbol's own grid. */\nexport interface PriceFormatter {\n /** The price as the symbol writes it. */\n format(price: number): string\n /** The number a viewer typed, or null when the text is not a price in this symbol's format. */\n parse(text: string): number | null\n /** How many digits `format` writes after the decimal sign. 0 for a fractional format, which\n * writes none; the widest band's width for a variable-tick format, so a column sized from it\n * never has to reflow. */\n precision(): number\n}\n\n/** The apostrophe written between a whole price and its counted fraction, and again\n * between that fraction and its sub-fraction: 110'16 and 110'16'2. */\nconst FRACTION_SIGN = \"'\"\n\n/** Decimal digits implied by a price scale: the digits it takes to write `pricescale - 1`. A power\n * of ten resolves exactly (100 → 2, 100000000 → 8); 32 resolves to 2, the width of '31'. */\nfunction decimalsOfPriceScale(pricescale: number): number {\n if (!Number.isFinite(pricescale) || pricescale <= 1) return 0\n return Math.min(16, Math.ceil(Math.log10(pricescale) - 1e-9))\n}\n\n/** The decimal sign a locale writes, resolved once. Falls back to '.' where `Intl` cannot answer. */\nfunction localeDecimalSign(locale: string): string {\n try {\n const part = new Intl.NumberFormat(locale).formatToParts(1.1).find((p) => p.type === 'decimal')\n return part?.value ?? '.'\n } catch {\n return '.'\n }\n}\n\n/** A non-negative integer written with `groupSign` every three digits from the right. */\nfunction groupDigits(digits: string, groupSign: string): string {\n if (!groupSign) return digits\n let out = ''\n for (let i = 0; i < digits.length; i++) {\n if (i > 0 && (digits.length - i) % 3 === 0) out += groupSign\n out += digits[i]\n }\n return out\n}\n\n/** The magnitude of `value` written at exactly `decimals` places. Rounding is the double's own: a\n * price arrives as a binary float, and `toFixed` rounds the value that is actually stored, so the\n * same input yields the same digits on every engine. The sign is applied by the caller, which is\n * what keeps a price that rounds to zero from writing '-0.00'. */\nfunction fixedText(value: number, decimals: number): string {\n return Math.abs(value).toFixed(Math.min(20, decimals))\n}\n\ninterface Punctuation {\n decimalSign: string\n groupSign: string\n}\n\nfunction writeDecimal(price: number, decimals: number, punctuation: Punctuation): string {\n const fixed = fixedText(price, decimals)\n const dot = fixed.indexOf('.')\n const whole = dot < 0 ? fixed : fixed.slice(0, dot)\n const frac = dot < 0 ? '' : fixed.slice(dot + 1)\n const sign = price < 0 && Number(fixed) !== 0 ? '-' : ''\n const body = groupDigits(whole, punctuation.groupSign)\n return frac ? `${sign}${body}${punctuation.decimalSign}${frac}` : `${sign}${body}`\n}\n\n/** The fractional form. `units` is the count of `1/pricescale` steps in the sub-unit part, split\n * into whole `minmove2`-sized groups (the thirty-seconds) and a remainder (the quarters of one\n * thirty-second). With no `minmove2` the sub-unit part is the count itself: 110'16. */\nfunction writeFractional(price: number, format: PriceFormat, punctuation: Punctuation): string {\n const scale = format.pricescale\n const second = format.minmove2 && format.minmove2 > 1 ? format.minmove2 : 1\n const at = Math.abs(price)\n const total = Math.round(at * scale)\n const whole = Math.floor(total / scale)\n const units = total - whole * scale\n const outer = Math.floor(units / second)\n const inner = units - outer * second\n const outerWidth = String(Math.ceil(scale / second) - 1).length\n const sign = price < 0 && total !== 0 ? '-' : ''\n const body = groupDigits(String(whole), punctuation.groupSign)\n const outerText = String(outer).padStart(outerWidth, '0')\n return second > 1\n ? `${sign}${body}${FRACTION_SIGN}${outerText}${FRACTION_SIGN}${inner}`\n : `${sign}${body}${FRACTION_SIGN}${outerText}`\n}\n\nfunction parseFractional(text: string, format: PriceFormat): number | null {\n const scale = format.pricescale\n const second = format.minmove2 && format.minmove2 > 1 ? format.minmove2 : 1\n const parts = text.split(FRACTION_SIGN)\n if (parts.length < 2 || parts.length > 3) return null\n const negative = parts[0]!.trim().startsWith('-')\n const whole = Number(parts[0]!.replace(/[^0-9]/g, ''))\n const outer = Number(parts[1]!.trim())\n const inner = parts.length === 3 ? Number(parts[2]!.trim()) : 0\n if (!Number.isInteger(whole) || !Number.isInteger(outer) || !Number.isInteger(inner)) return null\n if (outer < 0 || inner < 0 || inner >= second) return null\n if (outer * second + inner >= scale) return null\n const value = whole + (outer * second + inner) / scale\n return negative ? -value : value\n}\n\n/** Build the formatter for one symbol's price format. The result is stateless and reusable; a host\n * resolves a symbol once and keeps its formatter for as long as the symbol is on screen. */\nexport function createPriceFormatter(format: PriceFormat, options?: PriceFormatterOptions): PriceFormatter {\n const explicit = options?.numericPunctuation\n const punctuation: Punctuation = {\n decimalSign: explicit?.decimalSign ?? (options?.locale ? localeDecimalSign(options.locale) : '.'),\n groupSign: explicit?.groupSign ?? '',\n }\n const fractional = format.fractional === true\n const bands: readonly TickBand[] = format.variableTickSize ? parseTickBands(format.variableTickSize) : []\n const bandDecimals = (band: TickBand): number => {\n const text = decimalText(band.size)\n const dot = text.indexOf('.')\n return dot < 0 ? 0 : text.length - dot - 1\n }\n const fixedDecimals = decimalsOfPriceScale(format.pricescale)\n const widest = bands.length > 0 ? Math.max(...bands.map(bandDecimals)) : fixedDecimals\n const decimalsFor = (price: number): number => {\n if (bands.length === 0) return fixedDecimals\n const band = tickBandFor(bands, price)\n return band ? bandDecimals(band) : fixedDecimals\n }\n\n return {\n format(price) {\n if (!Number.isFinite(price)) return ''\n return fractional ? writeFractional(price, format, punctuation) : writeDecimal(price, decimalsFor(price), punctuation)\n },\n parse(text) {\n const trimmed = text.trim()\n if (trimmed === '') return null\n if (fractional) return parseFractional(trimmed, format)\n let plain = trimmed\n if (punctuation.groupSign) plain = plain.split(punctuation.groupSign).join('')\n if (punctuation.decimalSign !== '.') plain = plain.split(punctuation.decimalSign).join('.')\n if (!/^[+-]?(\\d+(\\.\\d*)?|\\.\\d+)$/.test(plain)) return null\n const value = Number(plain)\n return Number.isFinite(value) ? value : null\n },\n precision: () => (fractional ? 0 : widest),\n }\n}\n\n/** A number's shortest decimal text, with exponent notation expanded, so a tick of 1e-8 reads\n * '0.00000001' and its decimal width can be counted. */\nfunction decimalText(value: number): string {\n const text = String(value)\n const exp = /^(-?)(\\d)(?:\\.(\\d+))?e-(\\d+)$/.exec(text)\n if (!exp) return text\n const [, sign, lead, rest = '', power] = exp\n const zeros = Number(power) - 1\n return `${sign}0.${'0'.repeat(zeros)}${lead}${rest}`\n}\n"],"mappings":";AAyHO,SAAS,eAAe,kBAAsC;AACnE,QAAM,QAAQ,iBAAiB,KAAK,EAAE,MAAM,KAAK,EAAE,OAAO,OAAO;AACjE,MAAI,MAAM,WAAW,KAAK,MAAM,SAAS,MAAM,EAAG,QAAO,CAAC;AAC1D,QAAM,QAAoB,CAAC;AAC3B,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,GAAG;AACxC,UAAM,OAAO,OAAO,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AAO;AACjB,QAAM,CAAC,EAAE,MAAM,MAAM,OAAO,IAAI,KAAK,IAAI;AACzC,QAAM,QAAQ,OAAO,KAAK,IAAI;AAC9B,SAAO,GAAG,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,GAAG,IAAI,GAAG,IAAI;AACpD;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/symbolLabel.ts"],"sourcesContent":["// How a symbol is WRITTEN on screen: one rule, three faces, kept in one file so they cannot drift.\n// The toolbar pill wears the compact mark, the legend wears the title, and a search row wears the\n// mark beside the description. Every face drops the venue prefix, which is feed identity rather\n// than anything a viewer reads, and every surface that names a market, in this package or over it,\n// reads the same faces from `symbolNames`.\nimport type { SymbolRow } from './datafeed'\nimport type { SymbolInfo } from './symbology'\n\n/** The ticker inside a feed symbol. Only a well-formed `VENUE:TICKER` sheds its prefix, a ticker\n * written as a slash pair included (`KRAKEN:BTC/USD` reads `BTC/USD`); a spread expression, a ratio\n * such as `NYSE:F/2`, or anything else the pattern does not admit, is its own label and passes\n * through. */\nexport function bareTicker(symbol: string): string {\n return /^[A-Za-z][A-Za-z0-9._-]*:([A-Za-z0-9][A-Za-z0-9._!]*|[A-Za-z][A-Za-z0-9.]*\\/[A-Za-z][A-Za-z0-9.]*)$/.exec(symbol)?.[1] ?? symbol\n}\n\n/** A ticker written as a slash pair (`BTC/USD`): catalog identity that already says what it is\n * priced in. A reciprocal expression (`1/ES`) starts with a digit and is not one. */\nconst SLASH_PAIR = /^[A-Za-z][A-Za-z0-9.]*\\/[A-Za-z][A-Za-z0-9.]*$/\n\n/** Compact presentation of one symbol. Feed identity and spread expressions stay untouched. */\nexport function symbolLabel(symbol: string): string {\n const ticker = bareTicker(symbol)\n return SLASH_PAIR.test(ticker) ? ticker.replace('/', '') : ticker\n}\n\n/** The markets whose symbols ARE a pair: one thing priced in another, where the ticker alone says\n * what is being bought but not what it is priced in. Those read as `BASE / QUOTE`.\n *\n * Every other market is deliberately absent. Nearly every symbol carries a `currencyCode`, so the\n * gate cannot be \"has a currency\": a share quoted in dollars is not a pair, and `AAPL / USD` would\n * claim one that does not exist. */\nconst PAIR_MARKETS = new Set(['crypto', 'forex'])\n\n/** `BASE / QUOTE` for a pair market, or null for anything that is not one.\n *\n * A ticker written as a slash pair (`BTC/USD`) states both sides itself and reads as written. Any\n * other takes its quote from the feed's own currency; a ticker that already carries it as a suffix\n * (`BTCUSDT`, `EURUSD`) sheds it rather than repeating it, and the base is whatever the ticker\n * states, so an inverted quotation reads the way it is written. */\nexport function pairLabel(ticker: string, type: string, currencyCode: string | undefined): string | null {\n const quote = currencyCode?.trim()\n if (!quote || !PAIR_MARKETS.has(type.toLowerCase())) return null\n const bare = bareTicker(ticker)\n if (SLASH_PAIR.test(bare)) return bare.replace('/', ' / ')\n const base = bare.length > quote.length && bare.toUpperCase().endsWith(quote.toUpperCase()) ? bare.slice(0, -quote.length) : bare\n return base && base.toUpperCase() !== quote.toUpperCase() ? `${base} / ${quote}` : null\n}\n\n/** The three ways one market is written, from one rule. */\nexport interface SymbolNames {\n /** The compact mark a label wears at a glance: a pair closed up (`BTCUSDC`, `EURUSD`), otherwise\n * the bare ticker (`ES1!`, `AAPL`). A spread expression is its own mark, operators and all. */\n mark: string\n /** The title a reading wears: a pair spaced (`BTC / USDC`), otherwise the feed's short name where\n * it stated one apart from the description, otherwise the bare ticker. */\n title: string\n /** The description beside a mark: a pair spaced, otherwise the feed's long description, otherwise\n * the bare ticker, so a market never repeats its own mark for want of a name. */\n description: string\n}\n\n/** The facts the rule reads, in one shape whatever the surface holds. */\ninterface Facts {\n ticker: string\n type: string\n shortName: string\n longName: string\n currencyCode: string | undefined\n}\n\nfunction factsOf(symbol: SymbolInfo | SymbolRow | string): Facts {\n if (typeof symbol === 'string') return { ticker: symbol, type: '', shortName: '', longName: '', currencyCode: undefined }\n // A search row states one name, the long one; a resolved symbol states a short name beside its\n // description, and a short name that merely repeats the description has not been given.\n if ('symbol' in symbol) return { ticker: symbol.ticker?.trim() || symbol.symbol, type: symbol.type, shortName: '', longName: symbol.name.trim(), currencyCode: symbol.currencyCode }\n const name = symbol.name.trim()\n const description = symbol.description.trim()\n return { ticker: symbol.ticker, type: symbol.type, shortName: name !== description ? name : '', longName: description, currencyCode: symbol.currencyCode }\n}\n\n/** How a market is named, from a resolved `SymbolInfo`, a search row, or the feed symbol alone\n * before either has landed.\n *\n * A pair market reads as `BTC / USDC` or `EUR / USD`, both sides in the codes the market itself\n * trades in, never a spelled-out currency name. The quote comes from `currencyCode`, and a ticker\n * written as a slash pair (`BTC/USD`) needs no currency to say so. Before a symbol resolves there\n * is no pair to write, so the bare ticker stands on its own rather than guessing at a quote. A\n * market that is not a pair keeps the feed's own words: the short name as its title, the long\n * description beside its mark. */\nexport function symbolNames(symbol: SymbolInfo | SymbolRow | string): SymbolNames {\n const facts = factsOf(symbol)\n if (facts.type.toLowerCase() === 'spread') return { mark: facts.ticker, title: facts.ticker, description: facts.ticker }\n const bare = bareTicker(facts.ticker)\n const pair = pairLabel(facts.ticker, facts.type, facts.currencyCode) ?? (SLASH_PAIR.test(bare) ? bare.replace('/', ' / ') : null)\n return {\n mark: pair ? pair.replace(' / ', '') : symbolLabel(facts.ticker),\n title: pair ?? (facts.shortName || bare),\n description: pair ?? (facts.longName || bare),\n }\n}\n"],"mappings":";AAYO,SAAS,WAAW,QAAwB;AACjD,SAAO,sGAAsG,KAAK,MAAM,IAAI,CAAC,KAAK;AACpI;AAIA,IAAM,aAAa;AAGZ,SAAS,YAAY,QAAwB;AAClD,QAAM,SAAS,WAAW,MAAM;AAChC,SAAO,WAAW,KAAK,MAAM,IAAI,OAAO,QAAQ,KAAK,EAAE,IAAI;AAC7D;AAQA,IAAM,eAAe,oBAAI,IAAI,CAAC,UAAU,OAAO,CAAC;AAQzC,SAAS,UAAU,QAAgB,MAAc,cAAiD;AACvG,QAAM,QAAQ,cAAc,KAAK;AACjC,MAAI,CAAC,SAAS,CAAC,aAAa,IAAI,KAAK,YAAY,CAAC,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