@usherlabs/cex-broker 0.2.17 → 0.2.19
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.
- package/README.md +22 -1
- package/dist/commands/cli.js +2719 -1279
- package/dist/handlers/execute-action/context.d.ts +2 -0
- package/dist/handlers/execute-action/handler.d.ts +2 -0
- package/dist/handlers/subscribe/handler.d.ts +2 -0
- package/dist/helpers/broker-execution-archive/capture.d.ts +27 -0
- package/dist/helpers/broker-execution-archive/index.d.ts +5 -0
- package/dist/helpers/broker-execution-archive/redact.d.ts +7 -0
- package/dist/helpers/broker-execution-archive/rows.d.ts +31 -0
- package/dist/helpers/broker-execution-archive/types.d.ts +16 -0
- package/dist/helpers/broker-execution-archive/writer.d.ts +57 -0
- package/dist/helpers/market-data-archive/capture.d.ts +20 -0
- package/dist/helpers/market-data-archive/index.d.ts +9 -0
- package/dist/helpers/market-data-archive/ohlcv-bar-tracker.d.ts +11 -0
- package/dist/helpers/market-data-archive/ohlcv-bootstrap.d.ts +1 -0
- package/dist/helpers/market-data-archive/ohlcv-history.d.ts +8 -0
- package/dist/helpers/market-data-archive/orderbook-depth.d.ts +5 -0
- package/dist/helpers/market-data-archive/orderbook-sampler.d.ts +12 -0
- package/dist/helpers/market-data-archive/parse-stream.d.ts +26 -0
- package/dist/helpers/market-data-archive/rows.d.ts +18 -0
- package/dist/helpers/market-data-archive/types.d.ts +55 -0
- package/dist/helpers/order-telemetry.d.ts +1 -1
- package/dist/helpers/travel-rule-deposit-reconciler.d.ts +7 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5689 -4252
- package/dist/index.js.map +27 -13
- package/dist/server.d.ts +2 -1
- package/package.json +9 -1
|
@@ -3,6 +3,7 @@ import type { Metadata } from "@grpc/grpc-js";
|
|
|
3
3
|
import type { Exchange } from "@usherlabs/ccxt";
|
|
4
4
|
import type { z } from "zod";
|
|
5
5
|
import type { BrokerAccount, BrokerPoolEntry } from "../../helpers";
|
|
6
|
+
import type { BrokerExecutionArchiver } from "../../helpers/broker-execution-archive";
|
|
6
7
|
import type { Action as ActionType } from "../../helpers/constants";
|
|
7
8
|
import type { OtelMetrics } from "../../helpers/otel";
|
|
8
9
|
import type { PolicyConfig } from "../../types";
|
|
@@ -27,6 +28,7 @@ export type ExecuteActionContext = {
|
|
|
27
28
|
useVerity: boolean;
|
|
28
29
|
verityProverUrl: string;
|
|
29
30
|
otelMetrics?: OtelMetrics;
|
|
31
|
+
brokerArchiver?: BrokerExecutionArchiver;
|
|
30
32
|
};
|
|
31
33
|
export declare function requireSymbol(ctx: ExecuteActionContext, message?: string): ctx is ExecuteActionContext & {
|
|
32
34
|
symbol: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as grpc from "@grpc/grpc-js";
|
|
2
2
|
import { type BrokerPoolEntry } from "../../helpers/broker";
|
|
3
|
+
import type { BrokerExecutionArchiver } from "../../helpers/broker-execution-archive";
|
|
3
4
|
import type { OtelMetrics } from "../../helpers/otel";
|
|
4
5
|
import type { PolicyConfig } from "../../types";
|
|
5
6
|
import type { ActionRequest, ActionResponse } from "../types";
|
|
@@ -10,5 +11,6 @@ export type ExecuteActionDeps = {
|
|
|
10
11
|
useVerity: boolean;
|
|
11
12
|
verityProverUrl: string;
|
|
12
13
|
otelMetrics?: OtelMetrics;
|
|
14
|
+
brokerArchiver?: BrokerExecutionArchiver;
|
|
13
15
|
};
|
|
14
16
|
export declare function createExecuteActionHandler(deps: ExecuteActionDeps): (call: grpc.ServerUnaryCall<ActionRequest, ActionResponse>, callback: grpc.sendUnaryData<ActionResponse>) => Promise<void>;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import * as grpc from "@grpc/grpc-js";
|
|
2
2
|
import { type BrokerPoolEntry } from "../../helpers/broker";
|
|
3
|
+
import type { BrokerExecutionArchiver } from "../../helpers/broker-execution-archive";
|
|
3
4
|
import type { OtelMetrics } from "../../helpers/otel";
|
|
4
5
|
import type { SubscribeRequest, SubscribeResponse } from "../types";
|
|
5
6
|
export type SubscribeDeps = {
|
|
6
7
|
brokers: Record<string, BrokerPoolEntry>;
|
|
7
8
|
whitelistIps: string[];
|
|
8
9
|
otelMetrics?: OtelMetrics;
|
|
10
|
+
brokerArchiver?: BrokerExecutionArchiver;
|
|
9
11
|
};
|
|
10
12
|
type SubscribeCall = grpc.ServerWritableStream<SubscribeRequest, SubscribeResponse>;
|
|
11
13
|
export declare function createSubscribeHandler(deps: SubscribeDeps): (call: SubscribeCall) => Promise<void>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Exchange } from "@usherlabs/ccxt";
|
|
2
|
+
import { type OrderTelemetryAction, type OrderTelemetryContext } from "../order-telemetry";
|
|
3
|
+
import type { SubscribeArchiveType } from "./types";
|
|
4
|
+
import type { BrokerExecutionArchiver } from "./writer";
|
|
5
|
+
export declare function archiveOrderExecutionInBackground(archiver: BrokerExecutionArchiver | undefined, context: OrderTelemetryContext, order: unknown, error?: unknown, options?: {
|
|
6
|
+
marketMetadataHash?: string;
|
|
7
|
+
}): void;
|
|
8
|
+
export declare function archiveSubscribeStreamInBackground(archiver: BrokerExecutionArchiver | undefined, input: {
|
|
9
|
+
exchange: string;
|
|
10
|
+
accountSelector?: string;
|
|
11
|
+
symbol: string;
|
|
12
|
+
subscriptionType: SubscribeArchiveType;
|
|
13
|
+
streamPayload: unknown;
|
|
14
|
+
secretLiterals?: readonly string[];
|
|
15
|
+
}): void;
|
|
16
|
+
export declare function captureMarketMetadataSnapshot(archiver: BrokerExecutionArchiver | undefined, broker: Exchange, input: {
|
|
17
|
+
exchange: string;
|
|
18
|
+
accountSelector?: string;
|
|
19
|
+
symbol: string;
|
|
20
|
+
action: OrderTelemetryAction;
|
|
21
|
+
clientOrderId?: string;
|
|
22
|
+
orderId?: string;
|
|
23
|
+
makerActionId?: string;
|
|
24
|
+
idempotencyId?: string;
|
|
25
|
+
brokerObservedTimestamp?: string;
|
|
26
|
+
}): Promise<string | undefined>;
|
|
27
|
+
export declare function captureMarketMetadataSnapshotInBackground(archiver: BrokerExecutionArchiver | undefined, broker: Exchange, input: Parameters<typeof captureMarketMetadataSnapshot>[2]): void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { archiveOrderExecutionInBackground, archiveSubscribeStreamInBackground, captureMarketMetadataSnapshot, captureMarketMetadataSnapshotInBackground, } from "./capture";
|
|
2
|
+
export { hashMarketMetadata, redactErrorForArchive, redactSecretLiterals, redactStreamPayload, } from "./redact";
|
|
3
|
+
export { buildCommonArchiveTags, buildMarketMetadataSnapshotRow, buildOrderEventArchiveRow, buildSubscribeStreamArchiveRow, } from "./rows";
|
|
4
|
+
export { BROKER_WRITE_SOURCE, type BrokerArchiveCommonTags, type BrokerArchiveRow, type BrokerArchiveTable, type OrderArchiveAction, type SubscribeArchiveType, } from "./types";
|
|
5
|
+
export { BrokerExecutionArchiver, type BrokerExecutionArchiverOptions, createBrokerExecutionArchiverFromEnv, isArchiveOtelLogsEnabled, resolveArchiveForwarderUrlFromEnv, } from "./writer";
|
|
@@ -0,0 +1,7 @@
|
|
|
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;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { OrderExecutionTelemetry } from "../order-telemetry";
|
|
2
|
+
import { type BrokerArchiveCommonTags, type BrokerArchiveRow, type OrderArchiveAction, type SubscribeArchiveType } from "./types";
|
|
3
|
+
export declare function buildCommonArchiveTags(input: {
|
|
4
|
+
deploymentId: string;
|
|
5
|
+
accountSelector?: string;
|
|
6
|
+
exchange: string;
|
|
7
|
+
symbol?: string;
|
|
8
|
+
brokerObservedTimestamp?: string;
|
|
9
|
+
}): BrokerArchiveCommonTags;
|
|
10
|
+
export declare function buildOrderEventArchiveRow(input: {
|
|
11
|
+
tags: BrokerArchiveCommonTags;
|
|
12
|
+
action: OrderArchiveAction;
|
|
13
|
+
telemetry: OrderExecutionTelemetry;
|
|
14
|
+
eventKind?: "execute_action" | "subscribe_stream";
|
|
15
|
+
subscriptionType?: SubscribeArchiveType;
|
|
16
|
+
marketMetadataHash?: string;
|
|
17
|
+
}): BrokerArchiveRow;
|
|
18
|
+
export declare function buildSubscribeStreamArchiveRow(input: {
|
|
19
|
+
tags: BrokerArchiveCommonTags;
|
|
20
|
+
subscriptionType: SubscribeArchiveType;
|
|
21
|
+
streamPayload: unknown;
|
|
22
|
+
secretLiterals?: readonly string[];
|
|
23
|
+
}): BrokerArchiveRow;
|
|
24
|
+
export declare function buildMarketMetadataSnapshotRow(input: {
|
|
25
|
+
tags: BrokerArchiveCommonTags;
|
|
26
|
+
clientOrderId?: string;
|
|
27
|
+
orderId?: string;
|
|
28
|
+
makerActionId?: string;
|
|
29
|
+
idempotencyId?: string;
|
|
30
|
+
marketSnapshot: unknown;
|
|
31
|
+
}): BrokerArchiveRow;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const BROKER_WRITE_SOURCE: "broker_write";
|
|
2
|
+
export type BrokerArchiveTable = "broker_execution.order_events" | "broker_execution.market_metadata_snapshots" | "market_data.orderbook_snapshots" | "market_data.candles" | "market_data.cex_stream_events" | "market_data.cex_ticker_events" | "market_data.cex_trades";
|
|
3
|
+
export type BrokerArchiveRow = {
|
|
4
|
+
table: BrokerArchiveTable;
|
|
5
|
+
row: Record<string, unknown>;
|
|
6
|
+
};
|
|
7
|
+
export type BrokerArchiveCommonTags = {
|
|
8
|
+
source: typeof BROKER_WRITE_SOURCE;
|
|
9
|
+
deployment_id: string;
|
|
10
|
+
account_selector: string;
|
|
11
|
+
exchange: string;
|
|
12
|
+
symbol: string;
|
|
13
|
+
broker_observed_timestamp: string;
|
|
14
|
+
};
|
|
15
|
+
export type OrderArchiveAction = "CreateOrder" | "CancelOrder" | "GetOrderDetails";
|
|
16
|
+
export type SubscribeArchiveType = "ORDERS" | "BALANCE";
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { OtelLogs, OtelMetrics } from "../otel";
|
|
2
|
+
import type { BrokerArchiveRow } from "./types";
|
|
3
|
+
export type BrokerExecutionArchiverOptions = {
|
|
4
|
+
deploymentId?: string;
|
|
5
|
+
otelLogs?: OtelLogs;
|
|
6
|
+
otelMetrics?: OtelMetrics;
|
|
7
|
+
forwarderUrl?: string;
|
|
8
|
+
maxQueueSize?: number;
|
|
9
|
+
batchSize?: number;
|
|
10
|
+
flushIntervalMs?: number;
|
|
11
|
+
forwarderTimeoutMs?: number;
|
|
12
|
+
};
|
|
13
|
+
type ArchiverStats = {
|
|
14
|
+
enqueued: number;
|
|
15
|
+
shed: number;
|
|
16
|
+
flushed: number;
|
|
17
|
+
forwarderFailures: number;
|
|
18
|
+
};
|
|
19
|
+
export declare function isArchiveOtelLogsEnabled(): boolean;
|
|
20
|
+
export declare function resolveArchiveForwarderUrlFromEnv(): string | undefined;
|
|
21
|
+
export declare class BrokerExecutionArchiver {
|
|
22
|
+
private readonly deploymentId;
|
|
23
|
+
private readonly otelLogs?;
|
|
24
|
+
private readonly otelMetrics?;
|
|
25
|
+
private readonly forwarderUrl?;
|
|
26
|
+
private readonly maxQueueSize;
|
|
27
|
+
private readonly batchSize;
|
|
28
|
+
private readonly flushIntervalMs;
|
|
29
|
+
private readonly forwarderTimeoutMs;
|
|
30
|
+
private readonly queue;
|
|
31
|
+
private readonly stats;
|
|
32
|
+
private flushTimer;
|
|
33
|
+
private flushInFlight;
|
|
34
|
+
private closed;
|
|
35
|
+
private loggedMissingMarketForwarder;
|
|
36
|
+
private readonly enabled;
|
|
37
|
+
private readonly forwarderAuthToken?;
|
|
38
|
+
private constructor();
|
|
39
|
+
static disabled(): BrokerExecutionArchiver;
|
|
40
|
+
static create(options: BrokerExecutionArchiverOptions): BrokerExecutionArchiver;
|
|
41
|
+
getDeploymentId(): string;
|
|
42
|
+
isEnabled(): boolean;
|
|
43
|
+
canPersistMarketMetadataSnapshot(): boolean;
|
|
44
|
+
enqueue(row: BrokerArchiveRow): void;
|
|
45
|
+
enqueueInBackground(row: BrokerArchiveRow): void;
|
|
46
|
+
flush(): Promise<void>;
|
|
47
|
+
close(): Promise<void>;
|
|
48
|
+
getStats(): Readonly<ArchiverStats>;
|
|
49
|
+
getQueueDepth(): number;
|
|
50
|
+
private enforceQueueBound;
|
|
51
|
+
private flushBatch;
|
|
52
|
+
private recordArchiveMetric;
|
|
53
|
+
private emitOtelLog;
|
|
54
|
+
private postToForwarder;
|
|
55
|
+
}
|
|
56
|
+
export declare function createBrokerExecutionArchiverFromEnv(otelLogs?: OtelLogs, otelMetrics?: OtelMetrics): BrokerExecutionArchiver;
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { OtelMetrics } from "../otel";
|
|
2
|
+
import type { BrokerExecutionArchiver } from "../broker-execution-archive/writer";
|
|
3
|
+
import { OhlcvBarTracker } from "./ohlcv-bar-tracker";
|
|
4
|
+
import { OrderbookSampler } from "./orderbook-sampler";
|
|
5
|
+
import type { CexStreamArchiveInput, OhlcvArchiveInput, OrderbookArchiveInput, TickerArchiveInput, TradesArchiveInput } from "./types";
|
|
6
|
+
export declare function archiveOrderbookInBackground(archiver: BrokerExecutionArchiver | undefined, otelMetrics: OtelMetrics | undefined, input: OrderbookArchiveInput, options?: {
|
|
7
|
+
sampledOut?: boolean;
|
|
8
|
+
}): void;
|
|
9
|
+
/** @deprecated Use archiveOrderbookInBackground */
|
|
10
|
+
export declare const archiveOrderbookSnapshotInBackground: typeof archiveOrderbookInBackground;
|
|
11
|
+
/** @deprecated Use archiveOrderbookInBackground */
|
|
12
|
+
export declare const archiveOrderbookTobInBackground: typeof archiveOrderbookInBackground;
|
|
13
|
+
export declare function archiveOhlcvInBackground(archiver: BrokerExecutionArchiver | undefined, otelMetrics: OtelMetrics | undefined, tracker: OhlcvBarTracker, input: OhlcvArchiveInput): void;
|
|
14
|
+
export declare function createOrderbookSampler(): OrderbookSampler;
|
|
15
|
+
/** @deprecated Use createOrderbookSampler */
|
|
16
|
+
export declare const createOrderbookTobSampler: typeof createOrderbookSampler;
|
|
17
|
+
export declare function createOhlcvBarTracker(): OhlcvBarTracker;
|
|
18
|
+
export declare function archiveTradesInBackground(archiver: BrokerExecutionArchiver | undefined, otelMetrics: OtelMetrics | undefined, input: TradesArchiveInput): void;
|
|
19
|
+
export declare function archiveTickerInBackground(archiver: BrokerExecutionArchiver | undefined, otelMetrics: OtelMetrics | undefined, input: TickerArchiveInput): void;
|
|
20
|
+
export declare function archiveCexStreamEventInBackground(archiver: BrokerExecutionArchiver | undefined, otelMetrics: OtelMetrics | undefined, input: CexStreamArchiveInput): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { archiveCexStreamEventInBackground, archiveOhlcvInBackground, archiveOrderbookInBackground, archiveOrderbookSnapshotInBackground, archiveOrderbookTobInBackground, archiveTickerInBackground, archiveTradesInBackground, createOhlcvBarTracker, createOrderbookSampler, createOrderbookTobSampler, } from "./capture";
|
|
2
|
+
export { extractLatestOhlcvBar, extractOhlcvBars, OhlcvBarTracker, parseOhlcvBar, } from "./ohlcv-bar-tracker";
|
|
3
|
+
export { bootstrapOhlcvHistory } from "./ohlcv-history";
|
|
4
|
+
export { resolveOhlcvBootstrapLimit } from "./ohlcv-bootstrap";
|
|
5
|
+
export { extractTrades, parseTicker, parseTrade } from "./parse-stream";
|
|
6
|
+
export { getOrderbookIntervalMs, getOrderbookTobIntervalMs, isMarketArchiveEnabled, OrderbookSampler, OrderbookTobSampler, } from "./orderbook-sampler";
|
|
7
|
+
export { buildCandleRow, buildCexStreamEventRow, buildCexTickerEventRow, buildCexTradeRow, buildOrderbookDepthRow, buildOrderbookSnapshotRow, buildOrderbookTobRow, } from "./rows";
|
|
8
|
+
export { getOrderbookArchiveDepthLimit, splitOrderBookSide, } from "./orderbook-depth";
|
|
9
|
+
export type { CexStreamArchiveInput, CexStreamType, MarketArchiveContext, OhlcvArchiveCandidate, OhlcvArchiveInput, OrderbookArchiveInput, OrderbookSnapshotArchiveInput, OrderbookTobArchiveInput, ParsedOhlcvBar, TickerArchiveInput, TradesArchiveInput, } from "./types";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { OhlcvArchiveCandidate, ParsedOhlcvBar } from "./types";
|
|
2
|
+
export declare function parseOhlcvBar(value: unknown): ParsedOhlcvBar | null;
|
|
3
|
+
export declare function extractOhlcvBars(payload: unknown): ParsedOhlcvBar[];
|
|
4
|
+
export declare function extractLatestOhlcvBar(payload: unknown): ParsedOhlcvBar | null;
|
|
5
|
+
export declare class OhlcvBarTracker {
|
|
6
|
+
private lastOpenTimeMs;
|
|
7
|
+
private lastBar;
|
|
8
|
+
process(payload: unknown, brokerVersion: number): OhlcvArchiveCandidate[];
|
|
9
|
+
private processSingleBar;
|
|
10
|
+
private processBatch;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function resolveOhlcvBootstrapLimit(optionValue: string | undefined): number;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Exchange } from "@usherlabs/ccxt";
|
|
2
|
+
import type { OtelMetrics } from "../otel";
|
|
3
|
+
import type { BrokerExecutionArchiver } from "../broker-execution-archive/writer";
|
|
4
|
+
import type { OhlcvBarTracker } from "./ohlcv-bar-tracker";
|
|
5
|
+
import type { OhlcvArchiveInput } from "./types";
|
|
6
|
+
export declare function bootstrapOhlcvHistory(broker: Exchange, archiver: BrokerExecutionArchiver | undefined, otelMetrics: OtelMetrics | undefined, tracker: OhlcvBarTracker, input: OhlcvArchiveInput, options?: {
|
|
7
|
+
bootstrapLimit?: string;
|
|
8
|
+
}): Promise<unknown | null>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function getOrderbookIntervalMs(): number;
|
|
2
|
+
export declare function isMarketArchiveEnabled(): boolean;
|
|
3
|
+
export declare class OrderbookSampler {
|
|
4
|
+
private readonly intervalMs;
|
|
5
|
+
private lastEmitMs;
|
|
6
|
+
constructor(intervalMs?: number);
|
|
7
|
+
shouldEmit(nowMs?: number): boolean;
|
|
8
|
+
}
|
|
9
|
+
/** @deprecated Use getOrderbookIntervalMs */
|
|
10
|
+
export declare const getOrderbookTobIntervalMs: typeof getOrderbookIntervalMs;
|
|
11
|
+
/** @deprecated Use OrderbookSampler */
|
|
12
|
+
export declare const OrderbookTobSampler: typeof OrderbookSampler;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type ParsedTrade = {
|
|
2
|
+
tradeId: string;
|
|
3
|
+
eventTimeMs: number;
|
|
4
|
+
side: string;
|
|
5
|
+
price: number;
|
|
6
|
+
amount: number;
|
|
7
|
+
cost?: number;
|
|
8
|
+
takerOrMaker?: string;
|
|
9
|
+
};
|
|
10
|
+
export type ParsedTicker = {
|
|
11
|
+
eventTimeMs: number;
|
|
12
|
+
last?: number;
|
|
13
|
+
bid?: number;
|
|
14
|
+
ask?: number;
|
|
15
|
+
high?: number;
|
|
16
|
+
low?: number;
|
|
17
|
+
open?: number;
|
|
18
|
+
close?: number;
|
|
19
|
+
baseVolume?: number;
|
|
20
|
+
quoteVolume?: number;
|
|
21
|
+
change?: number;
|
|
22
|
+
percentage?: number;
|
|
23
|
+
};
|
|
24
|
+
export declare function parseTrade(value: unknown, fallbackMs?: number): ParsedTrade | null;
|
|
25
|
+
export declare function extractTrades(payload: unknown, fallbackMs?: number): ParsedTrade[];
|
|
26
|
+
export declare function parseTicker(value: unknown, fallbackMs: number): ParsedTicker | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type BrokerArchiveRow } from "../broker-execution-archive/types";
|
|
2
|
+
import type { ParsedTicker, ParsedTrade } from "./parse-stream";
|
|
3
|
+
import type { CexStreamArchiveInput, MarketArchiveContext, OrderbookArchiveInput, ParsedOhlcvBar, TickerArchiveInput, TradesArchiveInput } from "./types";
|
|
4
|
+
export declare function buildOrderbookSnapshotRow(input: OrderbookArchiveInput): BrokerArchiveRow | null;
|
|
5
|
+
/** @deprecated Use buildOrderbookSnapshotRow */
|
|
6
|
+
export declare const buildOrderbookTobRow: typeof buildOrderbookSnapshotRow;
|
|
7
|
+
/** @deprecated Use buildOrderbookSnapshotRow */
|
|
8
|
+
export declare const buildOrderbookDepthRow: typeof buildOrderbookSnapshotRow;
|
|
9
|
+
export declare function buildCandleRow(input: {
|
|
10
|
+
context: MarketArchiveContext;
|
|
11
|
+
bar: ParsedOhlcvBar;
|
|
12
|
+
isClosed: boolean;
|
|
13
|
+
brokerVersion: number;
|
|
14
|
+
receivedTimestamp: number;
|
|
15
|
+
}): BrokerArchiveRow;
|
|
16
|
+
export declare function buildCexStreamEventRow(input: CexStreamArchiveInput): BrokerArchiveRow;
|
|
17
|
+
export declare function buildCexTickerEventRow(input: TickerArchiveInput, ticker: ParsedTicker): BrokerArchiveRow;
|
|
18
|
+
export declare function buildCexTradeRow(input: TradesArchiveInput, trade: ParsedTrade): BrokerArchiveRow;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { BrokerMarketType } from "../market-type";
|
|
2
|
+
import type { NormalizedOrderBookSnapshot } from "../order-book";
|
|
3
|
+
import type { BrokerArchiveRow } from "../broker-execution-archive/types";
|
|
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
|
+
export type CexStreamType = "BALANCE" | "ORDERS" | "ORDERBOOK" | "TRADES" | "TICKER" | "OHLCV";
|
|
6
|
+
export type ParsedOhlcvBar = {
|
|
7
|
+
openTimeMs: number;
|
|
8
|
+
open: number;
|
|
9
|
+
high: number;
|
|
10
|
+
low: number;
|
|
11
|
+
close: number;
|
|
12
|
+
volume: number;
|
|
13
|
+
quoteVolume?: number;
|
|
14
|
+
};
|
|
15
|
+
export type OhlcvArchiveCandidate = {
|
|
16
|
+
bar: ParsedOhlcvBar;
|
|
17
|
+
isClosed: boolean;
|
|
18
|
+
brokerVersion: number;
|
|
19
|
+
};
|
|
20
|
+
export type MarketArchiveContext = {
|
|
21
|
+
exchange: string;
|
|
22
|
+
symbol: string;
|
|
23
|
+
assetType: BrokerMarketType;
|
|
24
|
+
timeframe?: string;
|
|
25
|
+
accountSelector?: string;
|
|
26
|
+
deploymentId: string;
|
|
27
|
+
};
|
|
28
|
+
export type OrderbookArchiveInput = MarketArchiveContext & {
|
|
29
|
+
snapshot: NormalizedOrderBookSnapshot;
|
|
30
|
+
};
|
|
31
|
+
/** @deprecated Use OrderbookArchiveInput */
|
|
32
|
+
export type OrderbookSnapshotArchiveInput = OrderbookArchiveInput;
|
|
33
|
+
/** @deprecated Use OrderbookArchiveInput */
|
|
34
|
+
export type OrderbookTobArchiveInput = OrderbookArchiveInput;
|
|
35
|
+
export type OhlcvArchiveInput = MarketArchiveContext & {
|
|
36
|
+
payload: unknown;
|
|
37
|
+
receivedTimestamp: number;
|
|
38
|
+
timeframe: string;
|
|
39
|
+
};
|
|
40
|
+
export type TradesArchiveInput = MarketArchiveContext & {
|
|
41
|
+
payload: unknown;
|
|
42
|
+
receivedTimestamp: number;
|
|
43
|
+
};
|
|
44
|
+
export type TickerArchiveInput = MarketArchiveContext & {
|
|
45
|
+
payload: unknown;
|
|
46
|
+
receivedTimestamp: number;
|
|
47
|
+
};
|
|
48
|
+
export type CexStreamArchiveInput = MarketArchiveContext & {
|
|
49
|
+
streamType: CexStreamType;
|
|
50
|
+
payload: unknown;
|
|
51
|
+
receivedTimestamp: number;
|
|
52
|
+
eventTimeMs?: number;
|
|
53
|
+
};
|
|
54
|
+
export declare function isMarketArchiveTable(table: string): table is MarketArchiveTable;
|
|
55
|
+
export type { BrokerArchiveRow };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { OtelMetrics } from "./otel";
|
|
2
|
-
export type OrderTelemetryAction = "CreateOrder" | "GetOrderDetails";
|
|
2
|
+
export type OrderTelemetryAction = "CreateOrder" | "CancelOrder" | "GetOrderDetails";
|
|
3
3
|
export type OrderTelemetryContext = {
|
|
4
4
|
action: OrderTelemetryAction;
|
|
5
5
|
cex: string;
|
|
@@ -46,6 +46,12 @@ export declare function parseLocalEntityDeposit(raw: Record<string, unknown>): L
|
|
|
46
46
|
* churn (owner wallet → Binance via a direct ERC20 transfer) that equals the
|
|
47
47
|
* token originator. A transfer routed through a contract could differ; hardening
|
|
48
48
|
* to the ERC20 Transfer event's `from` is possible later if that case arises.
|
|
49
|
+
*
|
|
50
|
+
* Uses `node:https` rather than the global `fetch`: inside the Gramine SGX
|
|
51
|
+
* enclave undici (which backs global fetch) fails to establish outbound
|
|
52
|
+
* connections — the same failure mode as the enclave's dead Binance user-data
|
|
53
|
+
* WebSocket — while the ccxt HTTP path (node http/https) works. Using node's
|
|
54
|
+
* request keeps this on the transport that is proven to work in the enclave.
|
|
49
55
|
*/
|
|
50
56
|
export declare function resolveOnChainSender(rpcUrl: string, txHash: string, timeoutMs?: number): Promise<string | null>;
|
|
51
57
|
/** Binance rate-limit signals (-1003 / HTTP 429 / DDoS guard). */
|
|
@@ -78,6 +84,7 @@ export type ReconcileOutcome = {
|
|
|
78
84
|
} | {
|
|
79
85
|
kind: "unproven-origin";
|
|
80
86
|
deposit: LocalEntityDeposit;
|
|
87
|
+
error?: string;
|
|
81
88
|
} | {
|
|
82
89
|
kind: "entity-drift";
|
|
83
90
|
deposit: LocalEntityDeposit;
|