w-trade-solve 1.0.1
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/.editorconfig +9 -0
- package/.eslintignore +3 -0
- package/.eslintrc.js +55 -0
- package/.jsdoc +25 -0
- package/README.md +132 -0
- package/SECURITY.md +5 -0
- package/babel.config.js +16 -0
- package/dist/w-trade-solve.umd.js +19 -0
- package/dist/w-trade-solve.umd.js.map +1 -0
- package/docs/calcFitness.mjs.html +205 -0
- package/docs/calcLevelNumTrade.mjs.html +164 -0
- package/docs/cont.mjs.html +94 -0
- package/docs/estimComps.mjs.html +190 -0
- package/docs/estimFinder.mjs.html +197 -0
- package/docs/estimKeys.mjs.html +571 -0
- package/docs/estimPicks.mjs.html +200 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
- package/docs/genSid.mjs.html +125 -0
- package/docs/genStrategyFileName.mjs.html +131 -0
- package/docs/genTid.mjs.html +113 -0
- package/docs/global.html +4932 -0
- package/docs/index.html +84 -0
- package/docs/ott.mjs.html +137 -0
- package/docs/p2r.mjs.html +111 -0
- package/docs/readStrategies.mjs.html +203 -0
- package/docs/scripts/collapse.js +39 -0
- package/docs/scripts/commonNav.js +28 -0
- package/docs/scripts/linenumber.js +25 -0
- package/docs/scripts/nav.js +12 -0
- package/docs/scripts/polyfill.js +4 -0
- package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/docs/scripts/prettify/lang-css.js +2 -0
- package/docs/scripts/prettify/prettify.js +28 -0
- package/docs/scripts/search.js +99 -0
- package/docs/styles/jsdoc.css +776 -0
- package/docs/styles/prettify.css +80 -0
- package/g.mjs +110 -0
- package/package.json +31 -0
- package/script.txt +19 -0
- package/src/WTradeSolve.mjs +29 -0
- package/src/calcFitness.mjs +133 -0
- package/src/calcLevelNumTrade.mjs +92 -0
- package/src/cont.mjs +22 -0
- package/src/estimComps.mjs +118 -0
- package/src/estimFinder.mjs +125 -0
- package/src/estimKeys.mjs +499 -0
- package/src/estimPicks.mjs +128 -0
- package/src/genSid.mjs +53 -0
- package/src/genStrategyFileName.mjs +59 -0
- package/src/genTid.mjs +41 -0
- package/src/ott.mjs +65 -0
- package/src/p2r.mjs +39 -0
- package/src/readStrategies.mjs +131 -0
- package/test/unit-WTradeSolve.test.mjs +83 -0
- package/test/unit-calcFitness.test.mjs +121 -0
- package/test/unit-calcLevelNumTrade.test.mjs +80 -0
- package/test/unit-estimComps.test.mjs +193 -0
- package/test/unit-estimFinder.test.mjs +184 -0
- package/test/unit-estimKeys.test.mjs +260 -0
- package/test/unit-estimPicks.test.mjs +241 -0
- package/test/unit-genSid.test.mjs +75 -0
- package/test/unit-genStrategyFileName.test.mjs +85 -0
- package/test/unit-genTid.test.mjs +72 -0
- package/test/unit-p2r.test.mjs +51 -0
- package/test/unit-readStrategies.test.mjs +258 -0
- package/test/unit-setup.mjs +119 -0
- package/toolg/addVersion.mjs +4 -0
- package/toolg/cleanFolder.mjs +5 -0
- package/toolg/gDistRollup.mjs +37 -0
- package/toolg/gDocsExams.mjs +48 -0
- package/toolg/modifyReadme.mjs +4 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>genSid.mjs - Documentation</title>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
+
<!--[if lt IE 9]>
|
|
12
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
+
<![endif]-->
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
+
<script src="scripts/nav.js" defer></script>
|
|
17
|
+
|
|
18
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
|
|
22
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
23
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
24
|
+
<div class="navicon"></div>
|
|
25
|
+
</label>
|
|
26
|
+
|
|
27
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
28
|
+
|
|
29
|
+
<nav >
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#calcFitness">calcFitness</a></li><li><a href="global.html#calcLevelNumTrade">calcLevelNumTrade</a></li><li><a href="global.html#cont">cont</a></li><li><a href="global.html#estimComps">estimComps</a></li><li><a href="global.html#estimFinder">estimFinder</a></li><li><a href="global.html#estimKeys">estimKeys</a></li><li><a href="global.html#estimPicks">estimPicks</a></li><li><a href="global.html#genSid">genSid</a></li><li><a href="global.html#genStrategyFileName">genStrategyFileName</a></li><li><a href="global.html#genTid">genTid</a></li><li><a href="global.html#nowTpeStr">nowTpeStr</a></li><li><a href="global.html#nowTpeStrp">nowTpeStrp</a></li><li><a href="global.html#ott">ott</a></li><li><a href="global.html#p2r">p2r</a></li><li><a href="global.html#readStrategies">readStrategies</a></li></ul>
|
|
33
|
+
|
|
34
|
+
</nav>
|
|
35
|
+
|
|
36
|
+
<div id="main">
|
|
37
|
+
|
|
38
|
+
<h1 class="page-title">genSid.mjs</h1>
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<section>
|
|
47
|
+
<article>
|
|
48
|
+
<pre class="prettyprint source linenums"><code>import join from 'lodash-es/join.js'
|
|
49
|
+
import map from 'lodash-es/map.js'
|
|
50
|
+
import cont from './cont.mjs'
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 產生策略識別碼sid
|
|
55
|
+
*
|
|
56
|
+
* 各cond先組為`${key}${sym}${th}`,再以cont.dlmSeps串接mode與各cond為識別字串,最後進行與genTid相同之縮寫替換
|
|
57
|
+
* 縮寫替換依序為: 剔除`${coin}_`、剔除`${interval}_`、'price_'轉'p_'、'index_'轉'i_'、'Ohlc_'轉'o_'、'Close_'轉'c_'、'Volumn_'轉'v_'
|
|
58
|
+
* 因替換係以`${coin}_`與`${interval}_`為樣式,故coin與interval須給予有效字串,否則將剔除全部底線
|
|
59
|
+
* sid已含各cond之門檻,故同組keys之不同門檻組合對應不同sid,可與僅由keys決定之tid區別
|
|
60
|
+
*
|
|
61
|
+
* Unit Test: {@link https://github.com/yuda-lyu/w-trade-solve/blob/master/test/unit-genSid.test.mjs Github}
|
|
62
|
+
* @function
|
|
63
|
+
* @param {String} coin 輸入幣種名稱字串,例如'btc'
|
|
64
|
+
* @param {String} interval 輸入K線週期字串,例如'4hr'
|
|
65
|
+
* @param {String} mode 輸入交易方向字串,可選'long'或'short'
|
|
66
|
+
* @param {Array} conds 輸入條件物件陣列,各元素為{key,sym,th},key為指標key字串,sym為'>'或'<',th為門檻數值
|
|
67
|
+
* @returns {String} 回傳策略識別碼sid字串
|
|
68
|
+
* @example
|
|
69
|
+
*
|
|
70
|
+
* let conds = [
|
|
71
|
+
* { key: 'btc_price_4hr_ma_1day', sym: '>', th: 0.05 },
|
|
72
|
+
* { key: 'btc_index_rsi_4hr', sym: '<', th: -0.2 },
|
|
73
|
+
* ]
|
|
74
|
+
*
|
|
75
|
+
* let sid = genSid('btc', '4hr', 'long', conds)
|
|
76
|
+
* console.log(sid)
|
|
77
|
+
* // => 'long ║ p_ma_1day>0.05 ║ i_rsi_4hr<-0.2'
|
|
78
|
+
*
|
|
79
|
+
*/
|
|
80
|
+
let genSid = (coin, interval, mode, conds) => {
|
|
81
|
+
let ss = map(conds, (cond) => {
|
|
82
|
+
// key,
|
|
83
|
+
// sym,
|
|
84
|
+
// th,
|
|
85
|
+
return `${cond.key}${cond.sym}${cond.th}`
|
|
86
|
+
})
|
|
87
|
+
let sid = join([mode, ...ss], cont.dlmSeps)
|
|
88
|
+
sid = sid.replaceAll(`${coin}_`, '')
|
|
89
|
+
sid = sid.replaceAll(`${interval}_`, '')
|
|
90
|
+
sid = sid.replaceAll(`price_`, 'p_')
|
|
91
|
+
sid = sid.replaceAll(`index_`, 'i_')
|
|
92
|
+
sid = sid.replaceAll(`Ohlc_`, 'o_')
|
|
93
|
+
sid = sid.replaceAll(`Close_`, 'c_')
|
|
94
|
+
sid = sid.replaceAll(`Volumn_`, 'v_')
|
|
95
|
+
// console.log('sid', sid)
|
|
96
|
+
return sid
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
export default genSid
|
|
101
|
+
</code></pre>
|
|
102
|
+
</article>
|
|
103
|
+
</section>
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
<br class="clear">
|
|
113
|
+
|
|
114
|
+
<footer>
|
|
115
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Tue Aug 04 2026 23:21:49 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
116
|
+
</footer>
|
|
117
|
+
|
|
118
|
+
<script>prettyPrint();</script>
|
|
119
|
+
<script src="scripts/polyfill.js"></script>
|
|
120
|
+
<script src="scripts/linenumber.js"></script>
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
</body>
|
|
125
|
+
</html>
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>genStrategyFileName.mjs - Documentation</title>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
+
<!--[if lt IE 9]>
|
|
12
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
+
<![endif]-->
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
+
<script src="scripts/nav.js" defer></script>
|
|
17
|
+
|
|
18
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
|
|
22
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
23
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
24
|
+
<div class="navicon"></div>
|
|
25
|
+
</label>
|
|
26
|
+
|
|
27
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
28
|
+
|
|
29
|
+
<nav >
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#calcFitness">calcFitness</a></li><li><a href="global.html#calcLevelNumTrade">calcLevelNumTrade</a></li><li><a href="global.html#cont">cont</a></li><li><a href="global.html#estimComps">estimComps</a></li><li><a href="global.html#estimFinder">estimFinder</a></li><li><a href="global.html#estimKeys">estimKeys</a></li><li><a href="global.html#estimPicks">estimPicks</a></li><li><a href="global.html#genSid">genSid</a></li><li><a href="global.html#genStrategyFileName">genStrategyFileName</a></li><li><a href="global.html#genTid">genTid</a></li><li><a href="global.html#nowTpeStr">nowTpeStr</a></li><li><a href="global.html#nowTpeStrp">nowTpeStrp</a></li><li><a href="global.html#ott">ott</a></li><li><a href="global.html#p2r">p2r</a></li><li><a href="global.html#readStrategies">readStrategies</a></li></ul>
|
|
33
|
+
|
|
34
|
+
</nav>
|
|
35
|
+
|
|
36
|
+
<div id="main">
|
|
37
|
+
|
|
38
|
+
<h1 class="page-title">genStrategyFileName.mjs</h1>
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<section>
|
|
47
|
+
<article>
|
|
48
|
+
<pre class="prettyprint source linenums"><code>import cint from 'wsemi/src/cint.mjs'
|
|
49
|
+
import cont from './cont.mjs'
|
|
50
|
+
import genTid from './genTid.mjs'
|
|
51
|
+
import calcLevelNumTrade from './calcLevelNumTrade.mjs'
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 產生策略儲存檔名
|
|
56
|
+
*
|
|
57
|
+
* 檔名為`${tid}${cont.dlmPkgs}${levelNumTrade}${cont.dlmPkgs}${rEquivalentCumuProfitOrLossFinalNormYear}.json`
|
|
58
|
+
* tid由genTid以coin、interval、mode與keys產生,levelNumTrade由calcLevelNumTrade以summary.numTrade產生
|
|
59
|
+
* 因tid與levelNumTrade皆入檔名,故可由檔名反解出同組keys與同交易次數級距之既有策略,供readStrategies列舉比較
|
|
60
|
+
* settings目前未參與檔名組成
|
|
61
|
+
*
|
|
62
|
+
* Unit Test: {@link https://github.com/yuda-lyu/w-trade-solve/blob/master/test/unit-genStrategyFileName.test.mjs Github}
|
|
63
|
+
* @function
|
|
64
|
+
* @param {String} coin 輸入幣種名稱字串,例如'btc'
|
|
65
|
+
* @param {String} interval 輸入K線週期字串,例如'4hr'
|
|
66
|
+
* @param {String} mode 輸入交易方向字串,可選'long'或'short'
|
|
67
|
+
* @param {Array} keys 輸入指標key字串陣列
|
|
68
|
+
* @param {Object} settings 輸入策略設定物件
|
|
69
|
+
* @param {Object} summary 輸入回測統計摘要物件,需含numTrade(交易次數)與rEquivalentCumuProfitOrLossFinalNormYear(最終等效年化盈虧百分比字串)欄位
|
|
70
|
+
* @returns {String} 回傳策略儲存檔名字串
|
|
71
|
+
* @example
|
|
72
|
+
*
|
|
73
|
+
* let keys = ['btc_price_4hr_ma_1day']
|
|
74
|
+
*
|
|
75
|
+
* let settings = { uIni: 1000, uTrade: 1, rTakeProfit: 0.05, rStopLoss: 0.03, rFee: 0.0005 }
|
|
76
|
+
*
|
|
77
|
+
* let summary = { numTrade: 30, rEquivalentCumuProfitOrLossFinalNormYear: '31.25%' }
|
|
78
|
+
*
|
|
79
|
+
* let fn = genStrategyFileName('btc', '4hr', 'long', keys, settings, summary)
|
|
80
|
+
* console.log(fn)
|
|
81
|
+
* // => 'long ║ p_ma_1day ⊙ 12 ⊙ 31.25%.json'
|
|
82
|
+
*
|
|
83
|
+
*/
|
|
84
|
+
let genStrategyFileName = (coin, interval, mode, keys, settings, summary) => {
|
|
85
|
+
|
|
86
|
+
//tid
|
|
87
|
+
let tid = genTid(coin, interval, mode, keys)
|
|
88
|
+
// console.log('tid', tid)
|
|
89
|
+
|
|
90
|
+
//numTrade
|
|
91
|
+
let numTrade = cint(summary.numTrade)
|
|
92
|
+
|
|
93
|
+
//levelNumTrade
|
|
94
|
+
let levelNumTrade = calcLevelNumTrade(numTrade)
|
|
95
|
+
|
|
96
|
+
//rEquivalentCumuProfitOrLossFinalNormYear
|
|
97
|
+
let rEquivalentCumuProfitOrLossFinalNormYear = summary.rEquivalentCumuProfitOrLossFinalNormYear
|
|
98
|
+
|
|
99
|
+
//fnStrategy
|
|
100
|
+
let fnStrategy = `${tid}${cont.dlmPkgs}${levelNumTrade}${cont.dlmPkgs}${rEquivalentCumuProfitOrLossFinalNormYear}.json`
|
|
101
|
+
|
|
102
|
+
return fnStrategy
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
export default genStrategyFileName
|
|
107
|
+
</code></pre>
|
|
108
|
+
</article>
|
|
109
|
+
</section>
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
</div>
|
|
117
|
+
|
|
118
|
+
<br class="clear">
|
|
119
|
+
|
|
120
|
+
<footer>
|
|
121
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Tue Aug 04 2026 23:21:49 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
122
|
+
</footer>
|
|
123
|
+
|
|
124
|
+
<script>prettyPrint();</script>
|
|
125
|
+
<script src="scripts/polyfill.js"></script>
|
|
126
|
+
<script src="scripts/linenumber.js"></script>
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
</body>
|
|
131
|
+
</html>
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>genTid.mjs - Documentation</title>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
+
<!--[if lt IE 9]>
|
|
12
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
+
<![endif]-->
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
+
<script src="scripts/nav.js" defer></script>
|
|
17
|
+
|
|
18
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
|
|
22
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
23
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
24
|
+
<div class="navicon"></div>
|
|
25
|
+
</label>
|
|
26
|
+
|
|
27
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
28
|
+
|
|
29
|
+
<nav >
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#calcFitness">calcFitness</a></li><li><a href="global.html#calcLevelNumTrade">calcLevelNumTrade</a></li><li><a href="global.html#cont">cont</a></li><li><a href="global.html#estimComps">estimComps</a></li><li><a href="global.html#estimFinder">estimFinder</a></li><li><a href="global.html#estimKeys">estimKeys</a></li><li><a href="global.html#estimPicks">estimPicks</a></li><li><a href="global.html#genSid">genSid</a></li><li><a href="global.html#genStrategyFileName">genStrategyFileName</a></li><li><a href="global.html#genTid">genTid</a></li><li><a href="global.html#nowTpeStr">nowTpeStr</a></li><li><a href="global.html#nowTpeStrp">nowTpeStrp</a></li><li><a href="global.html#ott">ott</a></li><li><a href="global.html#p2r">p2r</a></li><li><a href="global.html#readStrategies">readStrategies</a></li></ul>
|
|
33
|
+
|
|
34
|
+
</nav>
|
|
35
|
+
|
|
36
|
+
<div id="main">
|
|
37
|
+
|
|
38
|
+
<h1 class="page-title">genTid.mjs</h1>
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<section>
|
|
47
|
+
<article>
|
|
48
|
+
<pre class="prettyprint source linenums"><code>import join from 'lodash-es/join.js'
|
|
49
|
+
import cont from './cont.mjs'
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 產生策略種類識別碼tid
|
|
54
|
+
*
|
|
55
|
+
* 以cont.dlmSeps串接mode與各key為識別字串,再進行縮寫替換以縮短長度
|
|
56
|
+
* 縮寫替換依序為: 剔除`${coin}_`、剔除`${interval}_`、'price_'轉'p_'、'index_'轉'i_'、'Ohlc_'轉'o_'、'Close_'轉'c_'、'Volumn_'轉'v_'
|
|
57
|
+
* 因替換係以`${coin}_`與`${interval}_`為樣式,故coin與interval須給予有效字串,否則將剔除全部底線
|
|
58
|
+
* tid僅由mode與keys決定,未含各key之門檻條件,故同組keys之各門檻組合皆對應同一tid
|
|
59
|
+
*
|
|
60
|
+
* Unit Test: {@link https://github.com/yuda-lyu/w-trade-solve/blob/master/test/unit-genTid.test.mjs Github}
|
|
61
|
+
* @function
|
|
62
|
+
* @param {String} coin 輸入幣種名稱字串,例如'btc'
|
|
63
|
+
* @param {String} interval 輸入K線週期字串,例如'4hr'
|
|
64
|
+
* @param {String} mode 輸入交易方向字串,可選'long'或'short'
|
|
65
|
+
* @param {Array} keys 輸入指標key字串陣列
|
|
66
|
+
* @returns {String} 回傳策略種類識別碼tid字串
|
|
67
|
+
* @example
|
|
68
|
+
*
|
|
69
|
+
* let tid = genTid('btc', '4hr', 'long', ['btc_price_4hr_ma_1day', 'btc_index_rsi_4hr'])
|
|
70
|
+
* console.log(tid)
|
|
71
|
+
* // => 'long ║ p_ma_1day ║ i_rsi_4hr'
|
|
72
|
+
*
|
|
73
|
+
*/
|
|
74
|
+
let genTid = (coin, interval, mode, keys) => {
|
|
75
|
+
let tid = join([mode, ...keys], cont.dlmSeps)
|
|
76
|
+
tid = tid.replaceAll(`${coin}_`, '')
|
|
77
|
+
tid = tid.replaceAll(`${interval}_`, '')
|
|
78
|
+
tid = tid.replaceAll(`price_`, 'p_')
|
|
79
|
+
tid = tid.replaceAll(`index_`, 'i_')
|
|
80
|
+
tid = tid.replaceAll(`Ohlc_`, 'o_')
|
|
81
|
+
tid = tid.replaceAll(`Close_`, 'c_')
|
|
82
|
+
tid = tid.replaceAll(`Volumn_`, 'v_')
|
|
83
|
+
// console.log('tid', tid)
|
|
84
|
+
return tid
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
export default genTid
|
|
89
|
+
</code></pre>
|
|
90
|
+
</article>
|
|
91
|
+
</section>
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
<br class="clear">
|
|
101
|
+
|
|
102
|
+
<footer>
|
|
103
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Tue Aug 04 2026 23:21:49 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
104
|
+
</footer>
|
|
105
|
+
|
|
106
|
+
<script>prettyPrint();</script>
|
|
107
|
+
<script src="scripts/polyfill.js"></script>
|
|
108
|
+
<script src="scripts/linenumber.js"></script>
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
</body>
|
|
113
|
+
</html>
|