@pear-protocol/types 2.20.0 → 2.22.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/bundle.d.ts +1 -0
- package/dist/fee/entities.d.ts +1 -0
- package/dist/fee/responses.d.ts +26 -0
- package/dist/index.js +7355 -3
- package/dist/rewards/entities.d.ts +28 -0
- package/dist/rewards/payloads.d.ts +7 -0
- package/dist/rewards/responses.d.ts +73 -0
- package/dist/statistics/queries.d.ts +25 -0
- package/dist/statistics/responses.d.ts +120 -0
- package/dist/sync/responses.d.ts +1 -0
- package/dist/users/entities.d.ts +4 -0
- package/dist/users/response.d.ts +3 -0
- package/package.json +4 -3
- package/dist/auth/api-keys.js +0 -44
- package/dist/auth/entities.js +0 -25
- package/dist/auth/index.js +0 -4
- package/dist/auth/payloads.js +0 -84
- package/dist/auth/response.js +0 -82
- package/dist/baskets/recommended/entities.js +0 -22
- package/dist/baskets/recommended/index.js +0 -2
- package/dist/baskets/recommended/responses.js +0 -8
- package/dist/baskets/saved/entities.js +0 -23
- package/dist/baskets/saved/payloads.js +0 -18
- package/dist/baskets/saved/responses.js +0 -14
- package/dist/bundle.js +0 -36
- package/dist/common/address.js +0 -5
- package/dist/common/array.js +0 -17
- package/dist/common/client-id.js +0 -5
- package/dist/common/hex-string.js +0 -5
- package/dist/common/index.js +0 -4
- package/dist/common/refinement.js +0 -64
- package/dist/common/request.js +0 -24
- package/dist/common/response.js +0 -28
- package/dist/common/schema.js +0 -18
- package/dist/common/trade-legs.js +0 -50
- package/dist/connector/index.js +0 -12
- package/dist/copy/entities.js +0 -151
- package/dist/copy/index.js +0 -5
- package/dist/copy/payloads.js +0 -8
- package/dist/copy/performance.js +0 -63
- package/dist/copy/queries.js +0 -20
- package/dist/copy/responses.js +0 -89
- package/dist/execution/entities.js +0 -196
- package/dist/execution/index.js +0 -3
- package/dist/execution/queries.js +0 -18
- package/dist/execution/responses.js +0 -12
- package/dist/fee/entities.js +0 -34
- package/dist/fee/index.js +0 -3
- package/dist/fee/queries.js +0 -12
- package/dist/fee/responses.js +0 -29
- package/dist/fill/entities.js +0 -82
- package/dist/fill/index.js +0 -3
- package/dist/fill/queries.js +0 -14
- package/dist/fill/responses.js +0 -23
- package/dist/funding/entities.js +0 -16
- package/dist/funding/index.js +0 -3
- package/dist/funding/queries.js +0 -8
- package/dist/funding/responses.js +0 -11
- package/dist/instrument/entities.js +0 -102
- package/dist/instrument/index.js +0 -3
- package/dist/instrument/queries.js +0 -15
- package/dist/instrument/responses.js +0 -20
- package/dist/instrument-precision/index.js +0 -56
- package/dist/ladder/entities.js +0 -24
- package/dist/ladder/index.js +0 -4
- package/dist/ladder/payloads.js +0 -96
- package/dist/ladder/queries.js +0 -12
- package/dist/ladder/responses.js +0 -18
- package/dist/leverage/index.js +0 -2
- package/dist/leverage/payloads.js +0 -14
- package/dist/leverage/response.js +0 -5
- package/dist/margin/index.js +0 -2
- package/dist/margin/payloads.js +0 -20
- package/dist/margin/response.js +0 -11
- package/dist/market/entities.js +0 -52
- package/dist/market/index.js +0 -4
- package/dist/market/payloads.js +0 -11
- package/dist/market/queries.js +0 -19
- package/dist/market/responses.js +0 -18
- package/dist/misc/index.js +0 -2
- package/dist/misc/payloads.js +0 -99
- package/dist/misc/responses.js +0 -85
- package/dist/notification/entities.js +0 -274
- package/dist/notification/index.js +0 -4
- package/dist/notification/payloads.js +0 -15
- package/dist/notification/queries.js +0 -29
- package/dist/notification/responses.js +0 -20
- package/dist/order/entities.js +0 -81
- package/dist/order/index.js +0 -1
- package/dist/portfolio/entities.js +0 -77
- package/dist/portfolio/index.js +0 -3
- package/dist/portfolio/queries.js +0 -34
- package/dist/portfolio/responses.js +0 -33
- package/dist/position/entities.js +0 -433
- package/dist/position/index.js +0 -3
- package/dist/position/queries.js +0 -109
- package/dist/position/responses.js +0 -41
- package/dist/price/entities.js +0 -10
- package/dist/price/index.js +0 -3
- package/dist/price/queries.js +0 -8
- package/dist/price/responses.js +0 -15
- package/dist/realtime/channels.js +0 -16
- package/dist/realtime/frames.js +0 -140
- package/dist/realtime/index.js +0 -6
- package/dist/realtime/messages.js +0 -118
- package/dist/realtime/public-events.js +0 -92
- package/dist/realtime/user-events.js +0 -32
- package/dist/realtime/vault-events.js +0 -42
- package/dist/rebalance/entities.js +0 -86
- package/dist/rebalance/index.js +0 -4
- package/dist/rebalance/payloads.js +0 -56
- package/dist/rebalance/queries.js +0 -14
- package/dist/rebalance/responses.js +0 -41
- package/dist/schedule/entities.js +0 -239
- package/dist/schedule/index.js +0 -5
- package/dist/schedule/payloads.js +0 -85
- package/dist/schedule/queries.js +0 -30
- package/dist/schedule/randomization.js +0 -15
- package/dist/schedule/responses.js +0 -22
- package/dist/schedule/twap-config.js +0 -29
- package/dist/statistics/entities.js +0 -105
- package/dist/statistics/index.js +0 -3
- package/dist/statistics/queries.js +0 -93
- package/dist/statistics/responses.js +0 -17
- package/dist/sync/index.js +0 -2
- package/dist/sync/payloads.js +0 -136
- package/dist/sync/responses.js +0 -26
- package/dist/tca/entities.js +0 -9
- package/dist/tca/index.js +0 -3
- package/dist/tca/queries.js +0 -14
- package/dist/tca/responses.js +0 -126
- package/dist/trade/entities.js +0 -101
- package/dist/trade/index.js +0 -4
- package/dist/trade/payloads.js +0 -84
- package/dist/trade/queries.js +0 -9
- package/dist/trade/responses.js +0 -25
- package/dist/trade-accounts/entities.js +0 -61
- package/dist/trade-accounts/index.js +0 -4
- package/dist/trade-accounts/payloads.js +0 -132
- package/dist/trade-accounts/queries.js +0 -7
- package/dist/trade-accounts/response.js +0 -79
- package/dist/traders/index.js +0 -2
- package/dist/traders/performance.js +0 -21
- package/dist/traders/public.js +0 -192
- package/dist/trigger/common/index.js +0 -39
- package/dist/trigger/entities/conditions.js +0 -174
- package/dist/trigger/entities/index.js +0 -257
- package/dist/trigger/index.js +0 -9
- package/dist/trigger/oracle.js +0 -22
- package/dist/trigger/payloads/conditions.js +0 -213
- package/dist/trigger/payloads/config.js +0 -3
- package/dist/trigger/payloads/index.js +0 -173
- package/dist/trigger/queries.js +0 -16
- package/dist/trigger/refinement/index.js +0 -2
- package/dist/trigger/refinement/static.refinement.js +0 -50
- package/dist/trigger/refinement/trailing.refinement.js +0 -83
- package/dist/trigger/responses.js +0 -18
- package/dist/triggers/entities.js +0 -27
- package/dist/triggers/index.js +0 -3
- package/dist/triggers/queries.js +0 -10
- package/dist/triggers/responses.js +0 -9
- package/dist/users/entities.js +0 -45
- package/dist/users/index.js +0 -4
- package/dist/users/payloads.js +0 -33
- package/dist/users/queries.js +0 -8
- package/dist/users/response.js +0 -27
- package/dist/vaults/entities.js +0 -96
- package/dist/vaults/index.js +0 -4
- package/dist/vaults/payloads.js +0 -65
- package/dist/vaults/queries.js +0 -66
- package/dist/vaults/responses.js +0 -368
- /package/dist/{baskets/saved/index.js → rewards/index.d.ts} +0 -0
|
@@ -1,433 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { SignedDecimalString, UnsignedDecimalString } from '../common/schema';
|
|
3
|
-
import { Connector } from '../connector';
|
|
4
|
-
import { InstrumentId } from '../instrument';
|
|
5
|
-
|
|
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
|
-
]);
|
|
20
|
-
const PositionExposure = z.record(InstrumentId, SignedDecimalString);
|
|
21
|
-
const PositionInitialExposureUSD = z.record(InstrumentId, SignedDecimalString);
|
|
22
|
-
const PositionTotalFundingPayment = z.record(InstrumentId, SignedDecimalString);
|
|
23
|
-
const PositionEntryPrices = z.record(InstrumentId, UnsignedDecimalString);
|
|
24
|
-
const Position = z.object({
|
|
25
|
-
/**
|
|
26
|
-
* Position UUID
|
|
27
|
-
*/
|
|
28
|
-
id: z.uuid(),
|
|
29
|
-
/**
|
|
30
|
-
* Trade account UUID
|
|
31
|
-
*/
|
|
32
|
-
tradeAccountId: z.uuid(),
|
|
33
|
-
/**
|
|
34
|
-
* Connector
|
|
35
|
-
*/
|
|
36
|
-
connector: Connector,
|
|
37
|
-
/**
|
|
38
|
-
* Position status
|
|
39
|
-
*/
|
|
40
|
-
status: PositionStatus,
|
|
41
|
-
/**
|
|
42
|
-
* Closed reason
|
|
43
|
-
*/
|
|
44
|
-
closedReason: PositionClosedReason.nullable().optional(),
|
|
45
|
-
origin: PositionOrigin,
|
|
46
|
-
/** The subscription that opened this position, retained after copying stops. */
|
|
47
|
-
copySubscriptionId: z.uuid().optional(),
|
|
48
|
-
/** Whether the existing copy eligibility rules still allow this position to follow its leader. */
|
|
49
|
-
isCopying: z.boolean().optional(),
|
|
50
|
-
/**
|
|
51
|
-
* Position exposure
|
|
52
|
-
*/
|
|
53
|
-
exposure: PositionExposure,
|
|
54
|
-
/**
|
|
55
|
-
* Whether a backfilled fill invalidated historical metrics derived from this position.
|
|
56
|
-
*/
|
|
57
|
-
unstableHistoricalData: z.boolean(),
|
|
58
|
-
totalFundingPayment: PositionTotalFundingPayment,
|
|
59
|
-
/**
|
|
60
|
-
* Closed at timestamp
|
|
61
|
-
*/
|
|
62
|
-
closedAt: z.string().nullable().optional(),
|
|
63
|
-
/**
|
|
64
|
-
* The exposure expressed in USD at the time
|
|
65
|
-
* the position was opened. It does not change
|
|
66
|
-
* on adjustments, and is only used for UI purposes.
|
|
67
|
-
*/
|
|
68
|
-
initialExposureUSD: PositionInitialExposureUSD,
|
|
69
|
-
/**
|
|
70
|
-
* Per-instrument entry (cost-basis) price, derived from the fills ledger. Unlike
|
|
71
|
-
* initialExposureUSD, this DOES account for adjustments — it is the live weighted-average
|
|
72
|
-
* entry price of the current exposure.
|
|
73
|
-
*/
|
|
74
|
-
entryPrices: PositionEntryPrices,
|
|
75
|
-
createdAt: z.string(),
|
|
76
|
-
updatedAt: z.string()
|
|
77
|
-
});
|
|
78
|
-
const ClosedPositionLegSide = z.enum([
|
|
79
|
-
"LONG",
|
|
80
|
-
"SHORT"
|
|
81
|
-
]);
|
|
82
|
-
const PositionStepLeg = z.discriminatedUnion("kind", [
|
|
83
|
-
z.object({
|
|
84
|
-
kind: z.literal("INCREASE"),
|
|
85
|
-
asset: InstrumentId,
|
|
86
|
-
side: z.enum([
|
|
87
|
-
"BUY",
|
|
88
|
-
"SELL"
|
|
89
|
-
]),
|
|
90
|
-
quantity: UnsignedDecimalString,
|
|
91
|
-
/** "0" on an unpriceable synthetic — the ledger recorded no price to report. */
|
|
92
|
-
price: UnsignedDecimalString,
|
|
93
|
-
/** The venue's charge and Pear's, kept apart. Signed, so a maker rebate reads negative. */
|
|
94
|
-
tradeFee: SignedDecimalString,
|
|
95
|
-
pearFee: SignedDecimalString
|
|
96
|
-
}),
|
|
97
|
-
z.object({
|
|
98
|
-
kind: z.literal("REDUCE"),
|
|
99
|
-
asset: InstrumentId,
|
|
100
|
-
side: z.enum([
|
|
101
|
-
"BUY",
|
|
102
|
-
"SELL"
|
|
103
|
-
]),
|
|
104
|
-
/** The quantity that actually closed. On a flip this is less than the fill's own size. */
|
|
105
|
-
quantity: UnsignedDecimalString,
|
|
106
|
-
price: UnsignedDecimalString,
|
|
107
|
-
/** The running cost basis this reduction closed against, as the PnL walk held it. */
|
|
108
|
-
entryBasis: UnsignedDecimalString,
|
|
109
|
-
/** (price − entryBasis) × quantity, signed by direction. Booked by the walk, not re-derived. */
|
|
110
|
-
grossPnl: SignedDecimalString,
|
|
111
|
-
tradeFee: SignedDecimalString,
|
|
112
|
-
pearFee: SignedDecimalString
|
|
113
|
-
}),
|
|
114
|
-
z.object({
|
|
115
|
-
kind: z.literal("REDUCE_UNPRICED"),
|
|
116
|
-
asset: InstrumentId,
|
|
117
|
-
side: z.enum([
|
|
118
|
-
"BUY",
|
|
119
|
-
"SELL"
|
|
120
|
-
]),
|
|
121
|
-
quantity: UnsignedDecimalString,
|
|
122
|
-
tradeFee: SignedDecimalString,
|
|
123
|
-
pearFee: SignedDecimalString
|
|
124
|
-
})
|
|
125
|
-
]);
|
|
126
|
-
const PositionStep = z.object({
|
|
127
|
-
/**
|
|
128
|
-
* The execution that placed these fills. Absent when the fills recorded none, in
|
|
129
|
-
* which case the step was grouped by fill time and is best effort.
|
|
130
|
-
*/
|
|
131
|
-
executionId: z.string().optional(),
|
|
132
|
-
/** When the step's fills landed. */
|
|
133
|
-
at: z.string(),
|
|
134
|
-
/** Realized PnL this step booked: the sum of its reductions. "+0" for a pure increase. */
|
|
135
|
-
grossPnl: SignedDecimalString,
|
|
136
|
-
legs: z.array(PositionStepLeg)
|
|
137
|
-
});
|
|
138
|
-
const ClosedPositionLeg = z.object({
|
|
139
|
-
asset: InstrumentId,
|
|
140
|
-
side: ClosedPositionLegSide,
|
|
141
|
-
/** Size-weighted average price the leg opened at. Absent with no priced entry. */
|
|
142
|
-
entryVwap: UnsignedDecimalString.optional(),
|
|
143
|
-
/** Size-weighted average price the leg closed at. Absent when nothing closed at a known price. */
|
|
144
|
-
exitVwap: UnsignedDecimalString.optional(),
|
|
145
|
-
/** Realized PnL before fees. */
|
|
146
|
-
grossPnl: SignedDecimalString,
|
|
147
|
-
/** Realized PnL after fees. */
|
|
148
|
-
netPnl: SignedDecimalString,
|
|
149
|
-
/** Signed: a venue maker rebate makes a fee negative. */
|
|
150
|
-
totalFees: SignedDecimalString,
|
|
151
|
-
tradeFees: SignedDecimalString,
|
|
152
|
-
pearFees: SignedDecimalString,
|
|
153
|
-
/**
|
|
154
|
-
* Funding attributed to this leg over the position's life (signed; negative = net paid).
|
|
155
|
-
*
|
|
156
|
-
* Reported beside netPnl, never folded into it: netPnl carries the same fills-only
|
|
157
|
-
* meaning here as in /portfolio, and funding is a separate cash flow. A caller that
|
|
158
|
-
* wants the leg's all-in result adds the two.
|
|
159
|
-
*/
|
|
160
|
-
funding: SignedDecimalString,
|
|
161
|
-
/**
|
|
162
|
-
* Peak cash this leg alone had committed at one time — the leg's ROI denominator.
|
|
163
|
-
* "0" is an omission sentinel, not free entry: a zero-price synthetic opened part of
|
|
164
|
-
* the leg's basis, so its committed cash is unknowable and no return divides by it.
|
|
165
|
-
*/
|
|
166
|
-
entryNotional: UnsignedDecimalString,
|
|
167
|
-
/**
|
|
168
|
-
* Size closed at a known price. With undeterminedSize this accounts for every unit
|
|
169
|
-
* the leg closed, so the total closed size is the sum of the two. It is not reported
|
|
170
|
-
* separately, because a value derivable from two others can only drift.
|
|
171
|
-
*/
|
|
172
|
-
exitQuantity: UnsignedDecimalString,
|
|
173
|
-
/**
|
|
174
|
-
* Closed size whose PnL is unpriceable, because it closed against a 0-price
|
|
175
|
-
* synthetic or against an entry basis that was itself unpriced. It contributes
|
|
176
|
-
* nothing to grossPnl or exitVwap.
|
|
177
|
-
*/
|
|
178
|
-
undeterminedSize: UnsignedDecimalString
|
|
179
|
-
});
|
|
180
|
-
const ClosedPosition = z.object({
|
|
181
|
-
positionId: z.uuid(),
|
|
182
|
-
connector: Connector,
|
|
183
|
-
/** Lifecycle tag naming which history shape this row carries; each endpoint serves one of them. */
|
|
184
|
-
status: z.literal("CLOSED"),
|
|
185
|
-
/** When the position opened. */
|
|
186
|
-
openedAt: z.string(),
|
|
187
|
-
/** When the position closed. Falls back to the last update for rows that never recorded a close. */
|
|
188
|
-
closedAt: z.string(),
|
|
189
|
-
closedReason: PositionClosedReason.optional(),
|
|
190
|
-
origin: PositionOrigin,
|
|
191
|
-
/** The subscription that opened this position, retained after its lifecycle closes. */
|
|
192
|
-
copySubscriptionId: z.uuid().optional(),
|
|
193
|
-
/** A closed copy position no longer follows its leader, regardless of subscription status. */
|
|
194
|
-
isCopying: z.literal(false).optional(),
|
|
195
|
-
grossPnl: SignedDecimalString,
|
|
196
|
-
netPnl: SignedDecimalString,
|
|
197
|
-
totalFees: SignedDecimalString,
|
|
198
|
-
tradeFees: SignedDecimalString,
|
|
199
|
-
pearFees: SignedDecimalString,
|
|
200
|
-
/**
|
|
201
|
-
* Funding attributed to the whole position (signed; negative = net paid).
|
|
202
|
-
*
|
|
203
|
-
* Totals every asset the position carried exposure on, which can exceed the sum of
|
|
204
|
-
* the legs: funding follows exposure, and an asset with exposure but no confirmed
|
|
205
|
-
* fill earns no leg. Summing the legs instead would understate what the position paid.
|
|
206
|
-
*
|
|
207
|
-
* Reported beside netPnl, never folded into it. See the leg field's note.
|
|
208
|
-
*/
|
|
209
|
-
totalFunding: SignedDecimalString,
|
|
210
|
-
/**
|
|
211
|
-
* Peak cash the whole position had committed at one time — the ROI denominator.
|
|
212
|
-
* "0" is an omission sentinel, not free entry: a zero-price synthetic opened part of
|
|
213
|
-
* the basis, so committed cash is unknowable and clients must not divide by it.
|
|
214
|
-
*/
|
|
215
|
-
entryNotional: UnsignedDecimalString,
|
|
216
|
-
/**
|
|
217
|
-
* Proceeds of the priced closes. Understates whenever part of the position closed
|
|
218
|
-
* unpriceably — exitNotionalComplete says whether that happened.
|
|
219
|
-
*/
|
|
220
|
-
exitNotional: UnsignedDecimalString,
|
|
221
|
-
/**
|
|
222
|
-
* True when every closed unit had a known price, so exitNotional is the whole story.
|
|
223
|
-
*
|
|
224
|
-
* This is NOT the negation of hasSyntheticFills. A synthetic fill can carry a real
|
|
225
|
-
* price and stay complete, and a priced closing fill still breaks completeness when
|
|
226
|
-
* the entry basis it closed against was unpriced.
|
|
227
|
-
*/
|
|
228
|
-
exitNotionalComplete: z.boolean(),
|
|
229
|
-
/** Whether any fill on the position was a synthetic bridge fill (gap/gone reconstruction). */
|
|
230
|
-
hasSyntheticFills: z.boolean(),
|
|
231
|
-
/** Whether any fill is still PROVISIONAL, so fees and net PnL may still settle. */
|
|
232
|
-
hasProvisionalFills: z.boolean(),
|
|
233
|
-
/** Whether a backfilled fill made this position's historical metrics unreliable. */
|
|
234
|
-
unstableHistoricalData: z.boolean(),
|
|
235
|
-
longAssets: z.array(InstrumentId),
|
|
236
|
-
shortAssets: z.array(InstrumentId),
|
|
237
|
-
legs: z.array(ClosedPositionLeg),
|
|
238
|
-
/**
|
|
239
|
-
* What happened to the position, oldest first: the open, every add, every reduction
|
|
240
|
-
* and the close. `legs` says how each asset finished; this says how it got there.
|
|
241
|
-
*
|
|
242
|
-
* Absent unless the request asks for it, because the array is unbounded — one entry
|
|
243
|
-
* per recorded action, so a heavily traded position produces a long one. `openedAt`
|
|
244
|
-
* carries the open time that step 1 would otherwise have been the only source of.
|
|
245
|
-
*/
|
|
246
|
-
steps: z.array(PositionStep).optional()
|
|
247
|
-
});
|
|
248
|
-
const OpenPositionLeg = z.object({
|
|
249
|
-
asset: InstrumentId,
|
|
250
|
-
side: ClosedPositionLegSide,
|
|
251
|
-
/** Everything the leg has already closed. */
|
|
252
|
-
realized: z.object({
|
|
253
|
-
/**
|
|
254
|
-
* Size closed at a known price so far. With `unpricedQuantity` this accounts for
|
|
255
|
-
* every unit the leg has closed.
|
|
256
|
-
*/
|
|
257
|
-
quantity: UnsignedDecimalString,
|
|
258
|
-
/**
|
|
259
|
-
* Closed size whose PnL is unpriceable, because it closed against a 0-price
|
|
260
|
-
* synthetic or against an entry basis that was itself unpriced. It contributes
|
|
261
|
-
* nothing to `grossPnl` or `exitVwap`.
|
|
262
|
-
*/
|
|
263
|
-
unpricedQuantity: UnsignedDecimalString,
|
|
264
|
-
/** Size-weighted average price the leg has reduced at so far. Absent when nothing closed at a known price. */
|
|
265
|
-
exitVwap: UnsignedDecimalString.optional(),
|
|
266
|
-
/** PnL booked so far, before fees. */
|
|
267
|
-
grossPnl: SignedDecimalString,
|
|
268
|
-
/**
|
|
269
|
-
* PnL booked so far, after every fee charged to date. Entry fees are charged in
|
|
270
|
-
* full at entry — including on size that has not closed yet — so this understates
|
|
271
|
-
* until the leg is flat. Lead with `grossPnl` for a live reading.
|
|
272
|
-
*/
|
|
273
|
-
netPnl: SignedDecimalString
|
|
274
|
-
}),
|
|
275
|
-
/**
|
|
276
|
-
* What the leg still holds: the inputs to an unrealized figure, never the figure itself.
|
|
277
|
-
*/
|
|
278
|
-
remaining: z.object({
|
|
279
|
-
/**
|
|
280
|
-
* The quantity the leg still holds, signed the way `PositionExposure` signs
|
|
281
|
-
* exposure: `+6` for a long remainder, `-4` for a short one, so a consumer
|
|
282
|
-
* never has to recombine with `side` before doing arithmetic. "+0" is a real
|
|
283
|
-
* answer: a leg can walk to flat while the position it belongs to stays open.
|
|
284
|
-
*/
|
|
285
|
-
quantity: SignedDecimalString,
|
|
286
|
-
/**
|
|
287
|
-
* Weighted-average price that remaining quantity was opened at. Absent when the
|
|
288
|
-
* leg is flat, and absent when what remains was opened against an unpriceable
|
|
289
|
-
* basis — `quantity` tells the two absences apart.
|
|
290
|
-
*/
|
|
291
|
-
entryVwap: UnsignedDecimalString.optional()
|
|
292
|
-
}),
|
|
293
|
-
/** Signed: a venue maker rebate makes a fee negative. Charged across the leg's whole life. */
|
|
294
|
-
totalFees: SignedDecimalString,
|
|
295
|
-
tradeFees: SignedDecimalString,
|
|
296
|
-
pearFees: SignedDecimalString,
|
|
297
|
-
/**
|
|
298
|
-
* Funding attributed to this leg so far (signed; negative = net paid).
|
|
299
|
-
*
|
|
300
|
-
* Reported beside realized.netPnl, never folded into it — the same rule as
|
|
301
|
-
* ClosedPositionLeg. A caller that wants the leg's all-in result adds the two.
|
|
302
|
-
*
|
|
303
|
-
* Best-effort: funding payments carry no position id, so attribution walks
|
|
304
|
-
* exposure snapshots and under-attributes whenever untracked or external
|
|
305
|
-
* exposure shared the account. The account-level funding total is authoritative.
|
|
306
|
-
*/
|
|
307
|
-
funding: SignedDecimalString
|
|
308
|
-
});
|
|
309
|
-
const OpenPosition = z.object({
|
|
310
|
-
positionId: z.uuid(),
|
|
311
|
-
connector: Connector,
|
|
312
|
-
/** Lifecycle tag naming which history shape this row carries; each endpoint serves one of them. */
|
|
313
|
-
status: z.literal("OPEN"),
|
|
314
|
-
/** When the position opened — the immutable primary sort key for this history. */
|
|
315
|
-
openedAt: z.string(),
|
|
316
|
-
/** The position's last update, independent of the page cursor. */
|
|
317
|
-
updatedAt: z.string(),
|
|
318
|
-
origin: PositionOrigin,
|
|
319
|
-
/** The subscription that opened this position, retained after copying stops. */
|
|
320
|
-
copySubscriptionId: z.uuid().optional(),
|
|
321
|
-
/** Whether the existing copy eligibility rules still allow this position to follow its leader. */
|
|
322
|
-
isCopying: z.boolean().optional(),
|
|
323
|
-
/**
|
|
324
|
-
* Realized PnL booked so far, before fees. Qualified because the position is still
|
|
325
|
-
* live, and revisable while it is — see netCashflow on reconciliation.
|
|
326
|
-
*/
|
|
327
|
-
realizedGrossPnl: SignedDecimalString,
|
|
328
|
-
/** Lifetime executed USD turnover, including opening and closing fills. */
|
|
329
|
-
volume: UnsignedDecimalString.describe("Lifetime executed USD turnover across opening and closing fills"),
|
|
330
|
-
/** Gross unrealized PnL at current marks; missing marks or entry basis can make this total partial. */
|
|
331
|
-
grossUpnl: SignedDecimalString.describe("Gross unrealized USD PnL at current marks; missing marks or entry basis can make this total partial; excludes fees and funding"),
|
|
332
|
-
/**
|
|
333
|
-
* Cash booked so far: realized gross PnL minus every fee charged to date. Not a
|
|
334
|
-
* settled return on closed quantity — it books every fee charged so far, including
|
|
335
|
-
* entry fees on still-open size. Fee timing distorts it in two directions while
|
|
336
|
-
* open: entry fees are charged in full at entry (understates), and a provisional
|
|
337
|
-
* fill carries no fees yet (overstates). A provisional fill also revises its own
|
|
338
|
-
* price and quantity when it reconciles, so this and realizedGrossPnl can each
|
|
339
|
-
* change between two reads of a position that did not trade in between. Equals
|
|
340
|
-
* /positions/closed's netPnl once the position is flat. Lead with realizedGrossPnl
|
|
341
|
-
* for a live reading.
|
|
342
|
-
*/
|
|
343
|
-
netCashflow: SignedDecimalString,
|
|
344
|
-
totalFees: SignedDecimalString,
|
|
345
|
-
tradeFees: SignedDecimalString,
|
|
346
|
-
pearFees: SignedDecimalString,
|
|
347
|
-
/**
|
|
348
|
-
* Funding attributed to the position so far (signed; negative = net paid).
|
|
349
|
-
*
|
|
350
|
-
* Totals every asset the position carried exposure on, which can exceed the sum
|
|
351
|
-
* of the legs: funding follows exposure, and an asset with exposure but no fill
|
|
352
|
-
* earns no leg. Reported beside netCashflow, never folded into it.
|
|
353
|
-
*
|
|
354
|
-
* Best-effort: funding payments carry no position id, so attribution walks
|
|
355
|
-
* exposure snapshots and under-attributes whenever untracked or external
|
|
356
|
-
* exposure shared the account. The account-level funding total is authoritative.
|
|
357
|
-
*/
|
|
358
|
-
totalFunding: SignedDecimalString,
|
|
359
|
-
/**
|
|
360
|
-
* The exposure expressed in USD at the time the position was opened. It does not
|
|
361
|
-
* change on adjustments, and is only used for UI purposes — exactly the figure
|
|
362
|
-
* /positions reports.
|
|
363
|
-
*/
|
|
364
|
-
initialExposureUSD: PositionInitialExposureUSD,
|
|
365
|
-
/** Whether any fill on the position was a synthetic bridge fill (gap/gone reconstruction). */
|
|
366
|
-
hasSyntheticFills: z.boolean(),
|
|
367
|
-
/**
|
|
368
|
-
* Whether any fill on the position is still PROVISIONAL — the runtime flag that
|
|
369
|
-
* this row's economics are still settling, since a UI cannot read a JSDoc caveat.
|
|
370
|
-
* Independent of hasSyntheticFills: a row can have either, both or neither.
|
|
371
|
-
*/
|
|
372
|
-
hasProvisionalFills: z.boolean(),
|
|
373
|
-
/** Whether a backfilled fill made this position's historical metrics unreliable. */
|
|
374
|
-
unstableHistoricalData: z.boolean(),
|
|
375
|
-
/**
|
|
376
|
-
* Every asset the ledger recorded, each carrying its own side.
|
|
377
|
-
*
|
|
378
|
-
* Unlike ClosedPosition there is no separate longAssets / shortAssets pair: the two would
|
|
379
|
-
* restate exactly what the legs already say. They survive on the closed shape because
|
|
380
|
-
* portfolio analytics keys its pair breakdown on them; nothing keys anything on this
|
|
381
|
-
* endpoint. A caller wanting the basket sides groups the legs by `side`.
|
|
382
|
-
*/
|
|
383
|
-
legs: z.array(OpenPositionLeg),
|
|
384
|
-
/**
|
|
385
|
-
* What has happened to the position so far, oldest first. The step shape is
|
|
386
|
-
* status-agnostic — it describes what a fill did, and an open position's history
|
|
387
|
-
* is made of the same actions — so both histories use PositionStep verbatim.
|
|
388
|
-
*
|
|
389
|
-
* Absent unless the request asks for it, because the array is unbounded.
|
|
390
|
-
*/
|
|
391
|
-
steps: z.array(PositionStep).optional()
|
|
392
|
-
});
|
|
393
|
-
const VaultOpenPositionLeg = OpenPositionLeg.pick({
|
|
394
|
-
asset: true,
|
|
395
|
-
side: true,
|
|
396
|
-
realized: true,
|
|
397
|
-
remaining: true
|
|
398
|
-
});
|
|
399
|
-
const VaultOpenPosition = OpenPosition.pick({
|
|
400
|
-
positionId: true,
|
|
401
|
-
status: true,
|
|
402
|
-
connector: true,
|
|
403
|
-
openedAt: true,
|
|
404
|
-
updatedAt: true,
|
|
405
|
-
realizedGrossPnl: true,
|
|
406
|
-
netCashflow: true
|
|
407
|
-
}).extend({
|
|
408
|
-
legs: z.array(VaultOpenPositionLeg)
|
|
409
|
-
});
|
|
410
|
-
const VaultClosedPositionLeg = ClosedPositionLeg.pick({
|
|
411
|
-
asset: true,
|
|
412
|
-
side: true,
|
|
413
|
-
entryVwap: true,
|
|
414
|
-
exitVwap: true,
|
|
415
|
-
entryNotional: true,
|
|
416
|
-
grossPnl: true,
|
|
417
|
-
netPnl: true
|
|
418
|
-
});
|
|
419
|
-
const VaultClosedPosition = ClosedPosition.pick({
|
|
420
|
-
positionId: true,
|
|
421
|
-
status: true,
|
|
422
|
-
connector: true,
|
|
423
|
-
openedAt: true,
|
|
424
|
-
closedAt: true,
|
|
425
|
-
closedReason: true,
|
|
426
|
-
grossPnl: true,
|
|
427
|
-
netPnl: true,
|
|
428
|
-
hasProvisionalFills: true
|
|
429
|
-
}).extend({
|
|
430
|
-
legs: z.array(VaultClosedPositionLeg)
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
export { ClosedPosition, ClosedPositionLeg, ClosedPositionLegSide, OpenPosition, OpenPositionLeg, Position, PositionClosedReason, PositionEntryPrices, PositionExposure, PositionInitialExposureUSD, PositionOrigin, PositionStatus, PositionStep, PositionStepLeg, PositionTotalFundingPayment, VaultClosedPosition, VaultClosedPositionLeg, VaultOpenPosition, VaultOpenPositionLeg };
|
package/dist/position/index.js
DELETED
package/dist/position/queries.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { normalizeArray, CursorFindParams } from '../common';
|
|
3
|
-
import { Connector } from '../connector';
|
|
4
|
-
|
|
5
|
-
const OrderBy = z.union([
|
|
6
|
-
z.literal("createdAt"),
|
|
7
|
-
z.literal("-createdAt"),
|
|
8
|
-
z.literal("updatedAt"),
|
|
9
|
-
z.literal("-updatedAt")
|
|
10
|
-
]);
|
|
11
|
-
const StatusEnum = z.enum([
|
|
12
|
-
"OPEN",
|
|
13
|
-
"CLOSED"
|
|
14
|
-
]);
|
|
15
|
-
const StatusArray = z.preprocess((arg) => normalizeArray(arg), z.array(StatusEnum));
|
|
16
|
-
const PositionListParams = CursorFindParams.extend({
|
|
17
|
-
/**
|
|
18
|
-
* Connector filter
|
|
19
|
-
*/
|
|
20
|
-
connector: Connector.optional(),
|
|
21
|
-
/**
|
|
22
|
-
* Status filter
|
|
23
|
-
*/
|
|
24
|
-
status: StatusArray.optional(),
|
|
25
|
-
/**
|
|
26
|
-
* Order by field
|
|
27
|
-
*/
|
|
28
|
-
orderBy: OrderBy.default("-createdAt")
|
|
29
|
-
});
|
|
30
|
-
const ClosedPositionListParams = CursorFindParams.extend({
|
|
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
|
-
*/
|
|
35
|
-
limit: z.coerce.number().int().positive().max(200).optional().default(20),
|
|
36
|
-
/**
|
|
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
|
-
*/
|
|
41
|
-
startDate: z.string().optional(),
|
|
42
|
-
endDate: z.string().optional(),
|
|
43
|
-
/**
|
|
44
|
-
* Narrows the page to one closed position. The only scope `includeSteps` may be
|
|
45
|
-
* asked at — see the refinement below.
|
|
46
|
-
*/
|
|
47
|
-
positionId: z.uuid().optional(),
|
|
48
|
-
/**
|
|
49
|
-
* Whether to return each position's `steps` timeline. Off by default because the array
|
|
50
|
-
* is unbounded, and a caller listing history rarely needs every recorded action of
|
|
51
|
-
* every row. `openedAt` is always present, so omitting steps costs no timestamp.
|
|
52
|
-
*
|
|
53
|
-
* Accepts a real boolean from an SDK caller and its text form from a query string.
|
|
54
|
-
* Deliberately not `z.coerce.boolean()`, which reads the string "false" as true and
|
|
55
|
-
* so cannot be switched off from a URL at all.
|
|
56
|
-
*/
|
|
57
|
-
includeSteps: z.union([
|
|
58
|
-
z.boolean(),
|
|
59
|
-
z.stringbool()
|
|
60
|
-
]).optional().default(false)
|
|
61
|
-
}).refine((params) => !params.includeSteps || params.positionId !== void 0, {
|
|
62
|
-
path: [
|
|
63
|
-
"includeSteps"
|
|
64
|
-
],
|
|
65
|
-
message: "includeSteps requires positionId"
|
|
66
|
-
});
|
|
67
|
-
const OpenPositionListParams = CursorFindParams.extend({
|
|
68
|
-
/**
|
|
69
|
-
* Capped below the shared 2000 because every row drags its fills along — one page
|
|
70
|
-
* of open positions can pull thousands of fill rows into one response.
|
|
71
|
-
*/
|
|
72
|
-
limit: z.coerce.number().int().positive().max(200).optional().default(20),
|
|
73
|
-
/**
|
|
74
|
-
* Narrows the page to one open position. The only scope `includeSteps` may be
|
|
75
|
-
* asked at — see the refinement below.
|
|
76
|
-
*/
|
|
77
|
-
positionId: z.uuid().optional(),
|
|
78
|
-
/**
|
|
79
|
-
* Whether to return each position's `steps` timeline. Off by default because the array
|
|
80
|
-
* is unbounded, and a caller listing history rarely needs every recorded action of
|
|
81
|
-
* every row. `openedAt` is always present, so omitting steps costs no timestamp.
|
|
82
|
-
*
|
|
83
|
-
* Accepts a real boolean from an SDK caller and its text form from a query string.
|
|
84
|
-
* Deliberately not `z.coerce.boolean()`, which reads the string "false" as true and
|
|
85
|
-
* so cannot be switched off from a URL at all.
|
|
86
|
-
*/
|
|
87
|
-
includeSteps: z.union([
|
|
88
|
-
z.boolean(),
|
|
89
|
-
z.stringbool()
|
|
90
|
-
]).optional().default(false)
|
|
91
|
-
}).refine((params) => !params.includeSteps || params.positionId !== void 0, {
|
|
92
|
-
path: [
|
|
93
|
-
"includeSteps"
|
|
94
|
-
],
|
|
95
|
-
message: "includeSteps requires positionId"
|
|
96
|
-
});
|
|
97
|
-
const VaultOpenPositionListParams = CursorFindParams.extend({
|
|
98
|
-
/** Same cap as the private open history: every row drags its fills along. */
|
|
99
|
-
limit: z.coerce.number().int().positive().max(200).optional().default(20)
|
|
100
|
-
}).strict();
|
|
101
|
-
const VaultClosedPositionListParams = CursorFindParams.extend({
|
|
102
|
-
/** Same cap as the private closed history: every row drags its fills along. */
|
|
103
|
-
limit: z.coerce.number().int().positive().max(200).optional().default(20),
|
|
104
|
-
/** Inclusive bounds on the close time, exactly as `ClosedPositionListParams` defines them. */
|
|
105
|
-
startDate: z.string().optional(),
|
|
106
|
-
endDate: z.string().optional()
|
|
107
|
-
}).strict();
|
|
108
|
-
|
|
109
|
-
export { ClosedPositionListParams, OpenPositionListParams, PositionListParams, VaultClosedPositionListParams, VaultOpenPositionListParams };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { CursorResponse } from '../common';
|
|
3
|
-
import { EthereumAddress } from '../common/address';
|
|
4
|
-
import { SignedDecimalString } from '../common/schema';
|
|
5
|
-
import { Connector } from '../connector';
|
|
6
|
-
import { InstrumentId } from '../instrument';
|
|
7
|
-
import { Position, PositionOrigin, ClosedPosition, OpenPosition, VaultOpenPosition, VaultClosedPosition } from './entities';
|
|
8
|
-
|
|
9
|
-
const PositionListResponse = CursorResponse.extend({
|
|
10
|
-
positions: z.array(Position)
|
|
11
|
-
});
|
|
12
|
-
const OpenPositionLite = z.object({
|
|
13
|
-
id: z.uuid(),
|
|
14
|
-
/** The subscription that opened the position is identified only in this authenticated read. */
|
|
15
|
-
copySubscriptionId: z.uuid().optional(),
|
|
16
|
-
positionKey: z.string().trim().min(1, "positionKey must be non-empty"),
|
|
17
|
-
createdAt: z.iso.datetime(),
|
|
18
|
-
exposure: z.record(InstrumentId, SignedDecimalString),
|
|
19
|
-
status: z.literal("OPEN"),
|
|
20
|
-
origin: PositionOrigin,
|
|
21
|
-
connector: Connector
|
|
22
|
-
});
|
|
23
|
-
const OpenPositionLiteListResponse = z.object({
|
|
24
|
-
positions: z.array(OpenPositionLite)
|
|
25
|
-
});
|
|
26
|
-
const ClosedPositionListResponse = CursorResponse.extend({
|
|
27
|
-
positions: z.array(ClosedPosition)
|
|
28
|
-
});
|
|
29
|
-
const OpenPositionListResponse = CursorResponse.extend({
|
|
30
|
-
positions: z.array(OpenPosition)
|
|
31
|
-
});
|
|
32
|
-
const VaultOpenPositionListResponse = CursorResponse.extend({
|
|
33
|
-
vaultAddress: EthereumAddress,
|
|
34
|
-
positions: z.array(VaultOpenPosition)
|
|
35
|
-
});
|
|
36
|
-
const VaultClosedPositionListResponse = CursorResponse.extend({
|
|
37
|
-
vaultAddress: EthereumAddress,
|
|
38
|
-
positions: z.array(VaultClosedPosition)
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
export { ClosedPositionListResponse, OpenPositionListResponse, OpenPositionLite, OpenPositionLiteListResponse, PositionListResponse, VaultClosedPositionListResponse, VaultOpenPositionListResponse };
|
package/dist/price/entities.js
DELETED
package/dist/price/index.js
DELETED
package/dist/price/queries.js
DELETED
package/dist/price/responses.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { InstrumentPriceMap } from './entities';
|
|
3
|
-
|
|
4
|
-
const PricesResponse = z.object({
|
|
5
|
-
/**
|
|
6
|
-
* Mid prices for instruments
|
|
7
|
-
*/
|
|
8
|
-
mid: InstrumentPriceMap,
|
|
9
|
-
/**
|
|
10
|
-
* Mark prices for instruments
|
|
11
|
-
*/
|
|
12
|
-
mark: InstrumentPriceMap
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
export { PricesResponse };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
const WebsocketPublicChannel = z.enum([
|
|
4
|
-
"prices",
|
|
5
|
-
"funding",
|
|
6
|
-
"trades"
|
|
7
|
-
]);
|
|
8
|
-
const WebsocketChannel = z.enum([
|
|
9
|
-
...WebsocketPublicChannel.options,
|
|
10
|
-
"trigger_events",
|
|
11
|
-
"user_events",
|
|
12
|
-
"vault_events",
|
|
13
|
-
"vault_management"
|
|
14
|
-
]);
|
|
15
|
-
|
|
16
|
-
export { WebsocketChannel, WebsocketPublicChannel };
|