@polyester/sdk 0.7.0 → 0.9.0
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 +24 -0
- package/dist/catalogs/readers.js +1 -1
- package/dist/gen/auth/v1/api_keys_pb.d.ts +1 -1
- package/dist/gen/auth/v1/api_keys_pb.js.map +1 -1
- package/dist/gen/auth/v1/policies_pb.d.ts +69 -341
- package/dist/gen/auth/v1/policies_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/policies_pb.js +28 -46
- package/dist/gen/auth/v1/policies_pb.js.map +1 -1
- package/dist/gen/fees/v1/fees_pb.d.ts +0 -6
- package/dist/gen/fees/v1/fees_pb.d.ts.map +1 -1
- package/dist/gen/fees/v1/fees_pb.js +1 -1
- package/dist/gen/fees/v1/fees_pb.js.map +1 -1
- package/dist/gen/marketoverview/v1/marketoverview_pb.d.ts +6 -11
- package/dist/gen/marketoverview/v1/marketoverview_pb.d.ts.map +1 -1
- package/dist/gen/marketoverview/v1/marketoverview_pb.js +1 -1
- package/dist/gen/marketoverview/v1/marketoverview_pb.js.map +1 -1
- package/dist/gen/orderbook/v1/orderbook_pb.d.ts +3 -3
- package/dist/gen/orderbook/v1/orderbook_pb.js +1 -1
- package/dist/gen/orderbook/v1/orderbook_pb.js.map +1 -1
- package/dist/gen/orders/v1/orders_pb.d.ts +43 -12
- package/dist/gen/orders/v1/orders_pb.d.ts.map +1 -1
- package/dist/gen/orders/v1/orders_pb.js +25 -1
- package/dist/gen/orders/v1/orders_pb.js.map +1 -1
- package/dist/gen/triggers/v1/triggers_pb.d.ts +28 -14
- package/dist/gen/triggers/v1/triggers_pb.d.ts.map +1 -1
- package/dist/gen/triggers/v1/triggers_pb.js +7 -1
- package/dist/gen/triggers/v1/triggers_pb.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/services/fees/fees.schemas.d.ts +2 -3
- package/dist/services/fees/fees.schemas.d.ts.map +1 -1
- package/dist/services/fees/fees.schemas.js +3 -4
- package/dist/services/fees/fees.schemas.js.map +1 -1
- package/dist/services/market-data/market-data.schemas.js +1 -1
- package/dist/services/market-overview/market-overview.d.ts +1 -1
- package/dist/services/market-overview/market-overview.js +1 -1
- package/dist/services/market-overview/market-overview.js.map +1 -1
- package/dist/services/market-overview/market-overview.schemas.d.ts +20 -7
- package/dist/services/market-overview/market-overview.schemas.d.ts.map +1 -1
- package/dist/services/market-overview/market-overview.schemas.js +8 -6
- package/dist/services/market-overview/market-overview.schemas.js.map +1 -1
- package/dist/services/orderbook/orderbook.d.ts +3 -4
- package/dist/services/orderbook/orderbook.d.ts.map +1 -1
- package/dist/services/orderbook/orderbook.js +13 -10
- package/dist/services/orderbook/orderbook.js.map +1 -1
- package/dist/services/orderbook/orderbook.schemas.d.ts +8 -9
- package/dist/services/orderbook/orderbook.schemas.d.ts.map +1 -1
- package/dist/services/orderbook/orderbook.schemas.js +9 -8
- package/dist/services/orderbook/orderbook.schemas.js.map +1 -1
- package/dist/services/orders/order-errors.schemas.d.ts +1 -1
- package/dist/services/orders/orders-batch.schemas.d.ts +42 -42
- package/dist/services/orders/orders-batch.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-batch.schemas.js +7 -8
- package/dist/services/orders/orders-batch.schemas.js.map +1 -1
- package/dist/services/orders/orders-input.schemas.d.ts +29 -29
- package/dist/services/orders/orders-input.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-input.schemas.js +10 -10
- package/dist/services/orders/orders-input.schemas.js.map +1 -1
- package/dist/services/orders/orders-modify.schemas.d.ts +3 -2
- package/dist/services/orders/orders-modify.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-modify.schemas.js +5 -3
- package/dist/services/orders/orders-modify.schemas.js.map +1 -1
- package/dist/services/orders/orders-risk.schemas.js +1 -1
- package/dist/services/orders/orders.d.ts +5 -5
- package/dist/services/orders/orders.d.ts.map +1 -1
- package/dist/services/orders/orders.js +8 -8
- package/dist/services/orders/orders.js.map +1 -1
- package/dist/services/policies/api-key-policies/api-key-policies.d.ts +2 -2
- package/dist/services/policies/api-key-policies/api-key-policies.js +2 -2
- package/dist/services/policies/api-key-policies/api-key-policies.js.map +1 -1
- package/dist/services/policies/api-key-policies/api-key-policies.schemas.d.ts +30 -155
- package/dist/services/policies/api-key-policies/api-key-policies.schemas.d.ts.map +1 -1
- package/dist/services/policies/api-key-policies/api-key-policies.schemas.js +5 -53
- package/dist/services/policies/api-key-policies/api-key-policies.schemas.js.map +1 -1
- package/dist/services/policies/shared.codecs.js +4 -12
- package/dist/services/policies/shared.codecs.js.map +1 -1
- package/dist/services/policies/shared.d.ts +1 -1
- package/dist/services/policies/shared.d.ts.map +1 -1
- package/dist/services/policies/shared.js +5 -12
- package/dist/services/policies/shared.js.map +1 -1
- package/dist/services/policies/subaccount-policies/subaccount-policies.d.ts +1 -1
- package/dist/services/policies/subaccount-policies/subaccount-policies.js +1 -1
- package/dist/services/policies/subaccount-policies/subaccount-policies.js.map +1 -1
- package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.d.ts +19 -215
- package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.d.ts.map +1 -1
- package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.js +9 -115
- package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.js.map +1 -1
- package/dist/services/shared.js +4 -1
- package/dist/services/shared.js.map +1 -1
- package/dist/services/subaccounts/subaccounts.schemas.d.ts +1 -1
- package/dist/services/trades/trades.schemas.js +1 -1
- package/dist/services/trailing-oneof-inputs.js +1 -1
- package/dist/services/triggers/trigger-child-order.schemas.js +5 -3
- package/dist/services/triggers/trigger-child-order.schemas.js.map +1 -1
- package/dist/services/triggers/trigger-input.schemas.d.ts +46 -35
- package/dist/services/triggers/trigger-input.schemas.d.ts.map +1 -1
- package/dist/services/triggers/trigger-input.schemas.js +14 -4
- package/dist/services/triggers/trigger-input.schemas.js.map +1 -1
- package/dist/services/triggers/triggers-output.schemas.d.ts +4 -5
- package/dist/services/triggers/triggers-output.schemas.d.ts.map +1 -1
- package/dist/services/triggers/triggers-output.schemas.js +3 -3
- package/dist/services/triggers/triggers-output.schemas.js.map +1 -1
- package/dist/services/triggers/triggers.codecs.js +6 -3
- package/dist/services/triggers/triggers.codecs.js.map +1 -1
- package/dist/services/triggers/triggers.d.ts +4 -4
- package/dist/services/triggers/triggers.js +4 -4
- package/dist/services/triggers/triggers.js.map +1 -1
- package/dist/services/triggers/triggers.types.d.ts +3 -3
- package/dist/shared/decimal-surface.js +1 -1
- package/dist/shared/schemas.js +2 -2
- package/dist/shared/schemas.js.map +1 -1
- package/dist/shared/transports.js +6 -1
- package/dist/shared/transports.js.map +1 -1
- package/dist/shared/wire-bounds.js +3 -1
- package/dist/shared/wire-bounds.js.map +1 -1
- package/dist/utils/numbers.js +1 -10
- package/dist/utils/numbers.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orders-input.schemas.js","names":["ProtoWrite.MarketIocSchema","ProtoWrite.LimitGtcSchema","ProtoWrite.LimitIocSchema","ProtoWrite.LimitFokSchema"],"sources":["../../../src/services/orders/orders-input.schemas.ts"],"sourcesContent":["import * as ProtoWrite from \"../../gen/orders/v1/orders_pb.js\";\nimport { create } from \"@bufbuild/protobuf\";\nimport * as v from \"valibot\";\nimport { SideSchema } from \"../shared.js\";\nimport { tsNsToMs } from \"../../utils/time.js\";\nimport { idToBigInt } from \"../../utils/base58-id.js\";\nimport {\n OptionalPublicIdSchema,\n OptionalTimestampMsSchema,\n PublicIdSchema,\n TimestampMsSchema,\n optionalIdInputSchema,\n optionalUint64DecimalFilterSchema,\n} from \"../../shared/schemas.js\";\nimport {\n positiveDecimalInputToScaled,\n scaledToDecimalOutput,\n type SdkScales,\n} from \"../../shared/decimal-surface.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport {\n FEE_ASSET_VALUES,\n ORDER_STATUS_FILTER_VALUES,\n OrderSideCodec,\n OrderStatusFilterCodec,\n SELF_TRADE_PREVENTION_MODE_VALUES,\n FeeAssetCodec,\n SelfTradePreventionModeCodec,\n} from \"./orders.codecs.js\";\nimport {\n MarketMaxSlippageSchema,\n createRiskPolicyInputSchema,\n parseMarketMaxSlippage,\n} from \"./orders-risk.schemas.js\";\nimport { OptionalClientOrderIdInputSchema } from \"./orders-identifiers.schemas.js\";\nimport { OrderErrorDetailSchema } from \"./order-errors.schemas.js\";\n\nconst OrderStatusSchema = v.picklist(ORDER_STATUS_FILTER_VALUES);\nconst FeeAssetSchema = v.picklist(FEE_ASSET_VALUES);\nconst SelfTradePreventionModeSchema = v.picklist(SELF_TRADE_PREVENTION_MODE_VALUES);\n\nconst BaseOrdersFilterInputEntries = {\n ...AccountScopeInputEntries,\n symbolId: v.optional(v.array(v.number())),\n triggerId: optionalIdInputSchema(\"triggerId\"),\n side: v.pipe(\n v.optional(SideSchema),\n v.transform((v) => (v ? OrderSideCodec.inputToProto[v] : undefined)),\n ),\n limit: v.optional(v.number()),\n pageToken: v.optional(v.pipe(v.string(), v.trim())),\n};\n\nexport const BaseOrdersFilterInputSchema = v.pipe(\n v.strictObject(BaseOrdersFilterInputEntries),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\nexport const OpenOrdersInputSchema = v.pipe(\n v.strictObject({\n ...BaseOrdersFilterInputEntries,\n\n includeAttachedRisk: v.optional(v.boolean(), true),\n includeAttachedRiskState: v.optional(v.boolean(), false),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\nexport type OpenOrdersInput = v.InferInput<typeof OpenOrdersInputSchema>;\n\nexport const OrderHistoryInputSchema = v.pipe(\n v.strictObject({\n ...BaseOrdersFilterInputEntries,\n includeAttachedRisk: v.optional(v.boolean(), true),\n includeAttachedRiskState: v.optional(v.boolean(), false),\n status: v.pipe(\n v.optional(OrderStatusSchema),\n v.transform((v) => (v ? OrderStatusFilterCodec.inputToProto[v] : undefined)),\n ),\n startTsNs: optionalUint64DecimalFilterSchema(\"startTsNs\"),\n endTsNs: optionalUint64DecimalFilterSchema(\"endTsNs\"),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\nexport type OrderHistoryInput = v.InferInput<typeof OrderHistoryInputSchema>;\n\nconst DecimalInputStringSchema = v.pipe(v.string(), v.trim(), v.minLength(1));\n\nfunction createOrderIntentBaseEntries(scales: SdkScales) {\n return {\n symbol: v.pipe(v.string(), v.trim(), v.minLength(1)),\n side: v.pipe(\n SideSchema,\n v.transform((v) => OrderSideCodec.inputToProto[v]),\n ),\n execution: createOrderExecutionInputSchema(scales),\n clientOrderId: OptionalClientOrderIdInputSchema,\n feeAsset: v.pipe(\n v.optional(FeeAssetSchema),\n v.transform((v) => (v ? FeeAssetCodec.inputToProto[v] : undefined)),\n ),\n selfTradePreventionMode: v.pipe(\n v.optional(SelfTradePreventionModeSchema),\n v.transform((v) => (v ? SelfTradePreventionModeCodec.inputToProto[v] : undefined)),\n ),\n risk: createRiskPolicyInputSchema(scales),\n };\n}\n\ntype ParsedOrderIntentInput = v.InferOutput<ReturnType<typeof createOrderIntentInputObjectSchema>>;\n\nfunction createOrderIntentInputObjectSchema(scales: SdkScales) {\n const baseEntries = createOrderIntentBaseEntries(scales);\n return v.pipe(\n v.union([\n v.strictObject({\n ...baseEntries,\n qty: DecimalInputStringSchema,\n maxQuoteDebit: v.optional(v.never()),\n }),\n v.strictObject({\n ...baseEntries,\n qty: v.optional(v.never()),\n maxQuoteDebit: DecimalInputStringSchema,\n }),\n ]),\n v.check(\n (input) =>\n input.maxQuoteDebit === undefined ||\n (input.side === ProtoWrite.Side.BUY &&\n (input.execution.case === \"marketIoc\" || input.execution.case === \"limitIoc\")),\n \"maxQuoteDebit is supported only for BUY market IOC and BUY limit IOC orders\",\n ),\n v.check(\n (input) =>\n input.side !== ProtoWrite.Side.SELL ||\n input.feeAsset === undefined ||\n input.feeAsset === ProtoWrite.FeeAsset.QUOTE,\n \"SELL orders must use the quote fee asset\",\n ),\n );\n}\n\nfunction createScopedOrderIntentInputObjectSchema(scales: SdkScales) {\n const baseEntries = {\n ...AccountScopeInputEntries,\n ...createOrderIntentBaseEntries(scales),\n };\n return v.pipe(\n v.union([\n v.strictObject({\n ...baseEntries,\n qty: DecimalInputStringSchema,\n maxQuoteDebit: v.optional(v.never()),\n }),\n v.strictObject({\n ...baseEntries,\n qty: v.optional(v.never()),\n maxQuoteDebit: DecimalInputStringSchema,\n }),\n ]),\n v.check(\n (input) =>\n input.maxQuoteDebit === undefined ||\n (input.side === ProtoWrite.Side.BUY &&\n (input.execution.case === \"marketIoc\" || input.execution.case === \"limitIoc\")),\n \"maxQuoteDebit is supported only for BUY market IOC and BUY limit IOC orders\",\n ),\n v.check(\n (input) =>\n input.side !== ProtoWrite.Side.SELL ||\n input.feeAsset === undefined ||\n input.feeAsset === ProtoWrite.FeeAsset.QUOTE,\n \"SELL orders must use the quote fee asset\",\n ),\n );\n}\n\nfunction toOrderIntent(input: ParsedOrderIntentInput, scales: SdkScales) {\n const { risk, qty, maxQuoteDebit, ...intent } = input;\n const sizing =\n qty !== undefined\n ? ({\n case: \"baseQtyScaled\",\n value: positiveDecimalInputToScaled(\"qty\", qty, scales.baseQty(intent.symbol)),\n } as const)\n : ({\n case: \"maxQuoteDebitScaled\",\n value: positiveDecimalInputToScaled(\n \"maxQuoteDebit\",\n maxQuoteDebit,\n scales.quoteAmount(intent.symbol),\n ),\n } as const);\n return {\n ...intent,\n sizing,\n feeAsset: intent.feeAsset ?? ProtoWrite.FeeAsset.QUOTE,\n attachedRisk: risk,\n };\n}\n\nexport function createOrderIntentInputSchema(scales: SdkScales) {\n return v.pipe(\n createOrderIntentInputObjectSchema(scales),\n v.transform((input) => toOrderIntent(input, scales)),\n );\n}\n\nexport type OrderIntentInput = v.InferInput<ReturnType<typeof createOrderIntentInputSchema>>;\n\nfunction createOrderExecutionInputSchema(scales: SdkScales) {\n const priceToTicks = (fieldName: string, price: string) =>\n positiveDecimalInputToScaled(fieldName, price, scales.price());\n\n return v.variant(\"type\", [\n v.pipe(\n v.strictObject({\n type: v.literal(\"market_ioc\"),\n maxSlippage: v.optional(MarketMaxSlippageSchema),\n clientRefPrice: v.optional(DecimalInputStringSchema),\n }),\n v.transform(({ maxSlippage, clientRefPrice }) => ({\n case: \"marketIoc\" as const,\n value: create(ProtoWrite.MarketIocSchema, {\n maxSlippage: parseMarketMaxSlippage(scales, maxSlippage),\n clientRefPriceTicks:\n clientRefPrice === undefined\n ? 0n\n : priceToTicks(\"execution.clientRefPrice\", clientRefPrice),\n }),\n })),\n ),\n v.pipe(\n v.strictObject({\n type: v.literal(\"limit_gtc\"),\n price: DecimalInputStringSchema,\n postOnly: v.optional(v.boolean(), false),\n }),\n v.transform(({ price, postOnly }) => ({\n case: \"limitGtc\" as const,\n value: create(ProtoWrite.LimitGtcSchema, {\n priceTicks: priceToTicks(\"execution.price\", price),\n postOnly,\n }),\n })),\n ),\n v.pipe(\n v.strictObject({\n type: v.literal(\"limit_ioc\"),\n price: DecimalInputStringSchema,\n }),\n v.transform(({ price }) => ({\n case: \"limitIoc\" as const,\n value: create(ProtoWrite.LimitIocSchema, {\n priceTicks: priceToTicks(\"execution.price\", price),\n }),\n })),\n ),\n v.pipe(\n v.strictObject({\n type: v.literal(\"limit_fok\"),\n price: DecimalInputStringSchema,\n }),\n v.transform(({ price }) => ({\n case: \"limitFok\" as const,\n value: create(ProtoWrite.LimitFokSchema, {\n priceTicks: priceToTicks(\"execution.price\", price),\n }),\n })),\n ),\n ]);\n}\n\nexport function createNewOrderInputSchema(scales: SdkScales) {\n return v.pipe(\n createScopedOrderIntentInputObjectSchema(scales),\n v.transform(({ account, ...input }) => {\n return {\n subaccountId: accountScopeToSubaccountId(account),\n order: toOrderIntent(input, scales),\n };\n }),\n );\n}\n\nexport type NewOrderInput = v.InferInput<ReturnType<typeof createNewOrderInputSchema>>;\n\nconst CancelOrderScopeInputEntries = {\n symbolId: v.optional(v.number()),\n ...AccountScopeInputEntries,\n};\n\nexport const CancelOrderInputSchema = v.pipe(\n v.union([\n v.strictObject({\n ...CancelOrderScopeInputEntries,\n orderId: v.pipe(\n v.string(),\n v.trim(),\n v.minLength(1),\n v.transform((v) => idToBigInt(v, \"orderId\")),\n ),\n clientOrderId: v.optional(v.never()),\n }),\n v.strictObject({\n ...CancelOrderScopeInputEntries,\n orderId: v.optional(v.never()),\n clientOrderId: v.pipe(v.string(), v.trim(), v.minLength(1)),\n }),\n ]),\n v.transform(({ orderId, clientOrderId, account, ...rest }) => {\n const key =\n orderId !== undefined\n ? ({ case: \"orderId\", value: orderId } as const)\n : ({ case: \"clientOrderId\", value: clientOrderId } as const);\n return {\n ...rest,\n subaccountId: accountScopeToSubaccountId(account),\n key,\n };\n }),\n);\n\nexport type CancelOrderInput = v.InferInput<typeof CancelOrderInputSchema>;\n\nexport const CancelOrderResultSchema = v.pipe(\n v.object({\n status: v.string(),\n orderId: PublicIdSchema,\n tsNs: v.bigint(),\n }),\n v.transform(({ tsNs, ...result }) => ({\n ...result,\n ts: tsNsToMs(tsNs),\n tsNs: tsNs.toString(),\n })),\n);\n\nexport type CancelOrderResult = v.InferOutput<typeof CancelOrderResultSchema>;\n\nexport const CancelAllOrdersInputSchema = v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n symbol: v.optional(v.pipe(v.string(), v.trim())),\n side: v.pipe(\n v.optional(SideSchema),\n v.transform((v) => (v ? OrderSideCodec.inputToProto[v] : undefined)),\n ),\n dryRun: v.optional(v.boolean(), false),\n requestId: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(64))),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\nexport type CancelAllOrdersInput = v.InferInput<typeof CancelAllOrdersInputSchema>;\n\nexport const CancelAllOrdersResponseSchema = v.pipe(\n v.object({\n status: v.string(),\n matchedOrders: v.number(),\n submittedCancels: v.number(),\n failedCancels: v.number(),\n tsNs: v.bigint(),\n }),\n v.transform((o) => ({\n status: o.status,\n matchedOrders: o.matchedOrders,\n submittedCancels: o.submittedCancels,\n failedCancels: o.failedCancels,\n ts: tsNsToMs(o.tsNs),\n })),\n);\n\nexport type CancelAllOrdersResponse = v.InferOutput<typeof CancelAllOrdersResponseSchema>;\n\nexport const GetOrderDetailsInputSchema = v.pipe(\n v.strictObject({\n orderId: v.optional(v.pipe(v.string(), v.trim())),\n clientOrderId: v.optional(v.pipe(v.string(), v.trim())),\n ...AccountScopeInputEntries,\n includeAttachedRisk: v.optional(v.boolean(), true),\n includeAttachedRiskState: v.optional(v.boolean(), true),\n }),\n v.check((input) => {\n const hasOrderId = (input.orderId ?? \"\").length > 0;\n const hasClientOrderId = (input.clientOrderId ?? \"\").length > 0;\n return hasOrderId !== hasClientOrderId;\n }, \"Provide exactly one of orderId or clientOrderId\"),\n v.transform(({ account, orderId, clientOrderId, ...rest }) => {\n const hasOrderId = (orderId ?? \"\").length > 0;\n const key = hasOrderId\n ? ({ case: \"orderId\", value: idToBigInt(orderId ?? \"\", \"orderId\") } as const)\n : ({ case: \"clientOrderId\", value: clientOrderId ?? \"\" } as const);\n return {\n ...rest,\n subaccountId: accountScopeToSubaccountId(account),\n key,\n };\n }),\n);\n\nexport type GetOrderDetailsInput = v.InferInput<typeof GetOrderDetailsInputSchema>;\n\nexport function createCreateOrderResultSchema(scales: SdkScales, symbol: string) {\n return v.pipe(\n v.object({\n orderId: PublicIdSchema,\n clientOrderId: v.string(),\n acceptedAt: OptionalTimestampMsSchema,\n acceptedAtTsNs: v.bigint(),\n resolvedBaseQtyScaled: v.bigint(),\n submittedMaxQuoteDebitScaled: v.optional(v.bigint()),\n takeProfitTriggerId: OptionalPublicIdSchema,\n stopLossTriggerId: OptionalPublicIdSchema,\n trailingStopTriggerId: OptionalPublicIdSchema,\n }),\n v.transform(\n ({\n acceptedAt,\n acceptedAtTsNs,\n resolvedBaseQtyScaled,\n submittedMaxQuoteDebitScaled,\n ...result\n }) => ({\n ...result,\n acceptedAt: acceptedAt ?? tsNsToMs(acceptedAtTsNs),\n acceptedAtNs: acceptedAtTsNs.toString(),\n resolvedBaseQty: scaledToDecimalOutput(\n resolvedBaseQtyScaled,\n scales.baseQty(symbol),\n ),\n ...(submittedMaxQuoteDebitScaled === undefined\n ? {}\n : {\n submittedMaxQuoteDebit: scaledToDecimalOutput(\n submittedMaxQuoteDebitScaled,\n scales.quoteAmount(symbol),\n ),\n }),\n }),\n ),\n );\n}\n\nexport type CreateOrderResult = v.InferOutput<ReturnType<typeof createCreateOrderResultSchema>>;\n\nexport function createPreviewOrderResultSchema(scales: SdkScales, symbol: string) {\n return v.pipe(\n v.object({\n admissible: v.optional(v.boolean()),\n rejection: v.optional(OrderErrorDetailSchema),\n resolvedBaseQtyScaled: v.optional(v.bigint()),\n protectedPriceBoundTicks: v.optional(v.bigint()),\n evaluatedAt: TimestampMsSchema,\n }),\n v.transform(({ resolvedBaseQtyScaled, protectedPriceBoundTicks, ...result }) => ({\n ...result,\n ...(resolvedBaseQtyScaled === undefined\n ? {}\n : {\n resolvedBaseQty: scaledToDecimalOutput(\n resolvedBaseQtyScaled,\n scales.baseQty(symbol),\n ),\n }),\n ...(protectedPriceBoundTicks === undefined\n ? {}\n : {\n protectedPriceBound: scaledToDecimalOutput(\n protectedPriceBoundTicks,\n scales.price(),\n ),\n }),\n })),\n );\n}\n\nexport type PreviewOrderResult = v.InferOutput<ReturnType<typeof createPreviewOrderResultSchema>>;\n"],"mappings":";;;;;;;;;;;;;;;AAwCA,MAAM,oBAAoB,EAAE,SAAS,0BAA0B;AAC/D,MAAM,iBAAiB,EAAE,SAAS,gBAAgB;AAClD,MAAM,gCAAgC,EAAE,SAAS,iCAAiC;AAElF,MAAM,+BAA+B;CACjC,GAAG;CACH,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,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D,qBAAqB;EACrB,mBAAmB;EACnB,uBAAuB;CAC3B,CAAC,GACD,EAAE,WACG,EACG,YACA,gBACA,uBACA,8BACA,GAAG,cACA;EACH,GAAG;EACH,YAAY,cAAc,SAAS,cAAc;EACjD,cAAc,eAAe,SAAS;EACtC,iBAAiB,sBACb,uBACA,OAAO,QAAQ,MAAM,CACzB;EACA,GAAI,iCAAiC,KAAA,IAC/B,CAAC,IACD,EACI,wBAAwB,sBACpB,8BACA,OAAO,YAAY,MAAM,CAC7B,EACJ;CACV,EACJ,CACJ;AACJ;AAIA,SAAgB,+BAA+B,QAAmB,QAAgB;CAC9E,OAAO,EAAE,KACL,EAAE,OAAO;EACL,YAAY,EAAE,SAAS,EAAE,QAAQ,CAAC;EAClC,WAAW,EAAE,SAAS,sBAAsB;EAC5C,uBAAuB,EAAE,SAAS,EAAE,OAAO,CAAC;EAC5C,0BAA0B,EAAE,SAAS,EAAE,OAAO,CAAC;EAC/C,aAAa;CACjB,CAAC,GACD,EAAE,WAAW,EAAE,uBAAuB,0BAA0B,GAAG,cAAc;EAC7E,GAAG;EACH,GAAI,0BAA0B,KAAA,IACxB,CAAC,IACD,EACI,iBAAiB,sBACb,uBACA,OAAO,QAAQ,MAAM,CACzB,EACJ;EACN,GAAI,6BAA6B,KAAA,IAC3B,CAAC,IACD,EACI,qBAAqB,sBACjB,0BACA,OAAO,MAAM,CACjB,EACJ;CACV,EAAE,CACN;AACJ"}
|
|
1
|
+
{"version":3,"file":"orders-input.schemas.js","names":["ProtoWrite.MarketIocSchema","ProtoWrite.LimitGtcSchema","ProtoWrite.LimitIocSchema","ProtoWrite.LimitFokSchema"],"sources":["../../../src/services/orders/orders-input.schemas.ts"],"sourcesContent":["import * as ProtoWrite from \"../../gen/orders/v1/orders_pb.js\";\nimport { create } from \"@bufbuild/protobuf\";\nimport * as v from \"valibot\";\nimport { SideSchema, SymbolIdInputSchema } from \"../shared.js\";\nimport { tsNsToMs } from \"../../utils/time.js\";\nimport { idToBigInt } from \"../../utils/base58-id.js\";\nimport {\n OptionalPublicIdSchema,\n OptionalTimestampMsSchema,\n PublicIdSchema,\n TimestampMsSchema,\n optionalIdInputSchema,\n optionalUint64DecimalFilterSchema,\n} from \"../../shared/schemas.js\";\nimport {\n positiveDecimalInputToScaled,\n scaledToDecimalOutput,\n type SdkScales,\n} from \"../../shared/decimal-surface.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport {\n FEE_ASSET_VALUES,\n ORDER_STATUS_FILTER_VALUES,\n OrderSideCodec,\n OrderStatusFilterCodec,\n SELF_TRADE_PREVENTION_MODE_VALUES,\n FeeAssetCodec,\n SelfTradePreventionModeCodec,\n} from \"./orders.codecs.js\";\nimport {\n MarketMaxSlippageSchema,\n createRiskPolicyInputSchema,\n parseMarketMaxSlippage,\n} from \"./orders-risk.schemas.js\";\nimport { OptionalClientOrderIdInputSchema } from \"./orders-identifiers.schemas.js\";\nimport { OrderErrorDetailSchema } from \"./order-errors.schemas.js\";\n\nconst OrderStatusSchema = v.picklist(ORDER_STATUS_FILTER_VALUES);\nconst FeeAssetSchema = v.picklist(FEE_ASSET_VALUES);\nconst SelfTradePreventionModeSchema = v.picklist(SELF_TRADE_PREVENTION_MODE_VALUES);\n\nconst BaseOrdersFilterInputEntries = {\n ...AccountScopeInputEntries,\n symbolId: v.optional(v.array(v.number())),\n triggerId: optionalIdInputSchema(\"triggerId\"),\n side: v.pipe(\n v.optional(SideSchema),\n v.transform((v) => (v ? OrderSideCodec.inputToProto[v] : undefined)),\n ),\n limit: v.optional(v.number()),\n pageToken: v.optional(v.pipe(v.string(), v.trim())),\n};\n\nexport const BaseOrdersFilterInputSchema = v.pipe(\n v.strictObject(BaseOrdersFilterInputEntries),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\nexport const OpenOrdersInputSchema = v.pipe(\n v.strictObject({\n ...BaseOrdersFilterInputEntries,\n\n includeAttachedRisk: v.optional(v.boolean(), true),\n includeAttachedRiskState: v.optional(v.boolean(), false),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\nexport type OpenOrdersInput = v.InferInput<typeof OpenOrdersInputSchema>;\n\nexport const OrderHistoryInputSchema = v.pipe(\n v.strictObject({\n ...BaseOrdersFilterInputEntries,\n includeAttachedRisk: v.optional(v.boolean(), true),\n includeAttachedRiskState: v.optional(v.boolean(), false),\n status: v.pipe(\n v.optional(OrderStatusSchema),\n v.transform((v) => (v ? OrderStatusFilterCodec.inputToProto[v] : undefined)),\n ),\n startTsNs: optionalUint64DecimalFilterSchema(\"startTsNs\"),\n endTsNs: optionalUint64DecimalFilterSchema(\"endTsNs\"),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\nexport type OrderHistoryInput = v.InferInput<typeof OrderHistoryInputSchema>;\n\nconst DecimalInputStringSchema = v.pipe(v.string(), v.trim(), v.minLength(1));\n\nfunction createOrderIntentBaseEntries(scales: SdkScales) {\n return {\n symbolId: SymbolIdInputSchema,\n side: v.pipe(\n SideSchema,\n v.transform((v) => OrderSideCodec.inputToProto[v]),\n ),\n execution: createOrderExecutionInputSchema(scales),\n clientOrderId: OptionalClientOrderIdInputSchema,\n feeAsset: v.pipe(\n v.optional(FeeAssetSchema),\n v.transform((v) => (v ? FeeAssetCodec.inputToProto[v] : undefined)),\n ),\n selfTradePreventionMode: v.pipe(\n v.optional(SelfTradePreventionModeSchema),\n v.transform((v) => (v ? SelfTradePreventionModeCodec.inputToProto[v] : undefined)),\n ),\n risk: createRiskPolicyInputSchema(scales),\n };\n}\n\ntype ParsedOrderIntentInput = v.InferOutput<ReturnType<typeof createOrderIntentInputObjectSchema>>;\n\nfunction createOrderIntentInputObjectSchema(scales: SdkScales) {\n const baseEntries = createOrderIntentBaseEntries(scales);\n return v.pipe(\n v.union([\n v.strictObject({\n ...baseEntries,\n qty: DecimalInputStringSchema,\n maxQuoteDebit: v.optional(v.never()),\n }),\n v.strictObject({\n ...baseEntries,\n qty: v.optional(v.never()),\n maxQuoteDebit: DecimalInputStringSchema,\n }),\n ]),\n v.check(\n (input) =>\n input.maxQuoteDebit === undefined ||\n (input.side === ProtoWrite.Side.BUY &&\n (input.execution.case === \"marketIoc\" || input.execution.case === \"limitIoc\")),\n \"maxQuoteDebit is supported only for BUY market IOC and BUY limit IOC orders\",\n ),\n v.check(\n (input) =>\n input.side !== ProtoWrite.Side.SELL ||\n input.feeAsset === undefined ||\n input.feeAsset === ProtoWrite.FeeAsset.QUOTE,\n \"SELL orders must use the quote fee asset\",\n ),\n );\n}\n\nfunction createScopedOrderIntentInputObjectSchema(scales: SdkScales) {\n const baseEntries = {\n ...AccountScopeInputEntries,\n ...createOrderIntentBaseEntries(scales),\n };\n return v.pipe(\n v.union([\n v.strictObject({\n ...baseEntries,\n qty: DecimalInputStringSchema,\n maxQuoteDebit: v.optional(v.never()),\n }),\n v.strictObject({\n ...baseEntries,\n qty: v.optional(v.never()),\n maxQuoteDebit: DecimalInputStringSchema,\n }),\n ]),\n v.check(\n (input) =>\n input.maxQuoteDebit === undefined ||\n (input.side === ProtoWrite.Side.BUY &&\n (input.execution.case === \"marketIoc\" || input.execution.case === \"limitIoc\")),\n \"maxQuoteDebit is supported only for BUY market IOC and BUY limit IOC orders\",\n ),\n v.check(\n (input) =>\n input.side !== ProtoWrite.Side.SELL ||\n input.feeAsset === undefined ||\n input.feeAsset === ProtoWrite.FeeAsset.QUOTE,\n \"SELL orders must use the quote fee asset\",\n ),\n );\n}\n\nfunction toOrderIntent(input: ParsedOrderIntentInput, scales: SdkScales) {\n const { risk, qty, maxQuoteDebit, ...intent } = input;\n const sizing =\n qty !== undefined\n ? ({\n case: \"baseQtyScaled\",\n value: positiveDecimalInputToScaled(\"qty\", qty, scales.baseQty(intent.symbolId)),\n } as const)\n : ({\n case: \"maxQuoteDebitScaled\",\n value: positiveDecimalInputToScaled(\n \"maxQuoteDebit\",\n maxQuoteDebit,\n scales.quoteAmount(intent.symbolId),\n ),\n } as const);\n return {\n ...intent,\n sizing,\n feeAsset: intent.feeAsset ?? ProtoWrite.FeeAsset.QUOTE,\n attachedRisk: risk,\n };\n}\n\nexport function createOrderIntentInputSchema(scales: SdkScales) {\n return v.pipe(\n createOrderIntentInputObjectSchema(scales),\n v.transform((input) => toOrderIntent(input, scales)),\n );\n}\n\nexport type OrderIntentInput = v.InferInput<ReturnType<typeof createOrderIntentInputSchema>>;\n\nfunction createOrderExecutionInputSchema(scales: SdkScales) {\n const priceToTicks = (fieldName: string, price: string) =>\n positiveDecimalInputToScaled(fieldName, price, scales.price());\n\n return v.variant(\"type\", [\n v.pipe(\n v.strictObject({\n type: v.literal(\"market_ioc\"),\n maxSlippage: v.optional(MarketMaxSlippageSchema),\n clientRefPrice: v.optional(DecimalInputStringSchema),\n }),\n v.transform(({ maxSlippage, clientRefPrice }) => ({\n case: \"marketIoc\" as const,\n value: create(ProtoWrite.MarketIocSchema, {\n maxSlippage: parseMarketMaxSlippage(scales, maxSlippage),\n clientRefPriceTicks:\n clientRefPrice === undefined\n ? 0n\n : priceToTicks(\"execution.clientRefPrice\", clientRefPrice),\n }),\n })),\n ),\n v.pipe(\n v.strictObject({\n type: v.literal(\"limit_gtc\"),\n price: DecimalInputStringSchema,\n postOnly: v.optional(v.boolean(), false),\n }),\n v.transform(({ price, postOnly }) => ({\n case: \"limitGtc\" as const,\n value: create(ProtoWrite.LimitGtcSchema, {\n priceTicks: priceToTicks(\"execution.price\", price),\n postOnly,\n }),\n })),\n ),\n v.pipe(\n v.strictObject({\n type: v.literal(\"limit_ioc\"),\n price: DecimalInputStringSchema,\n }),\n v.transform(({ price }) => ({\n case: \"limitIoc\" as const,\n value: create(ProtoWrite.LimitIocSchema, {\n priceTicks: priceToTicks(\"execution.price\", price),\n }),\n })),\n ),\n v.pipe(\n v.strictObject({\n type: v.literal(\"limit_fok\"),\n price: DecimalInputStringSchema,\n }),\n v.transform(({ price }) => ({\n case: \"limitFok\" as const,\n value: create(ProtoWrite.LimitFokSchema, {\n priceTicks: priceToTicks(\"execution.price\", price),\n }),\n })),\n ),\n ]);\n}\n\nexport function createNewOrderInputSchema(scales: SdkScales) {\n return v.pipe(\n createScopedOrderIntentInputObjectSchema(scales),\n v.transform(({ account, ...input }) => {\n return {\n subaccountId: accountScopeToSubaccountId(account),\n order: toOrderIntent(input, scales),\n };\n }),\n );\n}\n\nexport type NewOrderInput = v.InferInput<ReturnType<typeof createNewOrderInputSchema>>;\n\nconst CancelOrderScopeInputEntries = {\n symbolId: v.optional(v.number()),\n ...AccountScopeInputEntries,\n};\n\nexport const CancelOrderInputSchema = v.pipe(\n v.union([\n v.strictObject({\n ...CancelOrderScopeInputEntries,\n orderId: v.pipe(\n v.string(),\n v.trim(),\n v.minLength(1),\n v.transform((v) => idToBigInt(v, \"orderId\")),\n ),\n clientOrderId: v.optional(v.never()),\n }),\n v.strictObject({\n ...CancelOrderScopeInputEntries,\n orderId: v.optional(v.never()),\n clientOrderId: v.pipe(v.string(), v.trim(), v.minLength(1)),\n }),\n ]),\n v.transform(({ orderId, clientOrderId, account, ...rest }) => {\n const key =\n orderId !== undefined\n ? ({ case: \"orderId\", value: orderId } as const)\n : ({ case: \"clientOrderId\", value: clientOrderId } as const);\n return {\n ...rest,\n subaccountId: accountScopeToSubaccountId(account),\n key,\n };\n }),\n);\n\nexport type CancelOrderInput = v.InferInput<typeof CancelOrderInputSchema>;\n\nexport const CancelOrderResultSchema = v.pipe(\n v.object({\n status: v.string(),\n orderId: PublicIdSchema,\n tsNs: v.bigint(),\n }),\n v.transform(({ tsNs, ...result }) => ({\n ...result,\n ts: tsNsToMs(tsNs),\n tsNs: tsNs.toString(),\n })),\n);\n\nexport type CancelOrderResult = v.InferOutput<typeof CancelOrderResultSchema>;\n\nexport const CancelAllOrdersInputSchema = v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n symbolId: v.optional(SymbolIdInputSchema),\n side: v.pipe(\n v.optional(SideSchema),\n v.transform((v) => (v ? OrderSideCodec.inputToProto[v] : undefined)),\n ),\n dryRun: v.optional(v.boolean(), false),\n requestId: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(64))),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\nexport type CancelAllOrdersInput = v.InferInput<typeof CancelAllOrdersInputSchema>;\n\nexport const CancelAllOrdersResponseSchema = v.pipe(\n v.object({\n status: v.string(),\n matchedOrders: v.number(),\n submittedCancels: v.number(),\n failedCancels: v.number(),\n tsNs: v.bigint(),\n }),\n v.transform((o) => ({\n status: o.status,\n matchedOrders: o.matchedOrders,\n submittedCancels: o.submittedCancels,\n failedCancels: o.failedCancels,\n ts: tsNsToMs(o.tsNs),\n })),\n);\n\nexport type CancelAllOrdersResponse = v.InferOutput<typeof CancelAllOrdersResponseSchema>;\n\nexport const GetOrderDetailsInputSchema = v.pipe(\n v.strictObject({\n orderId: v.optional(v.pipe(v.string(), v.trim())),\n clientOrderId: v.optional(v.pipe(v.string(), v.trim())),\n ...AccountScopeInputEntries,\n includeAttachedRisk: v.optional(v.boolean(), true),\n includeAttachedRiskState: v.optional(v.boolean(), true),\n }),\n v.check((input) => {\n const hasOrderId = (input.orderId ?? \"\").length > 0;\n const hasClientOrderId = (input.clientOrderId ?? \"\").length > 0;\n return hasOrderId !== hasClientOrderId;\n }, \"Provide exactly one of orderId or clientOrderId\"),\n v.transform(({ account, orderId, clientOrderId, ...rest }) => {\n const hasOrderId = (orderId ?? \"\").length > 0;\n const key = hasOrderId\n ? ({ case: \"orderId\", value: idToBigInt(orderId ?? \"\", \"orderId\") } as const)\n : ({ case: \"clientOrderId\", value: clientOrderId ?? \"\" } as const);\n return {\n ...rest,\n subaccountId: accountScopeToSubaccountId(account),\n key,\n };\n }),\n);\n\nexport type GetOrderDetailsInput = v.InferInput<typeof GetOrderDetailsInputSchema>;\n\nexport function createCreateOrderResultSchema(scales: SdkScales, symbolId: number) {\n return v.pipe(\n v.object({\n orderId: PublicIdSchema,\n clientOrderId: v.string(),\n acceptedAt: OptionalTimestampMsSchema,\n acceptedAtTsNs: v.bigint(),\n resolvedBaseQtyScaled: v.bigint(),\n submittedMaxQuoteDebitScaled: v.optional(v.bigint()),\n takeProfitTriggerId: OptionalPublicIdSchema,\n stopLossTriggerId: OptionalPublicIdSchema,\n trailingStopTriggerId: OptionalPublicIdSchema,\n }),\n v.transform(\n ({\n acceptedAt,\n acceptedAtTsNs,\n resolvedBaseQtyScaled,\n submittedMaxQuoteDebitScaled,\n ...result\n }) => ({\n ...result,\n acceptedAt: acceptedAt ?? tsNsToMs(acceptedAtTsNs),\n acceptedAtNs: acceptedAtTsNs.toString(),\n resolvedBaseQty: scaledToDecimalOutput(\n resolvedBaseQtyScaled,\n scales.baseQty(symbolId),\n ),\n ...(submittedMaxQuoteDebitScaled === undefined\n ? {}\n : {\n submittedMaxQuoteDebit: scaledToDecimalOutput(\n submittedMaxQuoteDebitScaled,\n scales.quoteAmount(symbolId),\n ),\n }),\n }),\n ),\n );\n}\n\nexport type CreateOrderResult = v.InferOutput<ReturnType<typeof createCreateOrderResultSchema>>;\n\nexport function createPreviewOrderResultSchema(scales: SdkScales, symbolId: number) {\n return v.pipe(\n v.object({\n admissible: v.optional(v.boolean()),\n rejection: v.optional(OrderErrorDetailSchema),\n resolvedBaseQtyScaled: v.optional(v.bigint()),\n protectedPriceBoundTicks: v.optional(v.bigint()),\n evaluatedAt: TimestampMsSchema,\n }),\n v.transform(({ resolvedBaseQtyScaled, protectedPriceBoundTicks, ...result }) => ({\n ...result,\n ...(resolvedBaseQtyScaled === undefined\n ? {}\n : {\n resolvedBaseQty: scaledToDecimalOutput(\n resolvedBaseQtyScaled,\n scales.baseQty(symbolId),\n ),\n }),\n ...(protectedPriceBoundTicks === undefined\n ? {}\n : {\n protectedPriceBound: scaledToDecimalOutput(\n protectedPriceBoundTicks,\n scales.price(),\n ),\n }),\n })),\n );\n}\n\nexport type PreviewOrderResult = v.InferOutput<ReturnType<typeof createPreviewOrderResultSchema>>;\n"],"mappings":";;;;;;;;;;;;;;;AAwCA,MAAM,oBAAoB,EAAE,SAAS,0BAA0B;AAC/D,MAAM,iBAAiB,EAAE,SAAS,gBAAgB;AAClD,MAAM,gCAAgC,EAAE,SAAS,iCAAiC;AAElF,MAAM,+BAA+B;CACjC,GAAG;CACH,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;CACxC,WAAW,sBAAsB,WAAW;CAC5C,MAAM,EAAE,KACJ,EAAE,SAAS,UAAU,GACrB,EAAE,WAAW,MAAO,IAAI,eAAe,aAAa,KAAK,KAAA,CAAU,CACvE;CACA,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC;CAC5B,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,CAAC,CAAC;AACtD;AAE2C,EAAE,KACzC,EAAE,aAAa,4BAA4B,GAC3C,EAAE,WAAW,EAAE,SAAS,GAAG,aAAa;CACpC,GAAG;CACH,cAAc,2BAA2B,OAAO;AACpD,EAAE,CACN;AAEA,MAAa,wBAAwB,EAAE,KACnC,EAAE,aAAa;CACX,GAAG;CAEH,qBAAqB,EAAE,SAAS,EAAE,QAAQ,GAAG,IAAI;CACjD,0BAA0B,EAAE,SAAS,EAAE,QAAQ,GAAG,KAAK;AAC3D,CAAC,GACD,EAAE,WAAW,EAAE,SAAS,GAAG,aAAa;CACpC,GAAG;CACH,cAAc,2BAA2B,OAAO;AACpD,EAAE,CACN;AAIA,MAAa,0BAA0B,EAAE,KACrC,EAAE,aAAa;CACX,GAAG;CACH,qBAAqB,EAAE,SAAS,EAAE,QAAQ,GAAG,IAAI;CACjD,0BAA0B,EAAE,SAAS,EAAE,QAAQ,GAAG,KAAK;CACvD,QAAQ,EAAE,KACN,EAAE,SAAS,iBAAiB,GAC5B,EAAE,WA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gB,8BAA8B,QAAmB,UAAkB;CAC/E,OAAO,EAAE,KACL,EAAE,OAAO;EACL,SAAS;EACT,eAAe,EAAE,OAAO;EACxB,YAAY;EACZ,gBAAgB,EAAE,OAAO;EACzB,uBAAuB,EAAE,OAAO;EAChC,8BAA8B,EAAE,SAAS,EAAE,OAAO,CAAC;EACnD,qBAAqB;EACrB,mBAAmB;EACnB,uBAAuB;CAC3B,CAAC,GACD,EAAE,WACG,EACG,YACA,gBACA,uBACA,8BACA,GAAG,cACA;EACH,GAAG;EACH,YAAY,cAAc,SAAS,cAAc;EACjD,cAAc,eAAe,SAAS;EACtC,iBAAiB,sBACb,uBACA,OAAO,QAAQ,QAAQ,CAC3B;EACA,GAAI,iCAAiC,KAAA,IAC/B,CAAC,IACD,EACI,wBAAwB,sBACpB,8BACA,OAAO,YAAY,QAAQ,CAC/B,EACJ;CACV,EACJ,CACJ;AACJ;AAIA,SAAgB,+BAA+B,QAAmB,UAAkB;CAChF,OAAO,EAAE,KACL,EAAE,OAAO;EACL,YAAY,EAAE,SAAS,EAAE,QAAQ,CAAC;EAClC,WAAW,EAAE,SAAS,sBAAsB;EAC5C,uBAAuB,EAAE,SAAS,EAAE,OAAO,CAAC;EAC5C,0BAA0B,EAAE,SAAS,EAAE,OAAO,CAAC;EAC/C,aAAa;CACjB,CAAC,GACD,EAAE,WAAW,EAAE,uBAAuB,0BAA0B,GAAG,cAAc;EAC7E,GAAG;EACH,GAAI,0BAA0B,KAAA,IACxB,CAAC,IACD,EACI,iBAAiB,sBACb,uBACA,OAAO,QAAQ,QAAQ,CAC3B,EACJ;EACN,GAAI,6BAA6B,KAAA,IAC3B,CAAC,IACD,EACI,qBAAqB,sBACjB,0BACA,OAAO,MAAM,CACjB,EACJ;CACV,EAAE,CACN;AACJ"}
|
|
@@ -8,7 +8,7 @@ declare function createModifyOrderInputSchema(scales: SdkScales): v.SchemaWithPi
|
|
|
8
8
|
readonly subaccountId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
|
|
9
9
|
}, undefined>], undefined>, undefined>;
|
|
10
10
|
}, undefined>, v.IntersectSchema<[v.ObjectSchema<{
|
|
11
|
-
readonly
|
|
11
|
+
readonly symbolId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>;
|
|
12
12
|
readonly behavior: v.OptionalSchema<v.PicklistSchema<readonly ["AMEND_OR_REPLACE", "AMEND_ONLY", "REPLACE_ONLY"], undefined>, undefined>;
|
|
13
13
|
readonly newClientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, "clientOrderId has an invalid format">]>, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
14
14
|
}, undefined>, v.UnionSchema<[v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
@@ -1467,7 +1467,7 @@ declare function createModifyOrderInputSchema(scales: SdkScales): v.SchemaWithPi
|
|
|
1467
1467
|
subaccountId: string;
|
|
1468
1468
|
} | undefined;
|
|
1469
1469
|
} & ({
|
|
1470
|
-
|
|
1470
|
+
symbolId: number;
|
|
1471
1471
|
behavior?: "AMEND_OR_REPLACE" | "AMEND_ONLY" | "REPLACE_ONLY" | undefined;
|
|
1472
1472
|
newClientOrderId?: string | undefined;
|
|
1473
1473
|
} & (({
|
|
@@ -1754,6 +1754,7 @@ declare function createModifyOrderInputSchema(scales: SdkScales): v.SchemaWithPi
|
|
|
1754
1754
|
} | undefined;
|
|
1755
1755
|
behavior: ModifyBehavior;
|
|
1756
1756
|
newClientOrderId: string;
|
|
1757
|
+
symbolId: number;
|
|
1757
1758
|
subaccountId: bigint | undefined;
|
|
1758
1759
|
requestId: string | undefined;
|
|
1759
1760
|
}>]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orders-modify.schemas.d.ts","names":[],"sources":["../../../src/services/orders/orders-modify.schemas.ts"],"mappings":";;;;iBA0LgB,6BAA6B,QAAQ,YAAS,EAAA,yBAAA,EAAA,iBAAA,EAAA
|
|
1
|
+
{"version":3,"file":"orders-modify.schemas.d.ts","names":[],"sources":["../../../src/services/orders/orders-modify.schemas.ts"],"mappings":";;;;iBA0LgB,6BAA6B,QAAQ,YAAS,EAAA,yBAAA,EAAA,iBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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B,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4BxB,oBAAoB,EAAE,mBAAmB"}
|
|
@@ -3,6 +3,7 @@ import { requiredEnumLabel } from "../../shared/proto-enum-codec.js";
|
|
|
3
3
|
import { idToBigInt } from "../../utils/base58-id.js";
|
|
4
4
|
import { tsNsToMs } from "../../utils/time.js";
|
|
5
5
|
import { OptionalPublicIdSchema, PublicIdSchema } from "../../shared/schemas.js";
|
|
6
|
+
import { PROTOBUF_UINT32_MAX } from "../../shared/wire-bounds.js";
|
|
6
7
|
import { AccountScopeInputEntries, accountScopeToSubaccountId } from "../../shared/account-scope.js";
|
|
7
8
|
import { positiveDecimalInputToScaled } from "../../shared/decimal-surface.js";
|
|
8
9
|
import { MODIFY_BEHAVIOR_VALUES, ModifyActionCodec, ModifyBehaviorCodec } from "./orders.codecs.js";
|
|
@@ -15,7 +16,7 @@ const ModifyBehaviorInputSchema = v.picklist(MODIFY_BEHAVIOR_VALUES);
|
|
|
15
16
|
const ModifyOrderIdInputSchema = v.pipe(v.string(), v.trim(), v.minLength(1), v.transform((value) => idToBigInt(value, "orderId")), v.check((value) => value > 0n, "orderId must be greater than zero"));
|
|
16
17
|
const DecimalInputStringSchema = v.pipe(v.string(), v.trim(), v.minLength(1));
|
|
17
18
|
const ModifyOrderItemBaseInputSchema = v.object({
|
|
18
|
-
|
|
19
|
+
symbolId: v.pipe(v.number(), v.integer(), v.gtValue(0), v.maxValue(PROTOBUF_UINT32_MAX)),
|
|
19
20
|
behavior: v.optional(ModifyBehaviorInputSchema),
|
|
20
21
|
newClientOrderId: v.optional(ClientOrderIdInputSchema)
|
|
21
22
|
});
|
|
@@ -103,10 +104,11 @@ function toModifyOrderItem(input, scales, defaultBehavior) {
|
|
|
103
104
|
return {
|
|
104
105
|
key: input.key,
|
|
105
106
|
newPriceTicks: input.newPrice === void 0 ? void 0 : positiveDecimalInputToScaled("newPrice", input.newPrice, scales.price()),
|
|
106
|
-
newQtyScaled: input.newQty === void 0 ? void 0 : positiveDecimalInputToScaled("newQty", input.newQty, scales.baseQty(input.
|
|
107
|
+
newQtyScaled: input.newQty === void 0 ? void 0 : positiveDecimalInputToScaled("newQty", input.newQty, scales.baseQty(input.symbolId)),
|
|
107
108
|
newAttachedRisk: input.clearRisk === true ? create(RiskPolicySchema) : input.risk,
|
|
108
109
|
behavior: input.behavior ? ModifyBehaviorCodec.inputToProto[input.behavior] : defaultBehavior,
|
|
109
|
-
newClientOrderId: input.newClientOrderId ?? ""
|
|
110
|
+
newClientOrderId: input.newClientOrderId ?? "",
|
|
111
|
+
symbolId: input.symbolId
|
|
110
112
|
};
|
|
111
113
|
}
|
|
112
114
|
function createModifyOrderInputSchema(scales) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orders-modify.schemas.js","names":["ProtoWrite.RiskPolicySchema","ProtoWrite.ModifyActionTaken"],"sources":["../../../src/services/orders/orders-modify.schemas.ts"],"sourcesContent":["import * as ProtoWrite from \"../../gen/orders/v1/orders_pb.js\";\nimport { create } from \"@bufbuild/protobuf\";\nimport * as v from \"valibot\";\nimport { tsNsToMs } from \"../../utils/time.js\";\nimport { idToBigInt } from \"../../utils/base58-id.js\";\nimport { OptionalPublicIdSchema, PublicIdSchema } from \"../../shared/schemas.js\";\nimport { positiveDecimalInputToScaled, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport { requiredEnumLabel } from \"../../shared/proto-enum-codec.js\";\nimport { MODIFY_BEHAVIOR_VALUES, ModifyActionCodec, ModifyBehaviorCodec } from \"./orders.codecs.js\";\nimport { createRequiredRiskPolicyInputSchema } from \"./orders-risk.schemas.js\";\nimport {\n ClientOrderIdInputSchema,\n OrderRequestIdInputSchema,\n} from \"./orders-identifiers.schemas.js\";\n\nconst ModifyBehaviorInputSchema = v.picklist(MODIFY_BEHAVIOR_VALUES);\n\nconst ModifyOrderIdInputSchema = v.pipe(\n v.string(),\n v.trim(),\n v.minLength(1),\n v.transform((value) => idToBigInt(value, \"orderId\")),\n v.check((value) => value > 0n, \"orderId must be greater than zero\"),\n);\n\nconst DecimalInputStringSchema = v.pipe(v.string(), v.trim(), v.minLength(1));\n\nconst ModifyOrderItemBaseInputSchema = v.object({\n // Pair symbol of the order being modified; required to resolve the\n // base-quantity wire scale for newQty.\n symbol: v.pipe(v.string(), v.trim(), v.minLength(1)),\n behavior: v.optional(ModifyBehaviorInputSchema),\n newClientOrderId: v.optional(ClientOrderIdInputSchema),\n});\n\nconst ModifyOrderRequestInputSchema = v.object({\n ...AccountScopeInputEntries,\n requestId: v.optional(OrderRequestIdInputSchema),\n});\n\nconst ModifyOrderKeyInputSchema = v.union([\n v.pipe(\n v.object({\n orderId: ModifyOrderIdInputSchema,\n clientOrderId: v.optional(v.never()),\n }),\n v.transform(({ orderId }) => ({\n key: { case: \"orderId\" as const, value: orderId },\n })),\n ),\n v.pipe(\n v.object({\n orderId: v.optional(v.never()),\n clientOrderId: ClientOrderIdInputSchema,\n }),\n v.transform(({ clientOrderId }) => ({\n key: { case: \"clientOrderId\" as const, value: clientOrderId },\n })),\n ),\n]);\n\nconst ModifyOrderPricePatchInputSchema = v.object({\n newPrice: DecimalInputStringSchema,\n newQty: v.optional(DecimalInputStringSchema),\n});\n\nconst ModifyOrderQtyPatchInputSchema = v.object({\n newPrice: v.optional(DecimalInputStringSchema),\n newQty: DecimalInputStringSchema,\n});\n\nconst ModifyOrderNoPriceQtyPatchInputSchema = v.object({\n newPrice: v.optional(v.never()),\n newQty: v.optional(v.never()),\n});\n\nconst ModifyOrderClearRiskPatchInputSchema = v.object({\n risk: v.optional(v.never()),\n clearRisk: v.literal(true),\n});\n\nconst ModifyOrderNoRiskPatchInputSchema = v.object({\n risk: v.optional(v.never()),\n clearRisk: v.optional(v.literal(false)),\n});\n\nconst MODIFY_ORDER_ITEM_INPUT_KEYS = new Set<string>([\n ...Object.keys(ModifyOrderItemBaseInputSchema.entries),\n \"orderId\",\n \"clientOrderId\",\n \"newPrice\",\n \"newQty\",\n \"risk\",\n \"clearRisk\",\n]);\n\nconst MODIFY_ORDER_INPUT_KEYS = new Set<string>([\n ...MODIFY_ORDER_ITEM_INPUT_KEYS,\n ...Object.keys(ModifyOrderRequestInputSchema.entries),\n]);\n\n/**\n * The modify-order input is a v.intersect of partial object schemas, so its\n * members cannot use v.strictObject (each member would reject the other\n * members' keys). Unknown keys are rejected up front instead, matching the\n * strict-input behavior of every other mutating method.\n */\nexport function assertKnownModifyOrderInputKeys(input: object): void {\n for (const key of Object.keys(input)) {\n if (!MODIFY_ORDER_INPUT_KEYS.has(key)) {\n throw new Error(`Unknown key \"${key}\" in modify order input.`);\n }\n }\n}\n\nfunction createModifyOrderPatchInputSchema(scales: SdkScales) {\n const ModifyOrderSetRiskPatchInputSchema = v.object({\n risk: createRequiredRiskPolicyInputSchema(scales),\n clearRisk: v.optional(v.literal(false)),\n });\n\n const ModifyOrderAnyRiskPatchInputSchema = v.union([\n ModifyOrderSetRiskPatchInputSchema,\n ModifyOrderClearRiskPatchInputSchema,\n ModifyOrderNoRiskPatchInputSchema,\n ]);\n\n const ModifyOrderRequiredRiskPatchInputSchema = v.union([\n ModifyOrderSetRiskPatchInputSchema,\n ModifyOrderClearRiskPatchInputSchema,\n ]);\n\n return v.union([\n v.intersect([ModifyOrderPricePatchInputSchema, ModifyOrderAnyRiskPatchInputSchema]),\n v.intersect([ModifyOrderQtyPatchInputSchema, ModifyOrderAnyRiskPatchInputSchema]),\n v.intersect([\n ModifyOrderNoPriceQtyPatchInputSchema,\n ModifyOrderRequiredRiskPatchInputSchema,\n ]),\n ]);\n}\n\nfunction createModifyOrderItemObjectInputSchema(scales: SdkScales) {\n return v.intersect([\n ModifyOrderItemBaseInputSchema,\n ModifyOrderKeyInputSchema,\n createModifyOrderPatchInputSchema(scales),\n ]);\n}\n\ntype ParsedModifyOrderItemInput = v.InferOutput<\n ReturnType<typeof createModifyOrderItemObjectInputSchema>\n>;\n\nfunction toModifyOrderItem(\n input: ParsedModifyOrderItemInput,\n scales: SdkScales,\n defaultBehavior: ProtoWrite.ModifyBehavior,\n) {\n return {\n key: input.key,\n newPriceTicks:\n input.newPrice === undefined\n ? undefined\n : positiveDecimalInputToScaled(\"newPrice\", input.newPrice, scales.price()),\n newQtyScaled:\n input.newQty === undefined\n ? undefined\n : positiveDecimalInputToScaled(\n \"newQty\",\n input.newQty,\n scales.baseQty(input.symbol),\n ),\n newAttachedRisk:\n input.clearRisk === true ? create(ProtoWrite.RiskPolicySchema) : input.risk,\n behavior: input.behavior\n ? ModifyBehaviorCodec.inputToProto[input.behavior]\n : defaultBehavior,\n newClientOrderId: input.newClientOrderId ?? \"\",\n };\n}\n\nexport function createModifyOrderInputSchema(scales: SdkScales) {\n return v.pipe(\n v.intersect([\n ModifyOrderRequestInputSchema,\n createModifyOrderItemObjectInputSchema(scales),\n ]),\n v.transform((input) => ({\n subaccountId: accountScopeToSubaccountId(input.account),\n requestId: input.requestId,\n ...toModifyOrderItem(input, scales, ProtoWrite.ModifyBehavior.AMEND_OR_REPLACE),\n })),\n );\n}\n\nexport type ModifyOrderInput = v.InferInput<ReturnType<typeof createModifyOrderInputSchema>>;\n\nexport const ModifyOrderResultSchema = v.pipe(\n v.object({\n actionTaken: v.pipe(\n v.enum(ProtoWrite.ModifyActionTaken),\n v.transform((v) =>\n requiredEnumLabel(\n ModifyActionCodec.protoToOutput,\n v,\n \"ModifyOrderResultSchema\",\n \"action taken\",\n ),\n ),\n ),\n oldOrderId: PublicIdSchema,\n finalOrderId: PublicIdSchema,\n code: v.string(),\n takeProfitTriggerId: OptionalPublicIdSchema,\n stopLossTriggerId: OptionalPublicIdSchema,\n trailingStopTriggerId: OptionalPublicIdSchema,\n tsNs: v.bigint(),\n }),\n v.transform(({ tsNs, ...result }) => ({\n ...result,\n ts: tsNsToMs(tsNs),\n tsNs: tsNs.toString(),\n })),\n);\n\nexport type ModifyOrderResult =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L;AAEA,SAAS,uCAAuC,QAAmB;CAC/D,OAAO,EAAE,UAAU;EACf;EACA;EACA,kCAAkC,MAAM;CAC5C,CAAC;AACL;AAMA,SAAS,kBACL,OACA,QACA,iBACF;CACE,OAAO;EACH,KAAK,MAAM;EACX,eACI,MAAM,aAAa,KAAA,IACb,KAAA,IACA,6BAA6B,YAAY,MAAM,UAAU,OAAO,MAAM,CAAC;EACjF,cACI,MAAM,WAAW,KAAA,IACX,KAAA,IACA,6BACI,UACA,MAAM,QACN,OAAO,QAAQ,MAAM,MAAM,CAC/B;EACV,iBACI,MAAM,cAAc,OAAO,OAAOA,gBAA2B,IAAI,MAAM;EAC3E,UAAU,MAAM,WACV,oBAAoB,aAAa,MAAM,YACvC;EACN,kBAAkB,MAAM,oBAAoB;CAChD;AACJ;AAEA,SAAgB,6BAA6B,QAAmB;CAC5D,OAAO,EAAE,KACL,EAAE,UAAU,CACR,+BACA,uCAAuC,MAAM,CACjD,CAAC,GACD,EAAE,WAAW,WAAW;EACpB,cAAc,2BAA2B,MAAM,OAAO;EACtD,WAAW,MAAM;EACjB,GAAG,kBAAkB,OAAO,QAAA,CAAkD;CAClF,EAAE,CACN;AACJ;AAIA,MAAa,0BAA0B,EAAE,KACrC,EAAE,OAAO;CACL,aAAa,EAAE,KACX,EAAE,KAAKC,iBAA4B,GACnC,EAAE,WAAW,MACT,kBACI,kBAAkB,eAClB,GACA,2BACA,cACJ,CACJ,CACJ;CACA,YAAY;CACZ,cAAc;CACd,MAAM,EAAE,OAAO;CACf,qBAAqB;CACrB,mBAAmB;CACnB,uBAAuB;CACvB,MAAM,EAAE,OAAO;AACnB,CAAC,GACD,EAAE,WAAW,EAAE,MAAM,GAAG,cAAc;CAClC,GAAG;CACH,IAAI,SAAS,IAAI;CACjB,MAAM,KAAK,SAAS;AACxB,EAAE,CACN"}
|
|
1
|
+
{"version":3,"file":"orders-modify.schemas.js","names":["ProtoWrite.RiskPolicySchema","ProtoWrite.ModifyActionTaken"],"sources":["../../../src/services/orders/orders-modify.schemas.ts"],"sourcesContent":["import * as ProtoWrite from \"../../gen/orders/v1/orders_pb.js\";\nimport { create } from \"@bufbuild/protobuf\";\nimport * as v from \"valibot\";\nimport { tsNsToMs } from \"../../utils/time.js\";\nimport { idToBigInt } from \"../../utils/base58-id.js\";\nimport { OptionalPublicIdSchema, PublicIdSchema } from \"../../shared/schemas.js\";\nimport { positiveDecimalInputToScaled, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport { PROTOBUF_UINT32_MAX } from \"../../shared/wire-bounds.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport { requiredEnumLabel } from \"../../shared/proto-enum-codec.js\";\nimport { MODIFY_BEHAVIOR_VALUES, ModifyActionCodec, ModifyBehaviorCodec } from \"./orders.codecs.js\";\nimport { createRequiredRiskPolicyInputSchema } from \"./orders-risk.schemas.js\";\nimport {\n ClientOrderIdInputSchema,\n OrderRequestIdInputSchema,\n} from \"./orders-identifiers.schemas.js\";\n\nconst ModifyBehaviorInputSchema = v.picklist(MODIFY_BEHAVIOR_VALUES);\n\nconst ModifyOrderIdInputSchema = v.pipe(\n v.string(),\n v.trim(),\n v.minLength(1),\n v.transform((value) => idToBigInt(value, \"orderId\")),\n v.check((value) => value > 0n, \"orderId must be greater than zero\"),\n);\n\nconst DecimalInputStringSchema = v.pipe(v.string(), v.trim(), v.minLength(1));\n\nconst ModifyOrderItemBaseInputSchema = v.object({\n symbolId: v.pipe(v.number(), v.integer(), v.gtValue(0), v.maxValue(PROTOBUF_UINT32_MAX)),\n behavior: v.optional(ModifyBehaviorInputSchema),\n newClientOrderId: v.optional(ClientOrderIdInputSchema),\n});\n\nconst ModifyOrderRequestInputSchema = v.object({\n ...AccountScopeInputEntries,\n requestId: v.optional(OrderRequestIdInputSchema),\n});\n\nconst ModifyOrderKeyInputSchema = v.union([\n v.pipe(\n v.object({\n orderId: ModifyOrderIdInputSchema,\n clientOrderId: v.optional(v.never()),\n }),\n v.transform(({ orderId }) => ({\n key: { case: \"orderId\" as const, value: orderId },\n })),\n ),\n v.pipe(\n v.object({\n orderId: v.optional(v.never()),\n clientOrderId: ClientOrderIdInputSchema,\n }),\n v.transform(({ clientOrderId }) => ({\n key: { case: \"clientOrderId\" as const, value: clientOrderId },\n })),\n ),\n]);\n\nconst ModifyOrderPricePatchInputSchema = v.object({\n newPrice: DecimalInputStringSchema,\n newQty: v.optional(DecimalInputStringSchema),\n});\n\nconst ModifyOrderQtyPatchInputSchema = v.object({\n newPrice: v.optional(DecimalInputStringSchema),\n newQty: DecimalInputStringSchema,\n});\n\nconst ModifyOrderNoPriceQtyPatchInputSchema = v.object({\n newPrice: v.optional(v.never()),\n newQty: v.optional(v.never()),\n});\n\nconst ModifyOrderClearRiskPatchInputSchema = v.object({\n risk: v.optional(v.never()),\n clearRisk: v.literal(true),\n});\n\nconst ModifyOrderNoRiskPatchInputSchema = v.object({\n risk: v.optional(v.never()),\n clearRisk: v.optional(v.literal(false)),\n});\n\nconst MODIFY_ORDER_ITEM_INPUT_KEYS = new Set<string>([\n ...Object.keys(ModifyOrderItemBaseInputSchema.entries),\n \"orderId\",\n \"clientOrderId\",\n \"newPrice\",\n \"newQty\",\n \"risk\",\n \"clearRisk\",\n]);\n\nconst MODIFY_ORDER_INPUT_KEYS = new Set<string>([\n ...MODIFY_ORDER_ITEM_INPUT_KEYS,\n ...Object.keys(ModifyOrderRequestInputSchema.entries),\n]);\n\n/**\n * The modify-order input is a v.intersect of partial object schemas, so its\n * members cannot use v.strictObject (each member would reject the other\n * members' keys). Unknown keys are rejected up front instead, matching the\n * strict-input behavior of every other mutating method.\n */\nexport function assertKnownModifyOrderInputKeys(input: object): void {\n for (const key of Object.keys(input)) {\n if (!MODIFY_ORDER_INPUT_KEYS.has(key)) {\n throw new Error(`Unknown key \"${key}\" in modify order input.`);\n }\n }\n}\n\nfunction createModifyOrderPatchInputSchema(scales: SdkScales) {\n const ModifyOrderSetRiskPatchInputSchema = v.object({\n risk: createRequiredRiskPolicyInputSchema(scales),\n clearRisk: v.optional(v.literal(false)),\n });\n\n const ModifyOrderAnyRiskPatchInputSchema = v.union([\n ModifyOrderSetRiskPatchInputSchema,\n ModifyOrderClearRiskPatchInputSchema,\n ModifyOrderNoRiskPatchInputSchema,\n ]);\n\n const ModifyOrderRequiredRiskPatchInputSchema = v.union([\n ModifyOrderSetRiskPatchInputSchema,\n ModifyOrderClearRiskPatchInputSchema,\n ]);\n\n return v.union([\n v.intersect([ModifyOrderPricePatchInputSchema, ModifyOrderAnyRiskPatchInputSchema]),\n v.intersect([ModifyOrderQtyPatchInputSchema, ModifyOrderAnyRiskPatchInputSchema]),\n v.intersect([\n ModifyOrderNoPriceQtyPatchInputSchema,\n ModifyOrderRequiredRiskPatchInputSchema,\n ]),\n ]);\n}\n\nfunction createModifyOrderItemObjectInputSchema(scales: SdkScales) {\n return v.intersect([\n ModifyOrderItemBaseInputSchema,\n ModifyOrderKeyInputSchema,\n createModifyOrderPatchInputSchema(scales),\n ]);\n}\n\ntype ParsedModifyOrderItemInput = v.InferOutput<\n ReturnType<typeof createModifyOrderItemObjectInputSchema>\n>;\n\nfunction toModifyOrderItem(\n input: ParsedModifyOrderItemInput,\n scales: SdkScales,\n defaultBehavior: ProtoWrite.ModifyBehavior,\n) {\n return {\n key: input.key,\n newPriceTicks:\n input.newPrice === undefined\n ? undefined\n : positiveDecimalInputToScaled(\"newPrice\", input.newPrice, scales.price()),\n newQtyScaled:\n input.newQty === undefined\n ? undefined\n : positiveDecimalInputToScaled(\n \"newQty\",\n input.newQty,\n scales.baseQty(input.symbolId),\n ),\n newAttachedRisk:\n input.clearRisk === true ? create(ProtoWrite.RiskPolicySchema) : input.risk,\n behavior: input.behavior\n ? ModifyBehaviorCodec.inputToProto[input.behavior]\n : defaultBehavior,\n newClientOrderId: input.newClientOrderId ?? \"\",\n symbolId: input.symbolId,\n };\n}\n\nexport function createModifyOrderInputSchema(scales: SdkScales) {\n return v.pipe(\n v.intersect([\n ModifyOrderRequestInputSchema,\n createModifyOrderItemObjectInputSchema(scales),\n ]),\n v.transform((input) => ({\n subaccountId: accountScopeToSubaccountId(input.account),\n requestId: input.requestId,\n ...toModifyOrderItem(input, scales, ProtoWrite.ModifyBehavior.AMEND_OR_REPLACE),\n })),\n );\n}\n\nexport type ModifyOrderInput = v.InferInput<ReturnType<typeof createModifyOrderInputSchema>>;\n\nexport const ModifyOrderResultSchema = v.pipe(\n v.object({\n actionTaken: v.pipe(\n v.enum(ProtoWrite.ModifyActionTaken),\n v.transform((v) =>\n requiredEnumLabel(\n ModifyActionCodec.protoToOutput,\n v,\n \"ModifyOrderResultSchema\",\n \"action taken\",\n ),\n ),\n ),\n oldOrderId: PublicIdSchema,\n finalOrderId: PublicIdSchema,\n code: v.string(),\n takeProfitTriggerId: OptionalPublicIdSchema,\n stopLossTriggerId: OptionalPublicIdSchema,\n trailingStopTriggerId: OptionalPublicIdSchema,\n tsNs: v.bigint(),\n }),\n v.transform(({ tsNs, ...result }) => ({\n ...result,\n ts: tsNsToMs(tsNs),\n tsNs: tsNs.toString(),\n })),\n);\n\nexport type ModifyOrderResult = v.InferOutput<typeof ModifyOrderResultSchema>;\n"],"mappings":";;;;;;;;;;;;;;AAoBA,MAAM,4BAA4B,EAAE,SAAS,sBAAsB;AAEnE,MAAM,2BAA2B,EAAE,KAC/B,EAAE,OAAO,GACT,EAAE,KAAK,GACP,EAAE,UAAU,CAAC,GACb,EAAE,WAAW,UAAU,WAAW,OAAO,SAAS,CAAC,GACnD,EAAE,OAAO,UAAU,QAAQ,IAAI,mCAAmC,CACtE;AAEA,MAAM,2BAA2B,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,GAAG,EAAE,UAAU,CAAC,CAAC;AAE5E,MAAM,iCAAiC,EAAE,OAAO;CAC5C,UAAU,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,QAAQ,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAE,SAAS,mBAAm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5C,UAAU,MAAM;CACpB;AACJ;AAEA,SAAgB,6BAA6B,QAAmB;CAC5D,OAAO,EAAE,KACL,EAAE,UAAU,CACR,+BACA,uCAAuC,MAAM,CACjD,CAAC,GACD,EAAE,WAAW,WAAW;EACpB,cAAc,2BAA2B,MAAM,OAAO;EACtD,WAAW,MAAM;EACjB,GAAG,kBAAkB,OAAO,QAAA,CAAkD;CAClF,EAAE,CACN;AACJ;AAIA,MAAa,0BAA0B,EAAE,KACrC,EAAE,OAAO;CACL,aAAa,EAAE,KACX,EAAE,KAAKC,iBAA4B,GACnC,EAAE,WAAW,MACT,kBACI,kBAAkB,eAClB,GACA,2BACA,cACJ,CACJ,CACJ;CACA,YAAY;CACZ,cAAc;CACd,MAAM,EAAE,OAAO;CACf,qBAAqB;CACrB,mBAAmB;CACnB,uBAAuB;CACvB,MAAM,EAAE,OAAO;AACnB,CAAC,GACD,EAAE,WAAW,EAAE,MAAM,GAAG,cAAc;CAClC,GAAG;CACH,IAAI,SAAS,IAAI;CACjB,MAAM,KAAK,SAAS;AACxB,EAAE,CACN"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RiskLimitGtcSchema, RiskMarketIocSchema } from "../../gen/orders/v1/orders_pb.js";
|
|
2
|
-
import { positiveDecimalInputToScaled, scaledToDecimalOutput } from "../../shared/decimal-surface.js";
|
|
3
2
|
import { BpsStringOrNumberInputSchema, NoneInputSchema, PriceDistanceInputSchema, PriceSlippageInputSchema } from "../shared.js";
|
|
3
|
+
import { positiveDecimalInputToScaled, scaledToDecimalOutput } from "../../shared/decimal-surface.js";
|
|
4
4
|
import { parseSlippageInput, parseTrailingDistanceInput } from "../trailing-oneof-inputs.js";
|
|
5
5
|
import { create } from "@bufbuild/protobuf";
|
|
6
6
|
import * as v from "valibot";
|
|
@@ -21,14 +21,14 @@ declare class OrdersService {
|
|
|
21
21
|
#private;
|
|
22
22
|
constructor(transport: Transport, realtime: PolyesterRealtime, resolver: SubaccountResolver | undefined, scales: SdkScales);
|
|
23
23
|
/**
|
|
24
|
-
* Returns open orders for the resolved root account or subaccount, with optional symbol, trigger ID, side, pagination, and attached-risk inclusion filters. Results are paginated with a server-determined page size: a single call is not the full set of open orders — keep calling with the returned nextPageToken until it is empty.
|
|
24
|
+
* Returns open orders for the resolved root account or subaccount, with optional symbol IDs, trigger ID, side, pagination, and attached-risk inclusion filters. Results are paginated with a server-determined page size: a single call is not the full set of open orders — keep calling with the returned nextPageToken until it is empty.
|
|
25
25
|
*/
|
|
26
26
|
listOpen(input?: v.InferInput<typeof OpenOrdersInputSchema>, options?: PolyesterRequestOptions): Promise<{
|
|
27
27
|
orders: Order[];
|
|
28
28
|
nextPageToken: string;
|
|
29
29
|
}>;
|
|
30
30
|
/**
|
|
31
|
-
* Returns historical orders for the resolved account scope, supporting symbol, trigger ID, side, status, time range, pagination, and attached-risk filters. Results are paginated with the backend nextPageToken.
|
|
31
|
+
* Returns historical orders for the resolved account scope, supporting symbol IDs, trigger ID, side, status, time range, pagination, and attached-risk filters. Results are paginated with the backend nextPageToken.
|
|
32
32
|
*/
|
|
33
33
|
listHistory(input?: v.InferInput<typeof OrderHistoryInputSchema>, options?: PolyesterRequestOptions): Promise<{
|
|
34
34
|
orders: Order[];
|
|
@@ -55,7 +55,7 @@ declare class OrdersService {
|
|
|
55
55
|
*/
|
|
56
56
|
batchCancel(input: BatchCancelOrdersInput, options?: PolyesterMutationOptions): Promise<BatchCancelOrdersResult>;
|
|
57
57
|
/**
|
|
58
|
-
* Applies a price, quantity, client id, or attached-risk patch to one open order
|
|
58
|
+
* Applies a price, quantity, client id, or attached-risk patch to one open order. The symbol ID routes policy checks and quantity scaling. A requestId is generated when omitted; provide a stable value when retrying the same logical modification.
|
|
59
59
|
*/
|
|
60
60
|
modify(input: ModifyOrderInput, options?: PolyesterMutationOptions): Promise<ModifyOrderResult>;
|
|
61
61
|
/**
|
|
@@ -67,11 +67,11 @@ declare class OrdersService {
|
|
|
67
67
|
*/
|
|
68
68
|
getBatchReplaceStatus(input: GetBatchReplaceStatusInput, options?: PolyesterRequestOptions): Promise<GetBatchReplaceStatusResult>;
|
|
69
69
|
/**
|
|
70
|
-
* Cancels all matching open orders for the resolved account scope, optionally narrowed by symbol and side, with dry-run preview. A requestId is generated when omitted; provide a stable value when retrying the same logical bulk cancellation.
|
|
70
|
+
* Cancels all matching open orders for the resolved account scope, optionally narrowed by symbol ID and side, with dry-run preview. A requestId is generated when omitted; provide a stable value when retrying the same logical bulk cancellation.
|
|
71
71
|
*/
|
|
72
72
|
cancelAll(input: v.InferInput<typeof CancelAllOrdersInputSchema>, options?: PolyesterMutationOptions): Promise<CancelAllOrdersResponse>;
|
|
73
73
|
/**
|
|
74
|
-
* Arms, refreshes, or disables the account dead-man switch. timeoutSec 0 disables it; 10–120 arms it. Generate a new requestId for each deliberate heartbeat, but reuse the same ID when retrying one ambiguous heartbeat.
|
|
74
|
+
* Arms, refreshes, or disables the account dead-man switch, optionally scoped by symbol ID and side. timeoutSec 0 disables it; 10–120 arms it. Generate a new requestId for each deliberate heartbeat, but reuse the same ID when retrying one ambiguous heartbeat.
|
|
75
75
|
*/
|
|
76
76
|
cancelAllAfter(input: CancelAllAfterInput, options?: PolyesterMutationOptions): Promise<CancelAllAfterResult>;
|
|
77
77
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orders.d.ts","names":[],"sources":["../../../src/services/orders/orders.ts"],"mappings":";;;;;;;;;;;;;UAqFU,6BAA6B,mBAAmB;EACtD;;;;;cAqBS;;EAaL,YAAA,WAAW,WACX,UAAU,mBACV,UAAU,gCACV,QAAQ;;;;EAiBN,SACF,QAAO,EAAE,kBAAkB,wBAC3B,UAAU,0BACX;IAAU,QAAQ;IAAS;;;;;EAoBxB,YACF,QAAO,EAAE,kBAAkB,0BAC3B,UAAU,0BACX;IAAU,QAAQ;IAAS;;;;;EAoBxB,QACF,OAAO,eACP,UAAU,0BACX,QAAQ;;;;
|
|
1
|
+
{"version":3,"file":"orders.d.ts","names":[],"sources":["../../../src/services/orders/orders.ts"],"mappings":";;;;;;;;;;;;;UAqFU,6BAA6B,mBAAmB;EACtD;;;;;cAqBS;;EAaL,YAAA,WAAW,WACX,UAAU,mBACV,UAAU,gCACV,QAAQ;;;;EAiBN,SACF,QAAO,EAAE,kBAAkB,wBAC3B,UAAU,0BACX;IAAU,QAAQ;IAAS;;;;;EAoBxB,YACF,QAAO,EAAE,kBAAkB,0BAC3B,UAAU,0BACX;IAAU,QAAQ;IAAS;;;;;EAoBxB,QACF,OAAO,eACP,UAAU,0BACX,QAAQ;;;;EAiBL,OACF,OAAO,eACP,UAAU,2BACX,QAAQ;;;;EAkBL,YACF,OAAO,wBACP,UAAU,2BACX,QAAQ;;;;EAyBL,OACF,OAAO,EAAE,kBAAkB,yBAC3B,UAAU,2BACX,QAAQ;;;;EAmBL,YACF,OAAO,wBACP,UAAU,2BACX,QAAQ;;;;EAkBL,OACF,OAAO,kBACP,UAAU,2BACX,QAAQ;;;;EAkBL,aACF,OAAO,yBACP,UAAU,2BACX,QAAQ;;;;EAyBL,sBACF,OAAO,4BACP,UAAU,0BACX,QAAQ;;;;EAaL,UACF,OAAO,EAAE,kBAAkB,6BAC3B,UAAU,2BACX,QAAQ;;;;EAgBL,eACF,OAAO,qBACP,UAAU,2BACX,QAAQ;;;;EAgBL,WACF,OAAO,EAAE,kBAAkB,6BAC3B,UAAU,0BACX,QAAQ;;;;EAqBX,UAAU,OAAO"}
|
|
@@ -60,7 +60,7 @@ var OrdersService = class {
|
|
|
60
60
|
this.#batchCreateOrdersInputSchema = createBatchCreateOrdersInputSchema(scales);
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
|
-
* Returns open orders for the resolved root account or subaccount, with optional symbol, trigger ID, side, pagination, and attached-risk inclusion filters. Results are paginated with a server-determined page size: a single call is not the full set of open orders — keep calling with the returned nextPageToken until it is empty.
|
|
63
|
+
* Returns open orders for the resolved root account or subaccount, with optional symbol IDs, trigger ID, side, pagination, and attached-risk inclusion filters. Results are paginated with a server-determined page size: a single call is not the full set of open orders — keep calling with the returned nextPageToken until it is empty.
|
|
64
64
|
*/
|
|
65
65
|
async listOpen(input = {}, options) {
|
|
66
66
|
await this.#scales.ready();
|
|
@@ -73,7 +73,7 @@ var OrdersService = class {
|
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
|
-
* Returns historical orders for the resolved account scope, supporting symbol, trigger ID, side, status, time range, pagination, and attached-risk filters. Results are paginated with the backend nextPageToken.
|
|
76
|
+
* Returns historical orders for the resolved account scope, supporting symbol IDs, trigger ID, side, status, time range, pagination, and attached-risk filters. Results are paginated with the backend nextPageToken.
|
|
77
77
|
*/
|
|
78
78
|
async listHistory(input = {}, options) {
|
|
79
79
|
await this.#scales.ready();
|
|
@@ -93,7 +93,7 @@ var OrdersService = class {
|
|
|
93
93
|
const resolved = resolveAccountScopedInput(input, this.#resolver);
|
|
94
94
|
const request = parse(this.#newOrderInputSchema, resolved);
|
|
95
95
|
const response = await this.#writeClient.previewOrder(removeUndefined(request), toConnectCallOptions(options));
|
|
96
|
-
return parse(createPreviewOrderResultSchema(this.#scales,
|
|
96
|
+
return parse(createPreviewOrderResultSchema(this.#scales, request.order.symbolId), response);
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
99
|
* Places a spot order with an explicit market-IOC, limit-GTC, limit-IOC, or limit-FOK execution policy and optional attached risk controls. clientOrderId is the caller-controlled idempotency key and should be reused only for the same logical order.
|
|
@@ -104,7 +104,7 @@ var OrdersService = class {
|
|
|
104
104
|
const validatedInput = parse(this.#newOrderInputSchema, resolved);
|
|
105
105
|
const requestPayload = removeUndefined(validatedInput);
|
|
106
106
|
const res = await this.#writeClient.createOrder(requestPayload, toConnectCallOptions(options));
|
|
107
|
-
return parse(createCreateOrderResultSchema(this.#scales,
|
|
107
|
+
return parse(createCreateOrderResultSchema(this.#scales, validatedInput.order.symbolId), res);
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
110
110
|
* Places 1–20 spot orders in one best-effort request. Results preserve item order and report admission as accepted or rejected; accepted orders still require lifecycle reconciliation. Supply a clientOrderId for each item and a stable requestId when an ambiguous batch may be retried.
|
|
@@ -117,7 +117,7 @@ var OrdersService = class {
|
|
|
117
117
|
};
|
|
118
118
|
const request = parse(this.#batchCreateOrdersInputSchema, resolved);
|
|
119
119
|
const response = await this.#writeClient.batchCreateOrders(removeUndefined(request), toConnectCallOptions(options));
|
|
120
|
-
const result = parse(createBatchCreateOrdersResultSchema(this.#scales,
|
|
120
|
+
const result = parse(createBatchCreateOrdersResultSchema(this.#scales, request.items.map((item) => item.symbolId)), response);
|
|
121
121
|
assertBatchResultCount("batchCreate", input.items.length, result.results.length);
|
|
122
122
|
return result;
|
|
123
123
|
}
|
|
@@ -149,7 +149,7 @@ var OrdersService = class {
|
|
|
149
149
|
return result;
|
|
150
150
|
}
|
|
151
151
|
/**
|
|
152
|
-
* Applies a price, quantity, client id, or attached-risk patch to one open order
|
|
152
|
+
* Applies a price, quantity, client id, or attached-risk patch to one open order. The symbol ID routes policy checks and quantity scaling. A requestId is generated when omitted; provide a stable value when retrying the same logical modification.
|
|
153
153
|
*/
|
|
154
154
|
async modify(input, options) {
|
|
155
155
|
await this.#scales.ready();
|
|
@@ -188,7 +188,7 @@ var OrdersService = class {
|
|
|
188
188
|
return parse(GetBatchReplaceStatusResultSchema, response);
|
|
189
189
|
}
|
|
190
190
|
/**
|
|
191
|
-
* Cancels all matching open orders for the resolved account scope, optionally narrowed by symbol and side, with dry-run preview. A requestId is generated when omitted; provide a stable value when retrying the same logical bulk cancellation.
|
|
191
|
+
* Cancels all matching open orders for the resolved account scope, optionally narrowed by symbol ID and side, with dry-run preview. A requestId is generated when omitted; provide a stable value when retrying the same logical bulk cancellation.
|
|
192
192
|
*/
|
|
193
193
|
async cancelAll(input, options) {
|
|
194
194
|
const resolved = {
|
|
@@ -200,7 +200,7 @@ var OrdersService = class {
|
|
|
200
200
|
return parse(CancelAllOrdersResponseSchema, res);
|
|
201
201
|
}
|
|
202
202
|
/**
|
|
203
|
-
* Arms, refreshes, or disables the account dead-man switch. timeoutSec 0 disables it; 10–120 arms it. Generate a new requestId for each deliberate heartbeat, but reuse the same ID when retrying one ambiguous heartbeat.
|
|
203
|
+
* Arms, refreshes, or disables the account dead-man switch, optionally scoped by symbol ID and side. timeoutSec 0 disables it; 10–120 arms it. Generate a new requestId for each deliberate heartbeat, but reuse the same ID when retrying one ambiguous heartbeat.
|
|
204
204
|
*/
|
|
205
205
|
async cancelAllAfter(input, options) {
|
|
206
206
|
const resolved = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orders.js","names":["#readClient","ProtoRead.OrdersReadService","#writeClient","ProtoWrite.OrdersService","#realtime","#resolver","#scales","#orderSchema","#orderDetailsSchema","#newOrderInputSchema","#modifyOrderInputSchema","#batchCreateOrdersInputSchema","ProtoRead.OrderSchema"],"sources":["../../../src/services/orders/orders.ts"],"sourcesContent":["import * as ProtoRead from \"../../gen/orders/v1/orders_read_pb.js\";\nimport * as ProtoWrite from \"../../gen/orders/v1/orders_pb.js\";\nimport { createClient, type Client, type Transport } from \"@connectrpc/connect\";\nimport { publicationHandlerErrorContext } from \"../../shared/subscription-errors.js\";\nimport * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\nimport { type SubaccountResolver, resolveAccountScopedInput } from \"../subaccount-resolver.js\";\nimport { removeUndefined } from \"../../utils/remove-undefined.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport type { PolyesterRealtime } from \"../../realtime/types.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport { createReadyGate, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport { getOrderErrorDetail } from \"../../utils/connect-order-errors.js\";\nimport { formatConnectError, isResourceNotFoundError } from \"../../utils/errors.js\";\nimport {\n OpenOrdersInputSchema,\n OrderHistoryInputSchema,\n type NewOrderInput,\n createNewOrderInputSchema,\n CancelOrderInputSchema,\n CancelOrderResultSchema,\n type CancelOrderResult,\n CancelAllOrdersInputSchema,\n CancelAllOrdersResponseSchema,\n type CancelAllOrdersResponse,\n type Order,\n GetOrderDetailsInputSchema,\n createCreateOrderResultSchema,\n createPreviewOrderResultSchema,\n type PreviewOrderResult,\n type ModifyOrderInput,\n assertKnownModifyOrderInputKeys,\n createModifyOrderInputSchema,\n ModifyOrderResultSchema,\n type CreateOrderResult,\n type ModifyOrderResult,\n type OrderDetails,\n createOrderSchema,\n createOrderDetailsSchema,\n CancelAllAfterInputSchema,\n CancelAllAfterResultSchema,\n type CancelAllAfterInput,\n type CancelAllAfterResult,\n BatchCancelOrdersInputSchema,\n BatchCancelOrdersResultSchema,\n type BatchCancelOrdersInput,\n type BatchCancelOrdersResult,\n createBatchCreateOrdersResultSchema,\n type BatchCreateOrdersInput,\n type BatchCreateOrdersResult,\n BatchReplaceOrdersResultSchema,\n type BatchReplaceOrdersInput,\n type BatchReplaceOrdersResult,\n GetBatchReplaceStatusInputSchema,\n GetBatchReplaceStatusResultSchema,\n type GetBatchReplaceStatusInput,\n type GetBatchReplaceStatusResult,\n assertKnownBatchReplaceOrderItemInputKeys,\n createBatchCreateOrdersInputSchema,\n createBatchReplaceOrdersInputSchema,\n} from \"./orders.schemas.js\";\n\nfunction hasKnownOrderSymbol(scales: SdkScales, order: { symbolId: number }): boolean {\n try {\n scales.baseQty(order.symbolId);\n return true;\n } catch {\n return false;\n }\n}\n\nconst MISCLASSIFIED_ORDER_NOT_FOUND_MESSAGE = \"order not found\";\n\nfunction isOrderNotFoundError(error: unknown): boolean {\n return (\n isResourceNotFoundError(error) ||\n getOrderErrorDetail(error)?.code === \"NOT_FOUND\" ||\n formatConnectError(error, \"\").toLowerCase() === MISCLASSIFIED_ORDER_NOT_FOUND_MESSAGE\n );\n}\n\ninterface SubscribeOrdersInput extends BaseSubscribeInput<Order> {\n accountId: string;\n}\n\nfunction createMutationRequestId(): string {\n return (\n globalThis.crypto?.randomUUID?.() ??\n `req_${Date.now()}_${Math.random().toString(16).slice(2)}`\n );\n}\n\nfunction assertBatchResultCount(operation: string, requested: number, returned: number): void {\n if (requested !== returned) {\n throw new Error(\n `${operation} returned ${returned} results for ${requested} requested items.`,\n );\n }\n}\n\n/**\n * Manages account-scoped spot orders across read, write, and realtime order update surfaces.\n */\nexport class OrdersService {\n #readClient: Client<typeof ProtoRead.OrdersReadService>;\n #writeClient: Client<typeof ProtoWrite.OrdersService>;\n #realtime: PolyesterRealtime;\n #resolver?: SubaccountResolver;\n #scales: SdkScales;\n #orderSchema: ReturnType<typeof createOrderSchema>;\n #orderDetailsSchema: ReturnType<typeof createOrderDetailsSchema>;\n #newOrderInputSchema: ReturnType<typeof createNewOrderInputSchema>;\n #modifyOrderInputSchema: ReturnType<typeof createModifyOrderInputSchema>;\n #batchCreateOrdersInputSchema: ReturnType<typeof createBatchCreateOrdersInputSchema>;\n\n constructor(\n transport: Transport,\n realtime: PolyesterRealtime,\n resolver: SubaccountResolver | undefined,\n scales: SdkScales,\n ) {\n this.#readClient = createClient(ProtoRead.OrdersReadService, transport);\n this.#writeClient = createClient(ProtoWrite.OrdersService, transport);\n this.#realtime = realtime;\n this.#resolver = resolver;\n this.#scales = scales;\n this.#orderSchema = createOrderSchema(scales);\n this.#orderDetailsSchema = createOrderDetailsSchema(scales);\n this.#newOrderInputSchema = createNewOrderInputSchema(scales);\n this.#modifyOrderInputSchema = createModifyOrderInputSchema(scales);\n this.#batchCreateOrdersInputSchema = createBatchCreateOrdersInputSchema(scales);\n }\n\n /**\n * Returns open orders for the resolved root account or subaccount, with optional symbol, trigger ID, side, pagination, and attached-risk inclusion filters. Results are paginated with a server-determined page size: a single call is not the full set of open orders — keep calling with the returned nextPageToken until it is empty.\n */\n async listOpen(\n input: v.InferInput<typeof OpenOrdersInputSchema> = {},\n options?: PolyesterRequestOptions,\n ): Promise<{ orders: Order[]; nextPageToken: string }> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validatedInput = parse(OpenOrdersInputSchema, resolved);\n const res = await this.#readClient.getOpenOrders(\n removeUndefined(validatedInput),\n toConnectCallOptions(options),\n );\n return {\n orders: parse(\n v.array(this.#orderSchema),\n res.orders.filter((order) => hasKnownOrderSymbol(this.#scales, order)),\n ),\n nextPageToken: res.nextPageToken,\n };\n }\n\n /**\n * Returns historical orders for the resolved account scope, supporting symbol, trigger ID, side, status, time range, pagination, and attached-risk filters. Results are paginated with the backend nextPageToken.\n */\n async listHistory(\n input: v.InferInput<typeof OrderHistoryInputSchema> = {},\n options?: PolyesterRequestOptions,\n ): Promise<{ orders: Order[]; nextPageToken: string }> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validatedInput = parse(OrderHistoryInputSchema, resolved);\n const res = await this.#readClient.getOrderHistory(\n removeUndefined(validatedInput),\n toConnectCallOptions(options),\n );\n return {\n orders: parse(\n v.array(this.#orderSchema),\n res.orders.filter((order) => hasKnownOrderSymbol(this.#scales, order)),\n ),\n nextPageToken: res.nextPageToken,\n };\n }\n\n /**\n * Evaluates one complete order intent against current market, policy, risk, and balance state without creating an order, reserving funds, or claiming its client order ID.\n */\n async preview(\n input: NewOrderInput,\n options?: PolyesterRequestOptions,\n ): Promise<PreviewOrderResult> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const request = parse(this.#newOrderInputSchema, resolved);\n const response = await this.#writeClient.previewOrder(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n return parse(createPreviewOrderResultSchema(this.#scales, input.symbol), response);\n }\n\n /**\n * Places a spot order with an explicit market-IOC, limit-GTC, limit-IOC, or limit-FOK execution policy and optional attached risk controls. clientOrderId is the caller-controlled idempotency key and should be reused only for the same logical order.\n */\n async create(\n input: NewOrderInput,\n options?: PolyesterMutationOptions,\n ): Promise<CreateOrderResult> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validatedInput = parse(this.#newOrderInputSchema, resolved);\n const requestPayload = removeUndefined(validatedInput);\n const res = await this.#writeClient.createOrder(\n requestPayload,\n toConnectCallOptions(options),\n );\n return parse(createCreateOrderResultSchema(this.#scales, input.symbol), res);\n }\n\n /**\n * Places 1–20 spot orders in one best-effort request. Results preserve item order and report admission as accepted or rejected; accepted orders still require lifecycle reconciliation. Supply a clientOrderId for each item and a stable requestId when an ambiguous batch may be retried.\n */\n async batchCreate(\n input: BatchCreateOrdersInput,\n options?: PolyesterMutationOptions,\n ): Promise<BatchCreateOrdersResult> {\n await this.#scales.ready();\n const resolved = {\n ...resolveAccountScopedInput(input, this.#resolver),\n requestId: input.requestId ?? createMutationRequestId(),\n };\n const request = parse(this.#batchCreateOrdersInputSchema, resolved);\n const response = await this.#writeClient.batchCreateOrders(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n const result = parse(\n createBatchCreateOrdersResultSchema(\n this.#scales,\n input.items.map((item) => item.symbol),\n ),\n response,\n );\n assertBatchResultCount(\"batchCreate\", input.items.length, result.results.length);\n return result;\n }\n\n /**\n * Requests cancellation of one order in the resolved account scope by order id or client order id, with optional symbol routing. The response acknowledges the cancellation request, not the order's final lifecycle state; reconcile through order reads or realtime before releasing local state. A missing target remains a {@link ResourceNotFoundError}; callers performing desired-state cleanup may treat that error as success when the order could already have filled or left the book.\n */\n async cancel(\n input: v.InferInput<typeof CancelOrderInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<CancelOrderResult> {\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n\n const validated = parse(CancelOrderInputSchema, resolved);\n\n const res = await this.#writeClient.cancelOrder(\n {\n key: validated.key,\n symbolId: validated.symbolId,\n subaccountId: validated.subaccountId,\n },\n toConnectCallOptions(options),\n );\n return parse(CancelOrderResultSchema, res);\n }\n\n /**\n * Cancels 1–50 explicit orders in one best-effort request. Results preserve item order and acknowledge cancellation admission rather than final order state. Supply a stable requestId when an ambiguous batch may be retried.\n */\n async batchCancel(\n input: BatchCancelOrdersInput,\n options?: PolyesterMutationOptions,\n ): Promise<BatchCancelOrdersResult> {\n const resolved = {\n ...resolveAccountScopedInput(input, this.#resolver),\n requestId: input.requestId ?? createMutationRequestId(),\n };\n const request = parse(BatchCancelOrdersInputSchema, resolved);\n const response = await this.#writeClient.batchCancelOrders(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n const result = parse(BatchCancelOrdersResultSchema, response);\n assertBatchResultCount(\"batchCancel\", input.items.length, result.results.length);\n return result;\n }\n\n /**\n * Applies a price, quantity, client id, or attached-risk patch to one open order using the backend modify behavior policy. A requestId is generated when omitted; provide a stable value when retrying the same logical modification.\n */\n async modify(\n input: ModifyOrderInput,\n options?: PolyesterMutationOptions,\n ): Promise<ModifyOrderResult> {\n await this.#scales.ready();\n const resolved = {\n ...resolveAccountScopedInput(input, this.#resolver),\n requestId: input.requestId ?? createMutationRequestId(),\n };\n assertKnownModifyOrderInputKeys(resolved);\n const validated = parse(this.#modifyOrderInputSchema, resolved);\n const res = await this.#writeClient.modifyOrder(\n removeUndefined(validated),\n toConnectCallOptions(options),\n );\n return parse(ModifyOrderResultSchema, res);\n }\n\n /**\n * Replaces 1–50 same-symbol orders and returns an index-stable durable admission receipt. Reuse requestId only when retrying the same logical batch; use the returned batchRequestId for later status reads.\n */\n async batchReplace(\n input: BatchReplaceOrdersInput,\n options?: PolyesterMutationOptions,\n ): Promise<BatchReplaceOrdersResult> {\n await this.#scales.ready();\n for (const item of input.items) {\n assertKnownBatchReplaceOrderItemInputKeys(item);\n }\n const resolved = {\n ...resolveAccountScopedInput(input, this.#resolver),\n requestId: input.requestId ?? createMutationRequestId(),\n };\n const request = parse(\n createBatchReplaceOrdersInputSchema(this.#scales, input.symbolId),\n resolved,\n );\n const response = await this.#writeClient.batchReplaceOrders(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n const result = parse(BatchReplaceOrdersResultSchema, response);\n assertBatchResultCount(\"batchReplace\", input.items.length, result.results.length);\n return result;\n }\n\n /**\n * Reads the durable per-item execution status for a batch replacement receipt.\n */\n async getBatchReplaceStatus(\n input: GetBatchReplaceStatusInput,\n options?: PolyesterRequestOptions,\n ): Promise<GetBatchReplaceStatusResult> {\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const request = parse(GetBatchReplaceStatusInputSchema, resolved);\n const response = await this.#readClient.getBatchReplaceStatus(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n return parse(GetBatchReplaceStatusResultSchema, response);\n }\n\n /**\n * Cancels all matching open orders for the resolved account scope, optionally narrowed by symbol and side, with dry-run preview. A requestId is generated when omitted; provide a stable value when retrying the same logical bulk cancellation.\n */\n async cancelAll(\n input: v.InferInput<typeof CancelAllOrdersInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<CancelAllOrdersResponse> {\n const resolved = {\n ...resolveAccountScopedInput(input, this.#resolver),\n requestId: input.requestId ?? createMutationRequestId(),\n };\n const validated = parse(CancelAllOrdersInputSchema, resolved);\n const res = await this.#writeClient.cancelAllOrders(\n removeUndefined(validated),\n toConnectCallOptions(options),\n );\n return parse(CancelAllOrdersResponseSchema, res);\n }\n\n /**\n * Arms, refreshes, or disables the account dead-man switch. timeoutSec 0 disables it; 10–120 arms it. Generate a new requestId for each deliberate heartbeat, but reuse the same ID when retrying one ambiguous heartbeat.\n */\n async cancelAllAfter(\n input: CancelAllAfterInput,\n options?: PolyesterMutationOptions,\n ): Promise<CancelAllAfterResult> {\n const resolved = {\n ...resolveAccountScopedInput(input, this.#resolver),\n requestId: input.requestId ?? createMutationRequestId(),\n };\n const request = parse(CancelAllAfterInputSchema, resolved);\n const response = await this.#writeClient.cancelAllAfter(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n return parse(CancelAllAfterResultSchema, response);\n }\n\n /**\n * Fetches one order by id or client order id and returns its order, trades, and transfer details when found. Returns null when the requested order is not found.\n */\n async getDetails(\n input: v.InferInput<typeof GetOrderDetailsInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<OrderDetails | null> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validatedInput = parse(GetOrderDetailsInputSchema, resolved);\n let res: ProtoRead.GetOrderResponse;\n try {\n res = await this.#readClient.getOrder(\n removeUndefined(validatedInput),\n toConnectCallOptions(options),\n );\n } catch (error) {\n if (isOrderNotFoundError(error)) return null;\n throw error;\n }\n if (!res.order) return null;\n return parse(this.#orderDetailsSchema, res);\n }\n\n /**\n * Subscribes to private order updates on private:spot:orders:{accountId}:proto and emits parsed order records until the returned unsubscribe function is called.\n */\n subscribe(input: SubscribeOrdersInput): () => void {\n const channel = `private:spot:orders:${input.accountId}:proto`;\n const gate = createReadyGate(\n () => this.#scales.ready(),\n (error) => input.onError?.(publicationHandlerErrorContext(channel, error)),\n );\n return this.#realtime.connectProtoChannel({\n channel,\n schema: ProtoRead.OrderSchema,\n onPublication: (data) => {\n gate.run(() => {\n const order = parse(this.#orderSchema, data);\n input.onEvent(order);\n });\n },\n onConnected: () => input.onOpen?.(),\n onDisconnected: () => input.onClose?.(),\n onError: input.onError,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkEA,SAAS,oBAAoB,QAAmB,OAAsC;CAClF,IAAI;EACA,OAAO,QAAQ,MAAM,QAAQ;EAC7B,OAAO;CACX,QAAQ;EACJ,OAAO;CACX;AACJ;AAEA,MAAM,wCAAwC;AAE9C,SAAS,qBAAqB,OAAyB;CACnD,OACI,wBAAwB,KAAK,KAC7B,oBAAoB,KAAK,CAAC,EAAE,SAAS,eACrC,mBAAmB,OAAO,EAAE,CAAC,CAAC,YAAY,MAAM;AAExD;AAMA,SAAS,0BAAkC;CACvC,OACI,WAAW,QAAQ,aAAa,KAChC,OAAO,KAAK,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC;AAE/D;AAEA,SAAS,uBAAuB,WAAmB,WAAmB,UAAwB;CAC1F,IAAI,cAAc,UACd,M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AM,MAAM,KAAKL,YAAY,SACzB,gBAAgB,cAAc,GAC9B,qBAAqB,OAAO,CAChC;EACJ,SAAS,OAAO;GACZ,IAAI,qBAAqB,KAAK,GAAG,OAAO;GACxC,MAAM;EACV;EACA,IAAI,CAAC,IAAI,OAAO,OAAO;EACvB,OAAO,MAAM,KAAKQ,qBAAqB,GAAG;CAC9C;;;;CAKA,UAAU,OAAyC;EAC/C,MAAM,UAAU,uBAAuB,MAAM,UAAU;EACvD,MAAM,OAAO,sBACH,KAAKF,QAAQ,MAAM,IACxB,UAAU,MAAM,UAAU,+BAA+B,SAAS,KAAK,CAAC,CAC7E;EACA,OAAO,KAAKF,UAAU,oBAAoB;GACtC;GACA,QAAQQ;GACR,gBAAgB,SAAS;IACrB,KAAK,UAAU;KACX,MAAM,QAAQ,MAAM,KAAKL,cAAc,IAAI;KAC3C,MAAM,QAAQ,KAAK;IACvB,CAAC;GACL;GACA,mBAAmB,MAAM,SAAS;GAClC,sBAAsB,MAAM,UAAU;GACtC,SAAS,MAAM;EACnB,CAAC;CACL;AACJ"}
|
|
1
|
+
{"version":3,"file":"orders.js","names":["#readClient","ProtoRead.OrdersReadService","#writeClient","ProtoWrite.OrdersService","#realtime","#resolver","#scales","#orderSchema","#orderDetailsSchema","#newOrderInputSchema","#modifyOrderInputSchema","#batchCreateOrdersInputSchema","ProtoRead.OrderSchema"],"sources":["../../../src/services/orders/orders.ts"],"sourcesContent":["import * as ProtoRead from \"../../gen/orders/v1/orders_read_pb.js\";\nimport * as ProtoWrite from \"../../gen/orders/v1/orders_pb.js\";\nimport { createClient, type Client, type Transport } from \"@connectrpc/connect\";\nimport { publicationHandlerErrorContext } from \"../../shared/subscription-errors.js\";\nimport * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\nimport { type SubaccountResolver, resolveAccountScopedInput } from \"../subaccount-resolver.js\";\nimport { removeUndefined } from \"../../utils/remove-undefined.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport type { PolyesterRealtime } from \"../../realtime/types.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport { createReadyGate, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport { getOrderErrorDetail } from \"../../utils/connect-order-errors.js\";\nimport { formatConnectError, isResourceNotFoundError } from \"../../utils/errors.js\";\nimport {\n OpenOrdersInputSchema,\n OrderHistoryInputSchema,\n type NewOrderInput,\n createNewOrderInputSchema,\n CancelOrderInputSchema,\n CancelOrderResultSchema,\n type CancelOrderResult,\n CancelAllOrdersInputSchema,\n CancelAllOrdersResponseSchema,\n type CancelAllOrdersResponse,\n type Order,\n GetOrderDetailsInputSchema,\n createCreateOrderResultSchema,\n createPreviewOrderResultSchema,\n type PreviewOrderResult,\n type ModifyOrderInput,\n assertKnownModifyOrderInputKeys,\n createModifyOrderInputSchema,\n ModifyOrderResultSchema,\n type CreateOrderResult,\n type ModifyOrderResult,\n type OrderDetails,\n createOrderSchema,\n createOrderDetailsSchema,\n CancelAllAfterInputSchema,\n CancelAllAfterResultSchema,\n type CancelAllAfterInput,\n type CancelAllAfterResult,\n BatchCancelOrdersInputSchema,\n BatchCancelOrdersResultSchema,\n type BatchCancelOrdersInput,\n type BatchCancelOrdersResult,\n createBatchCreateOrdersResultSchema,\n type BatchCreateOrdersInput,\n type BatchCreateOrdersResult,\n BatchReplaceOrdersResultSchema,\n type BatchReplaceOrdersInput,\n type BatchReplaceOrdersResult,\n GetBatchReplaceStatusInputSchema,\n GetBatchReplaceStatusResultSchema,\n type GetBatchReplaceStatusInput,\n type GetBatchReplaceStatusResult,\n assertKnownBatchReplaceOrderItemInputKeys,\n createBatchCreateOrdersInputSchema,\n createBatchReplaceOrdersInputSchema,\n} from \"./orders.schemas.js\";\n\nfunction hasKnownOrderSymbol(scales: SdkScales, order: { symbolId: number }): boolean {\n try {\n scales.baseQty(order.symbolId);\n return true;\n } catch {\n return false;\n }\n}\n\nconst MISCLASSIFIED_ORDER_NOT_FOUND_MESSAGE = \"order not found\";\n\nfunction isOrderNotFoundError(error: unknown): boolean {\n return (\n isResourceNotFoundError(error) ||\n getOrderErrorDetail(error)?.code === \"NOT_FOUND\" ||\n formatConnectError(error, \"\").toLowerCase() === MISCLASSIFIED_ORDER_NOT_FOUND_MESSAGE\n );\n}\n\ninterface SubscribeOrdersInput extends BaseSubscribeInput<Order> {\n accountId: string;\n}\n\nfunction createMutationRequestId(): string {\n return (\n globalThis.crypto?.randomUUID?.() ??\n `req_${Date.now()}_${Math.random().toString(16).slice(2)}`\n );\n}\n\nfunction assertBatchResultCount(operation: string, requested: number, returned: number): void {\n if (requested !== returned) {\n throw new Error(\n `${operation} returned ${returned} results for ${requested} requested items.`,\n );\n }\n}\n\n/**\n * Manages account-scoped spot orders across read, write, and realtime order update surfaces.\n */\nexport class OrdersService {\n #readClient: Client<typeof ProtoRead.OrdersReadService>;\n #writeClient: Client<typeof ProtoWrite.OrdersService>;\n #realtime: PolyesterRealtime;\n #resolver?: SubaccountResolver;\n #scales: SdkScales;\n #orderSchema: ReturnType<typeof createOrderSchema>;\n #orderDetailsSchema: ReturnType<typeof createOrderDetailsSchema>;\n #newOrderInputSchema: ReturnType<typeof createNewOrderInputSchema>;\n #modifyOrderInputSchema: ReturnType<typeof createModifyOrderInputSchema>;\n #batchCreateOrdersInputSchema: ReturnType<typeof createBatchCreateOrdersInputSchema>;\n\n constructor(\n transport: Transport,\n realtime: PolyesterRealtime,\n resolver: SubaccountResolver | undefined,\n scales: SdkScales,\n ) {\n this.#readClient = createClient(ProtoRead.OrdersReadService, transport);\n this.#writeClient = createClient(ProtoWrite.OrdersService, transport);\n this.#realtime = realtime;\n this.#resolver = resolver;\n this.#scales = scales;\n this.#orderSchema = createOrderSchema(scales);\n this.#orderDetailsSchema = createOrderDetailsSchema(scales);\n this.#newOrderInputSchema = createNewOrderInputSchema(scales);\n this.#modifyOrderInputSchema = createModifyOrderInputSchema(scales);\n this.#batchCreateOrdersInputSchema = createBatchCreateOrdersInputSchema(scales);\n }\n\n /**\n * Returns open orders for the resolved root account or subaccount, with optional symbol IDs, trigger ID, side, pagination, and attached-risk inclusion filters. Results are paginated with a server-determined page size: a single call is not the full set of open orders — keep calling with the returned nextPageToken until it is empty.\n */\n async listOpen(\n input: v.InferInput<typeof OpenOrdersInputSchema> = {},\n options?: PolyesterRequestOptions,\n ): Promise<{ orders: Order[]; nextPageToken: string }> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validatedInput = parse(OpenOrdersInputSchema, resolved);\n const res = await this.#readClient.getOpenOrders(\n removeUndefined(validatedInput),\n toConnectCallOptions(options),\n );\n return {\n orders: parse(\n v.array(this.#orderSchema),\n res.orders.filter((order) => hasKnownOrderSymbol(this.#scales, order)),\n ),\n nextPageToken: res.nextPageToken,\n };\n }\n\n /**\n * Returns historical orders for the resolved account scope, supporting symbol IDs, trigger ID, side, status, time range, pagination, and attached-risk filters. Results are paginated with the backend nextPageToken.\n */\n async listHistory(\n input: v.InferInput<typeof OrderHistoryInputSchema> = {},\n options?: PolyesterRequestOptions,\n ): Promise<{ orders: Order[]; nextPageToken: string }> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validatedInput = parse(OrderHistoryInputSchema, resolved);\n const res = await this.#readClient.getOrderHistory(\n removeUndefined(validatedInput),\n toConnectCallOptions(options),\n );\n return {\n orders: parse(\n v.array(this.#orderSchema),\n res.orders.filter((order) => hasKnownOrderSymbol(this.#scales, order)),\n ),\n nextPageToken: res.nextPageToken,\n };\n }\n\n /**\n * Evaluates one complete order intent against current market, policy, risk, and balance state without creating an order, reserving funds, or claiming its client order ID.\n */\n async preview(\n input: NewOrderInput,\n options?: PolyesterRequestOptions,\n ): Promise<PreviewOrderResult> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const request = parse(this.#newOrderInputSchema, resolved);\n const response = await this.#writeClient.previewOrder(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n return parse(\n createPreviewOrderResultSchema(this.#scales, request.order.symbolId),\n response,\n );\n }\n\n /**\n * Places a spot order with an explicit market-IOC, limit-GTC, limit-IOC, or limit-FOK execution policy and optional attached risk controls. clientOrderId is the caller-controlled idempotency key and should be reused only for the same logical order.\n */\n async create(\n input: NewOrderInput,\n options?: PolyesterMutationOptions,\n ): Promise<CreateOrderResult> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validatedInput = parse(this.#newOrderInputSchema, resolved);\n const requestPayload = removeUndefined(validatedInput);\n const res = await this.#writeClient.createOrder(\n requestPayload,\n toConnectCallOptions(options),\n );\n return parse(\n createCreateOrderResultSchema(this.#scales, validatedInput.order.symbolId),\n res,\n );\n }\n\n /**\n * Places 1–20 spot orders in one best-effort request. Results preserve item order and report admission as accepted or rejected; accepted orders still require lifecycle reconciliation. Supply a clientOrderId for each item and a stable requestId when an ambiguous batch may be retried.\n */\n async batchCreate(\n input: BatchCreateOrdersInput,\n options?: PolyesterMutationOptions,\n ): Promise<BatchCreateOrdersResult> {\n await this.#scales.ready();\n const resolved = {\n ...resolveAccountScopedInput(input, this.#resolver),\n requestId: input.requestId ?? createMutationRequestId(),\n };\n const request = parse(this.#batchCreateOrdersInputSchema, resolved);\n const response = await this.#writeClient.batchCreateOrders(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n const result = parse(\n createBatchCreateOrdersResultSchema(\n this.#scales,\n request.items.map((item) => item.symbolId),\n ),\n response,\n );\n assertBatchResultCount(\"batchCreate\", input.items.length, result.results.length);\n return result;\n }\n\n /**\n * Requests cancellation of one order in the resolved account scope by order id or client order id, with optional symbol routing. The response acknowledges the cancellation request, not the order's final lifecycle state; reconcile through order reads or realtime before releasing local state. A missing target remains a {@link ResourceNotFoundError}; callers performing desired-state cleanup may treat that error as success when the order could already have filled or left the book.\n */\n async cancel(\n input: v.InferInput<typeof CancelOrderInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<CancelOrderResult> {\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n\n const validated = parse(CancelOrderInputSchema, resolved);\n\n const res = await this.#writeClient.cancelOrder(\n {\n key: validated.key,\n symbolId: validated.symbolId,\n subaccountId: validated.subaccountId,\n },\n toConnectCallOptions(options),\n );\n return parse(CancelOrderResultSchema, res);\n }\n\n /**\n * Cancels 1–50 explicit orders in one best-effort request. Results preserve item order and acknowledge cancellation admission rather than final order state. Supply a stable requestId when an ambiguous batch may be retried.\n */\n async batchCancel(\n input: BatchCancelOrdersInput,\n options?: PolyesterMutationOptions,\n ): Promise<BatchCancelOrdersResult> {\n const resolved = {\n ...resolveAccountScopedInput(input, this.#resolver),\n requestId: input.requestId ?? createMutationRequestId(),\n };\n const request = parse(BatchCancelOrdersInputSchema, resolved);\n const response = await this.#writeClient.batchCancelOrders(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n const result = parse(BatchCancelOrdersResultSchema, response);\n assertBatchResultCount(\"batchCancel\", input.items.length, result.results.length);\n return result;\n }\n\n /**\n * Applies a price, quantity, client id, or attached-risk patch to one open order. The symbol ID routes policy checks and quantity scaling. A requestId is generated when omitted; provide a stable value when retrying the same logical modification.\n */\n async modify(\n input: ModifyOrderInput,\n options?: PolyesterMutationOptions,\n ): Promise<ModifyOrderResult> {\n await this.#scales.ready();\n const resolved = {\n ...resolveAccountScopedInput(input, this.#resolver),\n requestId: input.requestId ?? createMutationRequestId(),\n };\n assertKnownModifyOrderInputKeys(resolved);\n const validated = parse(this.#modifyOrderInputSchema, resolved);\n const res = await this.#writeClient.modifyOrder(\n removeUndefined(validated),\n toConnectCallOptions(options),\n );\n return parse(ModifyOrderResultSchema, res);\n }\n\n /**\n * Replaces 1–50 same-symbol orders and returns an index-stable durable admission receipt. Reuse requestId only when retrying the same logical batch; use the returned batchRequestId for later status reads.\n */\n async batchReplace(\n input: BatchReplaceOrdersInput,\n options?: PolyesterMutationOptions,\n ): Promise<BatchReplaceOrdersResult> {\n await this.#scales.ready();\n for (const item of input.items) {\n assertKnownBatchReplaceOrderItemInputKeys(item);\n }\n const resolved = {\n ...resolveAccountScopedInput(input, this.#resolver),\n requestId: input.requestId ?? createMutationRequestId(),\n };\n const request = parse(\n createBatchReplaceOrdersInputSchema(this.#scales, input.symbolId),\n resolved,\n );\n const response = await this.#writeClient.batchReplaceOrders(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n const result = parse(BatchReplaceOrdersResultSchema, response);\n assertBatchResultCount(\"batchReplace\", input.items.length, result.results.length);\n return result;\n }\n\n /**\n * Reads the durable per-item execution status for a batch replacement receipt.\n */\n async getBatchReplaceStatus(\n input: GetBatchReplaceStatusInput,\n options?: PolyesterRequestOptions,\n ): Promise<GetBatchReplaceStatusResult> {\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const request = parse(GetBatchReplaceStatusInputSchema, resolved);\n const response = await this.#readClient.getBatchReplaceStatus(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n return parse(GetBatchReplaceStatusResultSchema, response);\n }\n\n /**\n * Cancels all matching open orders for the resolved account scope, optionally narrowed by symbol ID and side, with dry-run preview. A requestId is generated when omitted; provide a stable value when retrying the same logical bulk cancellation.\n */\n async cancelAll(\n input: v.InferInput<typeof CancelAllOrdersInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<CancelAllOrdersResponse> {\n const resolved = {\n ...resolveAccountScopedInput(input, this.#resolver),\n requestId: input.requestId ?? createMutationRequestId(),\n };\n const validated = parse(CancelAllOrdersInputSchema, resolved);\n const res = await this.#writeClient.cancelAllOrders(\n removeUndefined(validated),\n toConnectCallOptions(options),\n );\n return parse(CancelAllOrdersResponseSchema, res);\n }\n\n /**\n * Arms, refreshes, or disables the account dead-man switch, optionally scoped by symbol ID and side. timeoutSec 0 disables it; 10–120 arms it. Generate a new requestId for each deliberate heartbeat, but reuse the same ID when retrying one ambiguous heartbeat.\n */\n async cancelAllAfter(\n input: CancelAllAfterInput,\n options?: PolyesterMutationOptions,\n ): Promise<CancelAllAfterResult> {\n const resolved = {\n ...resolveAccountScopedInput(input, this.#resolver),\n requestId: input.requestId ?? createMutationRequestId(),\n };\n const request = parse(CancelAllAfterInputSchema, resolved);\n const response = await this.#writeClient.cancelAllAfter(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n return parse(CancelAllAfterResultSchema, response);\n }\n\n /**\n * Fetches one order by id or client order id and returns its order, trades, and transfer details when found. Returns null when the requested order is not found.\n */\n async getDetails(\n input: v.InferInput<typeof GetOrderDetailsInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<OrderDetails | null> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validatedInput = parse(GetOrderDetailsInputSchema, resolved);\n let res: ProtoRead.GetOrderResponse;\n try {\n res = await this.#readClient.getOrder(\n removeUndefined(validatedInput),\n toConnectCallOptions(options),\n );\n } catch (error) {\n if (isOrderNotFoundError(error)) return null;\n throw error;\n }\n if (!res.order) return null;\n return parse(this.#orderDetailsSchema, res);\n }\n\n /**\n * Subscribes to private order updates on private:spot:orders:{accountId}:proto and emits parsed order records until the returned unsubscribe function is called.\n */\n subscribe(input: SubscribeOrdersInput): () => void {\n const channel = `private:spot:orders:${input.accountId}:proto`;\n const gate = createReadyGate(\n () => this.#scales.ready(),\n (error) => input.onError?.(publicationHandlerErrorContext(channel, error)),\n );\n return this.#realtime.connectProtoChannel({\n channel,\n schema: ProtoRead.OrderSchema,\n onPublication: (data) => {\n gate.run(() => {\n const order = parse(this.#orderSchema, data);\n input.onEvent(order);\n });\n },\n onConnected: () => input.onOpen?.(),\n onDisconnected: () => input.onClose?.(),\n onError: input.onError,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkEA,SAAS,oBAAoB,QAAmB,OAAsC;CAClF,IAAI;EACA,OAAO,QAAQ,MAAM,QAAQ;EAC7B,OAAO;CACX,QAAQ;EACJ,OAAO;CACX;AACJ;AAEA,MAAM,wCAAwC;AAE9C,SAAS,qBAAq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AAa,wBAAwB;EAC1D;EACA,MAAM,UAAU,MAAM,2BAA2B,QAAQ;EACzD,MAAM,WAAW,MAAM,KAAKH,aAAa,eACrC,gBAAgB,OAAO,GACvB,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,4BAA4B,QAAQ;CACrD;;;;CAKA,MAAM,WACF,OACA,SAC4B;EAC5B,MAAM,KAAKI,QAAQ,MAAM;EACzB,MAAM,WAAW,0BAA0B,OAAO,KAAKD,SAAS;EAChE,MAAM,iBAAiB,MAAM,4BAA4B,QAAQ;EACjE,IAAI;EACJ,IAAI;GACA,MAAM,MAAM,KAAKL,YAAY,SACzB,gBAAgB,cAAc,GAC9B,qBAAqB,OAAO,CAChC;EACJ,SAAS,OAAO;GACZ,IAAI,qBAAqB,KAAK,GAAG,OAAO;GACxC,MAAM;EACV;EACA,IAAI,CAAC,IAAI,OAAO,OAAO;EACvB,OAAO,MAAM,KAAKQ,qBAAqB,GAAG;CAC9C;;;;CAKA,UAAU,OAAyC;EAC/C,MAAM,UAAU,uBAAuB,MAAM,UAAU;EACvD,MAAM,OAAO,sBACH,KAAKF,QAAQ,MAAM,IACxB,UAAU,MAAM,UAAU,+BAA+B,SAAS,KAAK,CAAC,CAC7E;EACA,OAAO,KAAKF,UAAU,oBAAoB;GACtC;GACA,QAAQQ;GACR,gBAAgB,SAAS;IACrB,KAAK,UAAU;KACX,MAAM,QAAQ,MAAM,KAAKL,cAAc,IAAI;KAC3C,MAAM,QAAQ,KAAK;IACvB,CAAC;GACL;GACA,mBAAmB,MAAM,SAAS;GAClC,sBAAsB,MAAM,UAAU;GACtC,SAAS,MAAM;EACnB,CAAC;CACL;AACJ"}
|
|
@@ -18,7 +18,7 @@ declare class ApiKeyPoliciesService {
|
|
|
18
18
|
*/
|
|
19
19
|
get(input: v.InferInput<typeof GetApiKeyPolicyInputSchema>, options?: PolyesterRequestOptions): Promise<ApiKeyPolicy>;
|
|
20
20
|
/**
|
|
21
|
-
* Creates an API key policy template with market
|
|
21
|
+
* Creates an API key policy template with a spot-market scope, allowed actions, and optional immediate assignment to a key.
|
|
22
22
|
*/
|
|
23
23
|
create(input: v.InferInput<typeof CreateApiKeyPolicyInputSchema>, options?: PolyesterMutationOptions): Promise<ApiKeyPolicy>;
|
|
24
24
|
/**
|
|
@@ -30,7 +30,7 @@ declare class ApiKeyPoliciesService {
|
|
|
30
30
|
*/
|
|
31
31
|
delete(policyId: string, options?: PolyesterMutationOptions): Promise<void>;
|
|
32
32
|
/**
|
|
33
|
-
* Attaches a policy to an API key
|
|
33
|
+
* Attaches a policy to an API key. Passing a null policyId clears the binding and leaves the key with no permissions.
|
|
34
34
|
*/
|
|
35
35
|
apply(input: v.InferInput<typeof ApplyApiKeyPolicyInputSchema>, options?: PolyesterMutationOptions): Promise<void>;
|
|
36
36
|
}
|
|
@@ -36,7 +36,7 @@ var ApiKeyPoliciesService = class {
|
|
|
36
36
|
return parse(ApiKeyPolicySchema, res.policy);
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
|
-
* Creates an API key policy template with market
|
|
39
|
+
* Creates an API key policy template with a spot-market scope, allowed actions, and optional immediate assignment to a key.
|
|
40
40
|
*/
|
|
41
41
|
async create(input, options) {
|
|
42
42
|
const validatedInput = parse(CreateApiKeyPolicyInputSchema, input);
|
|
@@ -61,7 +61,7 @@ var ApiKeyPoliciesService = class {
|
|
|
61
61
|
await this.#client.deleteApiPolicy({ policyId: validatedPolicyId }, toConnectCallOptions(options));
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
|
-
* Attaches a policy to an API key
|
|
64
|
+
* Attaches a policy to an API key. Passing a null policyId clears the binding and leaves the key with no permissions.
|
|
65
65
|
*/
|
|
66
66
|
async apply(input, options) {
|
|
67
67
|
const validatedInput = parse(ApplyApiKeyPolicyInputSchema, input);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-key-policies.js","names":["#client","Proto.PolicyService"],"sources":["../../../../src/services/policies/api-key-policies/api-key-policies.ts"],"sourcesContent":["import * as Proto from \"../../../gen/auth/v1/policies_pb.js\";\nimport { createClient, type Client, type Transport } from \"@connectrpc/connect\";\nimport type * as v from \"valibot\";\nimport { parse } from \"../../../shared/validation.js\";\nimport { removeUndefined } from \"../../../utils/remove-undefined.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../../shared/request-options.js\";\nimport {\n ApiKeyPolicySchema,\n ListApiKeyPoliciesResponseSchema,\n CreateApiKeyPolicyInputSchema,\n UpdateApiKeyPolicyInputSchema,\n ApplyApiKeyPolicyInputSchema,\n DEFAULT_API_KEY_POLICY,\n type ApiKeyPolicy,\n ListApiKeyPoliciesInputSchema,\n GetApiKeyPolicyInputSchema,\n} from \"./api-key-policies.schemas.js\";\nimport { PolicyIdSchema } from \"../shared.js\";\n\n/**\n * Manages reusable API key policy templates and their assignment to API keys.\n */\nexport class ApiKeyPoliciesService {\n #client: Client<typeof Proto.PolicyService>;\n\n constructor(transport: Transport) {\n this.#client = createClient(Proto.PolicyService, transport);\n }\n\n /**\n * Returns API key policy templates available to the caller.\n */\n async list(\n input: v.InferInput<typeof ListApiKeyPoliciesInputSchema> = {},\n options?: PolyesterRequestOptions,\n ): Promise<ApiKeyPolicy[]> {\n const request = parse(ListApiKeyPoliciesInputSchema, input);\n const res = await this.#client.listApiPolicies(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n return parse(ListApiKeyPoliciesResponseSchema, res);\n }\n\n /**\n * Fetches an API key policy by base58 policy ID, falling back to the SDK default no-permissions policy when no ID or policy is returned.\n */\n async get(\n input: v.InferInput<typeof GetApiKeyPolicyInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<ApiKeyPolicy> {\n const { policyId, keyId } = parse(GetApiKeyPolicyInputSchema, input);\n if (!policyId) return DEFAULT_API_KEY_POLICY;\n const res = await this.#client.getApiPolicy(\n removeUndefined({ policyId, keyId }),\n toConnectCallOptions(options),\n );\n if (!res.policy) return DEFAULT_API_KEY_POLICY;\n return parse(ApiKeyPolicySchema, res.policy);\n }\n\n /**\n * Creates an API key policy template with market
|
|
1
|
+
{"version":3,"file":"api-key-policies.js","names":["#client","Proto.PolicyService"],"sources":["../../../../src/services/policies/api-key-policies/api-key-policies.ts"],"sourcesContent":["import * as Proto from \"../../../gen/auth/v1/policies_pb.js\";\nimport { createClient, type Client, type Transport } from \"@connectrpc/connect\";\nimport type * as v from \"valibot\";\nimport { parse } from \"../../../shared/validation.js\";\nimport { removeUndefined } from \"../../../utils/remove-undefined.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../../shared/request-options.js\";\nimport {\n ApiKeyPolicySchema,\n ListApiKeyPoliciesResponseSchema,\n CreateApiKeyPolicyInputSchema,\n UpdateApiKeyPolicyInputSchema,\n ApplyApiKeyPolicyInputSchema,\n DEFAULT_API_KEY_POLICY,\n type ApiKeyPolicy,\n ListApiKeyPoliciesInputSchema,\n GetApiKeyPolicyInputSchema,\n} from \"./api-key-policies.schemas.js\";\nimport { PolicyIdSchema } from \"../shared.js\";\n\n/**\n * Manages reusable API key policy templates and their assignment to API keys.\n */\nexport class ApiKeyPoliciesService {\n #client: Client<typeof Proto.PolicyService>;\n\n constructor(transport: Transport) {\n this.#client = createClient(Proto.PolicyService, transport);\n }\n\n /**\n * Returns API key policy templates available to the caller.\n */\n async list(\n input: v.InferInput<typeof ListApiKeyPoliciesInputSchema> = {},\n options?: PolyesterRequestOptions,\n ): Promise<ApiKeyPolicy[]> {\n const request = parse(ListApiKeyPoliciesInputSchema, input);\n const res = await this.#client.listApiPolicies(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n return parse(ListApiKeyPoliciesResponseSchema, res);\n }\n\n /**\n * Fetches an API key policy by base58 policy ID, falling back to the SDK default no-permissions policy when no ID or policy is returned.\n */\n async get(\n input: v.InferInput<typeof GetApiKeyPolicyInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<ApiKeyPolicy> {\n const { policyId, keyId } = parse(GetApiKeyPolicyInputSchema, input);\n if (!policyId) return DEFAULT_API_KEY_POLICY;\n const res = await this.#client.getApiPolicy(\n removeUndefined({ policyId, keyId }),\n toConnectCallOptions(options),\n );\n if (!res.policy) return DEFAULT_API_KEY_POLICY;\n return parse(ApiKeyPolicySchema, res.policy);\n }\n\n /**\n * Creates an API key policy template with a spot-market scope, allowed actions, and optional immediate assignment to a key.\n */\n async create(\n input: v.InferInput<typeof CreateApiKeyPolicyInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<ApiKeyPolicy> {\n const validatedInput = parse(CreateApiKeyPolicyInputSchema, input);\n const res = await this.#client.createApiPolicy(\n removeUndefined(validatedInput),\n toConnectCallOptions(options),\n );\n if (!res.policy) throw new Error(\"Failed to create API key policy\");\n return parse(ApiKeyPolicySchema, res.policy);\n }\n\n /**\n * Updates selected API key policy fields using optimistic concurrency.\n */\n async update(\n input: v.InferInput<typeof UpdateApiKeyPolicyInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<ApiKeyPolicy> {\n const validatedInput = parse(UpdateApiKeyPolicyInputSchema, input);\n const res = await this.#client.updateApiPolicy(\n removeUndefined(validatedInput),\n toConnectCallOptions(options),\n );\n if (!res.policy) throw new Error(\"Failed to update API key policy\");\n return parse(ApiKeyPolicySchema, res.policy);\n }\n\n /**\n * Deletes an API key policy template when it is not in use.\n */\n async delete(policyId: string, options?: PolyesterMutationOptions): Promise<void> {\n const validatedPolicyId = parse(PolicyIdSchema, policyId);\n await this.#client.deleteApiPolicy(\n { policyId: validatedPolicyId },\n toConnectCallOptions(options),\n );\n }\n\n /**\n * Attaches a policy to an API key. Passing a null policyId clears the binding and leaves the key with no permissions.\n */\n async apply(\n input: v.InferInput<typeof ApplyApiKeyPolicyInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<void> {\n const validatedInput = parse(ApplyApiKeyPolicyInputSchema, input);\n await this.#client.setApiKeyPolicy(\n removeUndefined(validatedInput),\n toConnectC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