reportify-sdk 0.3.27 → 0.3.28
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 +61 -1
- package/dist/index.d.ts +61 -1
- package/dist/index.js +84 -6
- package/dist/index.mjs +84 -6
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -762,6 +762,19 @@ interface BatchMinuteParams {
|
|
|
762
762
|
endDateTime: string;
|
|
763
763
|
market?: StockMarket;
|
|
764
764
|
}
|
|
765
|
+
interface BacktestUploadParams {
|
|
766
|
+
file: File;
|
|
767
|
+
entryFormula?: string;
|
|
768
|
+
strategyCode?: string;
|
|
769
|
+
exitFormula?: string;
|
|
770
|
+
initialCash?: number;
|
|
771
|
+
commission?: number;
|
|
772
|
+
positionSize?: number;
|
|
773
|
+
maxPositions?: number;
|
|
774
|
+
minVolume?: number;
|
|
775
|
+
autoClose?: boolean;
|
|
776
|
+
signalFactors?: Record<string, string>;
|
|
777
|
+
}
|
|
765
778
|
interface BacktestResult {
|
|
766
779
|
success: boolean;
|
|
767
780
|
initial_cash: number;
|
|
@@ -1072,6 +1085,52 @@ declare class QuantModule {
|
|
|
1072
1085
|
* ```
|
|
1073
1086
|
*/
|
|
1074
1087
|
backtest(params: BacktestParams): Promise<BacktestResult>;
|
|
1088
|
+
/**
|
|
1089
|
+
* Upload an Excel file to run backtest
|
|
1090
|
+
*
|
|
1091
|
+
* Upload an Excel file (.xlsx/.xls) containing OHLCV data for backtesting.
|
|
1092
|
+
* This allows you to use your own market data instead of the system's built-in data source.
|
|
1093
|
+
*
|
|
1094
|
+
* Excel file format requirements:
|
|
1095
|
+
* - Required columns: date, open, high, low, close
|
|
1096
|
+
* - Optional columns: symbol (required for multi-symbol), volume, amount
|
|
1097
|
+
* - Custom fields: any ASCII-named columns with numeric values (e.g., pe, market_cap, pb_ratio)
|
|
1098
|
+
*
|
|
1099
|
+
* @param params - Upload backtest parameters
|
|
1100
|
+
* @returns Backtest results
|
|
1101
|
+
*
|
|
1102
|
+
* @example
|
|
1103
|
+
* ```typescript
|
|
1104
|
+
* // Upload from file input
|
|
1105
|
+
* const fileInput = document.getElementById('file') as HTMLInputElement;
|
|
1106
|
+
* const result = await client.quant.backtestUpload({
|
|
1107
|
+
* file: fileInput.files[0],
|
|
1108
|
+
* entryFormula: 'CROSS(MA(CLOSE, 5), MA(CLOSE, 10))',
|
|
1109
|
+
* exitFormula: 'CROSS(MA(CLOSE, 10), MA(CLOSE, 5))',
|
|
1110
|
+
* initialCash: 100000,
|
|
1111
|
+
* commission: 0.0003
|
|
1112
|
+
* });
|
|
1113
|
+
*
|
|
1114
|
+
* console.log(`Total Return: ${(result.total_return_pct * 100).toFixed(2)}%`);
|
|
1115
|
+
*
|
|
1116
|
+
* // With custom strategy code
|
|
1117
|
+
* const result2 = await client.quant.backtestUpload({
|
|
1118
|
+
* file: fileInput.files[0],
|
|
1119
|
+
* signalFactors: { ma5: 'MA(CLOSE, 5)', ma20: 'MA(CLOSE, 20)' },
|
|
1120
|
+
* strategyCode: `
|
|
1121
|
+
* def handle_data(context, datas):
|
|
1122
|
+
* for data in datas:
|
|
1123
|
+
* symbol = data.name
|
|
1124
|
+
* if not context.portfolio.get_position(symbol):
|
|
1125
|
+
* if data.ma5 > data.ma20:
|
|
1126
|
+
* context.order_target_percent(symbol, 0.2)
|
|
1127
|
+
* elif data.ma5 < data.ma20:
|
|
1128
|
+
* context.order_target_percent(symbol, 0)
|
|
1129
|
+
* `
|
|
1130
|
+
* });
|
|
1131
|
+
* ```
|
|
1132
|
+
*/
|
|
1133
|
+
backtestUpload(params: BacktestUploadParams): Promise<BacktestResult>;
|
|
1075
1134
|
}
|
|
1076
1135
|
|
|
1077
1136
|
/**
|
|
@@ -1894,6 +1953,7 @@ declare class Reportify {
|
|
|
1894
1953
|
request<T = unknown>(method: string, path: string, options?: {
|
|
1895
1954
|
params?: Record<string, unknown>;
|
|
1896
1955
|
body?: Record<string, unknown>;
|
|
1956
|
+
formData?: FormData;
|
|
1897
1957
|
}): Promise<T>;
|
|
1898
1958
|
/**
|
|
1899
1959
|
* Make a GET request
|
|
@@ -1917,4 +1977,4 @@ declare class Reportify {
|
|
|
1917
1977
|
getBytes(path: string): Promise<ArrayBuffer>;
|
|
1918
1978
|
}
|
|
1919
1979
|
|
|
1920
|
-
export { APIError, type AgentConversation, type AgentMessage, AgentModule, AuthenticationError, type BacktestParams, type BacktestResult, type BatchKline1mParams, type BatchMinuteParams, type BatchOHLCVOutput, type BatchOHLCVParams, type Calendar, type Channel, ChannelsModule, type ChatCompletionOptions, type ChatCompletionResponse, type ChatMode, ChatModule, type Chunk, type ChunkSearchOptions, type CommodityData, type CommodityType, type CompanyInfo, type CompanyOverview, type Concept, type ConceptDoc, type ConceptEvent, type ConceptFeed, type ConceptStock, ConceptsModule, type DocsListOptions, DocsModule, type Document, type DocumentInput, type EarningsEvent, type EarningsSearchOptions, type FactorComputeData, type FactorComputeParams, type FactorMeta, type FinancialStatement, type FollowedCompany, FollowingModule, type IPOEvent, type IPOStatus, type IndexConstituent, type IndexFund, type IndustryConstituent, KBModule, type KBSearchOptions, type Kline1mParams, MacroModule, type Market, type MinuteParams, NotFoundError, type OHLCVData, type OHLCVParams, type PaginatedResponse, type Period, type PriceData, QuantModule, type Quote, RateLimitError, Reportify, type ReportifyConfig, ReportifyError, type ScreenParams, type ScreenedStock, SearchModule, type SearchOptions, type Shareholder, type ShareholderType, type StockInfo, type StockMarket, StockModule, TimelineModule, type TimelineOptions, type UploadDocRequest, UserModule };
|
|
1980
|
+
export { APIError, type AgentConversation, type AgentMessage, AgentModule, AuthenticationError, type BacktestParams, type BacktestResult, type BacktestUploadParams, type BatchKline1mParams, type BatchMinuteParams, type BatchOHLCVOutput, type BatchOHLCVParams, type Calendar, type Channel, ChannelsModule, type ChatCompletionOptions, type ChatCompletionResponse, type ChatMode, ChatModule, type Chunk, type ChunkSearchOptions, type CommodityData, type CommodityType, type CompanyInfo, type CompanyOverview, type Concept, type ConceptDoc, type ConceptEvent, type ConceptFeed, type ConceptStock, ConceptsModule, type DocsListOptions, DocsModule, type Document, type DocumentInput, type EarningsEvent, type EarningsSearchOptions, type FactorComputeData, type FactorComputeParams, type FactorMeta, type FinancialStatement, type FollowedCompany, FollowingModule, type IPOEvent, type IPOStatus, type IndexConstituent, type IndexFund, type IndustryConstituent, KBModule, type KBSearchOptions, type Kline1mParams, MacroModule, type Market, type MinuteParams, NotFoundError, type OHLCVData, type OHLCVParams, type PaginatedResponse, type Period, type PriceData, QuantModule, type Quote, RateLimitError, Reportify, type ReportifyConfig, ReportifyError, type ScreenParams, type ScreenedStock, SearchModule, type SearchOptions, type Shareholder, type ShareholderType, type StockInfo, type StockMarket, StockModule, TimelineModule, type TimelineOptions, type UploadDocRequest, UserModule };
|
package/dist/index.d.ts
CHANGED
|
@@ -762,6 +762,19 @@ interface BatchMinuteParams {
|
|
|
762
762
|
endDateTime: string;
|
|
763
763
|
market?: StockMarket;
|
|
764
764
|
}
|
|
765
|
+
interface BacktestUploadParams {
|
|
766
|
+
file: File;
|
|
767
|
+
entryFormula?: string;
|
|
768
|
+
strategyCode?: string;
|
|
769
|
+
exitFormula?: string;
|
|
770
|
+
initialCash?: number;
|
|
771
|
+
commission?: number;
|
|
772
|
+
positionSize?: number;
|
|
773
|
+
maxPositions?: number;
|
|
774
|
+
minVolume?: number;
|
|
775
|
+
autoClose?: boolean;
|
|
776
|
+
signalFactors?: Record<string, string>;
|
|
777
|
+
}
|
|
765
778
|
interface BacktestResult {
|
|
766
779
|
success: boolean;
|
|
767
780
|
initial_cash: number;
|
|
@@ -1072,6 +1085,52 @@ declare class QuantModule {
|
|
|
1072
1085
|
* ```
|
|
1073
1086
|
*/
|
|
1074
1087
|
backtest(params: BacktestParams): Promise<BacktestResult>;
|
|
1088
|
+
/**
|
|
1089
|
+
* Upload an Excel file to run backtest
|
|
1090
|
+
*
|
|
1091
|
+
* Upload an Excel file (.xlsx/.xls) containing OHLCV data for backtesting.
|
|
1092
|
+
* This allows you to use your own market data instead of the system's built-in data source.
|
|
1093
|
+
*
|
|
1094
|
+
* Excel file format requirements:
|
|
1095
|
+
* - Required columns: date, open, high, low, close
|
|
1096
|
+
* - Optional columns: symbol (required for multi-symbol), volume, amount
|
|
1097
|
+
* - Custom fields: any ASCII-named columns with numeric values (e.g., pe, market_cap, pb_ratio)
|
|
1098
|
+
*
|
|
1099
|
+
* @param params - Upload backtest parameters
|
|
1100
|
+
* @returns Backtest results
|
|
1101
|
+
*
|
|
1102
|
+
* @example
|
|
1103
|
+
* ```typescript
|
|
1104
|
+
* // Upload from file input
|
|
1105
|
+
* const fileInput = document.getElementById('file') as HTMLInputElement;
|
|
1106
|
+
* const result = await client.quant.backtestUpload({
|
|
1107
|
+
* file: fileInput.files[0],
|
|
1108
|
+
* entryFormula: 'CROSS(MA(CLOSE, 5), MA(CLOSE, 10))',
|
|
1109
|
+
* exitFormula: 'CROSS(MA(CLOSE, 10), MA(CLOSE, 5))',
|
|
1110
|
+
* initialCash: 100000,
|
|
1111
|
+
* commission: 0.0003
|
|
1112
|
+
* });
|
|
1113
|
+
*
|
|
1114
|
+
* console.log(`Total Return: ${(result.total_return_pct * 100).toFixed(2)}%`);
|
|
1115
|
+
*
|
|
1116
|
+
* // With custom strategy code
|
|
1117
|
+
* const result2 = await client.quant.backtestUpload({
|
|
1118
|
+
* file: fileInput.files[0],
|
|
1119
|
+
* signalFactors: { ma5: 'MA(CLOSE, 5)', ma20: 'MA(CLOSE, 20)' },
|
|
1120
|
+
* strategyCode: `
|
|
1121
|
+
* def handle_data(context, datas):
|
|
1122
|
+
* for data in datas:
|
|
1123
|
+
* symbol = data.name
|
|
1124
|
+
* if not context.portfolio.get_position(symbol):
|
|
1125
|
+
* if data.ma5 > data.ma20:
|
|
1126
|
+
* context.order_target_percent(symbol, 0.2)
|
|
1127
|
+
* elif data.ma5 < data.ma20:
|
|
1128
|
+
* context.order_target_percent(symbol, 0)
|
|
1129
|
+
* `
|
|
1130
|
+
* });
|
|
1131
|
+
* ```
|
|
1132
|
+
*/
|
|
1133
|
+
backtestUpload(params: BacktestUploadParams): Promise<BacktestResult>;
|
|
1075
1134
|
}
|
|
1076
1135
|
|
|
1077
1136
|
/**
|
|
@@ -1894,6 +1953,7 @@ declare class Reportify {
|
|
|
1894
1953
|
request<T = unknown>(method: string, path: string, options?: {
|
|
1895
1954
|
params?: Record<string, unknown>;
|
|
1896
1955
|
body?: Record<string, unknown>;
|
|
1956
|
+
formData?: FormData;
|
|
1897
1957
|
}): Promise<T>;
|
|
1898
1958
|
/**
|
|
1899
1959
|
* Make a GET request
|
|
@@ -1917,4 +1977,4 @@ declare class Reportify {
|
|
|
1917
1977
|
getBytes(path: string): Promise<ArrayBuffer>;
|
|
1918
1978
|
}
|
|
1919
1979
|
|
|
1920
|
-
export { APIError, type AgentConversation, type AgentMessage, AgentModule, AuthenticationError, type BacktestParams, type BacktestResult, type BatchKline1mParams, type BatchMinuteParams, type BatchOHLCVOutput, type BatchOHLCVParams, type Calendar, type Channel, ChannelsModule, type ChatCompletionOptions, type ChatCompletionResponse, type ChatMode, ChatModule, type Chunk, type ChunkSearchOptions, type CommodityData, type CommodityType, type CompanyInfo, type CompanyOverview, type Concept, type ConceptDoc, type ConceptEvent, type ConceptFeed, type ConceptStock, ConceptsModule, type DocsListOptions, DocsModule, type Document, type DocumentInput, type EarningsEvent, type EarningsSearchOptions, type FactorComputeData, type FactorComputeParams, type FactorMeta, type FinancialStatement, type FollowedCompany, FollowingModule, type IPOEvent, type IPOStatus, type IndexConstituent, type IndexFund, type IndustryConstituent, KBModule, type KBSearchOptions, type Kline1mParams, MacroModule, type Market, type MinuteParams, NotFoundError, type OHLCVData, type OHLCVParams, type PaginatedResponse, type Period, type PriceData, QuantModule, type Quote, RateLimitError, Reportify, type ReportifyConfig, ReportifyError, type ScreenParams, type ScreenedStock, SearchModule, type SearchOptions, type Shareholder, type ShareholderType, type StockInfo, type StockMarket, StockModule, TimelineModule, type TimelineOptions, type UploadDocRequest, UserModule };
|
|
1980
|
+
export { APIError, type AgentConversation, type AgentMessage, AgentModule, AuthenticationError, type BacktestParams, type BacktestResult, type BacktestUploadParams, type BatchKline1mParams, type BatchMinuteParams, type BatchOHLCVOutput, type BatchOHLCVParams, type Calendar, type Channel, ChannelsModule, type ChatCompletionOptions, type ChatCompletionResponse, type ChatMode, ChatModule, type Chunk, type ChunkSearchOptions, type CommodityData, type CommodityType, type CompanyInfo, type CompanyOverview, type Concept, type ConceptDoc, type ConceptEvent, type ConceptFeed, type ConceptStock, ConceptsModule, type DocsListOptions, DocsModule, type Document, type DocumentInput, type EarningsEvent, type EarningsSearchOptions, type FactorComputeData, type FactorComputeParams, type FactorMeta, type FinancialStatement, type FollowedCompany, FollowingModule, type IPOEvent, type IPOStatus, type IndexConstituent, type IndexFund, type IndustryConstituent, KBModule, type KBSearchOptions, type Kline1mParams, MacroModule, type Market, type MinuteParams, NotFoundError, type OHLCVData, type OHLCVParams, type PaginatedResponse, type Period, type PriceData, QuantModule, type Quote, RateLimitError, Reportify, type ReportifyConfig, ReportifyError, type ScreenParams, type ScreenedStock, SearchModule, type SearchOptions, type Shareholder, type ShareholderType, type StockInfo, type StockMarket, StockModule, TimelineModule, type TimelineOptions, type UploadDocRequest, UserModule };
|
package/dist/index.js
CHANGED
|
@@ -977,6 +977,77 @@ var QuantModule = class {
|
|
|
977
977
|
}
|
|
978
978
|
return this.client.post("/v1/quant/backtest", body);
|
|
979
979
|
}
|
|
980
|
+
/**
|
|
981
|
+
* Upload an Excel file to run backtest
|
|
982
|
+
*
|
|
983
|
+
* Upload an Excel file (.xlsx/.xls) containing OHLCV data for backtesting.
|
|
984
|
+
* This allows you to use your own market data instead of the system's built-in data source.
|
|
985
|
+
*
|
|
986
|
+
* Excel file format requirements:
|
|
987
|
+
* - Required columns: date, open, high, low, close
|
|
988
|
+
* - Optional columns: symbol (required for multi-symbol), volume, amount
|
|
989
|
+
* - Custom fields: any ASCII-named columns with numeric values (e.g., pe, market_cap, pb_ratio)
|
|
990
|
+
*
|
|
991
|
+
* @param params - Upload backtest parameters
|
|
992
|
+
* @returns Backtest results
|
|
993
|
+
*
|
|
994
|
+
* @example
|
|
995
|
+
* ```typescript
|
|
996
|
+
* // Upload from file input
|
|
997
|
+
* const fileInput = document.getElementById('file') as HTMLInputElement;
|
|
998
|
+
* const result = await client.quant.backtestUpload({
|
|
999
|
+
* file: fileInput.files[0],
|
|
1000
|
+
* entryFormula: 'CROSS(MA(CLOSE, 5), MA(CLOSE, 10))',
|
|
1001
|
+
* exitFormula: 'CROSS(MA(CLOSE, 10), MA(CLOSE, 5))',
|
|
1002
|
+
* initialCash: 100000,
|
|
1003
|
+
* commission: 0.0003
|
|
1004
|
+
* });
|
|
1005
|
+
*
|
|
1006
|
+
* console.log(`Total Return: ${(result.total_return_pct * 100).toFixed(2)}%`);
|
|
1007
|
+
*
|
|
1008
|
+
* // With custom strategy code
|
|
1009
|
+
* const result2 = await client.quant.backtestUpload({
|
|
1010
|
+
* file: fileInput.files[0],
|
|
1011
|
+
* signalFactors: { ma5: 'MA(CLOSE, 5)', ma20: 'MA(CLOSE, 20)' },
|
|
1012
|
+
* strategyCode: `
|
|
1013
|
+
* def handle_data(context, datas):
|
|
1014
|
+
* for data in datas:
|
|
1015
|
+
* symbol = data.name
|
|
1016
|
+
* if not context.portfolio.get_position(symbol):
|
|
1017
|
+
* if data.ma5 > data.ma20:
|
|
1018
|
+
* context.order_target_percent(symbol, 0.2)
|
|
1019
|
+
* elif data.ma5 < data.ma20:
|
|
1020
|
+
* context.order_target_percent(symbol, 0)
|
|
1021
|
+
* `
|
|
1022
|
+
* });
|
|
1023
|
+
* ```
|
|
1024
|
+
*/
|
|
1025
|
+
async backtestUpload(params) {
|
|
1026
|
+
const paramsJson = {
|
|
1027
|
+
initial_cash: params.initialCash ?? 1e5,
|
|
1028
|
+
commission: params.commission ?? 0,
|
|
1029
|
+
position_size: params.positionSize ?? 0.2,
|
|
1030
|
+
max_positions: params.maxPositions ?? 5,
|
|
1031
|
+
min_volume: params.minVolume ?? 100,
|
|
1032
|
+
auto_close: params.autoClose ?? true
|
|
1033
|
+
};
|
|
1034
|
+
if (params.entryFormula !== void 0) {
|
|
1035
|
+
paramsJson.entry_formula = params.entryFormula;
|
|
1036
|
+
}
|
|
1037
|
+
if (params.strategyCode !== void 0) {
|
|
1038
|
+
paramsJson.strategy_code = params.strategyCode;
|
|
1039
|
+
}
|
|
1040
|
+
if (params.exitFormula !== void 0) {
|
|
1041
|
+
paramsJson.exit_formula = params.exitFormula;
|
|
1042
|
+
}
|
|
1043
|
+
if (params.signalFactors !== void 0) {
|
|
1044
|
+
paramsJson.signal_factors = params.signalFactors;
|
|
1045
|
+
}
|
|
1046
|
+
const formData = new FormData();
|
|
1047
|
+
formData.append("file", params.file);
|
|
1048
|
+
formData.append("params", JSON.stringify(paramsJson));
|
|
1049
|
+
return this.client.request("POST", "/v1/quant/backtest/upload", { formData });
|
|
1050
|
+
}
|
|
980
1051
|
};
|
|
981
1052
|
|
|
982
1053
|
// src/concepts.ts
|
|
@@ -2040,15 +2111,22 @@ var Reportify = class {
|
|
|
2040
2111
|
}
|
|
2041
2112
|
const controller = new AbortController();
|
|
2042
2113
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
2114
|
+
const headers = {
|
|
2115
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
2116
|
+
"User-Agent": "reportify-sdk-js/0.3.10"
|
|
2117
|
+
};
|
|
2118
|
+
let requestBody;
|
|
2119
|
+
if (options.formData) {
|
|
2120
|
+
requestBody = options.formData;
|
|
2121
|
+
} else {
|
|
2122
|
+
headers["Content-Type"] = "application/json";
|
|
2123
|
+
requestBody = options.body ? JSON.stringify(options.body) : void 0;
|
|
2124
|
+
}
|
|
2043
2125
|
try {
|
|
2044
2126
|
const response = await fetch(url.toString(), {
|
|
2045
2127
|
method,
|
|
2046
|
-
headers
|
|
2047
|
-
|
|
2048
|
-
"Content-Type": "application/json",
|
|
2049
|
-
"User-Agent": "reportify-sdk-js/0.3.10"
|
|
2050
|
-
},
|
|
2051
|
-
body: options.body ? JSON.stringify(options.body) : void 0,
|
|
2128
|
+
headers,
|
|
2129
|
+
body: requestBody,
|
|
2052
2130
|
signal: controller.signal
|
|
2053
2131
|
});
|
|
2054
2132
|
clearTimeout(timeoutId);
|
package/dist/index.mjs
CHANGED
|
@@ -933,6 +933,77 @@ var QuantModule = class {
|
|
|
933
933
|
}
|
|
934
934
|
return this.client.post("/v1/quant/backtest", body);
|
|
935
935
|
}
|
|
936
|
+
/**
|
|
937
|
+
* Upload an Excel file to run backtest
|
|
938
|
+
*
|
|
939
|
+
* Upload an Excel file (.xlsx/.xls) containing OHLCV data for backtesting.
|
|
940
|
+
* This allows you to use your own market data instead of the system's built-in data source.
|
|
941
|
+
*
|
|
942
|
+
* Excel file format requirements:
|
|
943
|
+
* - Required columns: date, open, high, low, close
|
|
944
|
+
* - Optional columns: symbol (required for multi-symbol), volume, amount
|
|
945
|
+
* - Custom fields: any ASCII-named columns with numeric values (e.g., pe, market_cap, pb_ratio)
|
|
946
|
+
*
|
|
947
|
+
* @param params - Upload backtest parameters
|
|
948
|
+
* @returns Backtest results
|
|
949
|
+
*
|
|
950
|
+
* @example
|
|
951
|
+
* ```typescript
|
|
952
|
+
* // Upload from file input
|
|
953
|
+
* const fileInput = document.getElementById('file') as HTMLInputElement;
|
|
954
|
+
* const result = await client.quant.backtestUpload({
|
|
955
|
+
* file: fileInput.files[0],
|
|
956
|
+
* entryFormula: 'CROSS(MA(CLOSE, 5), MA(CLOSE, 10))',
|
|
957
|
+
* exitFormula: 'CROSS(MA(CLOSE, 10), MA(CLOSE, 5))',
|
|
958
|
+
* initialCash: 100000,
|
|
959
|
+
* commission: 0.0003
|
|
960
|
+
* });
|
|
961
|
+
*
|
|
962
|
+
* console.log(`Total Return: ${(result.total_return_pct * 100).toFixed(2)}%`);
|
|
963
|
+
*
|
|
964
|
+
* // With custom strategy code
|
|
965
|
+
* const result2 = await client.quant.backtestUpload({
|
|
966
|
+
* file: fileInput.files[0],
|
|
967
|
+
* signalFactors: { ma5: 'MA(CLOSE, 5)', ma20: 'MA(CLOSE, 20)' },
|
|
968
|
+
* strategyCode: `
|
|
969
|
+
* def handle_data(context, datas):
|
|
970
|
+
* for data in datas:
|
|
971
|
+
* symbol = data.name
|
|
972
|
+
* if not context.portfolio.get_position(symbol):
|
|
973
|
+
* if data.ma5 > data.ma20:
|
|
974
|
+
* context.order_target_percent(symbol, 0.2)
|
|
975
|
+
* elif data.ma5 < data.ma20:
|
|
976
|
+
* context.order_target_percent(symbol, 0)
|
|
977
|
+
* `
|
|
978
|
+
* });
|
|
979
|
+
* ```
|
|
980
|
+
*/
|
|
981
|
+
async backtestUpload(params) {
|
|
982
|
+
const paramsJson = {
|
|
983
|
+
initial_cash: params.initialCash ?? 1e5,
|
|
984
|
+
commission: params.commission ?? 0,
|
|
985
|
+
position_size: params.positionSize ?? 0.2,
|
|
986
|
+
max_positions: params.maxPositions ?? 5,
|
|
987
|
+
min_volume: params.minVolume ?? 100,
|
|
988
|
+
auto_close: params.autoClose ?? true
|
|
989
|
+
};
|
|
990
|
+
if (params.entryFormula !== void 0) {
|
|
991
|
+
paramsJson.entry_formula = params.entryFormula;
|
|
992
|
+
}
|
|
993
|
+
if (params.strategyCode !== void 0) {
|
|
994
|
+
paramsJson.strategy_code = params.strategyCode;
|
|
995
|
+
}
|
|
996
|
+
if (params.exitFormula !== void 0) {
|
|
997
|
+
paramsJson.exit_formula = params.exitFormula;
|
|
998
|
+
}
|
|
999
|
+
if (params.signalFactors !== void 0) {
|
|
1000
|
+
paramsJson.signal_factors = params.signalFactors;
|
|
1001
|
+
}
|
|
1002
|
+
const formData = new FormData();
|
|
1003
|
+
formData.append("file", params.file);
|
|
1004
|
+
formData.append("params", JSON.stringify(paramsJson));
|
|
1005
|
+
return this.client.request("POST", "/v1/quant/backtest/upload", { formData });
|
|
1006
|
+
}
|
|
936
1007
|
};
|
|
937
1008
|
|
|
938
1009
|
// src/concepts.ts
|
|
@@ -1996,15 +2067,22 @@ var Reportify = class {
|
|
|
1996
2067
|
}
|
|
1997
2068
|
const controller = new AbortController();
|
|
1998
2069
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
2070
|
+
const headers = {
|
|
2071
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
2072
|
+
"User-Agent": "reportify-sdk-js/0.3.10"
|
|
2073
|
+
};
|
|
2074
|
+
let requestBody;
|
|
2075
|
+
if (options.formData) {
|
|
2076
|
+
requestBody = options.formData;
|
|
2077
|
+
} else {
|
|
2078
|
+
headers["Content-Type"] = "application/json";
|
|
2079
|
+
requestBody = options.body ? JSON.stringify(options.body) : void 0;
|
|
2080
|
+
}
|
|
1999
2081
|
try {
|
|
2000
2082
|
const response = await fetch(url.toString(), {
|
|
2001
2083
|
method,
|
|
2002
|
-
headers
|
|
2003
|
-
|
|
2004
|
-
"Content-Type": "application/json",
|
|
2005
|
-
"User-Agent": "reportify-sdk-js/0.3.10"
|
|
2006
|
-
},
|
|
2007
|
-
body: options.body ? JSON.stringify(options.body) : void 0,
|
|
2084
|
+
headers,
|
|
2085
|
+
body: requestBody,
|
|
2008
2086
|
signal: controller.signal
|
|
2009
2087
|
});
|
|
2010
2088
|
clearTimeout(timeoutId);
|