@pear-protocol/types 2.15.0 → 2.16.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.
@@ -2,6 +2,7 @@ import { z } from 'zod';
2
2
  import { SignedDecimalString, UnsignedDecimalString } from '../common/schema';
3
3
  import { Connector } from '../connector';
4
4
  import { InstrumentId } from '../instrument';
5
+ import { CopyPerformance, CopyEndCaptureStatus, CopyStartSnapshot } from './performance';
5
6
 
6
7
  const CopySubscriptionStatus = z.enum([
7
8
  "ACTIVE",
@@ -16,6 +17,15 @@ const CopySizing = z.discriminatedUnion("mode", [
16
17
  mode: z.literal("LEADER_EQUITY_FRACTION")
17
18
  })
18
19
  ]);
20
+ const CopySubscriptionMetrics = z.object({
21
+ volume: UnsignedDecimalString.describe("Lifetime executed USD turnover across opens and closes; excludes fees and funding"),
22
+ grossRealizedPnl: SignedDecimalString.describe("Gross realized USD PnL over attributed positions during the copy period, including partial reductions; excludes fees and funding"),
23
+ grossUpnl: SignedDecimalString.describe("Gross unrealized USD PnL observed for the subscription; fixed at the actual asynchronous end capture for ended subscriptions; excludes fees and funding"),
24
+ fundingPayment: SignedDecimalString.describe("Signed USD funding attributed to exposure during the copy period; positive values are received funding"),
25
+ tradeFee: SignedDecimalString.describe("Signed USD trade fees on attributed position fills; negative values are rebates"),
26
+ pearFee: SignedDecimalString.describe("Signed USD Pear fees on attributed position fills; negative values are rebates"),
27
+ totalNetPnl: SignedDecimalString.describe("Gross realized plus gross unrealized plus fundingPayment minus tradeFee and pearFee in USD")
28
+ });
19
29
  const CopySubscription = z.object({
20
30
  id: z.uuid(),
21
31
  leaderTradeAccountId: z.uuid().describe("The account being copied"),
@@ -23,18 +33,25 @@ const CopySubscription = z.object({
23
33
  connector: Connector,
24
34
  status: CopySubscriptionStatus,
25
35
  sizing: CopySizing,
36
+ startSnapshot: CopyStartSnapshot.optional(),
37
+ endCapture: CopyEndCaptureStatus.optional(),
38
+ endReason: z.enum([
39
+ "UNSUBSCRIBED",
40
+ "MANUAL_TRADE",
41
+ "EXTERNAL_POSITION_DETECTED",
42
+ "LEADER_EXTERNAL_ACTIVITY",
43
+ "FAILURE_THRESHOLD"
44
+ ]).optional(),
45
+ performance: CopyPerformance.optional(),
46
+ ...CopySubscriptionMetrics.omit({
47
+ volume: true
48
+ }).partial().shape,
49
+ roi: SignedDecimalString.optional().describe("Whole-subscription net PnL divided by positive starting account equity, times 100; included with complete period performance"),
50
+ provisional: z.literal(true).optional(),
51
+ latestFillAt: z.string().datetime().optional().describe("Latest confirmed fill included in period accounting"),
26
52
  createdAt: z.string().describe("ISO 8601"),
27
53
  endedAt: z.string().optional().describe("ISO 8601; set once the follower unsubscribed")
28
54
  });
29
- const CopySubscriptionMetrics = z.object({
30
- volume: UnsignedDecimalString.describe("Lifetime executed USD turnover across opens and closes; excludes fees and funding"),
31
- grossRealizedPnl: SignedDecimalString.describe("Gross realized USD PnL over attributed positions, including partial reductions; excludes fees and funding"),
32
- grossUpnl: SignedDecimalString.describe("Gross unrealized USD PnL on OPEN attributed positions at current marks; missing marks or entry basis can make this total partial; excludes fees and funding"),
33
- fundingPayment: SignedDecimalString.describe("Signed USD funding attributed from historical exposure snapshots and per-unit payments; absent snapshots contribute no measured funding"),
34
- tradeFee: SignedDecimalString.describe("Signed USD trade fees on attributed position fills; negative values are rebates"),
35
- pearFee: SignedDecimalString.describe("Signed USD Pear fees on attributed position fills; negative values are rebates"),
36
- totalNetPnl: SignedDecimalString.describe("Gross realized plus gross unrealized plus fundingPayment minus tradeFee and pearFee in USD; mark, basis, or exposure gaps can make the measured total partial")
37
- });
38
55
  const CopySubscriptionWithMetrics = CopySubscription.extend({
39
56
  ...CopySubscriptionMetrics.shape,
40
57
  status: z.literal("ACTIVE")
@@ -1,4 +1,5 @@
1
1
  export * from './entities';
2
2
  export * from './payloads';
3
+ export * from './performance';
3
4
  export * from './queries';
4
5
  export * from './responses';
@@ -1,4 +1,5 @@
1
1
  export * from './entities';
2
2
  export * from './payloads';
3
+ export * from './performance';
3
4
  export * from './queries';
4
5
  export * from './responses';
@@ -0,0 +1,186 @@
1
+ /** Immutable local position totals and subscription-period returns. */
2
+ import { z } from 'zod';
3
+ export declare const CopyPnlBreakdown: z.ZodObject<{
4
+ grossRealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
5
+ unrealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
6
+ funding: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
7
+ tradingFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
8
+ platformFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
9
+ netPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
10
+ }, z.core.$strip>;
11
+ export type CopyPnlBreakdown = z.infer<typeof CopyPnlBreakdown>;
12
+ export declare const CopyStartingAccount: z.ZodObject<{
13
+ tradeAccountId: z.ZodString;
14
+ capturedAt: z.ZodString;
15
+ initialEquityUsd: z.ZodString;
16
+ pnl: z.ZodObject<{
17
+ grossRealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
18
+ unrealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
19
+ funding: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
20
+ tradingFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
21
+ platformFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
22
+ netPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
23
+ }, z.core.$strip>;
24
+ }, z.core.$strip>;
25
+ export type CopyStartingAccount = z.infer<typeof CopyStartingAccount>;
26
+ export declare const CopyStartSnapshot: z.ZodObject<{
27
+ leader: z.ZodObject<{
28
+ tradeAccountId: z.ZodString;
29
+ capturedAt: z.ZodString;
30
+ initialEquityUsd: z.ZodString;
31
+ pnl: z.ZodObject<{
32
+ grossRealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
33
+ unrealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
34
+ funding: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
35
+ tradingFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
36
+ platformFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
37
+ netPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
38
+ }, z.core.$strip>;
39
+ }, z.core.$strip>;
40
+ follower: z.ZodObject<{
41
+ tradeAccountId: z.ZodString;
42
+ capturedAt: z.ZodString;
43
+ initialEquityUsd: z.ZodString;
44
+ pnl: z.ZodObject<{
45
+ grossRealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
46
+ unrealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
47
+ funding: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
48
+ tradingFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
49
+ platformFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
50
+ netPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
51
+ }, z.core.$strip>;
52
+ }, z.core.$strip>;
53
+ }, z.core.$strip>;
54
+ export type CopyStartSnapshot = z.infer<typeof CopyStartSnapshot>;
55
+ export declare const CopyAccountPerformance: z.ZodObject<{
56
+ tradeAccountId: z.ZodString;
57
+ capturedAt: z.ZodString;
58
+ provisional: z.ZodLiteral<true>;
59
+ latestFillAt: z.ZodOptional<z.ZodString>;
60
+ pnl: z.ZodObject<{
61
+ grossRealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
62
+ unrealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
63
+ funding: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
64
+ tradingFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
65
+ platformFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
66
+ netPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
67
+ }, z.core.$strip>;
68
+ returnOnStartingEquityPercent: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>>;
69
+ }, z.core.$strip>;
70
+ export type CopyAccountPerformance = z.infer<typeof CopyAccountPerformance>;
71
+ export declare const CopyCaptureTiming: z.ZodLiteral<"DELAYED">;
72
+ export type CopyCaptureTiming = z.infer<typeof CopyCaptureTiming>;
73
+ export declare const CopyPerformance: z.ZodObject<{
74
+ kind: z.ZodLiteral<"OBSERVED">;
75
+ boundaryAt: z.ZodString;
76
+ timing: z.ZodUnion<readonly [z.ZodLiteral<"LIVE">, z.ZodLiteral<"DELAYED">]>;
77
+ accountTimings: z.ZodOptional<z.ZodObject<{
78
+ leader: z.ZodLiteral<"DELAYED">;
79
+ follower: z.ZodLiteral<"DELAYED">;
80
+ }, z.core.$strip>>;
81
+ leader: z.ZodObject<{
82
+ tradeAccountId: z.ZodString;
83
+ capturedAt: z.ZodString;
84
+ provisional: z.ZodLiteral<true>;
85
+ latestFillAt: z.ZodOptional<z.ZodString>;
86
+ pnl: z.ZodObject<{
87
+ grossRealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
88
+ unrealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
89
+ funding: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
90
+ tradingFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
91
+ platformFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
92
+ netPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
93
+ }, z.core.$strip>;
94
+ returnOnStartingEquityPercent: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>>;
95
+ }, z.core.$strip>;
96
+ follower: z.ZodObject<{
97
+ tradeAccountId: z.ZodString;
98
+ capturedAt: z.ZodString;
99
+ provisional: z.ZodLiteral<true>;
100
+ latestFillAt: z.ZodOptional<z.ZodString>;
101
+ pnl: z.ZodObject<{
102
+ grossRealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
103
+ unrealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
104
+ funding: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
105
+ tradingFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
106
+ platformFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
107
+ netPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
108
+ }, z.core.$strip>;
109
+ returnOnStartingEquityPercent: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>>;
110
+ }, z.core.$strip>;
111
+ }, z.core.$strip>;
112
+ export type CopyPerformance = z.infer<typeof CopyPerformance>;
113
+ /** The complete calculation freezes at the actual asynchronous capture boundary. */
114
+ export declare const CopyEndCapture: z.ZodObject<{
115
+ leader: z.ZodObject<{
116
+ tradeAccountId: z.ZodString;
117
+ capturedAt: z.ZodString;
118
+ provisional: z.ZodLiteral<true>;
119
+ latestFillAt: z.ZodOptional<z.ZodString>;
120
+ pnl: z.ZodObject<{
121
+ grossRealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
122
+ unrealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
123
+ funding: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
124
+ tradingFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
125
+ platformFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
126
+ netPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
127
+ }, z.core.$strip>;
128
+ returnOnStartingEquityPercent: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>>;
129
+ }, z.core.$strip>;
130
+ follower: z.ZodObject<{
131
+ tradeAccountId: z.ZodString;
132
+ capturedAt: z.ZodString;
133
+ provisional: z.ZodLiteral<true>;
134
+ latestFillAt: z.ZodOptional<z.ZodString>;
135
+ pnl: z.ZodObject<{
136
+ grossRealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
137
+ unrealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
138
+ funding: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
139
+ tradingFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
140
+ platformFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
141
+ netPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
142
+ }, z.core.$strip>;
143
+ returnOnStartingEquityPercent: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>>;
144
+ }, z.core.$strip>;
145
+ }, z.core.$strip>;
146
+ export type CopyEndCapture = z.infer<typeof CopyEndCapture>;
147
+ export declare const CopyEndCaptureStatus: z.ZodDiscriminatedUnion<[z.ZodObject<{
148
+ status: z.ZodLiteral<"PENDING">;
149
+ }, z.core.$strip>, z.ZodObject<{
150
+ status: z.ZodLiteral<"FAILED">;
151
+ }, z.core.$strip>, z.ZodObject<{
152
+ status: z.ZodLiteral<"COMPLETE">;
153
+ snapshot: z.ZodObject<{
154
+ leader: z.ZodObject<{
155
+ tradeAccountId: z.ZodString;
156
+ capturedAt: z.ZodString;
157
+ provisional: z.ZodLiteral<true>;
158
+ latestFillAt: z.ZodOptional<z.ZodString>;
159
+ pnl: z.ZodObject<{
160
+ grossRealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
161
+ unrealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
162
+ funding: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
163
+ tradingFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
164
+ platformFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
165
+ netPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
166
+ }, z.core.$strip>;
167
+ returnOnStartingEquityPercent: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>>;
168
+ }, z.core.$strip>;
169
+ follower: z.ZodObject<{
170
+ tradeAccountId: z.ZodString;
171
+ capturedAt: z.ZodString;
172
+ provisional: z.ZodLiteral<true>;
173
+ latestFillAt: z.ZodOptional<z.ZodString>;
174
+ pnl: z.ZodObject<{
175
+ grossRealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
176
+ unrealizedPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
177
+ funding: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
178
+ tradingFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
179
+ platformFees: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
180
+ netPnl: z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>;
181
+ }, z.core.$strip>;
182
+ returnOnStartingEquityPercent: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<`-${string}` | `+${string}`, string>>>;
183
+ }, z.core.$strip>;
184
+ }, z.core.$strip>;
185
+ }, z.core.$strip>], "status">;
186
+ export type CopyEndCaptureStatus = z.infer<typeof CopyEndCaptureStatus>;
@@ -0,0 +1,63 @@
1
+ import { z } from 'zod';
2
+ import { SignedDecimalString } from '../common/schema';
3
+
4
+ const Decimal = z.string().regex(/^[+-]?\d+(?:\.\d+)?$/);
5
+ const CopyPnlBreakdown = z.object({
6
+ grossRealizedPnl: SignedDecimalString,
7
+ unrealizedPnl: SignedDecimalString,
8
+ funding: SignedDecimalString,
9
+ tradingFees: SignedDecimalString,
10
+ platformFees: SignedDecimalString,
11
+ netPnl: SignedDecimalString
12
+ });
13
+ const CopyStartingAccount = z.object({
14
+ tradeAccountId: z.string(),
15
+ capturedAt: z.string().datetime(),
16
+ initialEquityUsd: Decimal,
17
+ pnl: CopyPnlBreakdown
18
+ });
19
+ const CopyStartSnapshot = z.object({
20
+ leader: CopyStartingAccount,
21
+ follower: CopyStartingAccount
22
+ });
23
+ const CopyAccountPerformance = z.object({
24
+ tradeAccountId: z.string(),
25
+ capturedAt: z.string().datetime(),
26
+ provisional: z.literal(true),
27
+ latestFillAt: z.string().datetime().optional(),
28
+ pnl: CopyPnlBreakdown,
29
+ returnOnStartingEquityPercent: SignedDecimalString.optional()
30
+ });
31
+ const CopyCaptureTiming = z.literal("DELAYED");
32
+ const CopyPerformance = z.object({
33
+ kind: z.literal("OBSERVED"),
34
+ boundaryAt: z.string().datetime(),
35
+ timing: z.union([
36
+ z.literal("LIVE"),
37
+ CopyCaptureTiming
38
+ ]),
39
+ accountTimings: z.object({
40
+ leader: CopyCaptureTiming,
41
+ follower: CopyCaptureTiming
42
+ }).optional(),
43
+ leader: CopyAccountPerformance,
44
+ follower: CopyAccountPerformance
45
+ });
46
+ const CopyEndCapture = z.object({
47
+ leader: CopyAccountPerformance,
48
+ follower: CopyAccountPerformance
49
+ });
50
+ const CopyEndCaptureStatus = z.discriminatedUnion("status", [
51
+ z.object({
52
+ status: z.literal("PENDING")
53
+ }),
54
+ z.object({
55
+ status: z.literal("FAILED")
56
+ }),
57
+ z.object({
58
+ status: z.literal("COMPLETE"),
59
+ snapshot: CopyEndCapture
60
+ })
61
+ ]);
62
+
63
+ export { CopyAccountPerformance, CopyCaptureTiming, CopyEndCapture, CopyEndCaptureStatus, CopyPerformance, CopyPnlBreakdown, CopyStartSnapshot, CopyStartingAccount };