@usherlabs/cex-broker 0.2.49 → 0.2.51

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 (55) hide show
  1. package/dist/commands/cex-canonical-orderbook-export.js +7747 -883
  2. package/dist/commands/cex-canonical-orderbook-export.js.map +41 -10
  3. package/dist/commands/cli.js +127 -34
  4. package/dist/commands/market-data-vendor-backfill.js +8284 -6391
  5. package/dist/commands/market-data-vendor-backfill.js.map +16 -15
  6. package/dist/helpers/canonical-orderbook-export/parquet-projection.d.ts +19 -0
  7. package/dist/helpers/market-data-archive/canonical-orderbook.d.ts +1 -1
  8. package/dist/helpers/market-data-preparation/conformance-fixtures.d.ts +114 -2
  9. package/dist/helpers/market-data-preparation/contracts.d.ts +1298 -18
  10. package/dist/helpers/market-data-preparation/required-clock-qualification.d.ts +43 -0
  11. package/dist/helpers/market-data-preparation/source-tape-dependencies.d.ts +19 -0
  12. package/dist/helpers/market-data-preparation/source-tape-operation.d.ts +109 -0
  13. package/dist/helpers/market-data-source-forensics.d.ts +400 -0
  14. package/dist/helpers/market-data-vendor-backfill/conformance-fixtures.d.ts +3 -5
  15. package/dist/helpers/market-data-vendor-backfill/contracts.d.ts +21 -56
  16. package/dist/helpers/market-data-vendor-backfill/core.d.ts +1 -0
  17. package/dist/helpers/market-data-vendor-backfill/cryptohftdata.d.ts +45 -5
  18. package/dist/helpers/market-data-vendor-backfill/manifests.d.ts +31 -1083
  19. package/dist/helpers/market-data-vendor-backfill/promotion.d.ts +1 -0
  20. package/dist/helpers/source-tape-sandbox.d.ts +82 -0
  21. package/dist/helpers/source-tape.d.ts +165 -0
  22. package/dist/helpers/trace-context.d.ts +8 -0
  23. package/dist/index.js +128 -35
  24. package/dist/index.js.map +7 -6
  25. package/dist/market-data-preparation/fixtures/{conformance-v2.json → conformance-v3.json} +257 -60
  26. package/dist/market-data-preparation/policies/capability-policy.json +15 -4
  27. package/dist/market-data-preparation/policies/resource-policy.json +3 -3
  28. package/dist/market-data-preparation/policies/source-tape-capability-v1.json +35 -0
  29. package/dist/market-data-preparation/schema-manifest.json +30 -10
  30. package/dist/market-data-preparation/schemas/canonical-orderbook-export-request-v1.schema.json +5 -1
  31. package/dist/market-data-preparation/schemas/{canonical-orderbook-export-result-v1.schema.json → canonical-orderbook-export-result-v2.schema.json} +20 -6
  32. package/dist/market-data-preparation/schemas/order-book-depth-summary-parquet-projection-v1.schema.json +256 -0
  33. package/dist/market-data-preparation/schemas/order-book-levels-parquet-projection-v1.schema.json +220 -0
  34. package/dist/market-data-preparation/schemas/{preparation-product-pin-v1.schema.json → preparation-product-pin-v2.schema.json} +59 -9
  35. package/dist/market-data-preparation/schemas/promotion-receipt-v1.schema.json +5 -1
  36. package/dist/market-data-preparation/schemas/source-forensics-ledger-v1.schema.json +463 -0
  37. package/dist/market-data-preparation/schemas/source-qualification-record-v1.schema.json +394 -0
  38. package/dist/market-data-preparation.d.ts +7 -0
  39. package/dist/market-data-preparation.js +35443 -25203
  40. package/dist/market-data-preparation.js.map +118 -78
  41. package/dist/market-data-vendor-backfill.d.ts +8 -5
  42. package/dist/market-data-vendor-backfill.js +19444 -15553
  43. package/dist/market-data-vendor-backfill.js.map +65 -60
  44. package/package.json +1 -5
  45. package/dist/market-data-preparation/policies/capability-policy-v1.json +0 -28
  46. package/dist/market-data-vendor-backfill/fixtures/conformance-v1.json +0 -448
  47. package/dist/market-data-vendor-backfill/policies/capability-policy-v2.json +0 -28
  48. package/dist/market-data-vendor-backfill/policies/capability-policy.json +0 -28
  49. package/dist/market-data-vendor-backfill/policies/resource-policy.json +0 -16
  50. package/dist/market-data-vendor-backfill/schema-manifest.json +0 -31
  51. package/dist/market-data-vendor-backfill/schemas/archive-selection.schema.json +0 -224
  52. package/dist/market-data-vendor-backfill/schemas/promotion-receipt.schema.json +0 -171
  53. package/dist/market-data-vendor-backfill/schemas/request.schema.json +0 -166
  54. package/dist/market-data-vendor-backfill/schemas/required-clock.schema.json +0 -47
  55. package/dist/market-data-vendor-backfill/schemas/result.schema.json +0 -198
@@ -3,7 +3,6 @@ export declare const BACKFILL_REQUEST_SCHEMA_ID: string;
3
3
  export declare const REQUIRED_CLOCK_SCHEMA_ID: string;
4
4
  export declare const ARCHIVE_SELECTION_SCHEMA_ID: string;
5
5
  export declare const PROMOTION_RECEIPT_SCHEMA_ID: string;
6
- export declare const BACKFILL_RESULT_SCHEMA_ID: string;
7
6
  export type FixedUtcTimestamp = string;
8
7
  export type Sha256Hex = string;
9
8
  export type LowercaseUuid = string;
@@ -161,7 +160,7 @@ export type PromotionReceiptWire = {
161
160
  end_at: FixedUtcTimestamp;
162
161
  };
163
162
  depth: number;
164
- construction_mode: "sampled_top_n_snapshot" | "exact_l2_reconstruction";
163
+ construction_mode: "sampled_top_n_snapshot" | "exact_l2_reconstruction" | "policy_neutral_top_n_state_change_tape/v1";
165
164
  canonical_schema: {
166
165
  schema_id: string;
167
166
  schema_sha256: Sha256Hex;
@@ -183,56 +182,32 @@ export type PromotionReceiptWire = {
183
182
  };
184
183
  export declare const FINAL_BACKFILL_STATUSES: readonly ["request_invalid", "archive_preflight_failed", "already_covered", "promoted", "capability_unsupported", "credentials_missing", "vendor_fetch_failed", "archive_ingest_failed", "promotion_verification_failed"];
185
184
  export type FinalBackfillStatus = (typeof FINAL_BACKFILL_STATUSES)[number];
186
- export type BackfillJobResultWire = {
187
- schema_id: typeof BACKFILL_RESULT_SCHEMA_ID;
188
- result_sha256: Sha256Hex;
189
- job_id: LowercaseUuid;
190
- request_file_sha256: Sha256Hex | null;
191
- executable_sha256: Sha256Hex;
192
- schema_manifest_sha256: Sha256Hex;
193
- cex_package: {
194
- name: "@usherlabs/cex-broker";
195
- version: string;
196
- package_sha256: Sha256Hex;
197
- };
198
- capability_policy: {
199
- policy_id: string;
200
- policy_sha256: Sha256Hex;
201
- };
202
- resource_policy: {
203
- policy_id: string;
204
- policy_sha256: Sha256Hex;
205
- };
206
- build: {
207
- fiet_tee_commit: string;
208
- created_at: FixedUtcTimestamp;
209
- };
210
- started_at: FixedUtcTimestamp;
211
- completed_at: FixedUtcTimestamp;
212
- outcome: {
213
- status: FinalBackfillStatus;
214
- reason_code: string;
215
- reason_subcode: string | null;
216
- request_id: LowercaseUuid | null;
217
- idempotency_key: Sha256Hex | null;
218
- target: {
219
- environment: string;
220
- cluster: string;
221
- } | null;
222
- selection: ArchiveSelectionWire | null;
223
- receipt: PromotionReceiptWire | null;
224
- diagnostics: Record<string, string | number | boolean>;
225
- };
185
+ export type BackfillOutcomeWire = {
186
+ status: FinalBackfillStatus;
187
+ reason_code: string;
188
+ reason_subcode: string | null;
189
+ request_id: LowercaseUuid | null;
190
+ idempotency_key: Sha256Hex | null;
191
+ target: {
192
+ environment: string;
193
+ cluster: string;
194
+ } | null;
195
+ selection: ArchiveSelectionWire | null;
196
+ receipt: PromotionReceiptWire | null;
197
+ diagnostics: Record<string, string | number | boolean>;
226
198
  };
227
199
  type Codec<T> = {
228
200
  decode(value: unknown): T;
229
201
  is(value: unknown): value is T;
230
202
  };
203
+ export declare class BackfillRequestValidationError extends Error {
204
+ readonly reasonSubcode: string;
205
+ constructor(reasonSubcode: string, message: string);
206
+ }
231
207
  export declare const requiredClockCodec: Codec<RequiredClockWire>;
232
208
  export declare const archiveSelectionCodec: Codec<ArchiveSelectionWire>;
233
209
  export declare function promotionIdentitySha256(receipt: Omit<PromotionReceiptWire, "receipt_id" | "promotion_identity_sha256"> & Partial<Pick<PromotionReceiptWire, "receipt_id" | "promotion_identity_sha256">>): string;
234
210
  export declare const promotionReceiptCodec: Codec<PromotionReceiptWire>;
235
- export declare const backfillResultCodec: Codec<BackfillJobResultWire>;
236
211
  export declare const backfillRequestCodec: {
237
212
  decode(value: unknown): {
238
213
  wire: BackfillRequestWire;
@@ -241,9 +216,7 @@ export declare const backfillRequestCodec: {
241
216
  };
242
217
  export declare function finalizeRequiredClock(clock: Omit<RequiredClockWire, "clock_sha256">): RequiredClockWire;
243
218
  export declare function finalizeArchiveSelection(selection: Omit<ArchiveSelectionWire, "selection_sha256">): ArchiveSelectionWire;
244
- export declare function finalizeBackfillResult(result: Omit<BackfillJobResultWire, "result_sha256"> & Partial<Pick<BackfillJobResultWire, "result_sha256">>): BackfillJobResultWire;
245
219
  export declare const BACKFILL_REQUEST_SCHEMA_VERSION: "market-data-vendor-backfill-request/v1";
246
- export declare const BACKFILL_RESULT_SCHEMA_VERSION: "market-data-vendor-backfill-result/v1";
247
220
  export declare const BACKFILL_PROMOTION_SCHEMA_VERSION: "market-data-vendor-backfill-promotion-receipt/v1";
248
221
  export declare const EXTERNAL_BACKFILL_SOURCE: "external_backfill";
249
222
  export declare const HISTORICAL_VENDOR_SOURCE_MODE: "vendor_historical_backfill_v1";
@@ -297,7 +270,8 @@ export declare const backfillRequestSchema: z.ZodObject<{
297
270
  }, z.core.$strict>;
298
271
  }, z.core.$strict>;
299
272
  type ProvisionalBackfillDomainRequest = z.infer<typeof backfillRequestSchema>;
300
- export type MarketDataVendorBackfillRequest = ProvisionalBackfillDomainRequest & {
273
+ export type MarketDataVendorBackfillRequest = Omit<ProvisionalBackfillDomainRequest, "constructionMode"> & {
274
+ constructionMode: ProvisionalBackfillDomainRequest["constructionMode"] | "policy_neutral_top_n_state_change_tape/v1";
301
275
  attemptId?: string;
302
276
  target?: {
303
277
  environment: string;
@@ -368,7 +342,7 @@ export type PromotionReceipt = {
368
342
  startTimeMs: number;
369
343
  endTimeMs: number;
370
344
  depth: number;
371
- constructionMode: "sampled_top_n_snapshot" | "exact_l2_reconstruction";
345
+ constructionMode: "sampled_top_n_snapshot" | "exact_l2_reconstruction" | "policy_neutral_top_n_state_change_tape/v1";
372
346
  canonicalSchemaVersion: string;
373
347
  checksumAlgorithm: "sha256-canonical-json-v1";
374
348
  vendorSemanticDigest: string;
@@ -381,13 +355,4 @@ export type PromotionReceipt = {
381
355
  verificationTimeMs: number;
382
356
  };
383
357
  export declare const promotionReceiptSchema: z.ZodType<PromotionReceipt>;
384
- export type BackfillResult = {
385
- schemaVersion: typeof BACKFILL_RESULT_SCHEMA_VERSION;
386
- requestId: string;
387
- idempotencyKey?: string;
388
- status: BackfillStatus;
389
- reasonCode: string;
390
- receipt?: PromotionReceipt;
391
- diagnostics?: Record<string, string | number | boolean>;
392
- };
393
358
  export {};
@@ -3,6 +3,7 @@ export type ProviderDataset<Row = unknown> = {
3
3
  objects: ProviderObjectEvidence[];
4
4
  vendorSemanticDigest: string;
5
5
  rows: Row[];
6
+ reconstructedBooks?: unknown[];
6
7
  };
7
8
  export type NormalizedBackfill = {
8
9
  captureBundleId: string;
@@ -1,7 +1,14 @@
1
- import { type MarketDataVendorBackfillRequest, type ProviderCapability } from "./contracts";
1
+ import type { ReconstructionObservationSink } from "../market-data-source-forensics";
2
+ import { type MarketDataVendorBackfillRequest, type ProviderCapability, type ProviderObjectEvidence } from "./contracts";
2
3
  import type { NormalizedBackfill, ProviderDataset } from "./core";
3
4
  export declare const CRYPTOHFTDATA_ADAPTER_VERSION: "cryptohftdata-orderbook/v2";
4
5
  export declare const CRYPTOHFTDATA_API_URL: "https://api.cryptohftdata.com";
6
+ export declare const DIAGNOSTIC_LAG_THRESHOLDS_MS: readonly [1000, 2000, 5000, 10000, 30000, 60000];
7
+ export declare const SOURCE_TAPE_MAX_STATES_PER_YIELD: 4;
8
+ export declare const SOURCE_TAPE_MAX_BATCH_BYTES: 5242880;
9
+ export declare const SOURCE_TAPE_MAX_IN_FLIGHT: 1;
10
+ export declare const BACKFILL_CLOCK_DIAGNOSTIC_KEYS: readonly ["target_time_ms", "source_time_ms", "asof_lag_ms", "max_prior_asof_lag_ms", "missing_target_count", "covered_target_count", "first_missing_target_time_ms", "last_missing_target_time_ms", "max_observed_asof_lag_ms", "missing_target_dates_utc", "total_target_count", "unanchored_target_count", "future_state_target_count", ...("covered_target_count_lag_1000_ms" | "covered_target_count_lag_60000_ms" | "covered_target_count_lag_5000_ms" | "covered_target_count_lag_2000_ms" | "covered_target_count_lag_10000_ms" | "covered_target_count_lag_30000_ms")[]];
11
+ export declare const BACKFILL_SEQUENCE_DIAGNOSTIC_KEYS: readonly ["event_time_ms", "expected_previous_sequence", "observed_previous_sequence", "observed_final_sequence", "sequence_gap_count", "first_sequence_gap_event_time_ms", "last_sequence_gap_event_time_ms"];
5
12
  export type CryptoHftDataCapabilityProfile = Readonly<{
6
13
  profileId: string;
7
14
  exchange: string;
@@ -20,9 +27,11 @@ export type CryptoHftDataCapabilityProfile = Readonly<{
20
27
  }>;
21
28
  export declare const CRYPTOHFTDATA_BINANCE_SPOT_BTCUSDT_PROFILE: CryptoHftDataCapabilityProfile;
22
29
  export declare const CRYPTOHFTDATA_OKX_SPOT_ARBUSDT_PROFILE: CryptoHftDataCapabilityProfile;
30
+ export declare const CRYPTOHFTDATA_OKX_SPOT_ARBUSDC_PROFILE: CryptoHftDataCapabilityProfile;
23
31
  export declare class CryptoHftDataError extends Error {
24
32
  readonly reason: string;
25
- constructor(reason: string);
33
+ readonly diagnostics: Readonly<Record<string, string | number | boolean>>;
34
+ constructor(reason: string, diagnostics?: Readonly<Record<string, string | number | boolean>>);
26
35
  }
27
36
  export type CryptoHftDataOrderBookRow = {
28
37
  received_time: string | number | bigint;
@@ -51,17 +60,42 @@ export type ReconstructedCryptoHftBook = {
51
60
  datasetObjectIdentity: string;
52
61
  datasetObjectChecksum: string;
53
62
  };
63
+ export type PolicyNeutralCryptoHftBookState = ReconstructedCryptoHftBook & {
64
+ tapeState: "initialization" | "change";
65
+ };
66
+ export type PolicyNeutralTapeSink = {
67
+ writeBatch(states: readonly PolicyNeutralCryptoHftBookState[]): Promise<void>;
68
+ complete(input: {
69
+ expectedObjectIdentities: readonly string[];
70
+ observedObjects: readonly ProviderObjectEvidence[];
71
+ stateCount: number;
72
+ }): Promise<void>;
73
+ abort(input: {
74
+ reason: string;
75
+ retainedStateCount: number;
76
+ }): Promise<void>;
77
+ };
54
78
  export declare function cryptoHftDataCapabilityFor(request: MarketDataVendorBackfillRequest, profiles?: readonly CryptoHftDataCapabilityProfile[]): ProviderCapability | undefined;
55
79
  export declare function enumerateCryptoHftDataObjects(request: MarketDataVendorBackfillRequest, providerExchangeId: string, resolvedSymbol: string): string[];
80
+ export declare function enumerateCryptoHftDataWindowObjects(request: MarketDataVendorBackfillRequest, providerExchangeId: string, resolvedSymbol: string): string[];
56
81
  export declare function providerAcquisitionRequest(request: MarketDataVendorBackfillRequest): MarketDataVendorBackfillRequest;
57
- export declare function reconstructCryptoHftDataOrderBooks(request: MarketDataVendorBackfillRequest, inputRows: readonly CryptoHftDataOrderBookRow[], profile?: CryptoHftDataCapabilityProfile): ReconstructedCryptoHftBook[];
82
+ export declare function reconstructCryptoHftDataOrderBooks(request: MarketDataVendorBackfillRequest, inputRows: readonly CryptoHftDataOrderBookRow[], profile?: CryptoHftDataCapabilityProfile, observer?: ReconstructionObservationSink): ReconstructedCryptoHftBook[];
83
+ /**
84
+ * Qualification-only full-window policy-neutral source projection.
85
+ * It uses the production OKX grouping, validation, sequence and mutation path,
86
+ * but continues after the submitted clock is exhausted and emits no Maker
87
+ * policy decisions.
88
+ */
89
+ export declare function reconstructCryptoHftDataPolicyNeutralTape(request: MarketDataVendorBackfillRequest, inputRows: readonly CryptoHftDataOrderBookRow[], profile: CryptoHftDataCapabilityProfile, observer?: ReconstructionObservationSink): PolicyNeutralCryptoHftBookState[];
58
90
  export declare function decodeCryptoHftParquetZstd(bytes: Uint8Array): Promise<Record<string, unknown>[]>;
59
- type CryptoHftDataAdapterOptions = {
91
+ export type CryptoHftDataAdapterOptions = {
60
92
  baseUrl?: string;
61
93
  fetch?: typeof fetch;
62
94
  nowMs?: () => number;
63
95
  decode?: (bytes: Uint8Array) => Promise<Record<string, unknown>[]>;
64
96
  profiles?: readonly CryptoHftDataCapabilityProfile[];
97
+ observer?: ReconstructionObservationSink;
98
+ policyNeutralTapeSink?: PolicyNeutralTapeSink;
65
99
  };
66
100
  export declare class CryptoHftDataAdapter {
67
101
  private readonly baseUrl;
@@ -69,10 +103,16 @@ export declare class CryptoHftDataAdapter {
69
103
  private readonly nowMs;
70
104
  private readonly decode;
71
105
  private readonly profiles;
106
+ private readonly observer?;
107
+ private readonly collectPolicyNeutralTape;
108
+ private readonly policyNeutralTapeSink?;
72
109
  constructor(options?: CryptoHftDataAdapterOptions);
110
+ private observe;
73
111
  capabilityFor(request: MarketDataVendorBackfillRequest): ProviderCapability | undefined;
112
+ private findProfile;
113
+ private profileFor;
74
114
  discoverSymbols(providerExchangeId: string): Promise<string[]>;
75
115
  acquire(request: MarketDataVendorBackfillRequest, capability: ProviderCapability, credential: unknown): Promise<ProviderDataset<CryptoHftDataOrderBookRow>>;
116
+ private acquireInternal;
76
117
  normalize(request: MarketDataVendorBackfillRequest, capability: ProviderCapability, dataset: ProviderDataset, captureBundleId: string): Promise<NormalizedBackfill>;
77
118
  }
78
- export {};