@usherlabs/cex-broker 0.2.11 → 0.2.13
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 +206 -14
- package/dist/commands/cli.js +9950 -7975
- package/dist/handlers/execute-action/context.d.ts +40 -0
- package/dist/handlers/execute-action/deposit.d.ts +2 -0
- package/dist/handlers/execute-action/handler.d.ts +14 -0
- package/dist/handlers/execute-action/index.d.ts +10 -0
- package/dist/handlers/execute-action/internal-transfer.d.ts +2 -0
- package/dist/handlers/execute-action/order-book-call.d.ts +3 -0
- package/dist/handlers/execute-action/orders.d.ts +2 -0
- package/dist/handlers/execute-action/pass-through.d.ts +2 -0
- package/dist/handlers/execute-action/perp-config.d.ts +2 -0
- package/dist/handlers/execute-action/registry.d.ts +5 -0
- package/dist/handlers/execute-action/treasury-call.d.ts +2 -0
- package/dist/handlers/execute-action/withdraw.d.ts +2 -0
- package/dist/handlers/subscribe/handler.d.ts +12 -0
- package/dist/handlers/subscribe/index.d.ts +1 -0
- package/dist/handlers/types.d.ts +23 -0
- package/dist/helpers/auth.d.ts +5 -0
- package/dist/helpers/binance-user-data-stream.d.ts +28 -0
- package/dist/helpers/broker.d.ts +38 -0
- package/dist/helpers/constants.d.ts +7 -2
- package/dist/helpers/deposit.d.ts +5 -0
- package/dist/helpers/exchange-credentials.d.ts +10 -0
- package/dist/helpers/grpc/broker.d.ts +5 -0
- package/dist/helpers/grpc/callbacks.d.ts +9 -0
- package/dist/helpers/grpc/payload.d.ts +9 -0
- package/dist/helpers/grpc/status.d.ts +8 -0
- package/dist/helpers/index.d.ts +8 -41
- package/dist/helpers/market-type.d.ts +16 -0
- package/dist/helpers/order-book.d.ts +79 -0
- package/dist/helpers/order-telemetry.d.ts +48 -0
- package/dist/helpers/shared/errors.d.ts +2 -0
- package/dist/helpers/shared/guards.d.ts +2 -0
- package/dist/helpers/transfer-network.d.ts +12 -0
- package/dist/helpers/treasury-discovery.d.ts +17 -0
- package/dist/helpers/verity.d.ts +5 -0
- package/dist/index.js +9738 -7763
- package/dist/index.js.map +78 -46
- package/dist/proto/node.descriptor.d.ts +127 -0
- package/dist/proto/node.descriptor.ts +3 -1
- package/dist/proto/node.proto +2 -0
- package/dist/proto-loader-options.d.ts +7 -0
- package/dist/proto-package-definition.d.ts +2 -0
- package/dist/schemas/action-payloads.d.ts +22 -0
- package/dist/server.d.ts +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,40 @@
|
|
|
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 { Action as ActionType } from "../../helpers/constants";
|
|
7
|
+
import type { OtelMetrics } from "../../helpers/otel";
|
|
8
|
+
import type { PolicyConfig } from "../../types";
|
|
9
|
+
import type { ActionRequest, ActionResponse } from "../types";
|
|
10
|
+
export type ActionHandler = (ctx: ExecuteActionContext) => Promise<void>;
|
|
11
|
+
export type ExecuteActionContext = {
|
|
12
|
+
call: grpc.ServerUnaryCall<ActionRequest, ActionResponse>;
|
|
13
|
+
wrappedCallback: grpc.sendUnaryData<ActionResponse>;
|
|
14
|
+
action: ActionType;
|
|
15
|
+
policy: PolicyConfig;
|
|
16
|
+
brokers: Record<string, BrokerPoolEntry>;
|
|
17
|
+
metadata: Metadata;
|
|
18
|
+
normalizedCex: string;
|
|
19
|
+
cex: string;
|
|
20
|
+
symbol?: string;
|
|
21
|
+
selectedBrokerAccount?: BrokerAccount;
|
|
22
|
+
broker: Exchange;
|
|
23
|
+
verity: {
|
|
24
|
+
proof: string;
|
|
25
|
+
};
|
|
26
|
+
applyVerityToBroker: (target: Exchange) => void;
|
|
27
|
+
useVerity: boolean;
|
|
28
|
+
verityProverUrl: string;
|
|
29
|
+
otelMetrics?: OtelMetrics;
|
|
30
|
+
};
|
|
31
|
+
export declare function requireSymbol(ctx: ExecuteActionContext, message?: string): ctx is ExecuteActionContext & {
|
|
32
|
+
symbol: string;
|
|
33
|
+
};
|
|
34
|
+
export declare function parsePayloadForAction<T>(ctx: ExecuteActionContext, schema: z.ZodType<T>): T | null;
|
|
35
|
+
export declare function rejectWithGrpcError(ctx: ExecuteActionContext, error: unknown, options?: {
|
|
36
|
+
message?: string;
|
|
37
|
+
prefix?: string;
|
|
38
|
+
preferStableMessageOnly?: boolean;
|
|
39
|
+
}): void;
|
|
40
|
+
export declare function successWithProof(ctx: ExecuteActionContext, result: unknown): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as grpc from "@grpc/grpc-js";
|
|
2
|
+
import { type BrokerPoolEntry } from "../../helpers/broker";
|
|
3
|
+
import type { OtelMetrics } from "../../helpers/otel";
|
|
4
|
+
import type { PolicyConfig } from "../../types";
|
|
5
|
+
import type { ActionRequest, ActionResponse } from "../types";
|
|
6
|
+
export type ExecuteActionDeps = {
|
|
7
|
+
policy: PolicyConfig;
|
|
8
|
+
brokers: Record<string, BrokerPoolEntry>;
|
|
9
|
+
whitelistIps: string[];
|
|
10
|
+
useVerity: boolean;
|
|
11
|
+
verityProverUrl: string;
|
|
12
|
+
otelMetrics?: OtelMetrics;
|
|
13
|
+
};
|
|
14
|
+
export declare function createExecuteActionHandler(deps: ExecuteActionDeps): (call: grpc.ServerUnaryCall<ActionRequest, ActionResponse>, callback: grpc.sendUnaryData<ActionResponse>) => Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
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";
|
|
@@ -0,0 +1,5 @@
|
|
|
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>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as grpc from "@grpc/grpc-js";
|
|
2
|
+
import { type BrokerPoolEntry } from "../../helpers/broker";
|
|
3
|
+
import type { OtelMetrics } from "../../helpers/otel";
|
|
4
|
+
import type { SubscribeRequest, SubscribeResponse } from "../types";
|
|
5
|
+
export type SubscribeDeps = {
|
|
6
|
+
brokers: Record<string, BrokerPoolEntry>;
|
|
7
|
+
whitelistIps: string[];
|
|
8
|
+
otelMetrics?: OtelMetrics;
|
|
9
|
+
};
|
|
10
|
+
type SubscribeCall = grpc.ServerWritableStream<SubscribeRequest, SubscribeResponse>;
|
|
11
|
+
export declare function createSubscribeHandler(deps: SubscribeDeps): (call: SubscribeCall) => Promise<void>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createSubscribeHandler, type SubscribeDeps } from "./handler";
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
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 type BinanceUserDataEvent = {
|
|
4
|
+
subscriptionId: number;
|
|
5
|
+
event: Record<string, unknown>;
|
|
6
|
+
};
|
|
7
|
+
export declare function getBinanceSpotWsApiUrl(exchange: Exchange): string;
|
|
8
|
+
export declare class BinanceSpotUserDataStream implements AsyncIterable<BinanceUserDataEvent> {
|
|
9
|
+
private readonly exchange;
|
|
10
|
+
private readonly ws;
|
|
11
|
+
private readonly requestId;
|
|
12
|
+
private readonly queue;
|
|
13
|
+
private readonly waiters;
|
|
14
|
+
private closed;
|
|
15
|
+
private closeError;
|
|
16
|
+
private subscriptionId;
|
|
17
|
+
constructor(exchange: Exchange);
|
|
18
|
+
[Symbol.asyncIterator](): AsyncIterator<BinanceUserDataEvent>;
|
|
19
|
+
close(): void;
|
|
20
|
+
private subscribe;
|
|
21
|
+
private handleMessage;
|
|
22
|
+
private push;
|
|
23
|
+
private nextEvent;
|
|
24
|
+
private fail;
|
|
25
|
+
private flushWaiters;
|
|
26
|
+
}
|
|
27
|
+
export declare function isBinanceBalanceUserDataEvent(event: Record<string, unknown>): boolean;
|
|
28
|
+
export declare function isBinanceOrderUserDataEvent(event: Record<string, unknown>): boolean;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Metadata } from "@grpc/grpc-js";
|
|
2
|
+
import type { Exchange } from "@usherlabs/ccxt";
|
|
3
|
+
import type { BrokerAccountRole, BrokerCredentials } from "../types";
|
|
4
|
+
export type BrokerAccount = {
|
|
5
|
+
exchange: Exchange;
|
|
6
|
+
label: "primary" | `secondary:${number}`;
|
|
7
|
+
index?: number;
|
|
8
|
+
role?: BrokerAccountRole;
|
|
9
|
+
email?: string;
|
|
10
|
+
subAccountId?: string;
|
|
11
|
+
uid?: string;
|
|
12
|
+
};
|
|
13
|
+
export type BrokerPoolEntry = {
|
|
14
|
+
primary: BrokerAccount;
|
|
15
|
+
secondaryBrokers: BrokerAccount[];
|
|
16
|
+
};
|
|
17
|
+
export declare class BrokerAccountPreconditionError extends Error {
|
|
18
|
+
constructor(message: string);
|
|
19
|
+
}
|
|
20
|
+
export declare function requireDestinationEmail(dest: BrokerAccount, transferType: "sub-to-sub" | "primary-to-sub"): string;
|
|
21
|
+
export declare function applyCommonExchangeConfig(exchange: Exchange): void;
|
|
22
|
+
export declare function createBroker(cex: string, credsOrMetadata: {
|
|
23
|
+
apiKey: string;
|
|
24
|
+
apiSecret: string;
|
|
25
|
+
} | Metadata): Exchange | null;
|
|
26
|
+
export declare function createPublicBroker(cex: string): Exchange | null;
|
|
27
|
+
type EnvConfigMap = Record<string, Partial<BrokerCredentials> & {
|
|
28
|
+
_secondaryMap?: Record<number, Partial<BrokerCredentials>>;
|
|
29
|
+
}>;
|
|
30
|
+
type ValidatedCredentialsMap = Record<string, BrokerCredentials & {
|
|
31
|
+
secondaryKeys: BrokerCredentials[];
|
|
32
|
+
}>;
|
|
33
|
+
export declare function createBrokerPool(cfg: EnvConfigMap | ValidatedCredentialsMap): Record<string, BrokerPoolEntry>;
|
|
34
|
+
export declare function selectBroker(brokers: BrokerPoolEntry | undefined, metadata: Metadata): Exchange | null;
|
|
35
|
+
export declare function getCurrentBrokerSelector(metadata: Metadata): string;
|
|
36
|
+
export declare function resolveBrokerAccount(brokers: BrokerPoolEntry | undefined, selector: string): BrokerAccount | null;
|
|
37
|
+
export declare function selectBrokerAccount(brokers: BrokerPoolEntry | undefined, metadata: Metadata): BrokerAccount | null;
|
|
38
|
+
export {};
|
|
@@ -14,6 +14,8 @@ export declare const Action: {
|
|
|
14
14
|
readonly FetchAccountId: 11;
|
|
15
15
|
readonly FetchFees: 12;
|
|
16
16
|
readonly InternalTransfer: 13;
|
|
17
|
+
readonly GetPerpConfigState: 14;
|
|
18
|
+
readonly SetPerpConfigState: 15;
|
|
17
19
|
};
|
|
18
20
|
export declare const SubscriptionType: {
|
|
19
21
|
readonly NO_ACTION: 0;
|
|
@@ -25,7 +27,10 @@ export declare const SubscriptionType: {
|
|
|
25
27
|
readonly ORDERS: 6;
|
|
26
28
|
};
|
|
27
29
|
export type Action = (typeof Action)[keyof typeof Action];
|
|
30
|
+
export type ActionName = keyof typeof Action;
|
|
28
31
|
export type SubscriptionType = (typeof SubscriptionType)[keyof typeof SubscriptionType];
|
|
32
|
+
export type SubscriptionTypeName = keyof typeof SubscriptionType;
|
|
29
33
|
export declare function getActionName(action: unknown): string;
|
|
30
|
-
export declare function getSubscriptionTypeName(subscriptionType:
|
|
31
|
-
export declare function
|
|
34
|
+
export declare function getSubscriptionTypeName(subscriptionType: unknown): string;
|
|
35
|
+
export declare function resolveAction(action: Action | ActionName | undefined): Action | undefined;
|
|
36
|
+
export declare function resolveSubscriptionType(type: SubscriptionType | SubscriptionTypeName | undefined): SubscriptionType;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function depositField(deposit: Record<string, unknown>, fields: string[]): {} | undefined;
|
|
2
|
+
export declare function normalizeDepositStatus(status: unknown): "unsupported" | "not_found" | "pending" | "credited" | "failed" | "timed_out";
|
|
3
|
+
export declare function depositMatchesTransaction(deposit: Record<string, unknown>, transactionHash: string): boolean;
|
|
4
|
+
export declare function stringAmountEquals(left: unknown, right: unknown): boolean;
|
|
5
|
+
export declare function normalizeAddress(value: unknown): string | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Exchange } from "@usherlabs/ccxt";
|
|
2
|
+
export type BrokerKeyPair = {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
apiSecret: string;
|
|
5
|
+
};
|
|
6
|
+
type RequiredCredentials = Exchange["requiredCredentials"];
|
|
7
|
+
export declare function getExchangeRequiredCredentials(cex: string): RequiredCredentials | null;
|
|
8
|
+
export declare function isWalletBasedExchange(cex: string): boolean;
|
|
9
|
+
export declare function buildCcxtConfig(cex: string, creds: BrokerKeyPair): Record<string, string> | null;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Metadata } from "@grpc/grpc-js";
|
|
2
|
+
import type { Exchange } from "@usherlabs/ccxt";
|
|
3
|
+
import { type BrokerAccount, type BrokerPoolEntry } from "../broker";
|
|
4
|
+
export declare function resolveActionBroker(normalizedCex: string, brokers: Record<string, BrokerPoolEntry>, metadata: Metadata, selectedBrokerAccount?: BrokerAccount): Exchange | null;
|
|
5
|
+
export declare function selectBrokerAccountForCex(normalizedCex: string, brokers: Record<string, BrokerPoolEntry>, metadata: Metadata): BrokerAccount | undefined;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as grpc from "@grpc/grpc-js";
|
|
2
|
+
import type { z } from "zod";
|
|
3
|
+
import { type ParsePayloadResult } from "./payload";
|
|
4
|
+
export declare function invalidArgumentError(message: string): grpc.ServiceError;
|
|
5
|
+
export declare function rejectInvalidPayload<T>(parsed: ParsePayloadResult<T>, callback: (error: grpc.ServiceError | null, value: null) => void): parsed is {
|
|
6
|
+
success: true;
|
|
7
|
+
data: T;
|
|
8
|
+
};
|
|
9
|
+
export declare function parseActionPayload<T>(schema: z.ZodType<T>, rawPayload: Record<string, string> | undefined, callback: (error: grpc.ServiceError | null, value: null) => void): T | null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
export type ParsePayloadResult<T> = {
|
|
3
|
+
success: true;
|
|
4
|
+
data: T;
|
|
5
|
+
} | {
|
|
6
|
+
success: false;
|
|
7
|
+
message: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function parsePayload<T>(schema: z.ZodType<T>, rawPayload: Record<string, string> | undefined): ParsePayloadResult<T>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as grpc from "@grpc/grpc-js";
|
|
2
|
+
export declare function stableGrpcErrorCode(message: string): grpc.status | undefined;
|
|
3
|
+
/** Maps CCXT typed errors to appropriate gRPC status codes. Returns undefined for unrecognized errors. */
|
|
4
|
+
export declare function mapCcxtErrorToGrpcStatus(error: unknown): grpc.status | undefined;
|
|
5
|
+
export declare function resolveGrpcError(error: unknown, message?: string): {
|
|
6
|
+
code: grpc.status;
|
|
7
|
+
message: string;
|
|
8
|
+
};
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1,47 +1,15 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
index?: number;
|
|
8
|
-
role?: BrokerAccountRole;
|
|
9
|
-
email?: string;
|
|
10
|
-
subAccountId?: string;
|
|
11
|
-
uid?: string;
|
|
12
|
-
};
|
|
13
|
-
export type BrokerPoolEntry = {
|
|
14
|
-
primary: BrokerAccount;
|
|
15
|
-
secondaryBrokers: BrokerAccount[];
|
|
16
|
-
};
|
|
17
|
-
export declare class BrokerAccountPreconditionError extends Error {
|
|
18
|
-
constructor(message: string);
|
|
19
|
-
}
|
|
20
|
-
export declare function authenticateRequest<T, E>(call: ServerUnaryCall<T, E>, whitelistIps: string[]): boolean;
|
|
21
|
-
export declare function createVerityHttpClientOverride(verityProverUrl: string, onProofCallback: (proof: string, notaryPubKey?: string) => void): (redact: string, proofTimeout: number) => HttpClientOverride;
|
|
22
|
-
export declare function applyCommonExchangeConfig(exchange: Exchange): void;
|
|
23
|
-
export declare function buildHttpClientOverrideFromMetadata(metadata: Metadata, verityProverUrl: string, onProofCallback: (proof: string, notaryPubKey?: string) => void): HttpClientOverride;
|
|
24
|
-
export declare const verityHttpClientOverridePredicate: HttpOverridePredicate;
|
|
25
|
-
export declare function createBroker(cex: string, credsOrMetadata: {
|
|
26
|
-
apiKey: string;
|
|
27
|
-
apiSecret: string;
|
|
28
|
-
} | Metadata): Exchange | null;
|
|
29
|
-
type EnvConfigMap = Record<string, Partial<BrokerCredentials> & {
|
|
30
|
-
_secondaryMap?: Record<number, Partial<BrokerCredentials>>;
|
|
31
|
-
}>;
|
|
32
|
-
type ValidatedCredentialsMap = Record<string, BrokerCredentials & {
|
|
33
|
-
secondaryKeys: BrokerCredentials[];
|
|
34
|
-
}>;
|
|
35
|
-
export declare function createBrokerPool(cfg: EnvConfigMap | ValidatedCredentialsMap): Record<string, BrokerPoolEntry>;
|
|
36
|
-
export declare function selectBroker(brokers: BrokerPoolEntry | undefined, metadata: Metadata): Exchange | null;
|
|
37
|
-
export declare function getCurrentBrokerSelector(metadata: Metadata): string;
|
|
38
|
-
export declare function resolveBrokerAccount(brokers: BrokerPoolEntry | undefined, selector: string): BrokerAccount | null;
|
|
39
|
-
export declare function selectBrokerAccount(brokers: BrokerPoolEntry | undefined, metadata: Metadata): BrokerAccount | null;
|
|
1
|
+
import type { Exchange } from "@usherlabs/ccxt";
|
|
2
|
+
import type { PolicyConfig } from "../types";
|
|
3
|
+
import { type BrokerAccount } from "./broker";
|
|
4
|
+
export { authenticateRequest } from "./auth";
|
|
5
|
+
export { applyCommonExchangeConfig, type BrokerAccount, BrokerAccountPreconditionError, type BrokerPoolEntry, createBroker, createBrokerPool, createPublicBroker, getCurrentBrokerSelector, resolveBrokerAccount, selectBroker, selectBrokerAccount, } from "./broker";
|
|
6
|
+
export { buildHttpClientOverrideFromMetadata, createVerityHttpClientOverride, verityHttpClientOverridePredicate, } from "./verity";
|
|
40
7
|
/**
|
|
41
8
|
* Loads and validates policy configuration
|
|
42
9
|
*/
|
|
43
10
|
export declare function loadPolicy(policyPath: string): PolicyConfig;
|
|
44
11
|
export declare function normalizePolicyConfig(policy: PolicyConfig): PolicyConfig;
|
|
12
|
+
export declare function normalizeBrokerNetworkId(network: string): string;
|
|
45
13
|
export declare function validateWithdraw(policy: PolicyConfig, exchange: string, network: string, recipientAddress: string, _amount: number, ticker: string): {
|
|
46
14
|
valid: boolean;
|
|
47
15
|
error?: string;
|
|
@@ -67,9 +35,8 @@ type OrderExecutionResolution = {
|
|
|
67
35
|
limitsApplied?: boolean;
|
|
68
36
|
matchedPatterns?: string[];
|
|
69
37
|
};
|
|
70
|
-
export declare function resolveOrderExecution(policy: PolicyConfig, broker: Exchange, cex: string, fromToken: string, toToken: string, amount: number, price: number): Promise<OrderExecutionResolution>;
|
|
38
|
+
export declare function resolveOrderExecution(policy: PolicyConfig, broker: Exchange, cex: string, fromToken: string, toToken: string, amount: number, price: number, marketTypeInput?: unknown): Promise<OrderExecutionResolution>;
|
|
71
39
|
export declare function validateDeposit(policy: PolicyConfig, exchange: string, network: string, ticker: string): {
|
|
72
40
|
valid: boolean;
|
|
73
41
|
error?: string;
|
|
74
42
|
};
|
|
75
|
-
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Exchange } from "@usherlabs/ccxt";
|
|
2
|
+
export type BrokerMarketType = "spot" | "swap" | "future";
|
|
3
|
+
export type TradableSymbolMatch = {
|
|
4
|
+
symbol: string;
|
|
5
|
+
side: "buy" | "sell";
|
|
6
|
+
marketType: BrokerMarketType;
|
|
7
|
+
};
|
|
8
|
+
export declare function parseMarketType(value: unknown): BrokerMarketType;
|
|
9
|
+
export declare function marketTypeToCcxtType(marketType: BrokerMarketType): "spot" | "swap" | "future";
|
|
10
|
+
export declare function findTradableSymbol(broker: Exchange, fromToken: string, toToken: string, marketType?: BrokerMarketType): Promise<TradableSymbolMatch | null>;
|
|
11
|
+
export declare function resolveSubscriptionSymbol(broker: Exchange, symbol: string, marketTypeInput: unknown): Promise<string>;
|
|
12
|
+
export type ParsedMarketPattern = {
|
|
13
|
+
symbolPattern: string;
|
|
14
|
+
requiredMarketType?: BrokerMarketType;
|
|
15
|
+
};
|
|
16
|
+
export declare function parseMarketPattern(symbolPattern: string): ParsedMarketPattern;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Exchange } from "@usherlabs/ccxt";
|
|
2
|
+
export declare const ORDER_BOOK_CALL_METHODS: {
|
|
3
|
+
readonly FETCH_CAPABILITY: "fetch_order_book_capability";
|
|
4
|
+
readonly FETCH_SNAPSHOT: "fetch_order_book_snapshot";
|
|
5
|
+
readonly FETCH_HISTORICAL_SNAPSHOTS: "fetch_historical_order_book_snapshots";
|
|
6
|
+
};
|
|
7
|
+
export type OrderBookCallMethod = (typeof ORDER_BOOK_CALL_METHODS)[keyof typeof ORDER_BOOK_CALL_METHODS];
|
|
8
|
+
export declare const ORDER_BOOK_CONSTRUCTION_MODES: {
|
|
9
|
+
readonly SAMPLED_TOP_N_SNAPSHOT: "sampled_top_n_snapshot";
|
|
10
|
+
readonly EXACT_L2_RECONSTRUCTION: "exact_l2_reconstruction";
|
|
11
|
+
};
|
|
12
|
+
export type OrderBookConstructionMode = (typeof ORDER_BOOK_CONSTRUCTION_MODES)[keyof typeof ORDER_BOOK_CONSTRUCTION_MODES];
|
|
13
|
+
export declare const HISTORICAL_ORDER_BOOK_PROVIDER_UNSUPPORTED = "historical_order_book_provider_unsupported";
|
|
14
|
+
export type OrderBookCallPayload = {
|
|
15
|
+
method: OrderBookCallMethod;
|
|
16
|
+
exchange: string;
|
|
17
|
+
symbol: string;
|
|
18
|
+
depthLimit: number;
|
|
19
|
+
constructionMode: OrderBookConstructionMode;
|
|
20
|
+
start?: string;
|
|
21
|
+
end?: string;
|
|
22
|
+
cadence?: string;
|
|
23
|
+
};
|
|
24
|
+
export type OrderBookCallParseResult = {
|
|
25
|
+
kind: "not_order_book";
|
|
26
|
+
} | {
|
|
27
|
+
kind: "error";
|
|
28
|
+
message: string;
|
|
29
|
+
} | {
|
|
30
|
+
kind: "order_book";
|
|
31
|
+
payload: OrderBookCallPayload;
|
|
32
|
+
};
|
|
33
|
+
export type NormalizedOrderBookSnapshot = {
|
|
34
|
+
bids: number[][];
|
|
35
|
+
asks: number[][];
|
|
36
|
+
timestamp: number | string | boolean | null;
|
|
37
|
+
receivedTimestamp: number;
|
|
38
|
+
exchange: string;
|
|
39
|
+
symbol: string;
|
|
40
|
+
depthLimit: number;
|
|
41
|
+
sequence?: number | string | boolean;
|
|
42
|
+
};
|
|
43
|
+
export declare function isOrderBookCallMethod(value: unknown): value is OrderBookCallMethod;
|
|
44
|
+
export declare function parseOrderBookCallPayload(payload: Record<string, string> | undefined, request: {
|
|
45
|
+
exchange?: string;
|
|
46
|
+
symbol?: string;
|
|
47
|
+
}): OrderBookCallParseResult;
|
|
48
|
+
export declare function parseOptionalDepthLimit(value: string | undefined): number | undefined;
|
|
49
|
+
export declare function normalizeOrderBookSnapshot(orderBook: unknown, options: {
|
|
50
|
+
exchange: string;
|
|
51
|
+
symbol: string;
|
|
52
|
+
depthLimit: number;
|
|
53
|
+
receivedTimestamp?: number;
|
|
54
|
+
}): NormalizedOrderBookSnapshot;
|
|
55
|
+
export declare function buildOrderBookCapability(broker: Exchange, payload: Pick<OrderBookCallPayload, "exchange" | "symbol" | "depthLimit" | "constructionMode">): {
|
|
56
|
+
exchange: string;
|
|
57
|
+
symbol: string;
|
|
58
|
+
provider: string;
|
|
59
|
+
maxDepth: number;
|
|
60
|
+
timestampPrecision: string;
|
|
61
|
+
constructionMode: OrderBookConstructionMode;
|
|
62
|
+
supportsCurrentSnapshot: boolean;
|
|
63
|
+
supportsLiveStream: boolean;
|
|
64
|
+
supportsHistoricalSnapshots: boolean;
|
|
65
|
+
supportsSampledTopN: boolean;
|
|
66
|
+
supportsExactL2Reconstruction: boolean;
|
|
67
|
+
};
|
|
68
|
+
export declare function buildHistoricalOrderBookUnsupported(payload: OrderBookCallPayload): {
|
|
69
|
+
exchange: string;
|
|
70
|
+
symbol: string;
|
|
71
|
+
provider: string;
|
|
72
|
+
constructionMode: OrderBookConstructionMode;
|
|
73
|
+
depthLimit: number;
|
|
74
|
+
start: string | undefined;
|
|
75
|
+
end: string | undefined;
|
|
76
|
+
cadence: string | undefined;
|
|
77
|
+
unsupported: boolean;
|
|
78
|
+
unsupportedReason: string;
|
|
79
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { OtelMetrics } from "./otel";
|
|
2
|
+
export type OrderTelemetryAction = "CreateOrder" | "GetOrderDetails";
|
|
3
|
+
export type OrderTelemetryContext = {
|
|
4
|
+
action: OrderTelemetryAction;
|
|
5
|
+
cex: string;
|
|
6
|
+
accountLabel?: string;
|
|
7
|
+
symbol?: string;
|
|
8
|
+
side?: string;
|
|
9
|
+
orderType?: string;
|
|
10
|
+
requestedQuantity?: number;
|
|
11
|
+
requestedNotional?: number;
|
|
12
|
+
clientOrderId?: string;
|
|
13
|
+
idempotencyId?: string;
|
|
14
|
+
makerActionId?: string;
|
|
15
|
+
brokerObservedTimestamp?: string;
|
|
16
|
+
};
|
|
17
|
+
export type OrderExecutionTelemetry = {
|
|
18
|
+
event: "cex_market_action_execution";
|
|
19
|
+
action: OrderTelemetryAction;
|
|
20
|
+
cex: string;
|
|
21
|
+
accountLabel: string;
|
|
22
|
+
symbol: string;
|
|
23
|
+
side: string;
|
|
24
|
+
orderType: string;
|
|
25
|
+
orderId?: string;
|
|
26
|
+
clientOrderId?: string;
|
|
27
|
+
idempotencyId?: string;
|
|
28
|
+
makerActionId?: string;
|
|
29
|
+
status: string;
|
|
30
|
+
requestedQuantity?: number;
|
|
31
|
+
requestedNotional?: number;
|
|
32
|
+
executedBaseQuantity?: number;
|
|
33
|
+
executedQuoteQuantity?: number;
|
|
34
|
+
averageExecutionPrice?: number;
|
|
35
|
+
filledAmount?: number;
|
|
36
|
+
remainingAmount?: number;
|
|
37
|
+
feeAmount?: number;
|
|
38
|
+
feeCurrency?: string;
|
|
39
|
+
feeRate?: number;
|
|
40
|
+
exchangeTimestamp?: string;
|
|
41
|
+
brokerObservedTimestamp: string;
|
|
42
|
+
errorType?: string;
|
|
43
|
+
errorMessage?: string;
|
|
44
|
+
};
|
|
45
|
+
export declare function emitOrderExecutionTelemetry(otelMetrics: OtelMetrics | undefined, context: OrderTelemetryContext, order: unknown, error?: unknown): Promise<OrderExecutionTelemetry | undefined>;
|
|
46
|
+
export declare function buildOrderExecutionTelemetry(context: OrderTelemetryContext, order: unknown, error?: unknown): OrderExecutionTelemetry;
|
|
47
|
+
export declare function emitOrderExecutionTelemetryInBackground(otelMetrics: OtelMetrics | undefined, context: OrderTelemetryContext, order: unknown, error?: unknown): void;
|
|
48
|
+
export declare function extractOrderTelemetryIds(params: Record<string, string | number> | undefined): Pick<OrderTelemetryContext, "clientOrderId" | "idempotencyId" | "makerActionId">;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Exchange } from "@usherlabs/ccxt";
|
|
2
|
+
export type TransferNetworkResolution = {
|
|
3
|
+
operatorAlias: string;
|
|
4
|
+
brokerNetworkId: string;
|
|
5
|
+
exchangeNetworkId: string;
|
|
6
|
+
networkKey: string | null;
|
|
7
|
+
};
|
|
8
|
+
export declare function buildTransferNetworkEvidence(currencyInfo: Record<string, unknown>): {
|
|
9
|
+
networks: Record<string, unknown>;
|
|
10
|
+
aliases: Record<string, TransferNetworkResolution>;
|
|
11
|
+
};
|
|
12
|
+
export declare function resolveTransferNetwork(broker: Exchange, assetCode: string, operatorAlias: string): Promise<TransferNetworkResolution>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Exchange } from "@usherlabs/ccxt";
|
|
2
|
+
export type ExchangeWithDiscovery = Exchange & {
|
|
3
|
+
has?: Record<string, unknown>;
|
|
4
|
+
markets?: Record<string, unknown>;
|
|
5
|
+
currencies?: Record<string, unknown>;
|
|
6
|
+
fetchMarkets?: (...args: unknown[]) => Promise<unknown>;
|
|
7
|
+
fetchCurrencies?: (...args: unknown[]) => Promise<Record<string, unknown>>;
|
|
8
|
+
fetchDeposits?: (code?: string, since?: number, limit?: number, params?: Record<string, unknown>) => Promise<Array<Record<string, unknown>>>;
|
|
9
|
+
};
|
|
10
|
+
export declare function callArgs(args: unknown[] | undefined, params: Record<string, unknown> | undefined): unknown[];
|
|
11
|
+
export declare function handleTreasuryDiscoveryCall(broker: Exchange, functionName: string, args: unknown[], params: Record<string, unknown>): Promise<{
|
|
12
|
+
handled: true;
|
|
13
|
+
result: unknown;
|
|
14
|
+
} | {
|
|
15
|
+
handled: false;
|
|
16
|
+
}>;
|
|
17
|
+
export declare function fetchCurrencyMetadata(broker: Exchange, assetCode: string): Promise<Record<string, unknown> | undefined>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Metadata } from "@grpc/grpc-js";
|
|
2
|
+
import type { HttpClientOverride, HttpOverridePredicate } from "@usherlabs/ccxt";
|
|
3
|
+
export declare function createVerityHttpClientOverride(verityProverUrl: string, onProofCallback: (proof: string, notaryPubKey?: string) => void): (redact: string, proofTimeout: number) => HttpClientOverride;
|
|
4
|
+
export declare function buildHttpClientOverrideFromMetadata(metadata: Metadata, verityProverUrl: string, onProofCallback: (proof: string, notaryPubKey?: string) => void): HttpClientOverride;
|
|
5
|
+
export declare const verityHttpClientOverridePredicate: HttpOverridePredicate;
|