@pear-protocol/types 0.0.17 → 0.0.19

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.
@@ -2,238 +2,134 @@ import { z } from 'zod';
2
2
  import { Side } from '../../common/schema';
3
3
  import { InstrumentId } from '../../instrument';
4
4
  import { PriceSource } from '../../price';
5
+ import { MetricTrack } from '../common';
5
6
 
6
- const TriggerDirection = z.enum(["ABOVE", "BELOW"]);
7
- const TriggerConditionRatioV1 = z.object({
8
- /**
9
- * Condition type
10
- */
11
- type: z.literal("ratio_v1"),
12
- /**
13
- * Condition data
14
- */
7
+ const Ratio = z.object({
8
+ type: z.literal("ratio"),
15
9
  data: z.object({
16
- /**
17
- * Price source
18
- */
19
10
  priceSource: PriceSource,
20
- /**
21
- * Numerator symbol
22
- */
23
11
  symbol_a: InstrumentId,
24
- /**
25
- * Denominator symbol
26
- */
27
12
  symbol_b: InstrumentId,
28
- /**
29
- * Trigger direction
30
- */
31
- direction: TriggerDirection,
32
- /**
33
- * Price ratio threshold
34
- */
13
+ track: MetricTrack,
35
14
  threshold: z.number()
36
15
  })
37
16
  });
38
- const TriggerConditionPriceV1 = z.object({
39
- /**
40
- * Condition type
41
- */
42
- type: z.literal("price_v1"),
43
- /**
44
- * Condition data
45
- */
17
+ const Price = z.object({
18
+ type: z.literal("price"),
46
19
  data: z.object({
47
- /**
48
- * Price source
49
- */
50
20
  priceSource: PriceSource,
51
- /**
52
- * Asset symbol
53
- */
54
21
  symbol: InstrumentId,
55
- /**
56
- * Trigger direction
57
- */
58
- direction: TriggerDirection,
59
- /**
60
- * Asset price threshold
61
- */
22
+ track: MetricTrack,
62
23
  threshold: z.number()
63
24
  })
64
25
  });
65
- const TriggerConditionIndexV1 = z.object({
66
- /**
67
- * Condition type
68
- */
69
- type: z.literal("index_v1"),
70
- /**
71
- * Condition data
72
- */
26
+ const WeightedRatio = z.object({
27
+ type: z.literal("weighted_ratio"),
73
28
  data: z.object({
74
- /**
75
- * Price source
76
- */
77
29
  priceSource: PriceSource,
78
- /**
79
- * Basket of assets
80
- */
81
30
  basket: z.array(
82
31
  z.object({
83
- /**
84
- * Asset symbol
85
- */
86
32
  symbol: InstrumentId,
87
- /**
88
- * Weight (sum of weights should be 1)
89
- */
33
+ side: Side,
90
34
  weight: z.number()
91
35
  })
92
36
  ),
93
- /**
94
- * Trigger direction
95
- */
96
- direction: TriggerDirection,
97
- /**
98
- * Index value threshold
99
- */
37
+ track: MetricTrack,
100
38
  threshold: z.number()
101
39
  })
102
40
  });
103
- const TriggerConditionWeightedRatioV1 = z.object({
104
- /**
105
- * Condition type
106
- */
107
- type: z.literal("weighted_ratio_v1"),
108
- /**
109
- * Condition data
110
- */
41
+ const Notional = z.object({
42
+ type: z.literal("notional"),
111
43
  data: z.object({
112
- /**
113
- * Price source
114
- */
115
44
  priceSource: PriceSource,
116
- /**
117
- * Basket of assets (needs at least one BUY and one SELL)
118
- */
119
- basket: z.array(
120
- z.object({
121
- /**
122
- * Asset symbol
123
- */
124
- symbol: InstrumentId,
125
- /**
126
- * Side
127
- */
128
- side: Side,
129
- /**
130
- * Weight (sum of weights should be 1)
131
- */
132
- weight: z.number()
133
- })
134
- ),
135
- /**
136
- * Trigger direction
137
- */
138
- direction: TriggerDirection,
139
- /**
140
- * Weighted ratio threshold
141
- */
45
+ track: MetricTrack,
142
46
  threshold: z.number()
143
47
  })
144
48
  });
145
- const TriggerConditionPositionValueV1 = z.object({
146
- /**
147
- * Condition type
148
- */
149
- type: z.literal("position_value_v1"),
150
- /**
151
- * Condition data
152
- */
49
+ const Upnl = z.object({
50
+ type: z.literal("upnl"),
153
51
  data: z.object({
154
- /**
155
- * Price source
156
- */
157
52
  priceSource: PriceSource,
158
- /**
159
- * Trigger direction
160
- */
161
- direction: TriggerDirection,
162
- /**
163
- * Position USD value threshold
164
- */
53
+ track: MetricTrack,
165
54
  threshold: z.number()
166
55
  })
167
56
  });
168
- const TriggerConditionPositionUPnLValueV1 = z.object({
169
- /**
170
- * Condition type
171
- */
172
- type: z.literal("position_upnl_value_v1"),
173
- /**
174
- * Condition data
175
- */
57
+ const UpnlBps = z.object({
58
+ type: z.literal("upnl_bps"),
176
59
  data: z.object({
177
- /**
178
- * Price source
179
- */
180
60
  priceSource: PriceSource,
181
- /**
182
- * Trigger direction
183
- */
184
- direction: TriggerDirection,
185
- /**
186
- * PnL value in USD threshold
187
- */
61
+ track: MetricTrack,
188
62
  threshold: z.number()
189
63
  })
190
64
  });
191
- const TriggerConditionPositionUPnLPercentageV1 = z.object({
192
- /**
193
- * Condition type
194
- */
195
- type: z.literal("position_upnl_percentage_v1"),
196
- /**
197
- * Condition data
198
- */
65
+ const RatioTrailing = z.object({
66
+ type: z.literal("ratio_trailing"),
199
67
  data: z.object({
200
- /**
201
- * Price source
202
- */
203
68
  priceSource: PriceSource,
204
- /**
205
- * Trigger direction
206
- */
207
- direction: TriggerDirection,
208
- /**
209
- * PnL value in basis points threshold
210
- */
211
- threshold_bps: z.number()
69
+ symbol_a: InstrumentId,
70
+ symbol_b: InstrumentId
212
71
  })
213
72
  });
214
- const TriggerConditionOpen = z.discriminatedUnion("type", [
215
- TriggerConditionRatioV1,
216
- TriggerConditionPriceV1,
217
- TriggerConditionIndexV1,
218
- TriggerConditionWeightedRatioV1
219
- ]);
73
+ const PriceTrailing = z.object({
74
+ type: z.literal("price_trailing"),
75
+ data: z.object({
76
+ priceSource: PriceSource,
77
+ symbol: InstrumentId
78
+ })
79
+ });
80
+ const WeightedRatioTrailing = z.object({
81
+ type: z.literal("weighted_ratio_trailing"),
82
+ data: z.object({
83
+ priceSource: PriceSource,
84
+ basket: z.array(
85
+ z.object({
86
+ symbol: InstrumentId,
87
+ side: Side,
88
+ weight: z.number()
89
+ })
90
+ )
91
+ })
92
+ });
93
+ const NotionalTrailing = z.object({
94
+ type: z.literal("notional_trailing"),
95
+ data: z.object({
96
+ priceSource: PriceSource
97
+ })
98
+ });
99
+ const UpnlTrailing = z.object({
100
+ type: z.literal("upnl_trailing"),
101
+ data: z.object({
102
+ priceSource: PriceSource
103
+ })
104
+ });
105
+ const UpnlBpsTrailing = z.object({
106
+ type: z.literal("upnl_bps_trailing"),
107
+ data: z.object({
108
+ priceSource: PriceSource
109
+ })
110
+ });
111
+ const TriggerConditionOpen = z.discriminatedUnion("type", [Ratio, Price, WeightedRatio]);
220
112
  const TriggerConditionAdjust = z.discriminatedUnion("type", [
221
- TriggerConditionRatioV1,
222
- TriggerConditionPriceV1,
223
- TriggerConditionIndexV1,
224
- TriggerConditionWeightedRatioV1,
225
- TriggerConditionPositionValueV1,
226
- TriggerConditionPositionUPnLValueV1,
227
- TriggerConditionPositionUPnLPercentageV1
113
+ Ratio,
114
+ Price,
115
+ WeightedRatio,
116
+ Notional,
117
+ Upnl,
118
+ UpnlBps
228
119
  ]);
229
120
  const TriggerConditionClose = z.discriminatedUnion("type", [
230
- TriggerConditionRatioV1,
231
- TriggerConditionPriceV1,
232
- TriggerConditionIndexV1,
233
- TriggerConditionWeightedRatioV1,
234
- TriggerConditionPositionValueV1,
235
- TriggerConditionPositionUPnLValueV1,
236
- TriggerConditionPositionUPnLPercentageV1
121
+ Ratio,
122
+ Price,
123
+ WeightedRatio,
124
+ Notional,
125
+ Upnl,
126
+ UpnlBps,
127
+ RatioTrailing,
128
+ PriceTrailing,
129
+ WeightedRatioTrailing,
130
+ NotionalTrailing,
131
+ UpnlTrailing,
132
+ UpnlBpsTrailing
237
133
  ]);
238
134
 
239
135
  export { TriggerConditionAdjust, TriggerConditionClose, TriggerConditionOpen };