@tradejs/types 1.0.6 → 1.0.9
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/index.d.mts +124 -4
- package/dist/index.d.ts +124 -4
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -88,6 +88,42 @@ type DerivativesRow = {
|
|
|
88
88
|
liqTotal?: number | null;
|
|
89
89
|
source?: string | null;
|
|
90
90
|
};
|
|
91
|
+
type DerivativesPressure = 'neutral' | 'crowded_long' | 'crowded_short' | 'long_flush' | 'short_flush';
|
|
92
|
+
type DerivativesContextRiskFlag = 'missing_derivatives' | 'stale_derivatives' | 'crowded_long' | 'crowded_short' | 'oi_falling' | 'oi_not_confirming' | 'long_liquidation_spike' | 'short_liquidation_spike';
|
|
93
|
+
interface DerivativesIntervalContext {
|
|
94
|
+
interval: DerivativesInterval;
|
|
95
|
+
asOfTs: number | null;
|
|
96
|
+
stale: boolean;
|
|
97
|
+
points: number;
|
|
98
|
+
openInterest: number | null;
|
|
99
|
+
oiChangePct1h: number | null;
|
|
100
|
+
oiChangePct4h: number | null;
|
|
101
|
+
oiChangePct24h: number | null;
|
|
102
|
+
fundingRate: number | null;
|
|
103
|
+
fundingZScore: number | null;
|
|
104
|
+
liqLong: number | null;
|
|
105
|
+
liqShort: number | null;
|
|
106
|
+
liqTotal: number | null;
|
|
107
|
+
liqImbalance: number | null;
|
|
108
|
+
liqSpikeRatio: number | null;
|
|
109
|
+
}
|
|
110
|
+
interface DerivativesSymbolContext {
|
|
111
|
+
source: 'coinalyze';
|
|
112
|
+
symbol: string;
|
|
113
|
+
timestamp: number;
|
|
114
|
+
intervals: Partial<Record<DerivativesInterval, DerivativesIntervalContext>>;
|
|
115
|
+
summary: {
|
|
116
|
+
pressure: DerivativesPressure;
|
|
117
|
+
directionAligned: boolean | null;
|
|
118
|
+
riskFlags: DerivativesContextRiskFlag[];
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
interface DerivativesContext extends DerivativesSymbolContext {
|
|
122
|
+
targetSymbol?: string;
|
|
123
|
+
primaryReferenceSymbol?: string;
|
|
124
|
+
referenceSymbols?: string[];
|
|
125
|
+
referenceContexts?: Record<string, DerivativesSymbolContext>;
|
|
126
|
+
}
|
|
91
127
|
type SpreadRow = {
|
|
92
128
|
symbol: string;
|
|
93
129
|
interval: DerivativesInterval;
|
|
@@ -112,6 +148,7 @@ type Order = {
|
|
|
112
148
|
price: number;
|
|
113
149
|
timestamp: number;
|
|
114
150
|
direction: Direction;
|
|
151
|
+
orderId?: string;
|
|
115
152
|
signal?: Signal;
|
|
116
153
|
};
|
|
117
154
|
type Position = {
|
|
@@ -120,6 +157,10 @@ type Position = {
|
|
|
120
157
|
price: number;
|
|
121
158
|
direction: Direction;
|
|
122
159
|
};
|
|
160
|
+
interface PositionPnlSnapshot extends Position {
|
|
161
|
+
currentPrice: number;
|
|
162
|
+
unrealizedPnl: number;
|
|
163
|
+
}
|
|
123
164
|
type OrderType = 'OPEN_LONG' | 'OPEN_SHORT' | 'CLOSE_LONG' | 'CLOSE_SHORT' | 'TAKE_PROFIT_LONG' | 'TAKE_PROFIT_SHORT' | 'STOP_LOSS_LONG' | 'STOP_LOSS_SHORT';
|
|
124
165
|
type ConnectorCreator = (config: ConnectorConfig) => Promise<Connector>;
|
|
125
166
|
interface ConnectorConfig {
|
|
@@ -135,6 +176,23 @@ interface ConnectorPluginDefinition {
|
|
|
135
176
|
}
|
|
136
177
|
type GetPosition = (symbol: string) => Promise<Position | null>;
|
|
137
178
|
type GetPositions = () => Promise<Position[]>;
|
|
179
|
+
type GetOpenPositionPnl = () => Promise<PositionPnlSnapshot[]>;
|
|
180
|
+
interface ClosedPnlRecord {
|
|
181
|
+
symbol: string;
|
|
182
|
+
qty: number;
|
|
183
|
+
entryPrice: number | null;
|
|
184
|
+
exitPrice: number | null;
|
|
185
|
+
closedPnl: number;
|
|
186
|
+
closedAt: number;
|
|
187
|
+
orderId?: string;
|
|
188
|
+
}
|
|
189
|
+
interface GetClosedPnlParams {
|
|
190
|
+
startTime: number;
|
|
191
|
+
endTime: number;
|
|
192
|
+
symbol?: string;
|
|
193
|
+
limit?: number;
|
|
194
|
+
}
|
|
195
|
+
type GetClosedPnl = (params: GetClosedPnlParams) => Promise<ClosedPnlRecord[]>;
|
|
138
196
|
type PlaceOrder = (order: Order) => Promise<boolean>;
|
|
139
197
|
type ClosePosition = (order: Omit<Order, 'qty'>) => Promise<boolean>;
|
|
140
198
|
type SetTakeProfits = (params: {
|
|
@@ -156,6 +214,8 @@ interface Connector {
|
|
|
156
214
|
setState: (state: object) => Promise<void>;
|
|
157
215
|
getPosition: GetPosition;
|
|
158
216
|
getPositions: GetPositions;
|
|
217
|
+
getOpenPositionPnl?: GetOpenPositionPnl;
|
|
218
|
+
getClosedPnl?: GetClosedPnl;
|
|
159
219
|
placeOrder: PlaceOrder;
|
|
160
220
|
setTakeProfits: SetTakeProfits;
|
|
161
221
|
setStopLoss: SetStopLoss;
|
|
@@ -269,14 +329,16 @@ interface TrendLineOptions {
|
|
|
269
329
|
}
|
|
270
330
|
interface Signal {
|
|
271
331
|
signalId: string;
|
|
332
|
+
orderId?: string;
|
|
272
333
|
symbol: string;
|
|
273
334
|
interval: Interval;
|
|
274
335
|
strategy: string;
|
|
275
336
|
direction: Direction;
|
|
276
337
|
timestamp: number;
|
|
277
|
-
orderStatus?:
|
|
338
|
+
orderStatus?: SignalOrderStatus;
|
|
278
339
|
orderSkipReason?: string;
|
|
279
340
|
isConfigFromBacktest?: boolean;
|
|
341
|
+
aiAnalysis?: Partial<SignalAnalysis>;
|
|
280
342
|
ml?: {
|
|
281
343
|
probability: number;
|
|
282
344
|
threshold: number;
|
|
@@ -298,6 +360,24 @@ interface Signal {
|
|
|
298
360
|
indicators: Record<string, any>;
|
|
299
361
|
additionalIndicators?: Record<string, any>;
|
|
300
362
|
}
|
|
363
|
+
type RuntimeSignalEvaluationStatus = 'signal' | 'skip' | 'error';
|
|
364
|
+
interface RuntimeSignalEvaluationRecord {
|
|
365
|
+
evaluationId: string;
|
|
366
|
+
userName: string;
|
|
367
|
+
strategy: string;
|
|
368
|
+
symbol: string;
|
|
369
|
+
interval: Interval;
|
|
370
|
+
timestamp: number;
|
|
371
|
+
evaluatedAt: number;
|
|
372
|
+
status: RuntimeSignalEvaluationStatus;
|
|
373
|
+
reason?: string;
|
|
374
|
+
signalId?: string;
|
|
375
|
+
direction?: Direction;
|
|
376
|
+
orderStatus?: SignalOrderStatus;
|
|
377
|
+
orderSkipReason?: string;
|
|
378
|
+
aiAnalysis?: Partial<SignalAnalysis> | null;
|
|
379
|
+
ml?: Signal['ml'];
|
|
380
|
+
}
|
|
301
381
|
interface SignalAnalysis {
|
|
302
382
|
direction: Direction | null;
|
|
303
383
|
quality: 1 | 2 | 3 | 4 | 5 | number;
|
|
@@ -312,8 +392,40 @@ interface SignalAnalysis {
|
|
|
312
392
|
riskLevels?: string;
|
|
313
393
|
qualityReason?: string;
|
|
314
394
|
triggerInvalidation?: string;
|
|
395
|
+
gateAnalysis?: Partial<SignalAnalysis>;
|
|
396
|
+
gateContradictsLlm?: boolean;
|
|
397
|
+
gateDecision?: 'approved' | 'rejected';
|
|
398
|
+
llmDecision?: 'approved' | 'rejected';
|
|
315
399
|
comment: string;
|
|
316
400
|
}
|
|
401
|
+
interface RuntimeAiAnalysisSnapshot {
|
|
402
|
+
strategy?: string;
|
|
403
|
+
symbol: string;
|
|
404
|
+
direction: Direction;
|
|
405
|
+
timestamp: number;
|
|
406
|
+
toleranceMs?: number;
|
|
407
|
+
analysis: Partial<SignalAnalysis>;
|
|
408
|
+
}
|
|
409
|
+
type SignalOrderStatus = 'completed' | 'failed' | 'skipped' | 'canceled';
|
|
410
|
+
type RuntimeTradeStatus = 'active' | 'closed';
|
|
411
|
+
interface RuntimeTradeRecord {
|
|
412
|
+
orderId: string;
|
|
413
|
+
signalId?: string;
|
|
414
|
+
strategy: string;
|
|
415
|
+
symbol: string;
|
|
416
|
+
direction: Direction;
|
|
417
|
+
qty: number;
|
|
418
|
+
entryPrice: number;
|
|
419
|
+
entryTimestamp: number;
|
|
420
|
+
status: RuntimeTradeStatus;
|
|
421
|
+
currentPrice?: number | null;
|
|
422
|
+
currentPnl?: number | null;
|
|
423
|
+
closedPnl?: number | null;
|
|
424
|
+
exitPrice?: number | null;
|
|
425
|
+
exitTimestamp?: number | null;
|
|
426
|
+
aiAnalysis?: Partial<SignalAnalysis> | null;
|
|
427
|
+
lastSyncedAt?: number;
|
|
428
|
+
}
|
|
317
429
|
|
|
318
430
|
type Strategy = (candle: KlineChartItem, btcCandle: KlineChartItem) => Promise<string | Signal>;
|
|
319
431
|
type BacktestPriceMode = 'mid' | 'close' | 'open' | 'rand';
|
|
@@ -372,6 +484,7 @@ interface TestingBoxResult {
|
|
|
372
484
|
stat: MinimalStat;
|
|
373
485
|
inlineOrderLog?: OrderLogData;
|
|
374
486
|
inlinePositionLog?: PositionLogData;
|
|
487
|
+
inlineReplaySignalEvaluations?: RuntimeSignalEvaluationRecord[];
|
|
375
488
|
}
|
|
376
489
|
type TestingBox = (test: Test) => Promise<TestingBoxResult | null>;
|
|
377
490
|
interface TestWorkerResult extends TestingBoxResult {
|
|
@@ -683,9 +796,12 @@ interface StrategyRuntimeMlOptions {
|
|
|
683
796
|
strategyConfig?: StrategyConfig;
|
|
684
797
|
mlThreshold?: number;
|
|
685
798
|
}
|
|
799
|
+
type StrategyAiMode = 'gate' | 'llm';
|
|
686
800
|
interface StrategyRuntimeAiOptions {
|
|
687
801
|
enabled?: boolean;
|
|
802
|
+
mode?: StrategyAiMode;
|
|
688
803
|
minQuality?: number;
|
|
804
|
+
replayAnalyses?: RuntimeAiAnalysisSnapshot[];
|
|
689
805
|
}
|
|
690
806
|
interface StrategyEntryRuntimeOptions {
|
|
691
807
|
ml?: StrategyRuntimeMlOptions;
|
|
@@ -867,7 +983,7 @@ interface StrategyHookAiContext {
|
|
|
867
983
|
quality?: number;
|
|
868
984
|
skippedReason?: StrategyHookAiSkippedReason;
|
|
869
985
|
}
|
|
870
|
-
type StrategyHookStage = 'onInit' | 'afterCoreDecision' | 'onSkip' | 'beforeClosePosition' | 'afterEnrichMl' | 'afterEnrichAi' | 'beforeEntryGate' | 'beforePlaceOrder' | 'afterPlaceOrder' | 'runtime.beforePlaceOrder' | 'enrichSignalWithMl' | 'enrichSignalWithAi' | 'setTakeProfits' | 'setStopLoss' | 'protectPosition' | 'closePosition' | 'placeOrder';
|
|
986
|
+
type StrategyHookStage = 'onInit' | 'onBar' | 'afterCoreDecision' | 'afterBarDecision' | 'onSkip' | 'beforeClosePosition' | 'afterEnrichMl' | 'afterEnrichAi' | 'beforeEntryGate' | 'beforePlaceOrder' | 'afterPlaceOrder' | 'runtime.beforePlaceOrder' | 'enrichSignalWithMl' | 'enrichSignalWithAi' | 'setTakeProfits' | 'setStopLoss' | 'protectPosition' | 'closePosition' | 'placeOrder';
|
|
871
987
|
interface StrategyHookErrorPayload {
|
|
872
988
|
stage: StrategyHookStage;
|
|
873
989
|
cause: unknown;
|
|
@@ -883,9 +999,11 @@ interface StrategyHookInitContext {
|
|
|
883
999
|
ctx: StrategyHookCtx;
|
|
884
1000
|
market: Required<Pick<StrategyHookMarketContext, 'data' | 'btcData'>>;
|
|
885
1001
|
}
|
|
886
|
-
interface
|
|
1002
|
+
interface StrategyHookBarContext {
|
|
887
1003
|
ctx: StrategyHookCtx;
|
|
888
1004
|
market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
|
|
1005
|
+
}
|
|
1006
|
+
interface StrategyHookAfterDecisionContext extends StrategyHookBarContext {
|
|
889
1007
|
decision: StrategyDecision;
|
|
890
1008
|
}
|
|
891
1009
|
interface StrategyHookSkipContext extends StrategyHookAfterDecisionContext {
|
|
@@ -950,7 +1068,9 @@ interface StrategyManifest {
|
|
|
950
1068
|
};
|
|
951
1069
|
hooks?: {
|
|
952
1070
|
onInit?: (params: StrategyHookInitContext) => Promise<void> | void;
|
|
1071
|
+
onBar?: (params: StrategyHookBarContext) => Promise<StrategyDecision | void> | StrategyDecision | void;
|
|
953
1072
|
afterCoreDecision?: (params: StrategyHookAfterDecisionContext) => Promise<void> | void;
|
|
1073
|
+
afterBarDecision?: (params: StrategyHookAfterDecisionContext) => Promise<void> | void;
|
|
954
1074
|
onSkip?: (params: StrategyHookSkipContext) => Promise<void> | void;
|
|
955
1075
|
beforeClosePosition?: (params: StrategyHookBeforeCloseContext) => Promise<StrategyHookGateResult | void> | StrategyHookGateResult | void;
|
|
956
1076
|
afterEnrichMl?: (params: StrategyHookEnrichContext) => Promise<void> | void;
|
|
@@ -988,4 +1108,4 @@ interface AiDatasetRow {
|
|
|
988
1108
|
connectorName?: string;
|
|
989
1109
|
}
|
|
990
1110
|
|
|
991
|
-
export type { AIChatHistory, AIChatMessage, AiDatasetRow, AiPayload, AiPromptPair, BacktestPriceMode, BacktestRunConfig, BaseIndicatorsHistorySnapshot, Bot, BotConfig, BotResults, BotStatus, BuildStrategySignalDraft, BuildStrategySignalParams, Candle, ChartColor, CompletedTest, Connector, ConnectorConfig, ConnectorCreator, ConnectorPluginDefinition, ConnectorRegistryEntry, CreateStrategyCore, CreateStrategyCoreParams, DerivativesInterval, DerivativesRow, Direction, EOMPoint, Figure, Filters, GetTickers, Indicator, IndicatorPluginComputeParams, IndicatorPluginDefinition, IndicatorPluginEntry, IndicatorPluginFigureRenderer, IndicatorPluginRenderer, IndicatorSnapshot, Indicators, IndicatorsHistorySnapshot, Interval, Item, Items, Kline, KlineChartData, KlineChartItem, KlineRequest, MetricThreshold, Metrics, MinimalStat, MlCandleIndicatorsSnapshot, MonthlyEquityStats, OnChangeCompare, OnChangeFilters, Order, OrderLog, OrderLogData, OrderType, Position, PositionLog, PositionLogData, Provider, Signal, SignalAnalysis, SimpleOrderLogData, Sl, SpreadRow, Strategy, StrategyAPI, StrategyAPIEntryParams, StrategyAPIExitParams, StrategyAPIMarketDataParams, StrategyAPIProtectParams, StrategyAdditionalIndicatorsMap, StrategyAiAdapter, StrategyClosePlan, StrategyConfig, StrategyConfigGrid, StrategyCoreRunner, StrategyCreator, StrategyCreatorParams, StrategyDecision, StrategyDirectionalTpSlParams, StrategyDirectionalTpSlResult, StrategyEntryBaseParams, StrategyEntryModelFigures, StrategyEntryOrderPlan, StrategyEntryRuntimeBaseParams, StrategyEntryRuntimeBuilderParams, StrategyEntryRuntimeOptions, StrategyEntrySignalContext, StrategyEntrySignalDecisionBuilderParams, StrategyEntryTakeProfitsParams, StrategyFigureLine, StrategyFigurePoint, StrategyFigurePoints, StrategyFigureZone, StrategyHookAfterAiContext, StrategyHookAfterDecisionContext, StrategyHookAfterPlaceOrderContext, StrategyHookAiContext, StrategyHookAiSkippedReason, StrategyHookBeforeCloseContext, StrategyHookBeforeEntryGateContext, StrategyHookBeforePlaceOrderContext, StrategyHookCtx, StrategyHookEnrichContext, StrategyHookEntryContext, StrategyHookErrorContext, StrategyHookErrorPayload, StrategyHookGateResult, StrategyHookInitContext, StrategyHookMarketContext, StrategyHookMlContext, StrategyHookMlSkippedReason, StrategyHookOrderContext, StrategyHookPolicyContext, StrategyHookSkipContext, StrategyHookStage, StrategyIndicatorsMap, StrategyIndicatorsState, StrategyLastTradeController, StrategyLastTradeControllerParams, StrategyManifest, StrategyMarketSnapshot, StrategyMlAdapter, StrategyPluginDefinition, StrategyProtectPlan, StrategyRegistryEntry, StrategyResultConfig, StrategyResultEntry, StrategyResults, StrategyRuntimeAiOptions, StrategyRuntimeMlOptions, StrategySignalMetaParams, StrategySignalPriceParams, Test, TestCompare, TestCompareList, TestConnector, TestConnectorContext, TestConnectorCreator, TestResult, TestStat, TestSuite, TestThresholds, TestThresholdsKey, TestWorkerResult, TestingBox, TestingBoxResult, TestingOptions, ThresholdLevel, Ticker, Tp, Trend, TrendLine, TrendLineMode, TrendLineOptions, UIFilters };
|
|
1111
|
+
export type { AIChatHistory, AIChatMessage, AiDatasetRow, AiPayload, AiPromptPair, BacktestPriceMode, BacktestRunConfig, BaseIndicatorsHistorySnapshot, Bot, BotConfig, BotResults, BotStatus, BuildStrategySignalDraft, BuildStrategySignalParams, Candle, ChartColor, ClosedPnlRecord, CompletedTest, Connector, ConnectorConfig, ConnectorCreator, ConnectorPluginDefinition, ConnectorRegistryEntry, CreateStrategyCore, CreateStrategyCoreParams, DerivativesContext, DerivativesContextRiskFlag, DerivativesInterval, DerivativesIntervalContext, DerivativesPressure, DerivativesRow, DerivativesSymbolContext, Direction, EOMPoint, Figure, Filters, GetClosedPnlParams, GetTickers, Indicator, IndicatorPluginComputeParams, IndicatorPluginDefinition, IndicatorPluginEntry, IndicatorPluginFigureRenderer, IndicatorPluginRenderer, IndicatorSnapshot, Indicators, IndicatorsHistorySnapshot, Interval, Item, Items, Kline, KlineChartData, KlineChartItem, KlineRequest, MetricThreshold, Metrics, MinimalStat, MlCandleIndicatorsSnapshot, MonthlyEquityStats, OnChangeCompare, OnChangeFilters, Order, OrderLog, OrderLogData, OrderType, Position, PositionLog, PositionLogData, PositionPnlSnapshot, Provider, RuntimeAiAnalysisSnapshot, RuntimeSignalEvaluationRecord, RuntimeSignalEvaluationStatus, RuntimeTradeRecord, RuntimeTradeStatus, Signal, SignalAnalysis, SignalOrderStatus, SimpleOrderLogData, Sl, SpreadRow, Strategy, StrategyAPI, StrategyAPIEntryParams, StrategyAPIExitParams, StrategyAPIMarketDataParams, StrategyAPIProtectParams, StrategyAdditionalIndicatorsMap, StrategyAiAdapter, StrategyAiMode, StrategyClosePlan, StrategyConfig, StrategyConfigGrid, StrategyCoreRunner, StrategyCreator, StrategyCreatorParams, StrategyDecision, StrategyDirectionalTpSlParams, StrategyDirectionalTpSlResult, StrategyEntryBaseParams, StrategyEntryModelFigures, StrategyEntryOrderPlan, StrategyEntryRuntimeBaseParams, StrategyEntryRuntimeBuilderParams, StrategyEntryRuntimeOptions, StrategyEntrySignalContext, StrategyEntrySignalDecisionBuilderParams, StrategyEntryTakeProfitsParams, StrategyFigureLine, StrategyFigurePoint, StrategyFigurePoints, StrategyFigureZone, StrategyHookAfterAiContext, StrategyHookAfterDecisionContext, StrategyHookAfterPlaceOrderContext, StrategyHookAiContext, StrategyHookAiSkippedReason, StrategyHookBarContext, StrategyHookBeforeCloseContext, StrategyHookBeforeEntryGateContext, StrategyHookBeforePlaceOrderContext, StrategyHookCtx, StrategyHookEnrichContext, StrategyHookEntryContext, StrategyHookErrorContext, StrategyHookErrorPayload, StrategyHookGateResult, StrategyHookInitContext, StrategyHookMarketContext, StrategyHookMlContext, StrategyHookMlSkippedReason, StrategyHookOrderContext, StrategyHookPolicyContext, StrategyHookSkipContext, StrategyHookStage, StrategyIndicatorsMap, StrategyIndicatorsState, StrategyLastTradeController, StrategyLastTradeControllerParams, StrategyManifest, StrategyMarketSnapshot, StrategyMlAdapter, StrategyPluginDefinition, StrategyProtectPlan, StrategyRegistryEntry, StrategyResultConfig, StrategyResultEntry, StrategyResults, StrategyRuntimeAiOptions, StrategyRuntimeMlOptions, StrategySignalMetaParams, StrategySignalPriceParams, Test, TestCompare, TestCompareList, TestConnector, TestConnectorContext, TestConnectorCreator, TestResult, TestStat, TestSuite, TestThresholds, TestThresholdsKey, TestWorkerResult, TestingBox, TestingBoxResult, TestingOptions, ThresholdLevel, Ticker, Tp, Trend, TrendLine, TrendLineMode, TrendLineOptions, UIFilters };
|
package/dist/index.d.ts
CHANGED
|
@@ -88,6 +88,42 @@ type DerivativesRow = {
|
|
|
88
88
|
liqTotal?: number | null;
|
|
89
89
|
source?: string | null;
|
|
90
90
|
};
|
|
91
|
+
type DerivativesPressure = 'neutral' | 'crowded_long' | 'crowded_short' | 'long_flush' | 'short_flush';
|
|
92
|
+
type DerivativesContextRiskFlag = 'missing_derivatives' | 'stale_derivatives' | 'crowded_long' | 'crowded_short' | 'oi_falling' | 'oi_not_confirming' | 'long_liquidation_spike' | 'short_liquidation_spike';
|
|
93
|
+
interface DerivativesIntervalContext {
|
|
94
|
+
interval: DerivativesInterval;
|
|
95
|
+
asOfTs: number | null;
|
|
96
|
+
stale: boolean;
|
|
97
|
+
points: number;
|
|
98
|
+
openInterest: number | null;
|
|
99
|
+
oiChangePct1h: number | null;
|
|
100
|
+
oiChangePct4h: number | null;
|
|
101
|
+
oiChangePct24h: number | null;
|
|
102
|
+
fundingRate: number | null;
|
|
103
|
+
fundingZScore: number | null;
|
|
104
|
+
liqLong: number | null;
|
|
105
|
+
liqShort: number | null;
|
|
106
|
+
liqTotal: number | null;
|
|
107
|
+
liqImbalance: number | null;
|
|
108
|
+
liqSpikeRatio: number | null;
|
|
109
|
+
}
|
|
110
|
+
interface DerivativesSymbolContext {
|
|
111
|
+
source: 'coinalyze';
|
|
112
|
+
symbol: string;
|
|
113
|
+
timestamp: number;
|
|
114
|
+
intervals: Partial<Record<DerivativesInterval, DerivativesIntervalContext>>;
|
|
115
|
+
summary: {
|
|
116
|
+
pressure: DerivativesPressure;
|
|
117
|
+
directionAligned: boolean | null;
|
|
118
|
+
riskFlags: DerivativesContextRiskFlag[];
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
interface DerivativesContext extends DerivativesSymbolContext {
|
|
122
|
+
targetSymbol?: string;
|
|
123
|
+
primaryReferenceSymbol?: string;
|
|
124
|
+
referenceSymbols?: string[];
|
|
125
|
+
referenceContexts?: Record<string, DerivativesSymbolContext>;
|
|
126
|
+
}
|
|
91
127
|
type SpreadRow = {
|
|
92
128
|
symbol: string;
|
|
93
129
|
interval: DerivativesInterval;
|
|
@@ -112,6 +148,7 @@ type Order = {
|
|
|
112
148
|
price: number;
|
|
113
149
|
timestamp: number;
|
|
114
150
|
direction: Direction;
|
|
151
|
+
orderId?: string;
|
|
115
152
|
signal?: Signal;
|
|
116
153
|
};
|
|
117
154
|
type Position = {
|
|
@@ -120,6 +157,10 @@ type Position = {
|
|
|
120
157
|
price: number;
|
|
121
158
|
direction: Direction;
|
|
122
159
|
};
|
|
160
|
+
interface PositionPnlSnapshot extends Position {
|
|
161
|
+
currentPrice: number;
|
|
162
|
+
unrealizedPnl: number;
|
|
163
|
+
}
|
|
123
164
|
type OrderType = 'OPEN_LONG' | 'OPEN_SHORT' | 'CLOSE_LONG' | 'CLOSE_SHORT' | 'TAKE_PROFIT_LONG' | 'TAKE_PROFIT_SHORT' | 'STOP_LOSS_LONG' | 'STOP_LOSS_SHORT';
|
|
124
165
|
type ConnectorCreator = (config: ConnectorConfig) => Promise<Connector>;
|
|
125
166
|
interface ConnectorConfig {
|
|
@@ -135,6 +176,23 @@ interface ConnectorPluginDefinition {
|
|
|
135
176
|
}
|
|
136
177
|
type GetPosition = (symbol: string) => Promise<Position | null>;
|
|
137
178
|
type GetPositions = () => Promise<Position[]>;
|
|
179
|
+
type GetOpenPositionPnl = () => Promise<PositionPnlSnapshot[]>;
|
|
180
|
+
interface ClosedPnlRecord {
|
|
181
|
+
symbol: string;
|
|
182
|
+
qty: number;
|
|
183
|
+
entryPrice: number | null;
|
|
184
|
+
exitPrice: number | null;
|
|
185
|
+
closedPnl: number;
|
|
186
|
+
closedAt: number;
|
|
187
|
+
orderId?: string;
|
|
188
|
+
}
|
|
189
|
+
interface GetClosedPnlParams {
|
|
190
|
+
startTime: number;
|
|
191
|
+
endTime: number;
|
|
192
|
+
symbol?: string;
|
|
193
|
+
limit?: number;
|
|
194
|
+
}
|
|
195
|
+
type GetClosedPnl = (params: GetClosedPnlParams) => Promise<ClosedPnlRecord[]>;
|
|
138
196
|
type PlaceOrder = (order: Order) => Promise<boolean>;
|
|
139
197
|
type ClosePosition = (order: Omit<Order, 'qty'>) => Promise<boolean>;
|
|
140
198
|
type SetTakeProfits = (params: {
|
|
@@ -156,6 +214,8 @@ interface Connector {
|
|
|
156
214
|
setState: (state: object) => Promise<void>;
|
|
157
215
|
getPosition: GetPosition;
|
|
158
216
|
getPositions: GetPositions;
|
|
217
|
+
getOpenPositionPnl?: GetOpenPositionPnl;
|
|
218
|
+
getClosedPnl?: GetClosedPnl;
|
|
159
219
|
placeOrder: PlaceOrder;
|
|
160
220
|
setTakeProfits: SetTakeProfits;
|
|
161
221
|
setStopLoss: SetStopLoss;
|
|
@@ -269,14 +329,16 @@ interface TrendLineOptions {
|
|
|
269
329
|
}
|
|
270
330
|
interface Signal {
|
|
271
331
|
signalId: string;
|
|
332
|
+
orderId?: string;
|
|
272
333
|
symbol: string;
|
|
273
334
|
interval: Interval;
|
|
274
335
|
strategy: string;
|
|
275
336
|
direction: Direction;
|
|
276
337
|
timestamp: number;
|
|
277
|
-
orderStatus?:
|
|
338
|
+
orderStatus?: SignalOrderStatus;
|
|
278
339
|
orderSkipReason?: string;
|
|
279
340
|
isConfigFromBacktest?: boolean;
|
|
341
|
+
aiAnalysis?: Partial<SignalAnalysis>;
|
|
280
342
|
ml?: {
|
|
281
343
|
probability: number;
|
|
282
344
|
threshold: number;
|
|
@@ -298,6 +360,24 @@ interface Signal {
|
|
|
298
360
|
indicators: Record<string, any>;
|
|
299
361
|
additionalIndicators?: Record<string, any>;
|
|
300
362
|
}
|
|
363
|
+
type RuntimeSignalEvaluationStatus = 'signal' | 'skip' | 'error';
|
|
364
|
+
interface RuntimeSignalEvaluationRecord {
|
|
365
|
+
evaluationId: string;
|
|
366
|
+
userName: string;
|
|
367
|
+
strategy: string;
|
|
368
|
+
symbol: string;
|
|
369
|
+
interval: Interval;
|
|
370
|
+
timestamp: number;
|
|
371
|
+
evaluatedAt: number;
|
|
372
|
+
status: RuntimeSignalEvaluationStatus;
|
|
373
|
+
reason?: string;
|
|
374
|
+
signalId?: string;
|
|
375
|
+
direction?: Direction;
|
|
376
|
+
orderStatus?: SignalOrderStatus;
|
|
377
|
+
orderSkipReason?: string;
|
|
378
|
+
aiAnalysis?: Partial<SignalAnalysis> | null;
|
|
379
|
+
ml?: Signal['ml'];
|
|
380
|
+
}
|
|
301
381
|
interface SignalAnalysis {
|
|
302
382
|
direction: Direction | null;
|
|
303
383
|
quality: 1 | 2 | 3 | 4 | 5 | number;
|
|
@@ -312,8 +392,40 @@ interface SignalAnalysis {
|
|
|
312
392
|
riskLevels?: string;
|
|
313
393
|
qualityReason?: string;
|
|
314
394
|
triggerInvalidation?: string;
|
|
395
|
+
gateAnalysis?: Partial<SignalAnalysis>;
|
|
396
|
+
gateContradictsLlm?: boolean;
|
|
397
|
+
gateDecision?: 'approved' | 'rejected';
|
|
398
|
+
llmDecision?: 'approved' | 'rejected';
|
|
315
399
|
comment: string;
|
|
316
400
|
}
|
|
401
|
+
interface RuntimeAiAnalysisSnapshot {
|
|
402
|
+
strategy?: string;
|
|
403
|
+
symbol: string;
|
|
404
|
+
direction: Direction;
|
|
405
|
+
timestamp: number;
|
|
406
|
+
toleranceMs?: number;
|
|
407
|
+
analysis: Partial<SignalAnalysis>;
|
|
408
|
+
}
|
|
409
|
+
type SignalOrderStatus = 'completed' | 'failed' | 'skipped' | 'canceled';
|
|
410
|
+
type RuntimeTradeStatus = 'active' | 'closed';
|
|
411
|
+
interface RuntimeTradeRecord {
|
|
412
|
+
orderId: string;
|
|
413
|
+
signalId?: string;
|
|
414
|
+
strategy: string;
|
|
415
|
+
symbol: string;
|
|
416
|
+
direction: Direction;
|
|
417
|
+
qty: number;
|
|
418
|
+
entryPrice: number;
|
|
419
|
+
entryTimestamp: number;
|
|
420
|
+
status: RuntimeTradeStatus;
|
|
421
|
+
currentPrice?: number | null;
|
|
422
|
+
currentPnl?: number | null;
|
|
423
|
+
closedPnl?: number | null;
|
|
424
|
+
exitPrice?: number | null;
|
|
425
|
+
exitTimestamp?: number | null;
|
|
426
|
+
aiAnalysis?: Partial<SignalAnalysis> | null;
|
|
427
|
+
lastSyncedAt?: number;
|
|
428
|
+
}
|
|
317
429
|
|
|
318
430
|
type Strategy = (candle: KlineChartItem, btcCandle: KlineChartItem) => Promise<string | Signal>;
|
|
319
431
|
type BacktestPriceMode = 'mid' | 'close' | 'open' | 'rand';
|
|
@@ -372,6 +484,7 @@ interface TestingBoxResult {
|
|
|
372
484
|
stat: MinimalStat;
|
|
373
485
|
inlineOrderLog?: OrderLogData;
|
|
374
486
|
inlinePositionLog?: PositionLogData;
|
|
487
|
+
inlineReplaySignalEvaluations?: RuntimeSignalEvaluationRecord[];
|
|
375
488
|
}
|
|
376
489
|
type TestingBox = (test: Test) => Promise<TestingBoxResult | null>;
|
|
377
490
|
interface TestWorkerResult extends TestingBoxResult {
|
|
@@ -683,9 +796,12 @@ interface StrategyRuntimeMlOptions {
|
|
|
683
796
|
strategyConfig?: StrategyConfig;
|
|
684
797
|
mlThreshold?: number;
|
|
685
798
|
}
|
|
799
|
+
type StrategyAiMode = 'gate' | 'llm';
|
|
686
800
|
interface StrategyRuntimeAiOptions {
|
|
687
801
|
enabled?: boolean;
|
|
802
|
+
mode?: StrategyAiMode;
|
|
688
803
|
minQuality?: number;
|
|
804
|
+
replayAnalyses?: RuntimeAiAnalysisSnapshot[];
|
|
689
805
|
}
|
|
690
806
|
interface StrategyEntryRuntimeOptions {
|
|
691
807
|
ml?: StrategyRuntimeMlOptions;
|
|
@@ -867,7 +983,7 @@ interface StrategyHookAiContext {
|
|
|
867
983
|
quality?: number;
|
|
868
984
|
skippedReason?: StrategyHookAiSkippedReason;
|
|
869
985
|
}
|
|
870
|
-
type StrategyHookStage = 'onInit' | 'afterCoreDecision' | 'onSkip' | 'beforeClosePosition' | 'afterEnrichMl' | 'afterEnrichAi' | 'beforeEntryGate' | 'beforePlaceOrder' | 'afterPlaceOrder' | 'runtime.beforePlaceOrder' | 'enrichSignalWithMl' | 'enrichSignalWithAi' | 'setTakeProfits' | 'setStopLoss' | 'protectPosition' | 'closePosition' | 'placeOrder';
|
|
986
|
+
type StrategyHookStage = 'onInit' | 'onBar' | 'afterCoreDecision' | 'afterBarDecision' | 'onSkip' | 'beforeClosePosition' | 'afterEnrichMl' | 'afterEnrichAi' | 'beforeEntryGate' | 'beforePlaceOrder' | 'afterPlaceOrder' | 'runtime.beforePlaceOrder' | 'enrichSignalWithMl' | 'enrichSignalWithAi' | 'setTakeProfits' | 'setStopLoss' | 'protectPosition' | 'closePosition' | 'placeOrder';
|
|
871
987
|
interface StrategyHookErrorPayload {
|
|
872
988
|
stage: StrategyHookStage;
|
|
873
989
|
cause: unknown;
|
|
@@ -883,9 +999,11 @@ interface StrategyHookInitContext {
|
|
|
883
999
|
ctx: StrategyHookCtx;
|
|
884
1000
|
market: Required<Pick<StrategyHookMarketContext, 'data' | 'btcData'>>;
|
|
885
1001
|
}
|
|
886
|
-
interface
|
|
1002
|
+
interface StrategyHookBarContext {
|
|
887
1003
|
ctx: StrategyHookCtx;
|
|
888
1004
|
market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
|
|
1005
|
+
}
|
|
1006
|
+
interface StrategyHookAfterDecisionContext extends StrategyHookBarContext {
|
|
889
1007
|
decision: StrategyDecision;
|
|
890
1008
|
}
|
|
891
1009
|
interface StrategyHookSkipContext extends StrategyHookAfterDecisionContext {
|
|
@@ -950,7 +1068,9 @@ interface StrategyManifest {
|
|
|
950
1068
|
};
|
|
951
1069
|
hooks?: {
|
|
952
1070
|
onInit?: (params: StrategyHookInitContext) => Promise<void> | void;
|
|
1071
|
+
onBar?: (params: StrategyHookBarContext) => Promise<StrategyDecision | void> | StrategyDecision | void;
|
|
953
1072
|
afterCoreDecision?: (params: StrategyHookAfterDecisionContext) => Promise<void> | void;
|
|
1073
|
+
afterBarDecision?: (params: StrategyHookAfterDecisionContext) => Promise<void> | void;
|
|
954
1074
|
onSkip?: (params: StrategyHookSkipContext) => Promise<void> | void;
|
|
955
1075
|
beforeClosePosition?: (params: StrategyHookBeforeCloseContext) => Promise<StrategyHookGateResult | void> | StrategyHookGateResult | void;
|
|
956
1076
|
afterEnrichMl?: (params: StrategyHookEnrichContext) => Promise<void> | void;
|
|
@@ -988,4 +1108,4 @@ interface AiDatasetRow {
|
|
|
988
1108
|
connectorName?: string;
|
|
989
1109
|
}
|
|
990
1110
|
|
|
991
|
-
export type { AIChatHistory, AIChatMessage, AiDatasetRow, AiPayload, AiPromptPair, BacktestPriceMode, BacktestRunConfig, BaseIndicatorsHistorySnapshot, Bot, BotConfig, BotResults, BotStatus, BuildStrategySignalDraft, BuildStrategySignalParams, Candle, ChartColor, CompletedTest, Connector, ConnectorConfig, ConnectorCreator, ConnectorPluginDefinition, ConnectorRegistryEntry, CreateStrategyCore, CreateStrategyCoreParams, DerivativesInterval, DerivativesRow, Direction, EOMPoint, Figure, Filters, GetTickers, Indicator, IndicatorPluginComputeParams, IndicatorPluginDefinition, IndicatorPluginEntry, IndicatorPluginFigureRenderer, IndicatorPluginRenderer, IndicatorSnapshot, Indicators, IndicatorsHistorySnapshot, Interval, Item, Items, Kline, KlineChartData, KlineChartItem, KlineRequest, MetricThreshold, Metrics, MinimalStat, MlCandleIndicatorsSnapshot, MonthlyEquityStats, OnChangeCompare, OnChangeFilters, Order, OrderLog, OrderLogData, OrderType, Position, PositionLog, PositionLogData, Provider, Signal, SignalAnalysis, SimpleOrderLogData, Sl, SpreadRow, Strategy, StrategyAPI, StrategyAPIEntryParams, StrategyAPIExitParams, StrategyAPIMarketDataParams, StrategyAPIProtectParams, StrategyAdditionalIndicatorsMap, StrategyAiAdapter, StrategyClosePlan, StrategyConfig, StrategyConfigGrid, StrategyCoreRunner, StrategyCreator, StrategyCreatorParams, StrategyDecision, StrategyDirectionalTpSlParams, StrategyDirectionalTpSlResult, StrategyEntryBaseParams, StrategyEntryModelFigures, StrategyEntryOrderPlan, StrategyEntryRuntimeBaseParams, StrategyEntryRuntimeBuilderParams, StrategyEntryRuntimeOptions, StrategyEntrySignalContext, StrategyEntrySignalDecisionBuilderParams, StrategyEntryTakeProfitsParams, StrategyFigureLine, StrategyFigurePoint, StrategyFigurePoints, StrategyFigureZone, StrategyHookAfterAiContext, StrategyHookAfterDecisionContext, StrategyHookAfterPlaceOrderContext, StrategyHookAiContext, StrategyHookAiSkippedReason, StrategyHookBeforeCloseContext, StrategyHookBeforeEntryGateContext, StrategyHookBeforePlaceOrderContext, StrategyHookCtx, StrategyHookEnrichContext, StrategyHookEntryContext, StrategyHookErrorContext, StrategyHookErrorPayload, StrategyHookGateResult, StrategyHookInitContext, StrategyHookMarketContext, StrategyHookMlContext, StrategyHookMlSkippedReason, StrategyHookOrderContext, StrategyHookPolicyContext, StrategyHookSkipContext, StrategyHookStage, StrategyIndicatorsMap, StrategyIndicatorsState, StrategyLastTradeController, StrategyLastTradeControllerParams, StrategyManifest, StrategyMarketSnapshot, StrategyMlAdapter, StrategyPluginDefinition, StrategyProtectPlan, StrategyRegistryEntry, StrategyResultConfig, StrategyResultEntry, StrategyResults, StrategyRuntimeAiOptions, StrategyRuntimeMlOptions, StrategySignalMetaParams, StrategySignalPriceParams, Test, TestCompare, TestCompareList, TestConnector, TestConnectorContext, TestConnectorCreator, TestResult, TestStat, TestSuite, TestThresholds, TestThresholdsKey, TestWorkerResult, TestingBox, TestingBoxResult, TestingOptions, ThresholdLevel, Ticker, Tp, Trend, TrendLine, TrendLineMode, TrendLineOptions, UIFilters };
|
|
1111
|
+
export type { AIChatHistory, AIChatMessage, AiDatasetRow, AiPayload, AiPromptPair, BacktestPriceMode, BacktestRunConfig, BaseIndicatorsHistorySnapshot, Bot, BotConfig, BotResults, BotStatus, BuildStrategySignalDraft, BuildStrategySignalParams, Candle, ChartColor, ClosedPnlRecord, CompletedTest, Connector, ConnectorConfig, ConnectorCreator, ConnectorPluginDefinition, ConnectorRegistryEntry, CreateStrategyCore, CreateStrategyCoreParams, DerivativesContext, DerivativesContextRiskFlag, DerivativesInterval, DerivativesIntervalContext, DerivativesPressure, DerivativesRow, DerivativesSymbolContext, Direction, EOMPoint, Figure, Filters, GetClosedPnlParams, GetTickers, Indicator, IndicatorPluginComputeParams, IndicatorPluginDefinition, IndicatorPluginEntry, IndicatorPluginFigureRenderer, IndicatorPluginRenderer, IndicatorSnapshot, Indicators, IndicatorsHistorySnapshot, Interval, Item, Items, Kline, KlineChartData, KlineChartItem, KlineRequest, MetricThreshold, Metrics, MinimalStat, MlCandleIndicatorsSnapshot, MonthlyEquityStats, OnChangeCompare, OnChangeFilters, Order, OrderLog, OrderLogData, OrderType, Position, PositionLog, PositionLogData, PositionPnlSnapshot, Provider, RuntimeAiAnalysisSnapshot, RuntimeSignalEvaluationRecord, RuntimeSignalEvaluationStatus, RuntimeTradeRecord, RuntimeTradeStatus, Signal, SignalAnalysis, SignalOrderStatus, SimpleOrderLogData, Sl, SpreadRow, Strategy, StrategyAPI, StrategyAPIEntryParams, StrategyAPIExitParams, StrategyAPIMarketDataParams, StrategyAPIProtectParams, StrategyAdditionalIndicatorsMap, StrategyAiAdapter, StrategyAiMode, StrategyClosePlan, StrategyConfig, StrategyConfigGrid, StrategyCoreRunner, StrategyCreator, StrategyCreatorParams, StrategyDecision, StrategyDirectionalTpSlParams, StrategyDirectionalTpSlResult, StrategyEntryBaseParams, StrategyEntryModelFigures, StrategyEntryOrderPlan, StrategyEntryRuntimeBaseParams, StrategyEntryRuntimeBuilderParams, StrategyEntryRuntimeOptions, StrategyEntrySignalContext, StrategyEntrySignalDecisionBuilderParams, StrategyEntryTakeProfitsParams, StrategyFigureLine, StrategyFigurePoint, StrategyFigurePoints, StrategyFigureZone, StrategyHookAfterAiContext, StrategyHookAfterDecisionContext, StrategyHookAfterPlaceOrderContext, StrategyHookAiContext, StrategyHookAiSkippedReason, StrategyHookBarContext, StrategyHookBeforeCloseContext, StrategyHookBeforeEntryGateContext, StrategyHookBeforePlaceOrderContext, StrategyHookCtx, StrategyHookEnrichContext, StrategyHookEntryContext, StrategyHookErrorContext, StrategyHookErrorPayload, StrategyHookGateResult, StrategyHookInitContext, StrategyHookMarketContext, StrategyHookMlContext, StrategyHookMlSkippedReason, StrategyHookOrderContext, StrategyHookPolicyContext, StrategyHookSkipContext, StrategyHookStage, StrategyIndicatorsMap, StrategyIndicatorsState, StrategyLastTradeController, StrategyLastTradeControllerParams, StrategyManifest, StrategyMarketSnapshot, StrategyMlAdapter, StrategyPluginDefinition, StrategyProtectPlan, StrategyRegistryEntry, StrategyResultConfig, StrategyResultEntry, StrategyResults, StrategyRuntimeAiOptions, StrategyRuntimeMlOptions, StrategySignalMetaParams, StrategySignalPriceParams, Test, TestCompare, TestCompareList, TestConnector, TestConnectorContext, TestConnectorCreator, TestResult, TestStat, TestSuite, TestThresholds, TestThresholdsKey, TestWorkerResult, TestingBox, TestingBoxResult, TestingOptions, ThresholdLevel, Ticker, Tp, Trend, TrendLine, TrendLineMode, TrendLineOptions, UIFilters };
|