@polyester/sdk 0.8.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 +8 -0
- package/dist/catalogs/readers.js +1 -1
- package/dist/gen/auth/v1/policies_pb.d.ts +28 -10
- package/dist/gen/auth/v1/policies_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/policies_pb.js +37 -31
- 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 +11 -11
- package/dist/gen/orders/v1/orders_pb.js +1 -1
- package/dist/gen/orders/v1/orders_pb.js.map +1 -1
- package/dist/gen/triggers/v1/triggers_pb.d.ts +6 -12
- package/dist/gen/triggers/v1/triggers_pb.d.ts.map +1 -1
- package/dist/gen/triggers/v1/triggers_pb.js +1 -1
- package/dist/gen/triggers/v1/triggers_pb.js.map +1 -1
- package/dist/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/lifecycle/lifecycle.schemas.d.ts +42 -42
- 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/orders-batch.schemas.d.ts +22 -22
- 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 +25 -25
- 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.js +1 -1
- package/dist/services/orders/orders-output.schemas.d.ts +6 -6
- package/dist/services/orders/orders-risk.schemas.js +1 -1
- package/dist/services/orders/orders.d.ts +4 -4
- package/dist/services/orders/orders.d.ts.map +1 -1
- package/dist/services/orders/orders.js +7 -7
- package/dist/services/orders/orders.js.map +1 -1
- package/dist/services/policies/api-key-policies/api-key-policies.schemas.d.ts +15 -15
- package/dist/services/policies/shared.d.ts.map +1 -1
- package/dist/services/policies/shared.js +2 -1
- package/dist/services/policies/shared.js.map +1 -1
- package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.d.ts +9 -9
- package/dist/services/shared.js +4 -1
- package/dist/services/shared.js.map +1 -1
- package/dist/services/subaccounts/subaccounts.schemas.d.ts +5 -5
- 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 +37 -33
- package/dist/services/triggers/trigger-input.schemas.d.ts.map +1 -1
- package/dist/services/triggers/trigger-input.schemas.js +8 -8
- package/dist/services/triggers/trigger-input.schemas.js.map +1 -1
- package/dist/services/triggers/triggers-output.schemas.d.ts +18 -19
- 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.d.ts +2 -2
- package/dist/services/triggers/triggers.js +2 -2
- package/dist/services/triggers/triggers.js.map +1 -1
- package/dist/shared/decimal-surface.js +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,S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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,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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"../../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 { AccountScopeInputEntries, accountScopeToSubaccountId } from "../../shared/account-scope.js";
|
|
7
6
|
import { PROTOBUF_UINT32_MAX } from "../../shared/wire-bounds.js";
|
|
7
|
+
import { AccountScopeInputEntries, accountScopeToSubaccountId } from "../../shared/account-scope.js";
|
|
8
8
|
import { positiveDecimalInputToScaled } from "../../shared/decimal-surface.js";
|
|
9
9
|
import { MODIFY_BEHAVIOR_VALUES, ModifyActionCodec, ModifyBehaviorCodec } from "./orders.codecs.js";
|
|
10
10
|
import { createRequiredRiskPolicyInputSchema } from "./orders-risk.schemas.js";
|
|
@@ -74,7 +74,7 @@ declare function createOrderSchema(scales: SdkScales): v.SchemaWithPipe<readonly
|
|
|
74
74
|
}, undefined>, undefined>;
|
|
75
75
|
readonly origin: v.OptionalSchema<v.ObjectSchema<{
|
|
76
76
|
readonly scope: v.SchemaWithPipe<readonly [v.EnumSchema<typeof OrderOriginScope, undefined>, v.TransformAction<OrderOriginScope, "unspecified" | "direct" | "attached_risk" | "standalone_trigger" | "system">]>;
|
|
77
|
-
readonly triggerType: v.SchemaWithPipe<readonly [v.EnumSchema<typeof OrderTriggerType, undefined>, v.TransformAction<OrderTriggerType, "unspecified" | "
|
|
77
|
+
readonly triggerType: v.SchemaWithPipe<readonly [v.EnumSchema<typeof OrderTriggerType, undefined>, v.TransformAction<OrderTriggerType, "unspecified" | "twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop">]>;
|
|
78
78
|
readonly triggerId: v.SchemaWithPipe<readonly [v.OptionalSchema<v.BigintSchema<undefined>, undefined>, v.TransformAction<bigint | undefined, string | undefined>]>;
|
|
79
79
|
readonly parentOrderId: v.SchemaWithPipe<readonly [v.OptionalSchema<v.BigintSchema<undefined>, undefined>, v.TransformAction<bigint | undefined, string | undefined>]>;
|
|
80
80
|
readonly childSeq: v.NumberSchema<undefined>;
|
|
@@ -155,7 +155,7 @@ declare function createOrderSchema(scales: SdkScales): v.SchemaWithPipe<readonly
|
|
|
155
155
|
} | undefined;
|
|
156
156
|
origin?: {
|
|
157
157
|
scope: "unspecified" | "direct" | "attached_risk" | "standalone_trigger" | "system";
|
|
158
|
-
triggerType: "unspecified" | "
|
|
158
|
+
triggerType: "unspecified" | "twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop";
|
|
159
159
|
triggerId?: string | undefined;
|
|
160
160
|
parentOrderId?: string | undefined;
|
|
161
161
|
childSeq: number;
|
|
@@ -174,7 +174,7 @@ declare function createOrderSchema(scales: SdkScales): v.SchemaWithPipe<readonly
|
|
|
174
174
|
marketClientRefPrice?: string | undefined;
|
|
175
175
|
origin?: {
|
|
176
176
|
scope: "unspecified" | "direct" | "attached_risk" | "standalone_trigger" | "system";
|
|
177
|
-
triggerType: "unspecified" | "
|
|
177
|
+
triggerType: "unspecified" | "twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop";
|
|
178
178
|
triggerId?: string | undefined;
|
|
179
179
|
parentOrderId?: string | undefined;
|
|
180
180
|
childSeq: number;
|
|
@@ -348,7 +348,7 @@ declare function createOrderDetailsSchema(scales: SdkScales): v.ObjectSchema<{
|
|
|
348
348
|
}, undefined>, undefined>;
|
|
349
349
|
readonly origin: v.OptionalSchema<v.ObjectSchema<{
|
|
350
350
|
readonly scope: v.SchemaWithPipe<readonly [v.EnumSchema<typeof OrderOriginScope, undefined>, v.TransformAction<OrderOriginScope, "unspecified" | "direct" | "attached_risk" | "standalone_trigger" | "system">]>;
|
|
351
|
-
readonly triggerType: v.SchemaWithPipe<readonly [v.EnumSchema<typeof OrderTriggerType, undefined>, v.TransformAction<OrderTriggerType, "unspecified" | "
|
|
351
|
+
readonly triggerType: v.SchemaWithPipe<readonly [v.EnumSchema<typeof OrderTriggerType, undefined>, v.TransformAction<OrderTriggerType, "unspecified" | "twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop">]>;
|
|
352
352
|
readonly triggerId: v.SchemaWithPipe<readonly [v.OptionalSchema<v.BigintSchema<undefined>, undefined>, v.TransformAction<bigint | undefined, string | undefined>]>;
|
|
353
353
|
readonly parentOrderId: v.SchemaWithPipe<readonly [v.OptionalSchema<v.BigintSchema<undefined>, undefined>, v.TransformAction<bigint | undefined, string | undefined>]>;
|
|
354
354
|
readonly childSeq: v.NumberSchema<undefined>;
|
|
@@ -429,7 +429,7 @@ declare function createOrderDetailsSchema(scales: SdkScales): v.ObjectSchema<{
|
|
|
429
429
|
} | undefined;
|
|
430
430
|
origin?: {
|
|
431
431
|
scope: "unspecified" | "direct" | "attached_risk" | "standalone_trigger" | "system";
|
|
432
|
-
triggerType: "unspecified" | "
|
|
432
|
+
triggerType: "unspecified" | "twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop";
|
|
433
433
|
triggerId?: string | undefined;
|
|
434
434
|
parentOrderId?: string | undefined;
|
|
435
435
|
childSeq: number;
|
|
@@ -448,7 +448,7 @@ declare function createOrderDetailsSchema(scales: SdkScales): v.ObjectSchema<{
|
|
|
448
448
|
marketClientRefPrice?: string | undefined;
|
|
449
449
|
origin?: {
|
|
450
450
|
scope: "unspecified" | "direct" | "attached_risk" | "standalone_trigger" | "system";
|
|
451
|
-
triggerType: "unspecified" | "
|
|
451
|
+
triggerType: "unspecified" | "twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop";
|
|
452
452
|
triggerId?: string | undefined;
|
|
453
453
|
parentOrderId?: string | undefined;
|
|
454
454
|
childSeq: number;
|
|
@@ -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[];
|
|
@@ -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
|
}
|
|
@@ -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. 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 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,MAAM,IAAI,MACN,GAAG,UAAU,YAAY,SAAS,eAAe,UAAU,kBAC/D;AAER;;;;AAKA,IAAa,gBAAb,MAA2B;CACvB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,YACI,WACA,UACA,UACA,QACF;EACE,KAAKA,cAAc,aAAaC,mBAA6B,SAAS;EACtE,KAAKC,eAAe,aAAaC,iBAA0B,SAAS;EACpE,KAAKC,YAAY;EACjB,KAAKC,YAAY;EACjB,KAAKC,UAAU;EACf,KA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,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,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,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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"}
|
|
@@ -24,7 +24,7 @@ declare const ApiKeyPolicySchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
24
24
|
readonly name: v.StringSchema<undefined>;
|
|
25
25
|
readonly description: v.StringSchema<undefined>;
|
|
26
26
|
readonly spotMarkets: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
27
|
-
readonly
|
|
27
|
+
readonly symbolId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>;
|
|
28
28
|
}, undefined>, undefined>, readonly []>;
|
|
29
29
|
readonly spotMarketScope: v.SchemaWithPipe<readonly [v.EnumSchema<typeof MarketScope_Value, undefined>, v.TransformAction<MarketScope_Value, DecodedEnum<"all" | "allowlist">>]>;
|
|
30
30
|
readonly actions: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ArraySchema<v.EnumSchema<typeof PolicyAction, undefined>, undefined>, readonly []>, v.TransformAction<v.EnumValues<typeof PolicyAction>[], DecodedEnum<"trade-spot" | "internal-transfer" | "external-withdraw" | "read-balances" | "read-spot" | "read-internal-transfers" | "read-address-book" | "manage-address-book">[]>]>;
|
|
@@ -47,7 +47,7 @@ declare const ApiKeyPolicySchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
47
47
|
name: string;
|
|
48
48
|
description: string;
|
|
49
49
|
spotMarkets: {
|
|
50
|
-
|
|
50
|
+
symbolId: number;
|
|
51
51
|
}[];
|
|
52
52
|
spotMarketScope: DecodedEnum<"all" | "allowlist">;
|
|
53
53
|
actions: DecodedEnum<"trade-spot" | "internal-transfer" | "external-withdraw" | "read-balances" | "read-spot" | "read-internal-transfers" | "read-address-book" | "manage-address-book">[];
|
|
@@ -66,7 +66,7 @@ declare const ApiKeyPolicySchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
66
66
|
name: string;
|
|
67
67
|
description: string;
|
|
68
68
|
spotMarkets: {
|
|
69
|
-
|
|
69
|
+
symbolId: number;
|
|
70
70
|
}[];
|
|
71
71
|
spotMarketScope: DecodedEnum<"all" | "allowlist">;
|
|
72
72
|
actions: DecodedEnum<"trade-spot" | "internal-transfer" | "external-withdraw" | "read-balances" | "read-spot" | "read-internal-transfers" | "read-address-book" | "manage-address-book">[];
|
|
@@ -82,7 +82,7 @@ declare const ListApiKeyPoliciesResponseSchema: v.SchemaWithPipe<readonly [v.Obj
|
|
|
82
82
|
readonly name: v.StringSchema<undefined>;
|
|
83
83
|
readonly description: v.StringSchema<undefined>;
|
|
84
84
|
readonly spotMarkets: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
85
|
-
readonly
|
|
85
|
+
readonly symbolId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>;
|
|
86
86
|
}, undefined>, undefined>, readonly []>;
|
|
87
87
|
readonly spotMarketScope: v.SchemaWithPipe<readonly [v.EnumSchema<typeof MarketScope_Value, undefined>, v.TransformAction<MarketScope_Value, DecodedEnum<"all" | "allowlist">>]>;
|
|
88
88
|
readonly actions: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ArraySchema<v.EnumSchema<typeof PolicyAction, undefined>, undefined>, readonly []>, v.TransformAction<v.EnumValues<typeof PolicyAction>[], DecodedEnum<"trade-spot" | "internal-transfer" | "external-withdraw" | "read-balances" | "read-spot" | "read-internal-transfers" | "read-address-book" | "manage-address-book">[]>]>;
|
|
@@ -105,7 +105,7 @@ declare const ListApiKeyPoliciesResponseSchema: v.SchemaWithPipe<readonly [v.Obj
|
|
|
105
105
|
name: string;
|
|
106
106
|
description: string;
|
|
107
107
|
spotMarkets: {
|
|
108
|
-
|
|
108
|
+
symbolId: number;
|
|
109
109
|
}[];
|
|
110
110
|
spotMarketScope: DecodedEnum<"all" | "allowlist">;
|
|
111
111
|
actions: DecodedEnum<"trade-spot" | "internal-transfer" | "external-withdraw" | "read-balances" | "read-spot" | "read-internal-transfers" | "read-address-book" | "manage-address-book">[];
|
|
@@ -124,7 +124,7 @@ declare const ListApiKeyPoliciesResponseSchema: v.SchemaWithPipe<readonly [v.Obj
|
|
|
124
124
|
name: string;
|
|
125
125
|
description: string;
|
|
126
126
|
spotMarkets: {
|
|
127
|
-
|
|
127
|
+
symbolId: number;
|
|
128
128
|
}[];
|
|
129
129
|
spotMarketScope: DecodedEnum<"all" | "allowlist">;
|
|
130
130
|
actions: DecodedEnum<"trade-spot" | "internal-transfer" | "external-withdraw" | "read-balances" | "read-spot" | "read-internal-transfers" | "read-address-book" | "manage-address-book">[];
|
|
@@ -141,7 +141,7 @@ declare const ListApiKeyPoliciesResponseSchema: v.SchemaWithPipe<readonly [v.Obj
|
|
|
141
141
|
name: string;
|
|
142
142
|
description: string;
|
|
143
143
|
spotMarkets: {
|
|
144
|
-
|
|
144
|
+
symbolId: number;
|
|
145
145
|
}[];
|
|
146
146
|
spotMarketScope: DecodedEnum<"all" | "allowlist">;
|
|
147
147
|
actions: DecodedEnum<"trade-spot" | "internal-transfer" | "external-withdraw" | "read-balances" | "read-spot" | "read-internal-transfers" | "read-address-book" | "manage-address-book">[];
|
|
@@ -157,7 +157,7 @@ declare const ListApiKeyPoliciesResponseSchema: v.SchemaWithPipe<readonly [v.Obj
|
|
|
157
157
|
name: string;
|
|
158
158
|
description: string;
|
|
159
159
|
spotMarkets: {
|
|
160
|
-
|
|
160
|
+
symbolId: number;
|
|
161
161
|
}[];
|
|
162
162
|
spotMarketScope: DecodedEnum<"all" | "allowlist">;
|
|
163
163
|
actions: DecodedEnum<"trade-spot" | "internal-transfer" | "external-withdraw" | "read-balances" | "read-spot" | "read-internal-transfers" | "read-address-book" | "manage-address-book">[];
|
|
@@ -171,7 +171,7 @@ declare const CreateApiKeyPolicyInputSchema: v.SchemaWithPipe<readonly [v.Strict
|
|
|
171
171
|
readonly name: v.StringSchema<undefined>;
|
|
172
172
|
readonly description: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
173
173
|
readonly spotMarkets: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
174
|
-
readonly
|
|
174
|
+
readonly symbolId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>;
|
|
175
175
|
}, undefined>, undefined>, readonly []>;
|
|
176
176
|
readonly spotMarketScope: v.SchemaWithPipe<readonly [v.PicklistSchema<readonly ["all", "allowlist"], undefined>, v.TransformAction<"all" | "allowlist", MarketScope_Value.ALL | MarketScope_Value.ALLOWLIST>]>;
|
|
177
177
|
readonly actions: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ArraySchema<v.PicklistSchema<readonly ["trade-spot", "internal-transfer", "external-withdraw", "read-balances", "read-spot", "read-internal-transfers", "read-address-book", "manage-address-book"], undefined>, undefined>, readonly []>, v.TransformAction<("trade-spot" | "internal-transfer" | "external-withdraw" | "read-balances" | "read-spot" | "read-internal-transfers" | "read-address-book" | "manage-address-book")[], (PolicyAction.TRADE_SPOT | PolicyAction.INTERNAL_TRANSFER | PolicyAction.EXTERNAL_WITHDRAW | PolicyAction.READ_BALANCES | PolicyAction.READ_SPOT | PolicyAction.READ_INTERNAL_TRANSFERS | PolicyAction.READ_ADDRESS_BOOK | PolicyAction.MANAGE_ADDRESS_BOOK)[]>]>;
|
|
@@ -181,7 +181,7 @@ declare const CreateApiKeyPolicyInputSchema: v.SchemaWithPipe<readonly [v.Strict
|
|
|
181
181
|
name: string;
|
|
182
182
|
description: string;
|
|
183
183
|
spotMarkets: {
|
|
184
|
-
|
|
184
|
+
symbolId: number;
|
|
185
185
|
}[];
|
|
186
186
|
spotMarketScope: MarketScope_Value.ALL | MarketScope_Value.ALLOWLIST;
|
|
187
187
|
actions: (PolicyAction.TRADE_SPOT | PolicyAction.INTERNAL_TRANSFER | PolicyAction.EXTERNAL_WITHDRAW | PolicyAction.READ_BALANCES | PolicyAction.READ_SPOT | PolicyAction.READ_INTERNAL_TRANSFERS | PolicyAction.READ_ADDRESS_BOOK | PolicyAction.MANAGE_ADDRESS_BOOK)[];
|
|
@@ -192,7 +192,7 @@ declare const CreateApiKeyPolicyInputSchema: v.SchemaWithPipe<readonly [v.Strict
|
|
|
192
192
|
name: string;
|
|
193
193
|
description: string;
|
|
194
194
|
spotMarkets: {
|
|
195
|
-
|
|
195
|
+
symbolId: number;
|
|
196
196
|
}[];
|
|
197
197
|
spotMarketScope: MarketScope_Value.ALL | MarketScope_Value.ALLOWLIST;
|
|
198
198
|
actions: (PolicyAction.TRADE_SPOT | PolicyAction.INTERNAL_TRANSFER | PolicyAction.EXTERNAL_WITHDRAW | PolicyAction.READ_BALANCES | PolicyAction.READ_SPOT | PolicyAction.READ_INTERNAL_TRANSFERS | PolicyAction.READ_ADDRESS_BOOK | PolicyAction.MANAGE_ADDRESS_BOOK)[];
|
|
@@ -207,7 +207,7 @@ declare const UpdateApiKeyPolicyInputSchema: v.SchemaWithPipe<readonly [v.Strict
|
|
|
207
207
|
readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
208
208
|
readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
209
209
|
readonly spotMarkets: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
210
|
-
readonly
|
|
210
|
+
readonly symbolId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>;
|
|
211
211
|
}, undefined>, undefined>, undefined>;
|
|
212
212
|
readonly spotMarketScope: v.OptionalSchema<v.PicklistSchema<readonly ["all", "allowlist"], undefined>, undefined>;
|
|
213
213
|
readonly actions: v.OptionalSchema<v.ArraySchema<v.PicklistSchema<readonly ["trade-spot", "internal-transfer", "external-withdraw", "read-balances", "read-spot", "read-internal-transfers", "read-address-book", "manage-address-book"], undefined>, undefined>, undefined>;
|
|
@@ -218,7 +218,7 @@ declare const UpdateApiKeyPolicyInputSchema: v.SchemaWithPipe<readonly [v.Strict
|
|
|
218
218
|
name?: string | undefined;
|
|
219
219
|
description?: string | undefined;
|
|
220
220
|
spotMarkets?: {
|
|
221
|
-
|
|
221
|
+
symbolId: number;
|
|
222
222
|
}[] | undefined;
|
|
223
223
|
spotMarketScope?: "all" | "allowlist" | undefined;
|
|
224
224
|
actions?: ("trade-spot" | "internal-transfer" | "external-withdraw" | "read-balances" | "read-spot" | "read-internal-transfers" | "read-address-book" | "manage-address-book")[] | undefined;
|
|
@@ -229,7 +229,7 @@ declare const UpdateApiKeyPolicyInputSchema: v.SchemaWithPipe<readonly [v.Strict
|
|
|
229
229
|
name?: string | undefined;
|
|
230
230
|
description?: string | undefined;
|
|
231
231
|
spotMarkets?: {
|
|
232
|
-
|
|
232
|
+
symbolId: number;
|
|
233
233
|
}[] | undefined;
|
|
234
234
|
spotMarketScope?: "all" | "allowlist" | undefined;
|
|
235
235
|
actions?: ("trade-spot" | "internal-transfer" | "external-withdraw" | "read-balances" | "read-spot" | "read-internal-transfers" | "read-address-book" | "manage-address-book")[] | undefined;
|
|
@@ -242,7 +242,7 @@ declare const UpdateApiKeyPolicyInputSchema: v.SchemaWithPipe<readonly [v.Strict
|
|
|
242
242
|
description: string;
|
|
243
243
|
} & {
|
|
244
244
|
spotMarkets: {
|
|
245
|
-
|
|
245
|
+
symbolId: number;
|
|
246
246
|
}[];
|
|
247
247
|
} & {
|
|
248
248
|
spotMarketScope: MarketScope_Value.ALL | MarketScope_Value.ALLOWLIST;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","names":[],"sources":["../../../src/services/policies/shared.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"shared.d.ts","names":[],"sources":["../../../src/services/policies/shared.ts"],"mappings":";;;cAuBa,wBAAsB,EAAA;cAEtB,6BAA2B,EAAA;KAC5B,oBAAoB,EAAE,mBAAmB;KAEzC,eAAe,EAAE,mBAAmB"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { idToBigInt } from "../../utils/base58-id.js";
|
|
2
2
|
import { MarketScope_Value, PolicyAction } from "../../gen/auth/v1/policies_pb.js";
|
|
3
|
+
import { SymbolIdInputSchema } from "../shared.js";
|
|
3
4
|
import * as v from "valibot";
|
|
4
5
|
//#region src/services/policies/shared.ts
|
|
5
|
-
const SpotMarketRuleSchema = v.object({
|
|
6
|
+
const SpotMarketRuleSchema = v.object({ symbolId: SymbolIdInputSchema });
|
|
6
7
|
const POLICY_ACTIONS = [
|
|
7
8
|
"trade-spot",
|
|
8
9
|
"internal-transfer",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","names":["Proto.PolicyAction","Proto.MarketScope_Value"],"sources":["../../../src/services/policies/shared.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport * as Proto from \"../../gen/auth/v1/policies_pb.js\";\nimport { idToBigInt } from \"../../utils/base58-id.js\";\n\nexport const SpotMarketRuleSchema = v.object({\n
|
|
1
|
+
{"version":3,"file":"shared.js","names":["Proto.PolicyAction","Proto.MarketScope_Value"],"sources":["../../../src/services/policies/shared.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport * as Proto from \"../../gen/auth/v1/policies_pb.js\";\nimport { idToBigInt } from \"../../utils/base58-id.js\";\nimport { SymbolIdInputSchema } from \"../shared.js\";\n\nexport const SpotMarketRuleSchema = v.object({\n symbolId: SymbolIdInputSchema,\n});\n\nexport const POLICY_ACTIONS = [\n \"trade-spot\",\n \"internal-transfer\",\n \"external-withdraw\",\n \"read-balances\",\n \"read-spot\",\n \"read-internal-transfers\",\n \"read-address-book\",\n \"manage-address-book\",\n] as const;\n\nexport const POLICY_MARKET_SCOPES = [\"all\", \"allowlist\"] as const;\n\nexport const ProtoPolicyActionEnumSchema = v.enum(Proto.PolicyAction);\nexport const PolicyActionEnumSchema = v.picklist(POLICY_ACTIONS);\nexport const ProtoPolicyMarketScopeEnumSchema = v.enum(Proto.MarketScope_Value);\nexport const PolicyMarketScopeEnumSchema = v.picklist(POLICY_MARKET_SCOPES);\nexport type PolicyMarketScope = v.InferOutput<typeof PolicyMarketScopeEnumSchema>;\n\nexport type PolicyAction = v.InferOutput<typeof PolicyActionEnumSchema>;\n\nexport const PolicyIdSchema = v.pipe(\n v.string(),\n v.trim(),\n v.minLength(1),\n v.transform((v) => idToBigInt(v, \"policyId\")),\n);\n"],"mappings":";;;;;AAKA,MAAa,uBAAuB,EAAE,OAAO,EACzC,UAAU,oBACd,CAAC;AAED,MAAa,iBAAiB;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;AAEA,MAAa,uBAAuB,CAAC,OAAO,WAAW;AAEvD,MAAa,8BAA8B,EAAE,KAAKA,YAAkB;AACpE,MAAa,yBAAyB,EAAE,SAAS,cAAc;AAC/D,MAAa,mCAAmC,EAAE,KAAKC,iBAAuB;AAC9E,MAAa,8BAA8B,EAAE,SAAS,oBAAoB;AAK1E,MAAa,iBAAiB,EAAE,KAC5B,EAAE,OAAO,GACT,EAAE,KAAK,GACP,EAAE,UAAU,CAAC,GACb,EAAE,WAAW,MAAM,WAAW,GAAG,UAAU,CAAC,CAChD"}
|