@pear-protocol/types 1.24.0 → 1.25.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 (75) hide show
  1. package/dist/auth/api-keys.js +11 -3
  2. package/dist/auth/entities.js +10 -2
  3. package/dist/auth/payloads.d.ts +7 -0
  4. package/dist/auth/payloads.js +15 -11
  5. package/dist/auth/response.js +4 -1
  6. package/dist/common/array.js +9 -2
  7. package/dist/common/refinement.js +25 -19
  8. package/dist/common/request.js +8 -8
  9. package/dist/common/response.js +10 -10
  10. package/dist/common/schema.js +9 -2
  11. package/dist/common/trade-legs.js +17 -12
  12. package/dist/connector/index.js +7 -1
  13. package/dist/execution/entities.js +96 -65
  14. package/dist/execution/queries.js +5 -1
  15. package/dist/execution/responses.js +3 -1
  16. package/dist/fee/entities.js +17 -3
  17. package/dist/fill/entities.js +33 -29
  18. package/dist/fill/queries.js +4 -1
  19. package/dist/funding/entities.js +4 -4
  20. package/dist/funding/responses.js +2 -2
  21. package/dist/instrument/entities.js +56 -44
  22. package/dist/instrument/queries.js +6 -1
  23. package/dist/instrument/responses.js +4 -4
  24. package/dist/instrument-precision/index.js +23 -23
  25. package/dist/ladder/entities.js +5 -1
  26. package/dist/ladder/payloads.js +15 -4
  27. package/dist/ladder/queries.js +0 -1
  28. package/dist/ladder/responses.js +12 -4
  29. package/dist/leverage/payloads.js +4 -1
  30. package/dist/notification/entities.js +37 -28
  31. package/dist/notification/payloads.js +9 -3
  32. package/dist/notification/queries.js +5 -1
  33. package/dist/notification/responses.js +4 -4
  34. package/dist/order/entities.js +38 -30
  35. package/dist/portfolio/queries.js +18 -3
  36. package/dist/position/entities.js +95 -72
  37. package/dist/position/queries.js +29 -23
  38. package/dist/price/entities.js +4 -1
  39. package/dist/price/responses.js +4 -4
  40. package/dist/rebalance/entities.js +23 -6
  41. package/dist/rebalance/payloads.js +23 -11
  42. package/dist/rebalance/queries.js +2 -8
  43. package/dist/rebalance/responses.js +12 -4
  44. package/dist/saved-baskets/entities.js +3 -1
  45. package/dist/saved-baskets/payloads.js +3 -1
  46. package/dist/schedule/entities.js +87 -71
  47. package/dist/schedule/payloads.js +36 -33
  48. package/dist/schedule/queries.js +5 -1
  49. package/dist/schedule/responses.js +12 -4
  50. package/dist/statistics/entities.d.ts +1 -0
  51. package/dist/statistics/entities.js +12 -0
  52. package/dist/statistics/queries.d.ts +2 -0
  53. package/dist/statistics/queries.js +16 -3
  54. package/dist/statistics/responses.d.ts +1 -0
  55. package/dist/sync/payloads.js +13 -17
  56. package/dist/tca/entities.js +4 -1
  57. package/dist/tca/responses.js +4 -1
  58. package/dist/trade/payloads.js +37 -23
  59. package/dist/trade/responses.js +15 -5
  60. package/dist/trade-accounts/entities.js +4 -1
  61. package/dist/trade-accounts/response.js +6 -2
  62. package/dist/trigger/common/index.js +27 -6
  63. package/dist/trigger/entities/conditions.js +14 -15
  64. package/dist/trigger/entities/index.js +89 -80
  65. package/dist/trigger/oracle.js +10 -3
  66. package/dist/trigger/payloads/conditions.js +8 -2
  67. package/dist/trigger/payloads/index.js +18 -4
  68. package/dist/trigger/queries.js +5 -1
  69. package/dist/trigger/refinement/static.refinement.js +5 -2
  70. package/dist/trigger/refinement/trailing.refinement.js +8 -6
  71. package/dist/trigger/responses.js +12 -4
  72. package/dist/triggers/entities.js +8 -2
  73. package/dist/users/entities.js +4 -1
  74. package/dist/users/payloads.js +17 -18
  75. package/package.json +1 -1
@@ -6,14 +6,14 @@ const NotificationListResponse = z.object({
6
6
  });
7
7
  const MarkNotificationsReadResponse = z.object({
8
8
  /**
9
- * How many notifications were flipped from unread to read.
10
- */
9
+ * How many notifications were flipped from unread to read.
10
+ */
11
11
  updated: z.number().int()
12
12
  });
13
13
  const MarkNotificationUnreadResponse = z.object({
14
14
  /**
15
- * How many notifications were flipped from read to unread.
16
- */
15
+ * How many notifications were flipped from read to unread.
16
+ */
17
17
  updated: z.number().int()
18
18
  });
19
19
 
@@ -3,67 +3,75 @@ import { UnsignedDecimalString, Side } from '../common/schema';
3
3
  import { Connector } from '../connector';
4
4
  import { InstrumentId } from '../instrument';
5
5
 
6
- const OrderStatus = z.enum(["PENDING", "PARTIAL", "FILLED", "CANCELLED", "REJECTED"]);
6
+ const OrderStatus = z.enum([
7
+ "PENDING",
8
+ "PARTIAL",
9
+ "FILLED",
10
+ "CANCELLED",
11
+ "REJECTED"
12
+ ]);
7
13
  const BaseOrder = z.object({
8
14
  /**
9
- * Order UUID
10
- */
15
+ * Order UUID
16
+ */
11
17
  id: z.uuid(),
12
18
  /**
13
- * Connector
14
- */
19
+ * Connector
20
+ */
15
21
  connector: Connector,
16
22
  /**
17
- * Order status
18
- */
23
+ * Order status
24
+ */
19
25
  status: OrderStatus,
20
26
  /**
21
- * Error message
22
- */
27
+ * Error message
28
+ */
23
29
  error: z.string().optional(),
24
30
  /**
25
- * Created at timestamp
26
- */
31
+ * Created at timestamp
32
+ */
27
33
  createdAt: z.string(),
28
34
  /**
29
- * Updated at timestamp
30
- */
35
+ * Updated at timestamp
36
+ */
31
37
  updatedAt: z.string()
32
38
  });
33
39
  const MarketOrder = BaseOrder.extend({
34
40
  /**
35
- * Order type
36
- */
41
+ * Order type
42
+ */
37
43
  type: z.literal("MARKET"),
38
44
  /**
39
- * Instrument ID
40
- */
45
+ * Instrument ID
46
+ */
41
47
  symbol: InstrumentId,
42
48
  /**
43
- * Side
44
- */
49
+ * Side
50
+ */
45
51
  side: Side,
46
52
  /**
47
- * Reduce only flag
48
- */
53
+ * Reduce only flag
54
+ */
49
55
  reduceOnly: z.boolean(),
50
56
  /**
51
- * Contract quantity to trade
52
- */
57
+ * Contract quantity to trade
58
+ */
53
59
  quantity: UnsignedDecimalString,
54
60
  /**
55
- * Price
56
- */
61
+ * Price
62
+ */
57
63
  price: UnsignedDecimalString,
58
64
  /**
59
- * Filled contract quantity
60
- */
65
+ * Filled contract quantity
66
+ */
61
67
  filledQuantity: UnsignedDecimalString,
62
68
  /**
63
- * Filled price
64
- */
69
+ * Filled price
70
+ */
65
71
  filledPrice: UnsignedDecimalString.optional()
66
72
  });
67
- const Order = z.discriminatedUnion("type", [BaseOrder.extend(MarketOrder.shape)]);
73
+ const Order = z.discriminatedUnion("type", [
74
+ BaseOrder.extend(MarketOrder.shape)
75
+ ]);
68
76
 
69
77
  export { MarketOrder, Order, OrderStatus };
@@ -1,19 +1,34 @@
1
1
  import { z } from 'zod';
2
2
 
3
- const PortfolioSource = z.enum(["all", "pear"]);
3
+ const PortfolioSource = z.enum([
4
+ "all",
5
+ "pear"
6
+ ]);
4
7
  const PortfolioQuery = z.object({
5
8
  startDate: z.string().optional(),
6
9
  endDate: z.string().optional(),
7
10
  // "pear" excludes external imported fills from volume calculations.
8
11
  source: PortfolioSource.optional().default("all")
9
12
  });
10
- const PortfolioAnalyticsInterval = z.enum(["1d", "1w", "1m", "1y", "all"]);
13
+ const PortfolioAnalyticsInterval = z.enum([
14
+ "1d",
15
+ "1w",
16
+ "1m",
17
+ "1y",
18
+ "all"
19
+ ]);
11
20
  const PortfolioAnalyticsQuery = z.object({
12
21
  startDate: z.string().optional(),
13
22
  endDate: z.string().optional(),
14
23
  interval: PortfolioAnalyticsInterval.optional(),
15
24
  rollingWindowDays: z.coerce.number().int().optional(),
16
- includeSeries: z.union([z.boolean(), z.enum(["false", "true"]).transform((value) => value === "true")]).optional(),
25
+ includeSeries: z.union([
26
+ z.boolean(),
27
+ z.enum([
28
+ "false",
29
+ "true"
30
+ ]).transform((value) => value === "true")
31
+ ]).optional(),
17
32
  source: PortfolioSource.optional().default("all")
18
33
  });
19
34
 
@@ -3,69 +3,86 @@ import { SignedDecimalString, UnsignedDecimalString } from '../common/schema';
3
3
  import { Connector } from '../connector';
4
4
  import { InstrumentId } from '../instrument';
5
5
 
6
- const PositionStatus = z.enum(["OPEN", "CLOSED"]);
7
- const PositionClosedReason = z.enum(["NETTED", "USER", "LIQUIDATED"]);
8
- const PositionOrigin = z.enum(["PEAR", "EXTERNAL", "PARTIAL"]);
6
+ const PositionStatus = z.enum([
7
+ "OPEN",
8
+ "CLOSED"
9
+ ]);
10
+ const PositionClosedReason = z.enum([
11
+ "NETTED",
12
+ "USER",
13
+ "LIQUIDATED"
14
+ ]);
15
+ const PositionOrigin = z.enum([
16
+ "PEAR",
17
+ "EXTERNAL",
18
+ "PARTIAL"
19
+ ]);
9
20
  const PositionExposure = z.record(InstrumentId, SignedDecimalString);
10
21
  const PositionInitialExposureUSD = z.record(InstrumentId, SignedDecimalString);
11
22
  const PositionTotalFundingPayment = z.record(InstrumentId, SignedDecimalString);
12
23
  const PositionEntryPrices = z.record(InstrumentId, UnsignedDecimalString);
13
24
  const Position = z.object({
14
25
  /**
15
- * Position UUID
16
- */
26
+ * Position UUID
27
+ */
17
28
  id: z.uuid(),
18
29
  /**
19
- * Trade account UUID
20
- */
30
+ * Trade account UUID
31
+ */
21
32
  tradeAccountId: z.uuid(),
22
33
  /**
23
- * Connector
24
- */
34
+ * Connector
35
+ */
25
36
  connector: Connector,
26
37
  /**
27
- * Position status
28
- */
38
+ * Position status
39
+ */
29
40
  status: PositionStatus,
30
41
  /**
31
- * Closed reason
32
- */
42
+ * Closed reason
43
+ */
33
44
  closedReason: PositionClosedReason.nullable().optional(),
34
45
  origin: PositionOrigin,
35
46
  /**
36
- * Position exposure
37
- */
47
+ * Position exposure
48
+ */
38
49
  exposure: PositionExposure,
39
50
  /**
40
- * Whether a backfilled fill invalidated historical metrics derived from this position.
41
- */
51
+ * Whether a backfilled fill invalidated historical metrics derived from this position.
52
+ */
42
53
  unstableHistoricalData: z.boolean(),
43
54
  totalFundingPayment: PositionTotalFundingPayment,
44
55
  /**
45
- * Closed at timestamp
46
- */
56
+ * Closed at timestamp
57
+ */
47
58
  closedAt: z.string().nullable().optional(),
48
59
  /**
49
- * The exposure expressed in USD at the time
50
- * the position was opened. It does not change
51
- * on adjustments, and is only used for UI purposes.
52
- */
60
+ * The exposure expressed in USD at the time
61
+ * the position was opened. It does not change
62
+ * on adjustments, and is only used for UI purposes.
63
+ */
53
64
  initialExposureUSD: PositionInitialExposureUSD,
54
65
  /**
55
- * Per-instrument entry (cost-basis) price, derived from the fills ledger. Unlike
56
- * initialExposureUSD, this DOES account for adjustments — it is the live weighted-average
57
- * entry price of the current exposure.
58
- */
66
+ * Per-instrument entry (cost-basis) price, derived from the fills ledger. Unlike
67
+ * initialExposureUSD, this DOES account for adjustments — it is the live weighted-average
68
+ * entry price of the current exposure.
69
+ */
59
70
  entryPrices: PositionEntryPrices,
60
71
  createdAt: z.string(),
61
72
  updatedAt: z.string()
62
73
  });
63
- const ClosedTradeLegSide = z.enum(["LONG", "SHORT"]);
74
+ const ClosedTradeLegSide = z.enum([
75
+ "LONG",
76
+ "SHORT"
77
+ ]);
64
78
  const ClosedTradeStepLeg = z.discriminatedUnion("kind", [
65
79
  z.object({
66
80
  kind: z.literal("INCREASE"),
67
81
  asset: InstrumentId,
68
- side: z.enum(["BUY", "SELL"]),
82
+ side: z.enum([
83
+ "BUY",
84
+ "SELL"
85
+ ]),
69
86
  quantity: UnsignedDecimalString,
70
87
  /** "0" on an unpriceable synthetic — the ledger recorded no price to report. */
71
88
  price: UnsignedDecimalString,
@@ -76,7 +93,10 @@ const ClosedTradeStepLeg = z.discriminatedUnion("kind", [
76
93
  z.object({
77
94
  kind: z.literal("REDUCE"),
78
95
  asset: InstrumentId,
79
- side: z.enum(["BUY", "SELL"]),
96
+ side: z.enum([
97
+ "BUY",
98
+ "SELL"
99
+ ]),
80
100
  /** The quantity that actually closed. On a flip this is less than the fill's own size. */
81
101
  quantity: UnsignedDecimalString,
82
102
  price: UnsignedDecimalString,
@@ -90,7 +110,10 @@ const ClosedTradeStepLeg = z.discriminatedUnion("kind", [
90
110
  z.object({
91
111
  kind: z.literal("REDUCE_UNPRICED"),
92
112
  asset: InstrumentId,
93
- side: z.enum(["BUY", "SELL"]),
113
+ side: z.enum([
114
+ "BUY",
115
+ "SELL"
116
+ ]),
94
117
  quantity: UnsignedDecimalString,
95
118
  tradeFee: SignedDecimalString,
96
119
  pearFee: SignedDecimalString
@@ -98,9 +121,9 @@ const ClosedTradeStepLeg = z.discriminatedUnion("kind", [
98
121
  ]);
99
122
  const ClosedTradeStep = z.object({
100
123
  /**
101
- * The execution that placed these fills. Absent when the fills recorded none, in
102
- * which case the step was grouped by fill time and is best effort.
103
- */
124
+ * The execution that placed these fills. Absent when the fills recorded none, in
125
+ * which case the step was grouped by fill time and is best effort.
126
+ */
104
127
  executionId: z.string().optional(),
105
128
  /** When the step's fills landed. */
106
129
  at: z.string(),
@@ -124,25 +147,25 @@ const ClosedTradeLeg = z.object({
124
147
  tradeFees: SignedDecimalString,
125
148
  pearFees: SignedDecimalString,
126
149
  /**
127
- * Funding attributed to this leg over the position's life (signed; negative = net paid).
128
- *
129
- * Reported beside netPnl, never folded into it: netPnl carries the same fills-only
130
- * meaning here as in /portfolio, and funding is a separate cash flow. A caller that
131
- * wants the leg's all-in result adds the two.
132
- */
150
+ * Funding attributed to this leg over the position's life (signed; negative = net paid).
151
+ *
152
+ * Reported beside netPnl, never folded into it: netPnl carries the same fills-only
153
+ * meaning here as in /portfolio, and funding is a separate cash flow. A caller that
154
+ * wants the leg's all-in result adds the two.
155
+ */
133
156
  funding: SignedDecimalString,
134
157
  entryNotional: UnsignedDecimalString,
135
158
  /**
136
- * Size closed at a known price. With undeterminedSize this accounts for every unit
137
- * the leg closed, so the total closed size is the sum of the two. It is not reported
138
- * separately, because a value derivable from two others can only drift.
139
- */
159
+ * Size closed at a known price. With undeterminedSize this accounts for every unit
160
+ * the leg closed, so the total closed size is the sum of the two. It is not reported
161
+ * separately, because a value derivable from two others can only drift.
162
+ */
140
163
  exitQuantity: UnsignedDecimalString,
141
164
  /**
142
- * Closed size whose PnL is unpriceable, because it closed against a 0-price
143
- * synthetic or against an entry basis that was itself unpriced. It contributes
144
- * nothing to grossPnl or exitVwap.
145
- */
165
+ * Closed size whose PnL is unpriceable, because it closed against a 0-price
166
+ * synthetic or against an entry basis that was itself unpriced. It contributes
167
+ * nothing to grossPnl or exitVwap.
168
+ */
146
169
  undeterminedSize: UnsignedDecimalString
147
170
  });
148
171
  const ClosedTrade = z.object({
@@ -160,28 +183,28 @@ const ClosedTrade = z.object({
160
183
  tradeFees: SignedDecimalString,
161
184
  pearFees: SignedDecimalString,
162
185
  /**
163
- * Funding attributed to the whole trade (signed; negative = net paid).
164
- *
165
- * Totals every asset the position carried exposure on, which can exceed the sum of
166
- * the legs: funding follows exposure, and an asset with exposure but no confirmed
167
- * fill earns no leg. Summing the legs instead would understate what the trade paid.
168
- *
169
- * Reported beside netPnl, never folded into it. See the leg field's note.
170
- */
186
+ * Funding attributed to the whole trade (signed; negative = net paid).
187
+ *
188
+ * Totals every asset the position carried exposure on, which can exceed the sum of
189
+ * the legs: funding follows exposure, and an asset with exposure but no confirmed
190
+ * fill earns no leg. Summing the legs instead would understate what the trade paid.
191
+ *
192
+ * Reported beside netPnl, never folded into it. See the leg field's note.
193
+ */
171
194
  totalFunding: SignedDecimalString,
172
195
  entryNotional: UnsignedDecimalString,
173
196
  /**
174
- * Proceeds of the priced closes. Understates whenever part of the position closed
175
- * unpriceably — exitNotionalComplete says whether that happened.
176
- */
197
+ * Proceeds of the priced closes. Understates whenever part of the position closed
198
+ * unpriceably — exitNotionalComplete says whether that happened.
199
+ */
177
200
  exitNotional: UnsignedDecimalString,
178
201
  /**
179
- * True when every closed unit had a known price, so exitNotional is the whole story.
180
- *
181
- * This is NOT the negation of hasSyntheticFills. A synthetic fill can carry a real
182
- * price and stay complete, and a priced closing fill still breaks completeness when
183
- * the entry basis it closed against was unpriced.
184
- */
202
+ * True when every closed unit had a known price, so exitNotional is the whole story.
203
+ *
204
+ * This is NOT the negation of hasSyntheticFills. A synthetic fill can carry a real
205
+ * price and stay complete, and a priced closing fill still breaks completeness when
206
+ * the entry basis it closed against was unpriced.
207
+ */
185
208
  exitNotionalComplete: z.boolean(),
186
209
  /** Whether any fill on the position was a synthetic bridge fill (gap/gone reconstruction). */
187
210
  hasSyntheticFills: z.boolean(),
@@ -191,13 +214,13 @@ const ClosedTrade = z.object({
191
214
  shortAssets: z.array(InstrumentId),
192
215
  legs: z.array(ClosedTradeLeg),
193
216
  /**
194
- * What happened to the position, oldest first: the open, every add, every reduction
195
- * and the close. `legs` says how each asset finished; this says how it got there.
196
- *
197
- * Absent unless the request asks for it, because the array is unbounded — one entry
198
- * per recorded action, so a heavily traded position produces a long one. `openedAt`
199
- * carries the open time that step 1 would otherwise have been the only source of.
200
- */
217
+ * What happened to the position, oldest first: the open, every add, every reduction
218
+ * and the close. `legs` says how each asset finished; this says how it got there.
219
+ *
220
+ * Absent unless the request asks for it, because the array is unbounded — one entry
221
+ * per recorded action, so a heavily traded position produces a long one. `openedAt`
222
+ * carries the open time that step 1 would otherwise have been the only source of.
223
+ */
201
224
  steps: z.array(ClosedTradeStep).optional()
202
225
  });
203
226
 
@@ -8,45 +8,51 @@ const OrderBy = z.union([
8
8
  z.literal("updatedAt"),
9
9
  z.literal("-updatedAt")
10
10
  ]);
11
- const StatusEnum = z.enum(["OPEN", "CLOSED"]);
11
+ const StatusEnum = z.enum([
12
+ "OPEN",
13
+ "CLOSED"
14
+ ]);
12
15
  const StatusArray = z.preprocess((arg) => normalizeArray(arg), z.array(StatusEnum));
13
16
  const PositionListParams = CursorFindParams.extend({
14
17
  /**
15
- * Connector filter
16
- */
18
+ * Connector filter
19
+ */
17
20
  connector: Connector.optional(),
18
21
  /**
19
- * Status filter
20
- */
22
+ * Status filter
23
+ */
21
24
  status: StatusArray.optional(),
22
25
  /**
23
- * Order by field
24
- */
26
+ * Order by field
27
+ */
25
28
  orderBy: OrderBy.default("-createdAt")
26
29
  });
27
30
  const ClosedPositionListParams = CursorFindParams.extend({
28
31
  /**
29
- * Capped below the shared 2000 because every row drags its fills along — 2000
30
- * closed positions could pull tens of thousands of fill rows into one response.
31
- */
32
+ * Capped below the shared 2000 because every row drags its fills along — 2000
33
+ * closed positions could pull tens of thousands of fill rows into one response.
34
+ */
32
35
  limit: z.coerce.number().int().positive().max(200).optional().default(20),
33
36
  /**
34
- * Inclusive bounds on the close time. They filter the same
35
- * `coalesce(closed_at, updated_at)` expression the ordering and cursor use, so
36
- * filtering and paging cannot disagree. Absent means unbounded.
37
- */
37
+ * Inclusive bounds on the close time. They filter the same
38
+ * `coalesce(closed_at, updated_at)` expression the ordering and cursor use, so
39
+ * filtering and paging cannot disagree. Absent means unbounded.
40
+ */
38
41
  startDate: z.string().optional(),
39
42
  endDate: z.string().optional(),
40
43
  /**
41
- * Whether to return each trade's `steps` timeline. Off by default because the array
42
- * is unbounded, and a caller listing history rarely needs every recorded action of
43
- * every row. `openedAt` is always present, so omitting steps costs no timestamp.
44
- *
45
- * Accepts a real boolean from an SDK caller and its text form from a query string.
46
- * Deliberately not `z.coerce.boolean()`, which reads the string "false" as true and
47
- * so cannot be switched off from a URL at all.
48
- */
49
- includeSteps: z.union([z.boolean(), z.stringbool()]).optional().default(false)
44
+ * Whether to return each trade's `steps` timeline. Off by default because the array
45
+ * is unbounded, and a caller listing history rarely needs every recorded action of
46
+ * every row. `openedAt` is always present, so omitting steps costs no timestamp.
47
+ *
48
+ * Accepts a real boolean from an SDK caller and its text form from a query string.
49
+ * Deliberately not `z.coerce.boolean()`, which reads the string "false" as true and
50
+ * so cannot be switched off from a URL at all.
51
+ */
52
+ includeSteps: z.union([
53
+ z.boolean(),
54
+ z.stringbool()
55
+ ]).optional().default(false)
50
56
  });
51
57
 
52
58
  export { ClosedPositionListParams, PositionListParams };
@@ -1,7 +1,10 @@
1
1
  import { z } from 'zod';
2
2
  import { InstrumentId } from '../instrument';
3
3
 
4
- const PriceSource = z.enum(["mid", "mark"]);
4
+ const PriceSource = z.enum([
5
+ "mid",
6
+ "mark"
7
+ ]);
5
8
  const InstrumentPriceMap = z.record(InstrumentId, z.string());
6
9
 
7
10
  export { InstrumentPriceMap, PriceSource };
@@ -3,12 +3,12 @@ import { InstrumentPriceMap } from './entities';
3
3
 
4
4
  const PricesResponse = z.object({
5
5
  /**
6
- * Mid prices for instruments
7
- */
6
+ * Mid prices for instruments
7
+ */
8
8
  mid: InstrumentPriceMap,
9
9
  /**
10
- * Mark prices for instruments
11
- */
10
+ * Mark prices for instruments
11
+ */
12
12
  mark: InstrumentPriceMap
13
13
  });
14
14
 
@@ -2,16 +2,29 @@ import { z } from 'zod';
2
2
  import { UnsignedDecimalString } from '../common/schema';
3
3
  import { InstrumentId } from '../instrument';
4
4
 
5
- const AutoRebalanceStatus = z.enum(["ACTIVE", "PAUSED"]);
5
+ const AutoRebalanceStatus = z.enum([
6
+ "ACTIVE",
7
+ "PAUSED"
8
+ ]);
6
9
  const AutoRebalancePausedReason = z.enum([
7
10
  "USER",
8
11
  "POSITION_CHANGED",
9
12
  "REPEATED_FAILURES",
10
13
  "INVALID_LIVE_BETA_EXPOSURE"
11
14
  ]);
12
- const AutoRebalanceWeightSource = z.enum(["INITIAL_WEIGHT", "LIVE_BETA"]);
13
- const AutoRebalanceTimeframe = z.enum(["1h", "4h", "1d"]);
14
- const RebalanceEventStatus = z.enum(["SUCCESS", "FAILED"]);
15
+ const AutoRebalanceWeightSource = z.enum([
16
+ "INITIAL_WEIGHT",
17
+ "LIVE_BETA"
18
+ ]);
19
+ const AutoRebalanceTimeframe = z.enum([
20
+ "1h",
21
+ "4h",
22
+ "1d"
23
+ ]);
24
+ const RebalanceEventStatus = z.enum([
25
+ "SUCCESS",
26
+ "FAILED"
27
+ ]);
15
28
  const WeightMap = z.record(InstrumentId, z.number());
16
29
  const AutoRebalanceConfigBase = z.object({
17
30
  id: z.uuid(),
@@ -23,7 +36,9 @@ const AutoRebalanceConfigBase = z.object({
23
36
  updatedAt: z.iso.datetime()
24
37
  });
25
38
  const AutoRebalanceBetaState = z.discriminatedUnion("state", [
26
- z.object({ state: z.literal("PENDING") }),
39
+ z.object({
40
+ state: z.literal("PENDING")
41
+ }),
27
42
  z.object({
28
43
  state: z.literal("BASELINED"),
29
44
  // The frozen drift baseline: implied beta of the achieved leg split at entry, re-snapshotted after
@@ -45,7 +60,9 @@ const AutoRebalanceBetaState = z.discriminatedUnion("state", [
45
60
  })
46
61
  ]);
47
62
  const AutoRebalanceConfig = z.discriminatedUnion("weightSource", [
48
- AutoRebalanceConfigBase.extend({ weightSource: z.literal("INITIAL_WEIGHT") }),
63
+ AutoRebalanceConfigBase.extend({
64
+ weightSource: z.literal("INITIAL_WEIGHT")
65
+ }),
49
66
  AutoRebalanceConfigBase.extend({
50
67
  weightSource: z.literal("LIVE_BETA"),
51
68
  // Stat-arb bar timeframe selecting which realtime candle feed drives the drift comparison.
@@ -8,15 +8,17 @@ import { AutoRebalanceTimeframe, AutoRebalanceStatus } from './entities';
8
8
 
9
9
  const RebalanceManual = z.object({
10
10
  orderType: ExecutionOrderType,
11
- weightings: z.array(
12
- z.object({
13
- symbol: InstrumentId,
14
- weight: z.number().positive({ message: "Weight must be greater than 0" }).max(1, { message: "Weight must be less than 1" })
11
+ weightings: z.array(z.object({
12
+ symbol: InstrumentId,
13
+ weight: z.number().positive({
14
+ message: "Weight must be greater than 0"
15
+ }).max(1, {
16
+ message: "Weight must be less than 1"
15
17
  })
16
- ).superRefine(RefineWeightingSum).superRefine(RefineUniqueSymbols).describe("Array of weightings to rebalance the position"),
18
+ })).superRefine(RefineWeightingSum).superRefine(RefineUniqueSymbols).describe("Array of weightings to rebalance the position"),
17
19
  /**
18
- * Attribution route code (client_ids.code)
19
- */
20
+ * Attribution route code (client_ids.code)
21
+ */
20
22
  clientId: ClientIdCode
21
23
  });
22
24
  const MinimumDriftPct = UnsignedDecimalString.refine((value) => Number(value) > 0 && Number(value) <= 1, {
@@ -31,10 +33,20 @@ const LiveBetaConfig = z.object({
31
33
  minimumDriftPct: MinimumDriftPct,
32
34
  timeframe: AutoRebalanceTimeframe
33
35
  });
34
- const CreateInitialWeight = InitialWeightConfig.extend({ positionId: z.uuid() });
35
- const CreateLiveBeta = LiveBetaConfig.extend({ positionId: z.uuid() });
36
- const CreateAutoRebalanceConfig = z.discriminatedUnion("weightSource", [CreateInitialWeight, CreateLiveBeta]);
37
- const ReplaceAutoRebalanceConfig = z.discriminatedUnion("weightSource", [InitialWeightConfig, LiveBetaConfig]);
36
+ const CreateInitialWeight = InitialWeightConfig.extend({
37
+ positionId: z.uuid()
38
+ });
39
+ const CreateLiveBeta = LiveBetaConfig.extend({
40
+ positionId: z.uuid()
41
+ });
42
+ const CreateAutoRebalanceConfig = z.discriminatedUnion("weightSource", [
43
+ CreateInitialWeight,
44
+ CreateLiveBeta
45
+ ]);
46
+ const ReplaceAutoRebalanceConfig = z.discriminatedUnion("weightSource", [
47
+ InitialWeightConfig,
48
+ LiveBetaConfig
49
+ ]);
38
50
  const UpdateAutoRebalanceConfig = z.object({
39
51
  minimumDriftPct: MinimumDriftPct.optional(),
40
52
  timeframe: AutoRebalanceTimeframe.optional(),
@@ -2,14 +2,8 @@ import { z } from 'zod';
2
2
  import { normalizeArray, CursorFindParams } from '../common';
3
3
  import { AutoRebalanceStatus, AutoRebalanceWeightSource } from './entities';
4
4
 
5
- const StatusArray = z.preprocess(
6
- (arg) => normalizeArray(arg),
7
- z.array(AutoRebalanceStatus)
8
- );
9
- const WeightSourceArray = z.preprocess(
10
- (arg) => normalizeArray(arg),
11
- z.array(AutoRebalanceWeightSource)
12
- );
5
+ const StatusArray = z.preprocess((arg) => normalizeArray(arg), z.array(AutoRebalanceStatus));
6
+ const WeightSourceArray = z.preprocess((arg) => normalizeArray(arg), z.array(AutoRebalanceWeightSource));
13
7
  const AutoRebalanceListParams = CursorFindParams.extend({
14
8
  status: StatusArray.optional(),
15
9
  weightSource: WeightSourceArray.optional(),