@pear-protocol/types 1.16.0 → 1.18.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.
- package/dist/instrument/entities.d.ts +19 -0
- package/dist/instrument/entities.js +12 -1
- package/dist/instrument/responses.d.ts +10 -0
- package/dist/instrument/responses.js +1 -1
- package/dist/leverage/payloads.d.ts +2 -2
- package/dist/market/entities.d.ts +23 -2
- package/dist/market/entities.js +13 -3
- package/dist/market/index.d.ts +1 -0
- package/dist/market/index.js +1 -0
- package/dist/market/payloads.d.ts +22 -0
- package/dist/market/payloads.js +11 -0
- package/dist/market/responses.d.ts +16 -2
- package/dist/market/responses.js +5 -2
- package/dist/notification/entities.d.ts +292 -34
- package/dist/notification/entities.js +72 -15
- package/dist/notification/responses.d.ts +144 -16
- package/dist/position/entities.d.ts +227 -0
- package/dist/position/entities.js +141 -1
- package/dist/position/queries.d.ts +16 -0
- package/dist/position/queries.js +25 -1
- package/dist/position/responses.d.ts +106 -0
- package/dist/position/responses.js +5 -2
- package/dist/rebalance/entities.d.ts +48 -9
- package/dist/rebalance/entities.js +33 -4
- package/dist/rebalance/responses.d.ts +70 -18
- package/dist/statistics/queries.d.ts +5 -2
- package/dist/statistics/queries.js +12 -3
- package/dist/users/payloads.d.ts +8 -0
- package/dist/users/payloads.js +9 -1
- package/dist/users/response.d.ts +5 -0
- package/dist/users/response.js +5 -1
- package/package.json +1 -1
|
@@ -10,18 +10,19 @@ export declare const NotificationListResponse: z.ZodObject<{
|
|
|
10
10
|
STOP_LOSS_FAILED: "STOP_LOSS_FAILED";
|
|
11
11
|
TRIGGER_ORDER_FAILED: "TRIGGER_ORDER_FAILED";
|
|
12
12
|
ATTACHED_TRIGGER_DISCARDED: "ATTACHED_TRIGGER_DISCARDED";
|
|
13
|
+
AUTO_REBALANCE_EXECUTED: "AUTO_REBALANCE_EXECUTED";
|
|
14
|
+
AUTO_REBALANCE_FAILED: "AUTO_REBALANCE_FAILED";
|
|
15
|
+
AUTO_REBALANCE_PAUSED: "AUTO_REBALANCE_PAUSED";
|
|
13
16
|
}>;
|
|
14
17
|
parameters: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
lighter: "lighter";
|
|
24
|
-
}>;
|
|
18
|
+
legs: z.ZodArray<z.ZodObject<{
|
|
19
|
+
id: z.ZodString;
|
|
20
|
+
symbol: z.ZodString;
|
|
21
|
+
side: z.ZodEnum<{
|
|
22
|
+
BUY: "BUY";
|
|
23
|
+
SELL: "SELL";
|
|
24
|
+
}>;
|
|
25
|
+
}, z.core.$strip>>;
|
|
25
26
|
metric: z.ZodOptional<z.ZodEnum<{
|
|
26
27
|
price: "price";
|
|
27
28
|
notional: "notional";
|
|
@@ -41,8 +42,7 @@ export declare const NotificationListResponse: z.ZodObject<{
|
|
|
41
42
|
}>>;
|
|
42
43
|
level: z.ZodOptional<z.ZodNumber>;
|
|
43
44
|
reason: z.ZodOptional<z.ZodString>;
|
|
44
|
-
|
|
45
|
-
type: z.ZodLiteral<"stop_loss">;
|
|
45
|
+
type: z.ZodLiteral<"take_profit">;
|
|
46
46
|
triggerId: z.ZodUUID;
|
|
47
47
|
positionId: z.ZodUUID;
|
|
48
48
|
connector: z.ZodEnum<{
|
|
@@ -52,6 +52,15 @@ export declare const NotificationListResponse: z.ZodObject<{
|
|
|
52
52
|
okx: "okx";
|
|
53
53
|
lighter: "lighter";
|
|
54
54
|
}>;
|
|
55
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
56
|
+
legs: z.ZodArray<z.ZodObject<{
|
|
57
|
+
id: z.ZodString;
|
|
58
|
+
symbol: z.ZodString;
|
|
59
|
+
side: z.ZodEnum<{
|
|
60
|
+
BUY: "BUY";
|
|
61
|
+
SELL: "SELL";
|
|
62
|
+
}>;
|
|
63
|
+
}, z.core.$strip>>;
|
|
55
64
|
metric: z.ZodOptional<z.ZodEnum<{
|
|
56
65
|
price: "price";
|
|
57
66
|
notional: "notional";
|
|
@@ -71,8 +80,7 @@ export declare const NotificationListResponse: z.ZodObject<{
|
|
|
71
80
|
}>>;
|
|
72
81
|
level: z.ZodOptional<z.ZodNumber>;
|
|
73
82
|
reason: z.ZodOptional<z.ZodString>;
|
|
74
|
-
|
|
75
|
-
type: z.ZodLiteral<"trigger_order">;
|
|
83
|
+
type: z.ZodLiteral<"stop_loss">;
|
|
76
84
|
triggerId: z.ZodUUID;
|
|
77
85
|
positionId: z.ZodUUID;
|
|
78
86
|
connector: z.ZodEnum<{
|
|
@@ -82,6 +90,15 @@ export declare const NotificationListResponse: z.ZodObject<{
|
|
|
82
90
|
okx: "okx";
|
|
83
91
|
lighter: "lighter";
|
|
84
92
|
}>;
|
|
93
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
94
|
+
legs: z.ZodArray<z.ZodObject<{
|
|
95
|
+
id: z.ZodString;
|
|
96
|
+
symbol: z.ZodString;
|
|
97
|
+
side: z.ZodEnum<{
|
|
98
|
+
BUY: "BUY";
|
|
99
|
+
SELL: "SELL";
|
|
100
|
+
}>;
|
|
101
|
+
}, z.core.$strip>>;
|
|
85
102
|
metric: z.ZodOptional<z.ZodEnum<{
|
|
86
103
|
price: "price";
|
|
87
104
|
notional: "notional";
|
|
@@ -101,9 +118,9 @@ export declare const NotificationListResponse: z.ZodObject<{
|
|
|
101
118
|
}>>;
|
|
102
119
|
level: z.ZodOptional<z.ZodNumber>;
|
|
103
120
|
reason: z.ZodOptional<z.ZodString>;
|
|
104
|
-
|
|
105
|
-
type: z.ZodLiteral<"default_trigger">;
|
|
121
|
+
type: z.ZodLiteral<"trigger_order">;
|
|
106
122
|
triggerId: z.ZodUUID;
|
|
123
|
+
positionId: z.ZodUUID;
|
|
107
124
|
connector: z.ZodEnum<{
|
|
108
125
|
hyperliquid: "hyperliquid";
|
|
109
126
|
binance: "binance";
|
|
@@ -111,6 +128,15 @@ export declare const NotificationListResponse: z.ZodObject<{
|
|
|
111
128
|
okx: "okx";
|
|
112
129
|
lighter: "lighter";
|
|
113
130
|
}>;
|
|
131
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
132
|
+
legs: z.ZodArray<z.ZodObject<{
|
|
133
|
+
id: z.ZodString;
|
|
134
|
+
symbol: z.ZodString;
|
|
135
|
+
side: z.ZodEnum<{
|
|
136
|
+
BUY: "BUY";
|
|
137
|
+
SELL: "SELL";
|
|
138
|
+
}>;
|
|
139
|
+
}, z.core.$strip>>;
|
|
114
140
|
metric: z.ZodOptional<z.ZodEnum<{
|
|
115
141
|
price: "price";
|
|
116
142
|
notional: "notional";
|
|
@@ -130,7 +156,24 @@ export declare const NotificationListResponse: z.ZodObject<{
|
|
|
130
156
|
}>>;
|
|
131
157
|
level: z.ZodOptional<z.ZodNumber>;
|
|
132
158
|
reason: z.ZodOptional<z.ZodString>;
|
|
159
|
+
type: z.ZodLiteral<"default_trigger">;
|
|
160
|
+
triggerId: z.ZodUUID;
|
|
161
|
+
connector: z.ZodEnum<{
|
|
162
|
+
hyperliquid: "hyperliquid";
|
|
163
|
+
binance: "binance";
|
|
164
|
+
bybit: "bybit";
|
|
165
|
+
okx: "okx";
|
|
166
|
+
lighter: "lighter";
|
|
167
|
+
}>;
|
|
133
168
|
}, z.core.$strip>, z.ZodObject<{
|
|
169
|
+
legs: z.ZodArray<z.ZodObject<{
|
|
170
|
+
id: z.ZodString;
|
|
171
|
+
symbol: z.ZodString;
|
|
172
|
+
side: z.ZodEnum<{
|
|
173
|
+
BUY: "BUY";
|
|
174
|
+
SELL: "SELL";
|
|
175
|
+
}>;
|
|
176
|
+
}, z.core.$strip>>;
|
|
134
177
|
type: z.ZodLiteral<"attached_trigger_discarded">;
|
|
135
178
|
positionId: z.ZodUUID;
|
|
136
179
|
positionKey: z.ZodString;
|
|
@@ -170,6 +213,91 @@ export declare const NotificationListResponse: z.ZodObject<{
|
|
|
170
213
|
}>;
|
|
171
214
|
}, z.core.$strip>>;
|
|
172
215
|
activeTriggerLimit: z.ZodNumber;
|
|
216
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
217
|
+
legs: z.ZodArray<z.ZodObject<{
|
|
218
|
+
id: z.ZodString;
|
|
219
|
+
symbol: z.ZodString;
|
|
220
|
+
side: z.ZodEnum<{
|
|
221
|
+
BUY: "BUY";
|
|
222
|
+
SELL: "SELL";
|
|
223
|
+
}>;
|
|
224
|
+
currentWeight: z.ZodNumber;
|
|
225
|
+
targetWeight: z.ZodNumber;
|
|
226
|
+
}, z.core.$strip>>;
|
|
227
|
+
driftPct: z.ZodNumber;
|
|
228
|
+
notionalUsd: z.ZodNumber;
|
|
229
|
+
configId: z.ZodUUID;
|
|
230
|
+
positionId: z.ZodUUID;
|
|
231
|
+
positionKey: z.ZodString;
|
|
232
|
+
connector: z.ZodEnum<{
|
|
233
|
+
hyperliquid: "hyperliquid";
|
|
234
|
+
binance: "binance";
|
|
235
|
+
bybit: "bybit";
|
|
236
|
+
okx: "okx";
|
|
237
|
+
lighter: "lighter";
|
|
238
|
+
}>;
|
|
239
|
+
weightSource: z.ZodEnum<{
|
|
240
|
+
INITIAL_WEIGHT: "INITIAL_WEIGHT";
|
|
241
|
+
LIVE_BETA: "LIVE_BETA";
|
|
242
|
+
}>;
|
|
243
|
+
type: z.ZodLiteral<"auto_rebalance_executed">;
|
|
244
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
245
|
+
legs: z.ZodArray<z.ZodObject<{
|
|
246
|
+
id: z.ZodString;
|
|
247
|
+
symbol: z.ZodString;
|
|
248
|
+
side: z.ZodEnum<{
|
|
249
|
+
BUY: "BUY";
|
|
250
|
+
SELL: "SELL";
|
|
251
|
+
}>;
|
|
252
|
+
currentWeight: z.ZodNumber;
|
|
253
|
+
targetWeight: z.ZodNumber;
|
|
254
|
+
}, z.core.$strip>>;
|
|
255
|
+
driftPct: z.ZodNumber;
|
|
256
|
+
reason: z.ZodString;
|
|
257
|
+
configId: z.ZodUUID;
|
|
258
|
+
positionId: z.ZodUUID;
|
|
259
|
+
positionKey: z.ZodString;
|
|
260
|
+
connector: z.ZodEnum<{
|
|
261
|
+
hyperliquid: "hyperliquid";
|
|
262
|
+
binance: "binance";
|
|
263
|
+
bybit: "bybit";
|
|
264
|
+
okx: "okx";
|
|
265
|
+
lighter: "lighter";
|
|
266
|
+
}>;
|
|
267
|
+
weightSource: z.ZodEnum<{
|
|
268
|
+
INITIAL_WEIGHT: "INITIAL_WEIGHT";
|
|
269
|
+
LIVE_BETA: "LIVE_BETA";
|
|
270
|
+
}>;
|
|
271
|
+
type: z.ZodLiteral<"auto_rebalance_failed">;
|
|
272
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
273
|
+
legs: z.ZodArray<z.ZodObject<{
|
|
274
|
+
id: z.ZodString;
|
|
275
|
+
symbol: z.ZodString;
|
|
276
|
+
side: z.ZodEnum<{
|
|
277
|
+
BUY: "BUY";
|
|
278
|
+
SELL: "SELL";
|
|
279
|
+
}>;
|
|
280
|
+
}, z.core.$strip>>;
|
|
281
|
+
pausedReason: z.ZodEnum<{
|
|
282
|
+
POSITION_CHANGED: "POSITION_CHANGED";
|
|
283
|
+
REPEATED_FAILURES: "REPEATED_FAILURES";
|
|
284
|
+
INVALID_LIVE_BETA_EXPOSURE: "INVALID_LIVE_BETA_EXPOSURE";
|
|
285
|
+
}>;
|
|
286
|
+
configId: z.ZodUUID;
|
|
287
|
+
positionId: z.ZodUUID;
|
|
288
|
+
positionKey: z.ZodString;
|
|
289
|
+
connector: z.ZodEnum<{
|
|
290
|
+
hyperliquid: "hyperliquid";
|
|
291
|
+
binance: "binance";
|
|
292
|
+
bybit: "bybit";
|
|
293
|
+
okx: "okx";
|
|
294
|
+
lighter: "lighter";
|
|
295
|
+
}>;
|
|
296
|
+
weightSource: z.ZodEnum<{
|
|
297
|
+
INITIAL_WEIGHT: "INITIAL_WEIGHT";
|
|
298
|
+
LIVE_BETA: "LIVE_BETA";
|
|
299
|
+
}>;
|
|
300
|
+
type: z.ZodLiteral<"auto_rebalance_paused">;
|
|
173
301
|
}, z.core.$strip>], "type">;
|
|
174
302
|
isRead: z.ZodBoolean;
|
|
175
303
|
createdAt: z.ZodString;
|
|
@@ -91,3 +91,230 @@ export declare const Position: z.ZodObject<{
|
|
|
91
91
|
updatedAt: z.ZodString;
|
|
92
92
|
}, z.core.$strip>;
|
|
93
93
|
export type Position = z.output<typeof Position>;
|
|
94
|
+
/** Which way a closed basket's leg was held. */
|
|
95
|
+
export declare const ClosedTradeLegSide: z.ZodEnum<{
|
|
96
|
+
LONG: "LONG";
|
|
97
|
+
SHORT: "SHORT";
|
|
98
|
+
}>;
|
|
99
|
+
export type ClosedTradeLegSide = z.output<typeof ClosedTradeLegSide>;
|
|
100
|
+
/**
|
|
101
|
+
* What one asset did inside one step.
|
|
102
|
+
*
|
|
103
|
+
* A discriminated union rather than optional fields: only a priced reduction closes
|
|
104
|
+
* against a basis and books PnL, and the other two kinds must not be able to carry
|
|
105
|
+
* either. REDUCE_UNPRICED is a real third state, not a degenerate REDUCE — it is the
|
|
106
|
+
* per-step face of `undeterminedSize`, where quantity closed but no price existed to
|
|
107
|
+
* value it. Collapsing it into REDUCE would invent a basis; collapsing it into
|
|
108
|
+
* INCREASE would report a close as an add.
|
|
109
|
+
*/
|
|
110
|
+
export declare const ClosedTradeStepLeg: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
111
|
+
kind: z.ZodLiteral<"INCREASE">;
|
|
112
|
+
asset: z.ZodString;
|
|
113
|
+
side: z.ZodEnum<{
|
|
114
|
+
BUY: "BUY";
|
|
115
|
+
SELL: "SELL";
|
|
116
|
+
}>;
|
|
117
|
+
quantity: z.ZodString;
|
|
118
|
+
price: z.ZodString;
|
|
119
|
+
tradeFee: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
120
|
+
pearFee: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
121
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
122
|
+
kind: z.ZodLiteral<"REDUCE">;
|
|
123
|
+
asset: z.ZodString;
|
|
124
|
+
side: z.ZodEnum<{
|
|
125
|
+
BUY: "BUY";
|
|
126
|
+
SELL: "SELL";
|
|
127
|
+
}>;
|
|
128
|
+
quantity: z.ZodString;
|
|
129
|
+
price: z.ZodString;
|
|
130
|
+
entryBasis: z.ZodString;
|
|
131
|
+
grossPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
132
|
+
tradeFee: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
133
|
+
pearFee: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
134
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
135
|
+
kind: z.ZodLiteral<"REDUCE_UNPRICED">;
|
|
136
|
+
asset: z.ZodString;
|
|
137
|
+
side: z.ZodEnum<{
|
|
138
|
+
BUY: "BUY";
|
|
139
|
+
SELL: "SELL";
|
|
140
|
+
}>;
|
|
141
|
+
quantity: z.ZodString;
|
|
142
|
+
tradeFee: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
143
|
+
pearFee: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
144
|
+
}, z.core.$strip>], "kind">;
|
|
145
|
+
export type ClosedTradeStepLeg = z.output<typeof ClosedTradeStepLeg>;
|
|
146
|
+
/**
|
|
147
|
+
* One action taken on the position, in the order it happened: the open, each add, each
|
|
148
|
+
* reduction, and the close.
|
|
149
|
+
*
|
|
150
|
+
* Grouped by the execution that placed the fills wherever one was recorded. Exchange
|
|
151
|
+
* sync records none, so those fills fall back to grouping by identical fill time —
|
|
152
|
+
* best effort, since the legs of one basket action land on the same instant. Two
|
|
153
|
+
* genuinely separate actions sharing an instant therefore merge into one step; the
|
|
154
|
+
* `executionId` being absent is the signal that a step was grouped this way.
|
|
155
|
+
*/
|
|
156
|
+
export declare const ClosedTradeStep: z.ZodObject<{
|
|
157
|
+
executionId: z.ZodOptional<z.ZodString>;
|
|
158
|
+
at: z.ZodString;
|
|
159
|
+
grossPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
160
|
+
legs: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
161
|
+
kind: z.ZodLiteral<"INCREASE">;
|
|
162
|
+
asset: z.ZodString;
|
|
163
|
+
side: z.ZodEnum<{
|
|
164
|
+
BUY: "BUY";
|
|
165
|
+
SELL: "SELL";
|
|
166
|
+
}>;
|
|
167
|
+
quantity: z.ZodString;
|
|
168
|
+
price: z.ZodString;
|
|
169
|
+
tradeFee: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
170
|
+
pearFee: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
171
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
172
|
+
kind: z.ZodLiteral<"REDUCE">;
|
|
173
|
+
asset: z.ZodString;
|
|
174
|
+
side: z.ZodEnum<{
|
|
175
|
+
BUY: "BUY";
|
|
176
|
+
SELL: "SELL";
|
|
177
|
+
}>;
|
|
178
|
+
quantity: z.ZodString;
|
|
179
|
+
price: z.ZodString;
|
|
180
|
+
entryBasis: z.ZodString;
|
|
181
|
+
grossPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
182
|
+
tradeFee: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
183
|
+
pearFee: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
184
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
185
|
+
kind: z.ZodLiteral<"REDUCE_UNPRICED">;
|
|
186
|
+
asset: z.ZodString;
|
|
187
|
+
side: z.ZodEnum<{
|
|
188
|
+
BUY: "BUY";
|
|
189
|
+
SELL: "SELL";
|
|
190
|
+
}>;
|
|
191
|
+
quantity: z.ZodString;
|
|
192
|
+
tradeFee: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
193
|
+
pearFee: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
194
|
+
}, z.core.$strip>], "kind">>;
|
|
195
|
+
}, z.core.$strip>;
|
|
196
|
+
export type ClosedTradeStep = z.output<typeof ClosedTradeStep>;
|
|
197
|
+
/**
|
|
198
|
+
* One leg of a closed trade, with its own entry and exit economics.
|
|
199
|
+
*
|
|
200
|
+
* Both optional prices are absent rather than "0" whenever they cannot be derived:
|
|
201
|
+
* "0" is a real price, and claiming one the ledger never recorded would be a lie.
|
|
202
|
+
* Absence is the honest answer.
|
|
203
|
+
*/
|
|
204
|
+
export declare const ClosedTradeLeg: z.ZodObject<{
|
|
205
|
+
asset: z.ZodString;
|
|
206
|
+
side: z.ZodEnum<{
|
|
207
|
+
LONG: "LONG";
|
|
208
|
+
SHORT: "SHORT";
|
|
209
|
+
}>;
|
|
210
|
+
entryVwap: z.ZodOptional<z.ZodString>;
|
|
211
|
+
exitVwap: z.ZodOptional<z.ZodString>;
|
|
212
|
+
grossPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
213
|
+
netPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
214
|
+
totalFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
215
|
+
tradeFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
216
|
+
pearFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
217
|
+
funding: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
218
|
+
entryNotional: z.ZodString;
|
|
219
|
+
exitQuantity: z.ZodString;
|
|
220
|
+
undeterminedSize: z.ZodString;
|
|
221
|
+
}, z.core.$strip>;
|
|
222
|
+
export type ClosedTradeLeg = z.output<typeof ClosedTradeLeg>;
|
|
223
|
+
/**
|
|
224
|
+
* One closed position, composed server-side into the trade a trader recognises:
|
|
225
|
+
* what it earned, what it cost, and what each leg did.
|
|
226
|
+
*/
|
|
227
|
+
export declare const ClosedTrade: z.ZodObject<{
|
|
228
|
+
positionId: z.ZodUUID;
|
|
229
|
+
connector: z.ZodEnum<{
|
|
230
|
+
hyperliquid: "hyperliquid";
|
|
231
|
+
binance: "binance";
|
|
232
|
+
bybit: "bybit";
|
|
233
|
+
okx: "okx";
|
|
234
|
+
lighter: "lighter";
|
|
235
|
+
}>;
|
|
236
|
+
openedAt: z.ZodString;
|
|
237
|
+
closedAt: z.ZodString;
|
|
238
|
+
closedReason: z.ZodOptional<z.ZodEnum<{
|
|
239
|
+
NETTED: "NETTED";
|
|
240
|
+
USER: "USER";
|
|
241
|
+
LIQUIDATED: "LIQUIDATED";
|
|
242
|
+
}>>;
|
|
243
|
+
origin: z.ZodEnum<{
|
|
244
|
+
PARTIAL: "PARTIAL";
|
|
245
|
+
PEAR: "PEAR";
|
|
246
|
+
EXTERNAL: "EXTERNAL";
|
|
247
|
+
}>;
|
|
248
|
+
grossPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
249
|
+
netPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
250
|
+
totalFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
251
|
+
tradeFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
252
|
+
pearFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
253
|
+
totalFunding: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
254
|
+
entryNotional: z.ZodString;
|
|
255
|
+
exitNotional: z.ZodString;
|
|
256
|
+
exitNotionalComplete: z.ZodBoolean;
|
|
257
|
+
hasSyntheticFills: z.ZodBoolean;
|
|
258
|
+
unstableHistoricalData: z.ZodBoolean;
|
|
259
|
+
longAssets: z.ZodArray<z.ZodString>;
|
|
260
|
+
shortAssets: z.ZodArray<z.ZodString>;
|
|
261
|
+
legs: z.ZodArray<z.ZodObject<{
|
|
262
|
+
asset: z.ZodString;
|
|
263
|
+
side: z.ZodEnum<{
|
|
264
|
+
LONG: "LONG";
|
|
265
|
+
SHORT: "SHORT";
|
|
266
|
+
}>;
|
|
267
|
+
entryVwap: z.ZodOptional<z.ZodString>;
|
|
268
|
+
exitVwap: z.ZodOptional<z.ZodString>;
|
|
269
|
+
grossPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
270
|
+
netPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
271
|
+
totalFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
272
|
+
tradeFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
273
|
+
pearFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
274
|
+
funding: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
275
|
+
entryNotional: z.ZodString;
|
|
276
|
+
exitQuantity: z.ZodString;
|
|
277
|
+
undeterminedSize: z.ZodString;
|
|
278
|
+
}, z.core.$strip>>;
|
|
279
|
+
steps: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
280
|
+
executionId: z.ZodOptional<z.ZodString>;
|
|
281
|
+
at: z.ZodString;
|
|
282
|
+
grossPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
283
|
+
legs: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
284
|
+
kind: z.ZodLiteral<"INCREASE">;
|
|
285
|
+
asset: z.ZodString;
|
|
286
|
+
side: z.ZodEnum<{
|
|
287
|
+
BUY: "BUY";
|
|
288
|
+
SELL: "SELL";
|
|
289
|
+
}>;
|
|
290
|
+
quantity: z.ZodString;
|
|
291
|
+
price: z.ZodString;
|
|
292
|
+
tradeFee: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
293
|
+
pearFee: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
294
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
295
|
+
kind: z.ZodLiteral<"REDUCE">;
|
|
296
|
+
asset: z.ZodString;
|
|
297
|
+
side: z.ZodEnum<{
|
|
298
|
+
BUY: "BUY";
|
|
299
|
+
SELL: "SELL";
|
|
300
|
+
}>;
|
|
301
|
+
quantity: z.ZodString;
|
|
302
|
+
price: z.ZodString;
|
|
303
|
+
entryBasis: z.ZodString;
|
|
304
|
+
grossPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
305
|
+
tradeFee: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
306
|
+
pearFee: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
307
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
308
|
+
kind: z.ZodLiteral<"REDUCE_UNPRICED">;
|
|
309
|
+
asset: z.ZodString;
|
|
310
|
+
side: z.ZodEnum<{
|
|
311
|
+
BUY: "BUY";
|
|
312
|
+
SELL: "SELL";
|
|
313
|
+
}>;
|
|
314
|
+
quantity: z.ZodString;
|
|
315
|
+
tradeFee: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
316
|
+
pearFee: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
|
|
317
|
+
}, z.core.$strip>], "kind">>;
|
|
318
|
+
}, z.core.$strip>>>;
|
|
319
|
+
}, z.core.$strip>;
|
|
320
|
+
export type ClosedTrade = z.output<typeof ClosedTrade>;
|
|
@@ -60,5 +60,145 @@ const Position = z.object({
|
|
|
60
60
|
createdAt: z.string(),
|
|
61
61
|
updatedAt: z.string()
|
|
62
62
|
});
|
|
63
|
+
const ClosedTradeLegSide = z.enum(["LONG", "SHORT"]);
|
|
64
|
+
const ClosedTradeStepLeg = z.discriminatedUnion("kind", [
|
|
65
|
+
z.object({
|
|
66
|
+
kind: z.literal("INCREASE"),
|
|
67
|
+
asset: InstrumentId,
|
|
68
|
+
side: z.enum(["BUY", "SELL"]),
|
|
69
|
+
quantity: UnsignedDecimalString,
|
|
70
|
+
/** "0" on an unpriceable synthetic — the ledger recorded no price to report. */
|
|
71
|
+
price: UnsignedDecimalString,
|
|
72
|
+
/** The venue's charge and Pear's, kept apart. Signed, so a maker rebate reads negative. */
|
|
73
|
+
tradeFee: SignedDecimalString,
|
|
74
|
+
pearFee: SignedDecimalString
|
|
75
|
+
}),
|
|
76
|
+
z.object({
|
|
77
|
+
kind: z.literal("REDUCE"),
|
|
78
|
+
asset: InstrumentId,
|
|
79
|
+
side: z.enum(["BUY", "SELL"]),
|
|
80
|
+
/** The quantity that actually closed. On a flip this is less than the fill's own size. */
|
|
81
|
+
quantity: UnsignedDecimalString,
|
|
82
|
+
price: UnsignedDecimalString,
|
|
83
|
+
/** The running cost basis this reduction closed against, as the PnL walk held it. */
|
|
84
|
+
entryBasis: UnsignedDecimalString,
|
|
85
|
+
/** (price − entryBasis) × quantity, signed by direction. Booked by the walk, not re-derived. */
|
|
86
|
+
grossPnl: SignedDecimalString,
|
|
87
|
+
tradeFee: SignedDecimalString,
|
|
88
|
+
pearFee: SignedDecimalString
|
|
89
|
+
}),
|
|
90
|
+
z.object({
|
|
91
|
+
kind: z.literal("REDUCE_UNPRICED"),
|
|
92
|
+
asset: InstrumentId,
|
|
93
|
+
side: z.enum(["BUY", "SELL"]),
|
|
94
|
+
quantity: UnsignedDecimalString,
|
|
95
|
+
tradeFee: SignedDecimalString,
|
|
96
|
+
pearFee: SignedDecimalString
|
|
97
|
+
})
|
|
98
|
+
]);
|
|
99
|
+
const ClosedTradeStep = z.object({
|
|
100
|
+
/**
|
|
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
|
+
*/
|
|
104
|
+
executionId: z.string().optional(),
|
|
105
|
+
/** When the step's fills landed. */
|
|
106
|
+
at: z.string(),
|
|
107
|
+
/** Realized PnL this step booked: the sum of its reductions. "+0" for a pure increase. */
|
|
108
|
+
grossPnl: SignedDecimalString,
|
|
109
|
+
legs: z.array(ClosedTradeStepLeg)
|
|
110
|
+
});
|
|
111
|
+
const ClosedTradeLeg = z.object({
|
|
112
|
+
asset: InstrumentId,
|
|
113
|
+
side: ClosedTradeLegSide,
|
|
114
|
+
/** Size-weighted average price the leg opened at. Absent with no priced entry. */
|
|
115
|
+
entryVwap: UnsignedDecimalString.optional(),
|
|
116
|
+
/** Size-weighted average price the leg closed at. Absent when nothing closed at a known price. */
|
|
117
|
+
exitVwap: UnsignedDecimalString.optional(),
|
|
118
|
+
/** Realized PnL before fees. */
|
|
119
|
+
grossPnl: SignedDecimalString,
|
|
120
|
+
/** Realized PnL after fees. */
|
|
121
|
+
netPnl: SignedDecimalString,
|
|
122
|
+
/** Signed: a venue maker rebate makes a fee negative. */
|
|
123
|
+
totalFees: SignedDecimalString,
|
|
124
|
+
tradeFees: SignedDecimalString,
|
|
125
|
+
pearFees: SignedDecimalString,
|
|
126
|
+
/**
|
|
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
|
+
*/
|
|
133
|
+
funding: SignedDecimalString,
|
|
134
|
+
entryNotional: UnsignedDecimalString,
|
|
135
|
+
/**
|
|
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
|
+
*/
|
|
140
|
+
exitQuantity: UnsignedDecimalString,
|
|
141
|
+
/**
|
|
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
|
+
*/
|
|
146
|
+
undeterminedSize: UnsignedDecimalString
|
|
147
|
+
});
|
|
148
|
+
const ClosedTrade = z.object({
|
|
149
|
+
positionId: z.uuid(),
|
|
150
|
+
connector: Connector,
|
|
151
|
+
/** When the position opened. */
|
|
152
|
+
openedAt: z.string(),
|
|
153
|
+
/** When the position closed. Falls back to the last update for rows that never recorded a close. */
|
|
154
|
+
closedAt: z.string(),
|
|
155
|
+
closedReason: PositionClosedReason.optional(),
|
|
156
|
+
origin: PositionOrigin,
|
|
157
|
+
grossPnl: SignedDecimalString,
|
|
158
|
+
netPnl: SignedDecimalString,
|
|
159
|
+
totalFees: SignedDecimalString,
|
|
160
|
+
tradeFees: SignedDecimalString,
|
|
161
|
+
pearFees: SignedDecimalString,
|
|
162
|
+
/**
|
|
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
|
+
*/
|
|
171
|
+
totalFunding: SignedDecimalString,
|
|
172
|
+
entryNotional: UnsignedDecimalString,
|
|
173
|
+
/**
|
|
174
|
+
* Proceeds of the priced closes. Understates whenever part of the position closed
|
|
175
|
+
* unpriceably — exitNotionalComplete says whether that happened.
|
|
176
|
+
*/
|
|
177
|
+
exitNotional: UnsignedDecimalString,
|
|
178
|
+
/**
|
|
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
|
+
*/
|
|
185
|
+
exitNotionalComplete: z.boolean(),
|
|
186
|
+
/** Whether any fill on the position was a synthetic bridge fill (gap/gone reconstruction). */
|
|
187
|
+
hasSyntheticFills: z.boolean(),
|
|
188
|
+
/** Whether a backfilled fill made this position's historical metrics unreliable. */
|
|
189
|
+
unstableHistoricalData: z.boolean(),
|
|
190
|
+
longAssets: z.array(InstrumentId),
|
|
191
|
+
shortAssets: z.array(InstrumentId),
|
|
192
|
+
legs: z.array(ClosedTradeLeg),
|
|
193
|
+
/**
|
|
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
|
+
*/
|
|
201
|
+
steps: z.array(ClosedTradeStep).optional()
|
|
202
|
+
});
|
|
63
203
|
|
|
64
|
-
export { Position, PositionClosedReason, PositionEntryPrices, PositionExposure, PositionInitialExposureUSD, PositionOrigin, PositionStatus, PositionTotalFundingPayment };
|
|
204
|
+
export { ClosedTrade, ClosedTradeLeg, ClosedTradeLegSide, ClosedTradeStep, ClosedTradeStepLeg, Position, PositionClosedReason, PositionEntryPrices, PositionExposure, PositionInitialExposureUSD, PositionOrigin, PositionStatus, PositionTotalFundingPayment };
|
|
@@ -17,3 +17,19 @@ export declare const PositionListParams: z.ZodObject<{
|
|
|
17
17
|
}, z.core.$strip>;
|
|
18
18
|
export type PositionListParamsInput = z.input<typeof PositionListParams>;
|
|
19
19
|
export type PositionListParams = z.output<typeof PositionListParams>;
|
|
20
|
+
/**
|
|
21
|
+
* Closed-trade history page.
|
|
22
|
+
*
|
|
23
|
+
* Ordering is fixed at newest-closed-first, so there is no `orderBy`: one order keeps
|
|
24
|
+
* the cursor and the supporting index single-purpose. The connector comes from the
|
|
25
|
+
* trade-account guard rather than the query.
|
|
26
|
+
*/
|
|
27
|
+
export declare const ClosedPositionListParams: z.ZodObject<{
|
|
28
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
29
|
+
limit: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<number>>>;
|
|
30
|
+
startDate: z.ZodOptional<z.ZodString>;
|
|
31
|
+
endDate: z.ZodOptional<z.ZodString>;
|
|
32
|
+
includeSteps: z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodCodec<z.ZodString, z.ZodBoolean>]>>>;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
export type ClosedPositionListParamsInput = z.input<typeof ClosedPositionListParams>;
|
|
35
|
+
export type ClosedPositionListParams = z.output<typeof ClosedPositionListParams>;
|
package/dist/position/queries.js
CHANGED
|
@@ -24,5 +24,29 @@ const PositionListParams = CursorFindParams.extend({
|
|
|
24
24
|
*/
|
|
25
25
|
orderBy: OrderBy.default("-createdAt")
|
|
26
26
|
});
|
|
27
|
+
const ClosedPositionListParams = CursorFindParams.extend({
|
|
28
|
+
/**
|
|
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
|
+
limit: z.coerce.number().int().positive().max(200).optional().default(20),
|
|
33
|
+
/**
|
|
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
|
+
*/
|
|
38
|
+
startDate: z.string().optional(),
|
|
39
|
+
endDate: z.string().optional(),
|
|
40
|
+
/**
|
|
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)
|
|
50
|
+
});
|
|
27
51
|
|
|
28
|
-
export { PositionListParams };
|
|
52
|
+
export { ClosedPositionListParams, PositionListParams };
|