@tradejs/types 1.0.4 → 1.0.6

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @tradejs/types
2
2
 
3
- Shared TradeJS contracts and TypeScript types.
3
+ Shared contracts and TypeScript types for the TradeJS open-source framework.
4
4
 
5
5
  - Homepage: https://tradejs.dev
6
6
  - Documentation: https://docs.tradejs.dev
package/dist/index.d.mts CHANGED
@@ -74,6 +74,7 @@ interface KlineRequest {
74
74
  end: number;
75
75
  silent?: boolean;
76
76
  cacheOnly?: boolean;
77
+ warmOnly?: boolean;
77
78
  }
78
79
  type DerivativesInterval = '15m' | '1h';
79
80
  type DerivativesRow = {
@@ -134,8 +135,19 @@ interface ConnectorPluginDefinition {
134
135
  }
135
136
  type GetPosition = (symbol: string) => Promise<Position | null>;
136
137
  type GetPositions = () => Promise<Position[]>;
137
- type PlaceOrder = (order: Order, tp?: Tp[], slPrice?: Sl) => Promise<boolean>;
138
+ type PlaceOrder = (order: Order) => Promise<boolean>;
138
139
  type ClosePosition = (order: Omit<Order, 'qty'>) => Promise<boolean>;
140
+ type SetTakeProfits = (params: {
141
+ symbol: string;
142
+ direction: Direction;
143
+ qty?: number;
144
+ takeProfits: Tp[];
145
+ }) => Promise<boolean>;
146
+ type SetStopLoss = (params: {
147
+ symbol: string;
148
+ direction: Direction;
149
+ stopLossPrice: Sl;
150
+ }) => Promise<boolean>;
139
151
  type Kline = (options: KlineRequest) => Promise<KlineChartData>;
140
152
  type GetTickers = () => Promise<Ticker[]>;
141
153
  interface Connector {
@@ -145,6 +157,8 @@ interface Connector {
145
157
  getPosition: GetPosition;
146
158
  getPositions: GetPositions;
147
159
  placeOrder: PlaceOrder;
160
+ setTakeProfits: SetTakeProfits;
161
+ setStopLoss: SetStopLoss;
148
162
  closePosition: ClosePosition;
149
163
  getTickers: GetTickers;
150
164
  }
@@ -335,7 +349,9 @@ interface Test extends BacktestRunConfig {
335
349
  symbol: string;
336
350
  options: TestingOptions;
337
351
  ml?: boolean;
352
+ ai?: boolean;
338
353
  chunkId?: string;
354
+ timeoutMs?: number;
339
355
  }
340
356
  type TestSuite = Test[];
341
357
  interface TestStat extends Metrics {
@@ -354,6 +370,8 @@ interface MinimalStat {
354
370
  interface TestingBoxResult {
355
371
  orderLogId: string;
356
372
  stat: MinimalStat;
373
+ inlineOrderLog?: OrderLogData;
374
+ inlinePositionLog?: PositionLogData;
357
375
  }
358
376
  type TestingBox = (test: Test) => Promise<TestingBoxResult | null>;
359
377
  interface TestWorkerResult extends TestingBoxResult {
@@ -400,6 +418,7 @@ interface TestConnector extends Connector {
400
418
  interface TestConnectorContext {
401
419
  userName?: string;
402
420
  mlEnabled?: boolean;
421
+ aiEnabled?: boolean;
403
422
  }
404
423
  type TestConnectorCreator = (connector: Connector, context?: TestConnectorContext) => TestConnector;
405
424
  type ChartColor = string;
@@ -446,197 +465,6 @@ interface UIFilters extends Filters {
446
465
  }
447
466
  type OnChangeFilters = (filters: Partial<UIFilters>) => void;
448
467
 
449
- interface AIChatMessage {
450
- from: 'user' | 'ai';
451
- text: string;
452
- command?: string;
453
- }
454
- type AIChatHistory = AIChatMessage[];
455
-
456
- interface AiPayload {
457
- signal: {
458
- symbol: Signal['symbol'];
459
- signalId: Signal['signalId'];
460
- interval: Signal['interval'];
461
- direction: Signal['direction'];
462
- timestamp: Signal['timestamp'];
463
- strategy: Signal['strategy'];
464
- prices: {
465
- currentPrice: Signal['prices']['currentPrice'];
466
- takeProfitPrice: Signal['prices']['takeProfitPrice'];
467
- stopLossPrice: Signal['prices']['stopLossPrice'];
468
- };
469
- };
470
- figures: Record<string, unknown>;
471
- indicators: unknown;
472
- additionalIndicators: unknown;
473
- }
474
- interface StrategyAiAdapter {
475
- buildPayload?: (params: {
476
- signal: Signal;
477
- basePayload: AiPayload;
478
- }) => AiPayload;
479
- buildSystemPromptAddon?: (params: {
480
- signal: Signal;
481
- }) => string;
482
- buildHumanPromptAddon?: (params: {
483
- signal: Signal;
484
- payload: AiPayload;
485
- }) => string;
486
- mapEntryRuntimeFromConfig?: (config: StrategyConfig) => StrategyRuntimeAiOptions | undefined;
487
- }
488
- interface StrategyMlAdapter {
489
- normalizeSignal?: (signal: Signal) => Signal;
490
- normalizeStrategyConfig?: (strategyConfig?: Record<string, any>) => Record<string, any> | undefined;
491
- mapEntryRuntimeFromConfig?: (config: StrategyConfig) => StrategyRuntimeMlOptions | undefined;
492
- }
493
- interface StrategyHookGateResult {
494
- allow?: boolean;
495
- reason?: string;
496
- }
497
- type EntryDecision = Extract<StrategyDecision, {
498
- kind: 'entry';
499
- }>;
500
- type ExitDecision = Extract<StrategyDecision, {
501
- kind: 'exit';
502
- }>;
503
- interface StrategyHookCtx {
504
- connector: Connector;
505
- strategyName: string;
506
- userName: string;
507
- symbol: string;
508
- strategyConfig: StrategyConfig;
509
- env: string;
510
- isConfigFromBacktest: boolean;
511
- }
512
- interface StrategyHookMarketContext {
513
- candle?: KlineChartItem;
514
- btcCandle?: KlineChartItem;
515
- data?: KlineChartItem[];
516
- btcData?: KlineChartItem[];
517
- }
518
- interface StrategyHookEntryContext {
519
- context: StrategyEntrySignalContext;
520
- orderPlan: StrategyEntryOrderPlan;
521
- signal?: Signal;
522
- runtime: {
523
- raw?: StrategyEntryRuntimeOptions;
524
- resolved: StrategyEntryRuntimeOptions;
525
- };
526
- }
527
- type StrategyHookMlSkippedReason = 'BACKTEST' | 'DISABLED' | 'NO_RUNTIME' | 'NO_STRATEGY_CONFIG' | 'NO_THRESHOLD' | 'NO_RESULT';
528
- interface StrategyHookMlContext {
529
- config?: StrategyRuntimeMlOptions;
530
- attempted: boolean;
531
- applied: boolean;
532
- result?: Signal['ml'];
533
- skippedReason?: StrategyHookMlSkippedReason;
534
- }
535
- type StrategyHookAiSkippedReason = 'BACKTEST' | 'DISABLED' | 'NO_RUNTIME' | 'NO_QUALITY';
536
- interface StrategyHookAiContext {
537
- config?: StrategyRuntimeAiOptions;
538
- attempted: boolean;
539
- applied: boolean;
540
- quality?: number;
541
- skippedReason?: StrategyHookAiSkippedReason;
542
- }
543
- type StrategyHookStage = 'onInit' | 'afterCoreDecision' | 'onSkip' | 'beforeClosePosition' | 'afterEnrichMl' | 'afterEnrichAi' | 'beforeEntryGate' | 'beforePlaceOrder' | 'afterPlaceOrder' | 'runtime.beforePlaceOrder' | 'enrichSignalWithMl' | 'enrichSignalWithAi' | 'closePosition' | 'placeOrder';
544
- interface StrategyHookErrorPayload {
545
- stage: StrategyHookStage;
546
- cause: unknown;
547
- }
548
- interface StrategyHookErrorContext {
549
- ctx: StrategyHookCtx;
550
- market?: StrategyHookMarketContext;
551
- decision?: StrategyDecision;
552
- entry?: StrategyHookEntryContext;
553
- error: StrategyHookErrorPayload;
554
- }
555
- interface StrategyHookInitContext {
556
- ctx: StrategyHookCtx;
557
- market: Required<Pick<StrategyHookMarketContext, 'data' | 'btcData'>>;
558
- }
559
- interface StrategyHookAfterDecisionContext {
560
- ctx: StrategyHookCtx;
561
- market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
562
- decision: StrategyDecision;
563
- }
564
- interface StrategyHookSkipContext extends StrategyHookAfterDecisionContext {
565
- decision: Extract<StrategyDecision, {
566
- kind: 'skip';
567
- }>;
568
- }
569
- interface StrategyHookBeforeCloseContext extends StrategyHookAfterDecisionContext {
570
- decision: ExitDecision;
571
- }
572
- interface StrategyHookEnrichContext {
573
- ctx: StrategyHookCtx;
574
- market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
575
- decision: EntryDecision;
576
- entry: StrategyHookEntryContext;
577
- ml: StrategyHookMlContext;
578
- }
579
- interface StrategyHookAfterAiContext extends StrategyHookEnrichContext {
580
- ai: StrategyHookAiContext;
581
- }
582
- interface StrategyHookPolicyContext {
583
- aiQuality?: number;
584
- makeOrdersEnabled: boolean;
585
- minAiQuality: number;
586
- }
587
- interface StrategyHookBeforeEntryGateContext {
588
- ctx: StrategyHookCtx;
589
- market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
590
- decision: EntryDecision;
591
- entry: StrategyHookEntryContext;
592
- policy: StrategyHookPolicyContext;
593
- ml?: StrategyHookMlContext;
594
- ai?: StrategyHookAiContext;
595
- }
596
- interface StrategyHookBeforePlaceOrderContext {
597
- ctx: StrategyHookCtx;
598
- market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
599
- decision: EntryDecision;
600
- entry: StrategyHookEntryContext;
601
- policy: StrategyHookPolicyContext;
602
- ml?: StrategyHookMlContext;
603
- ai?: StrategyHookAiContext;
604
- }
605
- interface StrategyHookOrderContext {
606
- result: Signal | string;
607
- }
608
- interface StrategyHookAfterPlaceOrderContext {
609
- ctx: StrategyHookCtx;
610
- market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
611
- decision: EntryDecision;
612
- entry: StrategyHookEntryContext;
613
- policy: StrategyHookPolicyContext;
614
- ml?: StrategyHookMlContext;
615
- ai?: StrategyHookAiContext;
616
- order: StrategyHookOrderContext;
617
- }
618
- interface StrategyManifest {
619
- name: string;
620
- entryRuntimeDefaults?: {
621
- ai?: StrategyRuntimeAiOptions;
622
- ml?: Pick<StrategyRuntimeMlOptions, 'enabled'>;
623
- };
624
- hooks?: {
625
- onInit?: (params: StrategyHookInitContext) => Promise<void> | void;
626
- afterCoreDecision?: (params: StrategyHookAfterDecisionContext) => Promise<void> | void;
627
- onSkip?: (params: StrategyHookSkipContext) => Promise<void> | void;
628
- beforeClosePosition?: (params: StrategyHookBeforeCloseContext) => Promise<StrategyHookGateResult | void> | StrategyHookGateResult | void;
629
- afterEnrichMl?: (params: StrategyHookEnrichContext) => Promise<void> | void;
630
- afterEnrichAi?: (params: StrategyHookAfterAiContext) => Promise<void> | void;
631
- beforeEntryGate?: (params: StrategyHookBeforeEntryGateContext) => Promise<StrategyHookGateResult | void> | StrategyHookGateResult | void;
632
- beforePlaceOrder?: (params: StrategyHookBeforePlaceOrderContext) => Promise<void> | void;
633
- afterPlaceOrder?: (params: StrategyHookAfterPlaceOrderContext) => Promise<void> | void;
634
- onRuntimeError?: (params: StrategyHookErrorContext) => Promise<void> | void;
635
- };
636
- aiAdapter?: StrategyAiAdapter;
637
- mlAdapter?: StrategyMlAdapter;
638
- }
639
-
640
468
  interface StrategySignalMetaParams {
641
469
  symbol: string;
642
470
  interval: Interval;
@@ -701,6 +529,21 @@ interface StrategyAPIEntryParams {
701
529
  orderPlan: StrategyEntryOrderPlan;
702
530
  runtime?: StrategyEntryRuntimeOptions;
703
531
  }
532
+ interface StrategyAPIExitParams {
533
+ code?: string;
534
+ direction: Direction;
535
+ price?: number;
536
+ timestamp?: number;
537
+ }
538
+ interface StrategyProtectPlan {
539
+ direction: Direction;
540
+ stopLossPrice?: number | null;
541
+ takeProfits?: Tp[];
542
+ }
543
+ interface StrategyAPIProtectParams {
544
+ code?: string;
545
+ protectPlan: StrategyProtectPlan;
546
+ }
704
547
  interface StrategyAPIMarketDataParams {
705
548
  preloadStart?: number;
706
549
  backtestPriceMode?: BacktestPriceMode;
@@ -811,6 +654,12 @@ interface StrategyAPI {
811
654
  entry: (params: StrategyAPIEntryParams) => Promise<Extract<StrategyDecision, {
812
655
  kind: 'entry';
813
656
  }>>;
657
+ exit: (params: StrategyAPIExitParams) => Promise<Extract<StrategyDecision, {
658
+ kind: 'exit';
659
+ }>>;
660
+ protect: (params: StrategyAPIProtectParams) => Extract<StrategyDecision, {
661
+ kind: 'protect';
662
+ }>;
814
663
  getMarketData: (params?: StrategyAPIMarketDataParams) => Promise<StrategyMarketSnapshot>;
815
664
  nextIndicators: (candle: KlineChartData[number], btcCandle: KlineChartData[number]) => unknown;
816
665
  getCurrentPosition: () => ReturnType<Connector['getPosition']>;
@@ -867,6 +716,10 @@ type StrategyDecision = {
867
716
  kind: 'exit';
868
717
  code: string;
869
718
  closePlan: StrategyClosePlan;
719
+ } | {
720
+ kind: 'protect';
721
+ code: string;
722
+ protectPlan: StrategyProtectPlan;
870
723
  };
871
724
  interface CreateStrategyCoreParams<TConfig extends StrategyConfig, TIndicatorsState extends StrategyIndicatorsState = StrategyIndicatorsState> {
872
725
  userName: string;
@@ -876,7 +729,7 @@ interface CreateStrategyCoreParams<TConfig extends StrategyConfig, TIndicatorsSt
876
729
  connector: Connector;
877
730
  data: KlineChartData;
878
731
  btcData: KlineChartData;
879
- loadPineScript: (fileNameOrPath: string, fallback?: string) => string;
732
+ loadPineScriptFile: (fileNameOrPath: string, fallback?: string) => string;
880
733
  strategyApi: StrategyAPI;
881
734
  indicatorsState: TIndicatorsState;
882
735
  }
@@ -922,4 +775,217 @@ interface IndicatorPluginDefinition {
922
775
  indicatorEntries: IndicatorPluginEntry[];
923
776
  }
924
777
 
925
- export type { AIChatHistory, AIChatMessage, AiPayload, 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, StrategyAPIMarketDataParams, 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, 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 };
778
+ interface AiPayload {
779
+ signal: {
780
+ symbol: Signal['symbol'];
781
+ signalId: Signal['signalId'];
782
+ interval: Signal['interval'];
783
+ direction: Signal['direction'];
784
+ timestamp: Signal['timestamp'];
785
+ strategy: Signal['strategy'];
786
+ prices: {
787
+ currentPrice: Signal['prices']['currentPrice'];
788
+ takeProfitPrice: Signal['prices']['takeProfitPrice'];
789
+ stopLossPrice: Signal['prices']['stopLossPrice'];
790
+ };
791
+ };
792
+ figures: Record<string, unknown>;
793
+ indicators: unknown;
794
+ additionalIndicators: unknown;
795
+ }
796
+ interface StrategyAiAdapter {
797
+ buildPayload?: (params: {
798
+ signal: Signal;
799
+ basePayload: AiPayload;
800
+ }) => AiPayload;
801
+ postProcessAnalysis?: (params: {
802
+ signal: Signal;
803
+ payload: AiPayload;
804
+ analysis: Partial<SignalAnalysis>;
805
+ }) => Partial<SignalAnalysis>;
806
+ buildSystemPromptAddon?: (params: {
807
+ signal: Signal;
808
+ }) => string;
809
+ buildHumanPromptAddon?: (params: {
810
+ signal: Signal;
811
+ payload: AiPayload;
812
+ }) => string;
813
+ mapEntryRuntimeFromConfig?: (config: StrategyConfig) => StrategyRuntimeAiOptions | undefined;
814
+ }
815
+ interface StrategyMlAdapter {
816
+ normalizeSignal?: (signal: Signal) => Signal;
817
+ normalizeStrategyConfig?: (strategyConfig?: Record<string, any>) => Record<string, any> | undefined;
818
+ mapEntryRuntimeFromConfig?: (config: StrategyConfig) => StrategyRuntimeMlOptions | undefined;
819
+ }
820
+ interface StrategyHookGateResult {
821
+ allow?: boolean;
822
+ reason?: string;
823
+ }
824
+ type EntryDecision = Extract<StrategyDecision, {
825
+ kind: 'entry';
826
+ }>;
827
+ type ExitDecision = Extract<StrategyDecision, {
828
+ kind: 'exit';
829
+ }>;
830
+ interface StrategyHookCtx {
831
+ connector: Connector;
832
+ strategyName: string;
833
+ userName: string;
834
+ symbol: string;
835
+ strategyConfig: StrategyConfig;
836
+ env: string;
837
+ isConfigFromBacktest: boolean;
838
+ }
839
+ interface StrategyHookMarketContext {
840
+ candle?: KlineChartItem;
841
+ btcCandle?: KlineChartItem;
842
+ data?: KlineChartItem[];
843
+ btcData?: KlineChartItem[];
844
+ }
845
+ interface StrategyHookEntryContext {
846
+ context: StrategyEntrySignalContext;
847
+ orderPlan: StrategyEntryOrderPlan;
848
+ signal?: Signal;
849
+ runtime: {
850
+ raw?: StrategyEntryRuntimeOptions;
851
+ resolved: StrategyEntryRuntimeOptions;
852
+ };
853
+ }
854
+ type StrategyHookMlSkippedReason = 'BACKTEST' | 'DISABLED' | 'NO_RUNTIME' | 'NO_STRATEGY_CONFIG' | 'NO_THRESHOLD' | 'NO_RESULT';
855
+ interface StrategyHookMlContext {
856
+ config?: StrategyRuntimeMlOptions;
857
+ attempted: boolean;
858
+ applied: boolean;
859
+ result?: Signal['ml'];
860
+ skippedReason?: StrategyHookMlSkippedReason;
861
+ }
862
+ type StrategyHookAiSkippedReason = 'BACKTEST' | 'DISABLED' | 'NO_RUNTIME' | 'NO_QUALITY';
863
+ interface StrategyHookAiContext {
864
+ config?: StrategyRuntimeAiOptions;
865
+ attempted: boolean;
866
+ applied: boolean;
867
+ quality?: number;
868
+ skippedReason?: StrategyHookAiSkippedReason;
869
+ }
870
+ type StrategyHookStage = 'onInit' | 'afterCoreDecision' | 'onSkip' | 'beforeClosePosition' | 'afterEnrichMl' | 'afterEnrichAi' | 'beforeEntryGate' | 'beforePlaceOrder' | 'afterPlaceOrder' | 'runtime.beforePlaceOrder' | 'enrichSignalWithMl' | 'enrichSignalWithAi' | 'setTakeProfits' | 'setStopLoss' | 'protectPosition' | 'closePosition' | 'placeOrder';
871
+ interface StrategyHookErrorPayload {
872
+ stage: StrategyHookStage;
873
+ cause: unknown;
874
+ }
875
+ interface StrategyHookErrorContext {
876
+ ctx: StrategyHookCtx;
877
+ market?: StrategyHookMarketContext;
878
+ decision?: StrategyDecision;
879
+ entry?: StrategyHookEntryContext;
880
+ error: StrategyHookErrorPayload;
881
+ }
882
+ interface StrategyHookInitContext {
883
+ ctx: StrategyHookCtx;
884
+ market: Required<Pick<StrategyHookMarketContext, 'data' | 'btcData'>>;
885
+ }
886
+ interface StrategyHookAfterDecisionContext {
887
+ ctx: StrategyHookCtx;
888
+ market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
889
+ decision: StrategyDecision;
890
+ }
891
+ interface StrategyHookSkipContext extends StrategyHookAfterDecisionContext {
892
+ decision: Extract<StrategyDecision, {
893
+ kind: 'skip';
894
+ }>;
895
+ }
896
+ interface StrategyHookBeforeCloseContext extends StrategyHookAfterDecisionContext {
897
+ decision: ExitDecision;
898
+ }
899
+ interface StrategyHookEnrichContext {
900
+ ctx: StrategyHookCtx;
901
+ market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
902
+ decision: EntryDecision;
903
+ entry: StrategyHookEntryContext;
904
+ ml: StrategyHookMlContext;
905
+ }
906
+ interface StrategyHookAfterAiContext extends StrategyHookEnrichContext {
907
+ ai: StrategyHookAiContext;
908
+ }
909
+ interface StrategyHookPolicyContext {
910
+ aiQuality?: number;
911
+ makeOrdersEnabled: boolean;
912
+ minAiQuality: number;
913
+ }
914
+ interface StrategyHookBeforeEntryGateContext {
915
+ ctx: StrategyHookCtx;
916
+ market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
917
+ decision: EntryDecision;
918
+ entry: StrategyHookEntryContext;
919
+ policy: StrategyHookPolicyContext;
920
+ ml?: StrategyHookMlContext;
921
+ ai?: StrategyHookAiContext;
922
+ }
923
+ interface StrategyHookBeforePlaceOrderContext {
924
+ ctx: StrategyHookCtx;
925
+ market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
926
+ decision: EntryDecision;
927
+ entry: StrategyHookEntryContext;
928
+ policy: StrategyHookPolicyContext;
929
+ ml?: StrategyHookMlContext;
930
+ ai?: StrategyHookAiContext;
931
+ }
932
+ interface StrategyHookOrderContext {
933
+ result: Signal | string;
934
+ }
935
+ interface StrategyHookAfterPlaceOrderContext {
936
+ ctx: StrategyHookCtx;
937
+ market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
938
+ decision: EntryDecision;
939
+ entry: StrategyHookEntryContext;
940
+ policy: StrategyHookPolicyContext;
941
+ ml?: StrategyHookMlContext;
942
+ ai?: StrategyHookAiContext;
943
+ order: StrategyHookOrderContext;
944
+ }
945
+ interface StrategyManifest {
946
+ name: string;
947
+ entryRuntimeDefaults?: {
948
+ ai?: StrategyRuntimeAiOptions;
949
+ ml?: Pick<StrategyRuntimeMlOptions, 'enabled'>;
950
+ };
951
+ hooks?: {
952
+ onInit?: (params: StrategyHookInitContext) => Promise<void> | void;
953
+ afterCoreDecision?: (params: StrategyHookAfterDecisionContext) => Promise<void> | void;
954
+ onSkip?: (params: StrategyHookSkipContext) => Promise<void> | void;
955
+ beforeClosePosition?: (params: StrategyHookBeforeCloseContext) => Promise<StrategyHookGateResult | void> | StrategyHookGateResult | void;
956
+ afterEnrichMl?: (params: StrategyHookEnrichContext) => Promise<void> | void;
957
+ afterEnrichAi?: (params: StrategyHookAfterAiContext) => Promise<void> | void;
958
+ beforeEntryGate?: (params: StrategyHookBeforeEntryGateContext) => Promise<StrategyHookGateResult | void> | StrategyHookGateResult | void;
959
+ beforePlaceOrder?: (params: StrategyHookBeforePlaceOrderContext) => Promise<void> | void;
960
+ afterPlaceOrder?: (params: StrategyHookAfterPlaceOrderContext) => Promise<void> | void;
961
+ onRuntimeError?: (params: StrategyHookErrorContext) => Promise<void> | void;
962
+ };
963
+ aiAdapter?: StrategyAiAdapter;
964
+ mlAdapter?: StrategyMlAdapter;
965
+ }
966
+
967
+ interface AIChatMessage {
968
+ from: 'user' | 'ai';
969
+ text: string;
970
+ command?: string;
971
+ }
972
+ type AIChatHistory = AIChatMessage[];
973
+ interface AiPromptPair {
974
+ systemPrompt: string;
975
+ humanPrompt: string;
976
+ }
977
+ interface AiDatasetRow {
978
+ signalId: string;
979
+ strategyName: string;
980
+ symbol: string;
981
+ direction: Direction;
982
+ timestamp: number;
983
+ profit: number;
984
+ payload: AiPayload;
985
+ testId?: string;
986
+ testSuiteId?: string;
987
+ testName?: string;
988
+ connectorName?: string;
989
+ }
990
+
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 };
package/dist/index.d.ts CHANGED
@@ -74,6 +74,7 @@ interface KlineRequest {
74
74
  end: number;
75
75
  silent?: boolean;
76
76
  cacheOnly?: boolean;
77
+ warmOnly?: boolean;
77
78
  }
78
79
  type DerivativesInterval = '15m' | '1h';
79
80
  type DerivativesRow = {
@@ -134,8 +135,19 @@ interface ConnectorPluginDefinition {
134
135
  }
135
136
  type GetPosition = (symbol: string) => Promise<Position | null>;
136
137
  type GetPositions = () => Promise<Position[]>;
137
- type PlaceOrder = (order: Order, tp?: Tp[], slPrice?: Sl) => Promise<boolean>;
138
+ type PlaceOrder = (order: Order) => Promise<boolean>;
138
139
  type ClosePosition = (order: Omit<Order, 'qty'>) => Promise<boolean>;
140
+ type SetTakeProfits = (params: {
141
+ symbol: string;
142
+ direction: Direction;
143
+ qty?: number;
144
+ takeProfits: Tp[];
145
+ }) => Promise<boolean>;
146
+ type SetStopLoss = (params: {
147
+ symbol: string;
148
+ direction: Direction;
149
+ stopLossPrice: Sl;
150
+ }) => Promise<boolean>;
139
151
  type Kline = (options: KlineRequest) => Promise<KlineChartData>;
140
152
  type GetTickers = () => Promise<Ticker[]>;
141
153
  interface Connector {
@@ -145,6 +157,8 @@ interface Connector {
145
157
  getPosition: GetPosition;
146
158
  getPositions: GetPositions;
147
159
  placeOrder: PlaceOrder;
160
+ setTakeProfits: SetTakeProfits;
161
+ setStopLoss: SetStopLoss;
148
162
  closePosition: ClosePosition;
149
163
  getTickers: GetTickers;
150
164
  }
@@ -335,7 +349,9 @@ interface Test extends BacktestRunConfig {
335
349
  symbol: string;
336
350
  options: TestingOptions;
337
351
  ml?: boolean;
352
+ ai?: boolean;
338
353
  chunkId?: string;
354
+ timeoutMs?: number;
339
355
  }
340
356
  type TestSuite = Test[];
341
357
  interface TestStat extends Metrics {
@@ -354,6 +370,8 @@ interface MinimalStat {
354
370
  interface TestingBoxResult {
355
371
  orderLogId: string;
356
372
  stat: MinimalStat;
373
+ inlineOrderLog?: OrderLogData;
374
+ inlinePositionLog?: PositionLogData;
357
375
  }
358
376
  type TestingBox = (test: Test) => Promise<TestingBoxResult | null>;
359
377
  interface TestWorkerResult extends TestingBoxResult {
@@ -400,6 +418,7 @@ interface TestConnector extends Connector {
400
418
  interface TestConnectorContext {
401
419
  userName?: string;
402
420
  mlEnabled?: boolean;
421
+ aiEnabled?: boolean;
403
422
  }
404
423
  type TestConnectorCreator = (connector: Connector, context?: TestConnectorContext) => TestConnector;
405
424
  type ChartColor = string;
@@ -446,197 +465,6 @@ interface UIFilters extends Filters {
446
465
  }
447
466
  type OnChangeFilters = (filters: Partial<UIFilters>) => void;
448
467
 
449
- interface AIChatMessage {
450
- from: 'user' | 'ai';
451
- text: string;
452
- command?: string;
453
- }
454
- type AIChatHistory = AIChatMessage[];
455
-
456
- interface AiPayload {
457
- signal: {
458
- symbol: Signal['symbol'];
459
- signalId: Signal['signalId'];
460
- interval: Signal['interval'];
461
- direction: Signal['direction'];
462
- timestamp: Signal['timestamp'];
463
- strategy: Signal['strategy'];
464
- prices: {
465
- currentPrice: Signal['prices']['currentPrice'];
466
- takeProfitPrice: Signal['prices']['takeProfitPrice'];
467
- stopLossPrice: Signal['prices']['stopLossPrice'];
468
- };
469
- };
470
- figures: Record<string, unknown>;
471
- indicators: unknown;
472
- additionalIndicators: unknown;
473
- }
474
- interface StrategyAiAdapter {
475
- buildPayload?: (params: {
476
- signal: Signal;
477
- basePayload: AiPayload;
478
- }) => AiPayload;
479
- buildSystemPromptAddon?: (params: {
480
- signal: Signal;
481
- }) => string;
482
- buildHumanPromptAddon?: (params: {
483
- signal: Signal;
484
- payload: AiPayload;
485
- }) => string;
486
- mapEntryRuntimeFromConfig?: (config: StrategyConfig) => StrategyRuntimeAiOptions | undefined;
487
- }
488
- interface StrategyMlAdapter {
489
- normalizeSignal?: (signal: Signal) => Signal;
490
- normalizeStrategyConfig?: (strategyConfig?: Record<string, any>) => Record<string, any> | undefined;
491
- mapEntryRuntimeFromConfig?: (config: StrategyConfig) => StrategyRuntimeMlOptions | undefined;
492
- }
493
- interface StrategyHookGateResult {
494
- allow?: boolean;
495
- reason?: string;
496
- }
497
- type EntryDecision = Extract<StrategyDecision, {
498
- kind: 'entry';
499
- }>;
500
- type ExitDecision = Extract<StrategyDecision, {
501
- kind: 'exit';
502
- }>;
503
- interface StrategyHookCtx {
504
- connector: Connector;
505
- strategyName: string;
506
- userName: string;
507
- symbol: string;
508
- strategyConfig: StrategyConfig;
509
- env: string;
510
- isConfigFromBacktest: boolean;
511
- }
512
- interface StrategyHookMarketContext {
513
- candle?: KlineChartItem;
514
- btcCandle?: KlineChartItem;
515
- data?: KlineChartItem[];
516
- btcData?: KlineChartItem[];
517
- }
518
- interface StrategyHookEntryContext {
519
- context: StrategyEntrySignalContext;
520
- orderPlan: StrategyEntryOrderPlan;
521
- signal?: Signal;
522
- runtime: {
523
- raw?: StrategyEntryRuntimeOptions;
524
- resolved: StrategyEntryRuntimeOptions;
525
- };
526
- }
527
- type StrategyHookMlSkippedReason = 'BACKTEST' | 'DISABLED' | 'NO_RUNTIME' | 'NO_STRATEGY_CONFIG' | 'NO_THRESHOLD' | 'NO_RESULT';
528
- interface StrategyHookMlContext {
529
- config?: StrategyRuntimeMlOptions;
530
- attempted: boolean;
531
- applied: boolean;
532
- result?: Signal['ml'];
533
- skippedReason?: StrategyHookMlSkippedReason;
534
- }
535
- type StrategyHookAiSkippedReason = 'BACKTEST' | 'DISABLED' | 'NO_RUNTIME' | 'NO_QUALITY';
536
- interface StrategyHookAiContext {
537
- config?: StrategyRuntimeAiOptions;
538
- attempted: boolean;
539
- applied: boolean;
540
- quality?: number;
541
- skippedReason?: StrategyHookAiSkippedReason;
542
- }
543
- type StrategyHookStage = 'onInit' | 'afterCoreDecision' | 'onSkip' | 'beforeClosePosition' | 'afterEnrichMl' | 'afterEnrichAi' | 'beforeEntryGate' | 'beforePlaceOrder' | 'afterPlaceOrder' | 'runtime.beforePlaceOrder' | 'enrichSignalWithMl' | 'enrichSignalWithAi' | 'closePosition' | 'placeOrder';
544
- interface StrategyHookErrorPayload {
545
- stage: StrategyHookStage;
546
- cause: unknown;
547
- }
548
- interface StrategyHookErrorContext {
549
- ctx: StrategyHookCtx;
550
- market?: StrategyHookMarketContext;
551
- decision?: StrategyDecision;
552
- entry?: StrategyHookEntryContext;
553
- error: StrategyHookErrorPayload;
554
- }
555
- interface StrategyHookInitContext {
556
- ctx: StrategyHookCtx;
557
- market: Required<Pick<StrategyHookMarketContext, 'data' | 'btcData'>>;
558
- }
559
- interface StrategyHookAfterDecisionContext {
560
- ctx: StrategyHookCtx;
561
- market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
562
- decision: StrategyDecision;
563
- }
564
- interface StrategyHookSkipContext extends StrategyHookAfterDecisionContext {
565
- decision: Extract<StrategyDecision, {
566
- kind: 'skip';
567
- }>;
568
- }
569
- interface StrategyHookBeforeCloseContext extends StrategyHookAfterDecisionContext {
570
- decision: ExitDecision;
571
- }
572
- interface StrategyHookEnrichContext {
573
- ctx: StrategyHookCtx;
574
- market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
575
- decision: EntryDecision;
576
- entry: StrategyHookEntryContext;
577
- ml: StrategyHookMlContext;
578
- }
579
- interface StrategyHookAfterAiContext extends StrategyHookEnrichContext {
580
- ai: StrategyHookAiContext;
581
- }
582
- interface StrategyHookPolicyContext {
583
- aiQuality?: number;
584
- makeOrdersEnabled: boolean;
585
- minAiQuality: number;
586
- }
587
- interface StrategyHookBeforeEntryGateContext {
588
- ctx: StrategyHookCtx;
589
- market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
590
- decision: EntryDecision;
591
- entry: StrategyHookEntryContext;
592
- policy: StrategyHookPolicyContext;
593
- ml?: StrategyHookMlContext;
594
- ai?: StrategyHookAiContext;
595
- }
596
- interface StrategyHookBeforePlaceOrderContext {
597
- ctx: StrategyHookCtx;
598
- market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
599
- decision: EntryDecision;
600
- entry: StrategyHookEntryContext;
601
- policy: StrategyHookPolicyContext;
602
- ml?: StrategyHookMlContext;
603
- ai?: StrategyHookAiContext;
604
- }
605
- interface StrategyHookOrderContext {
606
- result: Signal | string;
607
- }
608
- interface StrategyHookAfterPlaceOrderContext {
609
- ctx: StrategyHookCtx;
610
- market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
611
- decision: EntryDecision;
612
- entry: StrategyHookEntryContext;
613
- policy: StrategyHookPolicyContext;
614
- ml?: StrategyHookMlContext;
615
- ai?: StrategyHookAiContext;
616
- order: StrategyHookOrderContext;
617
- }
618
- interface StrategyManifest {
619
- name: string;
620
- entryRuntimeDefaults?: {
621
- ai?: StrategyRuntimeAiOptions;
622
- ml?: Pick<StrategyRuntimeMlOptions, 'enabled'>;
623
- };
624
- hooks?: {
625
- onInit?: (params: StrategyHookInitContext) => Promise<void> | void;
626
- afterCoreDecision?: (params: StrategyHookAfterDecisionContext) => Promise<void> | void;
627
- onSkip?: (params: StrategyHookSkipContext) => Promise<void> | void;
628
- beforeClosePosition?: (params: StrategyHookBeforeCloseContext) => Promise<StrategyHookGateResult | void> | StrategyHookGateResult | void;
629
- afterEnrichMl?: (params: StrategyHookEnrichContext) => Promise<void> | void;
630
- afterEnrichAi?: (params: StrategyHookAfterAiContext) => Promise<void> | void;
631
- beforeEntryGate?: (params: StrategyHookBeforeEntryGateContext) => Promise<StrategyHookGateResult | void> | StrategyHookGateResult | void;
632
- beforePlaceOrder?: (params: StrategyHookBeforePlaceOrderContext) => Promise<void> | void;
633
- afterPlaceOrder?: (params: StrategyHookAfterPlaceOrderContext) => Promise<void> | void;
634
- onRuntimeError?: (params: StrategyHookErrorContext) => Promise<void> | void;
635
- };
636
- aiAdapter?: StrategyAiAdapter;
637
- mlAdapter?: StrategyMlAdapter;
638
- }
639
-
640
468
  interface StrategySignalMetaParams {
641
469
  symbol: string;
642
470
  interval: Interval;
@@ -701,6 +529,21 @@ interface StrategyAPIEntryParams {
701
529
  orderPlan: StrategyEntryOrderPlan;
702
530
  runtime?: StrategyEntryRuntimeOptions;
703
531
  }
532
+ interface StrategyAPIExitParams {
533
+ code?: string;
534
+ direction: Direction;
535
+ price?: number;
536
+ timestamp?: number;
537
+ }
538
+ interface StrategyProtectPlan {
539
+ direction: Direction;
540
+ stopLossPrice?: number | null;
541
+ takeProfits?: Tp[];
542
+ }
543
+ interface StrategyAPIProtectParams {
544
+ code?: string;
545
+ protectPlan: StrategyProtectPlan;
546
+ }
704
547
  interface StrategyAPIMarketDataParams {
705
548
  preloadStart?: number;
706
549
  backtestPriceMode?: BacktestPriceMode;
@@ -811,6 +654,12 @@ interface StrategyAPI {
811
654
  entry: (params: StrategyAPIEntryParams) => Promise<Extract<StrategyDecision, {
812
655
  kind: 'entry';
813
656
  }>>;
657
+ exit: (params: StrategyAPIExitParams) => Promise<Extract<StrategyDecision, {
658
+ kind: 'exit';
659
+ }>>;
660
+ protect: (params: StrategyAPIProtectParams) => Extract<StrategyDecision, {
661
+ kind: 'protect';
662
+ }>;
814
663
  getMarketData: (params?: StrategyAPIMarketDataParams) => Promise<StrategyMarketSnapshot>;
815
664
  nextIndicators: (candle: KlineChartData[number], btcCandle: KlineChartData[number]) => unknown;
816
665
  getCurrentPosition: () => ReturnType<Connector['getPosition']>;
@@ -867,6 +716,10 @@ type StrategyDecision = {
867
716
  kind: 'exit';
868
717
  code: string;
869
718
  closePlan: StrategyClosePlan;
719
+ } | {
720
+ kind: 'protect';
721
+ code: string;
722
+ protectPlan: StrategyProtectPlan;
870
723
  };
871
724
  interface CreateStrategyCoreParams<TConfig extends StrategyConfig, TIndicatorsState extends StrategyIndicatorsState = StrategyIndicatorsState> {
872
725
  userName: string;
@@ -876,7 +729,7 @@ interface CreateStrategyCoreParams<TConfig extends StrategyConfig, TIndicatorsSt
876
729
  connector: Connector;
877
730
  data: KlineChartData;
878
731
  btcData: KlineChartData;
879
- loadPineScript: (fileNameOrPath: string, fallback?: string) => string;
732
+ loadPineScriptFile: (fileNameOrPath: string, fallback?: string) => string;
880
733
  strategyApi: StrategyAPI;
881
734
  indicatorsState: TIndicatorsState;
882
735
  }
@@ -922,4 +775,217 @@ interface IndicatorPluginDefinition {
922
775
  indicatorEntries: IndicatorPluginEntry[];
923
776
  }
924
777
 
925
- export type { AIChatHistory, AIChatMessage, AiPayload, 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, StrategyAPIMarketDataParams, 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, 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 };
778
+ interface AiPayload {
779
+ signal: {
780
+ symbol: Signal['symbol'];
781
+ signalId: Signal['signalId'];
782
+ interval: Signal['interval'];
783
+ direction: Signal['direction'];
784
+ timestamp: Signal['timestamp'];
785
+ strategy: Signal['strategy'];
786
+ prices: {
787
+ currentPrice: Signal['prices']['currentPrice'];
788
+ takeProfitPrice: Signal['prices']['takeProfitPrice'];
789
+ stopLossPrice: Signal['prices']['stopLossPrice'];
790
+ };
791
+ };
792
+ figures: Record<string, unknown>;
793
+ indicators: unknown;
794
+ additionalIndicators: unknown;
795
+ }
796
+ interface StrategyAiAdapter {
797
+ buildPayload?: (params: {
798
+ signal: Signal;
799
+ basePayload: AiPayload;
800
+ }) => AiPayload;
801
+ postProcessAnalysis?: (params: {
802
+ signal: Signal;
803
+ payload: AiPayload;
804
+ analysis: Partial<SignalAnalysis>;
805
+ }) => Partial<SignalAnalysis>;
806
+ buildSystemPromptAddon?: (params: {
807
+ signal: Signal;
808
+ }) => string;
809
+ buildHumanPromptAddon?: (params: {
810
+ signal: Signal;
811
+ payload: AiPayload;
812
+ }) => string;
813
+ mapEntryRuntimeFromConfig?: (config: StrategyConfig) => StrategyRuntimeAiOptions | undefined;
814
+ }
815
+ interface StrategyMlAdapter {
816
+ normalizeSignal?: (signal: Signal) => Signal;
817
+ normalizeStrategyConfig?: (strategyConfig?: Record<string, any>) => Record<string, any> | undefined;
818
+ mapEntryRuntimeFromConfig?: (config: StrategyConfig) => StrategyRuntimeMlOptions | undefined;
819
+ }
820
+ interface StrategyHookGateResult {
821
+ allow?: boolean;
822
+ reason?: string;
823
+ }
824
+ type EntryDecision = Extract<StrategyDecision, {
825
+ kind: 'entry';
826
+ }>;
827
+ type ExitDecision = Extract<StrategyDecision, {
828
+ kind: 'exit';
829
+ }>;
830
+ interface StrategyHookCtx {
831
+ connector: Connector;
832
+ strategyName: string;
833
+ userName: string;
834
+ symbol: string;
835
+ strategyConfig: StrategyConfig;
836
+ env: string;
837
+ isConfigFromBacktest: boolean;
838
+ }
839
+ interface StrategyHookMarketContext {
840
+ candle?: KlineChartItem;
841
+ btcCandle?: KlineChartItem;
842
+ data?: KlineChartItem[];
843
+ btcData?: KlineChartItem[];
844
+ }
845
+ interface StrategyHookEntryContext {
846
+ context: StrategyEntrySignalContext;
847
+ orderPlan: StrategyEntryOrderPlan;
848
+ signal?: Signal;
849
+ runtime: {
850
+ raw?: StrategyEntryRuntimeOptions;
851
+ resolved: StrategyEntryRuntimeOptions;
852
+ };
853
+ }
854
+ type StrategyHookMlSkippedReason = 'BACKTEST' | 'DISABLED' | 'NO_RUNTIME' | 'NO_STRATEGY_CONFIG' | 'NO_THRESHOLD' | 'NO_RESULT';
855
+ interface StrategyHookMlContext {
856
+ config?: StrategyRuntimeMlOptions;
857
+ attempted: boolean;
858
+ applied: boolean;
859
+ result?: Signal['ml'];
860
+ skippedReason?: StrategyHookMlSkippedReason;
861
+ }
862
+ type StrategyHookAiSkippedReason = 'BACKTEST' | 'DISABLED' | 'NO_RUNTIME' | 'NO_QUALITY';
863
+ interface StrategyHookAiContext {
864
+ config?: StrategyRuntimeAiOptions;
865
+ attempted: boolean;
866
+ applied: boolean;
867
+ quality?: number;
868
+ skippedReason?: StrategyHookAiSkippedReason;
869
+ }
870
+ type StrategyHookStage = 'onInit' | 'afterCoreDecision' | 'onSkip' | 'beforeClosePosition' | 'afterEnrichMl' | 'afterEnrichAi' | 'beforeEntryGate' | 'beforePlaceOrder' | 'afterPlaceOrder' | 'runtime.beforePlaceOrder' | 'enrichSignalWithMl' | 'enrichSignalWithAi' | 'setTakeProfits' | 'setStopLoss' | 'protectPosition' | 'closePosition' | 'placeOrder';
871
+ interface StrategyHookErrorPayload {
872
+ stage: StrategyHookStage;
873
+ cause: unknown;
874
+ }
875
+ interface StrategyHookErrorContext {
876
+ ctx: StrategyHookCtx;
877
+ market?: StrategyHookMarketContext;
878
+ decision?: StrategyDecision;
879
+ entry?: StrategyHookEntryContext;
880
+ error: StrategyHookErrorPayload;
881
+ }
882
+ interface StrategyHookInitContext {
883
+ ctx: StrategyHookCtx;
884
+ market: Required<Pick<StrategyHookMarketContext, 'data' | 'btcData'>>;
885
+ }
886
+ interface StrategyHookAfterDecisionContext {
887
+ ctx: StrategyHookCtx;
888
+ market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
889
+ decision: StrategyDecision;
890
+ }
891
+ interface StrategyHookSkipContext extends StrategyHookAfterDecisionContext {
892
+ decision: Extract<StrategyDecision, {
893
+ kind: 'skip';
894
+ }>;
895
+ }
896
+ interface StrategyHookBeforeCloseContext extends StrategyHookAfterDecisionContext {
897
+ decision: ExitDecision;
898
+ }
899
+ interface StrategyHookEnrichContext {
900
+ ctx: StrategyHookCtx;
901
+ market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
902
+ decision: EntryDecision;
903
+ entry: StrategyHookEntryContext;
904
+ ml: StrategyHookMlContext;
905
+ }
906
+ interface StrategyHookAfterAiContext extends StrategyHookEnrichContext {
907
+ ai: StrategyHookAiContext;
908
+ }
909
+ interface StrategyHookPolicyContext {
910
+ aiQuality?: number;
911
+ makeOrdersEnabled: boolean;
912
+ minAiQuality: number;
913
+ }
914
+ interface StrategyHookBeforeEntryGateContext {
915
+ ctx: StrategyHookCtx;
916
+ market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
917
+ decision: EntryDecision;
918
+ entry: StrategyHookEntryContext;
919
+ policy: StrategyHookPolicyContext;
920
+ ml?: StrategyHookMlContext;
921
+ ai?: StrategyHookAiContext;
922
+ }
923
+ interface StrategyHookBeforePlaceOrderContext {
924
+ ctx: StrategyHookCtx;
925
+ market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
926
+ decision: EntryDecision;
927
+ entry: StrategyHookEntryContext;
928
+ policy: StrategyHookPolicyContext;
929
+ ml?: StrategyHookMlContext;
930
+ ai?: StrategyHookAiContext;
931
+ }
932
+ interface StrategyHookOrderContext {
933
+ result: Signal | string;
934
+ }
935
+ interface StrategyHookAfterPlaceOrderContext {
936
+ ctx: StrategyHookCtx;
937
+ market: Required<Pick<StrategyHookMarketContext, 'candle' | 'btcCandle'>>;
938
+ decision: EntryDecision;
939
+ entry: StrategyHookEntryContext;
940
+ policy: StrategyHookPolicyContext;
941
+ ml?: StrategyHookMlContext;
942
+ ai?: StrategyHookAiContext;
943
+ order: StrategyHookOrderContext;
944
+ }
945
+ interface StrategyManifest {
946
+ name: string;
947
+ entryRuntimeDefaults?: {
948
+ ai?: StrategyRuntimeAiOptions;
949
+ ml?: Pick<StrategyRuntimeMlOptions, 'enabled'>;
950
+ };
951
+ hooks?: {
952
+ onInit?: (params: StrategyHookInitContext) => Promise<void> | void;
953
+ afterCoreDecision?: (params: StrategyHookAfterDecisionContext) => Promise<void> | void;
954
+ onSkip?: (params: StrategyHookSkipContext) => Promise<void> | void;
955
+ beforeClosePosition?: (params: StrategyHookBeforeCloseContext) => Promise<StrategyHookGateResult | void> | StrategyHookGateResult | void;
956
+ afterEnrichMl?: (params: StrategyHookEnrichContext) => Promise<void> | void;
957
+ afterEnrichAi?: (params: StrategyHookAfterAiContext) => Promise<void> | void;
958
+ beforeEntryGate?: (params: StrategyHookBeforeEntryGateContext) => Promise<StrategyHookGateResult | void> | StrategyHookGateResult | void;
959
+ beforePlaceOrder?: (params: StrategyHookBeforePlaceOrderContext) => Promise<void> | void;
960
+ afterPlaceOrder?: (params: StrategyHookAfterPlaceOrderContext) => Promise<void> | void;
961
+ onRuntimeError?: (params: StrategyHookErrorContext) => Promise<void> | void;
962
+ };
963
+ aiAdapter?: StrategyAiAdapter;
964
+ mlAdapter?: StrategyMlAdapter;
965
+ }
966
+
967
+ interface AIChatMessage {
968
+ from: 'user' | 'ai';
969
+ text: string;
970
+ command?: string;
971
+ }
972
+ type AIChatHistory = AIChatMessage[];
973
+ interface AiPromptPair {
974
+ systemPrompt: string;
975
+ humanPrompt: string;
976
+ }
977
+ interface AiDatasetRow {
978
+ signalId: string;
979
+ strategyName: string;
980
+ symbol: string;
981
+ direction: Direction;
982
+ timestamp: number;
983
+ profit: number;
984
+ payload: AiPayload;
985
+ testId?: string;
986
+ testSuiteId?: string;
987
+ testName?: string;
988
+ connectorName?: string;
989
+ }
990
+
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 };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tradejs/types",
3
- "version": "1.0.4",
4
- "description": "Shared TypeScript contracts for the TradeJS ecosystem.",
3
+ "version": "1.0.6",
4
+ "description": "Shared TypeScript contracts for the TradeJS open-source framework.",
5
5
  "keywords": [
6
6
  "tradejs",
7
7
  "trading",
@@ -10,6 +10,14 @@
10
10
  "types",
11
11
  "contracts"
12
12
  ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/tradejs-dev/tradejs.git",
16
+ "directory": "packages/types"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/tradejs-dev/tradejs/issues"
20
+ },
13
21
  "main": "dist/index.js",
14
22
  "module": "dist/index.mjs",
15
23
  "types": "dist/index.d.ts",