@usherlabs/cex-broker 0.2.52 → 0.3.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 (144) hide show
  1. package/dist/commands/cli.js +364 -71
  2. package/dist/index.js +365 -72
  3. package/dist/index.js.map +14 -13
  4. package/package.json +5 -28
  5. package/dist/commands/cex-canonical-orderbook-export.d.ts +0 -23
  6. package/dist/commands/cex-canonical-orderbook-export.js +0 -34275
  7. package/dist/commands/cex-canonical-orderbook-export.js.map +0 -266
  8. package/dist/commands/market-data-vendor-backfill.d.ts +0 -24
  9. package/dist/commands/market-data-vendor-backfill.js +0 -34930
  10. package/dist/commands/market-data-vendor-backfill.js.map +0 -268
  11. package/dist/handlers/execute-action/context.d.ts +0 -50
  12. package/dist/handlers/execute-action/deposit.d.ts +0 -2
  13. package/dist/handlers/execute-action/handler.d.ts +0 -19
  14. package/dist/handlers/execute-action/index.d.ts +0 -10
  15. package/dist/handlers/execute-action/internal-transfer.d.ts +0 -2
  16. package/dist/handlers/execute-action/order-book-call.d.ts +0 -3
  17. package/dist/handlers/execute-action/orders.d.ts +0 -2
  18. package/dist/handlers/execute-action/pass-through.d.ts +0 -2
  19. package/dist/handlers/execute-action/perp-config.d.ts +0 -2
  20. package/dist/handlers/execute-action/registry.d.ts +0 -5
  21. package/dist/handlers/execute-action/treasury-call.d.ts +0 -2
  22. package/dist/handlers/execute-action/withdraw.d.ts +0 -2
  23. package/dist/handlers/subscribe/broker-lifecycle.d.ts +0 -13
  24. package/dist/handlers/subscribe/handler.d.ts +0 -20
  25. package/dist/handlers/subscribe/index.d.ts +0 -2
  26. package/dist/handlers/types.d.ts +0 -23
  27. package/dist/helpers/account-balance-archive-poller.d.ts +0 -19
  28. package/dist/helpers/auth.d.ts +0 -5
  29. package/dist/helpers/balance-update-archive-consumer.d.ts +0 -16
  30. package/dist/helpers/binance-user-data-normalization.d.ts +0 -3
  31. package/dist/helpers/binance-user-data-stream.d.ts +0 -58
  32. package/dist/helpers/broker-execution-archive/capture.d.ts +0 -41
  33. package/dist/helpers/broker-execution-archive/index.d.ts +0 -7
  34. package/dist/helpers/broker-execution-archive/journal-export.d.ts +0 -20
  35. package/dist/helpers/broker-execution-archive/loss-journal.d.ts +0 -36
  36. package/dist/helpers/broker-execution-archive/redact.d.ts +0 -7
  37. package/dist/helpers/broker-execution-archive/rows.d.ts +0 -134
  38. package/dist/helpers/broker-execution-archive/types.d.ts +0 -26
  39. package/dist/helpers/broker-execution-archive/withdrawal-observation-tracker.d.ts +0 -23
  40. package/dist/helpers/broker-execution-archive/writer.d.ts +0 -105
  41. package/dist/helpers/broker.d.ts +0 -38
  42. package/dist/helpers/canonical-orderbook-export/exact-selection.d.ts +0 -21
  43. package/dist/helpers/canonical-orderbook-export/exporter.d.ts +0 -26
  44. package/dist/helpers/canonical-orderbook-export/parquet-projection.d.ts +0 -19
  45. package/dist/helpers/constants.d.ts +0 -36
  46. package/dist/helpers/deposit-archive-poller.d.ts +0 -66
  47. package/dist/helpers/deposit.d.ts +0 -5
  48. package/dist/helpers/exchange-credentials.d.ts +0 -10
  49. package/dist/helpers/fill-archive-poller.d.ts +0 -42
  50. package/dist/helpers/grpc/broker.d.ts +0 -5
  51. package/dist/helpers/grpc/callbacks.d.ts +0 -9
  52. package/dist/helpers/grpc/payload.d.ts +0 -9
  53. package/dist/helpers/grpc/status.d.ts +0 -8
  54. package/dist/helpers/index.d.ts +0 -44
  55. package/dist/helpers/logger.d.ts +0 -13
  56. package/dist/helpers/market-data-archive/canonical-orderbook.d.ts +0 -20
  57. package/dist/helpers/market-data-archive/capture-context.d.ts +0 -53
  58. package/dist/helpers/market-data-archive/capture-contract.d.ts +0 -30
  59. package/dist/helpers/market-data-archive/capture.d.ts +0 -22
  60. package/dist/helpers/market-data-archive/index.d.ts +0 -13
  61. package/dist/helpers/market-data-archive/legacy-migration.d.ts +0 -37
  62. package/dist/helpers/market-data-archive/ohlcv-bar-tracker.d.ts +0 -11
  63. package/dist/helpers/market-data-archive/ohlcv-bootstrap.d.ts +0 -1
  64. package/dist/helpers/market-data-archive/ohlcv-history.d.ts +0 -8
  65. package/dist/helpers/market-data-archive/orderbook-depth.d.ts +0 -5
  66. package/dist/helpers/market-data-archive/orderbook-sampler.d.ts +0 -12
  67. package/dist/helpers/market-data-archive/parse-stream.d.ts +0 -26
  68. package/dist/helpers/market-data-archive/rows.d.ts +0 -14
  69. package/dist/helpers/market-data-archive/types.d.ts +0 -83
  70. package/dist/helpers/market-data-preparation/conformance-fixtures.d.ts +0 -128
  71. package/dist/helpers/market-data-preparation/contracts.d.ts +0 -2970
  72. package/dist/helpers/market-data-preparation/file-job.d.ts +0 -38
  73. package/dist/helpers/market-data-preparation/required-clock-qualification.d.ts +0 -43
  74. package/dist/helpers/market-data-preparation/source-tape-dependencies.d.ts +0 -19
  75. package/dist/helpers/market-data-preparation/source-tape-operation.d.ts +0 -109
  76. package/dist/helpers/market-data-source-forensics.d.ts +0 -400
  77. package/dist/helpers/market-data-vendor-backfill/archive-reader.d.ts +0 -26
  78. package/dist/helpers/market-data-vendor-backfill/batching.d.ts +0 -10
  79. package/dist/helpers/market-data-vendor-backfill/conformance-fixtures.d.ts +0 -78
  80. package/dist/helpers/market-data-vendor-backfill/contracts.d.ts +0 -358
  81. package/dist/helpers/market-data-vendor-backfill/core.d.ts +0 -101
  82. package/dist/helpers/market-data-vendor-backfill/cryptohftdata.d.ts +0 -118
  83. package/dist/helpers/market-data-vendor-backfill/forwarder-client.d.ts +0 -25
  84. package/dist/helpers/market-data-vendor-backfill/identity.d.ts +0 -10
  85. package/dist/helpers/market-data-vendor-backfill/manifests.d.ts +0 -61
  86. package/dist/helpers/market-data-vendor-backfill/promotion.d.ts +0 -10
  87. package/dist/helpers/market-data-vendor-backfill/qualification.d.ts +0 -20
  88. package/dist/helpers/market-data-vendor-backfill/selection.d.ts +0 -30
  89. package/dist/helpers/market-data-vendor-backfill/semantic-verification.d.ts +0 -25
  90. package/dist/helpers/market-type.d.ts +0 -16
  91. package/dist/helpers/order-activity-tracker.d.ts +0 -22
  92. package/dist/helpers/order-book.d.ts +0 -79
  93. package/dist/helpers/order-telemetry.d.ts +0 -50
  94. package/dist/helpers/otel.d.ts +0 -83
  95. package/dist/helpers/passive-order.d.ts +0 -8
  96. package/dist/helpers/public-market-data-feed/identity.d.ts +0 -12
  97. package/dist/helpers/public-market-data-feed/index.d.ts +0 -5
  98. package/dist/helpers/public-market-data-feed/orderbook-coalescing-evidence.d.ts +0 -79
  99. package/dist/helpers/public-market-data-feed/orderbook-profile.d.ts +0 -54
  100. package/dist/helpers/public-market-data-feed/subscriber-buffer.d.ts +0 -31
  101. package/dist/helpers/public-market-data-feed/supervisor.d.ts +0 -82
  102. package/dist/helpers/shared/errors.d.ts +0 -14
  103. package/dist/helpers/shared/guards.d.ts +0 -2
  104. package/dist/helpers/source-tape-sandbox.d.ts +0 -82
  105. package/dist/helpers/source-tape.d.ts +0 -165
  106. package/dist/helpers/stream-health-publisher.d.ts +0 -41
  107. package/dist/helpers/trace-context.d.ts +0 -8
  108. package/dist/helpers/transfer-network.d.ts +0 -12
  109. package/dist/helpers/travel-rule-deposit-reconciler.d.ts +0 -159
  110. package/dist/helpers/travel-rule.d.ts +0 -75
  111. package/dist/helpers/treasury-discovery.d.ts +0 -17
  112. package/dist/helpers/user-asset-archive-poller.d.ts +0 -19
  113. package/dist/helpers/user-data-stream-supervisor.d.ts +0 -27
  114. package/dist/helpers/verity.d.ts +0 -5
  115. package/dist/index.d.ts +0 -56
  116. package/dist/market-data-preparation/fixtures/conformance-v3.json +0 -621
  117. package/dist/market-data-preparation/policies/capability-policy.json +0 -39
  118. package/dist/market-data-preparation/policies/resource-policy.json +0 -16
  119. package/dist/market-data-preparation/policies/source-tape-capability-v1.json +0 -35
  120. package/dist/market-data-preparation/schema-manifest.json +0 -66
  121. package/dist/market-data-preparation/schemas/archive-selection-v1.schema.json +0 -224
  122. package/dist/market-data-preparation/schemas/backfill-request-v1.schema.json +0 -166
  123. package/dist/market-data-preparation/schemas/backfill-result-v2.schema.json +0 -212
  124. package/dist/market-data-preparation/schemas/canonical-orderbook-export-request-v1.schema.json +0 -61
  125. package/dist/market-data-preparation/schemas/canonical-orderbook-export-result-v2.schema.json +0 -252
  126. package/dist/market-data-preparation/schemas/order-book-depth-summary-parquet-projection-v1.schema.json +0 -256
  127. package/dist/market-data-preparation/schemas/order-book-levels-parquet-projection-v1.schema.json +0 -220
  128. package/dist/market-data-preparation/schemas/preparation-product-pin-v2.schema.json +0 -176
  129. package/dist/market-data-preparation/schemas/promotion-receipt-v1.schema.json +0 -175
  130. package/dist/market-data-preparation/schemas/required-clock-v1.schema.json +0 -47
  131. package/dist/market-data-preparation/schemas/source-forensics-ledger-v1.schema.json +0 -463
  132. package/dist/market-data-preparation/schemas/source-qualification-record-v1.schema.json +0 -394
  133. package/dist/market-data-preparation.d.ts +0 -11
  134. package/dist/market-data-preparation.js +0 -37488
  135. package/dist/market-data-preparation.js.map +0 -277
  136. package/dist/market-data-vendor-backfill.d.ts +0 -21
  137. package/dist/market-data-vendor-backfill.js +0 -22463
  138. package/dist/market-data-vendor-backfill.js.map +0 -199
  139. package/dist/proto/node.descriptor.d.ts +0 -127
  140. package/dist/proto-loader-options.d.ts +0 -7
  141. package/dist/proto-package-definition.d.ts +0 -2
  142. package/dist/schemas/action-payloads.d.ts +0 -88
  143. package/dist/server.d.ts +0 -10
  144. package/dist/types.d.ts +0 -100
@@ -1,50 +0,0 @@
1
- import type * as grpc from "@grpc/grpc-js";
2
- import type { Metadata } from "@grpc/grpc-js";
3
- import type { Exchange } from "@usherlabs/ccxt";
4
- import type { z } from "zod";
5
- import type { BrokerAccount, BrokerPoolEntry } from "../../helpers";
6
- import type { BrokerExecutionArchiver, WithdrawalObservationTracker } from "../../helpers/broker-execution-archive";
7
- import type { Action as ActionType } from "../../helpers/constants";
8
- import type { OrderActivityTracker } from "../../helpers/order-activity-tracker";
9
- import type { OtelMetrics } from "../../helpers/otel";
10
- import type { PolicyConfig } from "../../types";
11
- import type { ActionRequest, ActionResponse } from "../types";
12
- export type ActionHandler = (ctx: ExecuteActionContext) => Promise<void>;
13
- export type ExecuteActionContext = {
14
- call: grpc.ServerUnaryCall<ActionRequest, ActionResponse>;
15
- wrappedCallback: grpc.sendUnaryData<ActionResponse>;
16
- action: ActionType;
17
- policy: PolicyConfig;
18
- brokers: Record<string, BrokerPoolEntry>;
19
- metadata: Metadata;
20
- normalizedCex: string;
21
- cex: string;
22
- symbol?: string;
23
- selectedBrokerAccount?: BrokerAccount;
24
- broker: Exchange;
25
- verity: {
26
- proof: string;
27
- };
28
- applyVerityToBroker: (target: Exchange) => void;
29
- useVerity: boolean;
30
- verityProverUrl: string;
31
- otelMetrics?: OtelMetrics;
32
- brokerArchiver?: BrokerExecutionArchiver;
33
- orderActivityTracker?: OrderActivityTracker;
34
- withdrawalObservationTracker: WithdrawalObservationTracker;
35
- };
36
- export declare function requireSymbol(ctx: ExecuteActionContext, message?: string): ctx is ExecuteActionContext & {
37
- symbol: string;
38
- };
39
- export declare function parsePayloadForAction<T>(ctx: ExecuteActionContext, schema: z.ZodType<T>): T | null;
40
- export declare function rejectWithGrpcError(ctx: ExecuteActionContext, error: unknown, options?: {
41
- message?: string;
42
- prefix?: string;
43
- preferStableMessageOnly?: boolean;
44
- /** Append the caught error's class name (e.g. InsufficientFunds) as a
45
- * suffix. It goes last, not in front, because the gRPC status code is
46
- * derived from the raw message via stableGrpcErrorCode; prepending the
47
- * class name would break that prefix match. */
48
- appendClassName?: boolean;
49
- }): void;
50
- export declare function successWithProof(ctx: ExecuteActionContext, result: unknown): void;
@@ -1,2 +0,0 @@
1
- import type { ExecuteActionContext } from "./context";
2
- export declare function handleDeposit(ctx: ExecuteActionContext): Promise<void>;
@@ -1,19 +0,0 @@
1
- import * as grpc from "@grpc/grpc-js";
2
- import { type BrokerPoolEntry } from "../../helpers/broker";
3
- import { type BrokerExecutionArchiver, WithdrawalObservationTracker } from "../../helpers/broker-execution-archive";
4
- import type { OrderActivityTracker } from "../../helpers/order-activity-tracker";
5
- import type { OtelMetrics } from "../../helpers/otel";
6
- import type { PolicyConfig } from "../../types";
7
- import type { ActionRequest, ActionResponse } from "../types";
8
- export type ExecuteActionDeps = {
9
- policy: PolicyConfig;
10
- brokers: Record<string, BrokerPoolEntry>;
11
- whitelistIps: string[];
12
- useVerity: boolean;
13
- verityProverUrl: string;
14
- otelMetrics?: OtelMetrics;
15
- brokerArchiver?: BrokerExecutionArchiver;
16
- orderActivityTracker?: OrderActivityTracker;
17
- withdrawalObservationTracker?: WithdrawalObservationTracker;
18
- };
19
- export declare function createExecuteActionHandler(deps: ExecuteActionDeps): (call: grpc.ServerUnaryCall<ActionRequest, ActionResponse>, callback: grpc.sendUnaryData<ActionResponse>) => Promise<void>;
@@ -1,10 +0,0 @@
1
- export type { ActionHandler, ExecuteActionContext } from "./context";
2
- export { handleDeposit } from "./deposit";
3
- export { createExecuteActionHandler, type ExecuteActionDeps, } from "./handler";
4
- export { handleInternalTransfer } from "./internal-transfer";
5
- export { handleOrderBookCall } from "./order-book-call";
6
- export { handleOrders } from "./orders";
7
- export { handlePassThrough } from "./pass-through";
8
- export { ACTION_HANDLERS, dispatchExecuteAction } from "./registry";
9
- export { handleTreasuryCall } from "./treasury-call";
10
- export { handleWithdraw } from "./withdraw";
@@ -1,2 +0,0 @@
1
- import type { ExecuteActionContext } from "./context";
2
- export declare function handleInternalTransfer(ctx: ExecuteActionContext): Promise<void>;
@@ -1,3 +0,0 @@
1
- import type { ExecuteActionContext } from "./context";
2
- /** Handles Action.Call order-book methods before generic broker dispatch. Returns true when fully handled. */
3
- export declare function handleOrderBookCall(ctx: ExecuteActionContext): Promise<boolean>;
@@ -1,2 +0,0 @@
1
- import type { ExecuteActionContext } from "./context";
2
- export declare function handleOrders(ctx: ExecuteActionContext): Promise<void>;
@@ -1,2 +0,0 @@
1
- import type { ExecuteActionContext } from "./context";
2
- export declare function handlePassThrough(ctx: ExecuteActionContext): Promise<void>;
@@ -1,2 +0,0 @@
1
- import type { ExecuteActionContext } from "./context";
2
- export declare function handlePerpConfig(ctx: ExecuteActionContext): Promise<void>;
@@ -1,5 +0,0 @@
1
- import { type Action as ActionType } from "../../helpers/constants";
2
- import type { ActionHandler, ExecuteActionContext } from "./context";
3
- /** Maps each ExecuteAction to its handler module. Cluster routers (orders, pass-through) are registered per action. */
4
- export declare const ACTION_HANDLERS: Partial<Record<ActionType, ActionHandler>>;
5
- export declare function dispatchExecuteAction(ctx: ExecuteActionContext): Promise<void>;
@@ -1,2 +0,0 @@
1
- import type { ExecuteActionContext } from "./context";
2
- export declare function handleTreasuryCall(ctx: ExecuteActionContext): Promise<void>;
@@ -1,2 +0,0 @@
1
- import type { ExecuteActionContext } from "./context";
2
- export declare function handleWithdraw(ctx: ExecuteActionContext): Promise<void>;
@@ -1,13 +0,0 @@
1
- import type { Exchange } from "@usherlabs/ccxt";
2
- type BrokerContext = {
3
- cex: string;
4
- symbol: string;
5
- };
6
- export type BrokerCloseOutcome = "closed" | "failed";
7
- export declare class SubscribeBrokerLifecycle {
8
- #private;
9
- register(broker: Exchange, context: BrokerContext): void;
10
- close(broker: Exchange): Promise<BrokerCloseOutcome>;
11
- closeAll(): Promise<void>;
12
- }
13
- export {};
@@ -1,20 +0,0 @@
1
- import * as grpc from "@grpc/grpc-js";
2
- import { type BrokerPoolEntry } from "../../helpers/broker";
3
- import type { BrokerExecutionArchiver } from "../../helpers/broker-execution-archive";
4
- import type { OtelMetrics } from "../../helpers/otel";
5
- import { PublicMarketDataFeedSupervisor } from "../../helpers/public-market-data-feed";
6
- import type { UserDataStreamSupervisor } from "../../helpers/user-data-stream-supervisor";
7
- import type { SubscribeRequest, SubscribeResponse } from "../types";
8
- import { SubscribeBrokerLifecycle } from "./broker-lifecycle";
9
- export type SubscribeDeps = {
10
- brokers: Record<string, BrokerPoolEntry>;
11
- whitelistIps: string[];
12
- otelMetrics?: OtelMetrics;
13
- brokerArchiver?: BrokerExecutionArchiver;
14
- brokerLifecycle?: SubscribeBrokerLifecycle;
15
- userDataStreamSupervisor?: UserDataStreamSupervisor;
16
- publicMarketDataFeedSupervisor?: PublicMarketDataFeedSupervisor;
17
- };
18
- type SubscribeCall = grpc.ServerWritableStream<SubscribeRequest, SubscribeResponse>;
19
- export declare function createSubscribeHandler(deps: SubscribeDeps): (call: SubscribeCall) => Promise<void>;
20
- export {};
@@ -1,2 +0,0 @@
1
- export { SubscribeBrokerLifecycle } from "./broker-lifecycle";
2
- export { createSubscribeHandler, type SubscribeDeps } from "./handler";
@@ -1,23 +0,0 @@
1
- import type { ActionName, Action as ActionType, SubscriptionTypeName, SubscriptionType as SubscriptionTypeValue } from "../helpers/constants";
2
- export type ActionRequest = {
3
- action?: ActionType | ActionName;
4
- payload?: Record<string, string>;
5
- cex?: string;
6
- symbol?: string;
7
- };
8
- export type ActionResponse = {
9
- result: string;
10
- proof?: string;
11
- };
12
- export type SubscribeRequest = {
13
- cex?: string;
14
- symbol?: string;
15
- type?: SubscriptionTypeValue | SubscriptionTypeName;
16
- options?: Record<string, string>;
17
- };
18
- export type SubscribeResponse = {
19
- data: string;
20
- timestamp: number;
21
- symbol: string;
22
- type: SubscriptionTypeValue;
23
- };
@@ -1,19 +0,0 @@
1
- import type { BrokerPoolEntry } from "./broker";
2
- import { type BrokerExecutionArchiver } from "./broker-execution-archive";
3
- import type { OtelMetrics } from "./otel";
4
- export type AccountBalanceArchivePollerConfig = {
5
- pollIntervalMs: number;
6
- };
7
- export declare class AccountBalanceArchivePoller {
8
- #private;
9
- private readonly params;
10
- constructor(params: {
11
- brokers: Record<string, BrokerPoolEntry>;
12
- archiver: BrokerExecutionArchiver;
13
- metrics?: OtelMetrics;
14
- config?: Partial<AccountBalanceArchivePollerConfig>;
15
- });
16
- start(): void;
17
- stop(): Promise<void>;
18
- pollAllOnce(): Promise<boolean>;
19
- }
@@ -1,5 +0,0 @@
1
- type GrpcPeerCall = {
2
- getPeer(): string;
3
- };
4
- export declare function authenticateRequest(call: GrpcPeerCall, whitelistIps: string[]): boolean;
5
- export {};
@@ -1,16 +0,0 @@
1
- import type { BrokerPoolEntry } from "./broker";
2
- import { type BrokerExecutionArchiver } from "./broker-execution-archive";
3
- import type { UserDataStreamSupervisor } from "./user-data-stream-supervisor";
4
- type BalanceUpdateSubscriptionSource = Pick<UserDataStreamSupervisor, "subscribe">;
5
- export declare class BalanceUpdateArchiveConsumer {
6
- #private;
7
- private readonly params;
8
- constructor(params: {
9
- brokers: Record<string, BrokerPoolEntry>;
10
- archiver: BrokerExecutionArchiver;
11
- userDataStreamSupervisor: BalanceUpdateSubscriptionSource;
12
- });
13
- start(): void;
14
- stop(): Promise<void>;
15
- }
16
- export {};
@@ -1,3 +0,0 @@
1
- import type { Exchange } from "@usherlabs/ccxt";
2
- export declare function normalizeBinanceSpotBalanceEvent(exchange: Exchange, event: Record<string, unknown>): Promise<unknown>;
3
- export declare function normalizeBinanceExecutionReport(exchange: Exchange, event: Record<string, unknown>): Record<string, unknown>;
@@ -1,58 +0,0 @@
1
- import type { Exchange } from "@usherlabs/ccxt";
2
- export declare const BINANCE_SPOT_WS_API_URL = "wss://ws-api.binance.com:443/ws-api/v3";
3
- export declare const DEFAULT_BINANCE_USER_DATA_MAX_BUFFERED_EVENTS = 16;
4
- export type BinanceUserDataEvent = {
5
- subscriptionId: number;
6
- event: Record<string, unknown>;
7
- };
8
- export type BinanceUserDataStreamFailureKind = "auth_failed" | "transport_error" | "remote_closed" | "protocol_error" | "backpressure";
9
- export type BinanceUserDataStreamObserver = {
10
- onConnected?: () => void;
11
- onAuthenticated?: () => void;
12
- onEvent?: (event: BinanceUserDataEvent) => void;
13
- onFailure?: (failure: {
14
- kind: BinanceUserDataStreamFailureKind;
15
- reason: string;
16
- }) => void;
17
- };
18
- type WebSocketLike = {
19
- on(event: "open", listener: () => void): unknown;
20
- on(event: "message", listener: (data: unknown) => void): unknown;
21
- on(event: "error", listener: (error: unknown) => void): unknown;
22
- on(event: "close", listener: (code: unknown, reason: unknown) => void): unknown;
23
- send(data: string): void;
24
- close(code?: number, reason?: string): void;
25
- };
26
- type WebSocketFactory = (url: string) => WebSocketLike;
27
- type BinanceSpotUserDataStreamOptions = {
28
- maxBufferedEvents?: number;
29
- observer?: BinanceUserDataStreamObserver;
30
- };
31
- export declare function setBinanceUserDataWebSocketFactoryForTests(factory: WebSocketFactory): () => void;
32
- export declare function getBinanceSpotWsApiUrl(exchange: Exchange): string;
33
- export declare class BinanceSpotUserDataStream implements AsyncIterable<BinanceUserDataEvent> {
34
- private readonly exchange;
35
- private readonly ws;
36
- private readonly secretValues;
37
- private readonly requestId;
38
- private readonly maxBufferedEvents;
39
- private readonly observer?;
40
- private readonly queue;
41
- private readonly waiters;
42
- private closed;
43
- private closeError;
44
- private subscriptionId;
45
- constructor(exchange: Exchange, options?: BinanceSpotUserDataStreamOptions);
46
- [Symbol.asyncIterator](): AsyncIterator<BinanceUserDataEvent>;
47
- close(): void;
48
- private handleClose;
49
- private subscribe;
50
- private handleMessage;
51
- private push;
52
- private nextEvent;
53
- private fail;
54
- private flushWaiters;
55
- }
56
- export declare function isBinanceBalanceUserDataEvent(event: Record<string, unknown>): boolean;
57
- export declare function isBinanceOrderUserDataEvent(event: Record<string, unknown>): boolean;
58
- export {};
@@ -1,41 +0,0 @@
1
- import type { Exchange } from "@usherlabs/ccxt";
2
- import { type OrderTelemetryAction, type OrderTelemetryContext } from "../order-telemetry";
3
- import { type TransferArchiveFields } from "./rows";
4
- import type { SubscribeArchiveType } from "./types";
5
- import type { WithdrawalObservationTracker } from "./withdrawal-observation-tracker";
6
- import { type BrokerExecutionArchiver } from "./writer";
7
- export declare function archiveOrderExecutionInBackground(archiver: BrokerExecutionArchiver | undefined, context: OrderTelemetryContext, order: unknown, error?: unknown, options?: {
8
- marketMetadataHash?: string;
9
- }): void;
10
- export declare function archiveSubscribeStreamInBackground(archiver: BrokerExecutionArchiver | undefined, input: {
11
- exchange: string;
12
- accountSelector?: string;
13
- symbol: string;
14
- subscriptionType: SubscribeArchiveType;
15
- streamPayload: unknown;
16
- secretLiterals?: readonly string[];
17
- }): void;
18
- export declare function archiveTransferEventInBackground(archiver: BrokerExecutionArchiver | undefined, input: {
19
- exchange: string;
20
- accountSelector?: string;
21
- assetSymbol?: string;
22
- brokerObservedTimestamp?: string;
23
- transfer: TransferArchiveFields;
24
- }): void;
25
- export declare function archiveWithdrawalObservationsInBackground(archiver: BrokerExecutionArchiver | undefined, tracker: WithdrawalObservationTracker, input: {
26
- exchange: string;
27
- accountSelector?: string;
28
- transactions: unknown;
29
- }): void;
30
- export declare function captureMarketMetadataSnapshot(archiver: BrokerExecutionArchiver | undefined, broker: Exchange, input: {
31
- exchange: string;
32
- accountSelector?: string;
33
- symbol: string;
34
- action: OrderTelemetryAction;
35
- clientOrderId?: string;
36
- orderId?: string;
37
- makerActionId?: string;
38
- idempotencyId?: string;
39
- brokerObservedTimestamp?: string;
40
- }): Promise<string | undefined>;
41
- export declare function captureMarketMetadataSnapshotInBackground(archiver: BrokerExecutionArchiver | undefined, broker: Exchange, input: Parameters<typeof captureMarketMetadataSnapshot>[2]): void;
@@ -1,7 +0,0 @@
1
- export { archiveOrderExecutionInBackground, archiveSubscribeStreamInBackground, archiveTransferEventInBackground, archiveWithdrawalObservationsInBackground, captureMarketMetadataSnapshot, captureMarketMetadataSnapshotInBackground, } from "./capture";
2
- export { DeadLetterJournalExportError, type DeadLetterJournalExportResult, exportDeadLetterJournal, exportDeadLetterJournalFromEnv, } from "./journal-export";
3
- export { hashMarketMetadata, redactErrorForArchive, redactSecretLiterals, redactStreamPayload, } from "./redact";
4
- export { buildAccountBalanceSnapshotRow, buildCommonArchiveTags, buildFillEventArchiveRow, buildMarketMetadataSnapshotRow, buildOrderEventArchiveRow, buildSubscribeStreamArchiveRow, buildTransferEventArchiveRow, buildUserAssetSnapshotRow, extractBinanceInternalTransferId, type FillArchiveFields, type NormalizedCcxtBalance, type NormalizedCcxtTransfer, type NormalizedUserAssets, normalizeBinanceUserAssetsForArchive, normalizeCcxtBalanceForArchive, normalizeCcxtTradeForArchive, normalizeCcxtTransactionForArchive, normalizeTimestamp, type TransferArchiveFields, } from "./rows";
5
- export { ACCOUNT_BALANCE_PRECISION_BASIS, ACCOUNT_BALANCE_SCOPE, ARCHIVE_SCHEMA_VERSION, BROKER_READ_SOURCE, BROKER_WRITE_SOURCE, type BrokerArchiveCommonTags, type BrokerArchiveRow, type BrokerArchiveSource, type BrokerArchiveTable, type OrderArchiveAction, type SubscribeArchiveType, type TransferEventKind, type TransferLifecycleAction, USER_ASSET_BALANCE_SCOPE, USER_ASSET_PRECISION_BASIS, } from "./types";
6
- export { DEFAULT_WITHDRAWAL_OBSERVATION_TRACKER_MAX_ENTRIES, WithdrawalObservationTracker, } from "./withdrawal-observation-tracker";
7
- export { BrokerExecutionArchiveDurabilityError, BrokerExecutionArchiver, type BrokerExecutionArchiverOptions, createBrokerExecutionArchiverFromEnv, isArchiveOtelLogsEnabled, isBrokerExecutionArchiveTable, resolveArchiveForwarderUrlFromEnv, rethrowArchiveDurabilityError, } from "./writer";
@@ -1,20 +0,0 @@
1
- export declare class DeadLetterJournalExportError extends Error {
2
- constructor(message: string, options?: ErrorOptions);
3
- }
4
- export type DeadLetterJournalExportResult = {
5
- status: "disabled";
6
- } | {
7
- status: "skipped_export_exists";
8
- exportPath: string;
9
- } | {
10
- status: "skipped_missing_journal";
11
- journalPath: string;
12
- } | {
13
- status: "exported";
14
- journalPath: string;
15
- exportPath: string;
16
- bytes: number;
17
- sha256: string;
18
- };
19
- export declare function exportDeadLetterJournalFromEnv(): DeadLetterJournalExportResult;
20
- export declare function exportDeadLetterJournal(journalPath: string, exportPath: string): DeadLetterJournalExportResult;
@@ -1,36 +0,0 @@
1
- import type { BrokerArchiveRow, BrokerArchiveSource } from "./types";
2
- export declare const LOSS_JOURNAL_RECORD_VERSION: 1;
3
- export type ArchiveLossReason = "queue_shed" | "shutdown_forwarder_failure" | "retry_exhausted";
4
- export type ArchiveLossRecord = {
5
- timestamp: string;
6
- source: BrokerArchiveSource;
7
- deployment_id: string;
8
- reason: ArchiveLossReason;
9
- payload: BrokerArchiveRow;
10
- record_version: typeof LOSS_JOURNAL_RECORD_VERSION;
11
- batch_id: string | null;
12
- batch_row_index: number;
13
- batch_row_count: number;
14
- };
15
- type ParsedArchiveLossRecordBase = Omit<ArchiveLossRecord, "payload" | "record_version" | "batch_id" | "batch_row_index" | "batch_row_count"> & {
16
- payload: {
17
- table: string;
18
- row: Record<string, unknown>;
19
- };
20
- };
21
- export type ParsedArchiveLossRecord = ParsedArchiveLossRecordBase & (Pick<ArchiveLossRecord, "record_version" | "batch_id" | "batch_row_index" | "batch_row_count"> | {
22
- record_version?: never;
23
- batch_id?: never;
24
- batch_row_index?: never;
25
- batch_row_count?: never;
26
- });
27
- export type ParsedLossJournalLine = {
28
- ok: true;
29
- record: ParsedArchiveLossRecord;
30
- } | {
31
- ok: false;
32
- reason: string;
33
- };
34
- export declare function parseLossJournalLine(line: string): ParsedLossJournalLine;
35
- export declare function lossJournalLineDigest(rawLine: string): string;
36
- export {};
@@ -1,7 +0,0 @@
1
- export declare function redactErrorForArchive(error: unknown): {
2
- error_type?: string;
3
- error_message?: string;
4
- };
5
- export declare function redactSecretLiterals(value: string, secretLiterals?: readonly string[]): string;
6
- export declare function redactStreamPayload(payload: unknown, secretLiterals?: readonly string[]): Record<string, unknown>;
7
- export declare function hashMarketMetadata(payload: unknown): string | undefined;
@@ -1,134 +0,0 @@
1
- import type { OrderExecutionTelemetry } from "../order-telemetry";
2
- import { type BrokerArchiveCommonTags, type BrokerArchiveRow, type BrokerArchiveSource, type OrderArchiveAction, type SubscribeArchiveType, type TransferEventKind, type TransferLifecycleAction } from "./types";
3
- type BalanceQuantityMap = Record<string, string>;
4
- export type NormalizedCcxtBalance = {
5
- exchangeTimestamp?: string;
6
- reportedAssets: string[];
7
- assetEntryAssets: string[];
8
- freeBalances: BalanceQuantityMap;
9
- usedBalances: BalanceQuantityMap;
10
- totalBalances: BalanceQuantityMap;
11
- freeMapPresent: boolean;
12
- usedMapPresent: boolean;
13
- totalMapPresent: boolean;
14
- };
15
- export declare function normalizeTimestamp(value: unknown): string | undefined;
16
- export declare function normalizeCcxtBalanceForArchive(balance: unknown): NormalizedCcxtBalance;
17
- export declare function buildAccountBalanceSnapshotRow(input: {
18
- tags: BrokerArchiveCommonTags;
19
- balance: NormalizedCcxtBalance;
20
- }): BrokerArchiveRow;
21
- export type NormalizedUserAssets = {
22
- reportedAssets: string[];
23
- incompleteAssets: string[];
24
- freeBalances: BalanceQuantityMap;
25
- lockedBalances: BalanceQuantityMap;
26
- freezeBalances: BalanceQuantityMap;
27
- withdrawingBalances: BalanceQuantityMap;
28
- };
29
- /**
30
- * Normalizes a `POST /sapi/v3/asset/getUserAsset` response into one coherent
31
- * snapshot.
32
- *
33
- * Fails closed on a response shape we cannot account for: a non-array body or a
34
- * duplicate/unkeyed asset entry would each drop owned quantity on the floor, and
35
- * an under-counted NAV is worse than an absent one. Per-bucket uncertainty is
36
- * narrower and is reported rather than thrown: the asset is listed in
37
- * `incompleteAssets` and its key is left out of the bucket map, so a reader sees
38
- * "unknown", never an implicit zero.
39
- */
40
- export declare function normalizeBinanceUserAssetsForArchive(response: unknown): NormalizedUserAssets;
41
- export declare function buildUserAssetSnapshotRow(input: {
42
- tags: BrokerArchiveCommonTags;
43
- userAssets: NormalizedUserAssets;
44
- }): BrokerArchiveRow;
45
- export declare function buildCommonArchiveTags(input: {
46
- source?: BrokerArchiveSource;
47
- deploymentId: string;
48
- accountSelector?: string;
49
- exchange: string;
50
- symbol?: string;
51
- brokerObservedTimestamp?: string;
52
- }): BrokerArchiveCommonTags;
53
- export declare function buildOrderEventArchiveRow(input: {
54
- tags: BrokerArchiveCommonTags;
55
- action: OrderArchiveAction;
56
- telemetry: OrderExecutionTelemetry;
57
- errorDetail?: string;
58
- eventKind?: "execute_action" | "subscribe_stream";
59
- subscriptionType?: SubscribeArchiveType;
60
- marketMetadataHash?: string;
61
- }): BrokerArchiveRow;
62
- export declare function buildSubscribeStreamArchiveRow(input: {
63
- tags: BrokerArchiveCommonTags;
64
- subscriptionType: SubscribeArchiveType;
65
- streamPayload: unknown;
66
- secretLiterals?: readonly string[];
67
- }): BrokerArchiveRow;
68
- export declare function extractBinanceInternalTransferId(response: unknown): string | undefined;
69
- export type TransferArchiveFields = {
70
- eventKind: TransferEventKind;
71
- lifecycleAction: TransferLifecycleAction;
72
- status?: string;
73
- assetSymbol?: string;
74
- amount?: string;
75
- address?: string;
76
- network?: string;
77
- externalId?: string;
78
- clientWithdrawalId?: string;
79
- txid?: string;
80
- resultIndex?: number;
81
- feeAmount?: string;
82
- feeCurrency?: string;
83
- exchangeTimestamp?: string;
84
- errorSummary?: string;
85
- payload: unknown;
86
- };
87
- export declare function buildTransferEventArchiveRow(input: {
88
- tags: BrokerArchiveCommonTags;
89
- transfer: TransferArchiveFields;
90
- }): BrokerArchiveRow;
91
- export type NormalizedCcxtTransfer = {
92
- externalId?: string;
93
- clientWithdrawalId?: string;
94
- txid?: string;
95
- address?: string;
96
- network?: string;
97
- amount?: string;
98
- assetSymbol?: string;
99
- status?: string;
100
- feeAmount?: string;
101
- feeCurrency?: string;
102
- exchangeTimestamp?: string;
103
- };
104
- export declare function normalizeCcxtTransactionForArchive(transaction: unknown): NormalizedCcxtTransfer;
105
- export type FillArchiveFields = {
106
- orderId?: string;
107
- clientOrderId?: string;
108
- fillId?: string;
109
- fillIndex?: number;
110
- side?: string;
111
- orderType?: string;
112
- price?: string;
113
- baseQuantity?: string;
114
- quoteQuantity?: string;
115
- feeAmount?: string;
116
- feeCurrency?: string;
117
- feeRate?: string;
118
- exchangeTimestamp?: string;
119
- payload: unknown;
120
- };
121
- export declare function buildFillEventArchiveRow(input: {
122
- tags: BrokerArchiveCommonTags;
123
- fill: FillArchiveFields;
124
- }): BrokerArchiveRow;
125
- export declare function normalizeCcxtTradeForArchive(trade: unknown): FillArchiveFields;
126
- export declare function buildMarketMetadataSnapshotRow(input: {
127
- tags: BrokerArchiveCommonTags;
128
- clientOrderId?: string;
129
- orderId?: string;
130
- makerActionId?: string;
131
- idempotencyId?: string;
132
- marketSnapshot: unknown;
133
- }): BrokerArchiveRow;
134
- export {};
@@ -1,26 +0,0 @@
1
- export declare const BROKER_READ_SOURCE: "broker_read";
2
- export declare const BROKER_WRITE_SOURCE: "broker_write";
3
- export type BrokerArchiveSource = typeof BROKER_READ_SOURCE | typeof BROKER_WRITE_SOURCE;
4
- export declare const ARCHIVE_SCHEMA_VERSION: "1";
5
- export type BrokerArchiveTable = "broker_execution.order_events" | "broker_execution.market_metadata_snapshots" | "broker_execution.transfer_events" | "broker_execution.fill_events" | "broker_account.balance_snapshots" | "broker_account.user_asset_snapshots" | "market_data.orderbook_snapshots" | "market_data.candles" | "market_data.cex_stream_events" | "market_data.cex_ticker_events" | "market_data.cex_trades" | "market_data.cex_ohlcv" | "market_data.cex_order_book_levels" | "market_data.cex_order_book_depth_summary";
6
- export type BrokerArchiveRow = {
7
- table: BrokerArchiveTable;
8
- row: Record<string, unknown>;
9
- };
10
- export type BrokerArchiveCommonTags = {
11
- source: BrokerArchiveSource;
12
- deployment_id: string;
13
- account_selector: string;
14
- exchange: string;
15
- symbol: string;
16
- broker_observed_timestamp: string;
17
- };
18
- export type OrderArchiveAction = "CreateOrder" | "CancelOrder" | "GetOrderDetails";
19
- export type SubscribeArchiveType = "ORDERS" | "BALANCE";
20
- export type TransferEventKind = "withdrawal" | "deposit" | "internal_transfer" | "balance_delta";
21
- export type TransferLifecycleAction = "submit_withdrawal" | "observe_withdrawal" | "observe_deposit" | "observe_balance_update" | "submit_internal_transfer";
22
- export declare const FILL_EVENT_KIND: "trade_history_fill";
23
- export declare const ACCOUNT_BALANCE_SCOPE: "spot";
24
- export declare const ACCOUNT_BALANCE_PRECISION_BASIS: "ccxt_normalized_number";
25
- export declare const USER_ASSET_BALANCE_SCOPE: "user_asset";
26
- export declare const USER_ASSET_PRECISION_BASIS: "venue_raw_string";
@@ -1,23 +0,0 @@
1
- import type { NormalizedCcxtTransfer } from "./rows";
2
- export declare const DEFAULT_WITHDRAWAL_OBSERVATION_TRACKER_MAX_ENTRIES = 10000;
3
- type WithdrawalObservation = {
4
- exchange: string;
5
- accountSelector?: string;
6
- assetSymbol?: string;
7
- transaction: unknown;
8
- normalized: NormalizedCcxtTransfer;
9
- };
10
- /**
11
- * Suppresses unchanged withdrawal-history observations within one broker process.
12
- * The tracker intentionally persists no state: restart replay is absorbed by
13
- * archive consumers, while the in-process bound prevents unbounded venue history.
14
- */
15
- export declare class WithdrawalObservationTracker {
16
- #private;
17
- constructor(options?: {
18
- maxEntries?: number;
19
- });
20
- shouldArchive(observation: WithdrawalObservation): boolean;
21
- getSize(): number;
22
- }
23
- export {};