@polyester/sdk 0.19.0 → 0.19.2
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/CHANGELOG.md +12 -0
- package/dist/gen/ledger/read/v1/ledger_read_pb.d.ts +258 -3
- package/dist/gen/ledger/read/v1/ledger_read_pb.d.ts.map +1 -1
- package/dist/gen/ledger/read/v1/ledger_read_pb.js +55 -13
- package/dist/gen/ledger/read/v1/ledger_read_pb.js.map +1 -1
- package/dist/gen/triggers/v1/triggers_pb.js +1 -1
- package/dist/gen/triggers/v1/triggers_pb.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/services/balances/balances.d.ts +9 -1
- package/dist/services/balances/balances.d.ts.map +1 -1
- package/dist/services/balances/balances.js +22 -1
- package/dist/services/balances/balances.js.map +1 -1
- package/dist/services/balances/balances.schemas.d.ts +165 -1
- package/dist/services/balances/balances.schemas.d.ts.map +1 -1
- package/dist/services/balances/balances.schemas.js +84 -3
- package/dist/services/balances/balances.schemas.js.map +1 -1
- package/dist/services/balances/balances.types.d.ts +2 -2
- package/dist/services/balances/index.d.ts +2 -2
- package/dist/services/orders/orders-input.schemas.d.ts +1 -1
- package/dist/services/orders/orders-output.schemas.d.ts +6 -6
- package/dist/services/subaccounts/subaccounts.schemas.d.ts +2 -2
- package/dist/services/trailing-oneof-inputs.js +3 -2
- package/dist/services/trailing-oneof-inputs.js.map +1 -1
- package/dist/services/triggers/trigger-input.schemas.d.ts +1 -1
- package/dist/services/triggers/triggers-output.schemas.d.ts +15 -15
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"balances.js","names":["#client","Proto.LedgerReadService","#realtime","#resolver","#scales","#ledgerBalanceSchema","#balanceHistoryResponseSchema","#equityHistoryResponseSchema","Proto.AssetBalanceSchema"],"sources":["../../../src/services/balances/balances.ts"],"sourcesContent":["import * as Proto from \"../../gen/ledger/read/v1/ledger_read_pb.js\";\nimport { createClient, type Client } from \"@connectrpc/connect\";\nimport * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\nimport type { PolyesterRealtime } from \"../../realtime/index.js\";\nimport { connectReadyGatedProtoChannel } from \"../../realtime/ready-gated-subscription.js\";\nimport { type SubaccountResolver, resolveAccountScopedInput } from \"../subaccount-resolver.js\";\nimport {\n toConnectCallOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport { accountScopeToSubaccountId, type AccountScopedInput } from \"../../shared/account-scope.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport type { SdkScales } from \"../../shared/decimal-surface.js\";\nimport type { AuthApiTransports } from \"../../shared/transports.js\";\nimport {\n BalanceHistoryInputSchema,\n BalancesListInputSchema,\n EquityHistoryInputSchema,\n createBalanceHistoryResponseSchema,\n createEquityHistoryResponseSchema,\n createLedgerBalanceSchema,\n type LedgerBalance,\n type BalanceHistoryInput,\n type BalanceHistoryResponse,\n type EquityHistoryInput,\n type EquityHistoryResponse,\n} from \"./balances.schemas.js\";\n\ninterface SubscribeBalancesInput extends BaseSubscribeInput<LedgerBalance> {\n accountId: string;\n}\n\n/**\n * Reads and streams ledger balances plus balance and equity history for the authenticated account scope.\n */\nexport class BalancesService {\n #client: Client<typeof Proto.LedgerReadService>;\n #realtime: PolyesterRealtime;\n #resolver?: SubaccountResolver;\n #scales: SdkScales;\n #ledgerBalanceSchema: ReturnType<typeof createLedgerBalanceSchema>;\n #balanceHistoryResponseSchema: ReturnType<typeof createBalanceHistoryResponseSchema>;\n #equityHistoryResponseSchema: ReturnType<typeof createEquityHistoryResponseSchema>;\n\n constructor(\n transports: AuthApiTransports,\n realtime: PolyesterRealtime,\n resolver: SubaccountResolver | undefined,\n scales: SdkScales,\n ) {\n this.#client = createClient(Proto.LedgerReadService, transports.authApi);\n this.#realtime = realtime;\n this.#resolver = resolver;\n this.#scales = scales;\n this.#ledgerBalanceSchema = createLedgerBalanceSchema();\n this.#balanceHistoryResponseSchema = createBalanceHistoryResponseSchema();\n this.#equityHistoryResponseSchema = createEquityHistoryResponseSchema(scales);\n }\n\n /**\n * Returns current asset balances for the resolved root account or subaccount, including trading, funding, reserved, and available amounts as decimal strings.\n */\n async list(\n input: AccountScopedInput = {},\n options?: PolyesterRequestOptions,\n ): Promise<LedgerBalance[]> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validated = parse(BalancesListInputSchema, resolved);\n const res = await this.#client.getBalances(\n {\n subaccountId: accountScopeToSubaccountId(validated.account),\n },\n toConnectCallOptions(options),\n );\n return parse(v.array(this.#ledgerBalanceSchema), res.balances);\n }\n\n /**\n * Returns columnar balance history for the resolved account scope over a selected range, optionally filtered by a non-negative integer ledger asset ID and account buckets. Ledger 0 or omission includes all assets.\n */\n async getBalanceHistory(\n input: BalanceHistoryInput,\n options?: PolyesterRequestOptions,\n ): Promise<BalanceHistoryResponse> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validated = parse(BalanceHistoryInputSchema, resolved);\n const res = await this.#client.getBalanceHistory(validated, toConnectCallOptions(options));\n return parse(this.#balanceHistoryResponseSchema, res);\n }\n\n /**\n * Returns equity history series for the resolved account scope over a selected range, optionally grouped by account or asset and filtered by account buckets.\n */\n async getEquityHistory(\n input: EquityHistoryInput,\n options?: PolyesterRequestOptions,\n ): Promise<EquityHistoryResponse> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validated = parse(EquityHistoryInputSchema, resolved);\n const res = await this.#client.getEquityHistorySeries(\n validated,\n toConnectCallOptions(options),\n );\n return parse(this.#equityHistoryResponseSchema, res);\n }\n\n /**\n * Subscribes to private balance updates on private:ledger:balances:{accountId}:proto and emits every balance record as a decimal-string row. Records for assets unknown to the catalog route a CatalogLookupError to onError.\n */\n subscribe(input: SubscribeBalancesInput): () => void {\n const channel = `private:ledger:balances:${input.accountId}:proto`;\n return connectReadyGatedProtoChannel(this.#realtime, {\n channel,\n schema: Proto.AssetBalanceSchema,\n ready: () => this.#scales.ready(),\n onPublication: (data) => {\n const b = parse(this.#ledgerBalanceSchema, data);\n input.onEvent(b);\n },\n onConnected: input.onOpen,\n onDisconnected: input.onClose,\n onError: input.onError,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"balances.js","names":["#client","Proto.LedgerReadService","#realtime","#resolver","#scales","#ledgerBalanceSchema","#balanceHistoryResponseSchema","#equityHistoryResponseSchema","#portfolioEquityHistoryResponseSchema","#portfolioEquitySnapshotResponseSchema","Proto.AssetBalanceSchema"],"sources":["../../../src/services/balances/balances.ts"],"sourcesContent":["import * as Proto from \"../../gen/ledger/read/v1/ledger_read_pb.js\";\nimport { createClient, type Client } from \"@connectrpc/connect\";\nimport * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\nimport type { PolyesterRealtime } from \"../../realtime/index.js\";\nimport { connectReadyGatedProtoChannel } from \"../../realtime/ready-gated-subscription.js\";\nimport { type SubaccountResolver, resolveAccountScopedInput } from \"../subaccount-resolver.js\";\nimport {\n toConnectCallOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport { accountScopeToSubaccountId, type AccountScopedInput } from \"../../shared/account-scope.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport type { SdkScales } from \"../../shared/decimal-surface.js\";\nimport type { AuthApiTransports } from \"../../shared/transports.js\";\nimport {\n BalanceHistoryInputSchema,\n BalancesListInputSchema,\n EquityHistoryInputSchema,\n PortfolioEquityHistoryInputSchema,\n createBalanceHistoryResponseSchema,\n createEquityHistoryResponseSchema,\n createLedgerBalanceSchema,\n createPortfolioEquityHistoryResponseSchema,\n createPortfolioEquitySnapshotResponseSchema,\n type LedgerBalance,\n type BalanceHistoryInput,\n type BalanceHistoryResponse,\n type EquityHistoryInput,\n type EquityHistoryResponse,\n type PortfolioEquityHistoryInput,\n type PortfolioEquityHistoryResponse,\n type PortfolioEquitySnapshotResponse,\n} from \"./balances.schemas.js\";\n\ninterface SubscribeBalancesInput extends BaseSubscribeInput<LedgerBalance> {\n accountId: string;\n}\n\n/**\n * Reads and streams ledger balances plus balance and equity history for the authenticated account scope.\n */\nexport class BalancesService {\n #client: Client<typeof Proto.LedgerReadService>;\n #realtime: PolyesterRealtime;\n #resolver?: SubaccountResolver;\n #scales: SdkScales;\n #ledgerBalanceSchema: ReturnType<typeof createLedgerBalanceSchema>;\n #balanceHistoryResponseSchema: ReturnType<typeof createBalanceHistoryResponseSchema>;\n #equityHistoryResponseSchema: ReturnType<typeof createEquityHistoryResponseSchema>;\n #portfolioEquityHistoryResponseSchema: ReturnType<\n typeof createPortfolioEquityHistoryResponseSchema\n >;\n #portfolioEquitySnapshotResponseSchema: ReturnType<\n typeof createPortfolioEquitySnapshotResponseSchema\n >;\n\n constructor(\n transports: AuthApiTransports,\n realtime: PolyesterRealtime,\n resolver: SubaccountResolver | undefined,\n scales: SdkScales,\n ) {\n this.#client = createClient(Proto.LedgerReadService, transports.authApi);\n this.#realtime = realtime;\n this.#resolver = resolver;\n this.#scales = scales;\n this.#ledgerBalanceSchema = createLedgerBalanceSchema();\n this.#balanceHistoryResponseSchema = createBalanceHistoryResponseSchema();\n this.#equityHistoryResponseSchema = createEquityHistoryResponseSchema(scales);\n this.#portfolioEquityHistoryResponseSchema =\n createPortfolioEquityHistoryResponseSchema(scales);\n this.#portfolioEquitySnapshotResponseSchema =\n createPortfolioEquitySnapshotResponseSchema(scales);\n }\n\n /**\n * Returns current asset balances for the resolved root account or subaccount, including trading, funding, reserved, and available amounts as decimal strings.\n */\n async list(\n input: AccountScopedInput = {},\n options?: PolyesterRequestOptions,\n ): Promise<LedgerBalance[]> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validated = parse(BalancesListInputSchema, resolved);\n const res = await this.#client.getBalances(\n {\n subaccountId: accountScopeToSubaccountId(validated.account),\n },\n toConnectCallOptions(options),\n );\n return parse(v.array(this.#ledgerBalanceSchema), res.balances);\n }\n\n /**\n * Returns columnar balance history for the resolved account scope over a selected range, optionally filtered by a non-negative integer ledger asset ID and account buckets. Ledger 0 or omission includes all assets.\n */\n async getBalanceHistory(\n input: BalanceHistoryInput,\n options?: PolyesterRequestOptions,\n ): Promise<BalanceHistoryResponse> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validated = parse(BalanceHistoryInputSchema, resolved);\n const res = await this.#client.getBalanceHistory(validated, toConnectCallOptions(options));\n return parse(this.#balanceHistoryResponseSchema, res);\n }\n\n /**\n * Returns equity history series for the resolved account scope over a selected range, optionally grouped by account or asset and filtered by account buckets.\n */\n async getEquityHistory(\n input: EquityHistoryInput,\n options?: PolyesterRequestOptions,\n ): Promise<EquityHistoryResponse> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validated = parse(EquityHistoryInputSchema, resolved);\n const res = await this.#client.getEquityHistorySeries(\n validated,\n toConnectCallOptions(options),\n );\n return parse(this.#equityHistoryResponseSchema, res);\n }\n\n /**\n * Returns root portfolio equity history grouped by the master account, leading owned subaccounts, and an optional remaining-subaccounts series.\n */\n async getPortfolioEquityHistory(\n input: PortfolioEquityHistoryInput,\n options?: PolyesterRequestOptions,\n ): Promise<PortfolioEquityHistoryResponse> {\n await this.#scales.ready();\n const validated = parse(PortfolioEquityHistoryInputSchema, input);\n const res = await this.#client.getPortfolioEquityHistorySeries(\n validated,\n toConnectCallOptions(options),\n );\n return parse(this.#portfolioEquityHistoryResponseSchema, res);\n }\n\n /**\n * Returns current root portfolio equity grouped by logical account and asset.\n */\n async getPortfolioEquitySnapshot(\n options?: PolyesterRequestOptions,\n ): Promise<PortfolioEquitySnapshotResponse> {\n await this.#scales.ready();\n const res = await this.#client.getPortfolioEquitySnapshot(\n {},\n toConnectCallOptions(options),\n );\n return parse(this.#portfolioEquitySnapshotResponseSchema, res);\n }\n\n /**\n * Subscribes to private balance updates on private:ledger:balances:{accountId}:proto and emits every balance record as a decimal-string row. Records for assets unknown to the catalog route a CatalogLookupError to onError.\n */\n subscribe(input: SubscribeBalancesInput): () => void {\n const channel = `private:ledger:balances:${input.accountId}:proto`;\n return connectReadyGatedProtoChannel(this.#realtime, {\n channel,\n schema: Proto.AssetBalanceSchema,\n ready: () => this.#scales.ready(),\n onPublication: (data) => {\n const b = parse(this.#ledgerBalanceSchema, data);\n input.onEvent(b);\n },\n onConnected: input.onOpen,\n onDisconnected: input.onClose,\n onError: input.onError,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA0CA,IAAa,kBAAb,MAA6B;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CAIA,YACI,YACA,UACA,UACA,QACF;EACE,KAAKA,UAAU,aAAaC,mBAAyB,WAAW,OAAO;EACvE,KAAKC,YAAY;EACjB,KAAKC,YAAY;EACjB,KAAKC,UAAU;EACf,KAAKC,uBAAuB,0BAA0B;EACtD,KAAKC,gCAAgC,mCAAmC;EACxE,KAAKC,+BAA+B,kCAAkC,MAAM;EAC5E,KAAKC,wCACD,2CAA2C,MAAM;EACrD,KAAKC,yCACD,4CAA4C,MAAM;CAC1D;;;;CAKA,MAAM,KACF,QAA4B,CAAC,GAC7B,SACwB;EACxB,MAAM,KAAKL,QAAQ,MAAM;EACzB,MAAM,WAAW,0BAA0B,OAAO,KAAKD,SAAS;EAChE,MAAM,YAAY,MAAM,yBAAyB,QAAQ;EACzD,MAAM,MAAM,MAAM,KAAKH,QAAQ,YAC3B,EACI,cAAc,2BAA2B,UAAU,OAAO,EAC9D,GACA,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,EAAE,MAAM,KAAKK,oBAAoB,GAAG,IAAI,QAAQ;CACjE;;;;CAKA,MAAM,kBACF,OACA,SAC+B;EAC/B,MAAM,KAAKD,QAAQ,MAAM;EACzB,MAAM,WAAW,0BAA0B,OAAO,KAAKD,SAAS;EAChE,MAAM,YAAY,MAAM,2BAA2B,QAAQ;EAC3D,MAAM,MAA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T | EquityGroupBy$1.GROUP_BY_ASSET;
|
|
137
137
|
}>]>;
|
|
138
138
|
type EquityHistoryInput = v.InferInput<typeof EquityHistoryInputSchema>;
|
|
139
|
+
declare const PortfolioEquityHistoryInputSchema: v.StrictObjectSchema<{
|
|
140
|
+
readonly range: v.SchemaWithPipe<readonly [v.PicklistSchema<readonly ["1d", "7d", "30d", "90d", "180d", "365d"], undefined>, v.TransformAction<"1d" | "7d" | "30d" | "90d" | "180d" | "365d", BalanceRange$1.DAY_1 | BalanceRange$1.DAY_7 | BalanceRange$1.DAY_30 | BalanceRange$1.DAY_90 | BalanceRange$1.DAY_180 | BalanceRange$1.DAY_365>]>;
|
|
141
|
+
}, undefined>;
|
|
142
|
+
type PortfolioEquityHistoryInput = v.InferInput<typeof PortfolioEquityHistoryInputSchema>;
|
|
139
143
|
type EquitySeriesGrouping = {
|
|
140
144
|
type: "account";
|
|
141
145
|
accountCode: DecodedEnum<AccountCodeValue>;
|
|
@@ -260,6 +264,166 @@ declare function createEquityHistoryResponseSchema(scales: SdkScales): v.SchemaW
|
|
|
260
264
|
}>]>;
|
|
261
265
|
type EquitySeries = v.InferOutput<typeof EquitySeriesSchema>;
|
|
262
266
|
type EquityHistoryResponse = v.InferOutput<ReturnType<typeof createEquityHistoryResponseSchema>>;
|
|
267
|
+
type PortfolioEquitySeriesGrouping = {
|
|
268
|
+
type: "portfolioAccount";
|
|
269
|
+
accountId: string;
|
|
270
|
+
remaining: false;
|
|
271
|
+
} | {
|
|
272
|
+
type: "portfolioAccount";
|
|
273
|
+
accountId?: never;
|
|
274
|
+
remaining: true;
|
|
275
|
+
};
|
|
276
|
+
declare const PortfolioEquitySeriesSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
277
|
+
readonly grouping: v.ObjectSchema<{
|
|
278
|
+
readonly case: v.LiteralSchema<"portfolioAccount", undefined>;
|
|
279
|
+
readonly value: v.VariantSchema<"remaining", [v.ObjectSchema<{
|
|
280
|
+
readonly accountId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
281
|
+
readonly remaining: v.LiteralSchema<false, undefined>;
|
|
282
|
+
}, undefined>, v.ObjectSchema<{
|
|
283
|
+
readonly accountId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
284
|
+
readonly remaining: v.LiteralSchema<true, undefined>;
|
|
285
|
+
}, undefined>], undefined>;
|
|
286
|
+
}, undefined>;
|
|
287
|
+
readonly equityQ: v.ArraySchema<v.BigintSchema<undefined>, undefined>;
|
|
288
|
+
}, undefined>, v.TransformAction<{
|
|
289
|
+
grouping: {
|
|
290
|
+
case: "portfolioAccount";
|
|
291
|
+
value: {
|
|
292
|
+
accountId: string;
|
|
293
|
+
remaining: false;
|
|
294
|
+
} | {
|
|
295
|
+
accountId?: undefined;
|
|
296
|
+
remaining: true;
|
|
297
|
+
};
|
|
298
|
+
};
|
|
299
|
+
equityQ: bigint[];
|
|
300
|
+
}, {
|
|
301
|
+
grouping: PortfolioEquitySeriesGrouping;
|
|
302
|
+
equity: string[];
|
|
303
|
+
}>]>;
|
|
304
|
+
declare function createPortfolioEquityHistoryResponseSchema(scales: SdkScales): v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
305
|
+
readonly range: v.SchemaWithPipe<readonly [v.EnumSchema<typeof BalanceRange$1, undefined>, v.TransformAction<BalanceRange$1, "unspecified" | "1d" | "7d" | "30d" | "90d" | "180d" | "365d">]>;
|
|
306
|
+
readonly bucket: v.StringSchema<undefined>;
|
|
307
|
+
readonly startTsSec: v.NumberSchema<undefined>;
|
|
308
|
+
readonly endTsSec: v.NumberSchema<undefined>;
|
|
309
|
+
readonly quoteAsset: v.StringSchema<undefined>;
|
|
310
|
+
readonly points: v.NumberSchema<undefined>;
|
|
311
|
+
readonly series: v.ArraySchema<v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
312
|
+
readonly grouping: v.ObjectSchema<{
|
|
313
|
+
readonly case: v.LiteralSchema<"portfolioAccount", undefined>;
|
|
314
|
+
readonly value: v.VariantSchema<"remaining", [v.ObjectSchema<{
|
|
315
|
+
readonly accountId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
316
|
+
readonly remaining: v.LiteralSchema<false, undefined>;
|
|
317
|
+
}, undefined>, v.ObjectSchema<{
|
|
318
|
+
readonly accountId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
319
|
+
readonly remaining: v.LiteralSchema<true, undefined>;
|
|
320
|
+
}, undefined>], undefined>;
|
|
321
|
+
}, undefined>;
|
|
322
|
+
readonly equityQ: v.ArraySchema<v.BigintSchema<undefined>, undefined>;
|
|
323
|
+
}, undefined>, v.TransformAction<{
|
|
324
|
+
grouping: {
|
|
325
|
+
case: "portfolioAccount";
|
|
326
|
+
value: {
|
|
327
|
+
accountId: string;
|
|
328
|
+
remaining: false;
|
|
329
|
+
} | {
|
|
330
|
+
accountId?: undefined;
|
|
331
|
+
remaining: true;
|
|
332
|
+
};
|
|
333
|
+
};
|
|
334
|
+
equityQ: bigint[];
|
|
335
|
+
}, {
|
|
336
|
+
grouping: PortfolioEquitySeriesGrouping;
|
|
337
|
+
equity: string[];
|
|
338
|
+
}>]>, undefined>;
|
|
339
|
+
readonly btcPricesQ: v.OptionalSchema<v.ArraySchema<v.BigintSchema<undefined>, undefined>, readonly []>;
|
|
340
|
+
}, undefined>, v.TransformAction<{
|
|
341
|
+
range: "unspecified" | "1d" | "7d" | "30d" | "90d" | "180d" | "365d";
|
|
342
|
+
bucket: string;
|
|
343
|
+
startTsSec: number;
|
|
344
|
+
endTsSec: number;
|
|
345
|
+
quoteAsset: string;
|
|
346
|
+
points: number;
|
|
347
|
+
series: {
|
|
348
|
+
grouping: PortfolioEquitySeriesGrouping;
|
|
349
|
+
equity: string[];
|
|
350
|
+
}[];
|
|
351
|
+
btcPricesQ: bigint[];
|
|
352
|
+
}, {
|
|
353
|
+
range: "unspecified" | "1d" | "7d" | "30d" | "90d" | "180d" | "365d";
|
|
354
|
+
bucket: string;
|
|
355
|
+
startTsSec: number;
|
|
356
|
+
endTsSec: number;
|
|
357
|
+
quoteAsset: string;
|
|
358
|
+
points: number;
|
|
359
|
+
series: {
|
|
360
|
+
grouping: PortfolioEquitySeriesGrouping;
|
|
361
|
+
equity: string[];
|
|
362
|
+
}[];
|
|
363
|
+
btcPrices: string[];
|
|
364
|
+
}>]>;
|
|
365
|
+
type PortfolioEquitySeries = v.InferOutput<typeof PortfolioEquitySeriesSchema>;
|
|
366
|
+
type PortfolioEquityHistoryResponse = v.InferOutput<ReturnType<typeof createPortfolioEquityHistoryResponseSchema>>;
|
|
367
|
+
declare function createPortfolioEquitySnapshotResponseSchema(scales: SdkScales): v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
368
|
+
readonly quoteAsset: v.StringSchema<undefined>;
|
|
369
|
+
readonly totalEquityQ: v.BigintSchema<undefined>;
|
|
370
|
+
readonly accounts: v.ArraySchema<v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
371
|
+
readonly accountId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
372
|
+
readonly equityQ: v.BigintSchema<undefined>;
|
|
373
|
+
readonly topAssetIds: v.ArraySchema<v.NumberSchema<undefined>, undefined>;
|
|
374
|
+
}, undefined>, v.TransformAction<{
|
|
375
|
+
accountId: string;
|
|
376
|
+
equityQ: bigint;
|
|
377
|
+
topAssetIds: number[];
|
|
378
|
+
}, {
|
|
379
|
+
accountId: string;
|
|
380
|
+
equity: string;
|
|
381
|
+
topAssetIds: number[];
|
|
382
|
+
}>]>, undefined>;
|
|
383
|
+
readonly assets: v.ArraySchema<v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
384
|
+
readonly assetId: v.NumberSchema<undefined>;
|
|
385
|
+
readonly balanceQ: v.BigintSchema<undefined>;
|
|
386
|
+
readonly equityQ: v.BigintSchema<undefined>;
|
|
387
|
+
}, undefined>, v.TransformAction<{
|
|
388
|
+
assetId: number;
|
|
389
|
+
balanceQ: bigint;
|
|
390
|
+
equityQ: bigint;
|
|
391
|
+
}, {
|
|
392
|
+
assetId: number;
|
|
393
|
+
balance: string;
|
|
394
|
+
equity: string;
|
|
395
|
+
}>]>, undefined>;
|
|
396
|
+
readonly btcPriceQ: v.BigintSchema<undefined>;
|
|
397
|
+
}, undefined>, v.TransformAction<{
|
|
398
|
+
quoteAsset: string;
|
|
399
|
+
totalEquityQ: bigint;
|
|
400
|
+
accounts: {
|
|
401
|
+
accountId: string;
|
|
402
|
+
equity: string;
|
|
403
|
+
topAssetIds: number[];
|
|
404
|
+
}[];
|
|
405
|
+
assets: {
|
|
406
|
+
assetId: number;
|
|
407
|
+
balance: string;
|
|
408
|
+
equity: string;
|
|
409
|
+
}[];
|
|
410
|
+
btcPriceQ: bigint;
|
|
411
|
+
}, {
|
|
412
|
+
quoteAsset: string;
|
|
413
|
+
totalEquity: string;
|
|
414
|
+
accounts: {
|
|
415
|
+
accountId: string;
|
|
416
|
+
equity: string;
|
|
417
|
+
topAssetIds: number[];
|
|
418
|
+
}[];
|
|
419
|
+
assets: {
|
|
420
|
+
assetId: number;
|
|
421
|
+
balance: string;
|
|
422
|
+
equity: string;
|
|
423
|
+
}[];
|
|
424
|
+
btcPrice: string;
|
|
425
|
+
}>]>;
|
|
426
|
+
type PortfolioEquitySnapshotResponse = v.InferOutput<ReturnType<typeof createPortfolioEquitySnapshotResponseSchema>>;
|
|
263
427
|
//#endregion
|
|
264
|
-
export { BalanceHistoryInput, BalanceHistoryInputSchema, BalanceHistoryResponse, BalanceRange, BalanceRangeSchema, EquityGroupBy, EquityGroupBySchema, EquityHistoryInput, EquityHistoryInputSchema, EquityHistoryResponse, EquitySeries, EquitySeriesGrouping, EquitySeriesSchema, LedgerBalance, createBalanceHistoryResponseSchema, createEquityHistoryResponseSchema, createLedgerBalanceSchema };
|
|
428
|
+
export { BalanceHistoryInput, BalanceHistoryInputSchema, BalanceHistoryResponse, BalanceRange, BalanceRangeSchema, EquityGroupBy, EquityGroupBySchema, EquityHistoryInput, EquityHistoryInputSchema, EquityHistoryResponse, EquitySeries, EquitySeriesGrouping, EquitySeriesSchema, LedgerBalance, PortfolioEquityHistoryInput, PortfolioEquityHistoryInputSchema, PortfolioEquityHistoryResponse, PortfolioEquitySeries, PortfolioEquitySeriesGrouping, PortfolioEquitySeriesSchema, PortfolioEquitySnapshotResponse, createBalanceHistoryResponseSchema, createEquityHistoryResponseSchema, createLedgerBalanceSchema, createPortfolioEquityHistoryResponseSchema, createPortfolioEquitySnapshotResponseSchema };
|
|
265
429
|
//# sourceMappingURL=balances.schemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"balances.schemas.d.ts","names":[],"sources":["../../../src/services/balances/balances.schemas.ts"],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"balances.schemas.d.ts","names":[],"sources":["../../../src/services/balances/balances.schemas.ts"],"mappings":";;;;;;;;;;;;;iBAwCgB,6BAAyB,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA+B7B,gBAAgB,EAAE,YAAY,kBAAkB;cAQ/C,oBAAkB,EAAA;KAEnB,eAAe,EAAE,mBAAmB;cASnC,qBAAmB,EAAA;KAEpB,gBAAgB,EAAE,mBAAmB;cAEpC,2BAAyB,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;KAwB1B,sBAAsB,EAAE,kBAAkB;iBAQtC,sCAAkC,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA0CtC,yBAAyB,EAAE,YACnC,kBAAkB;cAGT,0BAAwB,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;KAwBzB,qBAAqB,EAAE,kBAAkB;cAExC,mCAAiC,EAAA;;;KAIlC,8BAA8B,EAAE,kBAAkB;KAmBlD;EAEF;EACA,aAAa,YAAY;EACzB;;EAGA;EACA;EACA;;cAGG,oBAAkB,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKO,UAAA;EAA8B;;iBA6BpD,kCAAkC,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA7B7B,UAAA;IAA8B;;;;;;;;;;;IAA9B,UAAA;IAA8B;;;;;;;;;;;IAA9B,UAAA;IAA8B;;;;KAiExD,eAAe,EAAE,mBAAmB;KACpC,wBAAwB,EAAE,YAClC,kBAAkB;KAcV;EACJ;EAA0B;EAAmB;;EAC7C;EAA0B;EAAmB;;cAExC,6BAA2B,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;EAQF,UAAA;EAAuC;;iBAY7D,2CAA2C,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAZtC,UAAA;IAAuC;;;;;;;;;;;IAAvC,UAAA;IAAuC;;;;;;;;;;;IAAvC,UAAA;IAAuC;;;;KA+CjE,wBAAwB,EAAE,mBAAmB;KAC7C,iCAAiC,EAAE,YAC3C,kBAAkB;iBA6BN,4CAA4C,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAmBjE,kCAAkC,EAAE,YAC5C,kBAAkB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { requiredEnumLabel } from "../../shared/proto-enum-codec.js";
|
|
2
|
+
import { PublicIdSchema } from "../../shared/schemas.js";
|
|
2
3
|
import { AccountScopeInputEntries, accountScopeToSubaccountId } from "../../shared/account-scope.js";
|
|
3
4
|
import { BalanceRange } from "../../gen/ledger/read/v1/ledger_read_pb.js";
|
|
4
5
|
import { scaledToDecimalOutput } from "../../shared/decimal-surface.js";
|
|
@@ -57,11 +58,12 @@ const BALANCE_RANGES = [
|
|
|
57
58
|
"365d"
|
|
58
59
|
];
|
|
59
60
|
const BalanceRangeSchema = v.picklist(BALANCE_RANGES);
|
|
61
|
+
const BalanceRangeInputSchema = v.pipe(BalanceRangeSchema, v.transform((value) => BalanceRangeCodec.inputToProto[value]));
|
|
60
62
|
const EQUITY_GROUP_BYS = ["account", "asset"];
|
|
61
63
|
const EquityGroupBySchema = v.picklist(EQUITY_GROUP_BYS);
|
|
62
64
|
const BalanceHistoryInputSchema = v.pipe(v.strictObject({
|
|
63
65
|
...AccountScopeInputEntries,
|
|
64
|
-
range:
|
|
66
|
+
range: BalanceRangeInputSchema,
|
|
65
67
|
ledger: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(4294967295)), 0),
|
|
66
68
|
accountCodes: v.optional(v.array(v.pipe(v.picklist(ACCOUNT_CODE_VALUES), v.transform((value) => AccountCodeCodec.inputToProto[value]))), [])
|
|
67
69
|
}), v.transform(({ account, ...input }) => ({
|
|
@@ -98,13 +100,14 @@ function createBalanceHistoryResponseSchema() {
|
|
|
98
100
|
}
|
|
99
101
|
const EquityHistoryInputSchema = v.pipe(v.strictObject({
|
|
100
102
|
...AccountScopeInputEntries,
|
|
101
|
-
range:
|
|
103
|
+
range: BalanceRangeInputSchema,
|
|
102
104
|
accountCodes: v.optional(v.array(v.pipe(v.picklist(ACCOUNT_CODE_VALUES), v.transform((value) => AccountCodeCodec.inputToProto[value]))), []),
|
|
103
105
|
groupBy: v.pipe(v.optional(EquityGroupBySchema, "account"), v.transform((v) => EquityGroupByCodec.inputToProto[v ?? "account"]))
|
|
104
106
|
}), v.transform(({ account, ...input }) => ({
|
|
105
107
|
...input,
|
|
106
108
|
subaccountId: accountScopeToSubaccountId(account)
|
|
107
109
|
})));
|
|
110
|
+
const PortfolioEquityHistoryInputSchema = v.strictObject({ range: BalanceRangeInputSchema });
|
|
108
111
|
const EquitySeriesGroupingSchema = v.union([v.object({
|
|
109
112
|
case: v.literal("account"),
|
|
110
113
|
value: v.object({
|
|
@@ -161,7 +164,85 @@ function createEquityHistoryResponseSchema(scales) {
|
|
|
161
164
|
btcPrices: data.btcPricesQ.map((value) => scaledToDecimalOutput(value, scales.price()))
|
|
162
165
|
})));
|
|
163
166
|
}
|
|
167
|
+
const PortfolioAccountGroupingSchema = v.variant("remaining", [v.object({
|
|
168
|
+
accountId: PublicIdSchema,
|
|
169
|
+
remaining: v.literal(false)
|
|
170
|
+
}), v.object({
|
|
171
|
+
accountId: v.optional(v.never()),
|
|
172
|
+
remaining: v.literal(true)
|
|
173
|
+
})]);
|
|
174
|
+
const PortfolioEquitySeriesSchema = v.pipe(v.object({
|
|
175
|
+
grouping: v.object({
|
|
176
|
+
case: v.literal("portfolioAccount"),
|
|
177
|
+
value: PortfolioAccountGroupingSchema
|
|
178
|
+
}),
|
|
179
|
+
equityQ: v.array(v.bigint())
|
|
180
|
+
}), v.transform((series) => ({
|
|
181
|
+
grouping: series.grouping.value.remaining ? {
|
|
182
|
+
type: "portfolioAccount",
|
|
183
|
+
remaining: true
|
|
184
|
+
} : {
|
|
185
|
+
type: "portfolioAccount",
|
|
186
|
+
accountId: series.grouping.value.accountId,
|
|
187
|
+
remaining: false
|
|
188
|
+
},
|
|
189
|
+
equity: series.equityQ.map((value) => scaledToDecimalOutput(value, EQUITY_SCALE))
|
|
190
|
+
})));
|
|
191
|
+
function createPortfolioEquityHistoryResponseSchema(scales) {
|
|
192
|
+
return v.pipe(v.object({
|
|
193
|
+
range: v.pipe(v.enum(BalanceRange), v.transform((value) => requiredEnumLabel(BalanceRangeCodec.protoToOutput, value, "PortfolioEquityHistoryResponseSchema", "range"))),
|
|
194
|
+
bucket: v.string(),
|
|
195
|
+
startTsSec: v.number(),
|
|
196
|
+
endTsSec: v.number(),
|
|
197
|
+
quoteAsset: v.string(),
|
|
198
|
+
points: v.number(),
|
|
199
|
+
series: v.array(PortfolioEquitySeriesSchema),
|
|
200
|
+
btcPricesQ: v.optional(v.array(v.bigint()), [])
|
|
201
|
+
}), v.transform((data) => ({
|
|
202
|
+
range: data.range,
|
|
203
|
+
bucket: data.bucket,
|
|
204
|
+
startTsSec: data.startTsSec,
|
|
205
|
+
endTsSec: data.endTsSec,
|
|
206
|
+
quoteAsset: data.quoteAsset,
|
|
207
|
+
points: data.points,
|
|
208
|
+
series: data.series,
|
|
209
|
+
btcPrices: data.btcPricesQ.map((value) => scaledToDecimalOutput(value, scales.price()))
|
|
210
|
+
})));
|
|
211
|
+
}
|
|
212
|
+
const PortfolioAccountEquitySchema = v.pipe(v.object({
|
|
213
|
+
accountId: PublicIdSchema,
|
|
214
|
+
equityQ: v.bigint(),
|
|
215
|
+
topAssetIds: v.array(v.number())
|
|
216
|
+
}), v.transform((account) => ({
|
|
217
|
+
accountId: account.accountId,
|
|
218
|
+
equity: scaledToDecimalOutput(account.equityQ, EQUITY_SCALE),
|
|
219
|
+
topAssetIds: account.topAssetIds
|
|
220
|
+
})));
|
|
221
|
+
const PortfolioAssetEquitySchema = v.pipe(v.object({
|
|
222
|
+
assetId: v.number(),
|
|
223
|
+
balanceQ: v.bigint(),
|
|
224
|
+
equityQ: v.bigint()
|
|
225
|
+
}), v.transform((asset) => ({
|
|
226
|
+
assetId: asset.assetId,
|
|
227
|
+
balance: scaledToDecimalOutput(asset.balanceQ, BALANCE_HISTORY_SCALE),
|
|
228
|
+
equity: scaledToDecimalOutput(asset.equityQ, EQUITY_SCALE)
|
|
229
|
+
})));
|
|
230
|
+
function createPortfolioEquitySnapshotResponseSchema(scales) {
|
|
231
|
+
return v.pipe(v.object({
|
|
232
|
+
quoteAsset: v.string(),
|
|
233
|
+
totalEquityQ: v.bigint(),
|
|
234
|
+
accounts: v.array(PortfolioAccountEquitySchema),
|
|
235
|
+
assets: v.array(PortfolioAssetEquitySchema),
|
|
236
|
+
btcPriceQ: v.bigint()
|
|
237
|
+
}), v.transform((snapshot) => ({
|
|
238
|
+
quoteAsset: snapshot.quoteAsset,
|
|
239
|
+
totalEquity: scaledToDecimalOutput(snapshot.totalEquityQ, EQUITY_SCALE),
|
|
240
|
+
accounts: snapshot.accounts,
|
|
241
|
+
assets: snapshot.assets,
|
|
242
|
+
btcPrice: scaledToDecimalOutput(snapshot.btcPriceQ, scales.price())
|
|
243
|
+
})));
|
|
244
|
+
}
|
|
164
245
|
//#endregion
|
|
165
|
-
export { BALANCE_RANGES, BalanceHistoryInputSchema, BalanceRangeSchema, BalancesListInputSchema, EQUITY_GROUP_BYS, EquityGroupBySchema, EquityHistoryInputSchema, EquitySeriesSchema, createBalanceHistoryResponseSchema, createEquityHistoryResponseSchema, createLedgerBalanceSchema };
|
|
246
|
+
export { BALANCE_RANGES, BalanceHistoryInputSchema, BalanceRangeSchema, BalancesListInputSchema, EQUITY_GROUP_BYS, EquityGroupBySchema, EquityHistoryInputSchema, EquitySeriesSchema, PortfolioEquityHistoryInputSchema, PortfolioEquitySeriesSchema, createBalanceHistoryResponseSchema, createEquityHistoryResponseSchema, createLedgerBalanceSchema, createPortfolioEquityHistoryResponseSchema, createPortfolioEquitySnapshotResponseSchema };
|
|
166
247
|
|
|
167
248
|
//# sourceMappingURL=balances.schemas.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"balances.schemas.js","names":["Proto.BalanceRange"],"sources":["../../../src/services/balances/balances.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { fromU128 } from \"../../utils/u128.js\";\nimport { requiredEnumLabel } from \"../../shared/proto-enum-codec.js\";\nimport type { DecodedEnum } from \"../../utils/types.js\";\nimport * as Proto from \"../../gen/ledger/read/v1/ledger_read_pb.js\";\nimport {\n AccountCodeCodec,\n ACCOUNT_CODE_VALUES,\n type AccountCodeValue,\n} from \"../../shared/ledger-codes.js\";\nimport { E18_SCALE, scaledToDecimalOutput, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport { BalanceRangeCodec, EquityGroupByCodec } from \"./balances.codecs.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\n\n/**\n * Equity history values are quoted in the response's quote currency at a fixed\n * 4-decimal wire scale (proto: \"Equity in quote currency scaled by 1e4\").\n */\nconst EQUITY_SCALE = 4;\n\n/**\n * Balance history buckets use a fixed 7-decimal scale (proto: \"balance in\n * asset units scaled by 1e7\"), unlike live ledger balances which use E18.\n */\nconst BALANCE_HISTORY_SCALE = 7;\n\nconst U128Schema = v.object({\n hi: v.bigint(),\n lo: v.bigint(),\n});\n\n/**\n * AssetBalance u128 fields on the ledger wire are always 18-decimal scaled\n * (PolyesterChain base units), independent of per-asset quantityScale used\n * elsewhere for order quantities and transfer inputs.\n */\nexport function createLedgerBalanceSchema() {\n return v.pipe(\n v.object({\n assetId: v.number(),\n trading: v.pipe(v.optional(U128Schema), v.transform(fromU128)),\n funding: v.pipe(v.optional(U128Schema), v.transform(fromU128)),\n reserved: v.pipe(v.optional(U128Schema), v.transform(fromU128)),\n available: v.pipe(v.optional(U128Schema), v.transform(fromU128)),\n tradingRevision: v.pipe(\n v.optional(v.bigint(), 0n),\n v.transform((value) => value.toString()),\n ),\n fundingRevision: v.pipe(\n v.optional(v.bigint(), 0n),\n v.transform((value) => value.toString()),\n ),\n }),\n v.transform((b) => {\n return {\n assetId: b.assetId,\n funding: scaledToDecimalOutput(b.funding ?? 0n, E18_SCALE),\n trading: scaledToDecimalOutput(b.trading ?? 0n, E18_SCALE),\n reserved: scaledToDecimalOutput(b.reserved ?? 0n, E18_SCALE),\n available: scaledToDecimalOutput(b.available ?? 0n, E18_SCALE),\n tradingRevision: b.tradingRevision,\n fundingRevision: b.fundingRevision,\n };\n }),\n );\n}\n\nexport type LedgerBalance = v.InferOutput<ReturnType<typeof createLedgerBalanceSchema>>;\n\nexport const BalancesListInputSchema = v.strictObject(AccountScopeInputEntries);\n\nexport type BalancesListInput = v.InferInput<typeof BalancesListInputSchema>;\n\nexport const BALANCE_RANGES = [\"1d\", \"7d\", \"30d\", \"90d\", \"180d\", \"365d\"] as const;\n\nexport const BalanceRangeSchema = v.picklist(BALANCE_RANGES);\n\nexport type BalanceRange = v.InferOutput<typeof BalanceRangeSchema>;\n\nexport const EQUITY_GROUP_BYS = [\"account\", \"asset\"] as const;\n\nexport const EquityGroupBySchema = v.picklist(EQUITY_GROUP_BYS);\n\nexport type EquityGroupBy = v.InferOutput<typeof EquityGroupBySchema>;\n\nexport const BalanceHistoryInputSchema = v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n range: v.pipe(\n BalanceRangeSchema,\n v.transform((v) => BalanceRangeCodec.inputToProto[v]),\n ),\n ledger: v.optional(\n v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(4_294_967_295)),\n 0,\n ),\n accountCodes: v.optional(\n v.array(\n v.pipe(\n v.picklist(ACCOUNT_CODE_VALUES),\n v.transform((value) => AccountCodeCodec.inputToProto[value]),\n ),\n ),\n [],\n ),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\nexport type BalanceHistoryInput = v.InferInput<typeof BalanceHistoryInputSchema>;\n\nconst BalanceSeriesSchema = v.object({\n assetId: v.number(),\n accountCode: v.enum(AccountCodeCodec.inputToProto),\n balanceQ: v.array(v.bigint()),\n});\n\nexport function createBalanceHistoryResponseSchema() {\n return v.pipe(\n v.object({\n range: v.pipe(\n v.enum(Proto.BalanceRange),\n v.transform((v) =>\n requiredEnumLabel(\n BalanceRangeCodec.protoToOutput,\n v,\n \"BalanceHistoryResponseSchema\",\n \"range\",\n ),\n ),\n ),\n bucket: v.string(),\n startTsSec: v.number(),\n endTsSec: v.number(),\n points: v.number(),\n series: v.array(BalanceSeriesSchema),\n }),\n v.transform((data) => ({\n range: data.range,\n bucket: data.bucket,\n startTsSec: data.startTsSec,\n endTsSec: data.endTsSec,\n points: data.points,\n series: data.series.map((s) => {\n return {\n assetId: s.assetId,\n accountCode: requiredEnumLabel(\n AccountCodeCodec.protoToOutput,\n s.accountCode,\n \"BalanceHistoryResponseSchema\",\n \"account code\",\n ),\n balance: s.balanceQ.map((b) => scaledToDecimalOutput(b, BALANCE_HISTORY_SCALE)),\n };\n }),\n })),\n );\n}\n\nexport type BalanceHistoryResponse = v.InferOutput<\n ReturnType<typeof createBalanceHistoryResponseSchema>\n>;\n\nexport const EquityHistoryInputSchema = v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n range: v.pipe(\n BalanceRangeSchema,\n v.transform((v) => BalanceRangeCodec.inputToProto[v]),\n ),\n accountCodes: v.optional(\n v.array(\n v.pipe(\n v.picklist(ACCOUNT_CODE_VALUES),\n v.transform((value) => AccountCodeCodec.inputToProto[value]),\n ),\n ),\n [],\n ),\n groupBy: v.pipe(\n v.optional(EquityGroupBySchema, \"account\"),\n v.transform((v) => EquityGroupByCodec.inputToProto[v ?? \"account\"]),\n ),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\nexport type EquityHistoryInput = v.InferInput<typeof EquityHistoryInputSchema>;\n\nconst EquitySeriesGroupingSchema = v.union([\n v.object({\n case: v.literal(\"account\"),\n value: v.object({\n accountCode: v.enum(AccountCodeCodec.inputToProto),\n name: v.string(),\n }),\n }),\n v.object({\n case: v.literal(\"asset\"),\n value: v.object({\n id: v.number(),\n symbol: v.string(),\n }),\n }),\n]);\n\nexport type EquitySeriesGrouping =\n | {\n type: \"account\";\n accountCode: DecodedEnum<AccountCodeValue>;\n name: string;\n }\n | {\n type: \"asset\";\n assetId: number;\n symbol: string;\n };\n\nexport const EquitySeriesSchema = v.pipe(\n v.object({\n grouping: EquitySeriesGroupingSchema,\n equityQ: v.array(v.bigint()),\n }),\n v.transform((series): { grouping: EquitySeriesGrouping; equity: string[] } => {\n const equity = series.equityQ.map((value) => scaledToDecimalOutput(value, EQUITY_SCALE));\n if (series.grouping.case === \"account\") {\n return {\n grouping: {\n type: \"account\",\n accountCode: requiredEnumLabel(\n AccountCodeCodec.protoToOutput,\n series.grouping.value.accountCode,\n \"EquitySeriesSchema\",\n \"account code\",\n ),\n name: series.grouping.value.name,\n },\n equity,\n };\n }\n\n return {\n grouping: {\n type: \"asset\",\n assetId: series.grouping.value.id,\n symbol: series.grouping.value.symbol,\n },\n equity,\n };\n }),\n);\n\nexport function createEquityHistoryResponseSchema(scales: SdkScales) {\n return v.pipe(\n v.object({\n range: v.pipe(\n v.enum(Proto.BalanceRange),\n v.transform((v) =>\n requiredEnumLabel(\n BalanceRangeCodec.protoToOutput,\n v,\n \"EquityHistoryResponseSchema\",\n \"range\",\n ),\n ),\n ),\n bucket: v.string(),\n startTsSec: v.number(),\n endTsSec: v.number(),\n quoteAsset: v.string(),\n points: v.number(),\n series: v.array(EquitySeriesSchema),\n btcPricesQ: v.optional(v.array(v.bigint()), []),\n }),\n v.transform((data) => ({\n range: data.range,\n bucket: data.bucket,\n startTsSec: data.startTsSec,\n endTsSec: data.endTsSec,\n quoteAsset: data.quoteAsset,\n points: data.points,\n series: data.series,\n // BTC price in USDT at each timestamp, carried as price ticks on the wire.\n btcPrices: data.btcPricesQ.map((value) => scaledToDecimalOutput(value, scales.price())),\n })),\n );\n}\n\nexport type EquitySeries = v.InferOutput<typeof EquitySeriesSchema>;\nexport type EquityHistoryResponse = v.InferOutput<\n ReturnType<typeof createEquityHistoryResponseSchema>\n>;\n"],"mappings":";;;;;;;;;;;;;AAqBA,MAAM,eAAe;;;;;AAMrB,MAAM,wBAAwB;AAE9B,MAAM,aAAa,EAAE,OAAO;CACxB,IAAI,EAAE,OAAO;CACb,IAAI,EAAE,OAAO;AACjB,CAAC;;;;;;AAOD,SAAgB,4BAA4B;CACxC,OAAO,EAAE,KACL,EAAE,OAAO;EACL,SAAS,EAAE,OAAO;EAClB,SAAS,EAAE,KAAK,EAAE,SAAS,UAAU,GAAG,EAAE,UAAU,QAAQ,CAAC;EAC7D,SAAS,EAAE,KAAK,EAAE,SAAS,UAAU,GAAG,EAAE,UAAU,QAAQ,CAAC;EAC7D,UAAU,EAAE,KAAK,EAAE,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EACA,QAAQ,EAAE,OAAO;EACjB,YAAY,EAAE,OAAO;EACrB,UAAU,EAAE,OAAO;EACnB,YAAY,EAAE,OAAO;EACrB,QAAQ,EAAE,OAAO;EACjB,QAAQ,EAAE,MAAM,kBAAkB;EAClC,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;CAClD,CAAC,GACD,EAAE,WAAW,UAAU;EACnB,OAAO,KAAK;EACZ,QAAQ,KAAK;EACb,YAAY,KAAK;EACjB,UAAU,KAAK;EACf,YAAY,KAAK;EACjB,QAAQ,KAAK;EACb,QAAQ,KAAK;EAEb,WAAW,KAAK,WAAW,KAAK,UAAU,sBAAsB,OAAO,OAAO,MAAM,CAAC,CAAC;CAC1F,EAAE,CACN;AACJ"}
|
|
1
|
+
{"version":3,"file":"balances.schemas.js","names":["Proto.BalanceRange"],"sources":["../../../src/services/balances/balances.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { fromU128 } from \"../../utils/u128.js\";\nimport { requiredEnumLabel } from \"../../shared/proto-enum-codec.js\";\nimport type { DecodedEnum } from \"../../utils/types.js\";\nimport * as Proto from \"../../gen/ledger/read/v1/ledger_read_pb.js\";\nimport {\n AccountCodeCodec,\n ACCOUNT_CODE_VALUES,\n type AccountCodeValue,\n} from \"../../shared/ledger-codes.js\";\nimport { E18_SCALE, scaledToDecimalOutput, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport { BalanceRangeCodec, EquityGroupByCodec } from \"./balances.codecs.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport { PublicIdSchema } from \"../../shared/schemas.js\";\n\n/**\n * Equity history values are quoted in the response's quote currency at a fixed\n * 4-decimal wire scale (proto: \"Equity in quote currency scaled by 1e4\").\n */\nconst EQUITY_SCALE = 4;\n\n/**\n * Balance history buckets use a fixed 7-decimal scale (proto: \"balance in\n * asset units scaled by 1e7\"), unlike live ledger balances which use E18.\n */\nconst BALANCE_HISTORY_SCALE = 7;\n\nconst U128Schema = v.object({\n hi: v.bigint(),\n lo: v.bigint(),\n});\n\n/**\n * AssetBalance u128 fields on the ledger wire are always 18-decimal scaled\n * (PolyesterChain base units), independent of per-asset quantityScale used\n * elsewhere for order quantities and transfer inputs.\n */\nexport function createLedgerBalanceSchema() {\n return v.pipe(\n v.object({\n assetId: v.number(),\n trading: v.pipe(v.optional(U128Schema), v.transform(fromU128)),\n funding: v.pipe(v.optional(U128Schema), v.transform(fromU128)),\n reserved: v.pipe(v.optional(U128Schema), v.transform(fromU128)),\n available: v.pipe(v.optional(U128Schema), v.transform(fromU128)),\n tradingRevision: v.pipe(\n v.optional(v.bigint(), 0n),\n v.transform((value) => value.toString()),\n ),\n fundingRevision: v.pipe(\n v.optional(v.bigint(), 0n),\n v.transform((value) => value.toString()),\n ),\n }),\n v.transform((b) => {\n return {\n assetId: b.assetId,\n funding: scaledToDecimalOutput(b.funding ?? 0n, E18_SCALE),\n trading: scaledToDecimalOutput(b.trading ?? 0n, E18_SCALE),\n reserved: scaledToDecimalOutput(b.reserved ?? 0n, E18_SCALE),\n available: scaledToDecimalOutput(b.available ?? 0n, E18_SCALE),\n tradingRevision: b.tradingRevision,\n fundingRevision: b.fundingRevision,\n };\n }),\n );\n}\n\nexport type LedgerBalance = v.InferOutput<ReturnType<typeof createLedgerBalanceSchema>>;\n\nexport const BalancesListInputSchema = v.strictObject(AccountScopeInputEntries);\n\nexport type BalancesListInput = v.InferInput<typeof BalancesListInputSchema>;\n\nexport const BALANCE_RANGES = [\"1d\", \"7d\", \"30d\", \"90d\", \"180d\", \"365d\"] as const;\n\nexport const BalanceRangeSchema = v.picklist(BALANCE_RANGES);\n\nexport type BalanceRange = v.InferOutput<typeof BalanceRangeSchema>;\n\nconst BalanceRangeInputSchema = v.pipe(\n BalanceRangeSchema,\n v.transform((value) => BalanceRangeCodec.inputToProto[value]),\n);\n\nexport const EQUITY_GROUP_BYS = [\"account\", \"asset\"] as const;\n\nexport const EquityGroupBySchema = v.picklist(EQUITY_GROUP_BYS);\n\nexport type EquityGroupBy = v.InferOutput<typeof EquityGroupBySchema>;\n\nexport const BalanceHistoryInputSchema = v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n range: BalanceRangeInputSchema,\n ledger: v.optional(\n v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(4_294_967_295)),\n 0,\n ),\n accountCodes: v.optional(\n v.array(\n v.pipe(\n v.picklist(ACCOUNT_CODE_VALUES),\n v.transform((value) => AccountCodeCodec.inputToProto[value]),\n ),\n ),\n [],\n ),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\nexport type BalanceHistoryInput = v.InferInput<typeof BalanceHistoryInputSchema>;\n\nconst BalanceSeriesSchema = v.object({\n assetId: v.number(),\n accountCode: v.enum(AccountCodeCodec.inputToProto),\n balanceQ: v.array(v.bigint()),\n});\n\nexport function createBalanceHistoryResponseSchema() {\n return v.pipe(\n v.object({\n range: v.pipe(\n v.enum(Proto.BalanceRange),\n v.transform((v) =>\n requiredEnumLabel(\n BalanceRangeCodec.protoToOutput,\n v,\n \"BalanceHistoryResponseSchema\",\n \"range\",\n ),\n ),\n ),\n bucket: v.string(),\n startTsSec: v.number(),\n endTsSec: v.number(),\n points: v.number(),\n series: v.array(BalanceSeriesSchema),\n }),\n v.transform((data) => ({\n range: data.range,\n bucket: data.bucket,\n startTsSec: data.startTsSec,\n endTsSec: data.endTsSec,\n points: data.points,\n series: data.series.map((s) => {\n return {\n assetId: s.assetId,\n accountCode: requiredEnumLabel(\n AccountCodeCodec.protoToOutput,\n s.accountCode,\n \"BalanceHistoryResponseSchema\",\n \"account code\",\n ),\n balance: s.balanceQ.map((b) => scaledToDecimalOutput(b, BALANCE_HISTORY_SCALE)),\n };\n }),\n })),\n );\n}\n\nexport type BalanceHistoryResponse = v.InferOutput<\n ReturnType<typeof createBalanceHistoryResponseSchema>\n>;\n\nexport const EquityHistoryInputSchema = v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n range: BalanceRangeInputSchema,\n accountCodes: v.optional(\n v.array(\n v.pipe(\n v.picklist(ACCOUNT_CODE_VALUES),\n v.transform((value) => AccountCodeCodec.inputToProto[value]),\n ),\n ),\n [],\n ),\n groupBy: v.pipe(\n v.optional(EquityGroupBySchema, \"account\"),\n v.transform((v) => EquityGroupByCodec.inputToProto[v ?? \"account\"]),\n ),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\nexport type EquityHistoryInput = v.InferInput<typeof EquityHistoryInputSchema>;\n\nexport const PortfolioEquityHistoryInputSchema = v.strictObject({\n range: BalanceRangeInputSchema,\n});\n\nexport type PortfolioEquityHistoryInput = v.InferInput<typeof PortfolioEquityHistoryInputSchema>;\n\nconst EquitySeriesGroupingSchema = v.union([\n v.object({\n case: v.literal(\"account\"),\n value: v.object({\n accountCode: v.enum(AccountCodeCodec.inputToProto),\n name: v.string(),\n }),\n }),\n v.object({\n case: v.literal(\"asset\"),\n value: v.object({\n id: v.number(),\n symbol: v.string(),\n }),\n }),\n]);\n\nexport type EquitySeriesGrouping =\n | {\n type: \"account\";\n accountCode: DecodedEnum<AccountCodeValue>;\n name: string;\n }\n | {\n type: \"asset\";\n assetId: number;\n symbol: string;\n };\n\nexport const EquitySeriesSchema = v.pipe(\n v.object({\n grouping: EquitySeriesGroupingSchema,\n equityQ: v.array(v.bigint()),\n }),\n v.transform((series): { grouping: EquitySeriesGrouping; equity: string[] } => {\n const equity = series.equityQ.map((value) => scaledToDecimalOutput(value, EQUITY_SCALE));\n if (series.grouping.case === \"account\") {\n return {\n grouping: {\n type: \"account\",\n accountCode: requiredEnumLabel(\n AccountCodeCodec.protoToOutput,\n series.grouping.value.accountCode,\n \"EquitySeriesSchema\",\n \"account code\",\n ),\n name: series.grouping.value.name,\n },\n equity,\n };\n }\n\n return {\n grouping: {\n type: \"asset\",\n assetId: series.grouping.value.id,\n symbol: series.grouping.value.symbol,\n },\n equity,\n };\n }),\n);\n\nexport function createEquityHistoryResponseSchema(scales: SdkScales) {\n return v.pipe(\n v.object({\n range: v.pipe(\n v.enum(Proto.BalanceRange),\n v.transform((v) =>\n requiredEnumLabel(\n BalanceRangeCodec.protoToOutput,\n v,\n \"EquityHistoryResponseSchema\",\n \"range\",\n ),\n ),\n ),\n bucket: v.string(),\n startTsSec: v.number(),\n endTsSec: v.number(),\n quoteAsset: v.string(),\n points: v.number(),\n series: v.array(EquitySeriesSchema),\n btcPricesQ: v.optional(v.array(v.bigint()), []),\n }),\n v.transform((data) => ({\n range: data.range,\n bucket: data.bucket,\n startTsSec: data.startTsSec,\n endTsSec: data.endTsSec,\n quoteAsset: data.quoteAsset,\n points: data.points,\n series: data.series,\n // BTC price in USDT at each timestamp, carried as price ticks on the wire.\n btcPrices: data.btcPricesQ.map((value) => scaledToDecimalOutput(value, scales.price())),\n })),\n );\n}\n\nexport type EquitySeries = v.InferOutput<typeof EquitySeriesSchema>;\nexport type EquityHistoryResponse = v.InferOutput<\n ReturnType<typeof createEquityHistoryResponseSchema>\n>;\n\nconst PortfolioAccountGroupingSchema = v.variant(\"remaining\", [\n v.object({\n accountId: PublicIdSchema,\n remaining: v.literal(false),\n }),\n v.object({\n accountId: v.optional(v.never()),\n remaining: v.literal(true),\n }),\n]);\n\nexport type PortfolioEquitySeriesGrouping =\n | { type: \"portfolioAccount\"; accountId: string; remaining: false }\n | { type: \"portfolioAccount\"; accountId?: never; remaining: true };\n\nexport const PortfolioEquitySeriesSchema = v.pipe(\n v.object({\n grouping: v.object({\n case: v.literal(\"portfolioAccount\"),\n value: PortfolioAccountGroupingSchema,\n }),\n equityQ: v.array(v.bigint()),\n }),\n v.transform((series): { grouping: PortfolioEquitySeriesGrouping; equity: string[] } => ({\n grouping: series.grouping.value.remaining\n ? { type: \"portfolioAccount\", remaining: true }\n : {\n type: \"portfolioAccount\",\n accountId: series.grouping.value.accountId,\n remaining: false,\n },\n equity: series.equityQ.map((value) => scaledToDecimalOutput(value, EQUITY_SCALE)),\n })),\n);\n\nexport function createPortfolioEquityHistoryResponseSchema(scales: SdkScales) {\n return v.pipe(\n v.object({\n range: v.pipe(\n v.enum(Proto.BalanceRange),\n v.transform((value) =>\n requiredEnumLabel(\n BalanceRangeCodec.protoToOutput,\n value,\n \"PortfolioEquityHistoryResponseSchema\",\n \"range\",\n ),\n ),\n ),\n bucket: v.string(),\n startTsSec: v.number(),\n endTsSec: v.number(),\n quoteAsset: v.string(),\n points: v.number(),\n series: v.array(PortfolioEquitySeriesSchema),\n btcPricesQ: v.optional(v.array(v.bigint()), []),\n }),\n v.transform((data) => ({\n range: data.range,\n bucket: data.bucket,\n startTsSec: data.startTsSec,\n endTsSec: data.endTsSec,\n quoteAsset: data.quoteAsset,\n points: data.points,\n series: data.series,\n btcPrices: data.btcPricesQ.map((value) => scaledToDecimalOutput(value, scales.price())),\n })),\n );\n}\n\nexport type PortfolioEquitySeries = v.InferOutput<typeof PortfolioEquitySeriesSchema>;\nexport type PortfolioEquityHistoryResponse = v.InferOutput<\n ReturnType<typeof createPortfolioEquityHistoryResponseSchema>\n>;\n\nconst PortfolioAccountEquitySchema = v.pipe(\n v.object({\n accountId: PublicIdSchema,\n equityQ: v.bigint(),\n topAssetIds: v.array(v.number()),\n }),\n v.transform((account) => ({\n accountId: account.accountId,\n equity: scaledToDecimalOutput(account.equityQ, EQUITY_SCALE),\n topAssetIds: account.topAssetIds,\n })),\n);\n\nconst PortfolioAssetEquitySchema = v.pipe(\n v.object({\n assetId: v.number(),\n balanceQ: v.bigint(),\n equityQ: v.bigint(),\n }),\n v.transform((asset) => ({\n assetId: asset.assetId,\n balance: scaledToDecimalOutput(asset.balanceQ, BALANCE_HISTORY_SCALE),\n equity: scaledToDecimalOutput(asset.equityQ, EQUITY_SCALE),\n })),\n);\n\nexport function createPortfolioEquitySnapshotResponseSchema(scales: SdkScales) {\n return v.pipe(\n v.object({\n quoteAsset: v.string(),\n totalEquityQ: v.bigint(),\n accounts: v.array(PortfolioAccountEquitySchema),\n assets: v.array(PortfolioAssetEquitySchema),\n btcPriceQ: v.bigint(),\n }),\n v.transform((snapshot) => ({\n quoteAsset: snapshot.quoteAsset,\n totalEquity: scaledToDecimalOutput(snapshot.totalEquityQ, EQUITY_SCALE),\n accounts: snapshot.accounts,\n assets: snapshot.assets,\n btcPrice: scaledToDecimalOutput(snapshot.btcPriceQ, scales.price()),\n })),\n );\n}\n\nexport type PortfolioEquitySnapshotResponse = v.InferOutput<\n ReturnType<typeof createPortfolioEquitySnapshotResponseSchema>\n>;\n"],"mappings":";;;;;;;;;;;;;;AAsBA,MAAM,eAAe;;;;;AAMrB,MAAM,wBAAwB;AAE9B,MAAM,aAAa,EAAE,OAAO;CACxB,IAAI,EAAE,OAAO;CACb,IAAI,EAAE,OAAO;AACjB,CAAC;;;;;;AAOD,SAAgB,4BAA4B;CACxC,OAAO,EAAE,KACL,EAAE,OAAO;EACL,SAAS,EAAE,OAAO;EAClB,SAAS,EAAE,KAAK,EAAE,SAAS,UAAU,GAAG,EAAE,UAAU,QAAQ,CAAC;EAC7D,SAAS,EAAE,KAAK,EAAE,SAAS,UAAU,GAAG,EAAE,UAAU,QAAQ,CAAC;EAC7D,UAAU,EAAE,KAAK,EAAE,SAAS,UAAU,GAAG,EAAE,UAAU,QAAQ,CAAC;EAC9D,WAAW,EAAE,KAAK,EAAE,SAAS,UAAU,GAAG,EAAE,UAAU,QAAQ,CAAC;EAC/D,iBAAiB,EAAE,KACf,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE,GACzB,EAAE,WAAW,UAAU,MAAM,SAAS,CAAC,CAC3C;EACA,iBAAiB,EAAE,KACf,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE,GACzB,EAAE,WAAW,UAAU,MAAM,SAAS,CAAC,CAC3C;CACJ,CAAC,GACD,EAAE,WAAW,MAAM;EACf,OAAO;GACH,SAAS,EAAE;GACX,SAAS,sB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B,UAAU,KAAK;EACf,YAAY,KAAK;EACjB,QAAQ,KAAK;EACb,QAAQ,KAAK;EACb,WAAW,KAAK,WAAW,KAAK,UAAU,sBAAsB,OAAO,OAAO,MAAM,CAAC,CAAC;CAC1F,EAAE,CACN;AACJ;AAOA,MAAM,+BAA+B,EAAE,KACnC,EAAE,OAAO;CACL,WAAW;CACX,SAAS,EAAE,OAAO;CAClB,aAAa,EAAE,MAAM,EAAE,OAAO,CAAC;AACnC,CAAC,GACD,EAAE,WAAW,aAAa;CACtB,WAAW,QAAQ;CACnB,QAAQ,sBAAsB,QAAQ,SAAS,YAAY;CAC3D,aAAa,QAAQ;AACzB,EAAE,CACN;AAEA,MAAM,6BAA6B,EAAE,KACjC,EAAE,OAAO;CACL,SAAS,EAAE,OAAO;CAClB,UAAU,EAAE,OAAO;CACnB,SAAS,EAAE,OAAO;AACtB,CAAC,GACD,EAAE,WAAW,WAAW;CACpB,SAAS,MAAM;CACf,SAAS,sBAAsB,MAAM,UAAU,qBAAqB;CACpE,QAAQ,sBAAsB,MAAM,SAAS,YAAY;AAC7D,EAAE,CACN;AAEA,SAAgB,4CAA4C,QAAmB;CAC3E,OAAO,EAAE,KACL,EAAE,OAAO;EACL,YAAY,EAAE,OAAO;EACrB,cAAc,EAAE,OAAO;EACvB,UAAU,EAAE,MAAM,4BAA4B;EAC9C,QAAQ,EAAE,MAAM,0BAA0B;EAC1C,WAAW,EAAE,OAAO;CACxB,CAAC,GACD,EAAE,WAAW,cAAc;EACvB,YAAY,SAAS;EACrB,aAAa,sBAAsB,SAAS,cAAc,YAAY;EACtE,UAAU,SAAS;EACnB,QAAQ,SAAS;EACjB,UAAU,sBAAsB,SAAS,WAAW,OAAO,MAAM,CAAC;CACtE,EAAE,CACN;AACJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { BalanceHistoryInput, BalanceHistoryResponse, BalanceRange, EquityGroupBy, EquityHistoryInput, EquityHistoryResponse, EquitySeries, EquitySeriesGrouping, LedgerBalance } from "./balances.schemas.js";
|
|
2
|
-
export type { BalanceHistoryInput, BalanceHistoryResponse, BalanceRange, EquityGroupBy, EquityHistoryInput, EquityHistoryResponse, EquitySeries, EquitySeriesGrouping, LedgerBalance };
|
|
1
|
+
import { BalanceHistoryInput, BalanceHistoryResponse, BalanceRange, EquityGroupBy, EquityHistoryInput, EquityHistoryResponse, EquitySeries, EquitySeriesGrouping, LedgerBalance, PortfolioEquityHistoryInput, PortfolioEquityHistoryResponse, PortfolioEquitySeries, PortfolioEquitySeriesGrouping, PortfolioEquitySnapshotResponse } from "./balances.schemas.js";
|
|
2
|
+
export type { BalanceHistoryInput, BalanceHistoryResponse, BalanceRange, EquityGroupBy, EquityHistoryInput, EquityHistoryResponse, EquitySeries, EquitySeriesGrouping, LedgerBalance, PortfolioEquityHistoryInput, PortfolioEquityHistoryResponse, PortfolioEquitySeries, PortfolioEquitySeriesGrouping, PortfolioEquitySnapshotResponse };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BalanceHistoryInput, BalanceHistoryInputSchema, BalanceHistoryResponse, BalanceRange, BalanceRangeSchema, EquityGroupBy, EquityGroupBySchema, EquityHistoryInput, EquityHistoryInputSchema, EquityHistoryResponse, EquitySeries, EquitySeriesGrouping, EquitySeriesSchema, LedgerBalance, createBalanceHistoryResponseSchema, createEquityHistoryResponseSchema, createLedgerBalanceSchema } from "./balances.schemas.js";
|
|
1
|
+
import { BalanceHistoryInput, BalanceHistoryInputSchema, BalanceHistoryResponse, BalanceRange, BalanceRangeSchema, EquityGroupBy, EquityGroupBySchema, EquityHistoryInput, EquityHistoryInputSchema, EquityHistoryResponse, EquitySeries, EquitySeriesGrouping, EquitySeriesSchema, LedgerBalance, PortfolioEquityHistoryInput, PortfolioEquityHistoryInputSchema, PortfolioEquityHistoryResponse, PortfolioEquitySeries, PortfolioEquitySeriesGrouping, PortfolioEquitySeriesSchema, PortfolioEquitySnapshotResponse, createBalanceHistoryResponseSchema, createEquityHistoryResponseSchema, createLedgerBalanceSchema, createPortfolioEquityHistoryResponseSchema, createPortfolioEquitySnapshotResponseSchema } from "./balances.schemas.js";
|
|
2
2
|
import { BalancesService } from "./balances.js";
|
|
3
3
|
import { mergeLedgerBalances } from "./balances.merge.js";
|
|
4
|
-
export { BalanceHistoryInput, BalanceHistoryInputSchema, BalanceHistoryResponse, BalanceRange, BalanceRangeSchema, BalancesService, EquityGroupBy, EquityGroupBySchema, EquityHistoryInput, EquityHistoryInputSchema, EquityHistoryResponse, EquitySeries, EquitySeriesGrouping, EquitySeriesSchema, LedgerBalance, createBalanceHistoryResponseSchema, createEquityHistoryResponseSchema, createLedgerBalanceSchema, mergeLedgerBalances };
|
|
4
|
+
export { BalanceHistoryInput, BalanceHistoryInputSchema, BalanceHistoryResponse, BalanceRange, BalanceRangeSchema, BalancesService, EquityGroupBy, EquityGroupBySchema, EquityHistoryInput, EquityHistoryInputSchema, EquityHistoryResponse, EquitySeries, EquitySeriesGrouping, EquitySeriesSchema, LedgerBalance, PortfolioEquityHistoryInput, PortfolioEquityHistoryInputSchema, PortfolioEquityHistoryResponse, PortfolioEquitySeries, PortfolioEquitySeriesGrouping, PortfolioEquitySeriesSchema, PortfolioEquitySnapshotResponse, createBalanceHistoryResponseSchema, createEquityHistoryResponseSchema, createLedgerBalanceSchema, createPortfolioEquityHistoryResponseSchema, createPortfolioEquitySnapshotResponseSchema, mergeLedgerBalances };
|
|
@@ -40,7 +40,7 @@ type OpenOrdersInput = v.InferInput<typeof OpenOrdersInputSchema>;
|
|
|
40
40
|
declare const OrderHistoryInputSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
41
41
|
readonly includeAttachedRisk: v.OptionalSchema<v.BooleanSchema<undefined>, true>;
|
|
42
42
|
readonly includeAttachedRiskState: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
|
|
43
|
-
readonly status: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["FILLED", "CANCELED", "REJECTED"], undefined>, undefined>, v.TransformAction<"
|
|
43
|
+
readonly status: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["FILLED", "CANCELED", "REJECTED"], undefined>, undefined>, v.TransformAction<"FILLED" | "CANCELED" | "REJECTED" | undefined, OrderStatus.FILLED | OrderStatus.CANCELED | OrderStatus.REJECTED | undefined>]>;
|
|
44
44
|
readonly startTsNs: v.SchemaWithPipe<readonly [v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, undefined>, v.TransformAction<string | undefined, bigint | undefined>]>;
|
|
45
45
|
readonly endTsNs: v.SchemaWithPipe<readonly [v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, undefined>, v.TransformAction<string | undefined, bigint | undefined>]>;
|
|
46
46
|
readonly symbolId: v.OptionalSchema<v.ArraySchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>, undefined>, undefined>;
|
|
@@ -243,7 +243,7 @@ declare function createOrderSchema(scales: SdkScales): v.SchemaWithPipe<readonly
|
|
|
243
243
|
attachedRisk: {
|
|
244
244
|
takeProfit: {
|
|
245
245
|
state: {
|
|
246
|
-
status: "unspecified" | "failed" | "
|
|
246
|
+
status: "unspecified" | "failed" | "completed" | "created" | "armed" | "running" | "paused" | "canceled" | "not_configured";
|
|
247
247
|
armedTs: number | undefined;
|
|
248
248
|
armedTsNs: string | undefined;
|
|
249
249
|
terminalTs: number | undefined;
|
|
@@ -262,7 +262,7 @@ declare function createOrderSchema(scales: SdkScales): v.SchemaWithPipe<readonly
|
|
|
262
262
|
} | undefined;
|
|
263
263
|
stopLoss: {
|
|
264
264
|
state: {
|
|
265
|
-
status: "unspecified" | "failed" | "
|
|
265
|
+
status: "unspecified" | "failed" | "completed" | "created" | "armed" | "running" | "paused" | "canceled" | "not_configured";
|
|
266
266
|
armedTs: number | undefined;
|
|
267
267
|
armedTsNs: string | undefined;
|
|
268
268
|
terminalTs: number | undefined;
|
|
@@ -281,7 +281,7 @@ declare function createOrderSchema(scales: SdkScales): v.SchemaWithPipe<readonly
|
|
|
281
281
|
} | undefined;
|
|
282
282
|
trailingStop: {
|
|
283
283
|
state: {
|
|
284
|
-
status: "unspecified" | "failed" | "
|
|
284
|
+
status: "unspecified" | "failed" | "completed" | "created" | "armed" | "running" | "paused" | "canceled" | "not_configured";
|
|
285
285
|
armedTs: number | undefined;
|
|
286
286
|
armedTsNs: string | undefined;
|
|
287
287
|
terminalTs: number | undefined;
|
|
@@ -586,7 +586,7 @@ declare function createOrderDetailsSchema(scales: SdkScales): v.ObjectSchema<{
|
|
|
586
586
|
attachedRisk: {
|
|
587
587
|
takeProfit: {
|
|
588
588
|
state: {
|
|
589
|
-
status: "unspecified" | "failed" | "
|
|
589
|
+
status: "unspecified" | "failed" | "completed" | "created" | "armed" | "running" | "paused" | "canceled" | "not_configured";
|
|
590
590
|
armedTs: number | undefined;
|
|
591
591
|
armedTsNs: string | undefined;
|
|
592
592
|
terminalTs: number | undefined;
|
|
@@ -605,7 +605,7 @@ declare function createOrderDetailsSchema(scales: SdkScales): v.ObjectSchema<{
|
|
|
605
605
|
} | undefined;
|
|
606
606
|
stopLoss: {
|
|
607
607
|
state: {
|
|
608
|
-
status: "unspecified" | "failed" | "
|
|
608
|
+
status: "unspecified" | "failed" | "completed" | "created" | "armed" | "running" | "paused" | "canceled" | "not_configured";
|
|
609
609
|
armedTs: number | undefined;
|
|
610
610
|
armedTsNs: string | undefined;
|
|
611
611
|
terminalTs: number | undefined;
|
|
@@ -624,7 +624,7 @@ declare function createOrderDetailsSchema(scales: SdkScales): v.ObjectSchema<{
|
|
|
624
624
|
} | undefined;
|
|
625
625
|
trailingStop: {
|
|
626
626
|
state: {
|
|
627
|
-
status: "unspecified" | "failed" | "
|
|
627
|
+
status: "unspecified" | "failed" | "completed" | "created" | "armed" | "running" | "paused" | "canceled" | "not_configured";
|
|
628
628
|
armedTs: number | undefined;
|
|
629
629
|
armedTsNs: string | undefined;
|
|
630
630
|
terminalTs: number | undefined;
|
|
@@ -279,8 +279,8 @@ declare const SubaccountActivityEventSchema: v.ObjectSchema<{
|
|
|
279
279
|
seconds: bigint;
|
|
280
280
|
nanos: number;
|
|
281
281
|
} | undefined, number | undefined>]>;
|
|
282
|
-
readonly entityKind: v.SchemaWithPipe<readonly [v.EnumSchema<typeof ActivityEntityKind, undefined>, v.TransformAction<ActivityEntityKind, "unspecified" | "api_key" | "account" | "subaccount" | "destination" | "session" | "
|
|
283
|
-
readonly eventAction: v.SchemaWithPipe<readonly [v.EnumSchema<typeof ActivityEventAction, undefined>, v.TransformAction<ActivityEventAction, "unspecified" | "enabled" | "disabled" | "failed" | "
|
|
282
|
+
readonly entityKind: v.SchemaWithPipe<readonly [v.EnumSchema<typeof ActivityEntityKind, undefined>, v.TransformAction<ActivityEntityKind, "unspecified" | "api_key" | "account" | "subaccount" | "destination" | "session" | "policy" | "member" | "invite" | "security">]>;
|
|
283
|
+
readonly eventAction: v.SchemaWithPipe<readonly [v.EnumSchema<typeof ActivityEventAction, undefined>, v.TransformAction<ActivityEventAction, "unspecified" | "enabled" | "disabled" | "failed" | "created" | "updated" | "deleted" | "removed" | "role_set" | "received" | "replied" | "revoked" | "blocked" | "hold_placed" | "hold_released">]>;
|
|
284
284
|
readonly source: v.SchemaWithPipe<readonly [v.EnumSchema<typeof ActivityEventSource, undefined>, v.TransformAction<ActivityEventSource, "unspecified" | "web" | "mobile" | "api">]>;
|
|
285
285
|
readonly ip: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
286
286
|
readonly userAgent: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { parseOptionalPositiveIntLike } from "../utils/numbers.js";
|
|
2
|
-
import
|
|
2
|
+
import "../shared/wire-bounds.js";
|
|
3
3
|
import { CatalogConversionError } from "../catalogs/types.js";
|
|
4
4
|
import { positiveDecimalInputToScaled } from "../shared/decimal-surface.js";
|
|
5
5
|
//#region src/services/trailing-oneof-inputs.ts
|
|
6
6
|
/** Product-wide cap for bps slippage inputs (market IOC, attached and standalone trailing stops). */
|
|
7
7
|
const MAX_SLIPPAGE_BPS = 1e4;
|
|
8
|
+
const MAX_TRAILING_DISTANCE_BPS = 1e4;
|
|
8
9
|
function parseTrailingDistanceInput(scales, distance, fieldName) {
|
|
9
10
|
if (distance.kind === "none") return {
|
|
10
11
|
case: void 0,
|
|
@@ -15,7 +16,7 @@ function parseTrailingDistanceInput(scales, distance, fieldName) {
|
|
|
15
16
|
value: positiveDecimalInputToScaled(`${fieldName}.distance`, distance.distance, scales.price())
|
|
16
17
|
};
|
|
17
18
|
const bps = parseOptionalPositiveIntLike(distance.bps);
|
|
18
|
-
if (bps === void 0 || bps >
|
|
19
|
+
if (bps === void 0 || bps > MAX_TRAILING_DISTANCE_BPS) throw new CatalogConversionError(`${fieldName}.bps`, `${fieldName}Bps must be between 1 and ${MAX_TRAILING_DISTANCE_BPS}`);
|
|
19
20
|
return {
|
|
20
21
|
case: "trailingDistanceBps",
|
|
21
22
|
value: bps
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trailing-oneof-inputs.js","names":[],"sources":["../../src/services/trailing-oneof-inputs.ts"],"sourcesContent":["import { positiveDecimalInputToScaled, type SdkScales } from \"../shared/decimal-surface.js\";\nimport { CatalogConversionError } from \"../catalogs/types.js\";\nimport { parseOptionalPositiveIntLike } from \"../utils/numbers.js\";\nimport { PROTOBUF_INT32_MAX } from \"../shared/wire-bounds.js\";\n\ntype PositiveIntLikeInput = string | number;\n\n/** Product-wide cap for bps slippage inputs (market IOC, attached and standalone trailing stops). */\nexport const MAX_SLIPPAGE_BPS = 10_000;\n\n/**\n * Trailing distance and slippage inputs: absolute price distances and\n * slippages are decimal price strings (e.g. \"0.50\"), converted to wire ticks\n * via the price scale; basis points are integers.\n */\nexport type TrailingDistanceInput =\n | { kind: \"distance\"; distance: string }\n | { kind: \"bps\"; bps: PositiveIntLikeInput }\n | { kind: \"none\" };\n\nexport type SlippageInput =\n | { kind: \"slippage\"; slippage: string }\n | { kind: \"bps\"; bps: PositiveIntLikeInput }\n | { kind: \"none\" };\n\ntype UnsetOneof = { case: undefined; value: undefined };\n\ntype TrailingDistanceOneof =\n | { case: \"trailingDistanceTicks\"; value: bigint }\n | { case: \"trailingDistanceBps\"; value: number }\n | UnsetOneof;\n\ntype SlippageOneof<TicksCase extends string, BpsCase extends string> =\n | { case: TicksCase; value: number }\n | { case: BpsCase; value: number }\n | UnsetOneof;\n\ntype SlippageOptions<TicksCase extends string, BpsCase extends string> = {\n fieldName: string;\n ticksCase: TicksCase;\n bpsCase: BpsCase;\n maxBps?: number;\n};\n\nexport function parseTrailingDistanceInput(\n scales: SdkScales,\n distance: TrailingDistanceInput,\n fieldName: string,\n): TrailingDistanceOneof {\n if (distance.kind === \"none\") {\n return { case: undefined, value: undefined };\n }\n if (distance.kind === \"distance\") {\n return {\n case: \"trailingDistanceTicks\",\n value: positiveDecimalInputToScaled(\n `${fieldName}.distance`,\n distance.distance,\n scales.price(),\n ),\n };\n }\n\n const bps = parseOptionalPositiveIntLike(distance.bps);\n if (bps === undefined || bps >
|
|
1
|
+
{"version":3,"file":"trailing-oneof-inputs.js","names":[],"sources":["../../src/services/trailing-oneof-inputs.ts"],"sourcesContent":["import { positiveDecimalInputToScaled, type SdkScales } from \"../shared/decimal-surface.js\";\nimport { CatalogConversionError } from \"../catalogs/types.js\";\nimport { parseOptionalPositiveIntLike } from \"../utils/numbers.js\";\nimport { PROTOBUF_INT32_MAX } from \"../shared/wire-bounds.js\";\n\ntype PositiveIntLikeInput = string | number;\n\n/** Product-wide cap for bps slippage inputs (market IOC, attached and standalone trailing stops). */\nexport const MAX_SLIPPAGE_BPS = 10_000;\n\nconst MAX_TRAILING_DISTANCE_BPS = 10_000;\n\n/**\n * Trailing distance and slippage inputs: absolute price distances and\n * slippages are decimal price strings (e.g. \"0.50\"), converted to wire ticks\n * via the price scale; basis points are integers.\n */\nexport type TrailingDistanceInput =\n | { kind: \"distance\"; distance: string }\n | { kind: \"bps\"; bps: PositiveIntLikeInput }\n | { kind: \"none\" };\n\nexport type SlippageInput =\n | { kind: \"slippage\"; slippage: string }\n | { kind: \"bps\"; bps: PositiveIntLikeInput }\n | { kind: \"none\" };\n\ntype UnsetOneof = { case: undefined; value: undefined };\n\ntype TrailingDistanceOneof =\n | { case: \"trailingDistanceTicks\"; value: bigint }\n | { case: \"trailingDistanceBps\"; value: number }\n | UnsetOneof;\n\ntype SlippageOneof<TicksCase extends string, BpsCase extends string> =\n | { case: TicksCase; value: number }\n | { case: BpsCase; value: number }\n | UnsetOneof;\n\ntype SlippageOptions<TicksCase extends string, BpsCase extends string> = {\n fieldName: string;\n ticksCase: TicksCase;\n bpsCase: BpsCase;\n maxBps?: number;\n};\n\nexport function parseTrailingDistanceInput(\n scales: SdkScales,\n distance: TrailingDistanceInput,\n fieldName: string,\n): TrailingDistanceOneof {\n if (distance.kind === \"none\") {\n return { case: undefined, value: undefined };\n }\n if (distance.kind === \"distance\") {\n return {\n case: \"trailingDistanceTicks\",\n value: positiveDecimalInputToScaled(\n `${fieldName}.distance`,\n distance.distance,\n scales.price(),\n ),\n };\n }\n\n const bps = parseOptionalPositiveIntLike(distance.bps);\n if (bps === undefined || bps > MAX_TRAILING_DISTANCE_BPS) {\n throw new CatalogConversionError(\n `${fieldName}.bps`,\n `${fieldName}Bps must be between 1 and ${MAX_TRAILING_DISTANCE_BPS}`,\n );\n }\n return { case: \"trailingDistanceBps\", value: bps };\n}\n\nexport function parseSlippageInput<const TicksCase extends string, const BpsCase extends string>(\n scales: SdkScales,\n slippage: SlippageInput | undefined,\n options: SlippageOptions<TicksCase, BpsCase>,\n): SlippageOneof<TicksCase, BpsCase> {\n if (!slippage || slippage.kind === \"none\") {\n return { case: undefined, value: undefined };\n }\n if (slippage.kind === \"slippage\") {\n const ticks = positiveDecimalInputToScaled(\n `${options.fieldName}.slippage`,\n slippage.slippage,\n scales.price(),\n );\n if (ticks > PROTOBUF_INT32_MAX) {\n throw new CatalogConversionError(\n `${options.fieldName}.slippage`,\n `${options.fieldName}.slippage exceeds the maximum supported price distance: ${slippage.slippage}`,\n );\n }\n return { case: options.ticksCase, value: Number(ticks) };\n }\n\n const bps = parseOptionalPositiveIntLike(slippage.bps);\n if (bps === undefined || bps <= 0 || exceedsMax(bps, options.maxBps)) {\n throw new CatalogConversionError(\n `${options.fieldName}.bps`,\n `${options.fieldName}Bps must be ${\n options.maxBps === undefined\n ? \"a positive integer\"\n : `between 1 and ${options.maxBps}`\n }`,\n );\n }\n return { case: options.bpsCase, value: bps };\n}\n\nfunction exceedsMax(value: number, max: number | undefined): boolean {\n return max !== undefined && value > max;\n}\n"],"mappings":";;;;;;AAQA,MAAa,mBAAmB;AAEhC,MAAM,4BAA4B;AAoClC,SAAgB,2BACZ,QACA,UACA,WACqB;CACrB,IAAI,SAAS,SAAS,QAClB,OAAO;EAAE,MAAM,KAAA;EAAW,OAAO,KAAA;CAAU;CAE/C,IAAI,SAAS,SAAS,YAClB,OAAO;EACH,MAAM;EACN,OAAO,6BACH,GAAG,UAAU,YACb,SAAS,UACT,OAAO,MAAM,CACjB;CACJ;CAGJ,MAAM,MAAM,6BAA6B,SAAS,GAAG;CACrD,IAAI,QAAQ,KAAA,KAAa,MAAM,2BAC3B,MAAM,IAAI,uBACN,GAAG,UAAU,OACb,GAAG,UAAU,4BAA4B,2BAC7C;CAEJ,OAAO;EAAE,MAAM;EAAuB,OAAO;CAAI;AACrD;AAEA,SAAgB,mBACZ,QACA,UACA,SACiC;CACjC,IAAI,CAAC,YAAY,SAAS,SAAS,QAC/B,OAAO;EAAE,MAAM,KAAA;EAAW,OAAO,KAAA;CAAU;CAE/C,IAAI,SAAS,SAAS,YAAY;EAC9B,MAAM,QAAQ,6BACV,GAAG,QAAQ,UAAU,YACrB,SAAS,UACT,OAAO,MAAM,CACjB;EACA,IAAI,QAAA,aACA,MAAM,IAAI,uBACN,GAAG,QAAQ,UAAU,YACrB,GAAG,QAAQ,UAAU,0DAA0D,SAAS,UAC5F;EAEJ,OAAO;GAAE,MAAM,QAAQ;GAAW,OAAO,OAAO,KAAK;EAAE;CAC3D;CAEA,MAAM,MAAM,6BAA6B,SAAS,GAAG;CACrD,IAAI,QAAQ,KAAA,KAAa,OAAO,KAAK,WAAW,KAAK,QAAQ,MAAM,GAC/D,MAAM,IAAI,uBACN,GAAG,QAAQ,UAAU,OACrB,GAAG,QAAQ,UAAU,cACjB,QAAQ,WAAW,KAAA,IACb,uBACA,iBAAiB,QAAQ,UAEvC;CAEJ,OAAO;EAAE,MAAM,QAAQ;EAAS,OAAO;CAAI;AAC/C;AAEA,SAAS,WAAW,OAAe,KAAkC;CACjE,OAAO,QAAQ,KAAA,KAAa,QAAQ;AACxC"}
|
|
@@ -809,7 +809,7 @@ type CreateTriggerInput = v.InferInput<ReturnType<typeof createCreateTriggerInpu
|
|
|
809
809
|
declare const ListTriggersInputSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
810
810
|
readonly parentOrderId: v.SchemaWithPipe<readonly [v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, undefined>, v.TransformAction<string | undefined, bigint | undefined>]>;
|
|
811
811
|
readonly symbolId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>, undefined>;
|
|
812
|
-
readonly status: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ArraySchema<v.PicklistSchema<readonly ["created", "armed", "running", "completed", "cancelled", "failed", "paused"], undefined>, undefined>, undefined>, v.TransformAction<("failed" | "cancelled" | "
|
|
812
|
+
readonly status: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ArraySchema<v.PicklistSchema<readonly ["created", "armed", "running", "completed", "cancelled", "failed", "paused"], undefined>, undefined>, undefined>, v.TransformAction<("failed" | "cancelled" | "completed" | "created" | "armed" | "running" | "paused")[] | undefined, (TriggerStatus.STATUS_CREATED | TriggerStatus.STATUS_ARMED | TriggerStatus.STATUS_RUNNING | TriggerStatus.STATUS_COMPLETED | TriggerStatus.STATUS_CANCELED | TriggerStatus.STATUS_FAILED | TriggerStatus.STATUS_PAUSED)[]>]>;
|
|
813
813
|
readonly triggerType: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["stop_loss", "take_profit", "trailing_stop", "twap", "ladder"], undefined>, undefined>, v.TransformAction<"twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop" | undefined, TriggerType>]>;
|
|
814
814
|
readonly limit: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 1000, undefined>]>, 50>;
|
|
815
815
|
readonly pageToken: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, "">;
|