reportify-sdk 0.3.31 → 0.3.33
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 +11 -5
- package/dist/index.d.ts +11 -5
- package/dist/index.js +37 -11
- package/dist/index.mjs +37 -11
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -736,10 +736,11 @@ interface BacktestParams {
|
|
|
736
736
|
minCommissionAmount?: number;
|
|
737
737
|
slippage?: number;
|
|
738
738
|
stopLoss?: number;
|
|
739
|
-
positionSize?: number;
|
|
740
|
-
maxPositions?: number;
|
|
739
|
+
positionSize?: number | null;
|
|
740
|
+
maxPositions?: number | null;
|
|
741
741
|
minVolume?: number;
|
|
742
742
|
autoClose?: boolean;
|
|
743
|
+
cheatOnOpen?: boolean;
|
|
743
744
|
signalFactors?: Record<string, string>;
|
|
744
745
|
}
|
|
745
746
|
interface KlineParams {
|
|
@@ -783,10 +784,11 @@ interface BacktestUploadParams {
|
|
|
783
784
|
sellCommission?: number;
|
|
784
785
|
minCommissionAmount?: number;
|
|
785
786
|
slippage?: number;
|
|
786
|
-
positionSize?: number;
|
|
787
|
-
maxPositions?: number;
|
|
787
|
+
positionSize?: number | null;
|
|
788
|
+
maxPositions?: number | null;
|
|
788
789
|
minVolume?: number;
|
|
789
790
|
autoClose?: boolean;
|
|
791
|
+
cheatOnOpen?: boolean;
|
|
790
792
|
signalFactors?: Record<string, string>;
|
|
791
793
|
}
|
|
792
794
|
interface BacktestResult {
|
|
@@ -847,6 +849,7 @@ interface BacktestResult {
|
|
|
847
849
|
*/
|
|
848
850
|
declare class QuantModule {
|
|
849
851
|
private client;
|
|
852
|
+
private static readonly BACKTEST_TIMEOUT_MS;
|
|
850
853
|
constructor(client: Reportify);
|
|
851
854
|
/**
|
|
852
855
|
* Get list of available factors (variables, functions, and indicators)
|
|
@@ -861,11 +864,13 @@ declare class QuantModule {
|
|
|
861
864
|
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT
|
|
862
865
|
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
863
866
|
*
|
|
867
|
+
* @param market - Stock market ("cn", "hk", "us"), default "cn"
|
|
864
868
|
* @returns Array of factor definitions with name, type, level, description, and optional fields
|
|
865
869
|
*
|
|
866
870
|
* @example
|
|
867
871
|
* ```typescript
|
|
868
872
|
* const factors = await client.quant.factors();
|
|
873
|
+
* const hkFactors = await client.quant.factors('hk');
|
|
869
874
|
* factors.forEach(f => {
|
|
870
875
|
* console.log(`${f.name} (${f.type}, level ${f.level})`);
|
|
871
876
|
* if (f.fields) {
|
|
@@ -874,7 +879,7 @@ declare class QuantModule {
|
|
|
874
879
|
* });
|
|
875
880
|
* ```
|
|
876
881
|
*/
|
|
877
|
-
factors(): Promise<FactorMeta[]>;
|
|
882
|
+
factors(market?: StockMarket): Promise<FactorMeta[]>;
|
|
878
883
|
/**
|
|
879
884
|
* Compute factor values for given symbols
|
|
880
885
|
*
|
|
@@ -1971,6 +1976,7 @@ declare class Reportify {
|
|
|
1971
1976
|
params?: Record<string, unknown>;
|
|
1972
1977
|
body?: Record<string, unknown>;
|
|
1973
1978
|
formData?: FormData;
|
|
1979
|
+
timeoutMs?: number;
|
|
1974
1980
|
}): Promise<T>;
|
|
1975
1981
|
/**
|
|
1976
1982
|
* Make a GET request
|
package/dist/index.d.ts
CHANGED
|
@@ -736,10 +736,11 @@ interface BacktestParams {
|
|
|
736
736
|
minCommissionAmount?: number;
|
|
737
737
|
slippage?: number;
|
|
738
738
|
stopLoss?: number;
|
|
739
|
-
positionSize?: number;
|
|
740
|
-
maxPositions?: number;
|
|
739
|
+
positionSize?: number | null;
|
|
740
|
+
maxPositions?: number | null;
|
|
741
741
|
minVolume?: number;
|
|
742
742
|
autoClose?: boolean;
|
|
743
|
+
cheatOnOpen?: boolean;
|
|
743
744
|
signalFactors?: Record<string, string>;
|
|
744
745
|
}
|
|
745
746
|
interface KlineParams {
|
|
@@ -783,10 +784,11 @@ interface BacktestUploadParams {
|
|
|
783
784
|
sellCommission?: number;
|
|
784
785
|
minCommissionAmount?: number;
|
|
785
786
|
slippage?: number;
|
|
786
|
-
positionSize?: number;
|
|
787
|
-
maxPositions?: number;
|
|
787
|
+
positionSize?: number | null;
|
|
788
|
+
maxPositions?: number | null;
|
|
788
789
|
minVolume?: number;
|
|
789
790
|
autoClose?: boolean;
|
|
791
|
+
cheatOnOpen?: boolean;
|
|
790
792
|
signalFactors?: Record<string, string>;
|
|
791
793
|
}
|
|
792
794
|
interface BacktestResult {
|
|
@@ -847,6 +849,7 @@ interface BacktestResult {
|
|
|
847
849
|
*/
|
|
848
850
|
declare class QuantModule {
|
|
849
851
|
private client;
|
|
852
|
+
private static readonly BACKTEST_TIMEOUT_MS;
|
|
850
853
|
constructor(client: Reportify);
|
|
851
854
|
/**
|
|
852
855
|
* Get list of available factors (variables, functions, and indicators)
|
|
@@ -861,11 +864,13 @@ declare class QuantModule {
|
|
|
861
864
|
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT
|
|
862
865
|
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
863
866
|
*
|
|
867
|
+
* @param market - Stock market ("cn", "hk", "us"), default "cn"
|
|
864
868
|
* @returns Array of factor definitions with name, type, level, description, and optional fields
|
|
865
869
|
*
|
|
866
870
|
* @example
|
|
867
871
|
* ```typescript
|
|
868
872
|
* const factors = await client.quant.factors();
|
|
873
|
+
* const hkFactors = await client.quant.factors('hk');
|
|
869
874
|
* factors.forEach(f => {
|
|
870
875
|
* console.log(`${f.name} (${f.type}, level ${f.level})`);
|
|
871
876
|
* if (f.fields) {
|
|
@@ -874,7 +879,7 @@ declare class QuantModule {
|
|
|
874
879
|
* });
|
|
875
880
|
* ```
|
|
876
881
|
*/
|
|
877
|
-
factors(): Promise<FactorMeta[]>;
|
|
882
|
+
factors(market?: StockMarket): Promise<FactorMeta[]>;
|
|
878
883
|
/**
|
|
879
884
|
* Compute factor values for given symbols
|
|
880
885
|
*
|
|
@@ -1971,6 +1976,7 @@ declare class Reportify {
|
|
|
1971
1976
|
params?: Record<string, unknown>;
|
|
1972
1977
|
body?: Record<string, unknown>;
|
|
1973
1978
|
formData?: FormData;
|
|
1979
|
+
timeoutMs?: number;
|
|
1974
1980
|
}): Promise<T>;
|
|
1975
1981
|
/**
|
|
1976
1982
|
* Make a GET request
|
package/dist/index.js
CHANGED
|
@@ -614,10 +614,11 @@ var DocsModule = class {
|
|
|
614
614
|
};
|
|
615
615
|
|
|
616
616
|
// src/quant.ts
|
|
617
|
-
var QuantModule = class {
|
|
617
|
+
var QuantModule = class _QuantModule {
|
|
618
618
|
constructor(client) {
|
|
619
619
|
this.client = client;
|
|
620
620
|
}
|
|
621
|
+
static BACKTEST_TIMEOUT_MS = 12e4;
|
|
621
622
|
// ===========================================================================
|
|
622
623
|
// Factors (includes technical indicators and fundamental factors)
|
|
623
624
|
// ===========================================================================
|
|
@@ -634,11 +635,13 @@ var QuantModule = class {
|
|
|
634
635
|
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT
|
|
635
636
|
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
636
637
|
*
|
|
638
|
+
* @param market - Stock market ("cn", "hk", "us"), default "cn"
|
|
637
639
|
* @returns Array of factor definitions with name, type, level, description, and optional fields
|
|
638
640
|
*
|
|
639
641
|
* @example
|
|
640
642
|
* ```typescript
|
|
641
643
|
* const factors = await client.quant.factors();
|
|
644
|
+
* const hkFactors = await client.quant.factors('hk');
|
|
642
645
|
* factors.forEach(f => {
|
|
643
646
|
* console.log(`${f.name} (${f.type}, level ${f.level})`);
|
|
644
647
|
* if (f.fields) {
|
|
@@ -647,8 +650,8 @@ var QuantModule = class {
|
|
|
647
650
|
* });
|
|
648
651
|
* ```
|
|
649
652
|
*/
|
|
650
|
-
async factors() {
|
|
651
|
-
return this.client.get("/v1/quant/factors");
|
|
653
|
+
async factors(market = "cn") {
|
|
654
|
+
return this.client.get("/v1/quant/factors", { market });
|
|
652
655
|
}
|
|
653
656
|
/**
|
|
654
657
|
* Compute factor values for given symbols
|
|
@@ -963,8 +966,6 @@ var QuantModule = class {
|
|
|
963
966
|
min_commission_amount: params.minCommissionAmount ?? 0,
|
|
964
967
|
slippage: params.slippage ?? 0,
|
|
965
968
|
stop_loss: params.stopLoss ?? 0,
|
|
966
|
-
position_size: params.positionSize ?? 0.2,
|
|
967
|
-
max_positions: params.maxPositions ?? 5,
|
|
968
969
|
min_volume: params.minVolume ?? 100,
|
|
969
970
|
auto_close: params.autoClose ?? true
|
|
970
971
|
};
|
|
@@ -983,10 +984,22 @@ var QuantModule = class {
|
|
|
983
984
|
if (params.exitFormula !== void 0) {
|
|
984
985
|
body.exit_formula = params.exitFormula;
|
|
985
986
|
}
|
|
987
|
+
if (params.positionSize !== void 0) {
|
|
988
|
+
body.position_size = params.positionSize;
|
|
989
|
+
}
|
|
990
|
+
if (params.maxPositions !== void 0) {
|
|
991
|
+
body.max_positions = params.maxPositions;
|
|
992
|
+
}
|
|
993
|
+
if (params.cheatOnOpen !== void 0) {
|
|
994
|
+
body.cheat_on_open = params.cheatOnOpen;
|
|
995
|
+
}
|
|
986
996
|
if (params.signalFactors !== void 0) {
|
|
987
997
|
body.signal_factors = params.signalFactors;
|
|
988
998
|
}
|
|
989
|
-
return this.client.
|
|
999
|
+
return this.client.request("POST", "/v1/quant/backtest", {
|
|
1000
|
+
body,
|
|
1001
|
+
timeoutMs: _QuantModule.BACKTEST_TIMEOUT_MS
|
|
1002
|
+
});
|
|
990
1003
|
}
|
|
991
1004
|
/**
|
|
992
1005
|
* Upload an Excel file to run backtest
|
|
@@ -1042,9 +1055,7 @@ var QuantModule = class {
|
|
|
1042
1055
|
formData.append("sell_commission", String(params.sellCommission ?? 0));
|
|
1043
1056
|
formData.append("min_commission_amount", String(params.minCommissionAmount ?? 0));
|
|
1044
1057
|
formData.append("slippage", String(params.slippage ?? 0));
|
|
1045
|
-
formData.append("
|
|
1046
|
-
formData.append("max_positions", String(params.maxPositions ?? 5));
|
|
1047
|
-
formData.append("min_volume", String(params.minVolume ?? 100));
|
|
1058
|
+
formData.append("min_volume", String(params.minVolume ?? 1));
|
|
1048
1059
|
formData.append("auto_close", String(params.autoClose ?? true));
|
|
1049
1060
|
if (params.startDate !== void 0) {
|
|
1050
1061
|
formData.append("start_date", params.startDate);
|
|
@@ -1061,10 +1072,22 @@ var QuantModule = class {
|
|
|
1061
1072
|
if (params.exitFormula !== void 0) {
|
|
1062
1073
|
formData.append("exit_formula", params.exitFormula);
|
|
1063
1074
|
}
|
|
1075
|
+
if (params.positionSize !== void 0 && params.positionSize !== null) {
|
|
1076
|
+
formData.append("position_size", String(params.positionSize));
|
|
1077
|
+
}
|
|
1078
|
+
if (params.maxPositions !== void 0 && params.maxPositions !== null) {
|
|
1079
|
+
formData.append("max_positions", String(params.maxPositions));
|
|
1080
|
+
}
|
|
1081
|
+
if (params.cheatOnOpen !== void 0) {
|
|
1082
|
+
formData.append("cheat_on_open", String(params.cheatOnOpen));
|
|
1083
|
+
}
|
|
1064
1084
|
if (params.signalFactors !== void 0) {
|
|
1065
1085
|
formData.append("signal_factors", JSON.stringify(params.signalFactors));
|
|
1066
1086
|
}
|
|
1067
|
-
return this.client.request("POST", "/v1/quant/backtest/upload", {
|
|
1087
|
+
return this.client.request("POST", "/v1/quant/backtest/upload", {
|
|
1088
|
+
formData,
|
|
1089
|
+
timeoutMs: _QuantModule.BACKTEST_TIMEOUT_MS
|
|
1090
|
+
});
|
|
1068
1091
|
}
|
|
1069
1092
|
};
|
|
1070
1093
|
|
|
@@ -2128,7 +2151,10 @@ var Reportify = class {
|
|
|
2128
2151
|
});
|
|
2129
2152
|
}
|
|
2130
2153
|
const controller = new AbortController();
|
|
2131
|
-
const timeoutId = setTimeout(
|
|
2154
|
+
const timeoutId = setTimeout(
|
|
2155
|
+
() => controller.abort(),
|
|
2156
|
+
options.timeoutMs ?? this.timeout
|
|
2157
|
+
);
|
|
2132
2158
|
const headers = {
|
|
2133
2159
|
Authorization: `Bearer ${this.apiKey}`,
|
|
2134
2160
|
"User-Agent": "reportify-sdk-js/0.3.10"
|
package/dist/index.mjs
CHANGED
|
@@ -570,10 +570,11 @@ var DocsModule = class {
|
|
|
570
570
|
};
|
|
571
571
|
|
|
572
572
|
// src/quant.ts
|
|
573
|
-
var QuantModule = class {
|
|
573
|
+
var QuantModule = class _QuantModule {
|
|
574
574
|
constructor(client) {
|
|
575
575
|
this.client = client;
|
|
576
576
|
}
|
|
577
|
+
static BACKTEST_TIMEOUT_MS = 12e4;
|
|
577
578
|
// ===========================================================================
|
|
578
579
|
// Factors (includes technical indicators and fundamental factors)
|
|
579
580
|
// ===========================================================================
|
|
@@ -590,11 +591,13 @@ var QuantModule = class {
|
|
|
590
591
|
* - Variables (no parentheses): CLOSE, OPEN, HIGH, LOW, VOLUME, AMOUNT
|
|
591
592
|
* - Functions (TongDaXin style: col first, n second): MA(CLOSE, 20), PE(), ROE(), RSI(14), etc.
|
|
592
593
|
*
|
|
594
|
+
* @param market - Stock market ("cn", "hk", "us"), default "cn"
|
|
593
595
|
* @returns Array of factor definitions with name, type, level, description, and optional fields
|
|
594
596
|
*
|
|
595
597
|
* @example
|
|
596
598
|
* ```typescript
|
|
597
599
|
* const factors = await client.quant.factors();
|
|
600
|
+
* const hkFactors = await client.quant.factors('hk');
|
|
598
601
|
* factors.forEach(f => {
|
|
599
602
|
* console.log(`${f.name} (${f.type}, level ${f.level})`);
|
|
600
603
|
* if (f.fields) {
|
|
@@ -603,8 +606,8 @@ var QuantModule = class {
|
|
|
603
606
|
* });
|
|
604
607
|
* ```
|
|
605
608
|
*/
|
|
606
|
-
async factors() {
|
|
607
|
-
return this.client.get("/v1/quant/factors");
|
|
609
|
+
async factors(market = "cn") {
|
|
610
|
+
return this.client.get("/v1/quant/factors", { market });
|
|
608
611
|
}
|
|
609
612
|
/**
|
|
610
613
|
* Compute factor values for given symbols
|
|
@@ -919,8 +922,6 @@ var QuantModule = class {
|
|
|
919
922
|
min_commission_amount: params.minCommissionAmount ?? 0,
|
|
920
923
|
slippage: params.slippage ?? 0,
|
|
921
924
|
stop_loss: params.stopLoss ?? 0,
|
|
922
|
-
position_size: params.positionSize ?? 0.2,
|
|
923
|
-
max_positions: params.maxPositions ?? 5,
|
|
924
925
|
min_volume: params.minVolume ?? 100,
|
|
925
926
|
auto_close: params.autoClose ?? true
|
|
926
927
|
};
|
|
@@ -939,10 +940,22 @@ var QuantModule = class {
|
|
|
939
940
|
if (params.exitFormula !== void 0) {
|
|
940
941
|
body.exit_formula = params.exitFormula;
|
|
941
942
|
}
|
|
943
|
+
if (params.positionSize !== void 0) {
|
|
944
|
+
body.position_size = params.positionSize;
|
|
945
|
+
}
|
|
946
|
+
if (params.maxPositions !== void 0) {
|
|
947
|
+
body.max_positions = params.maxPositions;
|
|
948
|
+
}
|
|
949
|
+
if (params.cheatOnOpen !== void 0) {
|
|
950
|
+
body.cheat_on_open = params.cheatOnOpen;
|
|
951
|
+
}
|
|
942
952
|
if (params.signalFactors !== void 0) {
|
|
943
953
|
body.signal_factors = params.signalFactors;
|
|
944
954
|
}
|
|
945
|
-
return this.client.
|
|
955
|
+
return this.client.request("POST", "/v1/quant/backtest", {
|
|
956
|
+
body,
|
|
957
|
+
timeoutMs: _QuantModule.BACKTEST_TIMEOUT_MS
|
|
958
|
+
});
|
|
946
959
|
}
|
|
947
960
|
/**
|
|
948
961
|
* Upload an Excel file to run backtest
|
|
@@ -998,9 +1011,7 @@ var QuantModule = class {
|
|
|
998
1011
|
formData.append("sell_commission", String(params.sellCommission ?? 0));
|
|
999
1012
|
formData.append("min_commission_amount", String(params.minCommissionAmount ?? 0));
|
|
1000
1013
|
formData.append("slippage", String(params.slippage ?? 0));
|
|
1001
|
-
formData.append("
|
|
1002
|
-
formData.append("max_positions", String(params.maxPositions ?? 5));
|
|
1003
|
-
formData.append("min_volume", String(params.minVolume ?? 100));
|
|
1014
|
+
formData.append("min_volume", String(params.minVolume ?? 1));
|
|
1004
1015
|
formData.append("auto_close", String(params.autoClose ?? true));
|
|
1005
1016
|
if (params.startDate !== void 0) {
|
|
1006
1017
|
formData.append("start_date", params.startDate);
|
|
@@ -1017,10 +1028,22 @@ var QuantModule = class {
|
|
|
1017
1028
|
if (params.exitFormula !== void 0) {
|
|
1018
1029
|
formData.append("exit_formula", params.exitFormula);
|
|
1019
1030
|
}
|
|
1031
|
+
if (params.positionSize !== void 0 && params.positionSize !== null) {
|
|
1032
|
+
formData.append("position_size", String(params.positionSize));
|
|
1033
|
+
}
|
|
1034
|
+
if (params.maxPositions !== void 0 && params.maxPositions !== null) {
|
|
1035
|
+
formData.append("max_positions", String(params.maxPositions));
|
|
1036
|
+
}
|
|
1037
|
+
if (params.cheatOnOpen !== void 0) {
|
|
1038
|
+
formData.append("cheat_on_open", String(params.cheatOnOpen));
|
|
1039
|
+
}
|
|
1020
1040
|
if (params.signalFactors !== void 0) {
|
|
1021
1041
|
formData.append("signal_factors", JSON.stringify(params.signalFactors));
|
|
1022
1042
|
}
|
|
1023
|
-
return this.client.request("POST", "/v1/quant/backtest/upload", {
|
|
1043
|
+
return this.client.request("POST", "/v1/quant/backtest/upload", {
|
|
1044
|
+
formData,
|
|
1045
|
+
timeoutMs: _QuantModule.BACKTEST_TIMEOUT_MS
|
|
1046
|
+
});
|
|
1024
1047
|
}
|
|
1025
1048
|
};
|
|
1026
1049
|
|
|
@@ -2084,7 +2107,10 @@ var Reportify = class {
|
|
|
2084
2107
|
});
|
|
2085
2108
|
}
|
|
2086
2109
|
const controller = new AbortController();
|
|
2087
|
-
const timeoutId = setTimeout(
|
|
2110
|
+
const timeoutId = setTimeout(
|
|
2111
|
+
() => controller.abort(),
|
|
2112
|
+
options.timeoutMs ?? this.timeout
|
|
2113
|
+
);
|
|
2088
2114
|
const headers = {
|
|
2089
2115
|
Authorization: `Bearer ${this.apiKey}`,
|
|
2090
2116
|
"User-Agent": "reportify-sdk-js/0.3.10"
|