@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,257 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { SignedDecimalString } from '../../common/schema';
|
|
3
|
-
import { TradeLegPostOnly, TradeLeg } from '../../common/trade-legs';
|
|
4
|
-
import { Connector } from '../../connector';
|
|
5
|
-
import { Fill } from '../../fill';
|
|
6
|
-
import { InstrumentId } from '../../instrument';
|
|
7
|
-
import { TWAPRandomization } from '../../schedule/randomization';
|
|
8
|
-
import { TWAPSliceIntervalSec, MIN_TWAP_SLICE_INTERVAL_SEC, FINAL_TWAP_SLICE_START_HEADROOM_SEC, MAX_TWAP_DURATION_SEC, TWAPTargetNotional, TriggerTWAPOpenLegs } from '../../schedule/twap-config';
|
|
9
|
-
import { TrailingMode, BracketType, TriggerStatus, TriggerCancelledReason, TpSlBracketType } from '../common';
|
|
10
|
-
import { TriggerConditionOpen, TriggerConditionAdjust, TriggerConditionClose } from './conditions';
|
|
11
|
-
|
|
12
|
-
const Trailing = z.object({
|
|
13
|
-
/**
|
|
14
|
-
* Trailing mode to track the metric.
|
|
15
|
-
*/
|
|
16
|
-
mode: TrailingMode,
|
|
17
|
-
/**
|
|
18
|
-
* Delta value to track the metric in the given mode.
|
|
19
|
-
*/
|
|
20
|
-
deltaValue: z.number(),
|
|
21
|
-
/**
|
|
22
|
-
* Activation value to start tracking the metric.
|
|
23
|
-
* When omitted, trailing starts immediately from the current metric.
|
|
24
|
-
*/
|
|
25
|
-
activationValue: z.number().optional(),
|
|
26
|
-
/**
|
|
27
|
-
* Best metric seen
|
|
28
|
-
*/
|
|
29
|
-
bestMetricSeen: z.number().optional(),
|
|
30
|
-
/**
|
|
31
|
-
* Current stop value
|
|
32
|
-
*/
|
|
33
|
-
currentStopValue: z.number().optional(),
|
|
34
|
-
/**
|
|
35
|
-
* Timestamp (ms) when a stop/activation breach was detected.
|
|
36
|
-
*/
|
|
37
|
-
stopBreachedAt: z.number().optional()
|
|
38
|
-
});
|
|
39
|
-
const BaseTrigger = z.object({
|
|
40
|
-
/**
|
|
41
|
-
* Trigger UUID
|
|
42
|
-
*/
|
|
43
|
-
id: z.uuid(),
|
|
44
|
-
/**
|
|
45
|
-
* Trade account UUID
|
|
46
|
-
*/
|
|
47
|
-
tradeAccountId: z.uuid(),
|
|
48
|
-
/**
|
|
49
|
-
* Connector
|
|
50
|
-
*/
|
|
51
|
-
connector: Connector,
|
|
52
|
-
/**
|
|
53
|
-
* Status of the trigger
|
|
54
|
-
*/
|
|
55
|
-
status: TriggerStatus,
|
|
56
|
-
/**
|
|
57
|
-
* Parent ladder ID when this trigger is a ladder rung
|
|
58
|
-
*/
|
|
59
|
-
ladderId: z.uuid().optional(),
|
|
60
|
-
/**
|
|
61
|
-
* Zero-based rung index within the parent ladder
|
|
62
|
-
*/
|
|
63
|
-
ladderIndex: z.number().int().optional(),
|
|
64
|
-
/**
|
|
65
|
-
* Source open trigger that spawned this attached close trigger, when it originated from a conditional open
|
|
66
|
-
*/
|
|
67
|
-
parentTriggerId: z.uuid().optional(),
|
|
68
|
-
/**
|
|
69
|
-
* When the trigger was triggered
|
|
70
|
-
*/
|
|
71
|
-
triggeredAt: z.string().optional(),
|
|
72
|
-
/**
|
|
73
|
-
* When the trigger was cancelled
|
|
74
|
-
*/
|
|
75
|
-
cancelledAt: z.string().optional(),
|
|
76
|
-
/**
|
|
77
|
-
* Reason for the trigger being cancelled
|
|
78
|
-
*/
|
|
79
|
-
cancelledReason: TriggerCancelledReason.optional(),
|
|
80
|
-
/**
|
|
81
|
-
* Fills for the trigger
|
|
82
|
-
*/
|
|
83
|
-
fills: z.array(Fill).optional(),
|
|
84
|
-
/**
|
|
85
|
-
* Bracket type for trigger behavior
|
|
86
|
-
*/
|
|
87
|
-
bracketType: BracketType,
|
|
88
|
-
/**
|
|
89
|
-
* User-facing bracket semantics. `bracketType` is the crossing encoding the gateway
|
|
90
|
-
* fires on (wire-flipped for a price bracket on a short watched leg); this field is
|
|
91
|
-
* what the user asked for, so present this one as intent. Always stated: where a
|
|
92
|
-
* legacy client's encoding was unknowable, it carries `bracketType` as a best guess.
|
|
93
|
-
*/
|
|
94
|
-
semanticBracketType: BracketType,
|
|
95
|
-
/**
|
|
96
|
-
* Created at timestamp
|
|
97
|
-
*/
|
|
98
|
-
createdAt: z.string(),
|
|
99
|
-
/**
|
|
100
|
-
* Updated at timestamp
|
|
101
|
-
*/
|
|
102
|
-
updatedAt: z.string()
|
|
103
|
-
});
|
|
104
|
-
const TriggerMarketOpenAttachedTrigger = z.object({
|
|
105
|
-
kind: z.enum([
|
|
106
|
-
"STATIC",
|
|
107
|
-
"TRAILING"
|
|
108
|
-
]),
|
|
109
|
-
bracketType: TpSlBracketType
|
|
110
|
-
});
|
|
111
|
-
const TriggerMarketOpen = BaseTrigger.extend({
|
|
112
|
-
/**
|
|
113
|
-
* Intent
|
|
114
|
-
*/
|
|
115
|
-
intent: z.literal("OPEN"),
|
|
116
|
-
/**
|
|
117
|
-
* Order type
|
|
118
|
-
*/
|
|
119
|
-
type: z.literal("MARKET"),
|
|
120
|
-
/**
|
|
121
|
-
* Condition (only open conditions allowed)
|
|
122
|
-
*/
|
|
123
|
-
condition: TriggerConditionOpen,
|
|
124
|
-
/**
|
|
125
|
-
* Context
|
|
126
|
-
*/
|
|
127
|
-
context: z.object({
|
|
128
|
-
type: z.literal("MARKET"),
|
|
129
|
-
legs: z.tuple([
|
|
130
|
-
TradeLegPostOnly
|
|
131
|
-
]).rest(TradeLegPostOnly),
|
|
132
|
-
/**
|
|
133
|
-
* Close triggers configured to attach after this open trigger fires.
|
|
134
|
-
*/
|
|
135
|
-
attachedTriggers: z.array(TriggerMarketOpenAttachedTrigger)
|
|
136
|
-
})
|
|
137
|
-
});
|
|
138
|
-
const TriggerMarketAdjust = BaseTrigger.extend({
|
|
139
|
-
/**
|
|
140
|
-
* Intent
|
|
141
|
-
*/
|
|
142
|
-
intent: z.literal("ADJUST"),
|
|
143
|
-
/**
|
|
144
|
-
* Order type
|
|
145
|
-
*/
|
|
146
|
-
type: z.literal("MARKET"),
|
|
147
|
-
/**
|
|
148
|
-
* Condition (only adjust conditions allowed)
|
|
149
|
-
*/
|
|
150
|
-
condition: TriggerConditionAdjust,
|
|
151
|
-
/**
|
|
152
|
-
* Context
|
|
153
|
-
*/
|
|
154
|
-
context: z.object({
|
|
155
|
-
type: z.literal("MARKET"),
|
|
156
|
-
position: z.object({
|
|
157
|
-
id: z.uuid(),
|
|
158
|
-
initialExposure: z.record(InstrumentId, SignedDecimalString)
|
|
159
|
-
}),
|
|
160
|
-
legs: z.tuple([
|
|
161
|
-
TradeLeg
|
|
162
|
-
]).rest(TradeLeg)
|
|
163
|
-
}),
|
|
164
|
-
/**
|
|
165
|
-
* Optional: trailing configuration
|
|
166
|
-
*/
|
|
167
|
-
trailing: Trailing.optional()
|
|
168
|
-
});
|
|
169
|
-
const TriggerMarketClose = BaseTrigger.extend({
|
|
170
|
-
/**
|
|
171
|
-
* Intent
|
|
172
|
-
*/
|
|
173
|
-
intent: z.literal("CLOSE"),
|
|
174
|
-
/**
|
|
175
|
-
* Order type
|
|
176
|
-
*/
|
|
177
|
-
type: z.literal("MARKET"),
|
|
178
|
-
/**
|
|
179
|
-
* Condition (only close conditions allowed)
|
|
180
|
-
*/
|
|
181
|
-
condition: TriggerConditionClose,
|
|
182
|
-
/**
|
|
183
|
-
* Context
|
|
184
|
-
*/
|
|
185
|
-
context: z.object({
|
|
186
|
-
type: z.literal("MARKET"),
|
|
187
|
-
position: z.object({
|
|
188
|
-
id: z.uuid(),
|
|
189
|
-
initialExposure: z.record(InstrumentId, SignedDecimalString)
|
|
190
|
-
})
|
|
191
|
-
}),
|
|
192
|
-
/**
|
|
193
|
-
* Optional: trailing configuration
|
|
194
|
-
*/
|
|
195
|
-
trailing: Trailing.optional()
|
|
196
|
-
});
|
|
197
|
-
const TriggerMarket = z.discriminatedUnion("intent", [
|
|
198
|
-
TriggerMarketOpen,
|
|
199
|
-
TriggerMarketAdjust,
|
|
200
|
-
TriggerMarketClose
|
|
201
|
-
]);
|
|
202
|
-
const TriggerTWAPContext = z.object({
|
|
203
|
-
type: z.literal("TWAP"),
|
|
204
|
-
durationSec: z.int().min(MIN_TWAP_SLICE_INTERVAL_SEC + FINAL_TWAP_SLICE_START_HEADROOM_SEC).max(MAX_TWAP_DURATION_SEC),
|
|
205
|
-
sliceIntervalSec: TWAPSliceIntervalSec,
|
|
206
|
-
randomization: TWAPRandomization,
|
|
207
|
-
position: z.object({
|
|
208
|
-
id: z.uuid(),
|
|
209
|
-
initialExposure: z.record(InstrumentId, SignedDecimalString)
|
|
210
|
-
})
|
|
211
|
-
}).refine((context) => context.durationSec >= context.sliceIntervalSec + FINAL_TWAP_SLICE_START_HEADROOM_SEC, {
|
|
212
|
-
message: `TWAP duration must leave ${FINAL_TWAP_SLICE_START_HEADROOM_SEC} seconds after the first slice`,
|
|
213
|
-
path: [
|
|
214
|
-
"durationSec"
|
|
215
|
-
]
|
|
216
|
-
});
|
|
217
|
-
const TriggerTWAPAdjust = BaseTrigger.extend({
|
|
218
|
-
/** Intent. */
|
|
219
|
-
intent: z.literal("ADJUST"),
|
|
220
|
-
/** Order type. */
|
|
221
|
-
type: z.literal("TWAP"),
|
|
222
|
-
/** Schedule created when the trigger fired, absent before firing or after a skipped fire. */
|
|
223
|
-
scheduleId: z.uuid().optional(),
|
|
224
|
-
/** Condition. */
|
|
225
|
-
condition: TriggerConditionAdjust,
|
|
226
|
-
/** Persisted TWAP execution context. */
|
|
227
|
-
context: TriggerTWAPContext.safeExtend({
|
|
228
|
-
legs: TriggerTWAPOpenLegs,
|
|
229
|
-
targetNotional: TWAPTargetNotional
|
|
230
|
-
}),
|
|
231
|
-
/** Optional trailing configuration. */
|
|
232
|
-
trailing: Trailing.optional()
|
|
233
|
-
});
|
|
234
|
-
const TriggerTWAPClose = BaseTrigger.extend({
|
|
235
|
-
/** Intent. */
|
|
236
|
-
intent: z.literal("CLOSE"),
|
|
237
|
-
/** Order type. */
|
|
238
|
-
type: z.literal("TWAP"),
|
|
239
|
-
/** Schedule created when the trigger fired, absent before firing or after a skipped fire. */
|
|
240
|
-
scheduleId: z.uuid().optional(),
|
|
241
|
-
/** Condition. */
|
|
242
|
-
condition: TriggerConditionClose,
|
|
243
|
-
/** Persisted TWAP execution context. */
|
|
244
|
-
context: TriggerTWAPContext,
|
|
245
|
-
/** Optional trailing configuration. */
|
|
246
|
-
trailing: Trailing.optional()
|
|
247
|
-
});
|
|
248
|
-
const TriggerTWAP = z.discriminatedUnion("intent", [
|
|
249
|
-
TriggerTWAPAdjust,
|
|
250
|
-
TriggerTWAPClose
|
|
251
|
-
]);
|
|
252
|
-
const Trigger = z.discriminatedUnion("type", [
|
|
253
|
-
TriggerMarket,
|
|
254
|
-
TriggerTWAP
|
|
255
|
-
]);
|
|
256
|
-
|
|
257
|
-
export { Trailing, Trigger, TriggerMarket, TriggerMarketAdjust, TriggerMarketClose, TriggerMarketOpen, TriggerMarketOpenAttachedTrigger, TriggerTWAP, TriggerTWAPAdjust, TriggerTWAPClose };
|
package/dist/trigger/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './common';
|
|
2
|
-
export * from './entities';
|
|
3
|
-
export * from './entities/conditions';
|
|
4
|
-
export * from './oracle';
|
|
5
|
-
export * from './payloads';
|
|
6
|
-
export * from './payloads/conditions';
|
|
7
|
-
export * from './queries';
|
|
8
|
-
export * from './refinement';
|
|
9
|
-
export * from './responses';
|
package/dist/trigger/oracle.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
const OracleUnit = z.enum([
|
|
4
|
-
"cent",
|
|
5
|
-
"percent"
|
|
6
|
-
]);
|
|
7
|
-
const OracleValue = z.object({
|
|
8
|
-
value: z.number(),
|
|
9
|
-
unit: OracleUnit
|
|
10
|
-
});
|
|
11
|
-
const OracleTrigger = z.object({
|
|
12
|
-
id: z.string(),
|
|
13
|
-
category: z.enum([
|
|
14
|
-
"btcdom"
|
|
15
|
-
]),
|
|
16
|
-
source: z.enum([
|
|
17
|
-
"coingecko"
|
|
18
|
-
]),
|
|
19
|
-
oracle: OracleValue.nullable()
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
export { OracleTrigger, OracleUnit, OracleValue };
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { RefineMinimumTwoSymbols, RefineUniqueSymbols, RefineWeightingSum, RefineTwoUniqueSymbols } from '../../common/refinement';
|
|
3
|
-
import { AssetWeight, Side } from '../../common/schema';
|
|
4
|
-
import { Connector } from '../../connector';
|
|
5
|
-
import { InstrumentId } from '../../instrument';
|
|
6
|
-
import { MetricTrack } from '../common';
|
|
7
|
-
|
|
8
|
-
const TriggerThreshold = z.number().positive({
|
|
9
|
-
message: "Threshold must be greater than 0"
|
|
10
|
-
});
|
|
11
|
-
const PriceSource = z.enum([
|
|
12
|
-
"mid",
|
|
13
|
-
"mark"
|
|
14
|
-
], {
|
|
15
|
-
message: "Price source must be mid or mark"
|
|
16
|
-
});
|
|
17
|
-
const WeightedRatioBasketItem = z.object({
|
|
18
|
-
symbol: InstrumentId,
|
|
19
|
-
side: Side,
|
|
20
|
-
weight: AssetWeight
|
|
21
|
-
});
|
|
22
|
-
const WeightedRatioBasket = z.array(WeightedRatioBasketItem).superRefine(RefineMinimumTwoSymbols).superRefine(RefineUniqueSymbols).superRefine(RefineWeightingSum);
|
|
23
|
-
const RatioOpen = z.object({
|
|
24
|
-
type: z.literal("ratio"),
|
|
25
|
-
data: z.object({
|
|
26
|
-
priceSource: PriceSource,
|
|
27
|
-
symbol_a: InstrumentId,
|
|
28
|
-
symbol_b: InstrumentId,
|
|
29
|
-
track: MetricTrack,
|
|
30
|
-
threshold: TriggerThreshold
|
|
31
|
-
}).superRefine(RefineTwoUniqueSymbols)
|
|
32
|
-
});
|
|
33
|
-
const PriceOpen = z.object({
|
|
34
|
-
type: z.literal("price"),
|
|
35
|
-
data: z.object({
|
|
36
|
-
priceSource: PriceSource,
|
|
37
|
-
symbol: InstrumentId,
|
|
38
|
-
track: MetricTrack,
|
|
39
|
-
threshold: TriggerThreshold
|
|
40
|
-
})
|
|
41
|
-
});
|
|
42
|
-
const WeightedRatioOpen = z.object({
|
|
43
|
-
type: z.literal("weighted_ratio"),
|
|
44
|
-
data: z.object({
|
|
45
|
-
priceSource: PriceSource,
|
|
46
|
-
basket: WeightedRatioBasket,
|
|
47
|
-
track: MetricTrack,
|
|
48
|
-
threshold: TriggerThreshold
|
|
49
|
-
})
|
|
50
|
-
});
|
|
51
|
-
const PredictionMarketOpen = z.object({
|
|
52
|
-
type: z.literal("prediction_market"),
|
|
53
|
-
data: z.object({
|
|
54
|
-
source: z.enum([
|
|
55
|
-
"kalshi",
|
|
56
|
-
"polymarket"
|
|
57
|
-
]),
|
|
58
|
-
marketKey: z.string().min(1),
|
|
59
|
-
track: MetricTrack,
|
|
60
|
-
threshold: TriggerThreshold
|
|
61
|
-
})
|
|
62
|
-
});
|
|
63
|
-
const FundingRateOpen = z.object({
|
|
64
|
-
type: z.literal("funding_rate"),
|
|
65
|
-
data: z.object({
|
|
66
|
-
connector: Connector,
|
|
67
|
-
symbol: InstrumentId,
|
|
68
|
-
track: MetricTrack,
|
|
69
|
-
threshold: z.number()
|
|
70
|
-
})
|
|
71
|
-
});
|
|
72
|
-
const BtcDominanceOpen = z.object({
|
|
73
|
-
type: z.literal("btc_dominance"),
|
|
74
|
-
data: z.object({
|
|
75
|
-
source: z.literal("coingecko"),
|
|
76
|
-
track: MetricTrack,
|
|
77
|
-
threshold: TriggerThreshold
|
|
78
|
-
})
|
|
79
|
-
});
|
|
80
|
-
const RatioCloseStatic = z.object({
|
|
81
|
-
type: z.literal("ratio"),
|
|
82
|
-
data: z.object({
|
|
83
|
-
priceSource: PriceSource,
|
|
84
|
-
symbol_a: InstrumentId,
|
|
85
|
-
symbol_b: InstrumentId,
|
|
86
|
-
threshold: TriggerThreshold
|
|
87
|
-
}).superRefine(RefineTwoUniqueSymbols)
|
|
88
|
-
});
|
|
89
|
-
const PriceCloseStatic = z.object({
|
|
90
|
-
type: z.literal("price"),
|
|
91
|
-
data: z.object({
|
|
92
|
-
priceSource: PriceSource,
|
|
93
|
-
symbol: InstrumentId,
|
|
94
|
-
threshold: TriggerThreshold
|
|
95
|
-
})
|
|
96
|
-
});
|
|
97
|
-
const WeightedRatioCloseStatic = z.object({
|
|
98
|
-
type: z.literal("weighted_ratio"),
|
|
99
|
-
data: z.object({
|
|
100
|
-
priceSource: PriceSource,
|
|
101
|
-
basket: WeightedRatioBasket,
|
|
102
|
-
threshold: TriggerThreshold
|
|
103
|
-
})
|
|
104
|
-
});
|
|
105
|
-
const NotionalCloseStatic = z.object({
|
|
106
|
-
type: z.literal("notional"),
|
|
107
|
-
data: z.object({
|
|
108
|
-
priceSource: PriceSource,
|
|
109
|
-
threshold: TriggerThreshold
|
|
110
|
-
})
|
|
111
|
-
});
|
|
112
|
-
const UpnlCloseStatic = z.object({
|
|
113
|
-
type: z.literal("upnl"),
|
|
114
|
-
data: z.object({
|
|
115
|
-
priceSource: PriceSource,
|
|
116
|
-
threshold: z.number()
|
|
117
|
-
})
|
|
118
|
-
});
|
|
119
|
-
const UpnlBpsCloseStatic = z.object({
|
|
120
|
-
type: z.literal("upnl_bps"),
|
|
121
|
-
data: z.object({
|
|
122
|
-
priceSource: PriceSource,
|
|
123
|
-
threshold: z.number()
|
|
124
|
-
})
|
|
125
|
-
});
|
|
126
|
-
const PredictionMarketCloseStatic = z.object({
|
|
127
|
-
type: z.literal("prediction_market"),
|
|
128
|
-
data: z.object({
|
|
129
|
-
source: z.enum([
|
|
130
|
-
"kalshi",
|
|
131
|
-
"polymarket"
|
|
132
|
-
]),
|
|
133
|
-
marketKey: z.string().min(1),
|
|
134
|
-
threshold: TriggerThreshold
|
|
135
|
-
})
|
|
136
|
-
});
|
|
137
|
-
const RatioCloseTrailing = z.object({
|
|
138
|
-
type: z.literal("ratio_trailing"),
|
|
139
|
-
data: z.object({
|
|
140
|
-
priceSource: PriceSource,
|
|
141
|
-
symbol_a: InstrumentId,
|
|
142
|
-
symbol_b: InstrumentId
|
|
143
|
-
}).superRefine(RefineTwoUniqueSymbols)
|
|
144
|
-
});
|
|
145
|
-
const PriceCloseTrailing = z.object({
|
|
146
|
-
type: z.literal("price_trailing"),
|
|
147
|
-
data: z.object({
|
|
148
|
-
priceSource: PriceSource,
|
|
149
|
-
symbol: InstrumentId
|
|
150
|
-
})
|
|
151
|
-
});
|
|
152
|
-
const WeightedRatioCloseTrailing = z.object({
|
|
153
|
-
type: z.literal("weighted_ratio_trailing"),
|
|
154
|
-
data: z.object({
|
|
155
|
-
priceSource: PriceSource,
|
|
156
|
-
basket: WeightedRatioBasket
|
|
157
|
-
})
|
|
158
|
-
});
|
|
159
|
-
const NotionalCloseTrailing = z.object({
|
|
160
|
-
type: z.literal("notional_trailing"),
|
|
161
|
-
data: z.object({
|
|
162
|
-
priceSource: PriceSource
|
|
163
|
-
})
|
|
164
|
-
});
|
|
165
|
-
const UpnlCloseTrailing = z.object({
|
|
166
|
-
type: z.literal("upnl_trailing"),
|
|
167
|
-
data: z.object({
|
|
168
|
-
priceSource: PriceSource
|
|
169
|
-
})
|
|
170
|
-
});
|
|
171
|
-
const UpnlBpsCloseTrailing = z.object({
|
|
172
|
-
type: z.literal("upnl_bps_trailing"),
|
|
173
|
-
data: z.object({
|
|
174
|
-
priceSource: PriceSource
|
|
175
|
-
})
|
|
176
|
-
});
|
|
177
|
-
const CreateTriggerConditionOpen = z.discriminatedUnion("type", [
|
|
178
|
-
RatioOpen,
|
|
179
|
-
PriceOpen,
|
|
180
|
-
WeightedRatioOpen,
|
|
181
|
-
FundingRateOpen,
|
|
182
|
-
PredictionMarketOpen,
|
|
183
|
-
BtcDominanceOpen
|
|
184
|
-
]);
|
|
185
|
-
const CreateTriggerConditionCloseStatic = z.discriminatedUnion("type", [
|
|
186
|
-
RatioCloseStatic,
|
|
187
|
-
PriceCloseStatic,
|
|
188
|
-
WeightedRatioCloseStatic,
|
|
189
|
-
NotionalCloseStatic,
|
|
190
|
-
UpnlCloseStatic,
|
|
191
|
-
UpnlBpsCloseStatic,
|
|
192
|
-
PredictionMarketCloseStatic
|
|
193
|
-
]);
|
|
194
|
-
const CreateTriggerConditionCloseTrailing = z.discriminatedUnion("type", [
|
|
195
|
-
RatioCloseTrailing,
|
|
196
|
-
PriceCloseTrailing,
|
|
197
|
-
WeightedRatioCloseTrailing,
|
|
198
|
-
NotionalCloseTrailing,
|
|
199
|
-
UpnlCloseTrailing,
|
|
200
|
-
UpnlBpsCloseTrailing
|
|
201
|
-
]);
|
|
202
|
-
const CreateTriggerConditionAttachStatic = z.discriminatedUnion("type", [
|
|
203
|
-
NotionalCloseStatic,
|
|
204
|
-
UpnlCloseStatic,
|
|
205
|
-
UpnlBpsCloseStatic
|
|
206
|
-
]);
|
|
207
|
-
const CreateTriggerConditionAttachTrailing = z.discriminatedUnion("type", [
|
|
208
|
-
NotionalCloseTrailing,
|
|
209
|
-
UpnlCloseTrailing,
|
|
210
|
-
UpnlBpsCloseTrailing
|
|
211
|
-
]);
|
|
212
|
-
|
|
213
|
-
export { CreateTriggerConditionAttachStatic, CreateTriggerConditionAttachTrailing, CreateTriggerConditionCloseStatic, CreateTriggerConditionCloseTrailing, CreateTriggerConditionOpen };
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { ClientIdCode } from '../../common/client-id';
|
|
3
|
-
import { RefineMinimumOneSymbol, RefineUniqueSymbols } from '../../common/refinement';
|
|
4
|
-
import { TradeLegPostOnly } from '../../common/trade-legs';
|
|
5
|
-
import { TWAPRandomization, DEFAULT_TWAP_RANDOMIZATION } from '../../schedule/randomization';
|
|
6
|
-
import { TWAPSliceIntervalSec, MIN_TWAP_SLICE_INTERVAL_SEC, FINAL_TWAP_SLICE_START_HEADROOM_SEC, MAX_TWAP_DURATION_SEC, TWAPTargetNotional, TriggerTWAPOpenLegs } from '../../schedule/twap-config';
|
|
7
|
-
import { TrailingMode, TpSlBracketType, BracketType } from '../common';
|
|
8
|
-
import { RefineStaticLogicalRules } from '../refinement/static.refinement';
|
|
9
|
-
import { RefineTrailingConfig, RefineTrailingLogicalRules } from '../refinement/trailing.refinement';
|
|
10
|
-
import { CreateTriggerConditionAttachStatic, CreateTriggerConditionAttachTrailing, CreateTriggerConditionOpen, CreateTriggerConditionCloseStatic, CreateTriggerConditionCloseTrailing } from './conditions';
|
|
11
|
-
import { MAX_ATTACH_TRIGGERS } from './config';
|
|
12
|
-
|
|
13
|
-
var __defProp = Object.defineProperty;
|
|
14
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
-
const CreateTriggerMarketPayload = z.object({
|
|
16
|
-
type: z.literal("MARKET"),
|
|
17
|
-
legs: z.tuple([
|
|
18
|
-
TradeLegPostOnly.strict()
|
|
19
|
-
]).rest(TradeLegPostOnly.strict()).superRefine(RefineMinimumOneSymbol).superRefine(RefineUniqueSymbols).describe("Array of legs to make up the exposure")
|
|
20
|
-
}).strict();
|
|
21
|
-
const CreateTriggerTWAPConfig = z.object({
|
|
22
|
-
type: z.literal("TWAP"),
|
|
23
|
-
durationSec: z.int().min(MIN_TWAP_SLICE_INTERVAL_SEC + FINAL_TWAP_SLICE_START_HEADROOM_SEC).max(MAX_TWAP_DURATION_SEC),
|
|
24
|
-
sliceIntervalSec: TWAPSliceIntervalSec,
|
|
25
|
-
randomization: TWAPRandomization.optional().default(DEFAULT_TWAP_RANDOMIZATION)
|
|
26
|
-
}).strict().refine((payload) => payload.durationSec >= payload.sliceIntervalSec + FINAL_TWAP_SLICE_START_HEADROOM_SEC, {
|
|
27
|
-
message: `TWAP duration must leave ${FINAL_TWAP_SLICE_START_HEADROOM_SEC} seconds after the first slice`,
|
|
28
|
-
path: [
|
|
29
|
-
"durationSec"
|
|
30
|
-
]
|
|
31
|
-
});
|
|
32
|
-
const CreateTriggerTWAPAdjustPayload = CreateTriggerTWAPConfig.safeExtend({
|
|
33
|
-
legs: TriggerTWAPOpenLegs,
|
|
34
|
-
targetNotional: TWAPTargetNotional
|
|
35
|
-
});
|
|
36
|
-
const TrailingConfig = z.object({
|
|
37
|
-
mode: TrailingMode,
|
|
38
|
-
deltaValue: z.number(),
|
|
39
|
-
activationValue: z.number().optional()
|
|
40
|
-
}).superRefine(RefineTrailingConfig);
|
|
41
|
-
const AttachTriggerMarketCloseStatic = z.object({
|
|
42
|
-
intent: z.literal("CLOSE"),
|
|
43
|
-
type: z.literal("MARKET"),
|
|
44
|
-
bracketType: TpSlBracketType,
|
|
45
|
-
condition: CreateTriggerConditionAttachStatic
|
|
46
|
-
}).superRefine(RefineStaticLogicalRules);
|
|
47
|
-
const AttachTriggerMarketCloseTrailing = z.object({
|
|
48
|
-
intent: z.literal("CLOSE"),
|
|
49
|
-
type: z.literal("MARKET"),
|
|
50
|
-
condition: CreateTriggerConditionAttachTrailing,
|
|
51
|
-
trailing: TrailingConfig
|
|
52
|
-
}).superRefine(RefineTrailingLogicalRules);
|
|
53
|
-
const AttachTriggerMarketClose = z.union([
|
|
54
|
-
AttachTriggerMarketCloseStatic,
|
|
55
|
-
AttachTriggerMarketCloseTrailing
|
|
56
|
-
]);
|
|
57
|
-
const AttachTriggerMarketCloseList = z.array(AttachTriggerMarketClose).max(MAX_ATTACH_TRIGGERS, `At most ${MAX_ATTACH_TRIGGERS} close triggers can be attached.`).superRefine((attachTriggers, ctx) => {
|
|
58
|
-
const trailingCount = attachTriggers.filter(isAttachTriggerMarketCloseTrailing).length;
|
|
59
|
-
if (trailingCount > 1) {
|
|
60
|
-
ctx.addIssue({
|
|
61
|
-
code: "custom",
|
|
62
|
-
message: "At most one trailing close trigger can be attached."
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
const CreateTriggerMarketOpen = z.object({
|
|
67
|
-
intent: z.literal("OPEN"),
|
|
68
|
-
type: z.literal("MARKET"),
|
|
69
|
-
condition: CreateTriggerConditionOpen,
|
|
70
|
-
attachTriggers: AttachTriggerMarketCloseList.optional(),
|
|
71
|
-
payload: CreateTriggerMarketPayload,
|
|
72
|
-
/**
|
|
73
|
-
* Attribution route code (client_ids.code)
|
|
74
|
-
*/
|
|
75
|
-
clientId: ClientIdCode
|
|
76
|
-
}).strict();
|
|
77
|
-
const CreateTriggerMarketAdjust = z.object({
|
|
78
|
-
intent: z.literal("ADJUST"),
|
|
79
|
-
type: z.literal("MARKET"),
|
|
80
|
-
positionId: z.uuid(),
|
|
81
|
-
condition: CreateTriggerConditionOpen,
|
|
82
|
-
payload: CreateTriggerMarketPayload,
|
|
83
|
-
/**
|
|
84
|
-
* Attribution route code (client_ids.code)
|
|
85
|
-
*/
|
|
86
|
-
clientId: ClientIdCode
|
|
87
|
-
}).strict();
|
|
88
|
-
const CreateTriggerTWAPAdjust = z.object({
|
|
89
|
-
intent: z.literal("ADJUST"),
|
|
90
|
-
type: z.literal("TWAP"),
|
|
91
|
-
positionId: z.uuid(),
|
|
92
|
-
condition: CreateTriggerConditionOpen,
|
|
93
|
-
payload: CreateTriggerTWAPAdjustPayload,
|
|
94
|
-
/**
|
|
95
|
-
* Attribution route code (client_ids.code)
|
|
96
|
-
*/
|
|
97
|
-
clientId: ClientIdCode
|
|
98
|
-
}).strict();
|
|
99
|
-
const CreateTriggerMarketCloseStatic = z.object({
|
|
100
|
-
intent: z.literal("CLOSE"),
|
|
101
|
-
type: z.literal("MARKET"),
|
|
102
|
-
positionId: z.uuid(),
|
|
103
|
-
bracketType: BracketType,
|
|
104
|
-
// User intent when bracketType is a side-dependent price-crossing encoding.
|
|
105
|
-
// Optional so older clients remain wire-compatible during rollout.
|
|
106
|
-
semanticBracketType: TpSlBracketType.optional(),
|
|
107
|
-
condition: CreateTriggerConditionCloseStatic,
|
|
108
|
-
/**
|
|
109
|
-
* Attribution route code (client_ids.code)
|
|
110
|
-
*/
|
|
111
|
-
clientId: ClientIdCode
|
|
112
|
-
}).superRefine(RefineStaticLogicalRules);
|
|
113
|
-
const CreateTriggerMarketCloseTrailing = z.object({
|
|
114
|
-
intent: z.literal("CLOSE"),
|
|
115
|
-
type: z.literal("MARKET"),
|
|
116
|
-
positionId: z.uuid(),
|
|
117
|
-
condition: CreateTriggerConditionCloseTrailing,
|
|
118
|
-
trailing: TrailingConfig,
|
|
119
|
-
/**
|
|
120
|
-
* Attribution route code (client_ids.code)
|
|
121
|
-
*/
|
|
122
|
-
clientId: ClientIdCode
|
|
123
|
-
}).superRefine(RefineTrailingLogicalRules);
|
|
124
|
-
const CreateTriggerMarketClose = z.union([
|
|
125
|
-
CreateTriggerMarketCloseStatic,
|
|
126
|
-
CreateTriggerMarketCloseTrailing
|
|
127
|
-
]);
|
|
128
|
-
const CreateTriggerTWAPCloseStatic = z.object({
|
|
129
|
-
intent: z.literal("CLOSE"),
|
|
130
|
-
type: z.literal("TWAP"),
|
|
131
|
-
positionId: z.uuid(),
|
|
132
|
-
bracketType: BracketType,
|
|
133
|
-
semanticBracketType: TpSlBracketType.optional(),
|
|
134
|
-
condition: CreateTriggerConditionCloseStatic,
|
|
135
|
-
payload: CreateTriggerTWAPConfig,
|
|
136
|
-
/**
|
|
137
|
-
* Attribution route code (client_ids.code)
|
|
138
|
-
*/
|
|
139
|
-
clientId: ClientIdCode
|
|
140
|
-
}).strict().superRefine(RefineStaticLogicalRules);
|
|
141
|
-
const CreateTriggerTWAPCloseTrailing = z.object({
|
|
142
|
-
intent: z.literal("CLOSE"),
|
|
143
|
-
type: z.literal("TWAP"),
|
|
144
|
-
positionId: z.uuid(),
|
|
145
|
-
condition: CreateTriggerConditionCloseTrailing,
|
|
146
|
-
trailing: TrailingConfig,
|
|
147
|
-
payload: CreateTriggerTWAPConfig,
|
|
148
|
-
/**
|
|
149
|
-
* Attribution route code (client_ids.code)
|
|
150
|
-
*/
|
|
151
|
-
clientId: ClientIdCode
|
|
152
|
-
}).strict().superRefine(RefineTrailingLogicalRules);
|
|
153
|
-
const CreateTriggerTWAPClose = z.union([
|
|
154
|
-
CreateTriggerTWAPCloseStatic,
|
|
155
|
-
CreateTriggerTWAPCloseTrailing
|
|
156
|
-
]);
|
|
157
|
-
const CreateTriggerOpen = z.discriminatedUnion("type", [
|
|
158
|
-
z.discriminatedUnion("intent", [
|
|
159
|
-
CreateTriggerMarketOpen,
|
|
160
|
-
CreateTriggerMarketAdjust
|
|
161
|
-
]),
|
|
162
|
-
CreateTriggerTWAPAdjust
|
|
163
|
-
]);
|
|
164
|
-
const CreateTriggerClose = z.union([
|
|
165
|
-
CreateTriggerMarketClose,
|
|
166
|
-
CreateTriggerTWAPClose
|
|
167
|
-
]);
|
|
168
|
-
function isAttachTriggerMarketCloseTrailing(attachedTrigger) {
|
|
169
|
-
return "trailing" in attachedTrigger && attachedTrigger.trailing !== void 0;
|
|
170
|
-
}
|
|
171
|
-
__name(isAttachTriggerMarketCloseTrailing, "isAttachTriggerMarketCloseTrailing");
|
|
172
|
-
|
|
173
|
-
export { AttachTriggerMarketClose, AttachTriggerMarketCloseList, AttachTriggerMarketCloseStatic, AttachTriggerMarketCloseTrailing, CreateTriggerClose, CreateTriggerMarketAdjust, CreateTriggerMarketClose, CreateTriggerMarketCloseStatic, CreateTriggerMarketCloseTrailing, CreateTriggerMarketOpen, CreateTriggerOpen, CreateTriggerTWAPAdjust, CreateTriggerTWAPClose, CreateTriggerTWAPCloseStatic, CreateTriggerTWAPCloseTrailing, TrailingConfig, isAttachTriggerMarketCloseTrailing };
|
package/dist/trigger/queries.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { normalizeArray, CursorFindParams } from '../common';
|
|
3
|
-
import { Connector } from '../connector';
|
|
4
|
-
|
|
5
|
-
const StatusEnum = z.enum([
|
|
6
|
-
"ACTIVE",
|
|
7
|
-
"COMPLETED",
|
|
8
|
-
"CANCELLED"
|
|
9
|
-
]);
|
|
10
|
-
const StatusArray = z.preprocess((arg) => normalizeArray(arg), z.array(StatusEnum));
|
|
11
|
-
const TriggerListParams = CursorFindParams.extend({
|
|
12
|
-
connector: Connector.optional(),
|
|
13
|
-
status: StatusArray.optional()
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export { TriggerListParams };
|