@symmio/trading-core 4.4.0 → 4.5.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.
Files changed (123) hide show
  1. package/dist/candles/adapters/tradingview/map-resolution.d.ts.map +1 -1
  2. package/dist/candles/adapters/tradingview/map-resolution.js +2 -0
  3. package/dist/candles/adapters/tradingview/map-resolution.js.map +1 -1
  4. package/dist/candles/adapters/tradingview/to-tradingview-datafeed.d.ts.map +1 -1
  5. package/dist/candles/adapters/tradingview/to-tradingview-datafeed.js +6 -4
  6. package/dist/candles/adapters/tradingview/to-tradingview-datafeed.js.map +1 -1
  7. package/dist/candles/history-query.d.ts +67 -0
  8. package/dist/candles/history-query.d.ts.map +1 -0
  9. package/dist/candles/history-query.js +80 -0
  10. package/dist/candles/history-query.js.map +1 -0
  11. package/dist/candles/index.d.ts +3 -0
  12. package/dist/candles/index.d.ts.map +1 -1
  13. package/dist/candles/merge-candle-pages.d.ts +5 -0
  14. package/dist/candles/merge-candle-pages.d.ts.map +1 -0
  15. package/dist/candles/merge-candle-pages.js +13 -0
  16. package/dist/candles/merge-candle-pages.js.map +1 -0
  17. package/dist/candles/query.d.ts +5 -1
  18. package/dist/candles/query.d.ts.map +1 -1
  19. package/dist/candles/query.js +3 -2
  20. package/dist/candles/query.js.map +1 -1
  21. package/dist/candles/refresh-candle-history.d.ts +31 -0
  22. package/dist/candles/refresh-candle-history.d.ts.map +1 -0
  23. package/dist/candles/refresh-candle-history.js +91 -0
  24. package/dist/candles/refresh-candle-history.js.map +1 -0
  25. package/dist/candles/resolution.d.ts +3 -3
  26. package/dist/candles/resolution.d.ts.map +1 -1
  27. package/dist/candles/resolution.js +1 -0
  28. package/dist/candles/resolution.js.map +1 -1
  29. package/dist/candles/sources/binance/create-binance-candle-source.d.ts.map +1 -1
  30. package/dist/candles/sources/binance/create-binance-candle-source.js +3 -1
  31. package/dist/candles/sources/binance/create-binance-candle-source.js.map +1 -1
  32. package/dist/candles/sources/lowcap/create-lowcap-candle-source.d.ts +35 -0
  33. package/dist/candles/sources/lowcap/create-lowcap-candle-source.d.ts.map +1 -0
  34. package/dist/candles/sources/lowcap/create-lowcap-candle-source.js +104 -0
  35. package/dist/candles/sources/lowcap/create-lowcap-candle-source.js.map +1 -0
  36. package/dist/candles/sources/lowcap/create-lowcap-symbol-loader.d.ts +4 -0
  37. package/dist/candles/sources/lowcap/create-lowcap-symbol-loader.d.ts.map +1 -0
  38. package/dist/candles/sources/lowcap/create-lowcap-symbol-loader.js +40 -0
  39. package/dist/candles/sources/lowcap/create-lowcap-symbol-loader.js.map +1 -0
  40. package/dist/candles/sources/lowcap/get-lowcap-candles.d.ts +12 -0
  41. package/dist/candles/sources/lowcap/get-lowcap-candles.d.ts.map +1 -0
  42. package/dist/candles/sources/lowcap/get-lowcap-candles.js +48 -0
  43. package/dist/candles/sources/lowcap/get-lowcap-candles.js.map +1 -0
  44. package/dist/candles/sources/lowcap/index.d.ts +2 -0
  45. package/dist/candles/sources/lowcap/index.d.ts.map +1 -0
  46. package/dist/candles/sources/lowcap/lowcap-candle-time.d.ts +9 -0
  47. package/dist/candles/sources/lowcap/lowcap-candle-time.d.ts.map +1 -0
  48. package/dist/candles/sources/lowcap/lowcap-candle-time.js +24 -0
  49. package/dist/candles/sources/lowcap/lowcap-candle-time.js.map +1 -0
  50. package/dist/candles/sources/lowcap/map-resolution.d.ts +16 -0
  51. package/dist/candles/sources/lowcap/map-resolution.d.ts.map +1 -0
  52. package/dist/candles/sources/lowcap/map-resolution.js +26 -0
  53. package/dist/candles/sources/lowcap/map-resolution.js.map +1 -0
  54. package/dist/candles/sources/lowcap/resolve-lowcap-symbol.d.ts +12 -0
  55. package/dist/candles/sources/lowcap/resolve-lowcap-symbol.d.ts.map +1 -0
  56. package/dist/candles/sources/lowcap/resolve-lowcap-symbol.js +8 -0
  57. package/dist/candles/sources/lowcap/resolve-lowcap-symbol.js.map +1 -0
  58. package/dist/candles/sources/lowcap/watch-lowcap-candles.d.ts +19 -0
  59. package/dist/candles/sources/lowcap/watch-lowcap-candles.d.ts.map +1 -0
  60. package/dist/candles/sources/lowcap/watch-lowcap-candles.js +104 -0
  61. package/dist/candles/sources/lowcap/watch-lowcap-candles.js.map +1 -0
  62. package/dist/candles/types.d.ts +32 -16
  63. package/dist/candles/types.d.ts.map +1 -1
  64. package/dist/gasless/get-gasless-batch-funding/batch-fee-approvals.d.ts +20 -0
  65. package/dist/gasless/get-gasless-batch-funding/batch-fee-approvals.d.ts.map +1 -0
  66. package/dist/gasless/get-gasless-batch-funding/batch-fee-approvals.js +29 -0
  67. package/dist/gasless/get-gasless-batch-funding/batch-fee-approvals.js.map +1 -0
  68. package/dist/gasless/get-gasless-batch-funding/get-gasless-batch-funding.d.ts +43 -0
  69. package/dist/gasless/get-gasless-batch-funding/get-gasless-batch-funding.d.ts.map +1 -0
  70. package/dist/gasless/get-gasless-batch-funding/get-gasless-batch-funding.js +96 -0
  71. package/dist/gasless/get-gasless-batch-funding/get-gasless-batch-funding.js.map +1 -0
  72. package/dist/gasless/get-gasless-batch-funding/index.d.ts +4 -0
  73. package/dist/gasless/get-gasless-batch-funding/index.d.ts.map +1 -0
  74. package/dist/gasless/get-gasless-batch-funding/query.d.ts +31 -0
  75. package/dist/gasless/get-gasless-batch-funding/query.d.ts.map +1 -0
  76. package/dist/gasless/get-gasless-batch-funding/query.js +22 -0
  77. package/dist/gasless/get-gasless-batch-funding/query.js.map +1 -0
  78. package/dist/gasless/get-gasless-batch-funding/types.d.ts +80 -0
  79. package/dist/gasless/get-gasless-batch-funding/types.d.ts.map +1 -0
  80. package/dist/gasless/get-gasless-margin-funding/get-gasless-margin-funding.d.ts +33 -0
  81. package/dist/gasless/get-gasless-margin-funding/get-gasless-margin-funding.d.ts.map +1 -0
  82. package/dist/gasless/get-gasless-margin-funding/get-gasless-margin-funding.js +31 -0
  83. package/dist/gasless/get-gasless-margin-funding/get-gasless-margin-funding.js.map +1 -0
  84. package/dist/gasless/get-gasless-margin-funding/index.d.ts +4 -0
  85. package/dist/gasless/get-gasless-margin-funding/index.d.ts.map +1 -0
  86. package/dist/gasless/get-gasless-margin-funding/query.d.ts +31 -0
  87. package/dist/gasless/get-gasless-margin-funding/query.d.ts.map +1 -0
  88. package/dist/gasless/get-gasless-margin-funding/query.js +22 -0
  89. package/dist/gasless/get-gasless-margin-funding/query.js.map +1 -0
  90. package/dist/gasless/get-gasless-margin-funding/types.d.ts +27 -0
  91. package/dist/gasless/get-gasless-margin-funding/types.d.ts.map +1 -0
  92. package/dist/gasless/index.d.ts +2 -0
  93. package/dist/gasless/index.d.ts.map +1 -1
  94. package/dist/index.d.ts +2 -2
  95. package/dist/index.d.ts.map +1 -1
  96. package/dist/index.js +505 -498
  97. package/dist/pools/listing-config/to-listing-config.d.ts +10 -3
  98. package/dist/pools/listing-config/to-listing-config.d.ts.map +1 -1
  99. package/dist/pools/listing-config/to-listing-config.js +5 -1
  100. package/dist/pools/listing-config/to-listing-config.js.map +1 -1
  101. package/dist/pools/types/generated/listing-backend.d.ts +266 -1
  102. package/dist/pools/types/generated/listing-backend.d.ts.map +1 -1
  103. package/dist/pools/types/generated/listing-backend.js.map +1 -1
  104. package/dist/pools/types.d.ts +7 -0
  105. package/dist/pools/types.d.ts.map +1 -1
  106. package/dist/pools/types.js.map +1 -1
  107. package/dist/price-service/enigma/ohlcv/fetch-enigma-ohlcv.d.ts +39 -0
  108. package/dist/price-service/enigma/ohlcv/fetch-enigma-ohlcv.d.ts.map +1 -0
  109. package/dist/price-service/enigma/ohlcv/fetch-enigma-ohlcv.js +43 -0
  110. package/dist/price-service/enigma/ohlcv/fetch-enigma-ohlcv.js.map +1 -0
  111. package/dist/price-service/enigma/ohlcv/generated/enigma-price-service-ohlcv.d.ts +67 -0
  112. package/dist/price-service/enigma/ohlcv/generated/enigma-price-service-ohlcv.d.ts.map +1 -0
  113. package/dist/price-service/enigma/ohlcv/generated/enigma-price-service-ohlcv.js +15 -0
  114. package/dist/price-service/enigma/ohlcv/generated/enigma-price-service-ohlcv.js.map +1 -0
  115. package/dist/price-service/enigma/ohlcv/parse-enigma-ohlcv.d.ts +21 -0
  116. package/dist/price-service/enigma/ohlcv/parse-enigma-ohlcv.d.ts.map +1 -0
  117. package/dist/price-service/enigma/ohlcv/parse-enigma-ohlcv.js +36 -0
  118. package/dist/price-service/enigma/ohlcv/parse-enigma-ohlcv.js.map +1 -0
  119. package/dist/price-service/enigma/symbols-info/get-enigma-price-service-symbols-info.d.ts +2 -0
  120. package/dist/price-service/enigma/symbols-info/get-enigma-price-service-symbols-info.d.ts.map +1 -1
  121. package/dist/price-service/enigma/symbols-info/get-enigma-price-service-symbols-info.js +12 -8
  122. package/dist/price-service/enigma/symbols-info/get-enigma-price-service-symbols-info.js.map +1 -1
  123. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"create-binance-candle-source.d.ts","sourceRoot":"","sources":["../../../../src/candles/sources/binance/create-binance-candle-source.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAE5E,OAAO,KAAK,EAGV,YAAY,EAKb,MAAM,aAAa,CAAC;AACrB,OAAO,EAKL,KAAK,aAAa,EACnB,MAAM,aAAa,CAAC;AAMrB;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C;;;OAGG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,6EAA6E;IAC7E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;;;;OASG;IACH,aAAa,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAC3D;;;OAGG;IACH,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;CAC7C;AAkBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,yBAAyB,CAAC,UAAU,GAAE,6BAAkC,GAAG,YAAY,CAqJtG"}
1
+ {"version":3,"file":"create-binance-candle-source.d.ts","sourceRoot":"","sources":["../../../../src/candles/sources/binance/create-binance-candle-source.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAE5E,OAAO,KAAK,EAGV,YAAY,EAKb,MAAM,aAAa,CAAC;AACrB,OAAO,EAKL,KAAK,aAAa,EACnB,MAAM,aAAa,CAAC;AAMrB;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C;;;OAGG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,6EAA6E;IAC7E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;;;;OASG;IACH,aAAa,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAC3D;;;OAGG;IACH,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;CAC7C;AAkBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,yBAAyB,CAAC,UAAU,GAAE,6BAAkC,GAAG,YAAY,CAuJtG"}
@@ -46,7 +46,9 @@ function d(d = {}) {
46
46
  sourceSymbol: n.symbol,
47
47
  description: r,
48
48
  pricePrecision: n.pricePrecision,
49
- volumePrecision: 2
49
+ volumePrecision: 2,
50
+ volumeUnit: "base",
51
+ volumeCurrency: n.baseAsset
50
52
  };
51
53
  },
52
54
  async getCandles(e) {
@@ -1 +1 @@
1
- {"version":3,"file":"create-binance-candle-source.js","names":[],"sources":["../../../../src/candles/sources/binance/create-binance-candle-source.ts"],"sourcesContent":["import { SymmError } from \"../../../shared/errors/symm-error\";\nimport type { WebSocketConstructor } from \"../../../shared/types/websocket\";\nimport type { Unwatch } from \"../../../websocket/notifications/watch-notifications\";\nimport type {\n Candle,\n CandleResolution,\n CandleSource,\n CandleSymbol,\n GetCandlesParameters,\n GetCandlesReturnType,\n WatchCandlesParameters,\n} from \"../../types\";\nimport {\n BINANCE_MAX_LIMIT,\n BINANCE_MAX_PAGES,\n BINANCE_REST_URL,\n BINANCE_WS_URL,\n type BinanceMarket,\n} from \"./constants\";\nimport { fetchBinanceExchangeInfo, type BinanceSymbolInfo } from \"./fetch-binance-exchange-info\";\nimport { fetchBinanceKlines } from \"./fetch-binance-klines\";\nimport { getBinanceSupportedResolutions, toBinanceInterval } from \"./map-resolution\";\nimport { watchBinanceKlines } from \"./watch-binance-klines\";\n\n/**\n * Parameters for {@link createBinanceCandleSource}.\n */\nexport interface BinanceCandleSourceParameters {\n /**\n * Which Binance market to read. Defaults to `\"usd-m-futures\"` — its symbols\n * are perpetual contracts, matching what a SYMMIO market actually is.\n */\n market?: BinanceMarket;\n /** Override the REST host (a regional mirror, or your own caching proxy). */\n restUrl?: string;\n /** Override the WebSocket endpoint. */\n wsUrl?: string;\n /**\n * Map a SYMMIO market name onto a Binance symbol, or return `undefined` when\n * the market has no Binance listing.\n *\n * Defaults to an upper-case identity mapping, which holds for current SYMMIO\n * deployments where market names are already Binance USD-M symbols. Override\n * it rather than relying on that coincidence if your deployment's names can\n * diverge — an unmapped name otherwise resolves to a symbol that does not\n * exist and the chart simply stays empty.\n */\n resolveSymbol?: (marketName: string) => string | undefined;\n /**\n * WebSocket implementation for {@link CandleSource.watchCandles}. Defaults to\n * `globalThis.WebSocket`; pass the `ws` package in Node environments without one.\n */\n webSocketConstructor?: WebSocketConstructor;\n}\n\nfunction defaultResolveSymbol(marketName: string): string {\n return marketName.toUpperCase();\n}\n\nfunction resolveWebSocketConstructor(injected?: WebSocketConstructor): WebSocketConstructor {\n const ctor = injected ?? (globalThis as { WebSocket?: WebSocketConstructor }).WebSocket;\n if (!ctor) {\n throw new SymmError(\n \"config\",\n \"NO_WEBSOCKET_IMPLEMENTATION\",\n \"No WebSocket implementation available. Pass `webSocketConstructor` to createBinanceCandleSource (e.g. the `ws` package in Node).\",\n );\n }\n return ctor;\n}\n\n/**\n * Create a {@link CandleSource} backed by Binance klines.\n *\n * History comes from the REST `/klines` endpoint, paged backwards from the end\n * of the requested range, and live bars from the kline WebSocket stream. Both\n * are reachable directly from a browser — Binance serves permissive CORS\n * headers on market data, so no proxy or API key is involved.\n *\n * Two caveats worth surfacing to users of a chart built on this:\n * - The series is `priceBasis: \"reference-exchange\"`. It is Binance's perp\n * price, not the SYMMIO solver's mark price that a trade actually settles at.\n * - `api.binance.com` and `fapi.binance.com` are blocked in some jurisdictions.\n * Supply `restUrl`/`wsUrl` to route through your own proxy where that matters.\n *\n * @param parameters - Market selection, endpoint overrides, and symbol mapping.\n * @returns A source usable by `getCandlesQueryOptions`, `useCandles`, or\n * `toTradingViewDatafeed`.\n *\n * @example\n * ```ts\n * const source = createBinanceCandleSource();\n * const { candles } = await source.getCandles({\n * marketName: \"BTCUSDT\",\n * resolution: \"1m\",\n * from: Date.now() - 60 * 60 * 1000,\n * to: Date.now(),\n * limit: 60,\n * });\n * ```\n */\nexport function createBinanceCandleSource(parameters: BinanceCandleSourceParameters = {}): CandleSource {\n const market = parameters.market ?? \"usd-m-futures\";\n const restUrl = parameters.restUrl ?? BINANCE_REST_URL[market];\n const wsUrl = parameters.wsUrl ?? BINANCE_WS_URL[market];\n const resolveSymbol = parameters.resolveSymbol ?? defaultResolveSymbol;\n const maxLimit = BINANCE_MAX_LIMIT[market];\n\n /**\n * `exchangeInfo` lists every contract on the venue and only changes on a\n * listing or delisting, so it is fetched once per source and shared by every\n * `getSymbol` call. The promise itself is cached so concurrent callers during\n * the first load share one request; a rejection clears it so a transient\n * failure does not poison the source for its lifetime.\n */\n let exchangeInfo: Promise<Map<string, BinanceSymbolInfo>> | null = null;\n\n function getExchangeInfo(): Promise<Map<string, BinanceSymbolInfo>> {\n if (!exchangeInfo) {\n exchangeInfo = fetchBinanceExchangeInfo(restUrl, market).catch((err: unknown) => {\n exchangeInfo = null;\n throw err;\n });\n }\n return exchangeInfo;\n }\n\n function requireInterval(resolution: CandleResolution): string {\n const interval = toBinanceInterval(market, resolution);\n if (!interval) {\n throw new SymmError(\n \"validation\",\n \"UNSUPPORTED_CANDLE_RESOLUTION\",\n `Binance ${market} has no klines interval for resolution \"${resolution}\".`,\n );\n }\n return interval;\n }\n\n function requireSourceSymbol(marketName: string): string {\n const symbol = resolveSymbol(marketName);\n if (!symbol) {\n throw new SymmError(\n \"validation\",\n \"UNMAPPED_CANDLE_MARKET\",\n `No Binance symbol is mapped for market \"${marketName}\".`,\n );\n }\n return symbol;\n }\n\n return {\n id: `binance:${market}`,\n priceBasis: \"reference-exchange\",\n supportedResolutions: getBinanceSupportedResolutions(market),\n maxCandlesPerRequest: maxLimit,\n\n async getSymbol(marketName: string): Promise<CandleSymbol | undefined> {\n const sourceSymbol = resolveSymbol(marketName);\n if (!sourceSymbol) return undefined;\n\n const info = (await getExchangeInfo()).get(sourceSymbol.toUpperCase());\n if (!info) return undefined;\n\n const description = info.baseAsset && info.quoteAsset ? `${info.baseAsset} / ${info.quoteAsset}` : info.symbol;\n\n return {\n marketName,\n sourceSymbol: info.symbol,\n description,\n pricePrecision: info.pricePrecision,\n /** Binance reports base-asset volume; two decimals reads well for every listed contract. */\n volumePrecision: 2,\n };\n },\n\n async getCandles(getCandlesParameters: GetCandlesParameters): Promise<GetCandlesReturnType> {\n const { marketName, resolution, from, to, limit, signal } = getCandlesParameters;\n const interval = requireInterval(resolution);\n const symbol = requireSourceSymbol(marketName);\n const wanted = limit && limit > 0 ? limit : Number.POSITIVE_INFINITY;\n\n const candles: Candle[] = [];\n\n /**\n * Paged backwards from `to`, not forwards from `from`. Binance caps a\n * range request from its *start*: sending `startTime`, `endTime` and\n * `limit` together returns the OLDEST `limit` bars in the window, which\n * for a chart is the wrong end entirely. Sending `endTime` alone returns\n * the newest bars ending there, which is what a chart scrolling back\n * actually needs; the `from` bound is then applied client-side.\n */\n let cursorEnd = to - 1;\n\n for (let page = 0; page < BINANCE_MAX_PAGES; page++) {\n if (cursorEnd < from) break;\n\n const remaining = wanted - candles.length;\n const requestLimit = Math.max(1, Math.min(maxLimit, remaining));\n\n const batch = await fetchBinanceKlines({\n restUrl,\n market,\n symbol,\n interval,\n endTime: cursorEnd,\n limit: requestLimit,\n signal,\n });\n const oldest = batch[0];\n if (!oldest) break;\n\n candles.unshift(...batch.filter((candle) => candle.time >= from && candle.time < to));\n\n /** Reached the requested start, or the venue has nothing older. */\n if (oldest.time <= from || batch.length < requestLimit) break;\n if (candles.length >= wanted) break;\n\n const nextCursor = oldest.time - 1;\n /** No-progress guard: without it a venue quirk could spin the loop. */\n if (nextCursor >= cursorEnd) break;\n cursorEnd = nextCursor;\n }\n\n return {\n candles,\n /**\n * An empty result is the venue saying it has nothing in this window —\n * for a 24/7 market that means the range predates the listing, so a\n * chart paging backwards should stop rather than keep asking.\n */\n noMoreData: candles.length === 0,\n };\n },\n\n watchCandles(watchCandlesParameters: WatchCandlesParameters): Unwatch {\n const { marketName, resolution, onCandle, onReset, onStatusChange, onError } = watchCandlesParameters;\n\n return watchBinanceKlines({\n wsUrl,\n symbol: requireSourceSymbol(marketName),\n interval: requireInterval(resolution),\n webSocketConstructor: resolveWebSocketConstructor(parameters.webSocketConstructor),\n onCandle,\n onReset,\n onStatusChange,\n onError,\n });\n },\n };\n}\n"],"mappings":";;;;;;;AAuDA,SAAS,EAAqB,GAA4B;CACxD,OAAO,EAAW,YAAY;AAChC;AAEA,SAAS,EAA4B,GAAuD;CAC1F,IAAM,IAAO,KAAa,WAAoD;CAC9E,IAAI,CAAC,GACH,MAAM,IAAI,EACR,UACA,+BACA,kIACF;CAEF,OAAO;AACT;AAgCA,SAAgB,EAA0B,IAA4C,CAAC,GAAiB;CACtG,IAAM,IAAS,EAAW,UAAU,iBAC9B,IAAU,EAAW,WAAW,EAAiB,IACjD,IAAQ,EAAW,SAAS,EAAe,IAC3C,IAAgB,EAAW,iBAAiB,GAC5C,IAAW,EAAkB,IAS/B,IAA+D;CAEnE,SAAS,IAA2D;EAOlE,OANA,AACE,MAAe,EAAyB,GAAS,CAAM,EAAE,OAAO,MAAiB;GAE/E,MADA,IAAe,MACT;EACR,CAAC,GAEI;CACT;CAEA,SAAS,EAAgB,GAAsC;EAC7D,IAAM,IAAW,EAAkB,GAAQ,CAAU;EACrD,IAAI,CAAC,GACH,MAAM,IAAI,EACR,cACA,iCACA,WAAW,EAAO,0CAA0C,EAAW,GACzE;EAEF,OAAO;CACT;CAEA,SAAS,EAAoB,GAA4B;EACvD,IAAM,IAAS,EAAc,CAAU;EACvC,IAAI,CAAC,GACH,MAAM,IAAI,EACR,cACA,0BACA,2CAA2C,EAAW,GACxD;EAEF,OAAO;CACT;CAEA,OAAO;EACL,IAAI,WAAW;EACf,YAAY;EACZ,sBAAsB,EAA+B,CAAM;EAC3D,sBAAsB;EAEtB,MAAM,UAAU,GAAuD;GACrE,IAAM,IAAe,EAAc,CAAU;GAC7C,IAAI,CAAC,GAAc;GAEnB,IAAM,KAAQ,MAAM,EAAgB,GAAG,IAAI,EAAa,YAAY,CAAC;GACrE,IAAI,CAAC,GAAM;GAEX,IAAM,IAAc,EAAK,aAAa,EAAK,aAAa,GAAG,EAAK,UAAU,KAAK,EAAK,eAAe,EAAK;GAExG,OAAO;IACL;IACA,cAAc,EAAK;IACnB;IACA,gBAAgB,EAAK;IAErB,iBAAiB;GACnB;EACF;EAEA,MAAM,WAAW,GAA2E;GAC1F,IAAM,EAAE,eAAY,eAAY,SAAM,OAAI,UAAO,cAAW,GACtD,IAAW,EAAgB,CAAU,GACrC,IAAS,EAAoB,CAAU,GACvC,IAAS,KAAS,IAAQ,IAAI,IAAQ,UAEtC,IAAoB,CAAC,GAUvB,IAAY,IAAK;GAErB,KAAK,IAAI,IAAO,GAAG,IAAA,MACb,MAAY,IAD2B,KAAQ;IAGnD,IAAM,IAAY,IAAS,EAAQ,QAC7B,IAAe,KAAK,IAAI,GAAG,KAAK,IAAI,GAAU,CAAS,CAAC,GAExD,IAAQ,MAAM,EAAmB;KACrC;KACA;KACA;KACA;KACA,SAAS;KACT,OAAO;KACP;IACF,CAAC,GACK,IAAS,EAAM;IAOrB,IANI,CAAC,MAEL,EAAQ,QAAQ,GAAG,EAAM,QAAQ,MAAW,EAAO,QAAQ,KAAQ,EAAO,OAAO,CAAE,CAAC,GAGhF,EAAO,QAAQ,KAAQ,EAAM,SAAS,MACtC,EAAQ,UAAU,GAAQ;IAE9B,IAAM,IAAa,EAAO,OAAO;IAEjC,IAAI,KAAc,GAAW;IAC7B,IAAY;GACd;GAEA,OAAO;IACL;IAMA,YAAY,EAAQ,WAAW;GACjC;EACF;EAEA,aAAa,GAAyD;GACpE,IAAM,EAAE,eAAY,eAAY,aAAU,YAAS,mBAAgB,eAAY;GAE/E,OAAO,EAAmB;IACxB;IACA,QAAQ,EAAoB,CAAU;IACtC,UAAU,EAAgB,CAAU;IACpC,sBAAsB,EAA4B,EAAW,oBAAoB;IACjF;IACA;IACA;IACA;GACF,CAAC;EACH;CACF;AACF"}
1
+ {"version":3,"file":"create-binance-candle-source.js","names":[],"sources":["../../../../src/candles/sources/binance/create-binance-candle-source.ts"],"sourcesContent":["import { SymmError } from \"../../../shared/errors/symm-error\";\nimport type { WebSocketConstructor } from \"../../../shared/types/websocket\";\nimport type { Unwatch } from \"../../../websocket/notifications/watch-notifications\";\nimport type {\n Candle,\n CandleResolution,\n CandleSource,\n CandleSymbol,\n GetCandlesParameters,\n GetCandlesReturnType,\n WatchCandlesParameters,\n} from \"../../types\";\nimport {\n BINANCE_MAX_LIMIT,\n BINANCE_MAX_PAGES,\n BINANCE_REST_URL,\n BINANCE_WS_URL,\n type BinanceMarket,\n} from \"./constants\";\nimport { fetchBinanceExchangeInfo, type BinanceSymbolInfo } from \"./fetch-binance-exchange-info\";\nimport { fetchBinanceKlines } from \"./fetch-binance-klines\";\nimport { getBinanceSupportedResolutions, toBinanceInterval } from \"./map-resolution\";\nimport { watchBinanceKlines } from \"./watch-binance-klines\";\n\n/**\n * Parameters for {@link createBinanceCandleSource}.\n */\nexport interface BinanceCandleSourceParameters {\n /**\n * Which Binance market to read. Defaults to `\"usd-m-futures\"` — its symbols\n * are perpetual contracts, matching what a SYMMIO market actually is.\n */\n market?: BinanceMarket;\n /** Override the REST host (a regional mirror, or your own caching proxy). */\n restUrl?: string;\n /** Override the WebSocket endpoint. */\n wsUrl?: string;\n /**\n * Map a SYMMIO market name onto a Binance symbol, or return `undefined` when\n * the market has no Binance listing.\n *\n * Defaults to an upper-case identity mapping, which holds for current SYMMIO\n * deployments where market names are already Binance USD-M symbols. Override\n * it rather than relying on that coincidence if your deployment's names can\n * diverge — an unmapped name otherwise resolves to a symbol that does not\n * exist and the chart simply stays empty.\n */\n resolveSymbol?: (marketName: string) => string | undefined;\n /**\n * WebSocket implementation for {@link CandleSource.watchCandles}. Defaults to\n * `globalThis.WebSocket`; pass the `ws` package in Node environments without one.\n */\n webSocketConstructor?: WebSocketConstructor;\n}\n\nfunction defaultResolveSymbol(marketName: string): string {\n return marketName.toUpperCase();\n}\n\nfunction resolveWebSocketConstructor(injected?: WebSocketConstructor): WebSocketConstructor {\n const ctor = injected ?? (globalThis as { WebSocket?: WebSocketConstructor }).WebSocket;\n if (!ctor) {\n throw new SymmError(\n \"config\",\n \"NO_WEBSOCKET_IMPLEMENTATION\",\n \"No WebSocket implementation available. Pass `webSocketConstructor` to createBinanceCandleSource (e.g. the `ws` package in Node).\",\n );\n }\n return ctor;\n}\n\n/**\n * Create a {@link CandleSource} backed by Binance klines.\n *\n * History comes from the REST `/klines` endpoint, paged backwards from the end\n * of the requested range, and live bars from the kline WebSocket stream. Both\n * are reachable directly from a browser — Binance serves permissive CORS\n * headers on market data, so no proxy or API key is involved.\n *\n * Two caveats worth surfacing to users of a chart built on this:\n * - The series is `priceBasis: \"reference-exchange\"`. It is Binance's perp\n * price, not the SYMMIO solver's mark price that a trade actually settles at.\n * - `api.binance.com` and `fapi.binance.com` are blocked in some jurisdictions.\n * Supply `restUrl`/`wsUrl` to route through your own proxy where that matters.\n *\n * @param parameters - Market selection, endpoint overrides, and symbol mapping.\n * @returns A source usable by `getCandlesQueryOptions`, `useCandles`, or\n * `toTradingViewDatafeed`.\n *\n * @example\n * ```ts\n * const source = createBinanceCandleSource();\n * const { candles } = await source.getCandles({\n * marketName: \"BTCUSDT\",\n * resolution: \"1m\",\n * from: Date.now() - 60 * 60 * 1000,\n * to: Date.now(),\n * limit: 60,\n * });\n * ```\n */\nexport function createBinanceCandleSource(parameters: BinanceCandleSourceParameters = {}): CandleSource {\n const market = parameters.market ?? \"usd-m-futures\";\n const restUrl = parameters.restUrl ?? BINANCE_REST_URL[market];\n const wsUrl = parameters.wsUrl ?? BINANCE_WS_URL[market];\n const resolveSymbol = parameters.resolveSymbol ?? defaultResolveSymbol;\n const maxLimit = BINANCE_MAX_LIMIT[market];\n\n /**\n * `exchangeInfo` lists every contract on the venue and only changes on a\n * listing or delisting, so it is fetched once per source and shared by every\n * `getSymbol` call. The promise itself is cached so concurrent callers during\n * the first load share one request; a rejection clears it so a transient\n * failure does not poison the source for its lifetime.\n */\n let exchangeInfo: Promise<Map<string, BinanceSymbolInfo>> | null = null;\n\n function getExchangeInfo(): Promise<Map<string, BinanceSymbolInfo>> {\n if (!exchangeInfo) {\n exchangeInfo = fetchBinanceExchangeInfo(restUrl, market).catch((err: unknown) => {\n exchangeInfo = null;\n throw err;\n });\n }\n return exchangeInfo;\n }\n\n function requireInterval(resolution: CandleResolution): string {\n const interval = toBinanceInterval(market, resolution);\n if (!interval) {\n throw new SymmError(\n \"validation\",\n \"UNSUPPORTED_CANDLE_RESOLUTION\",\n `Binance ${market} has no klines interval for resolution \"${resolution}\".`,\n );\n }\n return interval;\n }\n\n function requireSourceSymbol(marketName: string): string {\n const symbol = resolveSymbol(marketName);\n if (!symbol) {\n throw new SymmError(\n \"validation\",\n \"UNMAPPED_CANDLE_MARKET\",\n `No Binance symbol is mapped for market \"${marketName}\".`,\n );\n }\n return symbol;\n }\n\n return {\n id: `binance:${market}`,\n priceBasis: \"reference-exchange\",\n supportedResolutions: getBinanceSupportedResolutions(market),\n maxCandlesPerRequest: maxLimit,\n\n async getSymbol(marketName: string): Promise<CandleSymbol | undefined> {\n const sourceSymbol = resolveSymbol(marketName);\n if (!sourceSymbol) return undefined;\n\n const info = (await getExchangeInfo()).get(sourceSymbol.toUpperCase());\n if (!info) return undefined;\n\n const description = info.baseAsset && info.quoteAsset ? `${info.baseAsset} / ${info.quoteAsset}` : info.symbol;\n\n return {\n marketName,\n sourceSymbol: info.symbol,\n description,\n pricePrecision: info.pricePrecision,\n /** Binance reports base-asset volume; two decimals reads well for every listed contract. */\n volumePrecision: 2,\n volumeUnit: \"base\",\n volumeCurrency: info.baseAsset,\n };\n },\n\n async getCandles(getCandlesParameters: GetCandlesParameters): Promise<GetCandlesReturnType> {\n const { marketName, resolution, from, to, limit, signal } = getCandlesParameters;\n const interval = requireInterval(resolution);\n const symbol = requireSourceSymbol(marketName);\n const wanted = limit && limit > 0 ? limit : Number.POSITIVE_INFINITY;\n\n const candles: Candle[] = [];\n\n /**\n * Paged backwards from `to`, not forwards from `from`. Binance caps a\n * range request from its *start*: sending `startTime`, `endTime` and\n * `limit` together returns the OLDEST `limit` bars in the window, which\n * for a chart is the wrong end entirely. Sending `endTime` alone returns\n * the newest bars ending there, which is what a chart scrolling back\n * actually needs; the `from` bound is then applied client-side.\n */\n let cursorEnd = to - 1;\n\n for (let page = 0; page < BINANCE_MAX_PAGES; page++) {\n if (cursorEnd < from) break;\n\n const remaining = wanted - candles.length;\n const requestLimit = Math.max(1, Math.min(maxLimit, remaining));\n\n const batch = await fetchBinanceKlines({\n restUrl,\n market,\n symbol,\n interval,\n endTime: cursorEnd,\n limit: requestLimit,\n signal,\n });\n const oldest = batch[0];\n if (!oldest) break;\n\n candles.unshift(...batch.filter((candle) => candle.time >= from && candle.time < to));\n\n /** Reached the requested start, or the venue has nothing older. */\n if (oldest.time <= from || batch.length < requestLimit) break;\n if (candles.length >= wanted) break;\n\n const nextCursor = oldest.time - 1;\n /** No-progress guard: without it a venue quirk could spin the loop. */\n if (nextCursor >= cursorEnd) break;\n cursorEnd = nextCursor;\n }\n\n return {\n candles,\n /**\n * An empty result is the venue saying it has nothing in this window —\n * for a 24/7 market that means the range predates the listing, so a\n * chart paging backwards should stop rather than keep asking.\n */\n noMoreData: candles.length === 0,\n };\n },\n\n watchCandles(watchCandlesParameters: WatchCandlesParameters): Unwatch {\n const { marketName, resolution, onCandle, onReset, onStatusChange, onError } = watchCandlesParameters;\n\n return watchBinanceKlines({\n wsUrl,\n symbol: requireSourceSymbol(marketName),\n interval: requireInterval(resolution),\n webSocketConstructor: resolveWebSocketConstructor(parameters.webSocketConstructor),\n onCandle,\n onReset,\n onStatusChange,\n onError,\n });\n },\n };\n}\n"],"mappings":";;;;;;;AAuDA,SAAS,EAAqB,GAA4B;CACxD,OAAO,EAAW,YAAY;AAChC;AAEA,SAAS,EAA4B,GAAuD;CAC1F,IAAM,IAAO,KAAa,WAAoD;CAC9E,IAAI,CAAC,GACH,MAAM,IAAI,EACR,UACA,+BACA,kIACF;CAEF,OAAO;AACT;AAgCA,SAAgB,EAA0B,IAA4C,CAAC,GAAiB;CACtG,IAAM,IAAS,EAAW,UAAU,iBAC9B,IAAU,EAAW,WAAW,EAAiB,IACjD,IAAQ,EAAW,SAAS,EAAe,IAC3C,IAAgB,EAAW,iBAAiB,GAC5C,IAAW,EAAkB,IAS/B,IAA+D;CAEnE,SAAS,IAA2D;EAOlE,OANA,AACE,MAAe,EAAyB,GAAS,CAAM,EAAE,OAAO,MAAiB;GAE/E,MADA,IAAe,MACT;EACR,CAAC,GAEI;CACT;CAEA,SAAS,EAAgB,GAAsC;EAC7D,IAAM,IAAW,EAAkB,GAAQ,CAAU;EACrD,IAAI,CAAC,GACH,MAAM,IAAI,EACR,cACA,iCACA,WAAW,EAAO,0CAA0C,EAAW,GACzE;EAEF,OAAO;CACT;CAEA,SAAS,EAAoB,GAA4B;EACvD,IAAM,IAAS,EAAc,CAAU;EACvC,IAAI,CAAC,GACH,MAAM,IAAI,EACR,cACA,0BACA,2CAA2C,EAAW,GACxD;EAEF,OAAO;CACT;CAEA,OAAO;EACL,IAAI,WAAW;EACf,YAAY;EACZ,sBAAsB,EAA+B,CAAM;EAC3D,sBAAsB;EAEtB,MAAM,UAAU,GAAuD;GACrE,IAAM,IAAe,EAAc,CAAU;GAC7C,IAAI,CAAC,GAAc;GAEnB,IAAM,KAAQ,MAAM,EAAgB,GAAG,IAAI,EAAa,YAAY,CAAC;GACrE,IAAI,CAAC,GAAM;GAEX,IAAM,IAAc,EAAK,aAAa,EAAK,aAAa,GAAG,EAAK,UAAU,KAAK,EAAK,eAAe,EAAK;GAExG,OAAO;IACL;IACA,cAAc,EAAK;IACnB;IACA,gBAAgB,EAAK;IAErB,iBAAiB;IACjB,YAAY;IACZ,gBAAgB,EAAK;GACvB;EACF;EAEA,MAAM,WAAW,GAA2E;GAC1F,IAAM,EAAE,eAAY,eAAY,SAAM,OAAI,UAAO,cAAW,GACtD,IAAW,EAAgB,CAAU,GACrC,IAAS,EAAoB,CAAU,GACvC,IAAS,KAAS,IAAQ,IAAI,IAAQ,UAEtC,IAAoB,CAAC,GAUvB,IAAY,IAAK;GAErB,KAAK,IAAI,IAAO,GAAG,IAAA,MACb,MAAY,IAD2B,KAAQ;IAGnD,IAAM,IAAY,IAAS,EAAQ,QAC7B,IAAe,KAAK,IAAI,GAAG,KAAK,IAAI,GAAU,CAAS,CAAC,GAExD,IAAQ,MAAM,EAAmB;KACrC;KACA;KACA;KACA;KACA,SAAS;KACT,OAAO;KACP;IACF,CAAC,GACK,IAAS,EAAM;IAOrB,IANI,CAAC,MAEL,EAAQ,QAAQ,GAAG,EAAM,QAAQ,MAAW,EAAO,QAAQ,KAAQ,EAAO,OAAO,CAAE,CAAC,GAGhF,EAAO,QAAQ,KAAQ,EAAM,SAAS,MACtC,EAAQ,UAAU,GAAQ;IAE9B,IAAM,IAAa,EAAO,OAAO;IAEjC,IAAI,KAAc,GAAW;IAC7B,IAAY;GACd;GAEA,OAAO;IACL;IAMA,YAAY,EAAQ,WAAW;GACjC;EACF;EAEA,aAAa,GAAyD;GACpE,IAAM,EAAE,eAAY,eAAY,aAAU,YAAS,mBAAgB,eAAY;GAE/E,OAAO,EAAmB;IACxB;IACA,QAAQ,EAAoB,CAAU;IACtC,UAAU,EAAgB,CAAU;IACpC,sBAAsB,EAA4B,EAAW,oBAAoB;IACjF;IACA;IACA;IACA;GACF,CAAC;EACH;CACF;AACF"}
@@ -0,0 +1,35 @@
1
+ import { SolverId } from '../../../core/chains/types.js';
2
+ import { Config } from '../../../core/config/index.js';
3
+ import { CandleSource } from '../../types.js';
4
+ /** Options for {@link createLowcapCandleSource}. Endpoints come from the SDK config. */
5
+ export interface LowcapCandleSourceParameters {
6
+ /** Target chain. Defaults to the config's default chain. */
7
+ chainId?: number;
8
+ /** Solver whose price service to use. Defaults to the chain's default solver. */
9
+ solverId?: SolverId;
10
+ /** Include flat candles. Defaults to false; sent explicitly on every history request. */
11
+ includeFlat?: boolean;
12
+ /** Recent OHLCV reconciliation interval in milliseconds. Defaults to 30_000; minimum 1_000. */
13
+ refreshIntervalMs?: number;
14
+ }
15
+ /**
16
+ * Create a lowcap candle source backed by the configured public price service.
17
+ *
18
+ * Resolves full market names to symbol addresses, requests final-price OHLCV,
19
+ * and reports quote volume in USD. Listings are reused for 60 seconds per source;
20
+ * history is not cached. Empty windows do
21
+ * not prove exhaustion: `noMoreData` is true only when the service confirms it.
22
+ * Live prices form provisional candles; HTTP refreshes reconcile OHLCV.
23
+ *
24
+ * @param config - SDK configuration supplying matching REST and WebSocket endpoints.
25
+ * @param parameters - Chain, solver, flat-candle policy, and refresh interval.
26
+ * @returns A source for history hooks, stream hooks, and chart adapters.
27
+ * @throws {SymmError} for invalid options. Unsupported deployments fail when a source method is called.
28
+ * @example
29
+ * ```ts
30
+ * const source = createLowcapCandleSource(config);
31
+ * const history = await source.getCandles({ marketName, resolution: "1h", from, to });
32
+ * ```
33
+ */
34
+ export declare function createLowcapCandleSource(config: Config, parameters?: LowcapCandleSourceParameters): CandleSource;
35
+ //# sourceMappingURL=create-lowcap-candle-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-lowcap-candle-source.d.ts","sourceRoot":"","sources":["../../../../src/candles/sources/lowcap/create-lowcap-candle-source.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAInD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAOhD,wFAAwF;AACxF,MAAM,WAAW,4BAA4B;IAC3C,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iFAAiF;IACjF,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,yFAAyF;IACzF,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,+FAA+F;IAC/F,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,GAAE,4BAAiC,GAAG,YAAY,CA8GpH"}
@@ -0,0 +1,104 @@
1
+ import { SymmError as e } from "../../../shared/errors/symm-error.js";
2
+ import { assertPriceServiceProvider as t } from "../../../price-service/assert-price-service-provider.js";
3
+ import { resolvePriceService as n } from "../../../price-service/resolve-price-service.js";
4
+ import { createLowcapSymbolLoader as r } from "./create-lowcap-symbol-loader.js";
5
+ import { getLowcapSupportedResolutions as i, toLowcapTimeframe as a } from "./map-resolution.js";
6
+ import { LOWCAP_HISTORY_WINDOW_INTERVALS as o, getLowcapCandles as s } from "./get-lowcap-candles.js";
7
+ import { resolveLowcapSymbol as c } from "./resolve-lowcap-symbol.js";
8
+ import { watchLowcapCandles as l } from "./watch-lowcap-candles.js";
9
+ import { hash as u } from "ohash";
10
+ //#region src/candles/sources/lowcap/create-lowcap-candle-source.ts
11
+ function d(d, f = {}) {
12
+ let { chainId: p, solverId: m, includeFlat: h = !1, refreshIntervalMs: g = 3e4 } = f;
13
+ if (typeof h != "boolean") throw new e("validation", "INVALID_ENIGMA_OHLCV_FLAT_ENABLE", "includeFlat must be true or false.");
14
+ if (!Number.isSafeInteger(g) || g < 1e3 || g > 2147483647) throw new e("validation", "INVALID_CANDLE_REFRESH_INTERVAL", "refreshIntervalMs must be an integer from 1000 to 2147483647.");
15
+ function _() {
16
+ try {
17
+ let e = n(d, {
18
+ chainId: p,
19
+ solverId: m
20
+ });
21
+ return t(e, "enigma", "createLowcapCandleSource"), { value: e };
22
+ } catch (t) {
23
+ if (!(t instanceof e) || t.kind !== "config") throw t;
24
+ return { error: t };
25
+ }
26
+ }
27
+ let v = _();
28
+ function y() {
29
+ if (!v.value) throw v.error;
30
+ return v.value;
31
+ }
32
+ let b;
33
+ async function x(e, t) {
34
+ t?.throwIfAborted(), b ??= r(y().url);
35
+ let n = await b(t);
36
+ return t?.throwIfAborted(), c(n, e);
37
+ }
38
+ async function S(t, n) {
39
+ let r = await x(t, n);
40
+ if (!r) throw new e("validation", "UNMAPPED_CANDLE_MARKET", `No lowcap market matches the full name "${t}".`);
41
+ return r;
42
+ }
43
+ return {
44
+ id: `lowcap:${u({
45
+ ...v.value ? {
46
+ url: v.value.url,
47
+ wsUrl: v.value.wsUrl
48
+ } : {
49
+ chainId: p ?? d.defaultChainId,
50
+ solverId: m,
51
+ error: v.error?.code
52
+ },
53
+ includeFlat: h
54
+ })}`,
55
+ priceBasis: "price-service",
56
+ supportedResolutions: i(),
57
+ maxCandlesPerRequest: o,
58
+ async getSymbol(e) {
59
+ let t = await x(e);
60
+ return t ? {
61
+ marketName: t.name,
62
+ sourceSymbol: t.address,
63
+ description: t.name,
64
+ pricePrecision: 8,
65
+ volumePrecision: 2,
66
+ volumeUnit: "quote",
67
+ volumeCurrency: "USD"
68
+ } : void 0;
69
+ },
70
+ async getCandles(e) {
71
+ let t = await S(e.marketName, e.signal);
72
+ return s({
73
+ ...e,
74
+ baseURL: y().url,
75
+ symbolAddress: t.address,
76
+ includeFlat: h
77
+ });
78
+ },
79
+ watchCandles(t) {
80
+ let n = y();
81
+ if (!a(t.resolution)) throw new e("validation", "UNSUPPORTED_CANDLE_RESOLUTION", `Unsupported lowcap resolution: ${t.resolution}.`);
82
+ return l(d, {
83
+ ...t,
84
+ chainId: p,
85
+ solverId: m,
86
+ includeFlat: h,
87
+ refreshIntervalMs: g,
88
+ resolveAddress: async (e) => (await S(t.marketName, e)).address,
89
+ getHistory: (e, r) => s({
90
+ ...r,
91
+ marketName: t.marketName,
92
+ resolution: t.resolution,
93
+ baseURL: n.url,
94
+ symbolAddress: e,
95
+ includeFlat: h
96
+ })
97
+ });
98
+ }
99
+ };
100
+ }
101
+ //#endregion
102
+ export { d as createLowcapCandleSource };
103
+
104
+ //# sourceMappingURL=create-lowcap-candle-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-lowcap-candle-source.js","names":[],"sources":["../../../../src/candles/sources/lowcap/create-lowcap-candle-source.ts"],"sourcesContent":["import { hash } from \"ohash\";\nimport type { SolverId } from \"../../../core/chains/types\";\nimport type { Config } from \"../../../core/config\";\nimport { assertPriceServiceProvider } from \"../../../price-service/assert-price-service-provider\";\nimport { resolvePriceService } from \"../../../price-service/resolve-price-service\";\nimport { SymmError } from \"../../../shared/errors/symm-error\";\nimport type { CandleSource } from \"../../types\";\nimport { createLowcapSymbolLoader } from \"./create-lowcap-symbol-loader\";\nimport { getLowcapCandles, LOWCAP_HISTORY_WINDOW_INTERVALS } from \"./get-lowcap-candles\";\nimport { getLowcapSupportedResolutions, toLowcapTimeframe } from \"./map-resolution\";\nimport { resolveLowcapSymbol } from \"./resolve-lowcap-symbol\";\nimport { watchLowcapCandles } from \"./watch-lowcap-candles\";\n\n/** Options for {@link createLowcapCandleSource}. Endpoints come from the SDK config. */\nexport interface LowcapCandleSourceParameters {\n /** Target chain. Defaults to the config's default chain. */\n chainId?: number;\n /** Solver whose price service to use. Defaults to the chain's default solver. */\n solverId?: SolverId;\n /** Include flat candles. Defaults to false; sent explicitly on every history request. */\n includeFlat?: boolean;\n /** Recent OHLCV reconciliation interval in milliseconds. Defaults to 30_000; minimum 1_000. */\n refreshIntervalMs?: number;\n}\n\n/**\n * Create a lowcap candle source backed by the configured public price service.\n *\n * Resolves full market names to symbol addresses, requests final-price OHLCV,\n * and reports quote volume in USD. Listings are reused for 60 seconds per source;\n * history is not cached. Empty windows do\n * not prove exhaustion: `noMoreData` is true only when the service confirms it.\n * Live prices form provisional candles; HTTP refreshes reconcile OHLCV.\n *\n * @param config - SDK configuration supplying matching REST and WebSocket endpoints.\n * @param parameters - Chain, solver, flat-candle policy, and refresh interval.\n * @returns A source for history hooks, stream hooks, and chart adapters.\n * @throws {SymmError} for invalid options. Unsupported deployments fail when a source method is called.\n * @example\n * ```ts\n * const source = createLowcapCandleSource(config);\n * const history = await source.getCandles({ marketName, resolution: \"1h\", from, to });\n * ```\n */\nexport function createLowcapCandleSource(config: Config, parameters: LowcapCandleSourceParameters = {}): CandleSource {\n const { chainId, solverId, includeFlat = false, refreshIntervalMs = 30_000 } = parameters;\n if (typeof includeFlat !== \"boolean\") {\n throw new SymmError(\"validation\", \"INVALID_ENIGMA_OHLCV_FLAT_ENABLE\", \"includeFlat must be true or false.\");\n }\n if (!Number.isSafeInteger(refreshIntervalMs) || refreshIntervalMs < 1_000 || refreshIntervalMs > 2_147_483_647) {\n throw new SymmError(\n \"validation\",\n \"INVALID_CANDLE_REFRESH_INTERVAL\",\n \"refreshIntervalMs must be an integer from 1000 to 2147483647.\",\n );\n }\n\n function resolveService() {\n try {\n const value = resolvePriceService(config, { chainId, solverId });\n assertPriceServiceProvider(value, \"enigma\", \"createLowcapCandleSource\");\n return { value };\n } catch (error) {\n if (!(error instanceof SymmError) || error.kind !== \"config\") throw error;\n return { error };\n }\n }\n const resolved = resolveService();\n function requireService() {\n if (!resolved.value) throw resolved.error;\n return resolved.value;\n }\n let loadSymbols: ReturnType<typeof createLowcapSymbolLoader> | undefined;\n\n async function findSymbol(marketName: string, signal?: AbortSignal) {\n signal?.throwIfAborted();\n loadSymbols ??= createLowcapSymbolLoader(requireService().url);\n const symbols = await loadSymbols(signal);\n signal?.throwIfAborted();\n return resolveLowcapSymbol(symbols, marketName);\n }\n\n async function requireSymbol(marketName: string, signal?: AbortSignal) {\n const symbol = await findSymbol(marketName, signal);\n if (!symbol)\n throw new SymmError(\n \"validation\",\n \"UNMAPPED_CANDLE_MARKET\",\n `No lowcap market matches the full name \"${marketName}\".`,\n );\n return symbol;\n }\n\n return {\n id: `lowcap:${hash({\n ...(resolved.value\n ? { url: resolved.value.url, wsUrl: resolved.value.wsUrl }\n : { chainId: chainId ?? config.defaultChainId, solverId, error: resolved.error?.code }),\n includeFlat,\n })}`,\n priceBasis: \"price-service\",\n supportedResolutions: getLowcapSupportedResolutions(),\n maxCandlesPerRequest: LOWCAP_HISTORY_WINDOW_INTERVALS,\n async getSymbol(marketName) {\n const symbol = await findSymbol(marketName);\n return symbol\n ? {\n marketName: symbol.name,\n sourceSymbol: symbol.address,\n description: symbol.name,\n pricePrecision: 8,\n volumePrecision: 2,\n volumeUnit: \"quote\",\n volumeCurrency: \"USD\",\n }\n : undefined;\n },\n async getCandles(request) {\n const symbol = await requireSymbol(request.marketName, request.signal);\n return getLowcapCandles({\n ...request,\n baseURL: requireService().url,\n symbolAddress: symbol.address,\n includeFlat,\n });\n },\n watchCandles(request) {\n const service = requireService();\n if (!toLowcapTimeframe(request.resolution)) {\n throw new SymmError(\n \"validation\",\n \"UNSUPPORTED_CANDLE_RESOLUTION\",\n `Unsupported lowcap resolution: ${request.resolution}.`,\n );\n }\n return watchLowcapCandles(config, {\n ...request,\n chainId,\n solverId,\n includeFlat,\n refreshIntervalMs,\n resolveAddress: async (signal) => (await requireSymbol(request.marketName, signal)).address,\n getHistory: (symbolAddress, range) =>\n getLowcapCandles({\n ...range,\n marketName: request.marketName,\n resolution: request.resolution,\n baseURL: service.url,\n symbolAddress,\n includeFlat,\n }),\n });\n },\n };\n}\n"],"mappings":";;;;;;;;;;AA4CA,SAAgB,EAAyB,GAAgB,IAA2C,CAAC,GAAiB;CACpH,IAAM,EAAE,YAAS,aAAU,iBAAc,IAAO,uBAAoB,QAAW;CAC/E,IAAI,OAAO,KAAgB,WACzB,MAAM,IAAI,EAAU,cAAc,oCAAoC,oCAAoC;CAE5G,IAAI,CAAC,OAAO,cAAc,CAAiB,KAAK,IAAoB,OAAS,IAAoB,YAC/F,MAAM,IAAI,EACR,cACA,mCACA,+DACF;CAGF,SAAS,IAAiB;EACxB,IAAI;GACF,IAAM,IAAQ,EAAoB,GAAQ;IAAE;IAAS;GAAS,CAAC;GAE/D,OADA,EAA2B,GAAO,UAAU,0BAA0B,GAC/D,EAAE,SAAM;EACjB,SAAS,GAAO;GACd,IAAI,EAAE,aAAiB,MAAc,EAAM,SAAS,UAAU,MAAM;GACpE,OAAO,EAAE,SAAM;EACjB;CACF;CACA,IAAM,IAAW,EAAe;CAChC,SAAS,IAAiB;EACxB,IAAI,CAAC,EAAS,OAAO,MAAM,EAAS;EACpC,OAAO,EAAS;CAClB;CACA,IAAI;CAEJ,eAAe,EAAW,GAAoB,GAAsB;EAElE,AADA,GAAQ,eAAe,GACvB,MAAgB,EAAyB,EAAe,EAAE,GAAG;EAC7D,IAAM,IAAU,MAAM,EAAY,CAAM;EAExC,OADA,GAAQ,eAAe,GAChB,EAAoB,GAAS,CAAU;CAChD;CAEA,eAAe,EAAc,GAAoB,GAAsB;EACrE,IAAM,IAAS,MAAM,EAAW,GAAY,CAAM;EAClD,IAAI,CAAC,GACH,MAAM,IAAI,EACR,cACA,0BACA,2CAA2C,EAAW,GACxD;EACF,OAAO;CACT;CAEA,OAAO;EACL,IAAI,UAAU,EAAK;GACjB,GAAI,EAAS,QACT;IAAE,KAAK,EAAS,MAAM;IAAK,OAAO,EAAS,MAAM;GAAM,IACvD;IAAE,SAAS,KAAW,EAAO;IAAgB;IAAU,OAAO,EAAS,OAAO;GAAK;GACvF;EACF,CAAC;EACD,YAAY;EACZ,sBAAsB,EAA8B;EACpD,sBAAsB;EACtB,MAAM,UAAU,GAAY;GAC1B,IAAM,IAAS,MAAM,EAAW,CAAU;GAC1C,OAAO,IACH;IACE,YAAY,EAAO;IACnB,cAAc,EAAO;IACrB,aAAa,EAAO;IACpB,gBAAgB;IAChB,iBAAiB;IACjB,YAAY;IACZ,gBAAgB;GAClB,IACA,KAAA;EACN;EACA,MAAM,WAAW,GAAS;GACxB,IAAM,IAAS,MAAM,EAAc,EAAQ,YAAY,EAAQ,MAAM;GACrE,OAAO,EAAiB;IACtB,GAAG;IACH,SAAS,EAAe,EAAE;IAC1B,eAAe,EAAO;IACtB;GACF,CAAC;EACH;EACA,aAAa,GAAS;GACpB,IAAM,IAAU,EAAe;GAC/B,IAAI,CAAC,EAAkB,EAAQ,UAAU,GACvC,MAAM,IAAI,EACR,cACA,iCACA,kCAAkC,EAAQ,WAAW,EACvD;GAEF,OAAO,EAAmB,GAAQ;IAChC,GAAG;IACH;IACA;IACA;IACA;IACA,gBAAgB,OAAO,OAAY,MAAM,EAAc,EAAQ,YAAY,CAAM,GAAG;IACpF,aAAa,GAAe,MAC1B,EAAiB;KACf,GAAG;KACH,YAAY,EAAQ;KACpB,YAAY,EAAQ;KACpB,SAAS,EAAQ;KACjB;KACA;IACF,CAAC;GACL,CAAC;EACH;CACF;AACF"}
@@ -0,0 +1,4 @@
1
+ import { EnigmaSymbolInfo } from '../../../price-service/enigma/symbols-info/get-enigma-price-service-symbols-info.js';
2
+ /** Source-local metadata reuse. Cancelling one reader never cancels another reader's request. @internal */
3
+ export declare function createLowcapSymbolLoader(baseURL: string): (signal?: AbortSignal) => Promise<EnigmaSymbolInfo[]>;
4
+ //# sourceMappingURL=create-lowcap-symbol-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-lowcap-symbol-loader.d.ts","sourceRoot":"","sources":["../../../../src/candles/sources/lowcap/create-lowcap-symbol-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,gBAAgB,EACtB,MAAM,kFAAkF,CAAC;AAQ1F,2GAA2G;AAC3G,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,IAI1B,SAAS,WAAW,KAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAkD/E"}
@@ -0,0 +1,40 @@
1
+ import { fetchEnigmaPriceServiceSymbolsInfo as e } from "../../../price-service/enigma/symbols-info/get-enigma-price-service-symbols-info.js";
2
+ //#region src/candles/sources/lowcap/create-lowcap-symbol-loader.ts
3
+ function t(t) {
4
+ let n, r;
5
+ return function(i) {
6
+ if (i?.throwIfAborted(), n && n.expires > Date.now()) return Promise.resolve(n.symbols);
7
+ if (!r) {
8
+ let i = new AbortController(), a = {
9
+ controller: i,
10
+ readers: 0,
11
+ promise: e(t, i.signal).then((e) => (i.signal.throwIfAborted(), n = {
12
+ symbols: e,
13
+ expires: Date.now() + 6e4
14
+ }, e)).finally(() => {
15
+ r === a && (r = void 0);
16
+ })
17
+ };
18
+ r = a;
19
+ }
20
+ let a = r;
21
+ return a.readers++, new Promise((e, t) => {
22
+ let n = !1;
23
+ function o() {
24
+ return n ? !1 : (n = !0, i?.removeEventListener("abort", s), a.readers--, a.readers === 0 && r === a && (r = void 0, a.controller.abort()), !0);
25
+ }
26
+ function s() {
27
+ o() && t(i?.reason);
28
+ }
29
+ i?.addEventListener("abort", s, { once: !0 }), i?.aborted && s(), a.promise.then((t) => {
30
+ o() && e(t);
31
+ }, (e) => {
32
+ o() && t(e);
33
+ });
34
+ });
35
+ };
36
+ }
37
+ //#endregion
38
+ export { t as createLowcapSymbolLoader };
39
+
40
+ //# sourceMappingURL=create-lowcap-symbol-loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-lowcap-symbol-loader.js","names":[],"sources":["../../../../src/candles/sources/lowcap/create-lowcap-symbol-loader.ts"],"sourcesContent":["import {\n fetchEnigmaPriceServiceSymbolsInfo,\n type EnigmaSymbolInfo,\n} from \"../../../price-service/enigma/symbols-info/get-enigma-price-service-symbols-info\";\n\ninterface Pending {\n controller: AbortController;\n promise: Promise<EnigmaSymbolInfo[]>;\n readers: number;\n}\n\n/** Source-local metadata reuse. Cancelling one reader never cancels another reader's request. @internal */\nexport function createLowcapSymbolLoader(baseURL: string) {\n let cached: { symbols: EnigmaSymbolInfo[]; expires: number } | undefined;\n let pending: Pending | undefined;\n\n return function loadSymbols(signal?: AbortSignal): Promise<EnigmaSymbolInfo[]> {\n signal?.throwIfAborted();\n if (cached && cached.expires > Date.now()) return Promise.resolve(cached.symbols);\n if (!pending) {\n const controller = new AbortController();\n const request: Pending = {\n controller,\n readers: 0,\n promise: fetchEnigmaPriceServiceSymbolsInfo(baseURL, controller.signal)\n .then((symbols) => {\n controller.signal.throwIfAborted();\n cached = { symbols, expires: Date.now() + 60_000 };\n return symbols;\n })\n .finally(() => {\n if (pending === request) pending = undefined;\n }),\n };\n pending = request;\n }\n const request = pending;\n request.readers++;\n return new Promise((resolve, reject) => {\n let settled = false;\n function finish() {\n if (settled) return false;\n settled = true;\n signal?.removeEventListener(\"abort\", abort);\n request.readers--;\n if (request.readers === 0 && pending === request) {\n pending = undefined;\n request.controller.abort();\n }\n return true;\n }\n function abort() {\n if (finish()) reject(signal?.reason);\n }\n signal?.addEventListener(\"abort\", abort, { once: true });\n if (signal?.aborted) abort();\n request.promise.then(\n (symbols) => {\n if (finish()) resolve(symbols);\n },\n (error: unknown) => {\n if (finish()) reject(error);\n },\n );\n });\n };\n}\n"],"mappings":";;AAYA,SAAgB,EAAyB,GAAiB;CACxD,IAAI,GACA;CAEJ,OAAO,SAAqB,GAAmD;EAE7E,IADA,GAAQ,eAAe,GACnB,KAAU,EAAO,UAAU,KAAK,IAAI,GAAG,OAAO,QAAQ,QAAQ,EAAO,OAAO;EAChF,IAAI,CAAC,GAAS;GACZ,IAAM,IAAa,IAAI,gBAAgB,GACjC,IAAmB;IACvB;IACA,SAAS;IACT,SAAS,EAAmC,GAAS,EAAW,MAAM,EACnE,MAAM,OACL,EAAW,OAAO,eAAe,GACjC,IAAS;KAAE;KAAS,SAAS,KAAK,IAAI,IAAI;IAAO,GAC1C,EACR,EACA,cAAc;KACb,AAAI,MAAY,MAAS,IAAU,KAAA;IACrC,CAAC;GACL;GACA,IAAU;EACZ;EACA,IAAM,IAAU;EAEhB,OADA,EAAQ,WACD,IAAI,SAAS,GAAS,MAAW;GACtC,IAAI,IAAU;GACd,SAAS,IAAS;IAShB,OARI,IAAgB,MACpB,IAAU,IACV,GAAQ,oBAAoB,SAAS,CAAK,GAC1C,EAAQ,WACJ,EAAQ,YAAY,KAAK,MAAY,MACvC,IAAU,KAAA,GACV,EAAQ,WAAW,MAAM,IAEpB;GACT;GACA,SAAS,IAAQ;IACf,AAAI,EAAO,KAAG,EAAO,GAAQ,MAAM;GACrC;GAGA,AAFA,GAAQ,iBAAiB,SAAS,GAAO,EAAE,MAAM,GAAK,CAAC,GACnD,GAAQ,WAAS,EAAM,GAC3B,EAAQ,QAAQ,MACb,MAAY;IACX,AAAI,EAAO,KAAG,EAAQ,CAAO;GAC/B,IACC,MAAmB;IAClB,AAAI,EAAO,KAAG,EAAO,CAAK;GAC5B,CACF;EACF,CAAC;CACH;AACF"}
@@ -0,0 +1,12 @@
1
+ import { GetCandlesParameters, GetCandlesReturnType } from '../../types.js';
2
+ /** Bound response size independently of the optional vendor limit parameter. @internal */
3
+ export declare const LOWCAP_HISTORY_WINDOW_INTERVALS = 1000;
4
+ /** Endpoint and resolved identity for one history read. @internal */
5
+ export interface LowcapHistoryParameters extends GetCandlesParameters {
6
+ baseURL: string;
7
+ symbolAddress: string;
8
+ includeFlat: boolean;
9
+ }
10
+ /** Read bounded UTC windows backwards without interpreting sparse pages as exhaustion. @internal */
11
+ export declare function getLowcapCandles(parameters: LowcapHistoryParameters): Promise<GetCandlesReturnType>;
12
+ //# sourceMappingURL=get-lowcap-candles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-lowcap-candles.d.ts","sourceRoot":"","sources":["../../../../src/candles/sources/lowcap/get-lowcap-candles.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAU,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAItF,0FAA0F;AAC1F,eAAO,MAAM,+BAA+B,OAAQ,CAAC;AAErD,qEAAqE;AACrE,MAAM,WAAW,uBAAwB,SAAQ,oBAAoB;IACnE,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,OAAO,CAAC;CACtB;AAcD,oGAAoG;AACpG,wBAAsB,gBAAgB,CAAC,UAAU,EAAE,uBAAuB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA0DzG"}
@@ -0,0 +1,48 @@
1
+ import { SymmError as e } from "../../../shared/errors/symm-error.js";
2
+ import { fetchEnigmaOhlcvPage as t } from "../../../price-service/enigma/ohlcv/fetch-enigma-ohlcv.js";
3
+ import { ceilLowcapCandleTime as n, shiftLowcapCandleTime as r } from "./lowcap-candle-time.js";
4
+ import { toLowcapTimeframe as i } from "./map-resolution.js";
5
+ //#region src/candles/sources/lowcap/get-lowcap-candles.ts
6
+ var a = 1e3;
7
+ function o(e) {
8
+ return e.filter((t, n) => {
9
+ let r = e[n - 1];
10
+ return !r || t.volume !== 0 || [
11
+ t.open,
12
+ t.high,
13
+ t.low,
14
+ t.close
15
+ ].some((e) => e !== r.close);
16
+ });
17
+ }
18
+ async function s(s) {
19
+ let { baseURL: c, symbolAddress: l, resolution: u, from: d, to: f, limit: p, includeFlat: m, signal: h } = s, g = i(u);
20
+ if (!g) throw new e("validation", "UNSUPPORTED_CANDLE_RESOLUTION", `Unsupported lowcap resolution: ${u}.`);
21
+ if (![d, f].every((e) => Number.isSafeInteger(e) && Number.isFinite(new Date(e).getTime())) || d >= f) throw new e("validation", "INVALID_CANDLE_RANGE", "Candle ranges must be finite integer milliseconds with from < to.");
22
+ if (p !== void 0 && (!Number.isSafeInteger(p) || p < 1)) throw new e("validation", "INVALID_CANDLE_LIMIT", "Candle limit must be a positive integer.");
23
+ let _ = n(d, u), v = n(f, u), y = [], b = 0, x;
24
+ for (; v > _;) {
25
+ h?.throwIfAborted();
26
+ let e = Math.max(_, r(v, u, -a)), n = await t({
27
+ baseURL: c,
28
+ symbolAddress: l,
29
+ timeframe: g,
30
+ fromDate: new Date(e).toISOString(),
31
+ toDate: new Date(v).toISOString(),
32
+ includeFlat: m,
33
+ signal: h
34
+ });
35
+ h?.throwIfAborted();
36
+ let i = n.candles.filter((t) => t.time >= e && t.time < v && t.time < f);
37
+ if (y.push(i), b += i.length, x = n.hasOlder, v = e, x === !1 || p !== void 0 && (m ? b >= p : o([...y].reverse().flat()).length > p)) break;
38
+ }
39
+ let S = y.reverse().flat(), C = m ? S : o(S), w = p === void 0 ? C : C.slice(-p);
40
+ return {
41
+ candles: w,
42
+ noMoreData: x === !1 && w.length === C.length
43
+ };
44
+ }
45
+ //#endregion
46
+ export { a as LOWCAP_HISTORY_WINDOW_INTERVALS, s as getLowcapCandles };
47
+
48
+ //# sourceMappingURL=get-lowcap-candles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-lowcap-candles.js","names":[],"sources":["../../../../src/candles/sources/lowcap/get-lowcap-candles.ts"],"sourcesContent":["import { fetchEnigmaOhlcvPage } from \"../../../price-service/enigma/ohlcv/fetch-enigma-ohlcv\";\nimport { SymmError } from \"../../../shared/errors/symm-error\";\nimport type { Candle, GetCandlesParameters, GetCandlesReturnType } from \"../../types\";\nimport { ceilLowcapCandleTime, shiftLowcapCandleTime } from \"./lowcap-candle-time\";\nimport { toLowcapTimeframe } from \"./map-resolution\";\n\n/** Bound response size independently of the optional vendor limit parameter. @internal */\nexport const LOWCAP_HISTORY_WINDOW_INTERVALS = 1_000;\n\n/** Endpoint and resolved identity for one history read. @internal */\nexport interface LowcapHistoryParameters extends GetCandlesParameters {\n baseURL: string;\n symbolAddress: string;\n includeFlat: boolean;\n}\n\n/** Match the backend's flat filter after joining independently filtered pages. */\nfunction filterFlatCandles(candles: Candle[]): Candle[] {\n return candles.filter((candle, index) => {\n const previous = candles[index - 1];\n return (\n !previous ||\n candle.volume !== 0 ||\n [candle.open, candle.high, candle.low, candle.close].some((price) => price !== previous.close)\n );\n });\n}\n\n/** Read bounded UTC windows backwards without interpreting sparse pages as exhaustion. @internal */\nexport async function getLowcapCandles(parameters: LowcapHistoryParameters): Promise<GetCandlesReturnType> {\n const { baseURL, symbolAddress, resolution, from, to, limit, includeFlat, signal } = parameters;\n const timeframe = toLowcapTimeframe(resolution);\n if (!timeframe) {\n throw new SymmError(\"validation\", \"UNSUPPORTED_CANDLE_RESOLUTION\", `Unsupported lowcap resolution: ${resolution}.`);\n }\n if (\n ![from, to].every((time) => Number.isSafeInteger(time) && Number.isFinite(new Date(time).getTime())) ||\n from >= to\n ) {\n throw new SymmError(\n \"validation\",\n \"INVALID_CANDLE_RANGE\",\n \"Candle ranges must be finite integer milliseconds with from < to.\",\n );\n }\n if (limit !== undefined && (!Number.isSafeInteger(limit) || limit < 1)) {\n throw new SymmError(\"validation\", \"INVALID_CANDLE_LIMIT\", \"Candle limit must be a positive integer.\");\n }\n\n const start = ceilLowcapCandleTime(from, resolution);\n let end = ceilLowcapCandleTime(to, resolution);\n const pages: Candle[][] = [];\n let count = 0;\n let hasOlder: boolean | undefined;\n\n while (end > start) {\n signal?.throwIfAborted();\n // Without limit the service returns the full date range. Bound its size\n // locally; discard the inclusive boundary bar without truncating samples.\n const pageStart = Math.max(start, shiftLowcapCandleTime(end, resolution, -LOWCAP_HISTORY_WINDOW_INTERVALS));\n const page = await fetchEnigmaOhlcvPage({\n baseURL,\n symbolAddress,\n timeframe,\n fromDate: new Date(pageStart).toISOString(),\n toDate: new Date(end).toISOString(),\n includeFlat,\n signal,\n });\n signal?.throwIfAborted();\n const candles = page.candles.filter((candle) => candle.time >= pageStart && candle.time < end && candle.time < to);\n pages.push(candles);\n count += candles.length;\n hasOlder = page.hasOlder;\n end = pageStart;\n if (hasOlder === false) break;\n if (limit !== undefined) {\n /** The first flat candle is provisional until an older page supplies its preceding price. */\n const enough = includeFlat ? count >= limit : filterFlatCandles([...pages].reverse().flat()).length > limit;\n if (enough) break;\n }\n }\n\n const all = pages.reverse().flat();\n const filtered = includeFlat ? all : filterFlatCandles(all);\n const candles = limit === undefined ? filtered : filtered.slice(-limit);\n return { candles, noMoreData: hasOlder === false && candles.length === filtered.length };\n}\n"],"mappings":";;;;;AAOA,IAAa,IAAkC;AAU/C,SAAS,EAAkB,GAA6B;CACtD,OAAO,EAAQ,QAAQ,GAAQ,MAAU;EACvC,IAAM,IAAW,EAAQ,IAAQ;EACjC,OACE,CAAC,KACD,EAAO,WAAW,KAClB;GAAC,EAAO;GAAM,EAAO;GAAM,EAAO;GAAK,EAAO;EAAK,EAAE,MAAM,MAAU,MAAU,EAAS,KAAK;CAEjG,CAAC;AACH;AAGA,eAAsB,EAAiB,GAAoE;CACzG,IAAM,EAAE,YAAS,kBAAe,eAAY,SAAM,OAAI,UAAO,gBAAa,cAAW,GAC/E,IAAY,EAAkB,CAAU;CAC9C,IAAI,CAAC,GACH,MAAM,IAAI,EAAU,cAAc,iCAAiC,kCAAkC,EAAW,EAAE;CAEpH,IACE,CAAC,CAAC,GAAM,CAAE,EAAE,OAAO,MAAS,OAAO,cAAc,CAAI,KAAK,OAAO,SAAS,IAAI,KAAK,CAAI,EAAE,QAAQ,CAAC,CAAC,KACnG,KAAQ,GAER,MAAM,IAAI,EACR,cACA,wBACA,mEACF;CAEF,IAAI,MAAU,KAAA,MAAc,CAAC,OAAO,cAAc,CAAK,KAAK,IAAQ,IAClE,MAAM,IAAI,EAAU,cAAc,wBAAwB,0CAA0C;CAGtG,IAAM,IAAQ,EAAqB,GAAM,CAAU,GAC/C,IAAM,EAAqB,GAAI,CAAU,GACvC,IAAoB,CAAC,GACvB,IAAQ,GACR;CAEJ,OAAO,IAAM,IAAO;EAClB,GAAQ,eAAe;EAGvB,IAAM,IAAY,KAAK,IAAI,GAAO,EAAsB,GAAK,GAAY,CAAC,CAA+B,CAAC,GACpG,IAAO,MAAM,EAAqB;GACtC;GACA;GACA;GACA,UAAU,IAAI,KAAK,CAAS,EAAE,YAAY;GAC1C,QAAQ,IAAI,KAAK,CAAG,EAAE,YAAY;GAClC;GACA;EACF,CAAC;EACD,GAAQ,eAAe;EACvB,IAAM,IAAU,EAAK,QAAQ,QAAQ,MAAW,EAAO,QAAQ,KAAa,EAAO,OAAO,KAAO,EAAO,OAAO,CAAE;EAMjH,IALA,EAAM,KAAK,CAAO,GAClB,KAAS,EAAQ,QACjB,IAAW,EAAK,UAChB,IAAM,GACF,MAAa,MACb,MAAU,KAAA,MAEG,IAAc,KAAS,IAAQ,EAAkB,CAAC,GAAG,CAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,SAAS,IAC1F;CAEhB;CAEA,IAAM,IAAM,EAAM,QAAQ,EAAE,KAAK,GAC3B,IAAW,IAAc,IAAM,EAAkB,CAAG,GACpD,IAAU,MAAU,KAAA,IAAY,IAAW,EAAS,MAAM,CAAC,CAAK;CACtE,OAAO;EAAE;EAAS,YAAY,MAAa,MAAS,EAAQ,WAAW,EAAS;CAAO;AACzF"}
@@ -0,0 +1,2 @@
1
+ export * from './create-lowcap-candle-source.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/candles/sources/lowcap/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { CandleResolution } from '../../types.js';
2
+ /** UTC bucket start; weeks start on Monday and months follow the calendar.
3
+ * @internal */
4
+ export declare function floorLowcapCandleTime(time: number, resolution: CandleResolution): number;
5
+ /** Shift an aligned candle boundary, retaining variable calendar month lengths. @internal */
6
+ export declare function shiftLowcapCandleTime(time: number, resolution: CandleResolution, count: number): number;
7
+ /** First candle start at or after a requested time. @internal */
8
+ export declare function ceilLowcapCandleTime(time: number, resolution: CandleResolution): number;
9
+ //# sourceMappingURL=lowcap-candle-time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lowcap-candle-time.d.ts","sourceRoot":"","sources":["../../../../src/candles/sources/lowcap/lowcap-candle-time.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;gBACgB;AAChB,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,gBAAgB,GAAG,MAAM,CASxF;AAED,6FAA6F;AAC7F,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAMvG;AAED,iEAAiE;AACjE,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,gBAAgB,GAAG,MAAM,CAGvF"}
@@ -0,0 +1,24 @@
1
+ import { resolutionToMs as e } from "../../resolution.js";
2
+ //#region src/candles/sources/lowcap/lowcap-candle-time.ts
3
+ function t(t, n) {
4
+ let r = new Date(t);
5
+ if (n === "1M") return Date.UTC(r.getUTCFullYear(), r.getUTCMonth(), 1);
6
+ if (n === "1w") return Date.UTC(r.getUTCFullYear(), r.getUTCMonth(), r.getUTCDate()) - (r.getUTCDay() + 6) % 7 * 864e5;
7
+ let i = e(n);
8
+ return Math.floor(t / i) * i;
9
+ }
10
+ function n(t, n, r) {
11
+ if (n === "1M") {
12
+ let e = new Date(t);
13
+ return Date.UTC(e.getUTCFullYear(), e.getUTCMonth() + r, 1);
14
+ }
15
+ return t + e(n) * r;
16
+ }
17
+ function r(e, r) {
18
+ let i = t(e, r);
19
+ return i === e ? i : n(i, r, 1);
20
+ }
21
+ //#endregion
22
+ export { r as ceilLowcapCandleTime, t as floorLowcapCandleTime, n as shiftLowcapCandleTime };
23
+
24
+ //# sourceMappingURL=lowcap-candle-time.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lowcap-candle-time.js","names":[],"sources":["../../../../src/candles/sources/lowcap/lowcap-candle-time.ts"],"sourcesContent":["import { resolutionToMs } from \"../../resolution\";\nimport type { CandleResolution } from \"../../types\";\n\n/** UTC bucket start; weeks start on Monday and months follow the calendar.\n * @internal */\nexport function floorLowcapCandleTime(time: number, resolution: CandleResolution): number {\n const date = new Date(time);\n if (resolution === \"1M\") return Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), 1);\n if (resolution === \"1w\") {\n const day = Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());\n return day - ((date.getUTCDay() + 6) % 7) * 86_400_000;\n }\n const interval = resolutionToMs(resolution);\n return Math.floor(time / interval) * interval;\n}\n\n/** Shift an aligned candle boundary, retaining variable calendar month lengths. @internal */\nexport function shiftLowcapCandleTime(time: number, resolution: CandleResolution, count: number): number {\n if (resolution === \"1M\") {\n const date = new Date(time);\n return Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + count, 1);\n }\n return time + resolutionToMs(resolution) * count;\n}\n\n/** First candle start at or after a requested time. @internal */\nexport function ceilLowcapCandleTime(time: number, resolution: CandleResolution): number {\n const start = floorLowcapCandleTime(time, resolution);\n return start === time ? start : shiftLowcapCandleTime(start, resolution, 1);\n}\n"],"mappings":";;AAKA,SAAgB,EAAsB,GAAc,GAAsC;CACxF,IAAM,IAAO,IAAI,KAAK,CAAI;CAC1B,IAAI,MAAe,MAAM,OAAO,KAAK,IAAI,EAAK,eAAe,GAAG,EAAK,YAAY,GAAG,CAAC;CACrF,IAAI,MAAe,MAEjB,OADY,KAAK,IAAI,EAAK,eAAe,GAAG,EAAK,YAAY,GAAG,EAAK,WAAW,CACzE,KAAQ,EAAK,UAAU,IAAI,KAAK,IAAK;CAE9C,IAAM,IAAW,EAAe,CAAU;CAC1C,OAAO,KAAK,MAAM,IAAO,CAAQ,IAAI;AACvC;AAGA,SAAgB,EAAsB,GAAc,GAA8B,GAAuB;CACvG,IAAI,MAAe,MAAM;EACvB,IAAM,IAAO,IAAI,KAAK,CAAI;EAC1B,OAAO,KAAK,IAAI,EAAK,eAAe,GAAG,EAAK,YAAY,IAAI,GAAO,CAAC;CACtE;CACA,OAAO,IAAO,EAAe,CAAU,IAAI;AAC7C;AAGA,SAAgB,EAAqB,GAAc,GAAsC;CACvF,IAAM,IAAQ,EAAsB,GAAM,CAAU;CACpD,OAAO,MAAU,IAAO,IAAQ,EAAsB,GAAO,GAAY,CAAC;AAC5E"}
@@ -0,0 +1,16 @@
1
+ import { PriceTimeframe } from '../../../price-service/enigma/ohlcv/generated/enigma-price-service-ohlcv.js';
2
+ import { CandleResolution } from '../../types.js';
3
+ /**
4
+ * Map an SDK resolution to the price-service timeframe.
5
+ * @param resolution - SDK bar size.
6
+ * @returns The service code, or undefined when unsupported.
7
+ * @internal
8
+ */
9
+ export declare function toLowcapTimeframe(resolution: CandleResolution): PriceTimeframe | undefined;
10
+ /**
11
+ * List only the resolutions declared by the price service.
12
+ * @returns A fresh list of supported SDK resolutions, shortest first.
13
+ * @internal
14
+ */
15
+ export declare function getLowcapSupportedResolutions(): CandleResolution[];
16
+ //# sourceMappingURL=map-resolution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-resolution.d.ts","sourceRoot":"","sources":["../../../../src/candles/sources/lowcap/map-resolution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0EAA0E,CAAC;AAC1G,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAiBpD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,gBAAgB,GAAG,cAAc,GAAG,SAAS,CAE1F;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,IAAI,gBAAgB,EAAE,CAElE"}
@@ -0,0 +1,26 @@
1
+ import { PriceTimeframe as e } from "../../../price-service/enigma/ohlcv/generated/enigma-price-service-ohlcv.js";
2
+ //#region src/candles/sources/lowcap/map-resolution.ts
3
+ var t = {
4
+ "1m": e["1m"],
5
+ "5m": e["5m"],
6
+ "10m": e["10m"],
7
+ "15m": e["15m"],
8
+ "30m": e["30m"],
9
+ "1h": e["1h"],
10
+ "4h": e["4h"],
11
+ "6h": e["6h"],
12
+ "12h": e["12h"],
13
+ "1d": e["1D"],
14
+ "1w": e["1W"],
15
+ "1M": e["1M"]
16
+ };
17
+ function n(e) {
18
+ return t[e];
19
+ }
20
+ function r() {
21
+ return Object.keys(t);
22
+ }
23
+ //#endregion
24
+ export { r as getLowcapSupportedResolutions, n as toLowcapTimeframe };
25
+
26
+ //# sourceMappingURL=map-resolution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-resolution.js","names":[],"sources":["../../../../src/candles/sources/lowcap/map-resolution.ts"],"sourcesContent":["import { PriceTimeframe } from \"../../../price-service/enigma/ohlcv/generated/enigma-price-service-ohlcv\";\nimport type { CandleResolution } from \"../../types\";\n\nconst TIMEFRAME_BY_RESOLUTION: Partial<Record<CandleResolution, PriceTimeframe>> = {\n \"1m\": PriceTimeframe[\"1m\"],\n \"5m\": PriceTimeframe[\"5m\"],\n \"10m\": PriceTimeframe[\"10m\"],\n \"15m\": PriceTimeframe[\"15m\"],\n \"30m\": PriceTimeframe[\"30m\"],\n \"1h\": PriceTimeframe[\"1h\"],\n \"4h\": PriceTimeframe[\"4h\"],\n \"6h\": PriceTimeframe[\"6h\"],\n \"12h\": PriceTimeframe[\"12h\"],\n \"1d\": PriceTimeframe[\"1D\"],\n \"1w\": PriceTimeframe[\"1W\"],\n \"1M\": PriceTimeframe[\"1M\"],\n};\n\n/**\n * Map an SDK resolution to the price-service timeframe.\n * @param resolution - SDK bar size.\n * @returns The service code, or undefined when unsupported.\n * @internal\n */\nexport function toLowcapTimeframe(resolution: CandleResolution): PriceTimeframe | undefined {\n return TIMEFRAME_BY_RESOLUTION[resolution];\n}\n\n/**\n * List only the resolutions declared by the price service.\n * @returns A fresh list of supported SDK resolutions, shortest first.\n * @internal\n */\nexport function getLowcapSupportedResolutions(): CandleResolution[] {\n return Object.keys(TIMEFRAME_BY_RESOLUTION) as CandleResolution[];\n}\n"],"mappings":";;AAGA,IAAM,IAA6E;CACjF,MAAM,EAAe;CACrB,MAAM,EAAe;CACrB,OAAO,EAAe;CACtB,OAAO,EAAe;CACtB,OAAO,EAAe;CACtB,MAAM,EAAe;CACrB,MAAM,EAAe;CACrB,MAAM,EAAe;CACrB,OAAO,EAAe;CACtB,MAAM,EAAe;CACrB,MAAM,EAAe;CACrB,MAAM,EAAe;AACvB;AAQA,SAAgB,EAAkB,GAA0D;CAC1F,OAAO,EAAwB;AACjC;AAOA,SAAgB,IAAoD;CAClE,OAAO,OAAO,KAAK,CAAuB;AAC5C"}
@@ -0,0 +1,12 @@
1
+ import { EnigmaSymbolInfo } from '../../../price-service/enigma/symbols-info/get-enigma-price-service-symbols-info.js';
2
+ /**
3
+ * Resolve a listed lowcap market by its complete, case-sensitive name.
4
+ * Tickers and truncated address suffixes are not unique market identifiers.
5
+ *
6
+ * @param symbols - Listings from the configured price service.
7
+ * @param marketName - Exact market name, including any `::` suffix.
8
+ * @returns The matching listing with its address unchanged, or undefined.
9
+ * @internal
10
+ */
11
+ export declare function resolveLowcapSymbol(symbols: readonly EnigmaSymbolInfo[], marketName: string): EnigmaSymbolInfo | undefined;
12
+ //# sourceMappingURL=resolve-lowcap-symbol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-lowcap-symbol.d.ts","sourceRoot":"","sources":["../../../../src/candles/sources/lowcap/resolve-lowcap-symbol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kFAAkF,CAAC;AAEzH;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,SAAS,gBAAgB,EAAE,EACpC,UAAU,EAAE,MAAM,GACjB,gBAAgB,GAAG,SAAS,CAE9B"}
@@ -0,0 +1,8 @@
1
+ //#region src/candles/sources/lowcap/resolve-lowcap-symbol.ts
2
+ function e(e, t) {
3
+ return e.find((e) => e.name === t);
4
+ }
5
+ //#endregion
6
+ export { e as resolveLowcapSymbol };
7
+
8
+ //# sourceMappingURL=resolve-lowcap-symbol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-lowcap-symbol.js","names":[],"sources":["../../../../src/candles/sources/lowcap/resolve-lowcap-symbol.ts"],"sourcesContent":["import type { EnigmaSymbolInfo } from \"../../../price-service/enigma/symbols-info/get-enigma-price-service-symbols-info\";\n\n/**\n * Resolve a listed lowcap market by its complete, case-sensitive name.\n * Tickers and truncated address suffixes are not unique market identifiers.\n *\n * @param symbols - Listings from the configured price service.\n * @param marketName - Exact market name, including any `::` suffix.\n * @returns The matching listing with its address unchanged, or undefined.\n * @internal\n */\nexport function resolveLowcapSymbol(\n symbols: readonly EnigmaSymbolInfo[],\n marketName: string,\n): EnigmaSymbolInfo | undefined {\n return symbols.find((symbol) => symbol.name === marketName);\n}\n"],"mappings":";AAWA,SAAgB,EACd,GACA,GAC8B;CAC9B,OAAO,EAAQ,MAAM,MAAW,EAAO,SAAS,CAAU;AAC5D"}
@@ -0,0 +1,19 @@
1
+ import { SolverId } from '../../../core/chains/types.js';
2
+ import { Config } from '../../../core/config/index.js';
3
+ import { GetCandlesReturnType, WatchCandlesParameters } from '../../types.js';
4
+ interface Parameters extends WatchCandlesParameters {
5
+ chainId?: number;
6
+ solverId?: SolverId;
7
+ includeFlat: boolean;
8
+ refreshIntervalMs: number;
9
+ resolveAddress: (signal: AbortSignal) => Promise<string>;
10
+ getHistory: (address: string, range: {
11
+ from: number;
12
+ to: number;
13
+ signal: AbortSignal;
14
+ }) => Promise<GetCandlesReturnType>;
15
+ }
16
+ /** Seed from OHLCV, apply timestamped price ticks, and reconcile without caching final history. @internal */
17
+ export declare function watchLowcapCandles(config: Config, parameters: Parameters): () => void;
18
+ export {};
19
+ //# sourceMappingURL=watch-lowcap-candles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watch-lowcap-candles.d.ts","sourceRoot":"","sources":["../../../../src/candles/sources/lowcap/watch-lowcap-candles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAInD,OAAO,KAAK,EAAU,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAGxF,UAAU,UAAW,SAAQ,sBAAsB;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,WAAW,EAAE,OAAO,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACzD,UAAU,EAAE,CACV,OAAO,EAAE,MAAM,EACf,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,WAAW,CAAA;KAAE,KACrD,OAAO,CAAC,oBAAoB,CAAC,CAAC;CACpC;AAaD,6GAA6G;AAC7G,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,MAAM,IAAI,CA0NrF"}