@polyester/sdk 0.32.0-devnet-20261102134326 → 0.32.1-devnet-20261102140938
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 +7 -1
- package/dist/services/balances/balances.schemas.d.ts +3 -3
- package/dist/services/candles/candles.schemas.d.ts +10 -10
- package/dist/services/heatmap/heatmap.schemas.d.ts +13 -13
- package/dist/services/lifecycle/lifecycle.schemas.d.ts +54 -54
- package/dist/services/market-overview/market-overview.schemas.d.ts +3 -3
- package/dist/services/orderbook/orderbook.schemas.d.ts +1 -1
- package/dist/services/orders/orders-batch.schemas.d.ts +216 -6
- package/dist/services/orders/orders-batch.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-input.schemas.d.ts +408 -2
- package/dist/services/orders/orders-input.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-input.schemas.js +3 -3
- package/dist/services/orders/orders-input.schemas.js.map +1 -1
- package/dist/services/orders/orders-modify.schemas.d.ts +31 -0
- package/dist/services/orders/orders-modify.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-output.schemas.d.ts +8 -8
- package/dist/services/orders/orders-risk.schemas.d.ts +21 -0
- package/dist/services/orders/orders-risk.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-risk.schemas.js +22 -7
- package/dist/services/orders/orders-risk.schemas.js.map +1 -1
- package/dist/services/rewards/rewards.schemas.d.ts +3 -3
- package/dist/services/subaccounts/subaccounts.schemas.d.ts +2 -2
- package/dist/services/trades/trades.schemas.d.ts +1 -1
- package/dist/services/transfers/transfers.schemas.d.ts +1 -1
- package/dist/services/triggers/trigger-input.schemas.d.ts +2 -2
- package/dist/services/triggers/triggers-output.schemas.d.ts +18 -18
- package/package.json +1 -1
|
@@ -51,6 +51,7 @@ declare function createTrailingStopInputSchema(scales: SdkScales): v.SchemaWithP
|
|
|
51
51
|
readonly kind: v.LiteralSchema<"none", undefined>;
|
|
52
52
|
}, undefined>], undefined>, undefined>;
|
|
53
53
|
readonly activationPrice: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
54
|
+
readonly limitPrice: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
54
55
|
readonly triggerPriceSource: v.OptionalSchema<v.SchemaWithPipe<readonly [v.PicklistSchema<["last", "index"], undefined>, v.TransformAction<"last" | "index", TriggerPriceSource.LAST_PRICE | TriggerPriceSource.INDEX_PRICE>]>, undefined>;
|
|
55
56
|
}, undefined>, v.TransformAction<{
|
|
56
57
|
trailingDistance: {
|
|
@@ -70,6 +71,7 @@ declare function createTrailingStopInputSchema(scales: SdkScales): v.SchemaWithP
|
|
|
70
71
|
kind: "none";
|
|
71
72
|
} | undefined;
|
|
72
73
|
activationPrice?: string | undefined;
|
|
74
|
+
limitPrice?: string | undefined;
|
|
73
75
|
triggerPriceSource?: TriggerPriceSource.LAST_PRICE | TriggerPriceSource.INDEX_PRICE | undefined;
|
|
74
76
|
}, {
|
|
75
77
|
trailingDistance: {
|
|
@@ -93,6 +95,7 @@ declare function createTrailingStopInputSchema(scales: SdkScales): v.SchemaWithP
|
|
|
93
95
|
value?: undefined;
|
|
94
96
|
};
|
|
95
97
|
activationPriceTicks: bigint;
|
|
98
|
+
limitPriceTicks: bigint;
|
|
96
99
|
triggerPriceSource: TriggerPriceSource.LAST_PRICE | TriggerPriceSource.INDEX_PRICE | undefined;
|
|
97
100
|
}>]>;
|
|
98
101
|
declare function createRiskPolicyInputSchema(scales: SdkScales): v.SchemaWithPipe<readonly [v.OptionalSchema<v.UnionSchema<[v.StrictObjectSchema<{
|
|
@@ -211,6 +214,7 @@ declare function createRiskPolicyInputSchema(scales: SdkScales): v.SchemaWithPip
|
|
|
211
214
|
readonly kind: v.LiteralSchema<"none", undefined>;
|
|
212
215
|
}, undefined>], undefined>, undefined>;
|
|
213
216
|
readonly activationPrice: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
217
|
+
readonly limitPrice: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
214
218
|
readonly triggerPriceSource: v.OptionalSchema<v.SchemaWithPipe<readonly [v.PicklistSchema<["last", "index"], undefined>, v.TransformAction<"last" | "index", TriggerPriceSource.LAST_PRICE | TriggerPriceSource.INDEX_PRICE>]>, undefined>;
|
|
215
219
|
}, undefined>, v.TransformAction<{
|
|
216
220
|
trailingDistance: {
|
|
@@ -230,6 +234,7 @@ declare function createRiskPolicyInputSchema(scales: SdkScales): v.SchemaWithPip
|
|
|
230
234
|
kind: "none";
|
|
231
235
|
} | undefined;
|
|
232
236
|
activationPrice?: string | undefined;
|
|
237
|
+
limitPrice?: string | undefined;
|
|
233
238
|
triggerPriceSource?: TriggerPriceSource.LAST_PRICE | TriggerPriceSource.INDEX_PRICE | undefined;
|
|
234
239
|
}, {
|
|
235
240
|
trailingDistance: {
|
|
@@ -253,6 +258,7 @@ declare function createRiskPolicyInputSchema(scales: SdkScales): v.SchemaWithPip
|
|
|
253
258
|
value?: undefined;
|
|
254
259
|
};
|
|
255
260
|
activationPriceTicks: bigint;
|
|
261
|
+
limitPriceTicks: bigint;
|
|
256
262
|
triggerPriceSource: TriggerPriceSource.LAST_PRICE | TriggerPriceSource.INDEX_PRICE | undefined;
|
|
257
263
|
}>]>;
|
|
258
264
|
readonly oco: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
@@ -347,6 +353,7 @@ declare function createRiskPolicyInputSchema(scales: SdkScales): v.SchemaWithPip
|
|
|
347
353
|
readonly kind: v.LiteralSchema<"none", undefined>;
|
|
348
354
|
}, undefined>], undefined>, undefined>;
|
|
349
355
|
readonly activationPrice: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
356
|
+
readonly limitPrice: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
350
357
|
readonly triggerPriceSource: v.OptionalSchema<v.SchemaWithPipe<readonly [v.PicklistSchema<["last", "index"], undefined>, v.TransformAction<"last" | "index", TriggerPriceSource.LAST_PRICE | TriggerPriceSource.INDEX_PRICE>]>, undefined>;
|
|
351
358
|
}, undefined>, v.TransformAction<{
|
|
352
359
|
trailingDistance: {
|
|
@@ -366,6 +373,7 @@ declare function createRiskPolicyInputSchema(scales: SdkScales): v.SchemaWithPip
|
|
|
366
373
|
kind: "none";
|
|
367
374
|
} | undefined;
|
|
368
375
|
activationPrice?: string | undefined;
|
|
376
|
+
limitPrice?: string | undefined;
|
|
369
377
|
triggerPriceSource?: TriggerPriceSource.LAST_PRICE | TriggerPriceSource.INDEX_PRICE | undefined;
|
|
370
378
|
}, {
|
|
371
379
|
trailingDistance: {
|
|
@@ -389,6 +397,7 @@ declare function createRiskPolicyInputSchema(scales: SdkScales): v.SchemaWithPip
|
|
|
389
397
|
value?: undefined;
|
|
390
398
|
};
|
|
391
399
|
activationPriceTicks: bigint;
|
|
400
|
+
limitPriceTicks: bigint;
|
|
392
401
|
triggerPriceSource: TriggerPriceSource.LAST_PRICE | TriggerPriceSource.INDEX_PRICE | undefined;
|
|
393
402
|
}>]>;
|
|
394
403
|
readonly oco: v.OptionalSchema<v.LiteralSchema<false, "oco requires takeProfit and exactly one stop leg">, undefined>;
|
|
@@ -458,6 +467,7 @@ declare function createRiskPolicyInputSchema(scales: SdkScales): v.SchemaWithPip
|
|
|
458
467
|
value?: undefined;
|
|
459
468
|
};
|
|
460
469
|
activationPriceTicks: bigint;
|
|
470
|
+
limitPriceTicks: bigint;
|
|
461
471
|
triggerPriceSource: TriggerPriceSource.LAST_PRICE | TriggerPriceSource.INDEX_PRICE | undefined;
|
|
462
472
|
};
|
|
463
473
|
oco?: boolean | undefined;
|
|
@@ -520,6 +530,7 @@ declare function createRiskPolicyInputSchema(scales: SdkScales): v.SchemaWithPip
|
|
|
520
530
|
value?: undefined;
|
|
521
531
|
};
|
|
522
532
|
activationPriceTicks: bigint;
|
|
533
|
+
limitPriceTicks: bigint;
|
|
523
534
|
triggerPriceSource: TriggerPriceSource.LAST_PRICE | TriggerPriceSource.INDEX_PRICE | undefined;
|
|
524
535
|
};
|
|
525
536
|
oco?: false | undefined;
|
|
@@ -576,6 +587,7 @@ declare function createRiskPolicyInputSchema(scales: SdkScales): v.SchemaWithPip
|
|
|
576
587
|
value?: undefined;
|
|
577
588
|
};
|
|
578
589
|
activationPriceTicks: bigint;
|
|
590
|
+
limitPriceTicks: bigint;
|
|
579
591
|
triggerPriceSource: TriggerPriceSource.LAST_PRICE | TriggerPriceSource.INDEX_PRICE | undefined;
|
|
580
592
|
};
|
|
581
593
|
} | {
|
|
@@ -700,6 +712,7 @@ declare function createRequiredRiskPolicyInputSchema(scales: SdkScales): v.Schem
|
|
|
700
712
|
readonly kind: v.LiteralSchema<"none", undefined>;
|
|
701
713
|
}, undefined>], undefined>, undefined>;
|
|
702
714
|
readonly activationPrice: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
715
|
+
readonly limitPrice: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
703
716
|
readonly triggerPriceSource: v.OptionalSchema<v.SchemaWithPipe<readonly [v.PicklistSchema<["last", "index"], undefined>, v.TransformAction<"last" | "index", TriggerPriceSource.LAST_PRICE | TriggerPriceSource.INDEX_PRICE>]>, undefined>;
|
|
704
717
|
}, undefined>, v.TransformAction<{
|
|
705
718
|
trailingDistance: {
|
|
@@ -719,6 +732,7 @@ declare function createRequiredRiskPolicyInputSchema(scales: SdkScales): v.Schem
|
|
|
719
732
|
kind: "none";
|
|
720
733
|
} | undefined;
|
|
721
734
|
activationPrice?: string | undefined;
|
|
735
|
+
limitPrice?: string | undefined;
|
|
722
736
|
triggerPriceSource?: TriggerPriceSource.LAST_PRICE | TriggerPriceSource.INDEX_PRICE | undefined;
|
|
723
737
|
}, {
|
|
724
738
|
trailingDistance: {
|
|
@@ -742,6 +756,7 @@ declare function createRequiredRiskPolicyInputSchema(scales: SdkScales): v.Schem
|
|
|
742
756
|
value?: undefined;
|
|
743
757
|
};
|
|
744
758
|
activationPriceTicks: bigint;
|
|
759
|
+
limitPriceTicks: bigint;
|
|
745
760
|
triggerPriceSource: TriggerPriceSource.LAST_PRICE | TriggerPriceSource.INDEX_PRICE | undefined;
|
|
746
761
|
}>]>;
|
|
747
762
|
readonly oco: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
@@ -836,6 +851,7 @@ declare function createRequiredRiskPolicyInputSchema(scales: SdkScales): v.Schem
|
|
|
836
851
|
readonly kind: v.LiteralSchema<"none", undefined>;
|
|
837
852
|
}, undefined>], undefined>, undefined>;
|
|
838
853
|
readonly activationPrice: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
854
|
+
readonly limitPrice: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
839
855
|
readonly triggerPriceSource: v.OptionalSchema<v.SchemaWithPipe<readonly [v.PicklistSchema<["last", "index"], undefined>, v.TransformAction<"last" | "index", TriggerPriceSource.LAST_PRICE | TriggerPriceSource.INDEX_PRICE>]>, undefined>;
|
|
840
856
|
}, undefined>, v.TransformAction<{
|
|
841
857
|
trailingDistance: {
|
|
@@ -855,6 +871,7 @@ declare function createRequiredRiskPolicyInputSchema(scales: SdkScales): v.Schem
|
|
|
855
871
|
kind: "none";
|
|
856
872
|
} | undefined;
|
|
857
873
|
activationPrice?: string | undefined;
|
|
874
|
+
limitPrice?: string | undefined;
|
|
858
875
|
triggerPriceSource?: TriggerPriceSource.LAST_PRICE | TriggerPriceSource.INDEX_PRICE | undefined;
|
|
859
876
|
}, {
|
|
860
877
|
trailingDistance: {
|
|
@@ -878,6 +895,7 @@ declare function createRequiredRiskPolicyInputSchema(scales: SdkScales): v.Schem
|
|
|
878
895
|
value?: undefined;
|
|
879
896
|
};
|
|
880
897
|
activationPriceTicks: bigint;
|
|
898
|
+
limitPriceTicks: bigint;
|
|
881
899
|
triggerPriceSource: TriggerPriceSource.LAST_PRICE | TriggerPriceSource.INDEX_PRICE | undefined;
|
|
882
900
|
}>]>;
|
|
883
901
|
readonly oco: v.OptionalSchema<v.LiteralSchema<false, "oco requires takeProfit and exactly one stop leg">, undefined>;
|
|
@@ -947,6 +965,7 @@ declare function createRequiredRiskPolicyInputSchema(scales: SdkScales): v.Schem
|
|
|
947
965
|
value?: undefined;
|
|
948
966
|
};
|
|
949
967
|
activationPriceTicks: bigint;
|
|
968
|
+
limitPriceTicks: bigint;
|
|
950
969
|
triggerPriceSource: TriggerPriceSource.LAST_PRICE | TriggerPriceSource.INDEX_PRICE | undefined;
|
|
951
970
|
};
|
|
952
971
|
oco?: boolean | undefined;
|
|
@@ -1009,6 +1028,7 @@ declare function createRequiredRiskPolicyInputSchema(scales: SdkScales): v.Schem
|
|
|
1009
1028
|
value?: undefined;
|
|
1010
1029
|
};
|
|
1011
1030
|
activationPriceTicks: bigint;
|
|
1031
|
+
limitPriceTicks: bigint;
|
|
1012
1032
|
triggerPriceSource: TriggerPriceSource.LAST_PRICE | TriggerPriceSource.INDEX_PRICE | undefined;
|
|
1013
1033
|
};
|
|
1014
1034
|
oco?: false | undefined;
|
|
@@ -1065,6 +1085,7 @@ declare function createRequiredRiskPolicyInputSchema(scales: SdkScales): v.Schem
|
|
|
1065
1085
|
value?: undefined;
|
|
1066
1086
|
};
|
|
1067
1087
|
activationPriceTicks: bigint;
|
|
1088
|
+
limitPriceTicks: bigint;
|
|
1068
1089
|
triggerPriceSource: TriggerPriceSource.LAST_PRICE | TriggerPriceSource.INDEX_PRICE | undefined;
|
|
1069
1090
|
};
|
|
1070
1091
|
} | {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orders-risk.schemas.d.ts","names":[],"sources":["../../../src/services/orders/orders-risk.schemas.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"orders-risk.schemas.d.ts","names":[],"sources":["../../../src/services/orders/orders-risk.schemas.ts"],"mappings":";;;;iBA8BS,2BAA2B,QAAQ,WAAW,yCAAsC,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+FpF,8BAA8B,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqHxC,4BAA4B,QAAQ,YAAS,EAAA,yBAAA,EAAA,eAAA,EAAA,aAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAO7C,oCAAoC,QAAQ,YAAS,EAAA,yBAAA,EAAA,aAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAOzD,kBAAkB,EAAE,WAAW,kBAAkB;KACjD,gBAAgB,EAAE,WAAW,kBAAkB;KAC/C,oBAAoB,EAAE,WAAW,kBAAkB;KACnD,kBAAkB,EAAE,WAAW,kBAAkB;KAOjD;EACJ;EAAkB;;EAClB;EAAa"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { formatId } from "../../utils/base58-id.js";
|
|
2
2
|
import { tsNsToMs } from "../../utils/time.js";
|
|
3
3
|
import { enumLabel } from "../../shared/proto-enum-codec.js";
|
|
4
|
+
import { CatalogConversionError } from "../../catalogs/types.js";
|
|
4
5
|
import { positiveDecimalInputToScaled, scaledToDecimalOutput } from "../../shared/decimal-surface.js";
|
|
5
6
|
import { BpsStringOrNumberInputSchema, NoneInputSchema, PriceDistanceInputSchema, PriceSlippageInputSchema } from "../shared.js";
|
|
6
7
|
import { RiskLimitGtcSchema, RiskMarketIocSchema } from "../../gen/orders/v1/orders_pb.js";
|
|
@@ -74,13 +75,20 @@ function createTrailingStopInputSchema(scales) {
|
|
|
74
75
|
trailingDistance: TrailingDistanceSchema,
|
|
75
76
|
maxSlippage: v.optional(MaxSlippageSchema),
|
|
76
77
|
activationPrice: v.optional(DecimalInputStringSchema),
|
|
78
|
+
limitPrice: v.optional(DecimalInputStringSchema),
|
|
77
79
|
triggerPriceSource: TriggerPriceSourceInputSchema
|
|
78
|
-
}), v.transform((input) =>
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
}), v.transform((input) => {
|
|
81
|
+
const activationPriceTicks = input.activationPrice === void 0 ? 0n : positiveDecimalInputToScaled("trailingStop.activationPrice", input.activationPrice, scales.price());
|
|
82
|
+
const limitPriceTicks = input.limitPrice === void 0 ? 0n : positiveDecimalInputToScaled("trailingStop.limitPrice", input.limitPrice, scales.price());
|
|
83
|
+
if (limitPriceTicks !== 0n && activationPriceTicks > limitPriceTicks) throw new CatalogConversionError("trailingStop.limitPrice", "trailingStop.limitPrice must be at least trailingStop.activationPrice");
|
|
84
|
+
return {
|
|
85
|
+
trailingDistance: parseTrailingDistance(scales, input.trailingDistance),
|
|
86
|
+
maxSlippage: input.maxSlippage ? parseMaxSlippage(scales, input.maxSlippage) : UNSET_TRAILING_STOP_MAX_SLIPPAGE,
|
|
87
|
+
activationPriceTicks,
|
|
88
|
+
limitPriceTicks,
|
|
89
|
+
triggerPriceSource: input.triggerPriceSource
|
|
90
|
+
};
|
|
91
|
+
}));
|
|
84
92
|
}
|
|
85
93
|
function createRiskPolicyObjectInputSchema(scales) {
|
|
86
94
|
const TakeProfitInputSchema = attachedTriggerInputSchema(scales, "takeProfit");
|
|
@@ -137,6 +145,13 @@ function transformRiskPolicyInput(input) {
|
|
|
137
145
|
oco: input.oco ?? false
|
|
138
146
|
};
|
|
139
147
|
}
|
|
148
|
+
const ATTACHED_TRAILING_LIMIT_SIDE_MESSAGE = "risk.trailingStop.limitPrice is required when the order sells and must be unset when it buys";
|
|
149
|
+
/** An attached trailing stop buys back a SELL order's fill, so only then does it carry a limit price. */
|
|
150
|
+
function attachedTrailingLimitMatchesSide(input) {
|
|
151
|
+
const stopLeg = input.risk?.stopLeg;
|
|
152
|
+
if (stopLeg?.case !== "trailingStop") return true;
|
|
153
|
+
return stopLeg.value.limitPriceTicks !== 0n === (input.side === 2);
|
|
154
|
+
}
|
|
140
155
|
function createRiskPolicyInputSchema(scales) {
|
|
141
156
|
return v.pipe(v.optional(createRiskPolicyObjectInputSchema(scales)), v.transform((input) => input ? transformRiskPolicyInput(input) : void 0));
|
|
142
157
|
}
|
|
@@ -297,6 +312,6 @@ function formatAttachedRisk(scales, risk) {
|
|
|
297
312
|
};
|
|
298
313
|
}
|
|
299
314
|
//#endregion
|
|
300
|
-
export { MarketMaxSlippageSchema, ReadAttachedRiskSchema, createRequiredRiskPolicyInputSchema, createRiskPolicyInputSchema, formatAttachedRisk, formatMarketMaxSlippage, parseMarketMaxSlippage };
|
|
315
|
+
export { ATTACHED_TRAILING_LIMIT_SIDE_MESSAGE, MarketMaxSlippageSchema, ReadAttachedRiskSchema, attachedTrailingLimitMatchesSide, createRequiredRiskPolicyInputSchema, createRiskPolicyInputSchema, formatAttachedRisk, formatMarketMaxSlippage, parseMarketMaxSlippage };
|
|
301
316
|
|
|
302
317
|
//# sourceMappingURL=orders-risk.schemas.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orders-risk.schemas.js","names":["ProtoWrite.RiskMarketIocSchema","ProtoWrite.RiskLimitGtcSchema"],"sources":["../../../src/services/orders/orders-risk.schemas.ts"],"sourcesContent":["import * as ProtoWrite from \"../../gen/orders/v1/orders_pb.js\";\nimport * as ProtoRead from \"../../gen/orders/v1/orders_read_pb.js\";\nimport { create } from \"@bufbuild/protobuf\";\nimport * as v from \"valibot\";\nimport {\n BpsStringOrNumberInputSchema,\n NoneInputSchema,\n PriceDistanceInputSchema,\n PriceSlippageInputSchema,\n} from \"../shared.js\";\nimport {\n positiveDecimalInputToScaled,\n scaledToDecimalOutput,\n type SdkScales,\n} from \"../../shared/decimal-surface.js\";\nimport {\n MAX_SELLING_SLIPPAGE_BPS,\n MAX_SLIPPAGE_BPS,\n parseSlippageInput,\n parseTrailingDistanceInput,\n} from \"../trailing-oneof-inputs.js\";\nimport { enumLabel } from \"../../shared/proto-enum-codec.js\";\nimport { formatId } from \"../../utils/base58-id.js\";\nimport { tsNsToMs } from \"../../utils/time.js\";\nimport { AttachedRiskLegStatusCodec, TriggerPriceSourceCodec } from \"./orders.codecs.js\";\nimport { TriggerPriceSourceInputSchema } from \"./order-enums.codecs.js\";\n\nconst DecimalInputStringSchema = v.pipe(v.string(), v.trim(), v.minLength(1));\n\nfunction attachedTriggerInputSchema(scales: SdkScales, fieldPrefix: \"takeProfit\" | \"stopLoss\") {\n return v.pipe(\n v.strictObject({\n triggerPrice: DecimalInputStringSchema,\n execution: v.variant(\"type\", [\n v.strictObject({\n type: v.literal(\"market_ioc\"),\n }),\n v.strictObject({\n type: v.literal(\"limit_gtc\"),\n price: DecimalInputStringSchema,\n }),\n ]),\n triggerPriceSource: TriggerPriceSourceInputSchema,\n }),\n v.transform((input) => {\n const execution: ProtoWrite.RiskExecution[\"execution\"] =\n input.execution.type === \"market_ioc\"\n ? {\n case: \"marketIoc\",\n value: create(ProtoWrite.RiskMarketIocSchema),\n }\n : {\n case: \"limitGtc\",\n value: create(ProtoWrite.RiskLimitGtcSchema, {\n priceTicks: positiveDecimalInputToScaled(\n `${fieldPrefix}.execution.price`,\n input.execution.price,\n scales.price(),\n ),\n }),\n };\n return {\n triggerPriceTicks: positiveDecimalInputToScaled(\n `${fieldPrefix}.triggerPrice`,\n input.triggerPrice,\n scales.price(),\n ),\n child: { execution },\n triggerPriceSource: input.triggerPriceSource,\n };\n }),\n );\n}\n\nconst TrailingDistanceSchema = v.union([PriceDistanceInputSchema, BpsStringOrNumberInputSchema]);\n\nconst MaxSlippageSchema = v.union([\n PriceSlippageInputSchema,\n BpsStringOrNumberInputSchema,\n NoneInputSchema,\n]);\n\nexport const MarketMaxSlippageSchema = v.union([\n PriceSlippageInputSchema,\n BpsStringOrNumberInputSchema,\n NoneInputSchema,\n]);\n\nconst UNSET_TRAILING_STOP_MAX_SLIPPAGE: ProtoWrite.TrailingStopPolicy[\"maxSlippage\"] = {\n case: undefined,\n value: undefined,\n};\n\nfunction parseTrailingDistance(\n scales: SdkScales,\n distance: v.InferOutput<typeof TrailingDistanceSchema>,\n): ProtoWrite.TrailingStopPolicy[\"trailingDistance\"] {\n return parseTrailingDistanceInput(scales, distance, \"trailingStop.trailingDistance\");\n}\n\nfunction parseMaxSlippage(\n scales: SdkScales,\n slippage: v.InferOutput<typeof MaxSlippageSchema>,\n): ProtoWrite.TrailingStopPolicy[\"maxSlippage\"] {\n return parseSlippageInput(scales, slippage, {\n fieldName: \"trailingStop.maxSlippage\",\n ticksCase: \"maxSlippageTicks\",\n bpsCase: \"maxSlippageBps\",\n maxBps: MAX_SELLING_SLIPPAGE_BPS,\n });\n}\n\nexport function parseMarketMaxSlippage(\n scales: SdkScales,\n slippage: v.InferOutput<typeof MarketMaxSlippageSchema> | undefined,\n): ProtoWrite.MarketIoc[\"maxSlippage\"] {\n return parseSlippageInput(scales, slippage, {\n fieldName: \"execution.maxSlippage\",\n ticksCase: \"maxSlippageTicks\",\n bpsCase: \"maxSlippageBps\",\n maxBps: MAX_SLIPPAGE_BPS,\n });\n}\n\nfunction createTrailingStopInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n trailingDistance: TrailingDistanceSchema,\n maxSlippage: v.optional(MaxSlippageSchema),\n activationPrice: v.optional(DecimalInputStringSchema),\n triggerPriceSource: TriggerPriceSourceInputSchema,\n }),\n v.transform((input) => ({\n trailingDistance: parseTrailingDistance(scales, input.trailingDistance),\n maxSlippage: input.maxSlippage\n ? parseMaxSlippage(scales, input.maxSlippage)\n : UNSET_TRAILING_STOP_MAX_SLIPPAGE,\n activationPriceTicks:\n input.activationPrice === undefined\n ? 0n\n : positiveDecimalInputToScaled(\n \"trailingStop.activationPrice\",\n input.activationPrice,\n scales.price(),\n ),\n triggerPriceSource: input.triggerPriceSource,\n })),\n );\n}\n\nfunction createRiskPolicyObjectInputSchema(scales: SdkScales) {\n const TakeProfitInputSchema = attachedTriggerInputSchema(scales, \"takeProfit\");\n const StopLossInputSchema = attachedTriggerInputSchema(scales, \"stopLoss\");\n const TrailingStopInputSchema = createTrailingStopInputSchema(scales);\n const InactiveOcoInputSchema = v.optional(\n v.literal(false, \"oco requires takeProfit and exactly one stop leg\"),\n );\n return v.union([\n v.strictObject({\n takeProfit: TakeProfitInputSchema,\n stopLoss: StopLossInputSchema,\n trailingStop: v.optional(v.never()),\n oco: v.optional(v.boolean()),\n }),\n v.strictObject({\n takeProfit: TakeProfitInputSchema,\n stopLoss: v.optional(v.never()),\n trailingStop: TrailingStopInputSchema,\n oco: v.optional(v.boolean()),\n }),\n v.strictObject({\n takeProfit: TakeProfitInputSchema,\n stopLoss: v.optional(v.never()),\n trailingStop: v.optional(v.never()),\n oco: InactiveOcoInputSchema,\n }),\n v.strictObject({\n takeProfit: v.optional(v.never()),\n stopLoss: StopLossInputSchema,\n trailingStop: v.optional(v.never()),\n oco: InactiveOcoInputSchema,\n }),\n v.strictObject({\n takeProfit: v.optional(v.never()),\n stopLoss: v.optional(v.never()),\n trailingStop: TrailingStopInputSchema,\n oco: InactiveOcoInputSchema,\n }),\n ]);\n}\n\ntype RiskPolicyObjectInput = v.InferOutput<ReturnType<typeof createRiskPolicyObjectInputSchema>>;\n\nfunction transformRiskPolicyInput(input: RiskPolicyObjectInput) {\n const stopLeg = input.stopLoss\n ? ({ case: \"stopLoss\", value: input.stopLoss } as const)\n : input.trailingStop\n ? ({ case: \"trailingStop\", value: input.trailingStop } as const)\n : ({ case: undefined, value: undefined } as const);\n return {\n takeProfit: input.takeProfit,\n stopLeg,\n oco: input.oco ?? false,\n };\n}\n\nexport function createRiskPolicyInputSchema(scales: SdkScales) {\n return v.pipe(\n v.optional(createRiskPolicyObjectInputSchema(scales)),\n v.transform((input) => (input ? transformRiskPolicyInput(input) : undefined)),\n );\n}\n\nexport function createRequiredRiskPolicyInputSchema(scales: SdkScales) {\n return v.pipe(\n createRiskPolicyObjectInputSchema(scales),\n v.transform((input) => transformRiskPolicyInput(input)),\n );\n}\n\nexport type TakeProfitInput = v.InferInput<ReturnType<typeof attachedTriggerInputSchema>>;\nexport type StopLossInput = v.InferInput<ReturnType<typeof attachedTriggerInputSchema>>;\nexport type TrailingStopInput = v.InferInput<ReturnType<typeof createTrailingStopInputSchema>>;\nexport type RiskPolicyInput = v.InferInput<ReturnType<typeof createRiskPolicyInputSchema>>;\n\ntype TrailingDistance =\n | { kind: \"distance\"; distance: string }\n | { kind: \"bps\"; bps: number }\n | { kind: \"none\" };\ntype TrailingMaxSlippage = { kind: \"slippage\"; slippage: string } | { kind: \"bps\"; bps: number };\nexport type MarketMaxSlippage =\n | { kind: \"slippage\"; slippage: string }\n | { kind: \"bps\"; bps: number };\n\nconst ReadRiskExecutionSchema = v.object({\n execution: v.variant(\"case\", [\n v.object({\n case: v.literal(\"marketIoc\"),\n value: v.object({}),\n }),\n v.object({\n case: v.literal(\"limitGtc\"),\n value: v.object({\n priceTicks: v.bigint(),\n }),\n }),\n ]),\n});\n\nconst ReadTakeProfitPolicySchema = v.object({\n triggerPriceTicks: v.bigint(),\n child: ReadRiskExecutionSchema,\n triggerPriceSource: v.optional(v.number(), 0),\n});\n\nconst ReadStopLossPolicySchema = v.object({\n triggerPriceTicks: v.bigint(),\n child: ReadRiskExecutionSchema,\n triggerPriceSource: v.optional(v.number(), 0),\n});\n\nconst ReadTrailingStopPolicySchema = v.object({\n trailingDistance: v.object({\n case: v.optional(\n v.union([\n v.literal(\"trailingDistanceTicks\"),\n v.literal(\"trailingDistanceBps\"),\n v.undefined(),\n ]),\n ),\n value: v.optional(v.union([v.bigint(), v.number(), v.undefined()])),\n }),\n maxSlippage: v.object({\n case: v.union([v.literal(\"maxSlippageTicks\"), v.literal(\"maxSlippageBps\"), v.undefined()]),\n value: v.optional(v.union([v.bigint(), v.number(), v.undefined()])),\n }),\n activationPriceTicks: v.bigint(),\n triggerPriceSource: v.optional(v.number(), 0),\n});\n\nconst ReadAttachedRiskLegStateSchema = v.object({\n status: v.number(),\n armedTsNs: v.bigint(),\n terminalTsNs: v.bigint(),\n triggerId: v.optional(v.bigint()),\n childOrderId: v.optional(v.bigint()),\n});\n\nconst ReadAttachedRiskTakeProfitSchema = v.object({\n policy: v.optional(ReadTakeProfitPolicySchema),\n state: v.optional(ReadAttachedRiskLegStateSchema),\n});\n\nconst ReadAttachedRiskStopLossSchema = v.object({\n policy: v.optional(ReadStopLossPolicySchema),\n state: v.optional(ReadAttachedRiskLegStateSchema),\n});\n\nconst ReadAttachedRiskTrailingStopSchema = v.object({\n policy: v.optional(ReadTrailingStopPolicySchema),\n state: v.optional(ReadAttachedRiskLegStateSchema),\n});\n\nexport const ReadAttachedRiskSchema = v.object({\n takeProfit: v.optional(ReadAttachedRiskTakeProfitSchema),\n stopLoss: v.optional(ReadAttachedRiskStopLossSchema),\n trailingStop: v.optional(ReadAttachedRiskTrailingStopSchema),\n oco: v.optional(v.boolean(), false),\n});\n\nfunction formatRiskExecution(\n scales: SdkScales,\n child: v.InferOutput<typeof ReadRiskExecutionSchema>,\n) {\n if (child.execution.case === \"marketIoc\") {\n return { type: \"market_ioc\" } as const;\n }\n return {\n type: \"limit_gtc\",\n price: scaledToDecimalOutput(child.execution.value.priceTicks, scales.price()),\n } as const;\n}\n\nfunction formatRiskLeg(\n scales: SdkScales,\n leg:\n | v.InferOutput<typeof ReadTakeProfitPolicySchema>\n | v.InferOutput<typeof ReadStopLossPolicySchema>,\n) {\n return {\n triggerPrice: scaledToDecimalOutput(leg.triggerPriceTicks, scales.price()),\n execution: formatRiskExecution(scales, leg.child),\n triggerPriceSource: enumLabel(\n TriggerPriceSourceCodec.protoToOutput,\n leg.triggerPriceSource,\n ),\n };\n}\n\nfunction formatRiskLegState(state: v.InferOutput<typeof ReadAttachedRiskLegStateSchema>) {\n return {\n status: enumLabel(AttachedRiskLegStatusCodec.protoToOutput, state.status),\n armedTs: state.armedTsNs > 0n ? tsNsToMs(state.armedTsNs) : undefined,\n armedTsNs: state.armedTsNs > 0n ? state.armedTsNs.toString() : undefined,\n terminalTs: state.terminalTsNs > 0n ? tsNsToMs(state.terminalTsNs) : undefined,\n terminalTsNs: state.terminalTsNs > 0n ? state.terminalTsNs.toString() : undefined,\n triggerId:\n state.triggerId !== undefined && state.triggerId > 0n\n ? formatId(state.triggerId)\n : undefined,\n childOrderId:\n state.childOrderId !== undefined && state.childOrderId > 0n\n ? formatId(state.childOrderId)\n : undefined,\n };\n}\n\nfunction formatTrailingDistance(\n scales: SdkScales,\n distance: v.InferOutput<typeof ReadTrailingStopPolicySchema>[\"trailingDistance\"],\n): TrailingDistance {\n if (distance.case === \"trailingDistanceTicks\" && typeof distance.value === \"bigint\") {\n return {\n kind: \"distance\",\n distance: scaledToDecimalOutput(distance.value, scales.price()),\n };\n }\n if (distance.case === \"trailingDistanceBps\" && typeof distance.value === \"number\") {\n return { kind: \"bps\", bps: distance.value };\n }\n return { kind: \"none\" };\n}\n\nfunction formatTrailingMaxSlippage(\n scales: SdkScales,\n slippage: v.InferOutput<typeof ReadTrailingStopPolicySchema>[\"maxSlippage\"],\n): TrailingMaxSlippage | undefined {\n if (slippage.case === \"maxSlippageTicks\" && typeof slippage.value === \"bigint\") {\n return {\n kind: \"slippage\",\n slippage: scaledToDecimalOutput(slippage.value, scales.price()),\n };\n }\n if (slippage.case === \"maxSlippageBps\" && typeof slippage.value === \"number\") {\n return { kind: \"bps\", bps: slippage.value };\n }\n return undefined;\n}\n\nexport function formatMarketMaxSlippage(\n scales: SdkScales,\n ticks: bigint,\n bps: number,\n): MarketMaxSlippage | undefined {\n if (ticks > 0n) {\n return { kind: \"slippage\", slippage: scaledToDecimalOutput(ticks, scales.price()) };\n }\n if (bps > 0) {\n return { kind: \"bps\", bps };\n }\n return undefined;\n}\n\nexport function formatAttachedRisk(\n scales: SdkScales,\n risk: v.InferOutput<typeof ReadAttachedRiskSchema> | undefined,\n) {\n if (!risk) return undefined;\n\n const takeProfit =\n risk.takeProfit?.policy ||\n (risk.takeProfit?.state &&\n risk.takeProfit.state.status !== ProtoRead.AttachedRiskLegState_Status.NOT_CONFIGURED)\n ? {\n ...(risk.takeProfit.policy\n ? formatRiskLeg(scales, risk.takeProfit.policy)\n : undefined),\n state: risk.takeProfit.state\n ? formatRiskLegState(risk.takeProfit.state)\n : undefined,\n }\n : undefined;\n const stopLoss =\n risk.stopLoss?.policy ||\n (risk.stopLoss?.state &&\n risk.stopLoss.state.status !== ProtoRead.AttachedRiskLegState_Status.NOT_CONFIGURED)\n ? {\n ...(risk.stopLoss.policy\n ? formatRiskLeg(scales, risk.stopLoss.policy)\n : undefined),\n state: risk.stopLoss.state ? formatRiskLegState(risk.stopLoss.state) : undefined,\n }\n : undefined;\n const trailingStop =\n risk.trailingStop?.policy ||\n (risk.trailingStop?.state &&\n risk.trailingStop.state.status !== ProtoRead.AttachedRiskLegState_Status.NOT_CONFIGURED)\n ? {\n ...(risk.trailingStop.policy\n ? {\n trailingDistance: formatTrailingDistance(\n scales,\n risk.trailingStop.policy.trailingDistance,\n ),\n maxSlippage: formatTrailingMaxSlippage(\n scales,\n risk.trailingStop.policy.maxSlippage,\n ),\n activationPrice:\n risk.trailingStop.policy.activationPriceTicks > 0n\n ? scaledToDecimalOutput(\n risk.trailingStop.policy.activationPriceTicks,\n scales.price(),\n )\n : undefined,\n triggerPriceSource: enumLabel(\n TriggerPriceSourceCodec.protoToOutput,\n risk.trailingStop.policy.triggerPriceSource,\n ),\n }\n : undefined),\n state: risk.trailingStop.state\n ? formatRiskLegState(risk.trailingStop.state)\n : undefined,\n }\n : undefined;\n\n if (!takeProfit && !stopLoss && !trailingStop) return undefined;\n\n return {\n takeProfit,\n stopLoss,\n trailingStop,\n oco: risk.oco,\n };\n}\n"],"mappings":";;;;;;;;;;;;;AA2BA,MAAM,2BAA2B,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,GAAG,EAAE,UAAU,CAAC,CAAC;AAE5E,SAAS,2BAA2B,QAAmB,aAAwC;CAC3F,OAAO,EAAE,KACL,EAAE,aAAa;EACX,cAAc;EACd,WAAW,EAAE,QAAQ,QAAQ,CACzB,EAAE,aAAa,EACX,MAAM,EAAE,QAAQ,YAAY,EAChC,CAAC,GACD,EAAE,aAAa;GACX,MAAM,EAAE,QAAQ,WAAW;GAC3B,OAAO;EACX,CAAC,CACL,CAAC;EACD,oBAAoB;CACxB,CAAC,GACD,EAAE,WAAW,UAAU;EACnB,MAAM,YACF,MAAM,UAAU,SAAS,eACnB;GACI,MAAM;GACN,OAAO,OAAOA,mBAA8B;EAChD,IACA;GACI,MAAM;GACN,OAAO,OAAOC,oBAA+B,EACzC,YAAY,6BACR,GAAG,YAAY,mBACf,MAAM,UAAU,OAChB,OAAO,MAAM,CACjB,EACJ,CAAC;EACL;EACV,OAAO;GACH,mBAAmB,6BACf,GAAG,YAAY,gBACf,MAAM,cACN,OAAO,MAAM,CACjB;GACA,OAAO,EAAE,UAAU;GACnB,oBAAoB,MAAM;EAC9B;CACJ,CAAC,CACL;AACJ;AAEA,MAAM,yBAAyB,EAAE,MAAM,CAAC,0BAA0B,4BAA4B,CAAC;AAE/F,MAAM,oBAAoB,EAAE,MAAM;CAC9B;CACA;CACA;AACJ,CAAC;AAED,MAAa,0BAA0B,EAAE,MAAM;CAC3C;CACA;CACA;AACJ,CAAC;AAED,MAAM,mCAAiF;CACnF,MAAM,KAAA;CACN,OAAO,KAAA;AACX;AAEA,SAAS,sBACL,QACA,UACiD;CACjD,OAAO,2BAA2B,QAAQ,UAAU,+BAA+B;AACvF;AAEA,S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Q,KAAK,SAAS,MAAM,IAC1C,KAAA;EACN,OAAO,KAAK,SAAS,QAAQ,mBAAmB,KAAK,SAAS,KAAK,IAAI,KAAA;CAC3E,IACA,KAAA;CACV,MAAM,eACF,KAAK,cAAc,UAClB,KAAK,cAAc,SAChB,KAAK,aAAa,MAAM,WAAA,IACtB;EACI,GAAI,KAAK,aAAa,SAChB;GACI,kBAAkB,uBACd,QACA,KAAK,aAAa,OAAO,gBAC7B;GACA,aAAa,0BACT,QACA,KAAK,aAAa,OAAO,WAC7B;GACA,iBACI,KAAK,aAAa,OAAO,uBAAuB,KAC1C,sBACI,KAAK,aAAa,OAAO,sBACzB,OAAO,MAAM,CACjB,IACA,KAAA;GACV,oBAAoB,UAChB,wBAAwB,eACxB,KAAK,aAAa,OAAO,kBAC7B;EACJ,IACA,KAAA;EACN,OAAO,KAAK,aAAa,QACnB,mBAAmB,KAAK,aAAa,KAAK,IAC1C,KAAA;CACV,IACA,KAAA;CAEV,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,cAAc,OAAO,KAAA;CAEtD,OAAO;EACH;EACA;EACA;EACA,KAAK,KAAK;CACd;AACJ"}
|
|
1
|
+
{"version":3,"file":"orders-risk.schemas.js","names":["ProtoWrite.RiskMarketIocSchema","ProtoWrite.RiskLimitGtcSchema"],"sources":["../../../src/services/orders/orders-risk.schemas.ts"],"sourcesContent":["import * as ProtoWrite from \"../../gen/orders/v1/orders_pb.js\";\nimport * as ProtoRead from \"../../gen/orders/v1/orders_read_pb.js\";\nimport { create } from \"@bufbuild/protobuf\";\nimport * as v from \"valibot\";\nimport {\n BpsStringOrNumberInputSchema,\n NoneInputSchema,\n PriceDistanceInputSchema,\n PriceSlippageInputSchema,\n} from \"../shared.js\";\nimport {\n positiveDecimalInputToScaled,\n scaledToDecimalOutput,\n type SdkScales,\n} from \"../../shared/decimal-surface.js\";\nimport {\n MAX_SELLING_SLIPPAGE_BPS,\n MAX_SLIPPAGE_BPS,\n parseSlippageInput,\n parseTrailingDistanceInput,\n} from \"../trailing-oneof-inputs.js\";\nimport { CatalogConversionError } from \"../../catalogs/types.js\";\nimport { enumLabel } from \"../../shared/proto-enum-codec.js\";\nimport { formatId } from \"../../utils/base58-id.js\";\nimport { tsNsToMs } from \"../../utils/time.js\";\nimport { AttachedRiskLegStatusCodec, TriggerPriceSourceCodec } from \"./orders.codecs.js\";\nimport { TriggerPriceSourceInputSchema } from \"./order-enums.codecs.js\";\n\nconst DecimalInputStringSchema = v.pipe(v.string(), v.trim(), v.minLength(1));\n\nfunction attachedTriggerInputSchema(scales: SdkScales, fieldPrefix: \"takeProfit\" | \"stopLoss\") {\n return v.pipe(\n v.strictObject({\n triggerPrice: DecimalInputStringSchema,\n execution: v.variant(\"type\", [\n v.strictObject({\n type: v.literal(\"market_ioc\"),\n }),\n v.strictObject({\n type: v.literal(\"limit_gtc\"),\n price: DecimalInputStringSchema,\n }),\n ]),\n triggerPriceSource: TriggerPriceSourceInputSchema,\n }),\n v.transform((input) => {\n const execution: ProtoWrite.RiskExecution[\"execution\"] =\n input.execution.type === \"market_ioc\"\n ? {\n case: \"marketIoc\",\n value: create(ProtoWrite.RiskMarketIocSchema),\n }\n : {\n case: \"limitGtc\",\n value: create(ProtoWrite.RiskLimitGtcSchema, {\n priceTicks: positiveDecimalInputToScaled(\n `${fieldPrefix}.execution.price`,\n input.execution.price,\n scales.price(),\n ),\n }),\n };\n return {\n triggerPriceTicks: positiveDecimalInputToScaled(\n `${fieldPrefix}.triggerPrice`,\n input.triggerPrice,\n scales.price(),\n ),\n child: { execution },\n triggerPriceSource: input.triggerPriceSource,\n };\n }),\n );\n}\n\nconst TrailingDistanceSchema = v.union([PriceDistanceInputSchema, BpsStringOrNumberInputSchema]);\n\nconst MaxSlippageSchema = v.union([\n PriceSlippageInputSchema,\n BpsStringOrNumberInputSchema,\n NoneInputSchema,\n]);\n\nexport const MarketMaxSlippageSchema = v.union([\n PriceSlippageInputSchema,\n BpsStringOrNumberInputSchema,\n NoneInputSchema,\n]);\n\nconst UNSET_TRAILING_STOP_MAX_SLIPPAGE: ProtoWrite.TrailingStopPolicy[\"maxSlippage\"] = {\n case: undefined,\n value: undefined,\n};\n\nfunction parseTrailingDistance(\n scales: SdkScales,\n distance: v.InferOutput<typeof TrailingDistanceSchema>,\n): ProtoWrite.TrailingStopPolicy[\"trailingDistance\"] {\n return parseTrailingDistanceInput(scales, distance, \"trailingStop.trailingDistance\");\n}\n\nfunction parseMaxSlippage(\n scales: SdkScales,\n slippage: v.InferOutput<typeof MaxSlippageSchema>,\n): ProtoWrite.TrailingStopPolicy[\"maxSlippage\"] {\n return parseSlippageInput(scales, slippage, {\n fieldName: \"trailingStop.maxSlippage\",\n ticksCase: \"maxSlippageTicks\",\n bpsCase: \"maxSlippageBps\",\n maxBps: MAX_SELLING_SLIPPAGE_BPS,\n });\n}\n\nexport function parseMarketMaxSlippage(\n scales: SdkScales,\n slippage: v.InferOutput<typeof MarketMaxSlippageSchema> | undefined,\n): ProtoWrite.MarketIoc[\"maxSlippage\"] {\n return parseSlippageInput(scales, slippage, {\n fieldName: \"execution.maxSlippage\",\n ticksCase: \"maxSlippageTicks\",\n bpsCase: \"maxSlippageBps\",\n maxBps: MAX_SLIPPAGE_BPS,\n });\n}\n\nfunction createTrailingStopInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n trailingDistance: TrailingDistanceSchema,\n maxSlippage: v.optional(MaxSlippageSchema),\n activationPrice: v.optional(DecimalInputStringSchema),\n // The most a buy-back pays per unit: required when the parent order sells, unset when it buys.\n limitPrice: v.optional(DecimalInputStringSchema),\n triggerPriceSource: TriggerPriceSourceInputSchema,\n }),\n v.transform((input) => {\n const activationPriceTicks =\n input.activationPrice === undefined\n ? 0n\n : positiveDecimalInputToScaled(\n \"trailingStop.activationPrice\",\n input.activationPrice,\n scales.price(),\n );\n const limitPriceTicks =\n input.limitPrice === undefined\n ? 0n\n : positiveDecimalInputToScaled(\n \"trailingStop.limitPrice\",\n input.limitPrice,\n scales.price(),\n );\n if (limitPriceTicks !== 0n && activationPriceTicks > limitPriceTicks) {\n throw new CatalogConversionError(\n \"trailingStop.limitPrice\",\n \"trailingStop.limitPrice must be at least trailingStop.activationPrice\",\n );\n }\n return {\n trailingDistance: parseTrailingDistance(scales, input.trailingDistance),\n maxSlippage: input.maxSlippage\n ? parseMaxSlippage(scales, input.maxSlippage)\n : UNSET_TRAILING_STOP_MAX_SLIPPAGE,\n activationPriceTicks,\n limitPriceTicks,\n triggerPriceSource: input.triggerPriceSource,\n };\n }),\n );\n}\n\nfunction createRiskPolicyObjectInputSchema(scales: SdkScales) {\n const TakeProfitInputSchema = attachedTriggerInputSchema(scales, \"takeProfit\");\n const StopLossInputSchema = attachedTriggerInputSchema(scales, \"stopLoss\");\n const TrailingStopInputSchema = createTrailingStopInputSchema(scales);\n const InactiveOcoInputSchema = v.optional(\n v.literal(false, \"oco requires takeProfit and exactly one stop leg\"),\n );\n return v.union([\n v.strictObject({\n takeProfit: TakeProfitInputSchema,\n stopLoss: StopLossInputSchema,\n trailingStop: v.optional(v.never()),\n oco: v.optional(v.boolean()),\n }),\n v.strictObject({\n takeProfit: TakeProfitInputSchema,\n stopLoss: v.optional(v.never()),\n trailingStop: TrailingStopInputSchema,\n oco: v.optional(v.boolean()),\n }),\n v.strictObject({\n takeProfit: TakeProfitInputSchema,\n stopLoss: v.optional(v.never()),\n trailingStop: v.optional(v.never()),\n oco: InactiveOcoInputSchema,\n }),\n v.strictObject({\n takeProfit: v.optional(v.never()),\n stopLoss: StopLossInputSchema,\n trailingStop: v.optional(v.never()),\n oco: InactiveOcoInputSchema,\n }),\n v.strictObject({\n takeProfit: v.optional(v.never()),\n stopLoss: v.optional(v.never()),\n trailingStop: TrailingStopInputSchema,\n oco: InactiveOcoInputSchema,\n }),\n ]);\n}\n\ntype RiskPolicyObjectInput = v.InferOutput<ReturnType<typeof createRiskPolicyObjectInputSchema>>;\n\nfunction transformRiskPolicyInput(input: RiskPolicyObjectInput) {\n const stopLeg = input.stopLoss\n ? ({ case: \"stopLoss\", value: input.stopLoss } as const)\n : input.trailingStop\n ? ({ case: \"trailingStop\", value: input.trailingStop } as const)\n : ({ case: undefined, value: undefined } as const);\n return {\n takeProfit: input.takeProfit,\n stopLeg,\n oco: input.oco ?? false,\n };\n}\n\nexport const ATTACHED_TRAILING_LIMIT_SIDE_MESSAGE =\n \"risk.trailingStop.limitPrice is required when the order sells and must be unset when it buys\";\n\n/** An attached trailing stop buys back a SELL order's fill, so only then does it carry a limit price. */\nexport function attachedTrailingLimitMatchesSide(input: {\n side: ProtoWrite.Side;\n risk?: ReturnType<typeof transformRiskPolicyInput>;\n}): boolean {\n const stopLeg = input.risk?.stopLeg;\n if (stopLeg?.case !== \"trailingStop\") {\n return true;\n }\n return (stopLeg.value.limitPriceTicks !== 0n) === (input.side === ProtoWrite.Side.SELL);\n}\n\nexport function createRiskPolicyInputSchema(scales: SdkScales) {\n return v.pipe(\n v.optional(createRiskPolicyObjectInputSchema(scales)),\n v.transform((input) => (input ? transformRiskPolicyInput(input) : undefined)),\n );\n}\n\nexport function createRequiredRiskPolicyInputSchema(scales: SdkScales) {\n return v.pipe(\n createRiskPolicyObjectInputSchema(scales),\n v.transform((input) => transformRiskPolicyInput(input)),\n );\n}\n\nexport type TakeProfitInput = v.InferInput<ReturnType<typeof attachedTriggerInputSchema>>;\nexport type StopLossInput = v.InferInput<ReturnType<typeof attachedTriggerInputSchema>>;\nexport type TrailingStopInput = v.InferInput<ReturnType<typeof createTrailingStopInputSchema>>;\nexport type RiskPolicyInput = v.InferInput<ReturnType<typeof createRiskPolicyInputSchema>>;\n\ntype TrailingDistance =\n | { kind: \"distance\"; distance: string }\n | { kind: \"bps\"; bps: number }\n | { kind: \"none\" };\ntype TrailingMaxSlippage = { kind: \"slippage\"; slippage: string } | { kind: \"bps\"; bps: number };\nexport type MarketMaxSlippage =\n | { kind: \"slippage\"; slippage: string }\n | { kind: \"bps\"; bps: number };\n\nconst ReadRiskExecutionSchema = v.object({\n execution: v.variant(\"case\", [\n v.object({\n case: v.literal(\"marketIoc\"),\n value: v.object({}),\n }),\n v.object({\n case: v.literal(\"limitGtc\"),\n value: v.object({\n priceTicks: v.bigint(),\n }),\n }),\n ]),\n});\n\nconst ReadTakeProfitPolicySchema = v.object({\n triggerPriceTicks: v.bigint(),\n child: ReadRiskExecutionSchema,\n triggerPriceSource: v.optional(v.number(), 0),\n});\n\nconst ReadStopLossPolicySchema = v.object({\n triggerPriceTicks: v.bigint(),\n child: ReadRiskExecutionSchema,\n triggerPriceSource: v.optional(v.number(), 0),\n});\n\nconst ReadTrailingStopPolicySchema = v.object({\n trailingDistance: v.object({\n case: v.optional(\n v.union([\n v.literal(\"trailingDistanceTicks\"),\n v.literal(\"trailingDistanceBps\"),\n v.undefined(),\n ]),\n ),\n value: v.optional(v.union([v.bigint(), v.number(), v.undefined()])),\n }),\n maxSlippage: v.object({\n case: v.union([v.literal(\"maxSlippageTicks\"), v.literal(\"maxSlippageBps\"), v.undefined()]),\n value: v.optional(v.union([v.bigint(), v.number(), v.undefined()])),\n }),\n activationPriceTicks: v.bigint(),\n triggerPriceSource: v.optional(v.number(), 0),\n});\n\nconst ReadAttachedRiskLegStateSchema = v.object({\n status: v.number(),\n armedTsNs: v.bigint(),\n terminalTsNs: v.bigint(),\n triggerId: v.optional(v.bigint()),\n childOrderId: v.optional(v.bigint()),\n});\n\nconst ReadAttachedRiskTakeProfitSchema = v.object({\n policy: v.optional(ReadTakeProfitPolicySchema),\n state: v.optional(ReadAttachedRiskLegStateSchema),\n});\n\nconst ReadAttachedRiskStopLossSchema = v.object({\n policy: v.optional(ReadStopLossPolicySchema),\n state: v.optional(ReadAttachedRiskLegStateSchema),\n});\n\nconst ReadAttachedRiskTrailingStopSchema = v.object({\n policy: v.optional(ReadTrailingStopPolicySchema),\n state: v.optional(ReadAttachedRiskLegStateSchema),\n});\n\nexport const ReadAttachedRiskSchema = v.object({\n takeProfit: v.optional(ReadAttachedRiskTakeProfitSchema),\n stopLoss: v.optional(ReadAttachedRiskStopLossSchema),\n trailingStop: v.optional(ReadAttachedRiskTrailingStopSchema),\n oco: v.optional(v.boolean(), false),\n});\n\nfunction formatRiskExecution(\n scales: SdkScales,\n child: v.InferOutput<typeof ReadRiskExecutionSchema>,\n) {\n if (child.execution.case === \"marketIoc\") {\n return { type: \"market_ioc\" } as const;\n }\n return {\n type: \"limit_gtc\",\n price: scaledToDecimalOutput(child.execution.value.priceTicks, scales.price()),\n } as const;\n}\n\nfunction formatRiskLeg(\n scales: SdkScales,\n leg:\n | v.InferOutput<typeof ReadTakeProfitPolicySchema>\n | v.InferOutput<typeof ReadStopLossPolicySchema>,\n) {\n return {\n triggerPrice: scaledToDecimalOutput(leg.triggerPriceTicks, scales.price()),\n execution: formatRiskExecution(scales, leg.child),\n triggerPriceSource: enumLabel(\n TriggerPriceSourceCodec.protoToOutput,\n leg.triggerPriceSource,\n ),\n };\n}\n\nfunction formatRiskLegState(state: v.InferOutput<typeof ReadAttachedRiskLegStateSchema>) {\n return {\n status: enumLabel(AttachedRiskLegStatusCodec.protoToOutput, state.status),\n armedTs: state.armedTsNs > 0n ? tsNsToMs(state.armedTsNs) : undefined,\n armedTsNs: state.armedTsNs > 0n ? state.armedTsNs.toString() : undefined,\n terminalTs: state.terminalTsNs > 0n ? tsNsToMs(state.terminalTsNs) : undefined,\n terminalTsNs: state.terminalTsNs > 0n ? state.terminalTsNs.toString() : undefined,\n triggerId:\n state.triggerId !== undefined && state.triggerId > 0n\n ? formatId(state.triggerId)\n : undefined,\n childOrderId:\n state.childOrderId !== undefined && state.childOrderId > 0n\n ? formatId(state.childOrderId)\n : undefined,\n };\n}\n\nfunction formatTrailingDistance(\n scales: SdkScales,\n distance: v.InferOutput<typeof ReadTrailingStopPolicySchema>[\"trailingDistance\"],\n): TrailingDistance {\n if (distance.case === \"trailingDistanceTicks\" && typeof distance.value === \"bigint\") {\n return {\n kind: \"distance\",\n distance: scaledToDecimalOutput(distance.value, scales.price()),\n };\n }\n if (distance.case === \"trailingDistanceBps\" && typeof distance.value === \"number\") {\n return { kind: \"bps\", bps: distance.value };\n }\n return { kind: \"none\" };\n}\n\nfunction formatTrailingMaxSlippage(\n scales: SdkScales,\n slippage: v.InferOutput<typeof ReadTrailingStopPolicySchema>[\"maxSlippage\"],\n): TrailingMaxSlippage | undefined {\n if (slippage.case === \"maxSlippageTicks\" && typeof slippage.value === \"bigint\") {\n return {\n kind: \"slippage\",\n slippage: scaledToDecimalOutput(slippage.value, scales.price()),\n };\n }\n if (slippage.case === \"maxSlippageBps\" && typeof slippage.value === \"number\") {\n return { kind: \"bps\", bps: slippage.value };\n }\n return undefined;\n}\n\nexport function formatMarketMaxSlippage(\n scales: SdkScales,\n ticks: bigint,\n bps: number,\n): MarketMaxSlippage | undefined {\n if (ticks > 0n) {\n return { kind: \"slippage\", slippage: scaledToDecimalOutput(ticks, scales.price()) };\n }\n if (bps > 0) {\n return { kind: \"bps\", bps };\n }\n return undefined;\n}\n\nexport function formatAttachedRisk(\n scales: SdkScales,\n risk: v.InferOutput<typeof ReadAttachedRiskSchema> | undefined,\n) {\n if (!risk) return undefined;\n\n const takeProfit =\n risk.takeProfit?.policy ||\n (risk.takeProfit?.state &&\n risk.takeProfit.state.status !== ProtoRead.AttachedRiskLegState_Status.NOT_CONFIGURED)\n ? {\n ...(risk.takeProfit.policy\n ? formatRiskLeg(scales, risk.takeProfit.policy)\n : undefined),\n state: risk.takeProfit.state\n ? formatRiskLegState(risk.takeProfit.state)\n : undefined,\n }\n : undefined;\n const stopLoss =\n risk.stopLoss?.policy ||\n (risk.stopLoss?.state &&\n risk.stopLoss.state.status !== ProtoRead.AttachedRiskLegState_Status.NOT_CONFIGURED)\n ? {\n ...(risk.stopLoss.policy\n ? formatRiskLeg(scales, risk.stopLoss.policy)\n : undefined),\n state: risk.stopLoss.state ? formatRiskLegState(risk.stopLoss.state) : undefined,\n }\n : undefined;\n const trailingStop =\n risk.trailingStop?.policy ||\n (risk.trailingStop?.state &&\n risk.trailingStop.state.status !== ProtoRead.AttachedRiskLegState_Status.NOT_CONFIGURED)\n ? {\n ...(risk.trailingStop.policy\n ? {\n trailingDistance: formatTrailingDistance(\n scales,\n risk.trailingStop.policy.trailingDistance,\n ),\n maxSlippage: formatTrailingMaxSlippage(\n scales,\n risk.trailingStop.policy.maxSlippage,\n ),\n activationPrice:\n risk.trailingStop.policy.activationPriceTicks > 0n\n ? scaledToDecimalOutput(\n risk.trailingStop.policy.activationPriceTicks,\n scales.price(),\n )\n : undefined,\n triggerPriceSource: enumLabel(\n TriggerPriceSourceCodec.protoToOutput,\n risk.trailingStop.policy.triggerPriceSource,\n ),\n }\n : undefined),\n state: risk.trailingStop.state\n ? formatRiskLegState(risk.trailingStop.state)\n : undefined,\n }\n : undefined;\n\n if (!takeProfit && !stopLoss && !trailingStop) return undefined;\n\n return {\n takeProfit,\n stopLoss,\n trailingStop,\n oco: risk.oco,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AA4BA,MAAM,2BAA2B,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,GAAG,EAAE,UAAU,CAAC,CAAC;AAE5E,SAAS,2BAA2B,QAAmB,aAAwC;CAC3F,OAAO,EAAE,KACL,EAAE,aAAa;EACX,cAAc;EACd,WAAW,EAAE,QAAQ,QAAQ,CACzB,EAAE,aAAa,EACX,MAAM,EAAE,QAAQ,YAAY,EAChC,CAAC,GACD,EAAE,aAAa;GACX,MAAM,EAAE,QAAQ,WAAW;GAC3B,OAAO;EACX,CAAC,CACL,CAAC;EACD,oBAAoB;CACxB,CAAC,GACD,EAAE,WAAW,UAAU;EACnB,MAAM,YACF,MAAM,UAAU,SAAS,eACnB;GACI,MAAM;GACN,OAAO,OAAOA,mBAA8B;EAChD,IACA;GACI,MAAM;GACN,OAAO,OAAOC,oBAA+B,EACzC,YAAY,6BACR,GAAG,YAAY,mBACf,MAAM,UAAU,OAChB,OAAO,MAAM,CACjB,EACJ,CAAC;EACL;EACV,OAAO;GACH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B,KAC1C,sBACI,KAAK,aAAa,OAAO,sBACzB,OAAO,MAAM,CACjB,IACA,KAAA;GACV,oBAAoB,UAChB,wBAAwB,eACxB,KAAK,aAAa,OAAO,kBAC7B;EACJ,IACA,KAAA;EACN,OAAO,KAAK,aAAa,QACnB,mBAAmB,KAAK,aAAa,KAAK,IAC1C,KAAA;CACV,IACA,KAAA;CAEV,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,cAAc,OAAO,KAAA;CAEtD,OAAO;EACH;EACA;EACA;EACA,KAAK,KAAK;CACd;AACJ"}
|
|
@@ -19,7 +19,7 @@ declare const RewardAwardSchema: v.ObjectSchema<{
|
|
|
19
19
|
readonly assetId: v.NumberSchema<undefined>;
|
|
20
20
|
readonly amountBaseUnits: v.StringSchema<undefined>;
|
|
21
21
|
readonly fulfillmentMethod: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "external_testnet" | "internal_trading">]>;
|
|
22
|
-
readonly fulfillmentState: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "
|
|
22
|
+
readonly fulfillmentState: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "failed" | "awaiting_destination" | "ready_for_payout" | "paid" | "canceled">]>;
|
|
23
23
|
readonly publishedAt: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
|
|
24
24
|
readonly seconds: v.BigintSchema<undefined>;
|
|
25
25
|
readonly nanos: v.OptionalSchema<v.NumberSchema<undefined>, 0>;
|
|
@@ -41,7 +41,7 @@ declare const ListRewardAwardsResultSchema: v.ObjectSchema<{
|
|
|
41
41
|
readonly assetId: v.NumberSchema<undefined>;
|
|
42
42
|
readonly amountBaseUnits: v.StringSchema<undefined>;
|
|
43
43
|
readonly fulfillmentMethod: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "external_testnet" | "internal_trading">]>;
|
|
44
|
-
readonly fulfillmentState: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "
|
|
44
|
+
readonly fulfillmentState: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "failed" | "awaiting_destination" | "ready_for_payout" | "paid" | "canceled">]>;
|
|
45
45
|
readonly publishedAt: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
|
|
46
46
|
readonly seconds: v.BigintSchema<undefined>;
|
|
47
47
|
readonly nanos: v.OptionalSchema<v.NumberSchema<undefined>, 0>;
|
|
@@ -65,7 +65,7 @@ declare const SetRewardDestinationResultSchema: v.ObjectSchema<{
|
|
|
65
65
|
readonly assetId: v.NumberSchema<undefined>;
|
|
66
66
|
readonly amountBaseUnits: v.StringSchema<undefined>;
|
|
67
67
|
readonly fulfillmentMethod: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "external_testnet" | "internal_trading">]>;
|
|
68
|
-
readonly fulfillmentState: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "
|
|
68
|
+
readonly fulfillmentState: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "failed" | "awaiting_destination" | "ready_for_payout" | "paid" | "canceled">]>;
|
|
69
69
|
readonly publishedAt: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
|
|
70
70
|
readonly seconds: v.BigintSchema<undefined>;
|
|
71
71
|
readonly nanos: v.OptionalSchema<v.NumberSchema<undefined>, 0>;
|
|
@@ -295,8 +295,8 @@ declare const SubaccountActivityEventSchema: v.ObjectSchema<{
|
|
|
295
295
|
seconds: bigint;
|
|
296
296
|
nanos: number;
|
|
297
297
|
} | undefined, number | undefined>]>;
|
|
298
|
-
readonly entityKind: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "subaccount" | "api_key" | "account" | "
|
|
299
|
-
readonly eventAction: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "disabled" | "
|
|
298
|
+
readonly entityKind: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "subaccount" | "api_key" | "account" | "destination" | "session" | "policy" | "member" | "invite" | "security">]>;
|
|
299
|
+
readonly eventAction: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "disabled" | "revoked" | "removed" | "failed" | "created" | "enabled" | "updated" | "deleted" | "role_set" | "received" | "replied" | "blocked" | "hold_placed" | "hold_released">]>;
|
|
300
300
|
readonly source: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "web" | "mobile" | "api">]>;
|
|
301
301
|
readonly ip: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
302
302
|
readonly userAgent: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
@@ -168,7 +168,7 @@ declare const GetUserTradesInputSchema: v.SchemaWithPipe<readonly [v.UnionSchema
|
|
|
168
168
|
readonly orderId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
169
169
|
readonly lineageId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>, v.CheckAction<bigint, `${string} must be greater than zero`>]>;
|
|
170
170
|
readonly throughGeneration: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>, undefined>;
|
|
171
|
-
}, undefined>], undefined>], ({ input }: v.UnionIssue<v.NumberIssue | v.BooleanIssue | v.IntegerIssue<number> | v.MinValueIssue<number, 1> | v.MaxValueIssue<number, 4294967295> | v.StringIssue | v.
|
|
171
|
+
}, undefined>], undefined>], ({ input }: v.UnionIssue<v.NumberIssue | v.BooleanIssue | v.IntegerIssue<number> | v.MinValueIssue<number, 1> | v.MaxValueIssue<number, 4294967295> | v.StringIssue | v.MinLengthIssue<string, 1> | v.StrictObjectIssue | v.PicklistIssue | v.UnionIssue<v.StringIssue | v.MinLengthIssue<string, 1> | v.StrictObjectIssue | v.PicklistIssue> | v.CheckIssue<bigint> | v.NeverIssue | v.MaxValueIssue<number, 1000> | v.UnionIssue<v.NumberIssue | v.BooleanIssue | v.IntegerIssue<number> | v.MinValueIssue<number, 1> | v.MaxValueIssue<number, 4294967295> | v.StringIssue | v.MinLengthIssue<string, 1> | v.StrictObjectIssue | v.PicklistIssue | v.UnionIssue<v.StringIssue | v.MinLengthIssue<string, 1> | v.StrictObjectIssue | v.PicklistIssue> | v.CheckIssue<bigint> | v.NeverIssue | v.MaxValueIssue<number, 1000>> | v.CheckIssue<number> | v.UnionIssue<v.NumberIssue | v.BooleanIssue | v.IntegerIssue<number> | v.MinValueIssue<number, 1> | v.MaxValueIssue<number, 4294967295> | v.StringIssue | v.MinLengthIssue<string, 1> | v.StrictObjectIssue | v.PicklistIssue | v.UnionIssue<v.StringIssue | v.MinLengthIssue<string, 1> | v.StrictObjectIssue | v.PicklistIssue> | v.CheckIssue<bigint> | v.NeverIssue | v.MaxValueIssue<number, 1000> | v.CheckIssue<number>>>) => "symbolId is required when afterMatchId is set" | "Provide at most one of orderId or lineageId" | "throughGeneration requires lineageId">, v.TransformAction<{
|
|
172
172
|
symbolId?: number | undefined;
|
|
173
173
|
afterMatchId?: undefined;
|
|
174
174
|
side?: Side.BUY | Side.SELL | undefined;
|
|
@@ -85,7 +85,7 @@ declare const LedgerTransferSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
85
85
|
amount: string;
|
|
86
86
|
balanceAfter: string | undefined;
|
|
87
87
|
type: "unspecified" | "internal_transfer" | "deposit" | "withdraw" | "maker_fee" | "taker_fee" | "trade_base" | "trade_quote" | "rebate" | "funding_to_trading" | "trading_to_funding" | "trading_withdraw_reserve" | "funding_user_transfer" | "trading_withdraw_request_fee";
|
|
88
|
-
accountCode: "unspecified" | "
|
|
88
|
+
accountCode: "unspecified" | "funding" | "trading";
|
|
89
89
|
timestamp: number;
|
|
90
90
|
isDebit: boolean;
|
|
91
91
|
linkId: string | undefined;
|
|
@@ -1108,7 +1108,7 @@ type CreateTriggerInput = v.InferInput<ReturnType<typeof createCreateTriggerInpu
|
|
|
1108
1108
|
declare const ListTriggersInputSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
1109
1109
|
readonly parentOrderId: v.SchemaWithPipe<readonly [v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, undefined>, v.TransformAction<string | undefined, bigint | undefined>]>;
|
|
1110
1110
|
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", "cancelled", "failed", "paused"], undefined>, undefined>, undefined>, v.TransformAction<("failed" | "cancelled" | "
|
|
1111
|
+
readonly status: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ArraySchema<v.PicklistSchema<readonly ["created", "armed", "running", "completed", "cancelled", "failed", "paused"], undefined>, undefined>, undefined>, v.TransformAction<("failed" | "cancelled" | "completed" | "created" | "armed" | "running" | "paused")[] | undefined, (TriggerStatus.STATUS_CREATED | TriggerStatus.STATUS_ARMED | TriggerStatus.STATUS_RUNNING | TriggerStatus.STATUS_COMPLETED | TriggerStatus.STATUS_CANCELED | TriggerStatus.STATUS_FAILED | TriggerStatus.STATUS_PAUSED)[]>]>;
|
|
1112
1112
|
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
1113
|
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
1114
|
readonly pageToken: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, "">;
|
|
@@ -1329,7 +1329,7 @@ declare const ListTriggerEventsInputSchema: v.SchemaWithPipe<readonly [v.StrictO
|
|
|
1329
1329
|
readonly triggerId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>;
|
|
1330
1330
|
}, undefined>, v.TransformAction<{
|
|
1331
1331
|
limit?: number | undefined;
|
|
1332
|
-
eventType?: "failed" | "canceled" | "
|
|
1332
|
+
eventType?: "failed" | "canceled" | "armed" | "updated" | "fired" | "activated" | undefined;
|
|
1333
1333
|
pageToken: string;
|
|
1334
1334
|
account?: "active" | "main" | {
|
|
1335
1335
|
subaccountId: string;
|
|
@@ -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" | "cancelled" | "
|
|
32
|
+
readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "failed" | "cancelled" | "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" | "cancelled" | "
|
|
36
|
+
status: "unspecified" | "failed" | "cancelled" | "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" | "cancelled" | "
|
|
42
|
+
status: "unspecified" | "failed" | "cancelled" | "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" | "cancelled" | "
|
|
47
|
+
readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "failed" | "cancelled" | "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" | "cancelled" | "
|
|
51
|
+
status: "unspecified" | "failed" | "cancelled" | "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" | "cancelled" | "
|
|
57
|
+
status: "unspecified" | "failed" | "cancelled" | "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" | "cancelled" | "
|
|
62
|
+
readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "failed" | "cancelled" | "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" | "cancelled" | "
|
|
66
|
+
status: "unspecified" | "failed" | "cancelled" | "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" | "cancelled" | "
|
|
72
|
+
status: "unspecified" | "failed" | "cancelled" | "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" | "cancelled" | "
|
|
77
|
+
readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "failed" | "cancelled" | "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" | "cancelled" | "
|
|
81
|
+
status: "unspecified" | "failed" | "cancelled" | "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" | "cancelled" | "
|
|
87
|
+
status: "unspecified" | "failed" | "cancelled" | "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" | "cancelled" | "
|
|
616
|
+
status: "unspecified" | "failed" | "cancelled" | "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" | "cancelled" | "
|
|
795
|
+
status: "unspecified" | "failed" | "cancelled" | "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" | "cancelled" | "
|
|
974
|
+
status: "unspecified" | "failed" | "cancelled" | "completed" | "created" | "armed" | "running" | "paused";
|
|
975
975
|
parentOrderId: string | undefined;
|
|
976
976
|
qty: string;
|
|
977
977
|
feeAsset: "unspecified" | "quote" | "base";
|
|
@@ -1192,7 +1192,7 @@ declare function createTriggerEventSchema(scales: SdkScales): v.SchemaWithPipe<r
|
|
|
1192
1192
|
subaccountId: string;
|
|
1193
1193
|
symbolId: number;
|
|
1194
1194
|
triggerType: "unspecified" | "twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop";
|
|
1195
|
-
eventType: "unspecified" | "failed" | "canceled" | "
|
|
1195
|
+
eventType: "unspecified" | "failed" | "canceled" | "armed" | "updated" | "fired" | "activated";
|
|
1196
1196
|
ts: number;
|
|
1197
1197
|
tsNs: string;
|
|
1198
1198
|
childSeq: number;
|
|
@@ -1205,7 +1205,7 @@ declare function createTriggerEventSchema(scales: SdkScales): v.SchemaWithPipe<r
|
|
|
1205
1205
|
subaccountId: string;
|
|
1206
1206
|
symbolId: number;
|
|
1207
1207
|
triggerType: "unspecified" | "twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop";
|
|
1208
|
-
eventType: "unspecified" | "failed" | "canceled" | "
|
|
1208
|
+
eventType: "unspecified" | "failed" | "canceled" | "armed" | "updated" | "fired" | "activated";
|
|
1209
1209
|
ts: number;
|
|
1210
1210
|
tsNs: string;
|
|
1211
1211
|
childSeq: number;
|
|
@@ -1218,7 +1218,7 @@ declare function createTriggerEventSchema(scales: SdkScales): v.SchemaWithPipe<r
|
|
|
1218
1218
|
subaccountId: string;
|
|
1219
1219
|
symbolId: number;
|
|
1220
1220
|
triggerType: "unspecified" | "twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop";
|
|
1221
|
-
eventType: "unspecified" | "failed" | "canceled" | "
|
|
1221
|
+
eventType: "unspecified" | "failed" | "canceled" | "armed" | "updated" | "fired" | "activated";
|
|
1222
1222
|
ts: number;
|
|
1223
1223
|
tsNs: string;
|
|
1224
1224
|
childSeq: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polyester/sdk",
|
|
3
|
-
"version": "0.32.
|
|
3
|
+
"version": "0.32.1-devnet-20261102140938",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "TypeScript SDK providing access to APIs on Polyester Exchange.",
|
|
6
6
|
"homepage": "https://github.com/Fabric-Labs/polyester-sdk-typescript#readme",
|