@usherlabs/cex-broker 0.2.23 → 0.2.25
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/dist/commands/cli.js +484 -8
- package/dist/handlers/execute-action/context.d.ts +2 -1
- package/dist/handlers/execute-action/handler.d.ts +2 -1
- package/dist/helpers/account-balance-archive-poller.d.ts +19 -0
- package/dist/helpers/broker-execution-archive/capture.d.ts +6 -0
- package/dist/helpers/broker-execution-archive/index.d.ts +5 -4
- package/dist/helpers/broker-execution-archive/rows.d.ts +18 -0
- package/dist/helpers/broker-execution-archive/types.d.ts +4 -2
- package/dist/helpers/broker-execution-archive/withdrawal-observation-tracker.d.ts +23 -0
- package/dist/helpers/broker-execution-archive/writer.d.ts +3 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +485 -9
- package/dist/index.js.map +15 -13
- package/dist/server.d.ts +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
}
|
|
@@ -2,6 +2,7 @@ import type { Exchange } from "@usherlabs/ccxt";
|
|
|
2
2
|
import { type OrderTelemetryAction, type OrderTelemetryContext } from "../order-telemetry";
|
|
3
3
|
import { type TransferArchiveFields } from "./rows";
|
|
4
4
|
import type { SubscribeArchiveType } from "./types";
|
|
5
|
+
import type { WithdrawalObservationTracker } from "./withdrawal-observation-tracker";
|
|
5
6
|
import type { BrokerExecutionArchiver } from "./writer";
|
|
6
7
|
export declare function archiveOrderExecutionInBackground(archiver: BrokerExecutionArchiver | undefined, context: OrderTelemetryContext, order: unknown, error?: unknown, options?: {
|
|
7
8
|
marketMetadataHash?: string;
|
|
@@ -21,6 +22,11 @@ export declare function archiveTransferEventInBackground(archiver: BrokerExecuti
|
|
|
21
22
|
brokerObservedTimestamp?: string;
|
|
22
23
|
transfer: TransferArchiveFields;
|
|
23
24
|
}): void;
|
|
25
|
+
export declare function archiveWithdrawalObservationsInBackground(archiver: BrokerExecutionArchiver | undefined, tracker: WithdrawalObservationTracker, input: {
|
|
26
|
+
exchange: string;
|
|
27
|
+
accountSelector?: string;
|
|
28
|
+
transactions: unknown;
|
|
29
|
+
}): void;
|
|
24
30
|
export declare function captureMarketMetadataSnapshot(archiver: BrokerExecutionArchiver | undefined, broker: Exchange, input: {
|
|
25
31
|
exchange: string;
|
|
26
32
|
accountSelector?: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { archiveOrderExecutionInBackground, archiveSubscribeStreamInBackground, archiveTransferEventInBackground, captureMarketMetadataSnapshot, captureMarketMetadataSnapshotInBackground, } from "./capture";
|
|
1
|
+
export { archiveOrderExecutionInBackground, archiveSubscribeStreamInBackground, archiveTransferEventInBackground, archiveWithdrawalObservationsInBackground, captureMarketMetadataSnapshot, captureMarketMetadataSnapshotInBackground, } from "./capture";
|
|
2
2
|
export { hashMarketMetadata, redactErrorForArchive, redactSecretLiterals, redactStreamPayload, } from "./redact";
|
|
3
|
-
export { buildCommonArchiveTags, buildFillEventArchiveRow, buildMarketMetadataSnapshotRow, buildOrderEventArchiveRow, buildSubscribeStreamArchiveRow, buildTransferEventArchiveRow, type FillArchiveFields,
|
|
4
|
-
export { ARCHIVE_SCHEMA_VERSION, BROKER_WRITE_SOURCE, type BrokerArchiveCommonTags, type BrokerArchiveRow, type BrokerArchiveTable, type OrderArchiveAction, type SubscribeArchiveType, type TransferEventKind, type TransferLifecycleAction, } from "./types";
|
|
5
|
-
export {
|
|
3
|
+
export { buildAccountBalanceSnapshotRow, buildCommonArchiveTags, buildFillEventArchiveRow, buildMarketMetadataSnapshotRow, buildOrderEventArchiveRow, buildSubscribeStreamArchiveRow, buildTransferEventArchiveRow, type FillArchiveFields, type NormalizedCcxtBalance, type NormalizedCcxtTransfer, normalizeCcxtBalanceForArchive, normalizeCcxtTradeForArchive, normalizeCcxtTransactionForArchive, type TransferArchiveFields, } from "./rows";
|
|
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
|
+
export { DEFAULT_WITHDRAWAL_OBSERVATION_TRACKER_MAX_ENTRIES, WithdrawalObservationTracker, } from "./withdrawal-observation-tracker";
|
|
6
|
+
export { BrokerExecutionArchiver, type BrokerExecutionArchiverOptions, createBrokerExecutionArchiverFromEnv, isArchiveOtelLogsEnabled, isBrokerExecutionArchiveTable, resolveArchiveForwarderUrlFromEnv, } from "./writer";
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import type { OrderExecutionTelemetry } from "../order-telemetry";
|
|
2
2
|
import { type BrokerArchiveCommonTags, type BrokerArchiveRow, 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 normalizeCcxtBalanceForArchive(balance: unknown): NormalizedCcxtBalance;
|
|
16
|
+
export declare function buildAccountBalanceSnapshotRow(input: {
|
|
17
|
+
tags: BrokerArchiveCommonTags;
|
|
18
|
+
balance: NormalizedCcxtBalance;
|
|
19
|
+
}): BrokerArchiveRow;
|
|
3
20
|
export declare function buildCommonArchiveTags(input: {
|
|
4
21
|
deploymentId: string;
|
|
5
22
|
accountSelector?: string;
|
|
@@ -83,3 +100,4 @@ export declare function buildMarketMetadataSnapshotRow(input: {
|
|
|
83
100
|
idempotencyId?: string;
|
|
84
101
|
marketSnapshot: unknown;
|
|
85
102
|
}): BrokerArchiveRow;
|
|
103
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const BROKER_WRITE_SOURCE: "broker_write";
|
|
2
2
|
export declare const ARCHIVE_SCHEMA_VERSION: "1";
|
|
3
|
-
export type BrokerArchiveTable = "broker_execution.order_events" | "broker_execution.market_metadata_snapshots" | "broker_execution.transfer_events" | "broker_execution.fill_events" | "market_data.orderbook_snapshots" | "market_data.candles" | "market_data.cex_stream_events" | "market_data.cex_ticker_events" | "market_data.cex_trades";
|
|
3
|
+
export type BrokerArchiveTable = "broker_execution.order_events" | "broker_execution.market_metadata_snapshots" | "broker_execution.transfer_events" | "broker_execution.fill_events" | "broker_account.balance_snapshots" | "market_data.orderbook_snapshots" | "market_data.candles" | "market_data.cex_stream_events" | "market_data.cex_ticker_events" | "market_data.cex_trades";
|
|
4
4
|
export type BrokerArchiveRow = {
|
|
5
5
|
table: BrokerArchiveTable;
|
|
6
6
|
row: Record<string, unknown>;
|
|
@@ -16,5 +16,7 @@ export type BrokerArchiveCommonTags = {
|
|
|
16
16
|
export type OrderArchiveAction = "CreateOrder" | "CancelOrder" | "GetOrderDetails";
|
|
17
17
|
export type SubscribeArchiveType = "ORDERS" | "BALANCE";
|
|
18
18
|
export type TransferEventKind = "withdrawal" | "deposit" | "internal_transfer";
|
|
19
|
-
export type TransferLifecycleAction = "submit_withdrawal" | "observe_deposit" | "submit_internal_transfer";
|
|
19
|
+
export type TransferLifecycleAction = "submit_withdrawal" | "observe_withdrawal" | "observe_deposit" | "submit_internal_transfer";
|
|
20
20
|
export declare const FILL_EVENT_KIND: "trade_history_fill";
|
|
21
|
+
export declare const ACCOUNT_BALANCE_SCOPE: "spot";
|
|
22
|
+
export declare const ACCOUNT_BALANCE_PRECISION_BASIS: "ccxt_normalized_number";
|
|
@@ -0,0 +1,23 @@
|
|
|
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 {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { OtelLogs, OtelMetrics } from "../otel";
|
|
2
|
-
import type { BrokerArchiveRow } from "./types";
|
|
2
|
+
import type { BrokerArchiveRow, BrokerArchiveTable } from "./types";
|
|
3
|
+
export declare function isBrokerExecutionArchiveTable(table: BrokerArchiveTable): boolean;
|
|
3
4
|
export type BrokerExecutionArchiverOptions = {
|
|
4
5
|
deploymentId?: string;
|
|
5
6
|
otelLogs?: OtelLogs;
|
|
@@ -41,6 +42,7 @@ export declare class BrokerExecutionArchiver {
|
|
|
41
42
|
getDeploymentId(): string;
|
|
42
43
|
isEnabled(): boolean;
|
|
43
44
|
canPersistMarketMetadataSnapshot(): boolean;
|
|
45
|
+
canPersistAccountBalanceSnapshots(): boolean;
|
|
44
46
|
enqueue(row: BrokerArchiveRow): void;
|
|
45
47
|
enqueueInBackground(row: BrokerArchiveRow): void;
|
|
46
48
|
flush(): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,9 @@ export default class CEXBroker {
|
|
|
14
14
|
private brokerArchiver?;
|
|
15
15
|
private depositReconciler?;
|
|
16
16
|
private readonly orderActivityTracker;
|
|
17
|
+
private readonly withdrawalObservationTracker;
|
|
17
18
|
private fillArchivePoller?;
|
|
19
|
+
private accountBalanceArchivePoller?;
|
|
18
20
|
/**
|
|
19
21
|
* Loads environment variables prefixed with CEX_BROKER_
|
|
20
22
|
* Expected format:
|