@pear-protocol/types 2.21.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/users/entities.d.ts +4 -0
- package/dist/users/response.d.ts +2 -0
- package/package.json +3 -2
- 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 -111
- package/dist/statistics/responses.js +0 -67
- package/dist/sync/index.js +0 -2
- package/dist/sync/payloads.js +0 -136
- package/dist/sync/responses.js +0 -28
- 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 -28
- 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
package/dist/order/entities.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { UnsignedDecimalString, Side } from '../common/schema';
|
|
3
|
-
import { Connector } from '../connector';
|
|
4
|
-
import { InstrumentId } from '../instrument';
|
|
5
|
-
|
|
6
|
-
const OrderStatus = z.enum([
|
|
7
|
-
"PENDING",
|
|
8
|
-
"PARTIAL",
|
|
9
|
-
"FILLED",
|
|
10
|
-
"CANCELLED",
|
|
11
|
-
"REJECTED"
|
|
12
|
-
]);
|
|
13
|
-
const BaseOrder = z.object({
|
|
14
|
-
/**
|
|
15
|
-
* Order UUID
|
|
16
|
-
*/
|
|
17
|
-
id: z.uuid(),
|
|
18
|
-
/**
|
|
19
|
-
* Connector
|
|
20
|
-
*/
|
|
21
|
-
connector: Connector,
|
|
22
|
-
/**
|
|
23
|
-
* Order status
|
|
24
|
-
*/
|
|
25
|
-
status: OrderStatus,
|
|
26
|
-
/**
|
|
27
|
-
* Error message
|
|
28
|
-
*/
|
|
29
|
-
error: z.string().optional(),
|
|
30
|
-
/**
|
|
31
|
-
* Venue-specific error code for the failure, when the venue provided one
|
|
32
|
-
*/
|
|
33
|
-
errorCode: z.string().optional(),
|
|
34
|
-
/**
|
|
35
|
-
* Created at timestamp
|
|
36
|
-
*/
|
|
37
|
-
createdAt: z.string(),
|
|
38
|
-
/**
|
|
39
|
-
* Updated at timestamp
|
|
40
|
-
*/
|
|
41
|
-
updatedAt: z.string()
|
|
42
|
-
});
|
|
43
|
-
const MarketOrder = BaseOrder.extend({
|
|
44
|
-
/**
|
|
45
|
-
* Order type
|
|
46
|
-
*/
|
|
47
|
-
type: z.literal("MARKET"),
|
|
48
|
-
/**
|
|
49
|
-
* Instrument ID
|
|
50
|
-
*/
|
|
51
|
-
symbol: InstrumentId,
|
|
52
|
-
/**
|
|
53
|
-
* Side
|
|
54
|
-
*/
|
|
55
|
-
side: Side,
|
|
56
|
-
/**
|
|
57
|
-
* Reduce only flag
|
|
58
|
-
*/
|
|
59
|
-
reduceOnly: z.boolean(),
|
|
60
|
-
/**
|
|
61
|
-
* Contract quantity to trade
|
|
62
|
-
*/
|
|
63
|
-
quantity: UnsignedDecimalString,
|
|
64
|
-
/**
|
|
65
|
-
* Price
|
|
66
|
-
*/
|
|
67
|
-
price: UnsignedDecimalString,
|
|
68
|
-
/**
|
|
69
|
-
* Filled contract quantity
|
|
70
|
-
*/
|
|
71
|
-
filledQuantity: UnsignedDecimalString,
|
|
72
|
-
/**
|
|
73
|
-
* Filled price
|
|
74
|
-
*/
|
|
75
|
-
filledPrice: UnsignedDecimalString.optional()
|
|
76
|
-
});
|
|
77
|
-
const Order = z.discriminatedUnion("type", [
|
|
78
|
-
BaseOrder.extend(MarketOrder.shape)
|
|
79
|
-
]);
|
|
80
|
-
|
|
81
|
-
export { MarketOrder, Order, OrderStatus };
|
package/dist/order/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './entities';
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
const NullableNumber = z.number().nullable();
|
|
4
|
-
const PortfolioCashflowAmounts = z.object({
|
|
5
|
-
grossPnl: z.number(),
|
|
6
|
-
tradeFees: z.number(),
|
|
7
|
-
pearFees: z.number(),
|
|
8
|
-
netCashflow: z.number(),
|
|
9
|
-
funding: z.number(),
|
|
10
|
-
netCashflowWithFunding: z.number(),
|
|
11
|
-
undeterminedQuantityByAsset: z.record(z.string(), z.number())
|
|
12
|
-
});
|
|
13
|
-
const PortfolioCashflowSeriesPoint = PortfolioCashflowAmounts.extend({
|
|
14
|
-
periodStart: z.string(),
|
|
15
|
-
periodEnd: z.string()
|
|
16
|
-
});
|
|
17
|
-
const PortfolioCashflowIntervals = z.object({
|
|
18
|
-
oneDay: z.array(PortfolioCashflowSeriesPoint),
|
|
19
|
-
oneWeek: z.array(PortfolioCashflowSeriesPoint),
|
|
20
|
-
oneMonth: z.array(PortfolioCashflowSeriesPoint),
|
|
21
|
-
oneYear: z.array(PortfolioCashflowSeriesPoint),
|
|
22
|
-
all: z.array(PortfolioCashflowSeriesPoint)
|
|
23
|
-
});
|
|
24
|
-
const PortfolioVolumeAmounts = z.object({
|
|
25
|
-
total: z.number()
|
|
26
|
-
});
|
|
27
|
-
const PortfolioVolumeSeriesPoint = z.object({
|
|
28
|
-
periodStart: z.string(),
|
|
29
|
-
periodEnd: z.string(),
|
|
30
|
-
volume: z.number()
|
|
31
|
-
});
|
|
32
|
-
const PortfolioVolumeIntervals = z.object({
|
|
33
|
-
oneDay: z.array(PortfolioVolumeSeriesPoint),
|
|
34
|
-
oneWeek: z.array(PortfolioVolumeSeriesPoint),
|
|
35
|
-
oneMonth: z.array(PortfolioVolumeSeriesPoint),
|
|
36
|
-
oneYear: z.array(PortfolioVolumeSeriesPoint),
|
|
37
|
-
all: z.array(PortfolioVolumeSeriesPoint)
|
|
38
|
-
});
|
|
39
|
-
const PortfolioClosedPositionStats = z.object({
|
|
40
|
-
totalPositions: z.number(),
|
|
41
|
-
wins: z.number(),
|
|
42
|
-
losses: z.number(),
|
|
43
|
-
hitRate: NullableNumber,
|
|
44
|
-
profitFactor: NullableNumber,
|
|
45
|
-
avgWinSize: NullableNumber,
|
|
46
|
-
avgLossSize: NullableNumber,
|
|
47
|
-
netPnl: z.number(),
|
|
48
|
-
positionPnls: z.array(z.number()),
|
|
49
|
-
positionReturns: z.array(z.number())
|
|
50
|
-
});
|
|
51
|
-
const PortfolioPairBreakdown = z.object({
|
|
52
|
-
key: z.string(),
|
|
53
|
-
longAssets: z.array(z.string()),
|
|
54
|
-
shortAssets: z.array(z.string()),
|
|
55
|
-
positions: z.number(),
|
|
56
|
-
wins: z.number(),
|
|
57
|
-
losses: z.number(),
|
|
58
|
-
hitRate: NullableNumber,
|
|
59
|
-
profitFactor: NullableNumber,
|
|
60
|
-
expectancy: z.number(),
|
|
61
|
-
grossPnl: z.number(),
|
|
62
|
-
tradeFees: z.number(),
|
|
63
|
-
pearFees: z.number(),
|
|
64
|
-
netPnl: z.number(),
|
|
65
|
-
// Signed share of closed-position net PnL; null when the closed book is zero.
|
|
66
|
-
bookPercent: NullableNumber
|
|
67
|
-
});
|
|
68
|
-
const PortfolioOpenSnapshot = z.object({
|
|
69
|
-
openInterest: z.number(),
|
|
70
|
-
unrealizedPnl: z.number()
|
|
71
|
-
});
|
|
72
|
-
const PortfolioAnalyticsConfig = z.object({
|
|
73
|
-
startDate: z.string(),
|
|
74
|
-
endDate: z.string()
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
export { NullableNumber, PortfolioAnalyticsConfig, PortfolioCashflowAmounts, PortfolioCashflowIntervals, PortfolioCashflowSeriesPoint, PortfolioClosedPositionStats, PortfolioOpenSnapshot, PortfolioPairBreakdown, PortfolioVolumeAmounts, PortfolioVolumeIntervals, PortfolioVolumeSeriesPoint };
|
package/dist/portfolio/index.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
const PortfolioSource = z.enum([
|
|
4
|
-
"all",
|
|
5
|
-
"pear"
|
|
6
|
-
]);
|
|
7
|
-
const PortfolioQuery = z.object({
|
|
8
|
-
startDate: z.string().optional().describe("Inclusive portfolio range start."),
|
|
9
|
-
endDate: z.string().optional().describe("Exclusive portfolio range end."),
|
|
10
|
-
// "pear" excludes external imported fills from volume calculations.
|
|
11
|
-
source: PortfolioSource.optional().default("all")
|
|
12
|
-
});
|
|
13
|
-
const PortfolioAnalyticsInterval = z.enum([
|
|
14
|
-
"1d",
|
|
15
|
-
"1w",
|
|
16
|
-
"1m",
|
|
17
|
-
"1y",
|
|
18
|
-
"all"
|
|
19
|
-
]);
|
|
20
|
-
const PortfolioAnalyticsQuery = z.object({
|
|
21
|
-
startDate: z.string().optional().describe("Inclusive analytics range start."),
|
|
22
|
-
endDate: z.string().optional().describe("Exclusive analytics range end."),
|
|
23
|
-
interval: PortfolioAnalyticsInterval.optional(),
|
|
24
|
-
includeSeries: z.union([
|
|
25
|
-
z.boolean(),
|
|
26
|
-
z.enum([
|
|
27
|
-
"false",
|
|
28
|
-
"true"
|
|
29
|
-
]).transform((value) => value === "true")
|
|
30
|
-
]).optional(),
|
|
31
|
-
source: PortfolioSource.optional().default("all")
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
export { PortfolioAnalyticsInterval, PortfolioAnalyticsQuery, PortfolioQuery, PortfolioSource };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { PortfolioOpenSnapshot, PortfolioClosedPositionStats, PortfolioVolumeAmounts, PortfolioVolumeIntervals, PortfolioCashflowAmounts, PortfolioCashflowIntervals, PortfolioAnalyticsConfig, PortfolioVolumeSeriesPoint, PortfolioPairBreakdown, PortfolioCashflowSeriesPoint } from './entities';
|
|
3
|
-
|
|
4
|
-
const PortfolioResponse = z.object({
|
|
5
|
-
/** Historical accounting or the current open snapshot still uses provisional fills. */
|
|
6
|
-
hasProvisionalFills: z.boolean(),
|
|
7
|
-
realizedCashflow: PortfolioCashflowAmounts.extend({
|
|
8
|
-
fundingSynced: z.boolean(),
|
|
9
|
-
intervals: PortfolioCashflowIntervals.optional()
|
|
10
|
-
}),
|
|
11
|
-
closedPositionStats: PortfolioClosedPositionStats,
|
|
12
|
-
openSnapshot: PortfolioOpenSnapshot,
|
|
13
|
-
volume: PortfolioVolumeAmounts.extend({
|
|
14
|
-
intervals: PortfolioVolumeIntervals.optional()
|
|
15
|
-
})
|
|
16
|
-
});
|
|
17
|
-
const PortfolioAnalyticsResponse = z.object({
|
|
18
|
-
config: PortfolioAnalyticsConfig,
|
|
19
|
-
/** Historical accounting or the current open snapshot still uses provisional fills. */
|
|
20
|
-
hasProvisionalFills: z.boolean(),
|
|
21
|
-
realizedCashflow: PortfolioCashflowAmounts.extend({
|
|
22
|
-
fundingSynced: z.boolean(),
|
|
23
|
-
series: z.array(PortfolioCashflowSeriesPoint).optional()
|
|
24
|
-
}),
|
|
25
|
-
closedPositionStats: PortfolioClosedPositionStats,
|
|
26
|
-
pairBreakdown: z.array(PortfolioPairBreakdown),
|
|
27
|
-
openSnapshot: PortfolioOpenSnapshot,
|
|
28
|
-
volume: PortfolioVolumeAmounts.extend({
|
|
29
|
-
series: z.array(PortfolioVolumeSeriesPoint).optional()
|
|
30
|
-
})
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
export { PortfolioAnalyticsResponse, PortfolioResponse };
|
|
@@ -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