@pear-protocol/types 1.14.1 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/auth/api-keys.d.ts +0 -1
  2. package/dist/auth/api-keys.js +1 -1
  3. package/dist/auth/entities.d.ts +0 -1
  4. package/dist/auth/entities.js +1 -1
  5. package/dist/auth/response.d.ts +0 -2
  6. package/dist/bundle.d.ts +1 -1
  7. package/dist/bundle.js +1 -1
  8. package/dist/common/refinement.js +1 -1
  9. package/dist/common/schema.d.ts +0 -1
  10. package/dist/common/schema.js +1 -2
  11. package/dist/execution/entities.d.ts +0 -13
  12. package/dist/execution/responses.d.ts +0 -8
  13. package/dist/fee/entities.d.ts +41 -0
  14. package/dist/fee/entities.js +19 -0
  15. package/dist/{admin/client-ids → fee}/index.d.ts +0 -1
  16. package/dist/{admin/client-ids → fee}/index.js +0 -1
  17. package/dist/fee/queries.d.ts +17 -0
  18. package/dist/fee/queries.js +12 -0
  19. package/dist/fee/responses.d.ts +35 -0
  20. package/dist/fee/responses.js +29 -0
  21. package/dist/instrument/entities.d.ts +10 -0
  22. package/dist/instrument/entities.js +22 -1
  23. package/dist/instrument/queries.d.ts +2 -2
  24. package/dist/instrument/responses.d.ts +12 -0
  25. package/dist/instrument/responses.js +8 -2
  26. package/dist/ladder/entities.d.ts +3 -0
  27. package/dist/ladder/payloads.js +1 -2
  28. package/dist/ladder/responses.d.ts +9 -0
  29. package/dist/market/queries.d.ts +2 -2
  30. package/dist/notification/queries.d.ts +1 -1
  31. package/dist/order/entities.d.ts +0 -2
  32. package/dist/order/entities.js +1 -5
  33. package/dist/portfolio/entities.d.ts +4 -0
  34. package/dist/portfolio/entities.js +10 -1
  35. package/dist/portfolio/responses.d.ts +4 -0
  36. package/dist/schedule/entities.d.ts +27 -37
  37. package/dist/schedule/entities.js +24 -28
  38. package/dist/schedule/index.d.ts +1 -0
  39. package/dist/schedule/index.js +1 -0
  40. package/dist/schedule/payloads.d.ts +28 -28
  41. package/dist/schedule/payloads.js +23 -33
  42. package/dist/schedule/randomization.d.ts +10 -0
  43. package/dist/schedule/randomization.js +15 -0
  44. package/dist/schedule/responses.d.ts +24 -20
  45. package/dist/statistics/entities.d.ts +20 -0
  46. package/dist/statistics/entities.js +23 -1
  47. package/dist/statistics/queries.d.ts +28 -0
  48. package/dist/statistics/queries.js +26 -1
  49. package/dist/statistics/responses.d.ts +22 -0
  50. package/dist/statistics/responses.js +5 -2
  51. package/dist/trade/responses.d.ts +0 -20
  52. package/dist/trigger/entities/index.d.ts +10 -0
  53. package/dist/trigger/entities/index.js +4 -0
  54. package/dist/trigger/responses.d.ts +6 -0
  55. package/dist/users/entities.d.ts +0 -1
  56. package/dist/users/entities.js +1 -1
  57. package/dist/users/response.d.ts +0 -1
  58. package/package.json +1 -1
  59. package/dist/admin/client-ids/entities.d.ts +0 -11
  60. package/dist/admin/client-ids/entities.js +0 -13
  61. package/dist/admin/client-ids/payloads.d.ts +0 -14
  62. package/dist/admin/client-ids/payloads.js +0 -13
  63. package/dist/admin/client-ids/queries.d.ts +0 -10
  64. package/dist/admin/client-ids/queries.js +0 -7
  65. package/dist/admin/client-ids/responses.d.ts +0 -11
  66. package/dist/admin/client-ids/responses.js +0 -6
@@ -8,10 +8,10 @@ export declare const MarketsQueryParams: z.ZodObject<{
8
8
  lighter: "lighter";
9
9
  }>;
10
10
  scope: z.ZodDefault<z.ZodEnum<{
11
- all: "all";
12
11
  tradable: "tradable";
13
12
  reduce_only: "reduce_only";
14
13
  not_tradable: "not_tradable";
14
+ all: "all";
15
15
  }>>;
16
16
  }, z.core.$strip>;
17
17
  export type MarketsQueryParamsInput = z.input<typeof MarketsQueryParams>;
@@ -25,10 +25,10 @@ export declare const MarketBasketsQueryParams: z.ZodObject<{
25
25
  lighter: "lighter";
26
26
  }>;
27
27
  scope: z.ZodDefault<z.ZodEnum<{
28
- all: "all";
29
28
  tradable: "tradable";
30
29
  reduce_only: "reduce_only";
31
30
  not_tradable: "not_tradable";
31
+ all: "all";
32
32
  }>>;
33
33
  search: z.ZodOptional<z.ZodString>;
34
34
  limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
@@ -4,8 +4,8 @@ export declare const NotificationListParams: z.ZodObject<{
4
4
  startDate: z.ZodOptional<z.ZodCoercedDate<Date>>;
5
5
  endDate: z.ZodOptional<z.ZodCoercedDate<Date>>;
6
6
  scope: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
7
- all: "all";
8
7
  read: "read";
8
+ all: "all";
9
9
  unread: "unread";
10
10
  }>>>;
11
11
  }, z.core.$strip>;
@@ -33,7 +33,6 @@ export declare const MarketOrder: z.ZodObject<{
33
33
  SELL: "SELL";
34
34
  }>;
35
35
  reduceOnly: z.ZodBoolean;
36
- leverage: z.ZodInt;
37
36
  quantity: z.ZodString;
38
37
  price: z.ZodString;
39
38
  filledQuantity: z.ZodString;
@@ -65,7 +64,6 @@ export declare const Order: z.ZodDiscriminatedUnion<[z.ZodObject<{
65
64
  SELL: "SELL";
66
65
  }>;
67
66
  reduceOnly: z.ZodBoolean;
68
- leverage: z.ZodInt;
69
67
  quantity: z.ZodString;
70
68
  price: z.ZodString;
71
69
  filledQuantity: z.ZodString;
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { UnsignedDecimalString, Leverage, Side } from '../common/schema';
2
+ import { UnsignedDecimalString, Side } from '../common/schema';
3
3
  import { Connector } from '../connector';
4
4
  import { InstrumentId } from '../instrument';
5
5
 
@@ -47,10 +47,6 @@ const MarketOrder = BaseOrder.extend({
47
47
  * Reduce only flag
48
48
  */
49
49
  reduceOnly: z.boolean(),
50
- /**
51
- * Leverage
52
- */
53
- leverage: Leverage,
54
50
  /**
55
51
  * Contract quantity to trade
56
52
  */
@@ -178,6 +178,9 @@ export declare const PortfolioSeriesPoint: z.ZodObject<{
178
178
  wins: z.ZodNumber;
179
179
  losses: z.ZodNumber;
180
180
  dayPnl: z.ZodNumber;
181
+ dayVolume: z.ZodNumber;
182
+ dayFunding: z.ZodNumber;
183
+ dayNetPnl: z.ZodNumber;
181
184
  hitRate: z.ZodNullable<z.ZodNumber>;
182
185
  winLossRatio: z.ZodNullable<z.ZodNumber>;
183
186
  rollingHitRate: z.ZodNullable<z.ZodNumber>;
@@ -195,5 +198,6 @@ export declare const PortfolioAnalyticsConfig: z.ZodObject<{
195
198
  rollingWindowDays: z.ZodNumber;
196
199
  startDate: z.ZodString;
197
200
  endDate: z.ZodString;
201
+ fundingSynced: z.ZodBoolean;
198
202
  }, z.core.$strip>;
199
203
  export type PortfolioAnalyticsConfig = z.output<typeof PortfolioAnalyticsConfig>;
@@ -79,6 +79,12 @@ const PortfolioSeriesPoint = z.object({
79
79
  wins: z.number(),
80
80
  losses: z.number(),
81
81
  dayPnl: z.number(),
82
+ // Fill notional traded that UTC day; honours the query's `source` filter.
83
+ dayVolume: z.number(),
84
+ // Account-level funding accrued that UTC day (signed; negative when the trader paid).
85
+ dayFunding: z.number(),
86
+ // dayPnl plus dayFunding — the figure that reconciles with the trader's exchange statement.
87
+ dayNetPnl: z.number(),
82
88
  hitRate: NullableNumber,
83
89
  winLossRatio: NullableNumber,
84
90
  rollingHitRate: NullableNumber,
@@ -94,7 +100,10 @@ const PortfolioSeriesPoint = z.object({
94
100
  const PortfolioAnalyticsConfig = z.object({
95
101
  rollingWindowDays: z.number(),
96
102
  startDate: z.string(),
97
- endDate: z.string()
103
+ endDate: z.string(),
104
+ // Whether funding history has ever reached the backend for this account. When false, every
105
+ // `dayFunding` is unknown rather than zero. Carries no claim about how recent the sync was.
106
+ fundingSynced: z.boolean()
98
107
  });
99
108
 
100
109
  export { NullableNumber, PortfolioAnalyticsConfig, PortfolioAssetAnalytics, PortfolioIntervalBucket, PortfolioIntervals, PortfolioMetricVariant, PortfolioMetrics, PortfolioOverall, PortfolioPairBreakdown, PortfolioSeriesPoint };
@@ -71,6 +71,7 @@ export declare const PortfolioAnalyticsResponse: z.ZodObject<{
71
71
  rollingWindowDays: z.ZodNumber;
72
72
  startDate: z.ZodString;
73
73
  endDate: z.ZodString;
74
+ fundingSynced: z.ZodBoolean;
74
75
  }, z.core.$strip>;
75
76
  portfolio: z.ZodObject<{
76
77
  realizedOnly: z.ZodObject<{
@@ -156,6 +157,9 @@ export declare const PortfolioAnalyticsResponse: z.ZodObject<{
156
157
  wins: z.ZodNumber;
157
158
  losses: z.ZodNumber;
158
159
  dayPnl: z.ZodNumber;
160
+ dayVolume: z.ZodNumber;
161
+ dayFunding: z.ZodNumber;
162
+ dayNetPnl: z.ZodNumber;
159
163
  hitRate: z.ZodNullable<z.ZodNumber>;
160
164
  winLossRatio: z.ZodNullable<z.ZodNumber>;
161
165
  rollingHitRate: z.ZodNullable<z.ZodNumber>;
@@ -20,11 +20,6 @@ export declare const ScheduleExecutionType: z.ZodEnum<{
20
20
  MARKET: "MARKET";
21
21
  }>;
22
22
  export type ScheduleExecutionType = z.infer<typeof ScheduleExecutionType>;
23
- export declare const ScheduleSliceMode: z.ZodEnum<{
24
- QUANTITY: "QUANTITY";
25
- USD: "USD";
26
- }>;
27
- export type ScheduleSliceMode = z.infer<typeof ScheduleSliceMode>;
28
23
  export declare const ScheduleCancelledReason: z.ZodEnum<{
29
24
  USER: "USER";
30
25
  POSITION_CLOSED: "POSITION_CLOSED";
@@ -33,21 +28,13 @@ export declare const ScheduleCancelledReason: z.ZodEnum<{
33
28
  POSITION_REVERSED: "POSITION_REVERSED";
34
29
  }>;
35
30
  export type ScheduleCancelledReason = z.infer<typeof ScheduleCancelledReason>;
36
- declare const TWAPSliceOpenLeg: z.ZodObject<{
31
+ declare const TWAPOpenLeg: z.ZodObject<{
37
32
  symbol: z.ZodString;
38
33
  side: z.ZodEnum<{
39
34
  BUY: "BUY";
40
35
  SELL: "SELL";
41
36
  }>;
42
- mode: z.ZodEnum<{
43
- QUANTITY: "QUANTITY";
44
- USD: "USD";
45
- }>;
46
- stepAmount: z.ZodString;
47
- }, z.core.$strip>;
48
- declare const TWAPSliceCloseLeg: z.ZodObject<{
49
- symbol: z.ZodString;
50
- stepAmount: z.ZodString;
37
+ weight: z.ZodNumber;
51
38
  }, z.core.$strip>;
52
39
  declare const BaseSchedule: z.ZodObject<{
53
40
  id: z.ZodUUID;
@@ -199,17 +186,18 @@ export declare const TWAPOpen: z.ZodObject<{
199
186
  strategy: z.ZodLiteral<"TWAP">;
200
187
  intent: z.ZodLiteral<"OPEN">;
201
188
  sliceIntervalSec: z.ZodNumber;
202
- sliceLegs: z.ZodArray<z.ZodObject<{
189
+ sliceCount: z.ZodNumber;
190
+ randomization: z.ZodObject<{
191
+ timingJitterBps: z.ZodInt;
192
+ sizeJitterBps: z.ZodInt;
193
+ }, z.core.$strip>;
194
+ legs: z.ZodArray<z.ZodObject<{
203
195
  symbol: z.ZodString;
204
196
  side: z.ZodEnum<{
205
197
  BUY: "BUY";
206
198
  SELL: "SELL";
207
199
  }>;
208
- mode: z.ZodEnum<{
209
- QUANTITY: "QUANTITY";
210
- USD: "USD";
211
- }>;
212
- stepAmount: z.ZodString;
200
+ weight: z.ZodNumber;
213
201
  }, z.core.$strip>>;
214
202
  targetNotional: z.ZodString;
215
203
  remainingNotional: z.ZodString;
@@ -286,11 +274,12 @@ export declare const TWAPClose: z.ZodObject<{
286
274
  strategy: z.ZodLiteral<"TWAP">;
287
275
  intent: z.ZodLiteral<"CLOSE">;
288
276
  sliceIntervalSec: z.ZodNumber;
277
+ sliceCount: z.ZodNumber;
278
+ randomization: z.ZodObject<{
279
+ timingJitterBps: z.ZodInt;
280
+ sizeJitterBps: z.ZodInt;
281
+ }, z.core.$strip>;
289
282
  positionId: z.ZodUUID;
290
- sliceLegs: z.ZodArray<z.ZodObject<{
291
- symbol: z.ZodString;
292
- stepAmount: z.ZodString;
293
- }, z.core.$strip>>;
294
283
  initialExposure: z.ZodRecord<z.ZodString, z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>>;
295
284
  }, z.core.$strip>;
296
285
  export declare const Schedule: z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -365,17 +354,18 @@ export declare const Schedule: z.ZodDiscriminatedUnion<[z.ZodObject<{
365
354
  strategy: z.ZodLiteral<"TWAP">;
366
355
  intent: z.ZodLiteral<"OPEN">;
367
356
  sliceIntervalSec: z.ZodNumber;
368
- sliceLegs: z.ZodArray<z.ZodObject<{
357
+ sliceCount: z.ZodNumber;
358
+ randomization: z.ZodObject<{
359
+ timingJitterBps: z.ZodInt;
360
+ sizeJitterBps: z.ZodInt;
361
+ }, z.core.$strip>;
362
+ legs: z.ZodArray<z.ZodObject<{
369
363
  symbol: z.ZodString;
370
364
  side: z.ZodEnum<{
371
365
  BUY: "BUY";
372
366
  SELL: "SELL";
373
367
  }>;
374
- mode: z.ZodEnum<{
375
- QUANTITY: "QUANTITY";
376
- USD: "USD";
377
- }>;
378
- stepAmount: z.ZodString;
368
+ weight: z.ZodNumber;
379
369
  }, z.core.$strip>>;
380
370
  targetNotional: z.ZodString;
381
371
  remainingNotional: z.ZodString;
@@ -451,15 +441,15 @@ export declare const Schedule: z.ZodDiscriminatedUnion<[z.ZodObject<{
451
441
  strategy: z.ZodLiteral<"TWAP">;
452
442
  intent: z.ZodLiteral<"CLOSE">;
453
443
  sliceIntervalSec: z.ZodNumber;
444
+ sliceCount: z.ZodNumber;
445
+ randomization: z.ZodObject<{
446
+ timingJitterBps: z.ZodInt;
447
+ sizeJitterBps: z.ZodInt;
448
+ }, z.core.$strip>;
454
449
  positionId: z.ZodUUID;
455
- sliceLegs: z.ZodArray<z.ZodObject<{
456
- symbol: z.ZodString;
457
- stepAmount: z.ZodString;
458
- }, z.core.$strip>>;
459
450
  initialExposure: z.ZodRecord<z.ZodString, z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>>;
460
451
  }, z.core.$strip>], "intent">;
461
- export type TWAPSliceOpenLeg = z.output<typeof TWAPSliceOpenLeg>;
462
- export type TWAPSliceCloseLeg = z.output<typeof TWAPSliceCloseLeg>;
452
+ export type TWAPOpenLeg = z.output<typeof TWAPOpenLeg>;
463
453
  export type BaseSchedule = z.output<typeof BaseSchedule>;
464
454
  export type TWAPOpen = z.output<typeof TWAPOpen>;
465
455
  export type TWAPClose = z.output<typeof TWAPClose>;
@@ -1,14 +1,14 @@
1
1
  import { z } from 'zod';
2
- import { UnsignedDecimalString, Side, SignedDecimalString } from '../common/schema';
2
+ import { AssetWeight, Side, UnsignedDecimalString, SignedDecimalString } from '../common/schema';
3
3
  import { Connector } from '../connector';
4
4
  import { Fill } from '../fill/entities';
5
5
  import { InstrumentId } from '../instrument';
6
+ import { TWAPRandomization } from './randomization';
6
7
 
7
8
  const ScheduleStrategy = z.enum(["TWAP", "VWAP"]);
8
9
  const ScheduleStatus = z.enum(["ACTIVE", "COMPLETED", "FAILED", "CANCELLED"]);
9
10
  const ScheduleIntent = z.enum(["OPEN", "CLOSE"]);
10
11
  const ScheduleExecutionType = z.enum(["MARKET"]);
11
- const ScheduleSliceMode = z.enum(["QUANTITY", "USD"]);
12
12
  const ScheduleCancelledReason = z.enum([
13
13
  "POSITION_CLOSED",
14
14
  "USER",
@@ -16,7 +16,7 @@ const ScheduleCancelledReason = z.enum([
16
16
  "POSITION_NETTED",
17
17
  "POSITION_REVERSED"
18
18
  ]);
19
- const TWAPSliceOpenLeg = z.object({
19
+ const TWAPOpenLeg = z.object({
20
20
  /**
21
21
  * Instrument ID
22
22
  */
@@ -26,25 +26,9 @@ const TWAPSliceOpenLeg = z.object({
26
26
  */
27
27
  side: Side,
28
28
  /**
29
- * Mode to interpret the step amount
30
- * @example QUANTITY: 0.001 means 0.001 BTC units
31
- * @example USD: 100 means $100 USD
29
+ * Share of the parent target notional allocated to this leg
32
30
  */
33
- mode: ScheduleSliceMode,
34
- /**
35
- * Step amount
36
- */
37
- stepAmount: UnsignedDecimalString
38
- });
39
- const TWAPSliceCloseLeg = z.object({
40
- /**
41
- * Instrument ID
42
- */
43
- symbol: InstrumentId,
44
- /**
45
- * Step amount
46
- */
47
- stepAmount: UnsignedDecimalString
31
+ weight: AssetWeight
48
32
  });
49
33
  const BaseSchedule = z.object({
50
34
  /**
@@ -122,9 +106,17 @@ const TWAPOpen = BaseSchedule.extend({
122
106
  */
123
107
  sliceIntervalSec: z.number(),
124
108
  /**
125
- * Slice legs
109
+ * Number of slices planned inside the execution window
126
110
  */
127
- sliceLegs: z.array(TWAPSliceOpenLeg),
111
+ sliceCount: z.number().int().positive(),
112
+ /**
113
+ * Bounded timing and basket-size randomization
114
+ */
115
+ randomization: TWAPRandomization,
116
+ /**
117
+ * Parent-order leg allocation
118
+ */
119
+ legs: z.array(TWAPOpenLeg),
128
120
  /**
129
121
  * Target notional
130
122
  */
@@ -148,13 +140,17 @@ const TWAPClose = BaseSchedule.extend({
148
140
  */
149
141
  sliceIntervalSec: z.number(),
150
142
  /**
151
- * Position UUID
143
+ * Number of slices planned inside the execution window
152
144
  */
153
- positionId: z.uuid(),
145
+ sliceCount: z.number().int().positive(),
154
146
  /**
155
- * Slice legs
147
+ * Bounded timing and basket-size randomization
156
148
  */
157
- sliceLegs: z.array(TWAPSliceCloseLeg),
149
+ randomization: TWAPRandomization,
150
+ /**
151
+ * Position UUID
152
+ */
153
+ positionId: z.uuid(),
158
154
  /**
159
155
  * Initial exposure
160
156
  */
@@ -162,4 +158,4 @@ const TWAPClose = BaseSchedule.extend({
162
158
  });
163
159
  const Schedule = z.discriminatedUnion("intent", [TWAPOpen, TWAPClose]);
164
160
 
165
- export { Schedule, ScheduleCancelledReason, ScheduleExecutionType, ScheduleIntent, ScheduleSliceMode, ScheduleStatus, ScheduleStrategy, TWAPClose, TWAPOpen };
161
+ export { Schedule, ScheduleCancelledReason, ScheduleExecutionType, ScheduleIntent, ScheduleStatus, ScheduleStrategy, TWAPClose, TWAPOpen };
@@ -1,4 +1,5 @@
1
1
  export * from './entities';
2
2
  export * from './payloads';
3
3
  export * from './queries';
4
+ export * from './randomization';
4
5
  export * from './responses';
@@ -1,4 +1,5 @@
1
1
  export * from './entities';
2
2
  export * from './payloads';
3
3
  export * from './queries';
4
+ export * from './randomization';
4
5
  export * from './responses';
@@ -1,71 +1,71 @@
1
1
  import { z } from 'zod';
2
2
  export declare const CreateTWAPOpen: z.ZodObject<{
3
- startAt: z.ZodPipe<z.ZodOptional<z.ZodCoercedDate<unknown>>, z.ZodTransform<Date, Date | undefined>>;
4
- endAt: z.ZodPipe<z.ZodOptional<z.ZodCoercedDate<unknown>>, z.ZodTransform<Date, Date | undefined>>;
3
+ startAt: z.ZodCoercedDate<unknown>;
4
+ endAt: z.ZodCoercedDate<unknown>;
5
+ randomization: z.ZodDefault<z.ZodOptional<z.ZodObject<{
6
+ timingJitterBps: z.ZodInt;
7
+ sizeJitterBps: z.ZodInt;
8
+ }, z.core.$strip>>>;
5
9
  strategy: z.ZodLiteral<"TWAP">;
6
10
  intent: z.ZodLiteral<"OPEN">;
7
11
  executionType: z.ZodLiteral<"MARKET">;
8
- sliceLegs: z.ZodArray<z.ZodObject<{
12
+ legs: z.ZodArray<z.ZodObject<{
9
13
  symbol: z.ZodString;
10
14
  side: z.ZodEnum<{
11
15
  BUY: "BUY";
12
16
  SELL: "SELL";
13
17
  }>;
14
- mode: z.ZodEnum<{
15
- QUANTITY: "QUANTITY";
16
- USD: "USD";
17
- }>;
18
- stepAmount: z.ZodString;
18
+ weight: z.ZodNumber;
19
19
  }, z.core.$strip>>;
20
20
  targetNotional: z.ZodString;
21
21
  sliceIntervalSec: z.ZodInt;
22
22
  clientId: z.ZodOptional<z.ZodString>;
23
23
  }, z.core.$strip>;
24
24
  export declare const CreateTWAPClose: z.ZodObject<{
25
- startAt: z.ZodPipe<z.ZodOptional<z.ZodCoercedDate<unknown>>, z.ZodTransform<Date, Date | undefined>>;
26
- endAt: z.ZodPipe<z.ZodOptional<z.ZodCoercedDate<unknown>>, z.ZodTransform<Date, Date | undefined>>;
25
+ startAt: z.ZodCoercedDate<unknown>;
26
+ endAt: z.ZodCoercedDate<unknown>;
27
+ randomization: z.ZodDefault<z.ZodOptional<z.ZodObject<{
28
+ timingJitterBps: z.ZodInt;
29
+ sizeJitterBps: z.ZodInt;
30
+ }, z.core.$strip>>>;
27
31
  strategy: z.ZodLiteral<"TWAP">;
28
32
  intent: z.ZodLiteral<"CLOSE">;
29
33
  executionType: z.ZodLiteral<"MARKET">;
30
- sliceLegs: z.ZodArray<z.ZodObject<{
31
- symbol: z.ZodString;
32
- stepAmount: z.ZodString;
33
- }, z.core.$strip>>;
34
34
  positionId: z.ZodUUID;
35
35
  sliceIntervalSec: z.ZodInt;
36
36
  clientId: z.ZodOptional<z.ZodString>;
37
37
  }, z.core.$strip>;
38
38
  export declare const CreateSchedule: z.ZodDiscriminatedUnion<[z.ZodObject<{
39
- startAt: z.ZodPipe<z.ZodOptional<z.ZodCoercedDate<unknown>>, z.ZodTransform<Date, Date | undefined>>;
40
- endAt: z.ZodPipe<z.ZodOptional<z.ZodCoercedDate<unknown>>, z.ZodTransform<Date, Date | undefined>>;
39
+ startAt: z.ZodCoercedDate<unknown>;
40
+ endAt: z.ZodCoercedDate<unknown>;
41
+ randomization: z.ZodDefault<z.ZodOptional<z.ZodObject<{
42
+ timingJitterBps: z.ZodInt;
43
+ sizeJitterBps: z.ZodInt;
44
+ }, z.core.$strip>>>;
41
45
  strategy: z.ZodLiteral<"TWAP">;
42
46
  intent: z.ZodLiteral<"OPEN">;
43
47
  executionType: z.ZodLiteral<"MARKET">;
44
- sliceLegs: z.ZodArray<z.ZodObject<{
48
+ legs: z.ZodArray<z.ZodObject<{
45
49
  symbol: z.ZodString;
46
50
  side: z.ZodEnum<{
47
51
  BUY: "BUY";
48
52
  SELL: "SELL";
49
53
  }>;
50
- mode: z.ZodEnum<{
51
- QUANTITY: "QUANTITY";
52
- USD: "USD";
53
- }>;
54
- stepAmount: z.ZodString;
54
+ weight: z.ZodNumber;
55
55
  }, z.core.$strip>>;
56
56
  targetNotional: z.ZodString;
57
57
  sliceIntervalSec: z.ZodInt;
58
58
  clientId: z.ZodOptional<z.ZodString>;
59
59
  }, z.core.$strip>, z.ZodObject<{
60
- startAt: z.ZodPipe<z.ZodOptional<z.ZodCoercedDate<unknown>>, z.ZodTransform<Date, Date | undefined>>;
61
- endAt: z.ZodPipe<z.ZodOptional<z.ZodCoercedDate<unknown>>, z.ZodTransform<Date, Date | undefined>>;
60
+ startAt: z.ZodCoercedDate<unknown>;
61
+ endAt: z.ZodCoercedDate<unknown>;
62
+ randomization: z.ZodDefault<z.ZodOptional<z.ZodObject<{
63
+ timingJitterBps: z.ZodInt;
64
+ sizeJitterBps: z.ZodInt;
65
+ }, z.core.$strip>>>;
62
66
  strategy: z.ZodLiteral<"TWAP">;
63
67
  intent: z.ZodLiteral<"CLOSE">;
64
68
  executionType: z.ZodLiteral<"MARKET">;
65
- sliceLegs: z.ZodArray<z.ZodObject<{
66
- symbol: z.ZodString;
67
- stepAmount: z.ZodString;
68
- }, z.core.$strip>>;
69
69
  positionId: z.ZodUUID;
70
70
  sliceIntervalSec: z.ZodInt;
71
71
  clientId: z.ZodOptional<z.ZodString>;
@@ -1,14 +1,17 @@
1
1
  import { z } from 'zod';
2
2
  import { ClientIdCode } from '../common/client-id';
3
- import { UnsignedDecimalString, Side } from '../common/schema';
3
+ import { RefineMinimumOneSymbol, RefineUniqueSymbols, RefineWeightingSum } from '../common/refinement';
4
+ import { UnsignedDecimalString, AssetWeight, Side } from '../common/schema';
4
5
  import { InstrumentId } from '../instrument';
5
- import { ScheduleSliceMode } from './entities';
6
+ import { TWAPRandomization, DEFAULT_TWAP_RANDOMIZATION } from './randomization';
6
7
 
7
8
  const THIRTY_ONE_DAYS_SEC = 60 * 60 * 24 * 31;
8
- const SliceIntervalSec = z.int().min(15).max(THIRTY_ONE_DAYS_SEC);
9
- const DefaultStartAt = z.coerce.date().optional().transform((value) => value ?? /* @__PURE__ */ new Date());
10
- const DefaultEndAt = z.coerce.date().optional().transform((value) => value ?? new Date(Date.now() + THIRTY_ONE_DAYS_SEC * 1e3));
11
- const TWAPSliceOpenLeg = z.object({
9
+ const MIN_TWAP_WINDOW_SEC = 15;
10
+ const SliceIntervalSec = z.int().min(MIN_TWAP_WINDOW_SEC).max(THIRTY_ONE_DAYS_SEC);
11
+ const TargetNotional = UnsignedDecimalString.refine((value) => /[1-9]/.test(value), {
12
+ message: "Target notional must be greater than zero"
13
+ });
14
+ const TWAPOpenLeg = z.object({
12
15
  /**
13
16
  * Instrument ID
14
17
  */
@@ -18,37 +21,28 @@ const TWAPSliceOpenLeg = z.object({
18
21
  */
19
22
  side: Side,
20
23
  /**
21
- * Mode to interpret the step amount
22
- * @example QUANTITY: 0.001 means 0.001 BTC units
23
- * @example USD: 100 means $100 USD
24
- */
25
- mode: ScheduleSliceMode,
26
- /**
27
- * Step amount for each slice depending on the mode
28
- */
29
- stepAmount: UnsignedDecimalString
30
- });
31
- const TWAPSliceCloseLeg = z.object({
32
- /**
33
- * Instrument ID
34
- */
35
- symbol: InstrumentId,
36
- /**
37
- * Step amount for each slice in base units
24
+ * Share of the parent target notional allocated to this leg
38
25
  */
39
- stepAmount: UnsignedDecimalString
26
+ weight: AssetWeight
40
27
  });
28
+ const TWAPOpenLegs = z.array(TWAPOpenLeg).superRefine(RefineMinimumOneSymbol).superRefine(RefineUniqueSymbols).superRefine(RefineWeightingSum);
41
29
  const BaseSchedule = z.object({
42
30
  /**
43
31
  * Start at date
44
32
  */
45
- startAt: DefaultStartAt,
33
+ startAt: z.coerce.date(),
46
34
  /**
47
35
  * End at date
48
36
  */
49
- endAt: DefaultEndAt
37
+ endAt: z.coerce.date(),
38
+ /**
39
+ * Optional bounded timing and basket-size randomization
40
+ */
41
+ randomization: TWAPRandomization.optional().default(DEFAULT_TWAP_RANDOMIZATION)
50
42
  }).refine((data) => data.startAt && data.endAt && data.startAt < data.endAt, {
51
43
  message: "Start at date must be before end at date"
44
+ }).refine((data) => data.endAt.getTime() - data.startAt.getTime() >= MIN_TWAP_WINDOW_SEC * 1e3, {
45
+ message: `TWAP execution window must be at least ${MIN_TWAP_WINDOW_SEC} seconds`
52
46
  });
53
47
  const CreateTWAPOpen = BaseSchedule.safeExtend({
54
48
  /**
@@ -64,13 +58,13 @@ const CreateTWAPOpen = BaseSchedule.safeExtend({
64
58
  */
65
59
  executionType: z.literal("MARKET"),
66
60
  /**
67
- * Step configuration for each leg
61
+ * Parent-order allocation for each leg
68
62
  */
69
- sliceLegs: z.array(TWAPSliceOpenLeg),
63
+ legs: TWAPOpenLegs,
70
64
  /**
71
65
  * Target notional
72
66
  */
73
- targetNotional: UnsignedDecimalString,
67
+ targetNotional: TargetNotional,
74
68
  /**
75
69
  * Slice interval in seconds
76
70
  */
@@ -93,10 +87,6 @@ const CreateTWAPClose = BaseSchedule.safeExtend({
93
87
  * Execution type
94
88
  */
95
89
  executionType: z.literal("MARKET"),
96
- /**
97
- * Step configuration for each leg
98
- */
99
- sliceLegs: z.array(TWAPSliceCloseLeg),
100
90
  /**
101
91
  * Position UUID
102
92
  */
@@ -0,0 +1,10 @@
1
+ import { z } from 'zod';
2
+ export declare const DEFAULT_TWAP_RANDOMIZATION: {
3
+ readonly timingJitterBps: 0;
4
+ readonly sizeJitterBps: 0;
5
+ };
6
+ export declare const TWAPRandomization: z.ZodObject<{
7
+ timingJitterBps: z.ZodInt;
8
+ sizeJitterBps: z.ZodInt;
9
+ }, z.core.$strip>;
10
+ export type TWAPRandomization = z.output<typeof TWAPRandomization>;
@@ -0,0 +1,15 @@
1
+ import { z } from 'zod';
2
+
3
+ const MAX_JITTER_BPS = 5e3;
4
+ const DEFAULT_TWAP_RANDOMIZATION = {
5
+ timingJitterBps: 0,
6
+ sizeJitterBps: 0
7
+ };
8
+ const TWAPRandomization = z.object({
9
+ /** Maximum symmetric timing variation in basis points, capped at ±50%. */
10
+ timingJitterBps: z.int().min(0).max(MAX_JITTER_BPS),
11
+ /** Maximum symmetric basket-size variation in basis points, capped at ±50%. */
12
+ sizeJitterBps: z.int().min(0).max(MAX_JITTER_BPS)
13
+ });
14
+
15
+ export { DEFAULT_TWAP_RANDOMIZATION, TWAPRandomization };