nexustrade 0.1.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.
@@ -0,0 +1,1487 @@
1
+ /* eslint-disable */
2
+ // GENERATED by src/scripts/codegen/generateNtSdk.ts — do not edit by hand.
3
+ // Regenerate: cd server && npx ts-node src/scripts/codegen/generateNtSdk.ts
4
+ export const CANDIDATE = { __candidate: true };
5
+ /** Portfolio-wide targetAssets: [] — rebalance cadence, not per-ticker DCA. */
6
+ export const PORTFOLIO_WIDE = { __portfolioWide: true };
7
+ function isCandidate(a) {
8
+ return typeof a === "object" && a !== null && a.__candidate === true;
9
+ }
10
+ function isPortfolioWide(a) {
11
+ return typeof a === "object" && a !== null && a.__portfolioWide === true;
12
+ }
13
+ /** Crypto ticker aliases for cryptoAsset() (BTC → BTC-USD). */
14
+ const CRYPTO_SYMBOL_ALIASES = {
15
+ BTC: "BTC-USD",
16
+ ETH: "ETH-USD",
17
+ SOL: "SOL-USD",
18
+ DOGE: "DOGE-USD",
19
+ ADA: "ADA-USD",
20
+ XRP: "XRP-USD",
21
+ AVAX: "AVAX-USD",
22
+ LINK: "LINK-USD",
23
+ DOT: "DOT-USD",
24
+ MATIC: "MATIC-USD",
25
+ "BTC-USD": "BTC-USD",
26
+ "ETH-USD": "ETH-USD",
27
+ "SOL-USD": "SOL-USD",
28
+ "DOGE-USD": "DOGE-USD",
29
+ "ADA-USD": "ADA-USD",
30
+ "XRP-USD": "XRP-USD",
31
+ "AVAX-USD": "AVAX-USD",
32
+ "LINK-USD": "LINK-USD",
33
+ "DOT-USD": "DOT-USD",
34
+ "MATIC-USD": "MATIC-USD",
35
+ };
36
+ function normalizeCryptoSymbol(symbol) {
37
+ const key = symbol.trim().toUpperCase();
38
+ if (CRYPTO_SYMBOL_ALIASES[key])
39
+ return CRYPTO_SYMBOL_ALIASES[key];
40
+ return null;
41
+ }
42
+ /**
43
+ * FormGroup.targetAssets reads `asset.name` (plural); targetAsset reads `symbol`
44
+ * (singular). Always set both so PositionValue / DaysSinceOrder round-trip.
45
+ * Bare ticker strings are rejected — use stockAsset() / cryptoAsset().
46
+ */
47
+ function toAsset(a) {
48
+ if (typeof a === "string") {
49
+ throw new Error('Bare ticker strings are not allowed (got ' +
50
+ JSON.stringify(a) +
51
+ '). Use stockAsset("AAPL") or cryptoAsset("BTC").');
52
+ }
53
+ if (isCandidate(a) || isPortfolioWide(a)) {
54
+ throw new Error("CANDIDATE / PORTFOLIO_WIDE are not concrete assets");
55
+ }
56
+ const asset = a;
57
+ const ticker = (asset.symbol || asset.name || "").trim().toUpperCase();
58
+ if (asset.type === "Cryptocurrency") {
59
+ const sym = normalizeCryptoSymbol(ticker) ?? (ticker.endsWith("-USD") ? ticker : ticker + "-USD");
60
+ return { type: "Cryptocurrency", symbol: sym, name: sym };
61
+ }
62
+ return { type: asset.type, symbol: ticker, name: asset.name || ticker };
63
+ }
64
+ /** Equity/ETF asset — required for stock/ETF buy/sell/indicators. */
65
+ export const stockAsset = (symbol) => {
66
+ const sym = symbol.trim().toUpperCase();
67
+ return { type: "Stock", symbol: sym, name: sym };
68
+ };
69
+ /** Cryptocurrency asset (BTC → BTC-USD) — required for crypto buy/sell/indicators. */
70
+ export const cryptoAsset = (symbol) => {
71
+ const cryptoSym = normalizeCryptoSymbol(symbol) ?? (symbol.trim().toUpperCase() + "-USD");
72
+ return { type: "Cryptocurrency", symbol: cryptoSym, name: cryptoSym };
73
+ };
74
+ /** Attach an asset field, or omit it entirely when bound to the pipeline candidate. */
75
+ function setAsset(target, key, a) {
76
+ if (isCandidate(a) || isPortfolioWide(a))
77
+ return;
78
+ target[key] = toAsset(a);
79
+ }
80
+ function setAssets(target, key, list) {
81
+ if (list === undefined)
82
+ return;
83
+ // Explicit portfolio-wide: empty array on the wire (YAML targetAssets: []).
84
+ if (isPortfolioWide(list) || (Array.isArray(list) && list.length === 0)) {
85
+ target[key] = [];
86
+ return;
87
+ }
88
+ const arr = Array.isArray(list) ? list : [list];
89
+ if (arr.some(isPortfolioWide)) {
90
+ target[key] = [];
91
+ return;
92
+ }
93
+ target[key] = arr.filter((a) => !isCandidate(a)).map(toAsset);
94
+ }
95
+ /**
96
+ * Drop undefined keys so optional args never serialise as explicit nulls.
97
+ * Constrained to `object`, not `Record<string, unknown>`: declared interfaces
98
+ * have no index signature, so the stricter bound rejects any typed config
99
+ * (e.g. againstParent(OptionPositionSelector)) that is not an object literal.
100
+ */
101
+ function compact(obj) {
102
+ const source = obj;
103
+ const out = {};
104
+ for (const key of Object.keys(source)) {
105
+ if (source[key] !== undefined)
106
+ out[key] = source[key];
107
+ }
108
+ return out;
109
+ }
110
+ function compare(lhs, rhs, comparison) {
111
+ const right = typeof rhs === "number" ? Value(rhs) : rhs;
112
+ return { type: "Base", lhs, comparison, rhs: right };
113
+ }
114
+ export const gt = (l, r) => compare(l, r, "greaterThan");
115
+ export const lt = (l, r) => compare(l, r, "lessThan");
116
+ export const gte = (l, r) => compare(l, r, "greaterThanOrEqual");
117
+ export const lte = (l, r) => compare(l, r, "lessThanOrEqual");
118
+ export const eq = (l, r) => compare(l, r, "equal");
119
+ export const neq = (l, r) => compare(l, r, "notEqual");
120
+ export const and = (...conditions) => ({ type: "And", conditions });
121
+ export const or = (...conditions) => ({ type: "Or", conditions });
122
+ /** Multi: true when at least `count` of `conditions` hold. */
123
+ export const atLeast = (count, ...conditions) => ({ type: "Multi", comparison: "greaterThanOrEqual", value: count, conditions });
124
+ /** Multi: true when at most `count` of `conditions` hold. */
125
+ export const atMost = (count, ...conditions) => ({ type: "Multi", comparison: "lessThanOrEqual", value: count, conditions });
126
+ /** Multi: true when fewer than `count` of `conditions` hold. */
127
+ export const fewerThan = (count, ...conditions) => ({ type: "Multi", comparison: "lessThan", value: count, conditions });
128
+ /** Multi: true when exactly `count` of `conditions` hold. */
129
+ export const exactly = (count, ...conditions) => ({ type: "Multi", comparison: "equal", value: count, conditions });
130
+ /** Multi with an explicit Comparator (same wire shape as YAML Multi). */
131
+ export const multi = (count, comparison, ...conditions) => ({ type: "Multi", comparison, value: count, conditions });
132
+ /** Always-true gate for strategies whose cadence lives in the pipeline. */
133
+ export const always = () => compare(Value(1), Value(0), "greaterThan");
134
+ export const filter = (condition) => ({ type: "Filter", condition });
135
+ export const selectTop = (metric, limit, direction = "Highest") => ({ type: "SelectTop", metric, limit, direction });
136
+ export const selectPercentile = (metric, percentile, direction = "Highest") => ({ type: "SelectPercentile", metric, percentile, direction });
137
+ export function universe(source, assets) {
138
+ if (source === "SPECIFIC_ASSETS") {
139
+ return { source, assets: (assets ?? []).map(toAsset) };
140
+ }
141
+ return { source };
142
+ }
143
+ // ---- equity + cash actions ----
144
+ export const buy = (target, amount, type = "percent of portfolio") => ({ type: "Buy", targetAsset: toAsset(target), amount: { type, amount } });
145
+ export const sell = (target, amount, type = "percent of portfolio") => ({ type: "Sell", targetAsset: toAsset(target), amount: { type, amount } });
146
+ export const deposit = (amount, type = "dollars") => ({ type: "Deposit", amount: { type, amount } });
147
+ export const withdraw = (amount, type = "dollars") => ({ type: "Withdraw", amount: { type, amount } });
148
+ export const alert = (message) => ({ type: "Alert", message });
149
+ export const launchAgent = (config) => compact({ type: "LaunchAgent", ...config });
150
+ export const dynamicRebalance = (config) => compact({ type: "DynamicRebalance", ...config });
151
+ // ---- options ----
152
+ /**
153
+ * One leg of a spread. Distance is signed from ATM; 0 is ATM.
154
+ * Delta targeting is a discriminated union: distanceType: "delta" requires
155
+ * fallbackDistance+fallbackDistanceType OR fallbackStrikeSelector.
156
+ */
157
+ export const leg = (config) => {
158
+ const distanceType = config.distanceType ?? "percent";
159
+ if (distanceType === "delta") {
160
+ const hasFallback = config.fallbackStrikeSelector !== undefined ||
161
+ (config.fallbackDistance !== undefined && config.fallbackDistanceType !== undefined);
162
+ if (!hasFallback) {
163
+ throw new Error('leg({ distanceType: "delta" }) requires fallbackDistance+fallbackDistanceType or fallbackStrikeSelector');
164
+ }
165
+ }
166
+ const strikeSelector = {
167
+ distanceType,
168
+ distance: config.distance,
169
+ };
170
+ const fallbackStrikeSelector = config.fallbackStrikeSelector ??
171
+ (config.fallbackDistance !== undefined
172
+ ? {
173
+ distanceType: config.fallbackDistanceType ?? "percent",
174
+ distance: config.fallbackDistance,
175
+ }
176
+ : undefined);
177
+ return compact({
178
+ optionType: config.optionType,
179
+ direction: config.direction,
180
+ expirationSelector: {
181
+ minDaysToExpiration: config.minDaysToExpiration,
182
+ maxDaysToExpiration: config.maxDaysToExpiration,
183
+ preference: config.preference ?? "nearest",
184
+ },
185
+ strikeSelector,
186
+ fallbackStrikeSelector,
187
+ strikeRange: config.strikeRange,
188
+ expirationRange: config.expirationRange,
189
+ ratio: config.ratio,
190
+ greekFilter: config.greekFilter,
191
+ });
192
+ };
193
+ export const optionsBuilder = (config) => compact(config);
194
+ export const againstParent = (config) => compact(config);
195
+ export const openOption = (config) => compact({ type: "OpenOption", ...config });
196
+ export const structureTemplate = (config) => compact(config);
197
+ export const sleeve = (config) => compact(config);
198
+ /**
199
+ * Rank a universe and rotate an option book. Keep take-profit / stop-loss / DTE
200
+ * exits in separate closeOption strategies, not here.
201
+ */
202
+ export const rebalanceOption = (config) => compact({ type: "RebalanceOption", ...config });
203
+ export const pnlTrigger = (bounds) => compact({ type: "pnl", ...bounds });
204
+ export const dteTrigger = (bounds) => compact({ type: "dte", ...bounds });
205
+ export const daysHeldTrigger = (bounds) => compact({ type: "daysHeld", ...bounds });
206
+ export const greeksTrigger = (bounds) => compact({ type: "greeks", ...bounds });
207
+ export const closeOption = (config = {}) => compact({ type: "CloseOption", ...config });
208
+ // ---- assembly ----
209
+ export const strategy = (name, condition, action, options = {}) => compact({ name, condition, action, ...options });
210
+ /**
211
+ * Session / clock flatten — condition carries the gate (MinutesAfterOpen, Day, …).
212
+ * Never pairs with always(); PnL/DTE/daysHeld exits use closeOption({ triggers }).
213
+ * Book-level only — CandidateCondition is rejected (same as strategy when).
214
+ */
215
+ export const sessionFlatten = (condition, config = {}, name = "Session flatten") => strategy(name, condition, closeOption({ ...config }));
216
+ export const portfolio = (name, strategies, options = {}) => compact({ name, initialValue: 10000, ...options, strategies });
217
+ // ---- generated indicator builders ----
218
+ /**
219
+ * AbsoluteValue indicator.
220
+ */
221
+ export function AbsoluteValue(operand) {
222
+ const d = { type: "AbsoluteValue" };
223
+ d.indicators = [operand];
224
+ return d;
225
+ }
226
+ /**
227
+ * AverageTrueRange indicator.
228
+ * @param asset Ticker name (ex. SPY, BTC)
229
+ * @param length Length of time
230
+ * @param interval Unit of time
231
+ */
232
+ export function AverageTrueRange(asset, length = 14, interval = "Day") {
233
+ const d = { type: "AverageTrueRange" };
234
+ setAsset(d, "targetAsset", asset);
235
+ d.window = { length: length, interval: interval };
236
+ return d;
237
+ }
238
+ /**
239
+ * BearishFairValueGap indicator.
240
+ * @param asset Ticker name (ex. SPY, BTC)
241
+ */
242
+ export function BearishFairValueGap(asset) {
243
+ const d = { type: "BearishFairValueGap" };
244
+ setAsset(d, "targetAsset", asset);
245
+ return d;
246
+ }
247
+ /**
248
+ * BollingerBand indicator.
249
+ * @param asset Ticker name (ex. SPY, BTC)
250
+ * @param length Length of time
251
+ * @param interval Unit of time
252
+ * @param numStandardDeviations How many standard deviations from the mean
253
+ */
254
+ export function BollingerBand(asset, length = 30, interval = "Day", numStandardDeviations = 1) {
255
+ const d = { type: "BollingerBand" };
256
+ setAsset(d, "targetAsset", asset);
257
+ d["numStandardDeviations"] = numStandardDeviations;
258
+ d.window = { length: length, interval: interval };
259
+ return d;
260
+ }
261
+ export const BBand = BollingerBand;
262
+ /**
263
+ * BullishFairValueGap indicator.
264
+ * @param asset Ticker name (ex. SPY, BTC)
265
+ */
266
+ export function BullishFairValueGap(asset) {
267
+ const d = { type: "BullishFairValueGap" };
268
+ setAsset(d, "targetAsset", asset);
269
+ return d;
270
+ }
271
+ /**
272
+ * BuyingPower indicator.
273
+ */
274
+ export function BuyingPower() {
275
+ const d = { type: "BuyingPower" };
276
+ return d;
277
+ }
278
+ /**
279
+ * CompoundAnnualGrowthRate indicator.
280
+ * @param asset Ticker name (ex. SPY, BTC)
281
+ * @param metric The fundamental metric to use
282
+ * @param years Floating point years value
283
+ */
284
+ export function CompoundAnnualGrowthRate(asset, metric, years) {
285
+ const d = { type: "CompoundAnnualGrowthRate" };
286
+ setAsset(d, "targetAsset", asset);
287
+ d["metric"] = metric;
288
+ d["years"] = years;
289
+ return d;
290
+ }
291
+ /**
292
+ * ConsecutiveTrue indicator.
293
+ * @param condition Condition evaluated over the window.
294
+ * @param length Length of time
295
+ * @param interval Unit of time
296
+ */
297
+ export function ConsecutiveTrue(condition, length = 1, interval = "Day") {
298
+ const d = { type: "ConsecutiveTrue" };
299
+ d.condition = condition;
300
+ d.window = { length: length, interval: interval };
301
+ return d;
302
+ }
303
+ /**
304
+ * CountTrue indicator.
305
+ * @param condition Condition evaluated over the window.
306
+ * @param length Length of time
307
+ * @param interval Unit of time
308
+ */
309
+ export function CountTrue(condition, length = 1, interval = "Day") {
310
+ const d = { type: "CountTrue" };
311
+ d.condition = condition;
312
+ d.window = { length: length, interval: interval };
313
+ return d;
314
+ }
315
+ /**
316
+ * CrossAbove indicator.
317
+ */
318
+ export function CrossAbove(left, right) {
319
+ const d = { type: "CrossAbove" };
320
+ d.indicators = [left, right];
321
+ return d;
322
+ }
323
+ /**
324
+ * CrossBelow indicator.
325
+ */
326
+ export function CrossBelow(left, right) {
327
+ const d = { type: "CrossBelow" };
328
+ d.indicators = [left, right];
329
+ return d;
330
+ }
331
+ /**
332
+ * CurrentTimeHours indicator.
333
+ */
334
+ export function CurrentTimeHours() {
335
+ const d = { type: "CurrentTimeHours" };
336
+ return d;
337
+ }
338
+ /**
339
+ * CurrentTimeMinutes indicator.
340
+ */
341
+ export function CurrentTimeMinutes() {
342
+ const d = { type: "CurrentTimeMinutes" };
343
+ return d;
344
+ }
345
+ /**
346
+ * CurrentTimeSeconds indicator.
347
+ */
348
+ export function CurrentTimeSeconds() {
349
+ const d = { type: "CurrentTimeSeconds" };
350
+ return d;
351
+ }
352
+ /**
353
+ * CustomIndicator indicator.
354
+ * @param asset Pass CANDIDATE inside a rebalance pipeline to bind per candidate.
355
+ * @param customIndicatorId 24-char hex ObjectId of the owned series (list_custom_indicators).
356
+ */
357
+ export function CustomIndicator(asset, customIndicatorId) {
358
+ const d = { type: "CustomIndicator" };
359
+ setAsset(d, "targetAsset", asset);
360
+ d["customIndicatorId"] = customIndicatorId;
361
+ return d;
362
+ }
363
+ /**
364
+ * Date indicator.
365
+ */
366
+ export function Date() {
367
+ const d = { type: "Date" };
368
+ return d;
369
+ }
370
+ /**
371
+ * Day indicator.
372
+ */
373
+ export function Day() {
374
+ const d = { type: "Day" };
375
+ return d;
376
+ }
377
+ /**
378
+ * DaysSinceAgent indicator.
379
+ */
380
+ export function DaysSinceAgent() {
381
+ const d = { type: "DaysSinceAgent" };
382
+ return d;
383
+ }
384
+ /**
385
+ * DaysSinceAlert indicator.
386
+ * @param message (Optional) Message to display when the indicator is triggered
387
+ */
388
+ export function DaysSinceAlert(message) {
389
+ const d = { type: "DaysSinceAlert" };
390
+ d["message"] = message;
391
+ return d;
392
+ }
393
+ /**
394
+ * DaysSinceEarnings indicator.
395
+ * @param asset Ticker name (ex. SPY, BTC)
396
+ */
397
+ export function DaysSinceEarnings(asset) {
398
+ const d = { type: "DaysSinceEarnings" };
399
+ setAsset(d, "targetAsset", asset);
400
+ return d;
401
+ }
402
+ /**
403
+ * DaysSinceLastRebalanceOptionOrder indicator.
404
+ */
405
+ export function DaysSinceLastRebalanceOptionOrder() {
406
+ const d = { type: "DaysSinceLastRebalanceOptionOrder" };
407
+ return d;
408
+ }
409
+ /**
410
+ * DaysSinceOptionOrder indicator.
411
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
412
+ * @param optionType Filter by Call or Put. Leave empty for all.
413
+ * @param direction Filter by Long or Short. Leave empty for all.
414
+ * @param spreadType Filter by spread type. Leave empty for all.
415
+ * @param positionEffect Filter by Open (entering position) or Close (exiting). Leave empty for all.
416
+ * @param minDte Minimum days to expiration at order time. Leave empty for no minimum.
417
+ * @param maxDte Maximum days to expiration at order time. Leave empty for no maximum.
418
+ * @param orderStatus Matches option order events with this status
419
+ */
420
+ export function DaysSinceOptionOrder(underlying, optionType, direction, spreadType, positionEffect, minDte, maxDte, orderStatus = "Filled") {
421
+ const d = { type: "DaysSinceOptionOrder" };
422
+ d["underlying"] = underlying;
423
+ d["optionType"] = optionType;
424
+ d["direction"] = direction;
425
+ d["spreadType"] = spreadType;
426
+ d["positionEffect"] = positionEffect;
427
+ d["minDte"] = minDte;
428
+ d["maxDte"] = maxDte;
429
+ d["orderStatus"] = orderStatus;
430
+ return d;
431
+ }
432
+ /**
433
+ * DaysSinceOrder indicator.
434
+ * @param assets Ticker(s) whose orders are counted. One string or an array.
435
+ * @param side Buy or Sell
436
+ */
437
+ export function DaysSinceOrder(assets, side, orderStatus = "Filled") {
438
+ const d = { type: "DaysSinceOrder" };
439
+ setAssets(d, "targetAssets", assets);
440
+ d["side"] = side;
441
+ d["orderStatus"] = orderStatus;
442
+ return d;
443
+ }
444
+ /**
445
+ * DaysSinceStrategyFired indicator.
446
+ */
447
+ export function DaysSinceStrategyFired() {
448
+ const d = { type: "DaysSinceStrategyFired" };
449
+ return d;
450
+ }
451
+ /**
452
+ * DaysSinceTransaction indicator.
453
+ * @param transactionType Matches transaction events with this type (deposit or withdraw)
454
+ * @param transactionStatus Matches transaction events with this status
455
+ */
456
+ export function DaysSinceTransaction(transactionType, transactionStatus = "Completed") {
457
+ const d = { type: "DaysSinceTransaction" };
458
+ d["transactionType"] = transactionType;
459
+ d["transactionStatus"] = transactionStatus;
460
+ return d;
461
+ }
462
+ /**
463
+ * DaysUntilEarnings indicator.
464
+ * @param asset Ticker name (ex. SPY, BTC)
465
+ */
466
+ export function DaysUntilEarnings(asset) {
467
+ const d = { type: "DaysUntilEarnings" };
468
+ setAsset(d, "targetAsset", asset);
469
+ return d;
470
+ }
471
+ /**
472
+ * Divide indicator.
473
+ */
474
+ export function Divide(left, right) {
475
+ const d = { type: "Divide" };
476
+ d.indicators = [left, right];
477
+ return d;
478
+ }
479
+ /**
480
+ * Economic indicator.
481
+ * @param metric The economic indicator to use
482
+ */
483
+ export function Economic(metric) {
484
+ const d = { type: "Economic" };
485
+ d["metric"] = metric;
486
+ return d;
487
+ }
488
+ /**
489
+ * ExponentialMovingAverage indicator.
490
+ * @param asset Ticker name (ex. SPY, BTC)
491
+ * @param length Length of time
492
+ * @param interval Unit of time
493
+ */
494
+ export function ExponentialMovingAverage(asset, length, interval = "Day") {
495
+ const d = { type: "ExponentialMovingAverage" };
496
+ setAsset(d, "targetAsset", asset);
497
+ d.window = { length: length, interval: interval };
498
+ return d;
499
+ }
500
+ export const EMA = ExponentialMovingAverage;
501
+ /**
502
+ * Exponentiation indicator.
503
+ * @param exponent The exponent to raise the value to
504
+ */
505
+ export function Exponentiation(operand, exponent = 2) {
506
+ const d = { type: "Exponentiation" };
507
+ d["exponent"] = exponent;
508
+ d.indicators = [operand];
509
+ return d;
510
+ }
511
+ /**
512
+ * Fundamental indicator.
513
+ * @param asset Ticker name (ex. SPY, BTC)
514
+ * @param metric The fundamental metric to use
515
+ */
516
+ export function Fundamental(asset, metric) {
517
+ const d = { type: "Fundamental" };
518
+ setAsset(d, "targetAsset", asset);
519
+ d["metric"] = metric;
520
+ return d;
521
+ }
522
+ /**
523
+ * GapPercentage indicator.
524
+ * @param asset Ticker name (ex. SPY, BTC)
525
+ */
526
+ export function GapPercentage(asset) {
527
+ const d = { type: "GapPercentage" };
528
+ setAsset(d, "targetAsset", asset);
529
+ return d;
530
+ }
531
+ /**
532
+ * GapSize indicator.
533
+ * @param asset Ticker name (ex. SPY, BTC)
534
+ */
535
+ export function GapSize(asset) {
536
+ const d = { type: "GapSize" };
537
+ setAsset(d, "targetAsset", asset);
538
+ return d;
539
+ }
540
+ /**
541
+ * HighOfDay indicator.
542
+ * @param asset Ticker name (ex. SPY, BTC)
543
+ */
544
+ export function HighOfDay(asset) {
545
+ const d = { type: "HighOfDay" };
546
+ setAsset(d, "targetAsset", asset);
547
+ return d;
548
+ }
549
+ /**
550
+ * Index indicator.
551
+ * @param metric Ticker key matching hydrated index price data (add more in BigQuery + rehydrate as needed)
552
+ */
553
+ export function Index(metric = "VIX") {
554
+ const d = { type: "Index" };
555
+ d["metric"] = metric;
556
+ return d;
557
+ }
558
+ /**
559
+ * IndicatorAtMinutesAfterOpen indicator.
560
+ * @param minutesAfterOpen The number of minutes after market open to capture the indicator value
561
+ */
562
+ export function IndicatorAtMinutesAfterOpen(operand, minutesAfterOpen = 30) {
563
+ const d = { type: "IndicatorAtMinutesAfterOpen" };
564
+ d["minutesAfterOpen"] = minutesAfterOpen;
565
+ d.indicators = [operand];
566
+ return d;
567
+ }
568
+ /**
569
+ * IndicatorExponentialMovingAverage indicator.
570
+ * @param length Length of time
571
+ * @param interval Unit of time
572
+ */
573
+ export function IndicatorExponentialMovingAverage(operand, length = 30, interval = "Day") {
574
+ const d = { type: "IndicatorExponentialMovingAverage" };
575
+ d.indicators = [operand];
576
+ d.window = { length: length, interval: interval };
577
+ return d;
578
+ }
579
+ /**
580
+ * IndicatorMeanAbsoluteDeviation indicator.
581
+ * @param length Length of time
582
+ * @param interval Unit of time
583
+ */
584
+ export function IndicatorMeanAbsoluteDeviation(operand, length = 30, interval = "Day") {
585
+ const d = { type: "IndicatorMeanAbsoluteDeviation" };
586
+ d.indicators = [operand];
587
+ d.window = { length: length, interval: interval };
588
+ return d;
589
+ }
590
+ /**
591
+ * IndicatorRateOfChange indicator.
592
+ * @param length Length of time
593
+ * @param interval Unit of time
594
+ */
595
+ export function IndicatorRateOfChange(operand, length = 30, interval = "Day") {
596
+ const d = { type: "IndicatorRateOfChange" };
597
+ d.indicators = [operand];
598
+ d.window = { length: length, interval: interval };
599
+ return d;
600
+ }
601
+ /**
602
+ * IndicatorSimpleMovingAverage indicator.
603
+ * @param length Length of time
604
+ * @param interval Unit of time
605
+ */
606
+ export function IndicatorSimpleMovingAverage(operand, length = 30, interval = "Day") {
607
+ const d = { type: "IndicatorSimpleMovingAverage" };
608
+ d.indicators = [operand];
609
+ d.window = { length: length, interval: interval };
610
+ return d;
611
+ }
612
+ /**
613
+ * IndicatorStandardDeviation indicator.
614
+ * @param length Length of time
615
+ * @param interval Unit of time
616
+ */
617
+ export function IndicatorStandardDeviation(operand, length = 30, interval = "Day") {
618
+ const d = { type: "IndicatorStandardDeviation" };
619
+ d.indicators = [operand];
620
+ d.window = { length: length, interval: interval };
621
+ return d;
622
+ }
623
+ /**
624
+ * IndicatorWindowAgo indicator.
625
+ * @param length Length of time
626
+ * @param interval Unit of time
627
+ */
628
+ export function IndicatorWindowAgo(operand, length, interval) {
629
+ const d = { type: "IndicatorWindowAgo" };
630
+ d.indicators = [operand];
631
+ d.window = { length: length, interval: interval };
632
+ return d;
633
+ }
634
+ /**
635
+ * InitialValue indicator.
636
+ */
637
+ export function InitialValue() {
638
+ const d = { type: "InitialValue" };
639
+ return d;
640
+ }
641
+ /**
642
+ * IsAsset indicator.
643
+ * @param matchAsset The specific asset to compare against (ex. UPRO, GLD)
644
+ * @param asset Ticker name (ex. SPY, BTC)
645
+ */
646
+ export function IsAsset(matchAsset, asset) {
647
+ const d = { type: "IsAsset" };
648
+ setAsset(d, "matchAsset", matchAsset);
649
+ setAsset(d, "targetAsset", asset);
650
+ return d;
651
+ }
652
+ /**
653
+ * IsAssetType indicator.
654
+ * @param asset Ticker name (ex. SPY, BTC)
655
+ * @param assetType The asset type to check against
656
+ */
657
+ export function IsAssetType(asset, assetType = "Stock") {
658
+ const d = { type: "IsAssetType" };
659
+ setAsset(d, "targetAsset", asset);
660
+ d["assetType"] = assetType;
661
+ return d;
662
+ }
663
+ /**
664
+ * IsIndexMember indicator.
665
+ * @param asset Ticker name (ex. SPY, BTC)
666
+ * @param index The index to check membership against
667
+ */
668
+ export function IsIndexMember(asset, index = "SP500") {
669
+ const d = { type: "IsIndexMember" };
670
+ setAsset(d, "targetAsset", asset);
671
+ d["index"] = index;
672
+ return d;
673
+ }
674
+ /**
675
+ * IsIndustry indicator.
676
+ * @param asset Ticker name (ex. SPY, BTC)
677
+ * @param industry The industry to check membership against
678
+ */
679
+ export function IsIndustry(asset, industry) {
680
+ const d = { type: "IsIndustry" };
681
+ setAsset(d, "targetAsset", asset);
682
+ d["industry"] = { "informationTechnology": "technology", "personalAndHouseholdGoods": "householdProducts", "investing": "assetManagement", "spaceExploration": "space", "alternativeEnergy": "cleanEnergy", "clothesAndApparal": "fashionAndApparel", "computationalChemistry": "computationalDrugDiscovery", "customerEngagement": "customerExperienceSoftware", "dataVisualization": "analytics", "graphicsCard": "gpuAndAccelerators", "materialScience": "advancedMaterials", "medicine": "pharmaceuticals", "messaging": "collaborationSoftware", "phones": "consumerElectronics", "security": "cybersecurity", "socialNetwork": "socialMedia", "television": "streaming", "videoConferencing": "collaborationSoftware", "videos": "streaming", "waterPurifaction": "waterInfrastructure", "waterTreatment": "waterInfrastructure" }[industry] ?? industry;
683
+ return d;
684
+ }
685
+ /**
686
+ * IsNotAsset indicator.
687
+ * @param matchAsset The specific asset to compare against (ex. UPRO, GLD)
688
+ * @param asset Ticker name (ex. SPY, BTC)
689
+ */
690
+ export function IsNotAsset(matchAsset, asset) {
691
+ const d = { type: "IsNotAsset" };
692
+ setAsset(d, "matchAsset", matchAsset);
693
+ setAsset(d, "targetAsset", asset);
694
+ return d;
695
+ }
696
+ /**
697
+ * LastOrderPrice indicator.
698
+ * @param asset Ticker name (ex. SPY, BTC)
699
+ * @param side Matches order events with this side (buy or sell)
700
+ * @param orderStatus Matches order events with this status
701
+ */
702
+ export function LastOrderPrice(asset, side, orderStatus = "Filled") {
703
+ const d = { type: "LastOrderPrice" };
704
+ setAsset(d, "targetAsset", asset);
705
+ d["side"] = side;
706
+ d["orderStatus"] = orderStatus;
707
+ return d;
708
+ }
709
+ /**
710
+ * Log indicator.
711
+ * @param base The base for the logarithm
712
+ */
713
+ export function Log(operand, base = 10) {
714
+ const d = { type: "Log" };
715
+ d["base"] = base;
716
+ d.indicators = [operand];
717
+ return d;
718
+ }
719
+ /**
720
+ * LowOfDay indicator.
721
+ * @param asset Ticker name (ex. SPY, BTC)
722
+ */
723
+ export function LowOfDay(asset) {
724
+ const d = { type: "LowOfDay" };
725
+ setAsset(d, "targetAsset", asset);
726
+ return d;
727
+ }
728
+ /**
729
+ * Max indicator.
730
+ */
731
+ export function Max(left, right) {
732
+ const d = { type: "Max" };
733
+ d.indicators = [left, right];
734
+ return d;
735
+ }
736
+ /**
737
+ * MaxDrawdown indicator.
738
+ * @param asset Ticker name (ex. SPY, BTC)
739
+ * @param length Length of time
740
+ * @param interval Unit of time
741
+ */
742
+ export function MaxDrawdown(asset, length = 30, interval = "Day") {
743
+ const d = { type: "MaxDrawdown" };
744
+ setAsset(d, "targetAsset", asset);
745
+ d.window = { length: length, interval: interval };
746
+ return d;
747
+ }
748
+ /**
749
+ * MaxDrawup indicator.
750
+ * @param asset Ticker name (ex. SPY, BTC)
751
+ * @param length Length of time
752
+ * @param interval Unit of time
753
+ */
754
+ export function MaxDrawup(asset, length = 30, interval = "Day") {
755
+ const d = { type: "MaxDrawup" };
756
+ setAsset(d, "targetAsset", asset);
757
+ d.window = { length: length, interval: interval };
758
+ return d;
759
+ }
760
+ /**
761
+ * MaximumPrice indicator.
762
+ * @param asset Ticker name (ex. SPY, BTC)
763
+ * @param length Length of time
764
+ * @param interval Unit of time
765
+ */
766
+ export function MaximumPrice(asset, length = 30, interval = "Day") {
767
+ const d = { type: "MaximumPrice" };
768
+ setAsset(d, "targetAsset", asset);
769
+ d.window = { length: length, interval: interval };
770
+ return d;
771
+ }
772
+ /**
773
+ * Min indicator.
774
+ */
775
+ export function Min(left, right) {
776
+ const d = { type: "Min" };
777
+ d.indicators = [left, right];
778
+ return d;
779
+ }
780
+ /**
781
+ * MinimumPrice indicator.
782
+ * @param asset Ticker name (ex. SPY, BTC)
783
+ * @param length Length of time
784
+ * @param interval Unit of time
785
+ */
786
+ export function MinimumPrice(asset, length = 30, interval = "Day") {
787
+ const d = { type: "MinimumPrice" };
788
+ setAsset(d, "targetAsset", asset);
789
+ d.window = { length: length, interval: interval };
790
+ return d;
791
+ }
792
+ /**
793
+ * Minus indicator.
794
+ */
795
+ export function Minus(left, right) {
796
+ const d = { type: "Minus" };
797
+ d.indicators = [left, right];
798
+ return d;
799
+ }
800
+ /**
801
+ * MinutesAfterOpen indicator.
802
+ */
803
+ export function MinutesAfterOpen() {
804
+ const d = { type: "MinutesAfterOpen" };
805
+ return d;
806
+ }
807
+ /**
808
+ * MinutesSinceAgent indicator.
809
+ */
810
+ export function MinutesSinceAgent() {
811
+ const d = { type: "MinutesSinceAgent" };
812
+ return d;
813
+ }
814
+ /**
815
+ * MinutesSinceAlert indicator.
816
+ * @param message (Optional) Message to display when the indicator is triggered
817
+ */
818
+ export function MinutesSinceAlert(message) {
819
+ const d = { type: "MinutesSinceAlert" };
820
+ d["message"] = message;
821
+ return d;
822
+ }
823
+ /**
824
+ * MinutesSinceOptionOrder indicator.
825
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
826
+ * @param optionType Filter by Call or Put. Leave empty for all.
827
+ * @param direction Filter by Long or Short. Leave empty for all.
828
+ * @param spreadType Filter by spread type. Leave empty for all.
829
+ * @param positionEffect Filter by Open (entering position) or Close (exiting). Leave empty for all.
830
+ * @param minDte Minimum days to expiration at order time. Leave empty for no minimum.
831
+ * @param maxDte Maximum days to expiration at order time. Leave empty for no maximum.
832
+ * @param orderStatus Matches option order events with this status
833
+ */
834
+ export function MinutesSinceOptionOrder(underlying, optionType, direction, spreadType, positionEffect, minDte, maxDte, orderStatus = "Filled") {
835
+ const d = { type: "MinutesSinceOptionOrder" };
836
+ d["underlying"] = underlying;
837
+ d["optionType"] = optionType;
838
+ d["direction"] = direction;
839
+ d["spreadType"] = spreadType;
840
+ d["positionEffect"] = positionEffect;
841
+ d["minDte"] = minDte;
842
+ d["maxDte"] = maxDte;
843
+ d["orderStatus"] = orderStatus;
844
+ return d;
845
+ }
846
+ /**
847
+ * MinutesSinceOrder indicator.
848
+ * @param assets Ticker(s) whose orders are counted. One string or an array.
849
+ * @param side Buy or Sell
850
+ */
851
+ export function MinutesSinceOrder(assets, side, orderStatus = "Filled") {
852
+ const d = { type: "MinutesSinceOrder" };
853
+ setAssets(d, "targetAssets", assets);
854
+ d["side"] = side;
855
+ d["orderStatus"] = orderStatus;
856
+ return d;
857
+ }
858
+ /**
859
+ * MinutesUntilClose indicator.
860
+ */
861
+ export function MinutesUntilClose() {
862
+ const d = { type: "MinutesUntilClose" };
863
+ return d;
864
+ }
865
+ /**
866
+ * Month indicator.
867
+ */
868
+ export function Month() {
869
+ const d = { type: "Month" };
870
+ return d;
871
+ }
872
+ /**
873
+ * Multiply indicator.
874
+ */
875
+ export function Multiply(left, right) {
876
+ const d = { type: "Multiply" };
877
+ d.indicators = [left, right];
878
+ return d;
879
+ }
880
+ /**
881
+ * Negative indicator.
882
+ */
883
+ export function Negative(operand) {
884
+ const d = { type: "Negative" };
885
+ d.indicators = [operand];
886
+ return d;
887
+ }
888
+ /**
889
+ * OpeningPrice indicator.
890
+ * @param asset Ticker name (ex. SPY, BTC)
891
+ */
892
+ export function OpeningPrice(asset) {
893
+ const d = { type: "OpeningPrice" };
894
+ setAsset(d, "targetAsset", asset);
895
+ return d;
896
+ }
897
+ /**
898
+ * OptionCollateral indicator.
899
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
900
+ * @param optionType Filter by Call or Put. Leave empty for all.
901
+ * @param direction Filter by Long or Short. Leave empty for all.
902
+ * @param spreadType Filter by spread type. Leave empty for all.
903
+ */
904
+ export function OptionCollateral(underlying, optionType, direction, spreadType) {
905
+ const d = { type: "OptionCollateral" };
906
+ d["underlying"] = underlying;
907
+ d["optionType"] = optionType;
908
+ d["direction"] = direction;
909
+ d["spreadType"] = spreadType;
910
+ return d;
911
+ }
912
+ /**
913
+ * OptionDaysHeld indicator.
914
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
915
+ * @param optionType Filter by Call or Put. Leave empty for all.
916
+ * @param direction Filter by Long or Short. Leave empty for all.
917
+ * @param spreadType Filter by spread type. Leave empty for all.
918
+ * @param minOrMax Return minimum or maximum value across matching spreads.
919
+ */
920
+ export function OptionDaysHeld(underlying, optionType, direction, spreadType, minOrMax = "min") {
921
+ const d = { type: "OptionDaysHeld" };
922
+ d["underlying"] = underlying;
923
+ d["optionType"] = optionType;
924
+ d["direction"] = direction;
925
+ d["spreadType"] = spreadType;
926
+ d["minOrMax"] = minOrMax;
927
+ return d;
928
+ }
929
+ /**
930
+ * OptionDaysToExpiration indicator.
931
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
932
+ * @param optionType Filter by Call or Put. Leave empty for all.
933
+ * @param direction Filter by Long or Short. Leave empty for all.
934
+ * @param spreadType Filter by spread type. Leave empty for all.
935
+ * @param minOrMax Return minimum or maximum value across matching spreads.
936
+ */
937
+ export function OptionDaysToExpiration(underlying, optionType, direction, spreadType, minOrMax = "min") {
938
+ const d = { type: "OptionDaysToExpiration" };
939
+ d["underlying"] = underlying;
940
+ d["optionType"] = optionType;
941
+ d["direction"] = direction;
942
+ d["spreadType"] = spreadType;
943
+ d["minOrMax"] = minOrMax;
944
+ return d;
945
+ }
946
+ /**
947
+ * OptionGrossExposurePercent indicator.
948
+ */
949
+ export function OptionGrossExposurePercent() {
950
+ const d = { type: "OptionGrossExposurePercent" };
951
+ return d;
952
+ }
953
+ /**
954
+ * OptionPositionCount indicator.
955
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
956
+ * @param optionType Filter by Call or Put. Leave empty for all.
957
+ * @param direction Filter by Long or Short. Leave empty for all.
958
+ * @param spreadType Filter by spread type. Leave empty for all.
959
+ */
960
+ export function OptionPositionCount(underlying, optionType, direction, spreadType) {
961
+ const d = { type: "OptionPositionCount" };
962
+ d["underlying"] = underlying;
963
+ d["optionType"] = optionType;
964
+ d["direction"] = direction;
965
+ d["spreadType"] = spreadType;
966
+ return d;
967
+ }
968
+ /**
969
+ * OptionPositionMaxDrawdown indicator.
970
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
971
+ * @param optionType Filter by Call or Put. Leave empty for all.
972
+ * @param direction Filter by Long or Short. Leave empty for all.
973
+ * @param spreadType Filter by spread type. Leave empty for all.
974
+ */
975
+ export function OptionPositionMaxDrawdown(underlying, optionType, direction, spreadType) {
976
+ const d = { type: "OptionPositionMaxDrawdown" };
977
+ d["underlying"] = underlying;
978
+ d["optionType"] = optionType;
979
+ d["direction"] = direction;
980
+ d["spreadType"] = spreadType;
981
+ return d;
982
+ }
983
+ /**
984
+ * OptionPositionPercentChange indicator.
985
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
986
+ * @param optionType Filter by Call or Put. Leave empty for all.
987
+ * @param direction Filter by Long or Short. Leave empty for all.
988
+ * @param spreadType Filter by spread type. Leave empty for all.
989
+ */
990
+ export function OptionPositionPercentChange(underlying, optionType, direction, spreadType) {
991
+ const d = { type: "OptionPositionPercentChange" };
992
+ d["underlying"] = underlying;
993
+ d["optionType"] = optionType;
994
+ d["direction"] = direction;
995
+ d["spreadType"] = spreadType;
996
+ return d;
997
+ }
998
+ /**
999
+ * OptionPositionValue indicator.
1000
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
1001
+ * @param optionType Filter by Call or Put. Leave empty for all.
1002
+ * @param direction Filter by Long or Short. Leave empty for all.
1003
+ * @param spreadType Filter by spread type. Leave empty for all.
1004
+ */
1005
+ export function OptionPositionValue(underlying, optionType, direction, spreadType) {
1006
+ const d = { type: "OptionPositionValue" };
1007
+ d["underlying"] = underlying;
1008
+ d["optionType"] = optionType;
1009
+ d["direction"] = direction;
1010
+ d["spreadType"] = spreadType;
1011
+ return d;
1012
+ }
1013
+ /**
1014
+ * OptionSpreadCount indicator.
1015
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
1016
+ * @param optionType Filter by Call or Put. Leave empty for all.
1017
+ * @param direction Filter by Long or Short. Leave empty for all.
1018
+ * @param spreadType Filter by spread type. Leave empty for all.
1019
+ */
1020
+ export function OptionSpreadCount(underlying, optionType, direction, spreadType) {
1021
+ const d = { type: "OptionSpreadCount" };
1022
+ d["underlying"] = underlying;
1023
+ d["optionType"] = optionType;
1024
+ d["direction"] = direction;
1025
+ d["spreadType"] = spreadType;
1026
+ return d;
1027
+ }
1028
+ /**
1029
+ * OptionUnrealizedPnL indicator.
1030
+ * @param underlying Filter by underlying (e.g., AAPL, SPY). Leave empty for all.
1031
+ * @param optionType Filter by Call or Put. Leave empty for all.
1032
+ * @param direction Filter by Long or Short. Leave empty for all.
1033
+ * @param spreadType Filter by spread type. Leave empty for all.
1034
+ */
1035
+ export function OptionUnrealizedPnL(underlying, optionType, direction, spreadType) {
1036
+ const d = { type: "OptionUnrealizedPnL" };
1037
+ d["underlying"] = underlying;
1038
+ d["optionType"] = optionType;
1039
+ d["direction"] = direction;
1040
+ d["spreadType"] = spreadType;
1041
+ return d;
1042
+ }
1043
+ /**
1044
+ * Plus indicator.
1045
+ */
1046
+ export function Plus(left, right) {
1047
+ const d = { type: "Plus" };
1048
+ d.indicators = [left, right];
1049
+ return d;
1050
+ }
1051
+ /**
1052
+ * PortfolioValue indicator.
1053
+ */
1054
+ export function PortfolioValue() {
1055
+ const d = { type: "PortfolioValue" };
1056
+ return d;
1057
+ }
1058
+ /**
1059
+ * PositionMaxDrawdown indicator.
1060
+ * @param asset Ticker name (ex. SPY, BTC)
1061
+ */
1062
+ export function PositionMaxDrawdown(asset) {
1063
+ const d = { type: "PositionMaxDrawdown" };
1064
+ setAsset(d, "targetAsset", asset);
1065
+ return d;
1066
+ }
1067
+ /**
1068
+ * PositionMaxDrawup indicator.
1069
+ * @param asset Ticker name (ex. SPY, BTC)
1070
+ */
1071
+ export function PositionMaxDrawup(asset) {
1072
+ const d = { type: "PositionMaxDrawup" };
1073
+ setAsset(d, "targetAsset", asset);
1074
+ return d;
1075
+ }
1076
+ /**
1077
+ * PositionPercentChange indicator.
1078
+ * @param assets Ticker name (ex. SPY, BTC)
1079
+ */
1080
+ export function PositionPercentChange(assets) {
1081
+ const d = { type: "PositionPercentChange" };
1082
+ setAssets(d, "targetAssets", assets);
1083
+ return d;
1084
+ }
1085
+ /**
1086
+ * PositionValue indicator.
1087
+ * @param assets Ticker name (ex. SPY, BTC)
1088
+ */
1089
+ export function PositionValue(assets) {
1090
+ const d = { type: "PositionValue" };
1091
+ setAssets(d, "targetAssets", assets);
1092
+ return d;
1093
+ }
1094
+ /**
1095
+ * PreviousClosingPrice indicator.
1096
+ * @param asset Ticker name (ex. SPY, BTC)
1097
+ */
1098
+ export function PreviousClosingPrice(asset) {
1099
+ const d = { type: "PreviousClosingPrice" };
1100
+ setAsset(d, "targetAsset", asset);
1101
+ return d;
1102
+ }
1103
+ /**
1104
+ * Price indicator.
1105
+ * @param asset Ticker name (ex. SPY, BTC)
1106
+ */
1107
+ export function Price(asset) {
1108
+ const d = { type: "Price" };
1109
+ setAsset(d, "targetAsset", asset);
1110
+ return d;
1111
+ }
1112
+ /**
1113
+ * PriceChangeSinceOpen indicator.
1114
+ * @param asset Ticker name (ex. SPY, BTC)
1115
+ */
1116
+ export function PriceChangeSinceOpen(asset) {
1117
+ const d = { type: "PriceChangeSinceOpen" };
1118
+ setAsset(d, "targetAsset", asset);
1119
+ return d;
1120
+ }
1121
+ /**
1122
+ * PriceMeanAbsoluteDeviation indicator.
1123
+ * @param asset Ticker name (ex. SPY, BTC)
1124
+ * @param length Length of time
1125
+ * @param interval Unit of time
1126
+ */
1127
+ export function PriceMeanAbsoluteDeviation(asset, length = 30, interval = "Day") {
1128
+ const d = { type: "PriceMeanAbsoluteDeviation" };
1129
+ setAsset(d, "targetAsset", asset);
1130
+ d.window = { length: length, interval: interval };
1131
+ return d;
1132
+ }
1133
+ /**
1134
+ * PriceRateOfChange indicator.
1135
+ * @param asset Ticker name (ex. SPY, BTC)
1136
+ * @param length Length of time
1137
+ * @param interval Unit of time
1138
+ */
1139
+ export function PriceRateOfChange(asset, length = 30, interval = "Day") {
1140
+ const d = { type: "PriceRateOfChange" };
1141
+ setAsset(d, "targetAsset", asset);
1142
+ d.window = { length: length, interval: interval };
1143
+ return d;
1144
+ }
1145
+ /**
1146
+ * PriceStandardDeviation indicator.
1147
+ * @param asset Ticker name (ex. SPY, BTC)
1148
+ * @param length Length of time
1149
+ * @param interval Unit of time
1150
+ */
1151
+ export function PriceStandardDeviation(asset, length = 30, interval = "Day") {
1152
+ const d = { type: "PriceStandardDeviation" };
1153
+ setAsset(d, "targetAsset", asset);
1154
+ d.window = { length: length, interval: interval };
1155
+ return d;
1156
+ }
1157
+ export const PriceStdDev = PriceStandardDeviation;
1158
+ /**
1159
+ * RelativeStrengthIndex indicator.
1160
+ * @param asset Ticker name (ex. SPY, BTC)
1161
+ * @param length Length of time
1162
+ * @param interval Unit of time
1163
+ */
1164
+ export function RelativeStrengthIndex(asset, length = 30, interval = "Day") {
1165
+ const d = { type: "RelativeStrengthIndex" };
1166
+ setAsset(d, "targetAsset", asset);
1167
+ d.window = { length: length, interval: interval };
1168
+ return d;
1169
+ }
1170
+ export const RSI = RelativeStrengthIndex;
1171
+ /**
1172
+ * SimpleMovingAverage indicator.
1173
+ * @param asset Ticker name (ex. SPY, BTC)
1174
+ * @param length Length of time
1175
+ * @param interval Unit of time
1176
+ */
1177
+ export function SimpleMovingAverage(asset, length = 30, interval = "Day") {
1178
+ const d = { type: "SimpleMovingAverage" };
1179
+ setAsset(d, "targetAsset", asset);
1180
+ d.window = { length: length, interval: interval };
1181
+ return d;
1182
+ }
1183
+ export const SMA = SimpleMovingAverage;
1184
+ /**
1185
+ * SquareRoot indicator.
1186
+ */
1187
+ export function SquareRoot(operand) {
1188
+ const d = { type: "SquareRoot" };
1189
+ d.indicators = [operand];
1190
+ return d;
1191
+ }
1192
+ /**
1193
+ * StockReport indicator.
1194
+ * @param asset Ticker name (ex. SPY, BTC)
1195
+ */
1196
+ export function StockReport(asset) {
1197
+ const d = { type: "StockReport" };
1198
+ setAsset(d, "targetAsset", asset);
1199
+ return d;
1200
+ }
1201
+ /**
1202
+ * SumOrderAmount indicator.
1203
+ * @param side Matches order events with this side (buy or sell)
1204
+ * @param orderStatus Matches order events with this status
1205
+ * @param length Length of time
1206
+ * @param interval Unit of time
1207
+ * @param assets Ticker name (ex. SPY, BTC)
1208
+ */
1209
+ export function SumOrderAmount(side, orderStatus = "Filled", length = 1, interval = "Day", assets) {
1210
+ const d = { type: "SumOrderAmount" };
1211
+ d["side"] = side;
1212
+ d["orderStatus"] = orderStatus;
1213
+ setAssets(d, "targetAssets", assets);
1214
+ d.window = { length: length, interval: interval };
1215
+ return d;
1216
+ }
1217
+ /**
1218
+ * SumOrderQuantity indicator.
1219
+ * @param side Matches order events with this side (buy or sell)
1220
+ * @param orderStatus Matches order events with this status
1221
+ * @param length Length of time
1222
+ * @param interval Unit of time
1223
+ * @param assets Ticker name (ex. SPY, BTC)
1224
+ */
1225
+ export function SumOrderQuantity(side, orderStatus = "Filled", length = 1, interval = "Day", assets) {
1226
+ const d = { type: "SumOrderQuantity" };
1227
+ d["side"] = side;
1228
+ d["orderStatus"] = orderStatus;
1229
+ setAssets(d, "targetAssets", assets);
1230
+ d.window = { length: length, interval: interval };
1231
+ return d;
1232
+ }
1233
+ /**
1234
+ * TrailingSum indicator.
1235
+ * @param length Length of the rolling window
1236
+ */
1237
+ export function TrailingSum(operand, length = 4) {
1238
+ const d = { type: "TrailingSum" };
1239
+ d["length"] = length;
1240
+ d.indicators = [operand];
1241
+ return d;
1242
+ }
1243
+ /**
1244
+ * TrueRange indicator.
1245
+ * @param asset Ticker name (ex. SPY, BTC)
1246
+ */
1247
+ export function TrueRange(asset) {
1248
+ const d = { type: "TrueRange" };
1249
+ setAsset(d, "targetAsset", asset);
1250
+ return d;
1251
+ }
1252
+ /**
1253
+ * UnderlyingMaxDrawdown indicator.
1254
+ * @param asset Ticker name (ex. SPY, BTC)
1255
+ */
1256
+ export function UnderlyingMaxDrawdown(asset) {
1257
+ const d = { type: "UnderlyingMaxDrawdown" };
1258
+ setAsset(d, "targetAsset", asset);
1259
+ return d;
1260
+ }
1261
+ /**
1262
+ * Value indicator.
1263
+ * @param value Constant value
1264
+ */
1265
+ export function Value(value = 0) {
1266
+ const d = { type: "Value" };
1267
+ d["value"] = value;
1268
+ return d;
1269
+ }
1270
+ /**
1271
+ * Volume indicator.
1272
+ * @param asset Ticker name (ex. SPY, BTC)
1273
+ * @param metric The fundamental metric to use
1274
+ */
1275
+ export function Volume(asset, metric = "volume") {
1276
+ const d = { type: "Volume" };
1277
+ setAsset(d, "targetAsset", asset);
1278
+ d["metric"] = metric;
1279
+ return d;
1280
+ }
1281
+ /**
1282
+ * VWAP indicator.
1283
+ * @param asset Ticker name (ex. SPY, BTC)
1284
+ */
1285
+ export function VWAP(asset) {
1286
+ const d = { type: "VWAP" };
1287
+ setAsset(d, "targetAsset", asset);
1288
+ return d;
1289
+ }
1290
+ /**
1291
+ * Year indicator.
1292
+ */
1293
+ export function Year() {
1294
+ const d = { type: "Year" };
1295
+ return d;
1296
+ }
1297
+ /** Submit a backtest. Returns a handle; results are read after it completes. */
1298
+ export const backtest = (portfolio, config) => ({
1299
+ tool: "backtest_portfolio",
1300
+ portfolio,
1301
+ args: compact({
1302
+ "start_date": config.startDate,
1303
+ "end_date": config.endDate,
1304
+ "baseline_symbol": config.baselineSymbol,
1305
+ "interval": config.interval,
1306
+ "initial_value": config.initialValue,
1307
+ "generate_events": config.generateEvents,
1308
+ "fee_config": config.feeConfig,
1309
+ }),
1310
+ });
1311
+ /** Submit a walk-forward study (anchored or rolling folds, GA or sweep engine). */
1312
+ export const walkForward = (portfolio, config) => ({
1313
+ tool: "run_walk_forward_study",
1314
+ portfolio,
1315
+ args: compact({
1316
+ "global_start_date": config.globalStartDate,
1317
+ "global_end_date": config.globalEndDate,
1318
+ "fold_count": config.foldCount,
1319
+ "engine_kind": config.engineKind,
1320
+ "walk_forward_mode": config.walkForwardMode,
1321
+ "oos_width_days": config.oosWidthDays,
1322
+ "validation_percent": config.validationPercent,
1323
+ "embargo_days": config.embargoDays,
1324
+ "population_size": config.populationSize,
1325
+ "num_generations": config.numGenerations,
1326
+ "num_windows": config.numWindows,
1327
+ "training_percent": config.trainingPercent,
1328
+ "window_overlap_percent": config.windowOverlapPercent,
1329
+ "fitness_functions": config.fitnessFunctions,
1330
+ "selection_policy": config.selectionPolicy,
1331
+ "fold_selection_policy": config.foldSelectionPolicy,
1332
+ "fee_config": config.feeConfig,
1333
+ "degradation_penalty": config.degradationPenalty,
1334
+ "leaderboard_size": config.leaderboardSize,
1335
+ "search_mode": config.searchMode,
1336
+ "preview_only": config.previewOnly,
1337
+ "interval": config.interval,
1338
+ "auto_run": config.autoRun,
1339
+ "name": config.name,
1340
+ "mode": config.mode,
1341
+ "oos_stride_days": config.oosStrideDays,
1342
+ "adaptive_config": config.adaptiveConfig,
1343
+ "inner_mode": config.innerMode,
1344
+ "certification": config.certification,
1345
+ "allow_ga_certification": config.allowGaCertification,
1346
+ "use_certification_selection_policy": config.useCertificationSelectionPolicy,
1347
+ "genes": config.genes,
1348
+ }),
1349
+ });
1350
+ /** Submit a genetic optimization over the portfolio's tunable genes. */
1351
+ export const optimization = (portfolio, config) => ({
1352
+ tool: "optimize_portfolio",
1353
+ portfolio,
1354
+ args: compact({
1355
+ "start_date": config.startDate,
1356
+ "end_date": config.endDate,
1357
+ "fitness_functions": config.fitnessFunctions,
1358
+ "population_size": config.populationSize,
1359
+ "num_generations": config.numGenerations,
1360
+ "num_windows": config.numWindows,
1361
+ "training_percent": config.trainingPercent,
1362
+ "window_overlap_percent": config.windowOverlapPercent,
1363
+ "interval": config.interval,
1364
+ "selection_policy": config.selectionPolicy,
1365
+ "fee_config": config.feeConfig,
1366
+ "genes": config.genes,
1367
+ }),
1368
+ });
1369
+ /** Sweep Subject (Portfolio scope) over a value set. */
1370
+ export const geneSubject = (values) => ({
1371
+ field: "Subject",
1372
+ scope: "Portfolio",
1373
+ target: { scope: "Portfolio", field: "Subject" },
1374
+ values: values,
1375
+ });
1376
+ /** Sweep EntryCondition (Strategy scope) over a value set. */
1377
+ export const geneEntryCondition = (strategyIndex, values) => ({
1378
+ field: "EntryCondition",
1379
+ scope: "Strategy",
1380
+ target: { scope: "Strategy", field: "EntryCondition", strategyIndex },
1381
+ values: values,
1382
+ });
1383
+ /** Sweep ExitCondition (Strategy scope) over a value set. */
1384
+ export const geneExitCondition = (strategyIndex, values) => ({
1385
+ field: "ExitCondition",
1386
+ scope: "Strategy",
1387
+ target: { scope: "Strategy", field: "ExitCondition", strategyIndex },
1388
+ values: values,
1389
+ });
1390
+ /** Sweep EntryCooldownDays (Strategy scope) over a value set. */
1391
+ export const geneEntryCooldownDays = (strategyIndex, values) => ({
1392
+ field: "EntryCooldownDays",
1393
+ scope: "Strategy",
1394
+ target: { scope: "Strategy", field: "EntryCooldownDays", strategyIndex },
1395
+ values: values,
1396
+ });
1397
+ /** Sweep RankSignal (Action scope) over a value set. */
1398
+ export const geneRankSignal = (strategyIndex, values) => ({
1399
+ field: "RankSignal",
1400
+ scope: "Action",
1401
+ target: { scope: "Action", field: "RankSignal", strategyIndex },
1402
+ values: values,
1403
+ });
1404
+ /** Sweep BuyingPowerPct (Action scope) over a value set. */
1405
+ export const geneBuyingPowerPct = (strategyIndex, values) => ({
1406
+ field: "BuyingPowerPct",
1407
+ scope: "Action",
1408
+ target: { scope: "Action", field: "BuyingPowerPct", strategyIndex },
1409
+ values: values,
1410
+ });
1411
+ /** Sweep AllocationPct (Action scope) over a value set. */
1412
+ export const geneAllocationPct = (strategyIndex, values) => ({
1413
+ field: "AllocationPct",
1414
+ scope: "Action",
1415
+ target: { scope: "Action", field: "AllocationPct", strategyIndex },
1416
+ values: values,
1417
+ });
1418
+ /** Sweep TotalBudgetPct (Action scope) over a value set. */
1419
+ export const geneTotalBudgetPct = (strategyIndex, values) => ({
1420
+ field: "TotalBudgetPct",
1421
+ scope: "Action",
1422
+ target: { scope: "Action", field: "TotalBudgetPct", strategyIndex },
1423
+ values: values,
1424
+ });
1425
+ /** Sweep DeploymentPct (Action scope) over a value set. */
1426
+ export const geneDeploymentPct = (strategyIndex, values) => ({
1427
+ field: "DeploymentPct",
1428
+ scope: "Action",
1429
+ target: { scope: "Action", field: "DeploymentPct", strategyIndex },
1430
+ values: values,
1431
+ });
1432
+ /** Sweep RollTriggerDte (Action scope) over a value set. */
1433
+ export const geneRollTriggerDte = (strategyIndex, values) => ({
1434
+ field: "RollTriggerDte",
1435
+ scope: "Action",
1436
+ target: { scope: "Action", field: "RollTriggerDte", strategyIndex },
1437
+ values: values,
1438
+ });
1439
+ /** Sweep TakeProfitPct (Action scope) over a value set. */
1440
+ export const geneTakeProfitPct = (strategyIndex, values) => ({
1441
+ field: "TakeProfitPct",
1442
+ scope: "Action",
1443
+ target: { scope: "Action", field: "TakeProfitPct", strategyIndex },
1444
+ values: values,
1445
+ });
1446
+ /** Sweep StructureKind (Action scope) over a value set. */
1447
+ export const geneStructureKind = (strategyIndex, values) => ({
1448
+ field: "StructureKind",
1449
+ scope: "Action",
1450
+ target: { scope: "Action", field: "StructureKind", strategyIndex },
1451
+ values: values,
1452
+ });
1453
+ /** Sweep OptionDelta (OptionLeg scope) over a value set. */
1454
+ export const geneOptionDelta = (strategyIndex, legIndex, values) => ({
1455
+ field: "OptionDelta",
1456
+ scope: "OptionLeg",
1457
+ target: { scope: "OptionLeg", field: "OptionDelta", strategyIndex, legIndex },
1458
+ values: values,
1459
+ });
1460
+ /** Sweep StrikeDistance (OptionLeg scope) over a value set. */
1461
+ export const geneStrikeDistance = (strategyIndex, legIndex, values) => ({
1462
+ field: "StrikeDistance",
1463
+ scope: "OptionLeg",
1464
+ target: { scope: "OptionLeg", field: "StrikeDistance", strategyIndex, legIndex },
1465
+ values: values,
1466
+ });
1467
+ /** Sweep DteBracket (OptionLeg scope) over a value set. */
1468
+ export const geneDteBracket = (strategyIndex, legIndex, values) => ({
1469
+ field: "DteBracket",
1470
+ scope: "OptionLeg",
1471
+ target: { scope: "OptionLeg", field: "DteBracket", strategyIndex, legIndex },
1472
+ values: values,
1473
+ });
1474
+ /** Sweep SelectTopLimit (UniversePipeline scope) over a value set. */
1475
+ export const geneSelectTopLimit = (strategyIndex, stageIndex, values) => ({
1476
+ field: "SelectTopLimit",
1477
+ scope: "UniversePipeline",
1478
+ target: { scope: "UniversePipeline", field: "SelectTopLimit", strategyIndex, stageIndex },
1479
+ values: values,
1480
+ });
1481
+ /** Sweep UniversePipelineFilter (UniversePipeline scope) over a value set. */
1482
+ export const geneUniversePipelineFilter = (strategyIndex, stageIndex, values) => ({
1483
+ field: "UniversePipelineFilter",
1484
+ scope: "UniversePipeline",
1485
+ target: { scope: "UniversePipeline", field: "UniversePipelineFilter", strategyIndex, stageIndex },
1486
+ values: values,
1487
+ });