@pear-protocol/types 1.30.1 → 1.32.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 (45) hide show
  1. package/dist/baskets/recommended/entities.d.ts +36 -0
  2. package/dist/baskets/recommended/entities.js +22 -0
  3. package/dist/baskets/recommended/index.d.ts +2 -0
  4. package/dist/baskets/recommended/index.js +2 -0
  5. package/dist/baskets/recommended/responses.d.ts +28 -0
  6. package/dist/baskets/recommended/responses.js +8 -0
  7. package/dist/{saved-baskets → baskets/saved}/entities.d.ts +3 -0
  8. package/dist/{saved-baskets → baskets/saved}/entities.js +6 -3
  9. package/dist/{saved-baskets → baskets/saved}/payloads.d.ts +4 -0
  10. package/dist/{saved-baskets → baskets/saved}/payloads.js +1 -1
  11. package/dist/{saved-baskets → baskets/saved}/responses.d.ts +6 -0
  12. package/dist/bundle.d.ts +2 -1
  13. package/dist/bundle.js +2 -1
  14. package/dist/common/refinement.d.ts +9 -0
  15. package/dist/common/refinement.js +9 -1
  16. package/dist/common/trade-legs.d.ts +2 -0
  17. package/dist/common/trade-legs.js +7 -3
  18. package/dist/execution/entities.d.ts +13 -0
  19. package/dist/execution/entities.js +2 -0
  20. package/dist/execution/responses.d.ts +8 -0
  21. package/dist/ladder/entities.d.ts +549 -0
  22. package/dist/ladder/payloads.d.ts +4 -0
  23. package/dist/ladder/responses.d.ts +2039 -392
  24. package/dist/notification/entities.d.ts +176 -3
  25. package/dist/notification/entities.js +31 -0
  26. package/dist/notification/responses.d.ts +86 -0
  27. package/dist/schedule/entities.d.ts +3 -0
  28. package/dist/schedule/entities.js +2 -0
  29. package/dist/schedule/payloads.d.ts +2 -0
  30. package/dist/schedule/payloads.js +6 -29
  31. package/dist/schedule/responses.d.ts +2 -0
  32. package/dist/schedule/twap-config.d.ts +41 -0
  33. package/dist/schedule/twap-config.js +29 -0
  34. package/dist/statistics/entities.js +23 -10
  35. package/dist/trade/payloads.d.ts +8 -0
  36. package/dist/trade/responses.d.ts +20 -0
  37. package/dist/trigger/entities/index.d.ts +1707 -54
  38. package/dist/trigger/entities/index.js +55 -2
  39. package/dist/trigger/payloads/index.d.ts +898 -91
  40. package/dist/trigger/payloads/index.js +68 -5
  41. package/dist/trigger/responses.d.ts +1151 -53
  42. package/package.json +1 -1
  43. /package/dist/{saved-baskets → baskets/saved}/index.d.ts +0 -0
  44. /package/dist/{saved-baskets → baskets/saved}/index.js +0 -0
  45. /package/dist/{saved-baskets → baskets/saved}/responses.js +0 -0
@@ -5,9 +5,10 @@ import { z } from 'zod';
5
5
  * execute; `ATTACHED_TRIGGER_DISCARDED` means requested close protection could
6
6
  * not be placed after a position opened; the `AUTO_REBALANCE_*` categories cover
7
7
  * an auto-rebalance config acting on, or stopping itself over, the position it
8
- * watches; `TRIGGER_CANCELLED_MIS_SCALED` means the remediation sweep cancelled
9
- * an unreachable stop loss. Outcome lives here in the category; display details
10
- * live in the `parameters` payload below.
8
+ * watches; the `TRIGGER_TWAP_*` categories describe a fired trigger starting,
9
+ * skipping, failing, or cancelling its TWAP; `TRIGGER_CANCELLED_MIS_SCALED`
10
+ * means the remediation sweep cancelled an unreachable stop loss. Outcome lives
11
+ * here in the category; display details live in the `parameters` payload below.
11
12
  */
12
13
  export declare const NotificationCategory: z.ZodEnum<{
13
14
  TAKE_PROFIT_HIT: "TAKE_PROFIT_HIT";
@@ -20,6 +21,10 @@ export declare const NotificationCategory: z.ZodEnum<{
20
21
  AUTO_REBALANCE_EXECUTED: "AUTO_REBALANCE_EXECUTED";
21
22
  AUTO_REBALANCE_FAILED: "AUTO_REBALANCE_FAILED";
22
23
  AUTO_REBALANCE_PAUSED: "AUTO_REBALANCE_PAUSED";
24
+ TRIGGER_TWAP_STARTED: "TRIGGER_TWAP_STARTED";
25
+ TRIGGER_TWAP_SKIPPED: "TRIGGER_TWAP_SKIPPED";
26
+ TRIGGER_TWAP_FAILED: "TRIGGER_TWAP_FAILED";
27
+ TRIGGER_TWAP_POSITION_CHANGED: "TRIGGER_TWAP_POSITION_CHANGED";
23
28
  TRIGGER_CANCELLED_MIS_SCALED: "TRIGGER_CANCELLED_MIS_SCALED";
24
29
  }>;
25
30
  export type NotificationCategory = z.infer<typeof NotificationCategory>;
@@ -333,6 +338,88 @@ export declare const NotificationParameters: z.ZodDiscriminatedUnion<[z.ZodObjec
333
338
  LIVE_BETA: "LIVE_BETA";
334
339
  }>;
335
340
  type: z.ZodLiteral<"auto_rebalance_paused">;
341
+ }, z.core.$strip>, z.ZodObject<{
342
+ legs: z.ZodArray<z.ZodObject<{
343
+ id: z.ZodString;
344
+ symbol: z.ZodString;
345
+ side: z.ZodEnum<{
346
+ BUY: "BUY";
347
+ SELL: "SELL";
348
+ }>;
349
+ }, z.core.$strip>>;
350
+ triggerId: z.ZodUUID;
351
+ positionId: z.ZodUUID;
352
+ connector: z.ZodEnum<{
353
+ hyperliquid: "hyperliquid";
354
+ binance: "binance";
355
+ bybit: "bybit";
356
+ okx: "okx";
357
+ lighter: "lighter";
358
+ }>;
359
+ type: z.ZodLiteral<"trigger_twap_started">;
360
+ scheduleId: z.ZodUUID;
361
+ }, z.core.$strip>, z.ZodObject<{
362
+ legs: z.ZodArray<z.ZodObject<{
363
+ id: z.ZodString;
364
+ symbol: z.ZodString;
365
+ side: z.ZodEnum<{
366
+ BUY: "BUY";
367
+ SELL: "SELL";
368
+ }>;
369
+ }, z.core.$strip>>;
370
+ triggerId: z.ZodUUID;
371
+ positionId: z.ZodUUID;
372
+ connector: z.ZodEnum<{
373
+ hyperliquid: "hyperliquid";
374
+ binance: "binance";
375
+ bybit: "bybit";
376
+ okx: "okx";
377
+ lighter: "lighter";
378
+ }>;
379
+ type: z.ZodLiteral<"trigger_twap_skipped">;
380
+ reason: z.ZodString;
381
+ }, z.core.$strip>, z.ZodObject<{
382
+ legs: z.ZodArray<z.ZodObject<{
383
+ id: z.ZodString;
384
+ symbol: z.ZodString;
385
+ side: z.ZodEnum<{
386
+ BUY: "BUY";
387
+ SELL: "SELL";
388
+ }>;
389
+ }, z.core.$strip>>;
390
+ triggerId: z.ZodUUID;
391
+ positionId: z.ZodUUID;
392
+ connector: z.ZodEnum<{
393
+ hyperliquid: "hyperliquid";
394
+ binance: "binance";
395
+ bybit: "bybit";
396
+ okx: "okx";
397
+ lighter: "lighter";
398
+ }>;
399
+ type: z.ZodLiteral<"trigger_twap_failed">;
400
+ scheduleId: z.ZodOptional<z.ZodUUID>;
401
+ reason: z.ZodString;
402
+ }, z.core.$strip>, z.ZodObject<{
403
+ legs: z.ZodArray<z.ZodObject<{
404
+ id: z.ZodString;
405
+ symbol: z.ZodString;
406
+ side: z.ZodEnum<{
407
+ BUY: "BUY";
408
+ SELL: "SELL";
409
+ }>;
410
+ }, z.core.$strip>>;
411
+ triggerId: z.ZodUUID;
412
+ positionId: z.ZodUUID;
413
+ connector: z.ZodEnum<{
414
+ hyperliquid: "hyperliquid";
415
+ binance: "binance";
416
+ bybit: "bybit";
417
+ okx: "okx";
418
+ lighter: "lighter";
419
+ }>;
420
+ type: z.ZodLiteral<"trigger_twap_position_changed">;
421
+ scheduleId: z.ZodUUID;
422
+ reason: z.ZodString;
336
423
  }, z.core.$strip>, z.ZodObject<{
337
424
  type: z.ZodLiteral<"trigger_cancelled_mis_scaled">;
338
425
  triggerId: z.ZodUUID;
@@ -354,6 +441,10 @@ export declare const Notification: z.ZodObject<{
354
441
  AUTO_REBALANCE_EXECUTED: "AUTO_REBALANCE_EXECUTED";
355
442
  AUTO_REBALANCE_FAILED: "AUTO_REBALANCE_FAILED";
356
443
  AUTO_REBALANCE_PAUSED: "AUTO_REBALANCE_PAUSED";
444
+ TRIGGER_TWAP_STARTED: "TRIGGER_TWAP_STARTED";
445
+ TRIGGER_TWAP_SKIPPED: "TRIGGER_TWAP_SKIPPED";
446
+ TRIGGER_TWAP_FAILED: "TRIGGER_TWAP_FAILED";
447
+ TRIGGER_TWAP_POSITION_CHANGED: "TRIGGER_TWAP_POSITION_CHANGED";
357
448
  TRIGGER_CANCELLED_MIS_SCALED: "TRIGGER_CANCELLED_MIS_SCALED";
358
449
  }>;
359
450
  parameters: z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -648,6 +739,88 @@ export declare const Notification: z.ZodObject<{
648
739
  LIVE_BETA: "LIVE_BETA";
649
740
  }>;
650
741
  type: z.ZodLiteral<"auto_rebalance_paused">;
742
+ }, z.core.$strip>, z.ZodObject<{
743
+ legs: z.ZodArray<z.ZodObject<{
744
+ id: z.ZodString;
745
+ symbol: z.ZodString;
746
+ side: z.ZodEnum<{
747
+ BUY: "BUY";
748
+ SELL: "SELL";
749
+ }>;
750
+ }, z.core.$strip>>;
751
+ triggerId: z.ZodUUID;
752
+ positionId: z.ZodUUID;
753
+ connector: z.ZodEnum<{
754
+ hyperliquid: "hyperliquid";
755
+ binance: "binance";
756
+ bybit: "bybit";
757
+ okx: "okx";
758
+ lighter: "lighter";
759
+ }>;
760
+ type: z.ZodLiteral<"trigger_twap_started">;
761
+ scheduleId: z.ZodUUID;
762
+ }, z.core.$strip>, z.ZodObject<{
763
+ legs: z.ZodArray<z.ZodObject<{
764
+ id: z.ZodString;
765
+ symbol: z.ZodString;
766
+ side: z.ZodEnum<{
767
+ BUY: "BUY";
768
+ SELL: "SELL";
769
+ }>;
770
+ }, z.core.$strip>>;
771
+ triggerId: z.ZodUUID;
772
+ positionId: z.ZodUUID;
773
+ connector: z.ZodEnum<{
774
+ hyperliquid: "hyperliquid";
775
+ binance: "binance";
776
+ bybit: "bybit";
777
+ okx: "okx";
778
+ lighter: "lighter";
779
+ }>;
780
+ type: z.ZodLiteral<"trigger_twap_skipped">;
781
+ reason: z.ZodString;
782
+ }, z.core.$strip>, z.ZodObject<{
783
+ legs: z.ZodArray<z.ZodObject<{
784
+ id: z.ZodString;
785
+ symbol: z.ZodString;
786
+ side: z.ZodEnum<{
787
+ BUY: "BUY";
788
+ SELL: "SELL";
789
+ }>;
790
+ }, z.core.$strip>>;
791
+ triggerId: z.ZodUUID;
792
+ positionId: z.ZodUUID;
793
+ connector: z.ZodEnum<{
794
+ hyperliquid: "hyperliquid";
795
+ binance: "binance";
796
+ bybit: "bybit";
797
+ okx: "okx";
798
+ lighter: "lighter";
799
+ }>;
800
+ type: z.ZodLiteral<"trigger_twap_failed">;
801
+ scheduleId: z.ZodOptional<z.ZodUUID>;
802
+ reason: z.ZodString;
803
+ }, z.core.$strip>, z.ZodObject<{
804
+ legs: z.ZodArray<z.ZodObject<{
805
+ id: z.ZodString;
806
+ symbol: z.ZodString;
807
+ side: z.ZodEnum<{
808
+ BUY: "BUY";
809
+ SELL: "SELL";
810
+ }>;
811
+ }, z.core.$strip>>;
812
+ triggerId: z.ZodUUID;
813
+ positionId: z.ZodUUID;
814
+ connector: z.ZodEnum<{
815
+ hyperliquid: "hyperliquid";
816
+ binance: "binance";
817
+ bybit: "bybit";
818
+ okx: "okx";
819
+ lighter: "lighter";
820
+ }>;
821
+ type: z.ZodLiteral<"trigger_twap_position_changed">;
822
+ scheduleId: z.ZodUUID;
823
+ reason: z.ZodString;
651
824
  }, z.core.$strip>, z.ZodObject<{
652
825
  type: z.ZodLiteral<"trigger_cancelled_mis_scaled">;
653
826
  triggerId: z.ZodUUID;
@@ -14,6 +14,10 @@ const NotificationCategory = z.enum([
14
14
  "AUTO_REBALANCE_EXECUTED",
15
15
  "AUTO_REBALANCE_FAILED",
16
16
  "AUTO_REBALANCE_PAUSED",
17
+ "TRIGGER_TWAP_STARTED",
18
+ "TRIGGER_TWAP_SKIPPED",
19
+ "TRIGGER_TWAP_FAILED",
20
+ "TRIGGER_TWAP_POSITION_CHANGED",
17
21
  "TRIGGER_CANCELLED_MIS_SCALED"
18
22
  ]);
19
23
  const NotificationMetric = z.enum([
@@ -146,6 +150,29 @@ const TriggerCancelledMisScaledNotificationParameters = z.object({
146
150
  storedBps: z.number(),
147
151
  readingMarginPct: z.number()
148
152
  });
153
+ const TriggerTWAPNotificationAnchor = PositionLegParameters.safeExtend({
154
+ triggerId: z.uuid(),
155
+ positionId: z.uuid(),
156
+ connector: Connector
157
+ });
158
+ const TriggerTWAPStartedNotificationParameters = TriggerTWAPNotificationAnchor.safeExtend({
159
+ type: z.literal("trigger_twap_started"),
160
+ scheduleId: z.uuid()
161
+ });
162
+ const TriggerTWAPSkippedNotificationParameters = TriggerTWAPNotificationAnchor.safeExtend({
163
+ type: z.literal("trigger_twap_skipped"),
164
+ reason: z.string().min(1).max(255)
165
+ });
166
+ const TriggerTWAPFailedNotificationParameters = TriggerTWAPNotificationAnchor.safeExtend({
167
+ type: z.literal("trigger_twap_failed"),
168
+ scheduleId: z.uuid().optional(),
169
+ reason: z.string().min(1).max(255)
170
+ });
171
+ const TriggerTWAPPositionChangedNotificationParameters = TriggerTWAPNotificationAnchor.safeExtend({
172
+ type: z.literal("trigger_twap_position_changed"),
173
+ scheduleId: z.uuid(),
174
+ reason: z.string().min(1).max(255)
175
+ });
149
176
  const NotificationParameters = z.discriminatedUnion("type", [
150
177
  TakeProfitNotificationParameters,
151
178
  StopLossNotificationParameters,
@@ -155,6 +182,10 @@ const NotificationParameters = z.discriminatedUnion("type", [
155
182
  AutoRebalanceExecutedNotificationParameters,
156
183
  AutoRebalanceFailedNotificationParameters,
157
184
  AutoRebalancePausedNotificationParameters,
185
+ TriggerTWAPStartedNotificationParameters,
186
+ TriggerTWAPSkippedNotificationParameters,
187
+ TriggerTWAPFailedNotificationParameters,
188
+ TriggerTWAPPositionChangedNotificationParameters,
158
189
  TriggerCancelledMisScaledNotificationParameters
159
190
  ]);
160
191
  const Notification = z.object({
@@ -13,6 +13,10 @@ export declare const NotificationListResponse: z.ZodObject<{
13
13
  AUTO_REBALANCE_EXECUTED: "AUTO_REBALANCE_EXECUTED";
14
14
  AUTO_REBALANCE_FAILED: "AUTO_REBALANCE_FAILED";
15
15
  AUTO_REBALANCE_PAUSED: "AUTO_REBALANCE_PAUSED";
16
+ TRIGGER_TWAP_STARTED: "TRIGGER_TWAP_STARTED";
17
+ TRIGGER_TWAP_SKIPPED: "TRIGGER_TWAP_SKIPPED";
18
+ TRIGGER_TWAP_FAILED: "TRIGGER_TWAP_FAILED";
19
+ TRIGGER_TWAP_POSITION_CHANGED: "TRIGGER_TWAP_POSITION_CHANGED";
16
20
  TRIGGER_CANCELLED_MIS_SCALED: "TRIGGER_CANCELLED_MIS_SCALED";
17
21
  }>;
18
22
  parameters: z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -307,6 +311,88 @@ export declare const NotificationListResponse: z.ZodObject<{
307
311
  LIVE_BETA: "LIVE_BETA";
308
312
  }>;
309
313
  type: z.ZodLiteral<"auto_rebalance_paused">;
314
+ }, z.core.$strip>, z.ZodObject<{
315
+ legs: z.ZodArray<z.ZodObject<{
316
+ id: z.ZodString;
317
+ symbol: z.ZodString;
318
+ side: z.ZodEnum<{
319
+ BUY: "BUY";
320
+ SELL: "SELL";
321
+ }>;
322
+ }, z.core.$strip>>;
323
+ triggerId: z.ZodUUID;
324
+ positionId: z.ZodUUID;
325
+ connector: z.ZodEnum<{
326
+ hyperliquid: "hyperliquid";
327
+ binance: "binance";
328
+ bybit: "bybit";
329
+ okx: "okx";
330
+ lighter: "lighter";
331
+ }>;
332
+ type: z.ZodLiteral<"trigger_twap_started">;
333
+ scheduleId: z.ZodUUID;
334
+ }, z.core.$strip>, z.ZodObject<{
335
+ legs: z.ZodArray<z.ZodObject<{
336
+ id: z.ZodString;
337
+ symbol: z.ZodString;
338
+ side: z.ZodEnum<{
339
+ BUY: "BUY";
340
+ SELL: "SELL";
341
+ }>;
342
+ }, z.core.$strip>>;
343
+ triggerId: z.ZodUUID;
344
+ positionId: z.ZodUUID;
345
+ connector: z.ZodEnum<{
346
+ hyperliquid: "hyperliquid";
347
+ binance: "binance";
348
+ bybit: "bybit";
349
+ okx: "okx";
350
+ lighter: "lighter";
351
+ }>;
352
+ type: z.ZodLiteral<"trigger_twap_skipped">;
353
+ reason: z.ZodString;
354
+ }, z.core.$strip>, z.ZodObject<{
355
+ legs: z.ZodArray<z.ZodObject<{
356
+ id: z.ZodString;
357
+ symbol: z.ZodString;
358
+ side: z.ZodEnum<{
359
+ BUY: "BUY";
360
+ SELL: "SELL";
361
+ }>;
362
+ }, z.core.$strip>>;
363
+ triggerId: z.ZodUUID;
364
+ positionId: z.ZodUUID;
365
+ connector: z.ZodEnum<{
366
+ hyperliquid: "hyperliquid";
367
+ binance: "binance";
368
+ bybit: "bybit";
369
+ okx: "okx";
370
+ lighter: "lighter";
371
+ }>;
372
+ type: z.ZodLiteral<"trigger_twap_failed">;
373
+ scheduleId: z.ZodOptional<z.ZodUUID>;
374
+ reason: z.ZodString;
375
+ }, z.core.$strip>, z.ZodObject<{
376
+ legs: z.ZodArray<z.ZodObject<{
377
+ id: z.ZodString;
378
+ symbol: z.ZodString;
379
+ side: z.ZodEnum<{
380
+ BUY: "BUY";
381
+ SELL: "SELL";
382
+ }>;
383
+ }, z.core.$strip>>;
384
+ triggerId: z.ZodUUID;
385
+ positionId: z.ZodUUID;
386
+ connector: z.ZodEnum<{
387
+ hyperliquid: "hyperliquid";
388
+ binance: "binance";
389
+ bybit: "bybit";
390
+ okx: "okx";
391
+ lighter: "lighter";
392
+ }>;
393
+ type: z.ZodLiteral<"trigger_twap_position_changed">;
394
+ scheduleId: z.ZodUUID;
395
+ reason: z.ZodString;
310
396
  }, z.core.$strip>, z.ZodObject<{
311
397
  type: z.ZodLiteral<"trigger_cancelled_mis_scaled">;
312
398
  triggerId: z.ZodUUID;
@@ -29,6 +29,7 @@ export declare const ScheduleCancelledReason: z.ZodEnum<{
29
29
  }>;
30
30
  export type ScheduleCancelledReason = z.infer<typeof ScheduleCancelledReason>;
31
31
  declare const TWAPOpenLeg: z.ZodObject<{
32
+ id: z.ZodOptional<z.ZodString>;
32
33
  symbol: z.ZodString;
33
34
  side: z.ZodEnum<{
34
35
  BUY: "BUY";
@@ -192,6 +193,7 @@ export declare const TWAPOpen: z.ZodObject<{
192
193
  sizeJitterBps: z.ZodInt;
193
194
  }, z.core.$strip>;
194
195
  legs: z.ZodArray<z.ZodObject<{
196
+ id: z.ZodOptional<z.ZodString>;
195
197
  symbol: z.ZodString;
196
198
  side: z.ZodEnum<{
197
199
  BUY: "BUY";
@@ -360,6 +362,7 @@ export declare const Schedule: z.ZodDiscriminatedUnion<[z.ZodObject<{
360
362
  sizeJitterBps: z.ZodInt;
361
363
  }, z.core.$strip>;
362
364
  legs: z.ZodArray<z.ZodObject<{
365
+ id: z.ZodOptional<z.ZodString>;
363
366
  symbol: z.ZodString;
364
367
  side: z.ZodEnum<{
365
368
  BUY: "BUY";
@@ -30,6 +30,8 @@ const ScheduleCancelledReason = z.enum([
30
30
  "POSITION_REVERSED"
31
31
  ]);
32
32
  const TWAPOpenLeg = z.object({
33
+ /** PHASE-1 LEG ID: mirrors `symbol` today; required in phase 3 when `symbol` becomes the ticker. */
34
+ id: InstrumentId.optional(),
33
35
  /**
34
36
  * Instrument ID
35
37
  */
@@ -10,6 +10,7 @@ export declare const CreateTWAPOpen: z.ZodObject<{
10
10
  intent: z.ZodLiteral<"OPEN">;
11
11
  executionType: z.ZodLiteral<"MARKET">;
12
12
  legs: z.ZodArray<z.ZodObject<{
13
+ id: z.ZodOptional<z.ZodString>;
13
14
  symbol: z.ZodString;
14
15
  side: z.ZodEnum<{
15
16
  BUY: "BUY";
@@ -46,6 +47,7 @@ export declare const CreateSchedule: z.ZodDiscriminatedUnion<[z.ZodObject<{
46
47
  intent: z.ZodLiteral<"OPEN">;
47
48
  executionType: z.ZodLiteral<"MARKET">;
48
49
  legs: z.ZodArray<z.ZodObject<{
50
+ id: z.ZodOptional<z.ZodString>;
49
51
  symbol: z.ZodString;
50
52
  side: z.ZodEnum<{
51
53
  BUY: "BUY";
@@ -1,31 +1,8 @@
1
1
  import { z } from 'zod';
2
2
  import { ClientIdCode } from '../common/client-id';
3
- import { RefineMinimumOneSymbol, RefineUniqueSymbols, RefineWeightingSum } from '../common/refinement';
4
- import { UnsignedDecimalString, AssetWeight, Side } from '../common/schema';
5
- import { InstrumentId } from '../instrument';
6
3
  import { TWAPRandomization, DEFAULT_TWAP_RANDOMIZATION } from './randomization';
4
+ import { FINAL_TWAP_SLICE_START_HEADROOM_SEC, TWAPSliceIntervalSec, TWAPTargetNotional, TWAPOpenLegs } from './twap-config';
7
5
 
8
- const THIRTY_ONE_DAYS_SEC = 60 * 60 * 24 * 31;
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({
15
- /**
16
- * Instrument ID
17
- */
18
- symbol: InstrumentId,
19
- /**
20
- * Direction to take
21
- */
22
- side: Side,
23
- /**
24
- * Share of the parent target notional allocated to this leg
25
- */
26
- weight: AssetWeight
27
- });
28
- const TWAPOpenLegs = z.array(TWAPOpenLeg).superRefine(RefineMinimumOneSymbol).superRefine(RefineUniqueSymbols).superRefine(RefineWeightingSum);
29
6
  const BaseSchedule = z.object({
30
7
  /**
31
8
  * Start at date
@@ -41,8 +18,8 @@ const BaseSchedule = z.object({
41
18
  randomization: TWAPRandomization.optional().default(DEFAULT_TWAP_RANDOMIZATION)
42
19
  }).refine((data) => data.startAt && data.endAt && data.startAt < data.endAt, {
43
20
  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`
21
+ }).refine((data) => data.endAt.getTime() - data.startAt.getTime() >= FINAL_TWAP_SLICE_START_HEADROOM_SEC * 1e3, {
22
+ message: `TWAP execution window must be at least ${FINAL_TWAP_SLICE_START_HEADROOM_SEC} seconds`
46
23
  });
47
24
  const CreateTWAPOpen = BaseSchedule.safeExtend({
48
25
  /**
@@ -64,11 +41,11 @@ const CreateTWAPOpen = BaseSchedule.safeExtend({
64
41
  /**
65
42
  * Target notional
66
43
  */
67
- targetNotional: TargetNotional,
44
+ targetNotional: TWAPTargetNotional,
68
45
  /**
69
46
  * Slice interval in seconds
70
47
  */
71
- sliceIntervalSec: SliceIntervalSec,
48
+ sliceIntervalSec: TWAPSliceIntervalSec,
72
49
  /**
73
50
  * Attribution route code (client_ids.code)
74
51
  */
@@ -94,7 +71,7 @@ const CreateTWAPClose = BaseSchedule.safeExtend({
94
71
  /**
95
72
  * Slice interval in seconds
96
73
  */
97
- sliceIntervalSec: SliceIntervalSec,
74
+ sliceIntervalSec: TWAPSliceIntervalSec,
98
75
  /**
99
76
  * Attribution route code (client_ids.code)
100
77
  */
@@ -80,6 +80,7 @@ export declare const ScheduleListResponse: z.ZodObject<{
80
80
  sizeJitterBps: z.ZodInt;
81
81
  }, z.core.$strip>;
82
82
  legs: z.ZodArray<z.ZodObject<{
83
+ id: z.ZodOptional<z.ZodString>;
83
84
  symbol: z.ZodString;
84
85
  side: z.ZodEnum<{
85
86
  BUY: "BUY";
@@ -250,6 +251,7 @@ export declare const CreateScheduleResponse: z.ZodObject<{
250
251
  sizeJitterBps: z.ZodInt;
251
252
  }, z.core.$strip>;
252
253
  legs: z.ZodArray<z.ZodObject<{
254
+ id: z.ZodOptional<z.ZodString>;
253
255
  symbol: z.ZodString;
254
256
  side: z.ZodEnum<{
255
257
  BUY: "BUY";
@@ -0,0 +1,41 @@
1
+ import { z } from 'zod';
2
+ export declare const MAX_TWAP_DURATION_SEC: number;
3
+ export declare const MIN_TWAP_SLICE_INTERVAL_SEC = 15;
4
+ export declare const FINAL_TWAP_SLICE_START_HEADROOM_SEC = 15;
5
+ export declare const TWAPSliceIntervalSec: z.ZodInt;
6
+ export declare const TWAPTargetNotional: z.ZodString;
7
+ export declare const TWAPOpenLeg: z.ZodObject<{
8
+ id: z.ZodOptional<z.ZodString>;
9
+ symbol: z.ZodString;
10
+ side: z.ZodEnum<{
11
+ BUY: "BUY";
12
+ SELL: "SELL";
13
+ }>;
14
+ weight: z.ZodNumber;
15
+ }, z.core.$strip>;
16
+ export declare const TWAPOpenLegs: z.ZodArray<z.ZodObject<{
17
+ id: z.ZodOptional<z.ZodString>;
18
+ symbol: z.ZodString;
19
+ side: z.ZodEnum<{
20
+ BUY: "BUY";
21
+ SELL: "SELL";
22
+ }>;
23
+ weight: z.ZodNumber;
24
+ }, z.core.$strip>>;
25
+ export declare const TriggerTWAPOpenLegs: z.ZodTuple<[z.ZodObject<{
26
+ id: z.ZodOptional<z.ZodString>;
27
+ symbol: z.ZodString;
28
+ side: z.ZodEnum<{
29
+ BUY: "BUY";
30
+ SELL: "SELL";
31
+ }>;
32
+ weight: z.ZodNumber;
33
+ }, z.core.$strict>], z.ZodObject<{
34
+ id: z.ZodOptional<z.ZodString>;
35
+ symbol: z.ZodString;
36
+ side: z.ZodEnum<{
37
+ BUY: "BUY";
38
+ SELL: "SELL";
39
+ }>;
40
+ weight: z.ZodNumber;
41
+ }, z.core.$strict>>;
@@ -0,0 +1,29 @@
1
+ import { z } from 'zod';
2
+ import { RefineLegIdMatchesSymbol, RefineMinimumOneSymbol, RefineUniqueSymbols, RefineWeightingSum } from '../common/refinement';
3
+ import { UnsignedDecimalString, AssetWeight, Side } from '../common/schema';
4
+ import { InstrumentId } from '../instrument';
5
+
6
+ const MAX_TWAP_DURATION_SEC = 60 * 60 * 24 * 31;
7
+ const MIN_TWAP_SLICE_INTERVAL_SEC = 15;
8
+ const FINAL_TWAP_SLICE_START_HEADROOM_SEC = 15;
9
+ const TWAPSliceIntervalSec = z.int().min(MIN_TWAP_SLICE_INTERVAL_SEC).max(MAX_TWAP_DURATION_SEC);
10
+ const TWAPTargetNotional = UnsignedDecimalString.refine((value) => /[1-9]/.test(value), {
11
+ message: "Target notional must be greater than zero"
12
+ });
13
+ const TWAPOpenLeg = z.object({
14
+ /** PHASE-1 LEG ID: mirrors `symbol` today; required in phase 3 when `symbol` becomes the ticker. */
15
+ id: InstrumentId.optional(),
16
+ /** Instrument ID. */
17
+ symbol: InstrumentId,
18
+ /** Direction to take. */
19
+ side: Side,
20
+ /** Share of the parent target notional allocated to this leg. */
21
+ weight: AssetWeight
22
+ }).superRefine(RefineLegIdMatchesSymbol);
23
+ const TWAPOpenLegs = z.array(TWAPOpenLeg).superRefine(RefineMinimumOneSymbol).superRefine(RefineUniqueSymbols).superRefine(RefineWeightingSum);
24
+ const TriggerTWAPOpenLeg = TWAPOpenLeg.strict();
25
+ const TriggerTWAPOpenLegs = z.tuple([
26
+ TriggerTWAPOpenLeg
27
+ ]).rest(TriggerTWAPOpenLeg).superRefine(RefineUniqueSymbols).superRefine(RefineWeightingSum);
28
+
29
+ export { FINAL_TWAP_SLICE_START_HEADROOM_SEC, MAX_TWAP_DURATION_SEC, MIN_TWAP_SLICE_INTERVAL_SEC, TWAPOpenLeg, TWAPOpenLegs, TWAPSliceIntervalSec, TWAPTargetNotional, TriggerTWAPOpenLegs };
@@ -28,15 +28,28 @@ const LeaderboardRow = z.object({
28
28
  pearFee: z.string(),
29
29
  tradeFee: z.string(),
30
30
  totalTrades: z.number(),
31
- // The plain average of this account's per-position returns, as a ratio: "0.25" is +25%.
32
- // Every position is weighted equally, so a small winner counts as much as a large one —
33
- // this is a measure of the trader's decisions, not of the dollars those decisions moved.
31
+ // This account's return over the window, as a ratio: "0.25" is +25%. The measured
32
+ // positions' PnL divided by the capital that earned it, so each position weighs by the
33
+ // money it put at risk — a measure of how the account's dollars did, not of how its
34
+ // individual calls went.
34
35
  //
35
- // One formula on every position: (realized + unrealized - fees paid) over the size it
36
- // opened with. A closed position holds nothing, so its unrealized half is zero and this
37
- // reduces to what the trader kept; a partly reduced open position counts both the profit
38
- // it banked and the worth of what it still holds. Only fees of fills that happened are
39
- // charged, so a running position never pays for the exit it has not made.
36
+ // One formula on every position: (realized + unrealized - fees paid) over the most cash that
37
+ // position had committed at one time. A closed position holds nothing, so its unrealized half
38
+ // is zero and this reduces to what the trader kept; a partly reduced open position counts
39
+ // both the profit it banked and the worth of what it still holds. Only fees of fills that
40
+ // happened are charged, so a running position never pays for the exit it has not made.
41
+ //
42
+ // The denominator is cash committed, not market value: each opening fill adds what it paid,
43
+ // each closing fill releases the share of that commitment the quantity it closed was holding,
44
+ // and the peak of that running total is what the return is measured against. So it is not the
45
+ // size the position opened at — a position scaled up afterwards is measured against what it
46
+ // went on to risk — and not the sum of everything it ever opened either, since capital
47
+ // reduced and recommitted counts once rather than twice.
48
+ //
49
+ // Measuring cash rather than market value is deliberate. A market-value denominator can fall
50
+ // below the money actually put in when a position is averaged down, which inflates the
51
+ // return; and no historical price series is kept, so market value could only ever be sampled
52
+ // at the fills themselves.
40
53
  //
41
54
  // Measured only where the window holds both the position's open and the moment the
42
55
  // measurement is taken at: now for a running position, the closing fill for a finished
@@ -46,8 +59,8 @@ const LeaderboardRow = z.object({
46
59
  // Absent when the board could measure none of the account's positions — never "0", which
47
60
  // would claim a break-even trader. An account reaches the board with nothing measurable
48
61
  // when its only trading in the window closed positions opened before it, when a closed
49
- // window left its open positions unpriced, when every position it opened in the window
50
- // closed after it, or when a position recorded no opening size.
62
+ // window left its open positions unpriced, or when every position it opened in the window
63
+ // closed after it.
51
64
  roi: z.string().optional(),
52
65
  // The trader's linked X account, published to every caller — the board names its traders
53
66
  // on the open internet, signed in or not. Absent for an account whose owner has connected