@wicklib/pro 0.0.0-stage → 0.11.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/LICENSE +93 -0
- package/README.md +51 -2
- package/dist/index.cjs +1020 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +593 -0
- package/dist/index.d.ts +593 -0
- package/dist/index.js +974 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
import { OhlcData, LicenseContext, ChartOverlayApi, ChartApi, Feature, WickExtension } from '@wicklib/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Semantic version of the installed pro package.
|
|
5
|
+
*/
|
|
6
|
+
declare const PRO_VERSION: string;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Target position for a strategy.
|
|
10
|
+
*
|
|
11
|
+
* -1 = fully short
|
|
12
|
+
* 0 = flat
|
|
13
|
+
* 1 = fully long
|
|
14
|
+
*/
|
|
15
|
+
type StrategyTarget = -1 | 0 | 1;
|
|
16
|
+
/**
|
|
17
|
+
* Context passed to a strategy once per closed bar.
|
|
18
|
+
*/
|
|
19
|
+
interface StrategyContext {
|
|
20
|
+
readonly bar: OhlcData;
|
|
21
|
+
readonly index: number;
|
|
22
|
+
readonly position: StrategyTarget;
|
|
23
|
+
readonly cash: number;
|
|
24
|
+
readonly units: number;
|
|
25
|
+
readonly equity: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Strategy callback. Return a target to schedule a fill at the next bar open, or
|
|
29
|
+
* `undefined`/`null` to hold the current target.
|
|
30
|
+
*/
|
|
31
|
+
type StrategyFunction = (context: StrategyContext) => StrategyTarget | null | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Backtest configuration.
|
|
34
|
+
*/
|
|
35
|
+
interface BacktestOptions {
|
|
36
|
+
/** Starting cash. Required and positive. */
|
|
37
|
+
initialCapital: number;
|
|
38
|
+
/** Fractional fee charged on absolute traded notional. Defaults to 0. */
|
|
39
|
+
feeRate?: number;
|
|
40
|
+
/** Fractional slippage applied against the fill. Defaults to 0. */
|
|
41
|
+
slippage?: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* One executed target change.
|
|
45
|
+
*/
|
|
46
|
+
interface BacktestFill {
|
|
47
|
+
time: number;
|
|
48
|
+
side: "buy" | "sell";
|
|
49
|
+
price: number;
|
|
50
|
+
quantity: number;
|
|
51
|
+
fee: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* One marked-to-market equity point.
|
|
55
|
+
*/
|
|
56
|
+
interface EquityPoint {
|
|
57
|
+
time: number;
|
|
58
|
+
cash: number;
|
|
59
|
+
units: number;
|
|
60
|
+
position: StrategyTarget;
|
|
61
|
+
price: number;
|
|
62
|
+
equity: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Deterministic strategy backtest result.
|
|
66
|
+
*/
|
|
67
|
+
interface BacktestResult {
|
|
68
|
+
initialCapital: number;
|
|
69
|
+
finalEquity: number;
|
|
70
|
+
returnPercent: number;
|
|
71
|
+
maxDrawdown: number;
|
|
72
|
+
fills: readonly BacktestFill[];
|
|
73
|
+
equity: readonly EquityPoint[];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Runs a target-position strategy against closed bars.
|
|
77
|
+
*
|
|
78
|
+
* Signals are evaluated on bar close and filled at the next bar open, preventing
|
|
79
|
+
* lookahead. Position sizing is fully invested at the fill price; leverage is not added.
|
|
80
|
+
* Requires the `strategy` license feature.
|
|
81
|
+
*/
|
|
82
|
+
declare function runBacktest(context: LicenseContext, bars: readonly OhlcData[], strategy: StrategyFunction, options: BacktestOptions): BacktestResult;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* One alert emitted by a script, including the bar it belongs to.
|
|
86
|
+
*/
|
|
87
|
+
interface ScriptAlertEvent {
|
|
88
|
+
time: number;
|
|
89
|
+
barIndex: number;
|
|
90
|
+
message: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Output required from a compiled script replay.
|
|
94
|
+
*
|
|
95
|
+
* This is structurally compatible with `@wicklib/script`'s `CompiledScript`, without making
|
|
96
|
+
* Pro depend on the script package at runtime.
|
|
97
|
+
*/
|
|
98
|
+
interface ScriptRunResult {
|
|
99
|
+
plots: Readonly<Record<string, ReadonlyArray<number | null>>>;
|
|
100
|
+
alerts: ReadonlyArray<string>;
|
|
101
|
+
alertEvents?: ReadonlyArray<ScriptAlertEvent>;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Minimal compiled-script contract accepted by the adapter.
|
|
105
|
+
*/
|
|
106
|
+
interface CompiledScriptLike {
|
|
107
|
+
replay(bars: readonly OhlcData[]): Promise<ScriptRunResult>;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Options for a script-driven backtest.
|
|
111
|
+
*/
|
|
112
|
+
interface ScriptBacktestOptions extends BacktestOptions {
|
|
113
|
+
/** Plot id whose values are target positions: -1 short, 0 flat, 1 long, null hold. */
|
|
114
|
+
signalPlot: string;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Backtest result plus script alerts.
|
|
118
|
+
*/
|
|
119
|
+
interface ScriptBacktestResult extends BacktestResult {
|
|
120
|
+
alerts: readonly ScriptAlertEvent[];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Runs a compiled script, maps one plot to target positions, and backtests the result.
|
|
124
|
+
*
|
|
125
|
+
* The script must emit positions on the configured plot. Alerts are returned with their
|
|
126
|
+
* source bar so the host can deliver or persist them. Requires the `strategy` feature.
|
|
127
|
+
*/
|
|
128
|
+
declare function runScriptBacktest(context: LicenseContext, script: CompiledScriptLike, bars: readonly OhlcData[], options: ScriptBacktestOptions): Promise<ScriptBacktestResult>;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Price field used by a price alert.
|
|
132
|
+
*/
|
|
133
|
+
type AlertPriceSource = "close" | "high" | "low";
|
|
134
|
+
/**
|
|
135
|
+
* Price alert direction.
|
|
136
|
+
*
|
|
137
|
+
* `cross` reports the side that was crossed.
|
|
138
|
+
*/
|
|
139
|
+
type AlertDirection = "above" | "below" | "cross";
|
|
140
|
+
/**
|
|
141
|
+
* A serializable price alert rule.
|
|
142
|
+
*/
|
|
143
|
+
interface PriceAlertRule {
|
|
144
|
+
readonly id: string;
|
|
145
|
+
readonly price: number;
|
|
146
|
+
readonly direction: AlertDirection;
|
|
147
|
+
/** Defaults to close. */
|
|
148
|
+
readonly source?: AlertPriceSource;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* A triggered alert.
|
|
152
|
+
*/
|
|
153
|
+
interface AlertTrigger {
|
|
154
|
+
readonly ruleId: string;
|
|
155
|
+
readonly time: number;
|
|
156
|
+
readonly direction: "above" | "below";
|
|
157
|
+
readonly price: number;
|
|
158
|
+
readonly value: number;
|
|
159
|
+
readonly bar: OhlcData;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Deterministic, offline alert evaluator for streaming bars.
|
|
163
|
+
*
|
|
164
|
+
* The first bar initializes state and never triggers. Subsequent bars trigger only on a
|
|
165
|
+
* transition so a rule does not fire repeatedly while it remains true.
|
|
166
|
+
*/
|
|
167
|
+
declare class AlertEngine {
|
|
168
|
+
private readonly rules;
|
|
169
|
+
private readonly previous;
|
|
170
|
+
private lastTime;
|
|
171
|
+
constructor(context: LicenseContext, rules: readonly PriceAlertRule[]);
|
|
172
|
+
/**
|
|
173
|
+
* Consumes one closed bar and returns the alerts triggered by that bar.
|
|
174
|
+
*/
|
|
175
|
+
update(bar: OhlcData): readonly AlertTrigger[];
|
|
176
|
+
/**
|
|
177
|
+
* Clears previous values so the next bar initializes state again.
|
|
178
|
+
*/
|
|
179
|
+
reset(): void;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Evaluates a batch of closed bars through the same streaming alert path.
|
|
183
|
+
*/
|
|
184
|
+
declare function evaluateAlerts(context: LicenseContext, rules: readonly PriceAlertRule[], bars: readonly OhlcData[]): readonly AlertTrigger[];
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* One side of a Level-2 depth snapshot.
|
|
188
|
+
*/
|
|
189
|
+
interface DepthLevel {
|
|
190
|
+
price: number;
|
|
191
|
+
size: number;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* A full bid/ask book snapshot at a point in time.
|
|
195
|
+
*/
|
|
196
|
+
interface DepthSnapshot {
|
|
197
|
+
/** Unix timestamp in milliseconds. */
|
|
198
|
+
time: number;
|
|
199
|
+
bids: readonly DepthLevel[];
|
|
200
|
+
asks: readonly DepthLevel[];
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Aggregated bid/ask liquidity by price bucket.
|
|
204
|
+
*/
|
|
205
|
+
interface DepthLevelBar {
|
|
206
|
+
priceLow: number;
|
|
207
|
+
priceHigh: number;
|
|
208
|
+
bidSize: number;
|
|
209
|
+
askSize: number;
|
|
210
|
+
totalSize: number;
|
|
211
|
+
delta: number;
|
|
212
|
+
imbalance: "bid" | "ask" | null;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Aggregated depth for one snapshot.
|
|
216
|
+
*/
|
|
217
|
+
interface DepthBar {
|
|
218
|
+
time: number;
|
|
219
|
+
priceLow: number;
|
|
220
|
+
priceHigh: number;
|
|
221
|
+
bidSize: number;
|
|
222
|
+
askSize: number;
|
|
223
|
+
totalSize: number;
|
|
224
|
+
delta: number;
|
|
225
|
+
imbalance: "bid" | "ask" | null;
|
|
226
|
+
levels: readonly DepthLevelBar[];
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Options for depth aggregation.
|
|
230
|
+
*/
|
|
231
|
+
interface DepthOptions {
|
|
232
|
+
/** Price bucket width. Required. */
|
|
233
|
+
priceStep?: number;
|
|
234
|
+
/** Ratio that qualifies total book pressure as imbalanced. Defaults to 2. */
|
|
235
|
+
imbalanceRatio?: number;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Incremental L2 depth aggregator.
|
|
239
|
+
*
|
|
240
|
+
* Snapshots are complete books, so newer snapshots replace the current view rather than
|
|
241
|
+
* accumulate. Non-decreasing timestamps are enforced.
|
|
242
|
+
*/
|
|
243
|
+
declare class DepthAggregator {
|
|
244
|
+
private readonly options;
|
|
245
|
+
private readonly bars;
|
|
246
|
+
private lastTime;
|
|
247
|
+
constructor(context: LicenseContext, options: DepthOptions);
|
|
248
|
+
/**
|
|
249
|
+
* Adds or replaces one complete snapshot and returns its aggregated bar.
|
|
250
|
+
*/
|
|
251
|
+
push(snapshot: DepthSnapshot): DepthBar;
|
|
252
|
+
/**
|
|
253
|
+
* Returns the latest snapshot at or before a time.
|
|
254
|
+
*/
|
|
255
|
+
latest(time?: number): DepthBar | null;
|
|
256
|
+
/**
|
|
257
|
+
* Returns all snapshots in ascending time order.
|
|
258
|
+
*/
|
|
259
|
+
getBars(): readonly DepthBar[];
|
|
260
|
+
/**
|
|
261
|
+
* Clears all snapshots and the streaming order guard.
|
|
262
|
+
*/
|
|
263
|
+
reset(): void;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Aggregates a batch of complete L2 book snapshots.
|
|
267
|
+
*
|
|
268
|
+
* Requires the `orderflow` license feature.
|
|
269
|
+
*/
|
|
270
|
+
declare function computeDepth(context: LicenseContext, snapshots: readonly DepthSnapshot[], options: DepthOptions): readonly DepthBar[];
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Aggressor side of a trade tick.
|
|
274
|
+
*/
|
|
275
|
+
type TradeSide = "buy" | "sell";
|
|
276
|
+
/**
|
|
277
|
+
* Minimal trade tick accepted by the orderflow aggregator.
|
|
278
|
+
*/
|
|
279
|
+
interface TradeTick {
|
|
280
|
+
/** Unix timestamp in milliseconds. */
|
|
281
|
+
time: number;
|
|
282
|
+
price: number;
|
|
283
|
+
size: number;
|
|
284
|
+
side: TradeSide;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Orderflow aggregation options.
|
|
288
|
+
*/
|
|
289
|
+
interface FootprintOptions {
|
|
290
|
+
/** Time bucket size in milliseconds. Defaults to one minute. */
|
|
291
|
+
bucketMs?: number;
|
|
292
|
+
/** Price bucket width. Required. */
|
|
293
|
+
priceStep?: number;
|
|
294
|
+
/** Ratio that qualifies a level as imbalanced. Defaults to 3. */
|
|
295
|
+
imbalanceRatio?: number;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* One price level in a footprint bar.
|
|
299
|
+
*/
|
|
300
|
+
interface FootprintLevel {
|
|
301
|
+
priceLow: number;
|
|
302
|
+
priceHigh: number;
|
|
303
|
+
buyVolume: number;
|
|
304
|
+
sellVolume: number;
|
|
305
|
+
totalVolume: number;
|
|
306
|
+
delta: number;
|
|
307
|
+
imbalance: TradeSide | null;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Aggregated footprint for one time bucket.
|
|
311
|
+
*/
|
|
312
|
+
interface FootprintBar {
|
|
313
|
+
time: number;
|
|
314
|
+
priceLow: number;
|
|
315
|
+
priceHigh: number;
|
|
316
|
+
buyVolume: number;
|
|
317
|
+
sellVolume: number;
|
|
318
|
+
totalVolume: number;
|
|
319
|
+
delta: number;
|
|
320
|
+
levels: readonly FootprintLevel[];
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Incremental trade-tick footprint aggregator.
|
|
324
|
+
*
|
|
325
|
+
* Trades must arrive in non-decreasing time order. Ticks in the same bucket update the
|
|
326
|
+
* same bar, so streaming and batch aggregation share the same code path.
|
|
327
|
+
*/
|
|
328
|
+
declare class FootprintAggregator {
|
|
329
|
+
private readonly options;
|
|
330
|
+
private readonly levels;
|
|
331
|
+
private lastTradeTime;
|
|
332
|
+
constructor(context: LicenseContext, options: FootprintOptions);
|
|
333
|
+
/**
|
|
334
|
+
* Adds one trade and returns the updated bar for its time bucket.
|
|
335
|
+
*/
|
|
336
|
+
push(trade: TradeTick): FootprintBar;
|
|
337
|
+
/**
|
|
338
|
+
* Adds multiple trades in input order.
|
|
339
|
+
*/
|
|
340
|
+
pushMany(trades: readonly TradeTick[]): readonly FootprintBar[];
|
|
341
|
+
/**
|
|
342
|
+
* Returns a bar by bucket start time, or any time inside that bucket.
|
|
343
|
+
*/
|
|
344
|
+
getBar(time: number): FootprintBar | null;
|
|
345
|
+
/**
|
|
346
|
+
* Returns all completed/current buckets in ascending time order.
|
|
347
|
+
*/
|
|
348
|
+
getBars(): readonly FootprintBar[];
|
|
349
|
+
/**
|
|
350
|
+
* Clears all trades and resets the streaming order guard.
|
|
351
|
+
*/
|
|
352
|
+
reset(): void;
|
|
353
|
+
private buildBar;
|
|
354
|
+
private validateTrade;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Aggregates trade ticks into bid/ask footprint bars with delta and imbalance.
|
|
358
|
+
*
|
|
359
|
+
* Requires the `orderflow` license feature. Trades are sorted by time before aggregation.
|
|
360
|
+
*/
|
|
361
|
+
declare function computeFootprint(context: LicenseContext, trades: readonly TradeTick[], options: FootprintOptions): readonly FootprintBar[];
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Options for absorption detection.
|
|
365
|
+
*/
|
|
366
|
+
interface AbsorptionOptions {
|
|
367
|
+
/** Time bucket size in milliseconds. Defaults to one minute. */
|
|
368
|
+
bucketMs?: number;
|
|
369
|
+
/** Price bucket width. Required. */
|
|
370
|
+
priceStep?: number;
|
|
371
|
+
/** Aggressive volume must reach passive size × this ratio. Defaults to 2. */
|
|
372
|
+
absorptionRatio?: number;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* A detected absorption event.
|
|
376
|
+
*/
|
|
377
|
+
interface AbsorptionEvent {
|
|
378
|
+
/** Bucket start time in milliseconds. */
|
|
379
|
+
time: number;
|
|
380
|
+
priceLow: number;
|
|
381
|
+
priceHigh: number;
|
|
382
|
+
/** Aggressor side that was absorbed. */
|
|
383
|
+
side: TradeSide;
|
|
384
|
+
/** Aggressive trade volume in the bucket and level. */
|
|
385
|
+
aggressiveVolume: number;
|
|
386
|
+
/** Passive book size at the level when the bucket completed. */
|
|
387
|
+
passiveVolume: number;
|
|
388
|
+
/** aggressiveVolume / passiveVolume. */
|
|
389
|
+
ratio: number;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Detects aggressive volume absorbed by passive L2 liquidity.
|
|
393
|
+
*
|
|
394
|
+
* For each footprint bucket and price level:
|
|
395
|
+
* - aggressive buys are compared with ask depth
|
|
396
|
+
* - aggressive sells are compared with bid depth
|
|
397
|
+
*
|
|
398
|
+
* A level is reported when aggressive volume is at least the configured multiple of the
|
|
399
|
+
* passive size. Requires the `orderflow` license feature.
|
|
400
|
+
*/
|
|
401
|
+
declare function detectAbsorption(context: LicenseContext, trades: readonly TradeTick[], snapshots: readonly DepthSnapshot[], options: AbsorptionOptions): readonly AbsorptionEvent[];
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Volume distribution model.
|
|
405
|
+
*
|
|
406
|
+
* `uniform` spreads each bar's volume evenly across its price range. `close` assigns the
|
|
407
|
+
* whole bar volume to the bin containing the close.
|
|
408
|
+
*/
|
|
409
|
+
type VolumeProfileDistribution = "uniform" | "close";
|
|
410
|
+
/**
|
|
411
|
+
* Options for {@link computeVolumeProfile}.
|
|
412
|
+
*/
|
|
413
|
+
interface VolumeProfileOptions {
|
|
414
|
+
/** Number of equal-width price bins. Defaults to 24. */
|
|
415
|
+
bins?: number;
|
|
416
|
+
/** Fixed price range. Defaults to the bars' low/high span. */
|
|
417
|
+
priceRange?: {
|
|
418
|
+
min: number;
|
|
419
|
+
max: number;
|
|
420
|
+
};
|
|
421
|
+
/** Fraction of total volume covered by the value area. Defaults to 0.7. */
|
|
422
|
+
valueArea?: number;
|
|
423
|
+
/** Volume distribution model. Defaults to uniform. */
|
|
424
|
+
distribution?: VolumeProfileDistribution;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* One price bucket in a volume profile.
|
|
428
|
+
*/
|
|
429
|
+
interface VolumeProfileBin {
|
|
430
|
+
index: number;
|
|
431
|
+
priceLow: number;
|
|
432
|
+
priceHigh: number;
|
|
433
|
+
priceMid: number;
|
|
434
|
+
volume: number;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Computed volume profile.
|
|
438
|
+
*/
|
|
439
|
+
interface VolumeProfile {
|
|
440
|
+
bins: readonly VolumeProfileBin[];
|
|
441
|
+
range: {
|
|
442
|
+
min: number;
|
|
443
|
+
max: number;
|
|
444
|
+
};
|
|
445
|
+
totalVolume: number;
|
|
446
|
+
/** Point of control, or null when there is no volume. */
|
|
447
|
+
poc: VolumeProfileBin | null;
|
|
448
|
+
valueArea: {
|
|
449
|
+
low: number;
|
|
450
|
+
high: number;
|
|
451
|
+
volume: number;
|
|
452
|
+
} | null;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Computes a deterministic volume profile from OHLCV bars.
|
|
456
|
+
*
|
|
457
|
+
* Requires the `volume-profile` license feature. Bars without a finite positive volume are
|
|
458
|
+
* ignored. Throws `WickError("INVALID_DATA")` when no usable volume remains.
|
|
459
|
+
*/
|
|
460
|
+
declare function computeVolumeProfile(context: LicenseContext, bars: readonly OhlcData[], options?: VolumeProfileOptions): VolumeProfile;
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Colors used by the volume-profile overlay.
|
|
464
|
+
*/
|
|
465
|
+
interface VolumeProfileOverlayColors {
|
|
466
|
+
bar: string;
|
|
467
|
+
valueArea: string;
|
|
468
|
+
poc: string;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Options for {@link addVolumeProfileOverlay}.
|
|
472
|
+
*/
|
|
473
|
+
interface VolumeProfileOverlayOptions extends VolumeProfileOptions {
|
|
474
|
+
/** Overlay id. Defaults to a unique pro id. */
|
|
475
|
+
id?: string;
|
|
476
|
+
/** Pane to draw in. Defaults to the main pane. */
|
|
477
|
+
paneId?: string;
|
|
478
|
+
/** Histogram side. Defaults to the left side. */
|
|
479
|
+
side?: "left" | "right";
|
|
480
|
+
/** Histogram width as a fraction of the pane plot width. Defaults to 0.22. */
|
|
481
|
+
widthRatio?: number;
|
|
482
|
+
colors?: Partial<VolumeProfileOverlayColors>;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Live volume-profile overlay.
|
|
486
|
+
*/
|
|
487
|
+
interface VolumeProfileOverlay extends ChartOverlayApi {
|
|
488
|
+
readonly profile: VolumeProfile;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Computes a volume profile and adds it to a chart as a clipped pane overlay.
|
|
492
|
+
*
|
|
493
|
+
* Requires the `volume-profile` license feature.
|
|
494
|
+
*/
|
|
495
|
+
declare function addVolumeProfileOverlay(context: LicenseContext, chart: ChartApi, bars: readonly OhlcData[], options?: VolumeProfileOverlayOptions): VolumeProfileOverlay;
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Features shipped in the commercial tier.
|
|
499
|
+
*/
|
|
500
|
+
declare const PRO_FEATURES: readonly ["orderflow", "volume-profile", "panes", "layouts", "strategy", "alerts", "script-functions"];
|
|
501
|
+
/**
|
|
502
|
+
* A feature name provided by the commercial tier.
|
|
503
|
+
*/
|
|
504
|
+
type ProFeature = (typeof PRO_FEATURES)[number];
|
|
505
|
+
/**
|
|
506
|
+
* Core feature tokens covered by the pro feature list.
|
|
507
|
+
*/
|
|
508
|
+
declare const PRO_CORE_FEATURES: readonly Feature[];
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Extension descriptor for a commercial feature.
|
|
512
|
+
*/
|
|
513
|
+
interface ProExtension extends WickExtension {
|
|
514
|
+
readonly kind: "feature";
|
|
515
|
+
readonly feature: ProFeature;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Capability descriptors for the commercial feature set.
|
|
519
|
+
*
|
|
520
|
+
* Hosts pass the granted descriptors through `ChartOptions.extensions`. Individual
|
|
521
|
+
* analytics register their runtime behavior separately.
|
|
522
|
+
*/
|
|
523
|
+
declare const PRO_EXTENSIONS: readonly ProExtension[];
|
|
524
|
+
/**
|
|
525
|
+
* Returns the feature descriptors granted by a license context.
|
|
526
|
+
*/
|
|
527
|
+
declare function getProExtensions(context: LicenseContext): readonly ProExtension[];
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Decoded payload of a Wicklib license token.
|
|
531
|
+
*
|
|
532
|
+
* Tokens are Ed25519-signed and verified offline. `exp` is seconds since the Unix
|
|
533
|
+
* epoch. `kid` selects the embedded public key.
|
|
534
|
+
*/
|
|
535
|
+
interface LicenseTokenPayload {
|
|
536
|
+
product: string;
|
|
537
|
+
plan: string;
|
|
538
|
+
seats: number;
|
|
539
|
+
domains: string[];
|
|
540
|
+
exp: number;
|
|
541
|
+
features: Feature[];
|
|
542
|
+
kid: string;
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Options for creating a license context.
|
|
546
|
+
*/
|
|
547
|
+
interface LicenseVerifierOptions {
|
|
548
|
+
/** Public keys indexed by `kid`, encoded as base64url raw Ed25519 keys. */
|
|
549
|
+
publicKeys: Readonly<Record<string, string>>;
|
|
550
|
+
/** Clock override for deterministic tests. Returns seconds since the epoch. */
|
|
551
|
+
now?: () => number;
|
|
552
|
+
/** Origin the license is being used from, if domain locking is enabled. */
|
|
553
|
+
domain?: string;
|
|
554
|
+
/** Expected product id. Defaults to wicklib-pro. */
|
|
555
|
+
product?: string;
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Machine-readable license failure codes.
|
|
559
|
+
*/
|
|
560
|
+
type LicenseErrorCode = "CRYPTO_UNAVAILABLE" | "INVALID_TOKEN" | "UNSUPPORTED_ALGORITHM" | "UNKNOWN_KID" | "INVALID_PAYLOAD" | "EXPIRED" | "WRONG_PRODUCT" | "DOMAIN_REQUIRED" | "DOMAIN_NOT_ALLOWED" | "SIGNATURE_INVALID";
|
|
561
|
+
/**
|
|
562
|
+
* Typed license verification failure.
|
|
563
|
+
*/
|
|
564
|
+
declare class LicenseError extends Error {
|
|
565
|
+
readonly code: LicenseErrorCode;
|
|
566
|
+
constructor(code: LicenseErrorCode, message: string);
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Verifies an Ed25519 license token and returns the feature context used by pro
|
|
570
|
+
* extensions.
|
|
571
|
+
*
|
|
572
|
+
* Verification is fully offline. No network or telemetry calls are made.
|
|
573
|
+
*/
|
|
574
|
+
declare function createLicenseContext(token: string, options: LicenseVerifierOptions): Promise<LicenseContext>;
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Wicklib Pro public API.
|
|
578
|
+
*
|
|
579
|
+
* The package is published to npm under the Wicklib Commercial License; its source
|
|
580
|
+
* repository is private.
|
|
581
|
+
*/
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Returns true when the active license grants a pro feature.
|
|
585
|
+
*/
|
|
586
|
+
declare function hasProFeature(context: LicenseContext, feature: Feature): boolean;
|
|
587
|
+
/**
|
|
588
|
+
* Throws `WickError("LICENSE_REQUIRED")` when a pro feature is not granted.
|
|
589
|
+
*/
|
|
590
|
+
declare function assertProFeature(context: LicenseContext, feature: Feature): void;
|
|
591
|
+
|
|
592
|
+
export { AlertEngine, DepthAggregator, FootprintAggregator, LicenseError, PRO_CORE_FEATURES, PRO_EXTENSIONS, PRO_FEATURES, PRO_VERSION, addVolumeProfileOverlay, assertProFeature, computeDepth, computeFootprint, computeVolumeProfile, createLicenseContext, detectAbsorption, evaluateAlerts, getProExtensions, hasProFeature, runBacktest, runScriptBacktest };
|
|
593
|
+
export type { AbsorptionEvent, AbsorptionOptions, AlertDirection, AlertPriceSource, AlertTrigger, BacktestFill, BacktestOptions, BacktestResult, CompiledScriptLike, DepthBar, DepthLevel, DepthLevelBar, DepthOptions, DepthSnapshot, EquityPoint, FootprintBar, FootprintLevel, FootprintOptions, LicenseErrorCode, LicenseTokenPayload, LicenseVerifierOptions, PriceAlertRule, ProExtension, ProFeature, ScriptAlertEvent, ScriptBacktestOptions, ScriptBacktestResult, ScriptRunResult, StrategyContext, StrategyFunction, StrategyTarget, TradeSide, TradeTick, VolumeProfile, VolumeProfileBin, VolumeProfileDistribution, VolumeProfileOptions, VolumeProfileOverlay, VolumeProfileOverlayColors, VolumeProfileOverlayOptions };
|