@usherlabs/cex-broker 0.2.27 → 0.2.28

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.
@@ -3,7 +3,7 @@ import { type OrderTelemetryAction, type OrderTelemetryContext } from "../order-
3
3
  import { type TransferArchiveFields } from "./rows";
4
4
  import type { SubscribeArchiveType } from "./types";
5
5
  import type { WithdrawalObservationTracker } from "./withdrawal-observation-tracker";
6
- import type { BrokerExecutionArchiver } from "./writer";
6
+ import { type BrokerExecutionArchiver } from "./writer";
7
7
  export declare function archiveOrderExecutionInBackground(archiver: BrokerExecutionArchiver | undefined, context: OrderTelemetryContext, order: unknown, error?: unknown, options?: {
8
8
  marketMetadataHash?: string;
9
9
  }): void;
@@ -3,4 +3,4 @@ export { hashMarketMetadata, redactErrorForArchive, redactSecretLiterals, redact
3
3
  export { buildAccountBalanceSnapshotRow, buildCommonArchiveTags, buildFillEventArchiveRow, buildMarketMetadataSnapshotRow, buildOrderEventArchiveRow, buildSubscribeStreamArchiveRow, buildTransferEventArchiveRow, type FillArchiveFields, type NormalizedCcxtBalance, type NormalizedCcxtTransfer, normalizeCcxtBalanceForArchive, normalizeCcxtTradeForArchive, normalizeCcxtTransactionForArchive, type TransferArchiveFields, } from "./rows";
4
4
  export { ACCOUNT_BALANCE_PRECISION_BASIS, ACCOUNT_BALANCE_SCOPE, ARCHIVE_SCHEMA_VERSION, BROKER_WRITE_SOURCE, type BrokerArchiveCommonTags, type BrokerArchiveRow, type BrokerArchiveTable, type OrderArchiveAction, type SubscribeArchiveType, type TransferEventKind, type TransferLifecycleAction, } from "./types";
5
5
  export { DEFAULT_WITHDRAWAL_OBSERVATION_TRACKER_MAX_ENTRIES, WithdrawalObservationTracker, } from "./withdrawal-observation-tracker";
6
- export { BrokerExecutionArchiver, type BrokerExecutionArchiverOptions, createBrokerExecutionArchiverFromEnv, isArchiveOtelLogsEnabled, isBrokerExecutionArchiveTable, resolveArchiveForwarderUrlFromEnv, } from "./writer";
6
+ export { BrokerExecutionArchiveDurabilityError, BrokerExecutionArchiver, type BrokerExecutionArchiverOptions, createBrokerExecutionArchiverFromEnv, isArchiveOtelLogsEnabled, isBrokerExecutionArchiveTable, resolveArchiveForwarderUrlFromEnv, rethrowArchiveDurabilityError, } from "./writer";
@@ -28,6 +28,7 @@ export declare function buildOrderEventArchiveRow(input: {
28
28
  tags: BrokerArchiveCommonTags;
29
29
  action: OrderArchiveAction;
30
30
  telemetry: OrderExecutionTelemetry;
31
+ errorDetail?: string;
31
32
  eventKind?: "execute_action" | "subscribe_stream";
32
33
  subscriptionType?: SubscribeArchiveType;
33
34
  marketMetadataHash?: string;
@@ -5,12 +5,17 @@ export type BrokerExecutionArchiverOptions = {
5
5
  deploymentId?: string;
6
6
  otelLogs?: OtelLogs;
7
7
  otelMetrics?: OtelMetrics;
8
- forwarderUrl?: string;
8
+ forwarderUrl: string;
9
+ deadLetterPath: string;
9
10
  maxQueueSize?: number;
10
11
  batchSize?: number;
11
12
  flushIntervalMs?: number;
12
13
  forwarderTimeoutMs?: number;
13
14
  };
15
+ export declare class BrokerExecutionArchiveDurabilityError extends Error {
16
+ constructor(message: string, options?: ErrorOptions);
17
+ }
18
+ export declare function rethrowArchiveDurabilityError(error: unknown): void;
14
19
  type ArchiverStats = {
15
20
  enqueued: number;
16
21
  shed: number;
@@ -24,6 +29,8 @@ export declare class BrokerExecutionArchiver {
24
29
  private readonly otelLogs?;
25
30
  private readonly otelMetrics?;
26
31
  private readonly forwarderUrl?;
32
+ private readonly deadLetterPath?;
33
+ private deadLetterFd?;
27
34
  private readonly maxQueueSize;
28
35
  private readonly batchSize;
29
36
  private readonly flushIntervalMs;
@@ -34,7 +41,6 @@ export declare class BrokerExecutionArchiver {
34
41
  private flushInFlight;
35
42
  private lastShedWarnAtMs;
36
43
  private closed;
37
- private loggedMissingMarketForwarder;
38
44
  private readonly enabled;
39
45
  private readonly forwarderAuthToken?;
40
46
  private constructor();
@@ -50,7 +56,9 @@ export declare class BrokerExecutionArchiver {
50
56
  close(): Promise<void>;
51
57
  getStats(): Readonly<ArchiverStats>;
52
58
  getQueueDepth(): number;
59
+ private closeLossJournal;
53
60
  private enforceQueueBound;
61
+ private appendLossRecords;
54
62
  private flushBatch;
55
63
  private recordFlushHealth;
56
64
  private recordArchiveMetric;
@@ -1,5 +1,5 @@
1
+ import { type BrokerExecutionArchiver } from "../broker-execution-archive/writer";
1
2
  import type { OtelMetrics } from "../otel";
2
- import type { BrokerExecutionArchiver } from "../broker-execution-archive/writer";
3
3
  import { OhlcvBarTracker } from "./ohlcv-bar-tracker";
4
4
  import { OrderbookSampler } from "./orderbook-sampler";
5
5
  import type { CexStreamArchiveInput, OhlcvArchiveInput, OrderbookArchiveInput, TickerArchiveInput, TradesArchiveInput } from "./types";
@@ -1,9 +1,9 @@
1
1
  export { archiveCexStreamEventInBackground, archiveOhlcvInBackground, archiveOrderbookInBackground, archiveOrderbookSnapshotInBackground, archiveOrderbookTobInBackground, archiveTickerInBackground, archiveTradesInBackground, createOhlcvBarTracker, createOrderbookSampler, createOrderbookTobSampler, } from "./capture";
2
2
  export { extractLatestOhlcvBar, extractOhlcvBars, OhlcvBarTracker, parseOhlcvBar, } from "./ohlcv-bar-tracker";
3
- export { bootstrapOhlcvHistory } from "./ohlcv-history";
4
3
  export { resolveOhlcvBootstrapLimit } from "./ohlcv-bootstrap";
5
- export { extractTrades, parseTicker, parseTrade } from "./parse-stream";
4
+ export { bootstrapOhlcvHistory } from "./ohlcv-history";
5
+ export { getOrderbookArchiveDepthLimit, splitOrderBookSide, } from "./orderbook-depth";
6
6
  export { getOrderbookIntervalMs, getOrderbookTobIntervalMs, isMarketArchiveEnabled, OrderbookSampler, OrderbookTobSampler, } from "./orderbook-sampler";
7
+ export { extractTrades, parseTicker, parseTrade } from "./parse-stream";
7
8
  export { buildCandleRow, buildCexStreamEventRow, buildCexTickerEventRow, buildCexTradeRow, buildOrderbookDepthRow, buildOrderbookSnapshotRow, buildOrderbookTobRow, } from "./rows";
8
- export { getOrderbookArchiveDepthLimit, splitOrderBookSide, } from "./orderbook-depth";
9
9
  export type { CexStreamArchiveInput, CexStreamType, MarketArchiveContext, OhlcvArchiveCandidate, OhlcvArchiveInput, OrderbookArchiveInput, OrderbookSnapshotArchiveInput, OrderbookTobArchiveInput, ParsedOhlcvBar, TickerArchiveInput, TradesArchiveInput, } from "./types";
@@ -1,6 +1,6 @@
1
1
  import type { Exchange } from "@usherlabs/ccxt";
2
- import type { OtelMetrics } from "../otel";
3
2
  import type { BrokerExecutionArchiver } from "../broker-execution-archive/writer";
3
+ import type { OtelMetrics } from "../otel";
4
4
  import type { OhlcvBarTracker } from "./ohlcv-bar-tracker";
5
5
  import type { OhlcvArchiveInput } from "./types";
6
6
  export declare function bootstrapOhlcvHistory(broker: Exchange, archiver: BrokerExecutionArchiver | undefined, otelMetrics: OtelMetrics | undefined, tracker: OhlcvBarTracker, input: OhlcvArchiveInput, options?: {
@@ -1,4 +1,4 @@
1
- import { type BrokerArchiveRow } from "../broker-execution-archive/types";
1
+ import type { BrokerArchiveRow } from "../broker-execution-archive/types";
2
2
  import type { ParsedTicker, ParsedTrade } from "./parse-stream";
3
3
  import type { CexStreamArchiveInput, MarketArchiveContext, OrderbookArchiveInput, ParsedOhlcvBar, TickerArchiveInput, TradesArchiveInput } from "./types";
4
4
  export declare function buildOrderbookSnapshotRow(input: OrderbookArchiveInput): BrokerArchiveRow | null;
@@ -1,6 +1,6 @@
1
+ import type { BrokerArchiveRow } from "../broker-execution-archive/types";
1
2
  import type { BrokerMarketType } from "../market-type";
2
3
  import type { NormalizedOrderBookSnapshot } from "../order-book";
3
- import type { BrokerArchiveRow } from "../broker-execution-archive/types";
4
4
  export type MarketArchiveTable = "market_data.orderbook_snapshots" | "market_data.candles" | "market_data.cex_stream_events" | "market_data.cex_ticker_events" | "market_data.cex_trades";
5
5
  export type CexStreamType = "BALANCE" | "ORDERS" | "ORDERBOOK" | "TRADES" | "TICKER" | "OHLCV";
6
6
  export type ParsedOhlcvBar = {
@@ -1,12 +1,14 @@
1
+ export declare const REDACTED_ERROR_MESSAGE = "redacted_error";
1
2
  export declare function getErrorMessage(error: unknown): string;
2
3
  /** Constructor/class name of a caught error (ccxt classes like InsufficientFunds,
3
4
  * BadSymbol, OrderNotFound carry the actionable signal). The generic `Error` name
4
5
  * adds nothing, so it is dropped; returns undefined for non-Error values. */
5
6
  export declare function errorClassName(error: unknown): string | undefined;
6
7
  /** Sanitized, single-line, length-capped detail for a caught error: the venue
7
- * error class name plus its message. Safe to return to gRPC callers — it carries
8
- * only the exchange's own error text (class + message), never a stack or payload,
9
- * so downstream consumers can distinguish e.g. InsufficientFunds from BadSymbol
10
- * instead of an opaque "<action> failed". */
11
- export declare function sanitizeErrorDetail(error: unknown): string;
8
+ * error class, optional primitive code, and message. It never includes a stack
9
+ * or attached payload. */
10
+ export declare function sanitizeErrorDetail(error: unknown, options?: {
11
+ includeCode?: boolean;
12
+ }): string;
12
13
  export declare function safeLogError(context: string, error: unknown): void;
14
+ export declare function safeLogRedactedError(context: string, error: unknown): void;