@polyester/sdk 0.35.0-devnet-20261110160258 → 0.35.0-devnet-20261110193018

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/README.md +8 -8
  3. package/dist/realtime/client.js +13 -6
  4. package/dist/realtime/client.js.map +1 -1
  5. package/dist/services/candles/candles.schemas.d.ts +10 -10
  6. package/dist/services/heatmap/heatmap.schemas.d.ts +13 -13
  7. package/dist/services/internal-transfers/internal-transfers.schemas.d.ts +3 -3
  8. package/dist/services/lifecycle/lifecycle.schemas.d.ts +79 -79
  9. package/dist/services/market-overview/market-overview.schemas.d.ts +3 -3
  10. package/dist/services/orderbook/orderbook.schemas.d.ts +1 -1
  11. package/dist/services/orders/orders-batch.schemas.d.ts +7 -7
  12. package/dist/services/orders/orders-input.schemas.d.ts +2 -2
  13. package/dist/services/orders/orders-input.schemas.js +1 -1
  14. package/dist/services/orders/orders-input.schemas.js.map +1 -1
  15. package/dist/services/orders/orders-output.schemas.d.ts +12 -12
  16. package/dist/services/rewards/rewards.schemas.d.ts +3 -3
  17. package/dist/services/subaccounts/subaccounts.schemas.d.ts +4 -4
  18. package/dist/services/transfers/transfers.schemas.d.ts +1 -1
  19. package/dist/services/transfers/transfers.schemas.js +1 -1
  20. package/dist/services/transfers/transfers.schemas.js.map +1 -1
  21. package/dist/services/triggers/trigger-input.schemas.d.ts +17 -12
  22. package/dist/services/triggers/trigger-input.schemas.d.ts.map +1 -1
  23. package/dist/services/triggers/trigger-input.schemas.js +26 -9
  24. package/dist/services/triggers/trigger-input.schemas.js.map +1 -1
  25. package/dist/services/triggers/triggers-output.schemas.d.ts +18 -18
  26. package/dist/shared/connect-error-mapping.d.ts.map +1 -1
  27. package/dist/shared/connect-error-mapping.js +2 -1
  28. package/dist/shared/connect-error-mapping.js.map +1 -1
  29. package/dist/shared/errors.d.ts +6 -1
  30. package/dist/shared/errors.d.ts.map +1 -1
  31. package/dist/shared/errors.js +8 -1
  32. package/dist/shared/errors.js.map +1 -1
  33. package/package.json +1 -1
@@ -3,8 +3,13 @@ import { TriggerEventType, TriggerLimitFok, TriggerLimitGtc, TriggerLimitIoc, Tr
3
3
  import { SdkScales } from "../../shared/decimal-surface.js";
4
4
  import * as v from "valibot";
5
5
  //#region src/services/triggers/trigger-input.schemas.d.ts
6
- /** Builds the create-trigger boundary schema using catalog scales keyed by symbol ID. */
7
- declare function createCreateTriggerInputSchema(scales: SdkScales): v.UnionSchema<[v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
6
+ /**
7
+ * Builds the create-trigger boundary schema using catalog scales keyed by symbol ID.
8
+ * The variant is picked by `triggerType` before validating, because a plain union
9
+ * reports the first branch's mismatch (e.g. "Expected stop_loss") instead of the
10
+ * chosen variant's missing or invalid field.
11
+ */
12
+ declare function createCreateTriggerInputSchema(scales: SdkScales): v.LazySchema<v.LazySchema<v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
8
13
  readonly side: v.LiteralSchema<"sell", undefined>;
9
14
  readonly execution: v.VariantSchema<"type", [v.StrictObjectSchema<{
10
15
  readonly type: v.LiteralSchema<"market_ioc", undefined>;
@@ -175,7 +180,7 @@ declare function createCreateTriggerInputSchema(scales: SdkScales): v.UnionSchem
175
180
  selfTradePreventionMode: SelfTradePreventionMode.EXPIRE_MAKER | SelfTradePreventionMode.EXPIRE_TAKER | SelfTradePreventionMode.EXPIRE_BOTH;
176
181
  clientTriggerId: string;
177
182
  };
178
- }>]>, v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
183
+ }>]> | v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
179
184
  readonly side: v.LiteralSchema<"buy", undefined>;
180
185
  readonly execution: v.VariantSchema<"type", [v.StrictObjectSchema<{
181
186
  readonly type: v.LiteralSchema<"market_ioc", undefined>;
@@ -311,7 +316,7 @@ declare function createCreateTriggerInputSchema(scales: SdkScales): v.UnionSchem
311
316
  selfTradePreventionMode: SelfTradePreventionMode.EXPIRE_MAKER | SelfTradePreventionMode.EXPIRE_TAKER | SelfTradePreventionMode.EXPIRE_BOTH;
312
317
  clientTriggerId: string;
313
318
  };
314
- }>]>, v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
319
+ }>]>> | v.LazySchema<v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
315
320
  readonly side: v.LiteralSchema<"sell", undefined>;
316
321
  readonly execution: v.VariantSchema<"type", [v.StrictObjectSchema<{
317
322
  readonly type: v.LiteralSchema<"market_ioc", undefined>;
@@ -482,7 +487,7 @@ declare function createCreateTriggerInputSchema(scales: SdkScales): v.UnionSchem
482
487
  selfTradePreventionMode: SelfTradePreventionMode.EXPIRE_MAKER | SelfTradePreventionMode.EXPIRE_TAKER | SelfTradePreventionMode.EXPIRE_BOTH;
483
488
  clientTriggerId: string;
484
489
  };
485
- }>]>, v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
490
+ }>]> | v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
486
491
  readonly side: v.LiteralSchema<"buy", undefined>;
487
492
  readonly execution: v.VariantSchema<"type", [v.StrictObjectSchema<{
488
493
  readonly type: v.LiteralSchema<"market_ioc", undefined>;
@@ -618,7 +623,7 @@ declare function createCreateTriggerInputSchema(scales: SdkScales): v.UnionSchem
618
623
  selfTradePreventionMode: SelfTradePreventionMode.EXPIRE_MAKER | SelfTradePreventionMode.EXPIRE_TAKER | SelfTradePreventionMode.EXPIRE_BOTH;
619
624
  clientTriggerId: string;
620
625
  };
621
- }>]>, v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
626
+ }>]>> | v.LazySchema<v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
622
627
  readonly side: v.OptionalSchema<v.LiteralSchema<"sell", undefined>, "sell">;
623
628
  readonly limitPrice: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
624
629
  readonly triggerType: v.LiteralSchema<"trailing_stop", undefined>;
@@ -746,7 +751,7 @@ declare function createCreateTriggerInputSchema(scales: SdkScales): v.UnionSchem
746
751
  selfTradePreventionMode: SelfTradePreventionMode.EXPIRE_MAKER | SelfTradePreventionMode.EXPIRE_TAKER | SelfTradePreventionMode.EXPIRE_BOTH;
747
752
  clientTriggerId: string;
748
753
  };
749
- }>]>, v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
754
+ }>]> | v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
750
755
  readonly side: v.LiteralSchema<"buy", undefined>;
751
756
  readonly limitPrice: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
752
757
  readonly triggerType: v.LiteralSchema<"trailing_stop", undefined>;
@@ -882,7 +887,7 @@ declare function createCreateTriggerInputSchema(scales: SdkScales): v.UnionSchem
882
887
  selfTradePreventionMode: SelfTradePreventionMode.EXPIRE_MAKER | SelfTradePreventionMode.EXPIRE_TAKER | SelfTradePreventionMode.EXPIRE_BOTH;
883
888
  clientTriggerId: string;
884
889
  };
885
- }, "limitPrice must be at least activationPrice">]>, v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
890
+ }, "limitPrice must be at least activationPrice">]>> | v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
886
891
  readonly triggerType: v.LiteralSchema<"twap", undefined>;
887
892
  readonly side: v.SchemaWithPipe<readonly [v.PicklistSchema<readonly ["buy", "sell"], undefined>, v.TransformAction<"buy" | "sell", Side.BUY | Side.SELL>]>;
888
893
  readonly durationMs: v.SchemaWithPipe<readonly [v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, v.NumberSchema<undefined>], undefined>, v.TransformAction<string | number, bigint>]>;
@@ -1018,7 +1023,7 @@ declare function createCreateTriggerInputSchema(scales: SdkScales): v.UnionSchem
1018
1023
  selfTradePreventionMode: SelfTradePreventionMode.EXPIRE_MAKER | SelfTradePreventionMode.EXPIRE_TAKER | SelfTradePreventionMode.EXPIRE_BOTH;
1019
1024
  clientTriggerId: string;
1020
1025
  };
1021
- }>]>, v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
1026
+ }>]> | v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
1022
1027
  readonly triggerType: v.LiteralSchema<"ladder", undefined>;
1023
1028
  readonly side: v.SchemaWithPipe<readonly [v.PicklistSchema<readonly ["buy", "sell"], undefined>, v.TransformAction<"buy" | "sell", Side.BUY | Side.SELL>]>;
1024
1029
  readonly priceMin: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
@@ -1101,14 +1106,14 @@ declare function createCreateTriggerInputSchema(scales: SdkScales): v.UnionSchem
1101
1106
  selfTradePreventionMode: SelfTradePreventionMode.EXPIRE_MAKER | SelfTradePreventionMode.EXPIRE_TAKER | SelfTradePreventionMode.EXPIRE_BOTH;
1102
1107
  clientTriggerId: string;
1103
1108
  };
1104
- }, "priceMin must be less than priceMax">]>], undefined>;
1109
+ }, "priceMin must be less than priceMax">]> | v.NeverSchema<`triggerType must be one of ${string}`>>;
1105
1110
  /** Public input for creating a standalone trigger. */
1106
1111
  type CreateTriggerInput = v.InferInput<ReturnType<typeof createCreateTriggerInputSchema>>;
1107
1112
  /** Public filters for listing triggers in an account scope. */
1108
1113
  declare const ListTriggersInputSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
1109
1114
  readonly parentOrderId: v.SchemaWithPipe<readonly [v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, undefined>, v.TransformAction<string | undefined, bigint | undefined>]>;
1110
1115
  readonly symbolId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>, undefined>;
1111
- readonly status: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ArraySchema<v.PicklistSchema<readonly ["created", "armed", "running", "completed", "canceled", "failed", "paused"], undefined>, undefined>, undefined>, v.TransformAction<("failed" | "completed" | "canceled" | "created" | "armed" | "running" | "paused")[] | undefined, (TriggerStatus.STATUS_CREATED | TriggerStatus.STATUS_ARMED | TriggerStatus.STATUS_RUNNING | TriggerStatus.STATUS_COMPLETED | TriggerStatus.STATUS_CANCELED | TriggerStatus.STATUS_FAILED | TriggerStatus.STATUS_PAUSED)[]>]>;
1116
+ readonly status: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ArraySchema<v.PicklistSchema<readonly ["created", "armed", "running", "completed", "canceled", "failed", "paused"], undefined>, undefined>, undefined>, v.TransformAction<("failed" | "canceled" | "completed" | "created" | "armed" | "running" | "paused")[] | undefined, (TriggerStatus.STATUS_CREATED | TriggerStatus.STATUS_ARMED | TriggerStatus.STATUS_RUNNING | TriggerStatus.STATUS_COMPLETED | TriggerStatus.STATUS_CANCELED | TriggerStatus.STATUS_FAILED | TriggerStatus.STATUS_PAUSED)[]>]>;
1112
1117
  readonly triggerType: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["stop_loss", "take_profit", "trailing_stop", "twap", "ladder"], undefined>, undefined>, v.TransformAction<"twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop" | undefined, TriggerType>]>;
1113
1118
  readonly limit: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 1000, undefined>]>, 50>;
1114
1119
  readonly pageToken: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, "">;
@@ -1329,7 +1334,7 @@ declare const ListTriggerEventsInputSchema: v.SchemaWithPipe<readonly [v.StrictO
1329
1334
  readonly triggerId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>;
1330
1335
  }, undefined>, v.TransformAction<{
1331
1336
  limit?: number | undefined;
1332
- eventType?: "failed" | "canceled" | "armed" | "updated" | "fired" | "activated" | "fire_refused" | undefined;
1337
+ eventType?: "failed" | "canceled" | "updated" | "armed" | "fired" | "activated" | "fire_refused" | undefined;
1333
1338
  pageToken: string;
1334
1339
  account?: "active" | "main" | {
1335
1340
  subaccountId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"trigger-input.schemas.d.ts","names":[],"sources":["../../../src/services/triggers/trigger-input.schemas.ts"],"mappings":";;;;;;iBA4WgB,+BAA+B,QAAQ,YAAS,EAAA,aAAA,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8CAe/D,EAAA;;KAGW,qBAAqB,EAAE,WAAW,kBAAkB;;cAGnD,yBAAuB,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAgCxB,oBAAoB,EAAE,kBAAkB;cAEvC,0BAAwB,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;KACzB,qBAAqB,EAAE,kBAAkB;cAExC,uBAAqB,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;KACtB,kBAAkB,EAAE,kBAAkB;cAErC,yBAAuB,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;KACxB,oBAAoB,EAAE,kBAAkB;cAEvC,0BAAwB,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;KAWzB,qBAAqB,EAAE,kBAAkB;iBAErC,+BAA+B,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4DpD,qBAAqB,EAAE,WAAW,kBAAkB;cAEnD,8BAA4B,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;KAiB7B,yBAAyB,EAAE,kBAAkB"}
@@ -44,7 +44,7 @@ function parseMaxSlippagePatch(scales, slippage) {
44
44
  case: "maxSlippageTicks",
45
45
  value: 0n
46
46
  };
47
- return parseMaxSlippage(scales, slippage, MAX_SELLING_SLIPPAGE_BPS);
47
+ return parseMaxSlippage(scales, slippage);
48
48
  }
49
49
  function createConditionalTriggerInputSchema(scales, triggerType) {
50
50
  const sharedEntries = {
@@ -189,15 +189,32 @@ function createLadderTriggerInputSchema(scales) {
189
189
  };
190
190
  }), v.check((output) => output.trigger.strategy.value.priceMinTicks < output.trigger.strategy.value.priceMaxTicks, "priceMin must be less than priceMax"));
191
191
  }
192
- /** Builds the create-trigger boundary schema using catalog scales keyed by symbol ID. */
192
+ function fieldOf(input, key) {
193
+ return typeof input === "object" && input !== null ? input[key] : void 0;
194
+ }
195
+ /** Validates against the side the caller chose, so errors name that side's fields. */
196
+ function bySide([sell, buy]) {
197
+ return v.lazy((input) => fieldOf(input, "side") === "buy" ? buy : sell);
198
+ }
199
+ /**
200
+ * Builds the create-trigger boundary schema using catalog scales keyed by symbol ID.
201
+ * The variant is picked by `triggerType` before validating, because a plain union
202
+ * reports the first branch's mismatch (e.g. "Expected stop_loss") instead of the
203
+ * chosen variant's missing or invalid field.
204
+ */
193
205
  function createCreateTriggerInputSchema(scales) {
194
- return v.union([
195
- ...createConditionalTriggerInputSchema(scales, "stop_loss"),
196
- ...createConditionalTriggerInputSchema(scales, "take_profit"),
197
- ...createTrailingStopTriggerInputSchema(scales),
198
- createTwapTriggerInputSchema(scales),
199
- createLadderTriggerInputSchema(scales)
200
- ]);
206
+ const variants = {
207
+ stop_loss: bySide(createConditionalTriggerInputSchema(scales, "stop_loss")),
208
+ take_profit: bySide(createConditionalTriggerInputSchema(scales, "take_profit")),
209
+ trailing_stop: bySide(createTrailingStopTriggerInputSchema(scales)),
210
+ twap: createTwapTriggerInputSchema(scales),
211
+ ladder: createLadderTriggerInputSchema(scales)
212
+ };
213
+ const unknownVariant = v.never(`triggerType must be one of ${TRIGGER_TYPE_VALUES.join(", ")}`);
214
+ return v.lazy((input) => {
215
+ const triggerType = fieldOf(input, "triggerType");
216
+ return typeof triggerType === "string" && Object.hasOwn(variants, triggerType) ? variants[triggerType] : unknownVariant;
217
+ });
201
218
  }
202
219
  /** Public filters for listing triggers in an account scope. */
203
220
  const ListTriggersInputSchema = v.pipe(v.strictObject({
@@ -1 +1 @@
1
- {"version":3,"file":"trigger-input.schemas.js","names":["TriggerSideCodec"],"sources":["../../../src/services/triggers/trigger-input.schemas.ts"],"sourcesContent":["import * as Proto from \"../../gen/triggers/v1/triggers_pb.js\";\nimport * as ProtoOrders from \"../../gen/orders/v1/orders_pb.js\";\nimport * as v from \"valibot\";\nimport { idInputSchema } from \"../../shared/schemas.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport { positiveDecimalInputToScaled, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport { PROTOBUF_INT64_MAX } from \"../../shared/wire-bounds.js\";\nimport {\n parseOptionalPositiveBigIntLike,\n parseOptionalPositiveIntLike,\n} from \"../../utils/numbers.js\";\nimport { idToBigInt } from \"../../utils/base58-id.js\";\nimport {\n TRIGGER_EVENT_TYPE_VALUES,\n TRIGGER_STATUS_FILTER_VALUES,\n TRIGGER_TYPE_VALUES,\n TriggerEventTypeCodec,\n TriggerSideCodec,\n TriggerTypeCodec,\n TriggerStatusCodec,\n} from \"./triggers.codecs.js\";\nimport { BpsStringOrNumberInputSchema, NoneInputSchema, SymbolIdInputSchema } from \"../shared.js\";\nimport { TriggerPriceSourceInputSchema } from \"../orders/order-enums.codecs.js\";\nimport {\n BaseTriggerFieldsSchema,\n ConditionalExecutionInputSchema,\n DecimalInputStringSchema,\n TriggerSideInputSchema,\n TwapExecutionInputSchema,\n buildConditionalExecution,\n buildTriggerIntentBase,\n buildTwapExecution,\n MaxSlippageInputSchema,\n parseMaxSlippage,\n type MaxSlippageOneof,\n type TrailingDistanceOneof,\n} from \"./trigger-child-order.schemas.js\";\nimport { MAX_SELLING_SLIPPAGE_BPS, parseTrailingDistanceInput } from \"../trailing-oneof-inputs.js\";\n\nconst TriggerTypeSchema = v.picklist(TRIGGER_TYPE_VALUES);\nconst TriggerStatusFilterSchema = v.picklist(TRIGGER_STATUS_FILTER_VALUES);\nconst TriggerEventTypeSchema = v.picklist(TRIGGER_EVENT_TYPE_VALUES);\nconst TriggerIdInputSchema = idInputSchema(\"triggerId\");\n\nconst TriggerScopedInputEntries = {\n triggerId: TriggerIdInputSchema,\n ...AccountScopeInputEntries,\n};\n\nconst TriggerScopedInputSchema = v.pipe(\n v.strictObject(TriggerScopedInputEntries),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\n/** Absolute price distance, as a decimal price string (e.g. \"0.50\"). */\nconst PriceDistanceInputSchema = v.strictObject({\n kind: v.literal(\"distance\"),\n distance: DecimalInputStringSchema,\n});\n\nconst TrailingDistanceInputSchema = v.union([\n PriceDistanceInputSchema,\n BpsStringOrNumberInputSchema,\n]);\n\nconst ActivationPricePatchInputSchema = v.union([DecimalInputStringSchema, NoneInputSchema]);\n\nfunction parseTrailingDistance(\n scales: SdkScales,\n distance: v.InferOutput<typeof TrailingDistanceInputSchema>,\n): TrailingDistanceOneof {\n return parseTrailingDistanceInput(scales, distance, \"trailingDistance\");\n}\n\nfunction parseTwapMilliseconds(\n value: string | number,\n fieldName: \"durationMs\" | \"sliceIntervalMs\",\n minimum: bigint,\n): bigint {\n const parsed = parseOptionalPositiveBigIntLike(value);\n if (parsed === undefined || parsed < minimum || parsed > PROTOBUF_INT64_MAX) {\n throw new Error(\n `${fieldName} must be between ${minimum} and ${PROTOBUF_INT64_MAX} milliseconds`,\n );\n }\n return parsed;\n}\n\nfunction parseMaxSlippagePatch(\n scales: SdkScales,\n slippage: v.InferOutput<typeof MaxSlippageInputSchema>,\n): MaxSlippageOneof {\n if (slippage.kind === \"none\") {\n return { case: \"maxSlippageTicks\", value: 0n };\n }\n // The patch does not say what it modifies, so it takes the cap shared by\n // trailing stops and sells; a buy market child's 10000 bps needs creation.\n return parseMaxSlippage(scales, slippage, MAX_SELLING_SLIPPAGE_BPS);\n}\n\nfunction createConditionalTriggerInputSchema<const TriggerType extends \"stop_loss\" | \"take_profit\">(\n scales: SdkScales,\n triggerType: TriggerType,\n) {\n const sharedEntries = {\n ...BaseTriggerFieldsSchema.entries,\n triggerType: v.literal(triggerType),\n triggerPrice: DecimalInputStringSchema,\n triggerPriceSource: TriggerPriceSourceInputSchema,\n };\n\n const sellInputSchema = v.strictObject({\n ...sharedEntries,\n side: v.literal(\"sell\"),\n execution: ConditionalExecutionInputSchema,\n });\n const buyInputSchema = v.strictObject({\n ...sharedEntries,\n side: v.literal(\"buy\"),\n execution: ConditionalExecutionInputSchema,\n });\n\n function transformInput(\n input: v.InferOutput<typeof sellInputSchema> | v.InferOutput<typeof buyInputSchema>,\n ) {\n const { subaccountId, intent } = buildTriggerIntentBase(input, scales);\n const side = TriggerSideCodec.inputToProto[input.side];\n const strategy = {\n triggerPriceTicks: positiveDecimalInputToScaled(\n \"triggerPrice\",\n input.triggerPrice,\n scales.price(),\n ),\n side,\n child: buildConditionalExecution(input.execution, scales, side),\n triggerPriceSource: input.triggerPriceSource,\n };\n return {\n subaccountId,\n trigger: {\n ...intent,\n strategy:\n triggerType === \"stop_loss\"\n ? ({ case: \"stopLoss\", value: strategy } as const)\n : ({ case: \"takeProfit\", value: strategy } as const),\n },\n };\n }\n\n return [\n v.pipe(\n sellInputSchema,\n v.check(\n (input) => input.feeAsset === ProtoOrders.FeeAsset.QUOTE,\n \"SELL triggers must use the quote fee asset\",\n ),\n v.transform((input: v.InferOutput<typeof sellInputSchema>) => transformInput(input)),\n ),\n v.pipe(\n buyInputSchema,\n v.transform((input: v.InferOutput<typeof buyInputSchema>) => transformInput(input)),\n ),\n ] as const;\n}\n\nfunction createTrailingStopTriggerInputSchema(scales: SdkScales) {\n const sharedEntries = {\n ...BaseTriggerFieldsSchema.entries,\n triggerType: v.literal(\"trailing_stop\"),\n trailingDistance: TrailingDistanceInputSchema,\n activationPrice: v.optional(DecimalInputStringSchema),\n maxSlippage: v.optional(MaxSlippageInputSchema),\n triggerPriceSource: TriggerPriceSourceInputSchema,\n };\n const sellInputSchema = v.strictObject({\n ...sharedEntries,\n side: v.optional(v.literal(\"sell\"), \"sell\"),\n limitPrice: v.optional(v.never()),\n });\n // A buy's child never pays more than `limitPrice`, which also sizes its reserved funds.\n const buyInputSchema = v.strictObject({\n ...sharedEntries,\n side: v.literal(\"buy\"),\n limitPrice: DecimalInputStringSchema,\n });\n\n function transformInput(\n input: v.InferOutput<typeof sellInputSchema> | v.InferOutput<typeof buyInputSchema>,\n ) {\n const { subaccountId, intent } = buildTriggerIntentBase(input, scales);\n return {\n subaccountId,\n trigger: {\n ...intent,\n strategy: {\n case: \"trailingStop\",\n value: {\n trailingDistance: parseTrailingDistance(scales, input.trailingDistance),\n activationPriceTicks:\n input.activationPrice === undefined\n ? 0n\n : positiveDecimalInputToScaled(\n \"activationPrice\",\n input.activationPrice,\n scales.price(),\n ),\n maxSlippage: parseMaxSlippage(\n scales,\n input.maxSlippage,\n MAX_SELLING_SLIPPAGE_BPS,\n ),\n side: TriggerSideCodec.inputToProto[input.side],\n limitPriceTicks:\n input.limitPrice === undefined\n ? 0n\n : positiveDecimalInputToScaled(\n \"limitPrice\",\n input.limitPrice,\n scales.price(),\n ),\n triggerPriceSource: input.triggerPriceSource,\n },\n } as const,\n },\n };\n }\n\n return [\n v.pipe(\n sellInputSchema,\n v.check(\n (input) => input.feeAsset === ProtoOrders.FeeAsset.QUOTE,\n \"SELL triggers must use the quote fee asset\",\n ),\n v.transform((input: v.InferOutput<typeof sellInputSchema>) => transformInput(input)),\n ),\n v.pipe(\n buyInputSchema,\n v.transform((input: v.InferOutput<typeof buyInputSchema>) => transformInput(input)),\n v.check(\n ({ trigger: { strategy } }) =>\n strategy.value.activationPriceTicks <= strategy.value.limitPriceTicks,\n \"limitPrice must be at least activationPrice\",\n ),\n ),\n ] as const;\n}\n\nfunction createTwapTriggerInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...BaseTriggerFieldsSchema.entries,\n triggerType: v.literal(\"twap\"),\n side: TriggerSideInputSchema,\n durationMs: v.pipe(\n v.union([v.pipe(v.string(), v.trim()), v.number()]),\n v.transform((value) => parseTwapMilliseconds(value, \"durationMs\", 1_000n)),\n ),\n sliceIntervalMs: v.pipe(\n v.union([v.pipe(v.string(), v.trim()), v.number()]),\n v.transform((value) => parseTwapMilliseconds(value, \"sliceIntervalMs\", 100n)),\n ),\n execution: TwapExecutionInputSchema,\n }),\n v.check(\n (input) =>\n input.side !== ProtoOrders.Side.SELL ||\n input.feeAsset === ProtoOrders.FeeAsset.QUOTE,\n \"SELL triggers must use the quote fee asset\",\n ),\n v.check(\n (input) => input.sliceIntervalMs <= input.durationMs,\n \"sliceIntervalMs cannot exceed durationMs\",\n ),\n v.transform((input) => {\n const { subaccountId, intent } = buildTriggerIntentBase(input, scales);\n return {\n subaccountId,\n trigger: {\n ...intent,\n strategy: {\n case: \"twap\",\n value: {\n side: input.side,\n durationMs: input.durationMs,\n sliceIntervalMs: input.sliceIntervalMs,\n execution: buildTwapExecution(input.execution, scales),\n },\n } as const,\n },\n };\n }),\n );\n}\n\nfunction createLadderTriggerInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...BaseTriggerFieldsSchema.entries,\n triggerType: v.literal(\"ladder\"),\n side: TriggerSideInputSchema,\n priceMin: DecimalInputStringSchema,\n priceMax: DecimalInputStringSchema,\n levels: v.pipe(\n v.union([v.pipe(v.string(), v.trim()), v.pipe(v.number(), v.integer())]),\n v.transform((value) => {\n const levels = parseOptionalPositiveIntLike(value);\n if (!levels || levels < 2 || levels > 100) {\n throw new Error(\"levels must be between 2 and 100\");\n }\n return levels;\n }),\n ),\n postOnly: v.optional(v.boolean(), false),\n }),\n v.check(\n (input) =>\n input.side !== ProtoOrders.Side.SELL ||\n input.feeAsset === ProtoOrders.FeeAsset.QUOTE,\n \"SELL triggers must use the quote fee asset\",\n ),\n v.transform((input) => {\n const { subaccountId, intent } = buildTriggerIntentBase(input, scales);\n return {\n subaccountId,\n trigger: {\n ...intent,\n strategy: {\n case: \"ladder\",\n value: {\n side: input.side,\n priceMinTicks: positiveDecimalInputToScaled(\n \"priceMin\",\n input.priceMin,\n scales.price(),\n ),\n priceMaxTicks: positiveDecimalInputToScaled(\n \"priceMax\",\n input.priceMax,\n scales.price(),\n ),\n levels: input.levels,\n postOnly: input.postOnly,\n },\n } as const,\n },\n };\n }),\n v.check(\n (output) =>\n output.trigger.strategy.value.priceMinTicks <\n output.trigger.strategy.value.priceMaxTicks,\n \"priceMin must be less than priceMax\",\n ),\n );\n}\n\n/** Builds the create-trigger boundary schema using catalog scales keyed by symbol ID. */\nexport function createCreateTriggerInputSchema(scales: SdkScales) {\n return v.union([\n ...createConditionalTriggerInputSchema(scales, \"stop_loss\"),\n ...createConditionalTriggerInputSchema(scales, \"take_profit\"),\n ...createTrailingStopTriggerInputSchema(scales),\n createTwapTriggerInputSchema(scales),\n createLadderTriggerInputSchema(scales),\n ]);\n}\n\n/** Public input for creating a standalone trigger. */\nexport type CreateTriggerInput = v.InferInput<ReturnType<typeof createCreateTriggerInputSchema>>;\n\n/** Public filters for listing triggers in an account scope. */\nexport const ListTriggersInputSchema = v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n parentOrderId: v.pipe(\n v.optional(v.pipe(v.string(), v.trim())),\n v.transform((value) => (value ? idToBigInt(value, \"parentOrderId\") : undefined)),\n ),\n symbolId: v.optional(SymbolIdInputSchema),\n status: v.pipe(\n v.optional(v.array(TriggerStatusFilterSchema)),\n v.transform(\n (values) => values?.map((value) => TriggerStatusCodec.inputToProto[value]) ?? [],\n ),\n ),\n triggerType: v.pipe(\n v.optional(TriggerTypeSchema),\n v.transform((value) =>\n value\n ? TriggerTypeCodec.inputToProto[value]\n : Proto.TriggerType.TRIGGER_TYPE_UNSPECIFIED,\n ),\n ),\n limit: v.optional(v.pipe(v.number(), v.integer(), v.gtValue(0), v.maxValue(1000)), 50),\n pageToken: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\n/** Public filters for listing triggers. */\nexport type ListTriggersInput = v.InferInput<typeof ListTriggersInputSchema>;\n\nexport const CancelTriggerInputSchema = TriggerScopedInputSchema;\nexport type CancelTriggerInput = v.InferInput<typeof CancelTriggerInputSchema>;\n\nexport const GetTriggerInputSchema = CancelTriggerInputSchema;\nexport type GetTriggerInput = v.InferInput<typeof GetTriggerInputSchema>;\n\nexport const PauseTriggerInputSchema = TriggerScopedInputSchema;\nexport type PauseTriggerInput = v.InferInput<typeof PauseTriggerInputSchema>;\n\nexport const ResumeTriggerInputSchema = v.pipe(\n v.strictObject({\n ...TriggerScopedInputEntries,\n symbolId: v.optional(SymbolIdInputSchema),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n/** Omitting `symbolId` uses the trigger's own market; when set, it must be that market. */\nexport type ResumeTriggerInput = v.InferInput<typeof ResumeTriggerInputSchema>;\n\nexport function createModifyTriggerInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...TriggerScopedInputEntries,\n symbolId: v.optional(SymbolIdInputSchema),\n triggerPrice: v.optional(DecimalInputStringSchema),\n trailingDistance: v.optional(TrailingDistanceInputSchema),\n activationPrice: v.optional(ActivationPricePatchInputSchema),\n maxSlippage: v.optional(MaxSlippageInputSchema),\n }),\n v.check(\n (input) =>\n input.triggerPrice !== undefined ||\n input.trailingDistance !== undefined ||\n input.activationPrice !== undefined ||\n input.maxSlippage !== undefined,\n \"At least one patch field is required\",\n ),\n v.transform(({ account, ...input }) => ({\n triggerId: input.triggerId,\n subaccountId: accountScopeToSubaccountId(account),\n // Zero targets the trigger's own market.\n symbolId: input.symbolId ?? 0,\n triggerPriceTicks:\n input.triggerPrice === undefined\n ? undefined\n : positiveDecimalInputToScaled(\n \"triggerPrice\",\n input.triggerPrice,\n scales.price(),\n ),\n trailingDistance:\n input.trailingDistance === undefined\n ? ({ case: undefined, value: undefined } as const)\n : parseTrailingDistance(scales, input.trailingDistance),\n activationPriceTicks:\n input.activationPrice === undefined\n ? undefined\n : typeof input.activationPrice !== \"string\"\n ? 0n\n : positiveDecimalInputToScaled(\n \"activationPrice\",\n input.activationPrice,\n scales.price(),\n ),\n maxSlippage:\n input.maxSlippage === undefined\n ? ({ case: undefined, value: undefined } as const)\n : parseMaxSlippagePatch(scales, input.maxSlippage),\n })),\n );\n}\n\n/**\n * A trigger patch. Omitted fields remain unchanged; `{ kind: \"none\" }` clears\n * `activationPrice` or `maxSlippage`. A cleared `maxSlippage` on a market child\n * falls back to the pair's default market slippage. Omitting `symbolId` uses\n * the trigger's own market; when set, it must be that market. A child's limit price is\n * fixed at creation: cancel the trigger and create a new one to change it.\n */\nexport type ModifyTriggerInput = v.InferInput<ReturnType<typeof createModifyTriggerInputSchema>>;\n\nexport const ListTriggerEventsInputSchema = v.pipe(\n v.strictObject({\n ...TriggerScopedInputEntries,\n limit: v.optional(v.pipe(v.number(), v.integer(), v.gtValue(0), v.maxValue(1000))),\n eventType: v.optional(TriggerEventTypeSchema),\n pageToken: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n eventType:\n input.eventType === undefined\n ? undefined\n : TriggerEventTypeCodec.inputToProto[input.eventType],\n })),\n);\n\nexport type ListTriggerEventsInput = v.InferInput<typeof ListTriggerEventsInputSchema>;\n"],"mappings":";;;;;;;;;;;;;;;AA0CA,MAAM,oBAAoB,EAAE,SAAS,mBAAmB;AACxD,MAAM,4BAA4B,EAAE,SAAS,4BAA4B;AACzE,MAAM,yBAAyB,EAAE,SAAS,yBAAyB;AAGnE,MAAM,4BAA4B;CAC9B,WAHyB,cAAc,WAGT;CAC9B,GAAG;AACP;AAEA,MAAM,2BAA2B,EAAE,KAC/B,EAAE,aAAa,yBAAyB,GACxC,EAAE,WAAW,EAAE,SAAS,GAAG,aAAa;CACpC,GAAG;CACH,cAAc,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AG;CACH,cAAc,2BAA2B,OAAO;CAChD,WACI,MAAM,cAAc,KAAA,IACd,KAAA,IACA,sBAAsB,aAAa,MAAM;AACvD,EAAE,CACN"}
1
+ {"version":3,"file":"trigger-input.schemas.js","names":["TriggerSideCodec"],"sources":["../../../src/services/triggers/trigger-input.schemas.ts"],"sourcesContent":["import * as Proto from \"../../gen/triggers/v1/triggers_pb.js\";\nimport * as ProtoOrders from \"../../gen/orders/v1/orders_pb.js\";\nimport * as v from \"valibot\";\nimport { idInputSchema } from \"../../shared/schemas.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport { positiveDecimalInputToScaled, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport { PROTOBUF_INT64_MAX } from \"../../shared/wire-bounds.js\";\nimport {\n parseOptionalPositiveBigIntLike,\n parseOptionalPositiveIntLike,\n} from \"../../utils/numbers.js\";\nimport { idToBigInt } from \"../../utils/base58-id.js\";\nimport {\n TRIGGER_EVENT_TYPE_VALUES,\n TRIGGER_STATUS_FILTER_VALUES,\n TRIGGER_TYPE_VALUES,\n TriggerEventTypeCodec,\n TriggerSideCodec,\n TriggerTypeCodec,\n TriggerStatusCodec,\n} from \"./triggers.codecs.js\";\nimport { BpsStringOrNumberInputSchema, NoneInputSchema, SymbolIdInputSchema } from \"../shared.js\";\nimport { TriggerPriceSourceInputSchema } from \"../orders/order-enums.codecs.js\";\nimport {\n BaseTriggerFieldsSchema,\n ConditionalExecutionInputSchema,\n DecimalInputStringSchema,\n TriggerSideInputSchema,\n TwapExecutionInputSchema,\n buildConditionalExecution,\n buildTriggerIntentBase,\n buildTwapExecution,\n MaxSlippageInputSchema,\n parseMaxSlippage,\n type MaxSlippageOneof,\n type TrailingDistanceOneof,\n} from \"./trigger-child-order.schemas.js\";\nimport { MAX_SELLING_SLIPPAGE_BPS, parseTrailingDistanceInput } from \"../trailing-oneof-inputs.js\";\n\nconst TriggerTypeSchema = v.picklist(TRIGGER_TYPE_VALUES);\nconst TriggerStatusFilterSchema = v.picklist(TRIGGER_STATUS_FILTER_VALUES);\nconst TriggerEventTypeSchema = v.picklist(TRIGGER_EVENT_TYPE_VALUES);\nconst TriggerIdInputSchema = idInputSchema(\"triggerId\");\n\nconst TriggerScopedInputEntries = {\n triggerId: TriggerIdInputSchema,\n ...AccountScopeInputEntries,\n};\n\nconst TriggerScopedInputSchema = v.pipe(\n v.strictObject(TriggerScopedInputEntries),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\n/** Absolute price distance, as a decimal price string (e.g. \"0.50\"). */\nconst PriceDistanceInputSchema = v.strictObject({\n kind: v.literal(\"distance\"),\n distance: DecimalInputStringSchema,\n});\n\nconst TrailingDistanceInputSchema = v.union([\n PriceDistanceInputSchema,\n BpsStringOrNumberInputSchema,\n]);\n\nconst ActivationPricePatchInputSchema = v.union([DecimalInputStringSchema, NoneInputSchema]);\n\nfunction parseTrailingDistance(\n scales: SdkScales,\n distance: v.InferOutput<typeof TrailingDistanceInputSchema>,\n): TrailingDistanceOneof {\n return parseTrailingDistanceInput(scales, distance, \"trailingDistance\");\n}\n\nfunction parseTwapMilliseconds(\n value: string | number,\n fieldName: \"durationMs\" | \"sliceIntervalMs\",\n minimum: bigint,\n): bigint {\n const parsed = parseOptionalPositiveBigIntLike(value);\n if (parsed === undefined || parsed < minimum || parsed > PROTOBUF_INT64_MAX) {\n throw new Error(\n `${fieldName} must be between ${minimum} and ${PROTOBUF_INT64_MAX} milliseconds`,\n );\n }\n return parsed;\n}\n\nfunction parseMaxSlippagePatch(\n scales: SdkScales,\n slippage: v.InferOutput<typeof MaxSlippageInputSchema>,\n): MaxSlippageOneof {\n if (slippage.kind === \"none\") {\n return { case: \"maxSlippageTicks\", value: 0n };\n }\n // The patch does not say which trigger it modifies, so it takes the widest\n // cap (a buy market child's 10000 bps); the server rejects 10000 for sells\n // and trailing stops with ERROR_CODE_MAX_SLIPPAGE_INVALID.\n return parseMaxSlippage(scales, slippage);\n}\n\nfunction createConditionalTriggerInputSchema<const TriggerType extends \"stop_loss\" | \"take_profit\">(\n scales: SdkScales,\n triggerType: TriggerType,\n) {\n const sharedEntries = {\n ...BaseTriggerFieldsSchema.entries,\n triggerType: v.literal(triggerType),\n triggerPrice: DecimalInputStringSchema,\n triggerPriceSource: TriggerPriceSourceInputSchema,\n };\n\n const sellInputSchema = v.strictObject({\n ...sharedEntries,\n side: v.literal(\"sell\"),\n execution: ConditionalExecutionInputSchema,\n });\n const buyInputSchema = v.strictObject({\n ...sharedEntries,\n side: v.literal(\"buy\"),\n execution: ConditionalExecutionInputSchema,\n });\n\n function transformInput(\n input: v.InferOutput<typeof sellInputSchema> | v.InferOutput<typeof buyInputSchema>,\n ) {\n const { subaccountId, intent } = buildTriggerIntentBase(input, scales);\n const side = TriggerSideCodec.inputToProto[input.side];\n const strategy = {\n triggerPriceTicks: positiveDecimalInputToScaled(\n \"triggerPrice\",\n input.triggerPrice,\n scales.price(),\n ),\n side,\n child: buildConditionalExecution(input.execution, scales, side),\n triggerPriceSource: input.triggerPriceSource,\n };\n return {\n subaccountId,\n trigger: {\n ...intent,\n strategy:\n triggerType === \"stop_loss\"\n ? ({ case: \"stopLoss\", value: strategy } as const)\n : ({ case: \"takeProfit\", value: strategy } as const),\n },\n };\n }\n\n return [\n v.pipe(\n sellInputSchema,\n v.check(\n (input) => input.feeAsset === ProtoOrders.FeeAsset.QUOTE,\n \"SELL triggers must use the quote fee asset\",\n ),\n v.transform((input: v.InferOutput<typeof sellInputSchema>) => transformInput(input)),\n ),\n v.pipe(\n buyInputSchema,\n v.transform((input: v.InferOutput<typeof buyInputSchema>) => transformInput(input)),\n ),\n ] as const;\n}\n\nfunction createTrailingStopTriggerInputSchema(scales: SdkScales) {\n const sharedEntries = {\n ...BaseTriggerFieldsSchema.entries,\n triggerType: v.literal(\"trailing_stop\"),\n trailingDistance: TrailingDistanceInputSchema,\n activationPrice: v.optional(DecimalInputStringSchema),\n maxSlippage: v.optional(MaxSlippageInputSchema),\n triggerPriceSource: TriggerPriceSourceInputSchema,\n };\n const sellInputSchema = v.strictObject({\n ...sharedEntries,\n side: v.optional(v.literal(\"sell\"), \"sell\"),\n limitPrice: v.optional(v.never()),\n });\n // A buy's child never pays more than `limitPrice`, which also sizes its reserved funds.\n const buyInputSchema = v.strictObject({\n ...sharedEntries,\n side: v.literal(\"buy\"),\n limitPrice: DecimalInputStringSchema,\n });\n\n function transformInput(\n input: v.InferOutput<typeof sellInputSchema> | v.InferOutput<typeof buyInputSchema>,\n ) {\n const { subaccountId, intent } = buildTriggerIntentBase(input, scales);\n return {\n subaccountId,\n trigger: {\n ...intent,\n strategy: {\n case: \"trailingStop\",\n value: {\n trailingDistance: parseTrailingDistance(scales, input.trailingDistance),\n activationPriceTicks:\n input.activationPrice === undefined\n ? 0n\n : positiveDecimalInputToScaled(\n \"activationPrice\",\n input.activationPrice,\n scales.price(),\n ),\n maxSlippage: parseMaxSlippage(\n scales,\n input.maxSlippage,\n MAX_SELLING_SLIPPAGE_BPS,\n ),\n side: TriggerSideCodec.inputToProto[input.side],\n limitPriceTicks:\n input.limitPrice === undefined\n ? 0n\n : positiveDecimalInputToScaled(\n \"limitPrice\",\n input.limitPrice,\n scales.price(),\n ),\n triggerPriceSource: input.triggerPriceSource,\n },\n } as const,\n },\n };\n }\n\n return [\n v.pipe(\n sellInputSchema,\n v.check(\n (input) => input.feeAsset === ProtoOrders.FeeAsset.QUOTE,\n \"SELL triggers must use the quote fee asset\",\n ),\n v.transform((input: v.InferOutput<typeof sellInputSchema>) => transformInput(input)),\n ),\n v.pipe(\n buyInputSchema,\n v.transform((input: v.InferOutput<typeof buyInputSchema>) => transformInput(input)),\n v.check(\n ({ trigger: { strategy } }) =>\n strategy.value.activationPriceTicks <= strategy.value.limitPriceTicks,\n \"limitPrice must be at least activationPrice\",\n ),\n ),\n ] as const;\n}\n\nfunction createTwapTriggerInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...BaseTriggerFieldsSchema.entries,\n triggerType: v.literal(\"twap\"),\n side: TriggerSideInputSchema,\n durationMs: v.pipe(\n v.union([v.pipe(v.string(), v.trim()), v.number()]),\n v.transform((value) => parseTwapMilliseconds(value, \"durationMs\", 1_000n)),\n ),\n sliceIntervalMs: v.pipe(\n v.union([v.pipe(v.string(), v.trim()), v.number()]),\n v.transform((value) => parseTwapMilliseconds(value, \"sliceIntervalMs\", 100n)),\n ),\n execution: TwapExecutionInputSchema,\n }),\n v.check(\n (input) =>\n input.side !== ProtoOrders.Side.SELL ||\n input.feeAsset === ProtoOrders.FeeAsset.QUOTE,\n \"SELL triggers must use the quote fee asset\",\n ),\n v.check(\n (input) => input.sliceIntervalMs <= input.durationMs,\n \"sliceIntervalMs cannot exceed durationMs\",\n ),\n v.transform((input) => {\n const { subaccountId, intent } = buildTriggerIntentBase(input, scales);\n return {\n subaccountId,\n trigger: {\n ...intent,\n strategy: {\n case: \"twap\",\n value: {\n side: input.side,\n durationMs: input.durationMs,\n sliceIntervalMs: input.sliceIntervalMs,\n execution: buildTwapExecution(input.execution, scales),\n },\n } as const,\n },\n };\n }),\n );\n}\n\nfunction createLadderTriggerInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...BaseTriggerFieldsSchema.entries,\n triggerType: v.literal(\"ladder\"),\n side: TriggerSideInputSchema,\n priceMin: DecimalInputStringSchema,\n priceMax: DecimalInputStringSchema,\n levels: v.pipe(\n v.union([v.pipe(v.string(), v.trim()), v.pipe(v.number(), v.integer())]),\n v.transform((value) => {\n const levels = parseOptionalPositiveIntLike(value);\n if (!levels || levels < 2 || levels > 100) {\n throw new Error(\"levels must be between 2 and 100\");\n }\n return levels;\n }),\n ),\n postOnly: v.optional(v.boolean(), false),\n }),\n v.check(\n (input) =>\n input.side !== ProtoOrders.Side.SELL ||\n input.feeAsset === ProtoOrders.FeeAsset.QUOTE,\n \"SELL triggers must use the quote fee asset\",\n ),\n v.transform((input) => {\n const { subaccountId, intent } = buildTriggerIntentBase(input, scales);\n return {\n subaccountId,\n trigger: {\n ...intent,\n strategy: {\n case: \"ladder\",\n value: {\n side: input.side,\n priceMinTicks: positiveDecimalInputToScaled(\n \"priceMin\",\n input.priceMin,\n scales.price(),\n ),\n priceMaxTicks: positiveDecimalInputToScaled(\n \"priceMax\",\n input.priceMax,\n scales.price(),\n ),\n levels: input.levels,\n postOnly: input.postOnly,\n },\n } as const,\n },\n };\n }),\n v.check(\n (output) =>\n output.trigger.strategy.value.priceMinTicks <\n output.trigger.strategy.value.priceMaxTicks,\n \"priceMin must be less than priceMax\",\n ),\n );\n}\n\ntype AnySchema = v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>;\n\nfunction fieldOf(input: unknown, key: string): unknown {\n return typeof input === \"object\" && input !== null\n ? (input as Record<string, unknown>)[key]\n : undefined;\n}\n\n/** Validates against the side the caller chose, so errors name that side's fields. */\nfunction bySide<const Sell extends AnySchema, const Buy extends AnySchema>([sell, buy]: readonly [\n Sell,\n Buy,\n]) {\n return v.lazy((input) => (fieldOf(input, \"side\") === \"buy\" ? buy : sell));\n}\n\n/**\n * Builds the create-trigger boundary schema using catalog scales keyed by symbol ID.\n * The variant is picked by `triggerType` before validating, because a plain union\n * reports the first branch's mismatch (e.g. \"Expected stop_loss\") instead of the\n * chosen variant's missing or invalid field.\n */\nexport function createCreateTriggerInputSchema(scales: SdkScales) {\n const variants = {\n stop_loss: bySide(createConditionalTriggerInputSchema(scales, \"stop_loss\")),\n take_profit: bySide(createConditionalTriggerInputSchema(scales, \"take_profit\")),\n trailing_stop: bySide(createTrailingStopTriggerInputSchema(scales)),\n twap: createTwapTriggerInputSchema(scales),\n ladder: createLadderTriggerInputSchema(scales),\n } satisfies Record<(typeof TRIGGER_TYPE_VALUES)[number], AnySchema>;\n const unknownVariant = v.never(`triggerType must be one of ${TRIGGER_TYPE_VALUES.join(\", \")}`);\n return v.lazy((input) => {\n const triggerType = fieldOf(input, \"triggerType\");\n return typeof triggerType === \"string\" && Object.hasOwn(variants, triggerType)\n ? variants[triggerType as keyof typeof variants]\n : unknownVariant;\n });\n}\n\n/** Public input for creating a standalone trigger. */\nexport type CreateTriggerInput = v.InferInput<ReturnType<typeof createCreateTriggerInputSchema>>;\n\n/** Public filters for listing triggers in an account scope. */\nexport const ListTriggersInputSchema = v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n parentOrderId: v.pipe(\n v.optional(v.pipe(v.string(), v.trim())),\n v.transform((value) => (value ? idToBigInt(value, \"parentOrderId\") : undefined)),\n ),\n symbolId: v.optional(SymbolIdInputSchema),\n status: v.pipe(\n v.optional(v.array(TriggerStatusFilterSchema)),\n v.transform(\n (values) => values?.map((value) => TriggerStatusCodec.inputToProto[value]) ?? [],\n ),\n ),\n triggerType: v.pipe(\n v.optional(TriggerTypeSchema),\n v.transform((value) =>\n value\n ? TriggerTypeCodec.inputToProto[value]\n : Proto.TriggerType.TRIGGER_TYPE_UNSPECIFIED,\n ),\n ),\n limit: v.optional(v.pipe(v.number(), v.integer(), v.gtValue(0), v.maxValue(1000)), 50),\n pageToken: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\n/** Public filters for listing triggers. */\nexport type ListTriggersInput = v.InferInput<typeof ListTriggersInputSchema>;\n\nexport const CancelTriggerInputSchema = TriggerScopedInputSchema;\nexport type CancelTriggerInput = v.InferInput<typeof CancelTriggerInputSchema>;\n\nexport const GetTriggerInputSchema = CancelTriggerInputSchema;\nexport type GetTriggerInput = v.InferInput<typeof GetTriggerInputSchema>;\n\nexport const PauseTriggerInputSchema = TriggerScopedInputSchema;\nexport type PauseTriggerInput = v.InferInput<typeof PauseTriggerInputSchema>;\n\nexport const ResumeTriggerInputSchema = v.pipe(\n v.strictObject({\n ...TriggerScopedInputEntries,\n symbolId: v.optional(SymbolIdInputSchema),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n/** Omitting `symbolId` uses the trigger's own market; when set, it must be that market. */\nexport type ResumeTriggerInput = v.InferInput<typeof ResumeTriggerInputSchema>;\n\nexport function createModifyTriggerInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...TriggerScopedInputEntries,\n symbolId: v.optional(SymbolIdInputSchema),\n triggerPrice: v.optional(DecimalInputStringSchema),\n trailingDistance: v.optional(TrailingDistanceInputSchema),\n activationPrice: v.optional(ActivationPricePatchInputSchema),\n maxSlippage: v.optional(MaxSlippageInputSchema),\n }),\n v.check(\n (input) =>\n input.triggerPrice !== undefined ||\n input.trailingDistance !== undefined ||\n input.activationPrice !== undefined ||\n input.maxSlippage !== undefined,\n \"At least one patch field is required\",\n ),\n v.transform(({ account, ...input }) => ({\n triggerId: input.triggerId,\n subaccountId: accountScopeToSubaccountId(account),\n // Zero targets the trigger's own market.\n symbolId: input.symbolId ?? 0,\n triggerPriceTicks:\n input.triggerPrice === undefined\n ? undefined\n : positiveDecimalInputToScaled(\n \"triggerPrice\",\n input.triggerPrice,\n scales.price(),\n ),\n trailingDistance:\n input.trailingDistance === undefined\n ? ({ case: undefined, value: undefined } as const)\n : parseTrailingDistance(scales, input.trailingDistance),\n activationPriceTicks:\n input.activationPrice === undefined\n ? undefined\n : typeof input.activationPrice !== \"string\"\n ? 0n\n : positiveDecimalInputToScaled(\n \"activationPrice\",\n input.activationPrice,\n scales.price(),\n ),\n maxSlippage:\n input.maxSlippage === undefined\n ? ({ case: undefined, value: undefined } as const)\n : parseMaxSlippagePatch(scales, input.maxSlippage),\n })),\n );\n}\n\n/**\n * A trigger patch. Omitted fields remain unchanged; `{ kind: \"none\" }` clears\n * `activationPrice` or `maxSlippage`. A cleared `maxSlippage` on a market child\n * falls back to the pair's default market slippage. Omitting `symbolId` uses\n * the trigger's own market; when set, it must be that market. A child's limit price is\n * fixed at creation: cancel the trigger and create a new one to change it.\n */\nexport type ModifyTriggerInput = v.InferInput<ReturnType<typeof createModifyTriggerInputSchema>>;\n\nexport const ListTriggerEventsInputSchema = v.pipe(\n v.strictObject({\n ...TriggerScopedInputEntries,\n limit: v.optional(v.pipe(v.number(), v.integer(), v.gtValue(0), v.maxValue(1000))),\n eventType: v.optional(TriggerEventTypeSchema),\n pageToken: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n eventType:\n input.eventType === undefined\n ? undefined\n : TriggerEventTypeCodec.inputToProto[input.eventType],\n })),\n);\n\nexport type ListTriggerEventsInput = v.InferInput<typeof ListTriggerEventsInputSchema>;\n"],"mappings":";;;;;;;;;;;;;;;AA0CA,MAAM,oBAAoB,EAAE,SAAS,mBAAmB;AACxD,MAAM,4BAA4B,EAAE,SAAS,4BAA4B;AACzE,MAAM,yBAAyB,EAAE,SAAS,yBAAyB;AAGnE,MAAM,4BAA4B;CAC9B,WAHyB,cAAc,WAGT;CAC9B,GAAG;AACP;AAEA,MAAM,2BAA2B,EAAE,KAC/B,EAAE,aAAa,yBAAyB,GACxC,EAAE,WAAW,EAAE,SAAS,GAAG,aAAa;CACpC,GAAG;CACH,cAAc,2BAA2B,OAAO;AACpD,EAAE,CACN;;AAGA,MAAM,2BAA2B,EAAE,aAAa;CAC5C,MAAM,EAAE,QAAQ,UAAU;CAC1B,UAAU;AACd,CAAC;AAED,MAAM,8BAA8B,EAAE,MAAM,CACxC,0BACA,4BACJ,CAAC;AAED,MAAM,kCAAkC,EAAE,MAAM,CAAC,0BAA0B,eAAe,CAAC;AAE3F,SAAS,sBACL,QACA,UACqB;CACrB,OAAO,2BAA2B,QAAQ,UAAU,kBAAkB;AAC1E;AAEA,SAAS,sBACL,OACA,WACA,SACM;CACN,MAAM,SAAS,gCAAgC,KAAK;CACpD,IAAI,WAAW,KAAA,KAAa,SAAS,WAAW,SAAA,sBAC5C,MAAM,IAAI,MACN,GAAG,UAAU,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a;CACpC,GAAG;CACH,cAAc,2BAA2B,OAAO;CAChD,WACI,MAAM,cAAc,KAAA,IACd,KAAA,IACA,sBAAsB,aAAa,MAAM;AACvD,EAAE,CACN"}
@@ -29,62 +29,62 @@ declare const CreateTriggerResultSchema: v.SchemaWithPipe<readonly [v.ObjectSche
29
29
  type CreateTriggerResult = v.InferOutput<typeof CreateTriggerResultSchema>;
30
30
  declare const CancelTriggerResultSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
31
31
  readonly triggerId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
32
- readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "failed" | "completed" | "canceled" | "created" | "armed" | "running" | "paused">]>;
32
+ readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "failed" | "canceled" | "completed" | "created" | "armed" | "running" | "paused">]>;
33
33
  readonly tsNs: v.BigintSchema<undefined>;
34
34
  }, undefined>, v.TransformAction<{
35
35
  triggerId: string;
36
- status: "unspecified" | "failed" | "completed" | "canceled" | "created" | "armed" | "running" | "paused";
36
+ status: "unspecified" | "failed" | "canceled" | "completed" | "created" | "armed" | "running" | "paused";
37
37
  tsNs: bigint;
38
38
  }, {
39
39
  ts: number;
40
40
  tsNs: string;
41
41
  triggerId: string;
42
- status: "unspecified" | "failed" | "completed" | "canceled" | "created" | "armed" | "running" | "paused";
42
+ status: "unspecified" | "failed" | "canceled" | "completed" | "created" | "armed" | "running" | "paused";
43
43
  }>]>;
44
44
  type CancelTriggerResult = v.InferOutput<typeof CancelTriggerResultSchema>;
45
45
  declare const ModifyTriggerResultSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
46
46
  readonly triggerId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
47
- readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "failed" | "completed" | "canceled" | "created" | "armed" | "running" | "paused">]>;
47
+ readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "failed" | "canceled" | "completed" | "created" | "armed" | "running" | "paused">]>;
48
48
  readonly tsNs: v.BigintSchema<undefined>;
49
49
  }, undefined>, v.TransformAction<{
50
50
  triggerId: string;
51
- status: "unspecified" | "failed" | "completed" | "canceled" | "created" | "armed" | "running" | "paused";
51
+ status: "unspecified" | "failed" | "canceled" | "completed" | "created" | "armed" | "running" | "paused";
52
52
  tsNs: bigint;
53
53
  }, {
54
54
  ts: number;
55
55
  tsNs: string;
56
56
  triggerId: string;
57
- status: "unspecified" | "failed" | "completed" | "canceled" | "created" | "armed" | "running" | "paused";
57
+ status: "unspecified" | "failed" | "canceled" | "completed" | "created" | "armed" | "running" | "paused";
58
58
  }>]>;
59
59
  type ModifyTriggerResult = v.InferOutput<typeof ModifyTriggerResultSchema>;
60
60
  declare const PauseTriggerResultSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
61
61
  readonly triggerId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
62
- readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "failed" | "completed" | "canceled" | "created" | "armed" | "running" | "paused">]>;
62
+ readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "failed" | "canceled" | "completed" | "created" | "armed" | "running" | "paused">]>;
63
63
  readonly tsNs: v.BigintSchema<undefined>;
64
64
  }, undefined>, v.TransformAction<{
65
65
  triggerId: string;
66
- status: "unspecified" | "failed" | "completed" | "canceled" | "created" | "armed" | "running" | "paused";
66
+ status: "unspecified" | "failed" | "canceled" | "completed" | "created" | "armed" | "running" | "paused";
67
67
  tsNs: bigint;
68
68
  }, {
69
69
  ts: number;
70
70
  tsNs: string;
71
71
  triggerId: string;
72
- status: "unspecified" | "failed" | "completed" | "canceled" | "created" | "armed" | "running" | "paused";
72
+ status: "unspecified" | "failed" | "canceled" | "completed" | "created" | "armed" | "running" | "paused";
73
73
  }>]>;
74
74
  type PauseTriggerResult = v.InferOutput<typeof PauseTriggerResultSchema>;
75
75
  declare const ResumeTriggerResultSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
76
76
  readonly triggerId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
77
- readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "failed" | "completed" | "canceled" | "created" | "armed" | "running" | "paused">]>;
77
+ readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "failed" | "canceled" | "completed" | "created" | "armed" | "running" | "paused">]>;
78
78
  readonly tsNs: v.BigintSchema<undefined>;
79
79
  }, undefined>, v.TransformAction<{
80
80
  triggerId: string;
81
- status: "unspecified" | "failed" | "completed" | "canceled" | "created" | "armed" | "running" | "paused";
81
+ status: "unspecified" | "failed" | "canceled" | "completed" | "created" | "armed" | "running" | "paused";
82
82
  tsNs: bigint;
83
83
  }, {
84
84
  ts: number;
85
85
  tsNs: string;
86
86
  triggerId: string;
87
- status: "unspecified" | "failed" | "completed" | "canceled" | "created" | "armed" | "running" | "paused";
87
+ status: "unspecified" | "failed" | "canceled" | "completed" | "created" | "armed" | "running" | "paused";
88
88
  }>]>;
89
89
  type ResumeTriggerResult = v.InferOutput<typeof ResumeTriggerResultSchema>;
90
90
  type StopDetailsOutput = {
@@ -613,7 +613,7 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
613
613
  triggerId: string;
614
614
  subaccountId: string;
615
615
  symbolId: number;
616
- status: "unspecified" | "failed" | "completed" | "canceled" | "created" | "armed" | "running" | "paused";
616
+ status: "unspecified" | "failed" | "canceled" | "completed" | "created" | "armed" | "running" | "paused";
617
617
  parentOrderId: string | undefined;
618
618
  qty: string;
619
619
  feeAsset: "unspecified" | "quote" | "base";
@@ -792,7 +792,7 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
792
792
  triggerId: string;
793
793
  subaccountId: string;
794
794
  symbolId: number;
795
- status: "unspecified" | "failed" | "completed" | "canceled" | "created" | "armed" | "running" | "paused";
795
+ status: "unspecified" | "failed" | "canceled" | "completed" | "created" | "armed" | "running" | "paused";
796
796
  parentOrderId: string | undefined;
797
797
  qty: string;
798
798
  feeAsset: "unspecified" | "quote" | "base";
@@ -971,7 +971,7 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
971
971
  triggerId: string;
972
972
  subaccountId: string;
973
973
  symbolId: number;
974
- status: "unspecified" | "failed" | "completed" | "canceled" | "created" | "armed" | "running" | "paused";
974
+ status: "unspecified" | "failed" | "canceled" | "completed" | "created" | "armed" | "running" | "paused";
975
975
  parentOrderId: string | undefined;
976
976
  qty: string;
977
977
  feeAsset: "unspecified" | "quote" | "base";
@@ -1196,7 +1196,7 @@ declare function createTriggerEventSchema(scales: SdkScales): v.SchemaWithPipe<r
1196
1196
  subaccountId: string;
1197
1197
  symbolId: number;
1198
1198
  triggerType: "unspecified" | "twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop";
1199
- eventType: "unspecified" | "failed" | "canceled" | "armed" | "updated" | "fired" | "activated" | "fire_refused";
1199
+ eventType: "unspecified" | "failed" | "canceled" | "updated" | "armed" | "fired" | "activated" | "fire_refused";
1200
1200
  ts: number;
1201
1201
  tsNs: string;
1202
1202
  childSeq: number;
@@ -1211,7 +1211,7 @@ declare function createTriggerEventSchema(scales: SdkScales): v.SchemaWithPipe<r
1211
1211
  subaccountId: string;
1212
1212
  symbolId: number;
1213
1213
  triggerType: "unspecified" | "twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop";
1214
- eventType: "unspecified" | "failed" | "canceled" | "armed" | "updated" | "fired" | "activated" | "fire_refused";
1214
+ eventType: "unspecified" | "failed" | "canceled" | "updated" | "armed" | "fired" | "activated" | "fire_refused";
1215
1215
  ts: number;
1216
1216
  tsNs: string;
1217
1217
  childSeq: number;
@@ -1226,7 +1226,7 @@ declare function createTriggerEventSchema(scales: SdkScales): v.SchemaWithPipe<r
1226
1226
  subaccountId: string;
1227
1227
  symbolId: number;
1228
1228
  triggerType: "unspecified" | "twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop";
1229
- eventType: "unspecified" | "failed" | "canceled" | "armed" | "updated" | "fired" | "activated" | "fire_refused";
1229
+ eventType: "unspecified" | "failed" | "canceled" | "updated" | "armed" | "fired" | "activated" | "fire_refused";
1230
1230
  ts: number;
1231
1231
  tsNs: string;
1232
1232
  childSeq: number;
@@ -1 +1 @@
1
- {"version":3,"file":"connect-error-mapping.d.ts","names":[],"sources":["../../src/shared/connect-error-mapping.ts"],"mappings":";;;;;;;iBAiMgB,6BAA6B,IAAI,eAAe;;;;;;;;;iBA0OhD,iBAAiB;;;;;;iBAyDjB,iCAAiC"}
1
+ {"version":3,"file":"connect-error-mapping.d.ts","names":[],"sources":["../../src/shared/connect-error-mapping.ts"],"mappings":";;;;;;;iBAmMgB,6BAA6B,IAAI,eAAe;;;;;;;;;iBA+OhD,iBAAiB;;;;;;iBAyDjB,iCAAiC"}
@@ -1,4 +1,4 @@
1
- import { AlreadyExistsError, AuthenticationError, InternalServerError, MfaEnrollmentRequiredError, MfaLastFactorRequiredError, MfaVerificationError, NotImplementedError, OutcomeUnknownError, PermissionError, PolicyInUseError, PolicyLockedError, PolicyScopeMismatchError, PolyesterError, PreconditionFailedError, RateLimitError, RequestDeadlineExceededError, ResourceNotFoundError, RevisionConflictError, ServiceUnavailableError, SessionElevationRequiredError, StaleQuoteError, StepUpRequiredError, SubaccountChallengeInvalidError, TimeoutError, TimestampSkewError, TransientError, ValidationError, WithdrawDeadlineExpiredError, errorFromHttpStatus, isAbortError, isTimeoutAbortError, normalizeErrorMessage } from "./errors.js";
1
+ import { AlreadyExistsError, AuthenticationError, InternalServerError, MfaEnrollmentRequiredError, MfaLastFactorRequiredError, MfaVerificationError, NetworkError, NotImplementedError, OutcomeUnknownError, PermissionError, PolicyInUseError, PolicyLockedError, PolicyScopeMismatchError, PolyesterError, PreconditionFailedError, RateLimitError, RequestDeadlineExceededError, ResourceNotFoundError, RevisionConflictError, ServiceUnavailableError, SessionElevationRequiredError, StaleQuoteError, StepUpRequiredError, SubaccountChallengeInvalidError, TimeoutError, TimestampSkewError, TransientError, ValidationError, WithdrawDeadlineExpiredError, errorFromHttpStatus, isAbortError, isFetchNetworkError, isTimeoutAbortError, normalizeErrorMessage } from "./errors.js";
2
2
  import { loadErrorDetailDecoders, parseConnectErrorDetail } from "./error-detail.js";
3
3
  import { Code, ConnectError } from "@connectrpc/connect";
4
4
  //#region src/shared/connect-error-mapping.ts
@@ -158,6 +158,7 @@ function connectErrorToPolyesterError(ce) {
158
158
  case Code.Unimplemented: return new NotImplementedError(withFallback("Operation not implemented."), options);
159
159
  case Code.Aborted: return new TransientError(withFallback("Operation aborted by the backend."), options);
160
160
  default:
161
+ if (ce.code === Code.Unknown && isFetchNetworkError(ce.cause)) return new NetworkError("Transport request failed", options);
161
162
  if (/service temporarily unavailable/i.test(message)) return new ServiceUnavailableError(withFallback("Service unavailable."), options);
162
163
  return new InternalServerError(withFallback("Internal server error."), options);
163
164
  }