ohlcv-indicators 3.4.6 → 3.4.7
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/ohlcv-indicators.min.js +715 -683
- package/index.js +40 -9
- package/package.json +1 -1
- package/src/utilities/dateUtilities.js +7 -0
- package/src/utilities/verticalToHorizontal.js +16 -8
package/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import { pushToMain } from './src/core-functions/pushToMain.js'
|
|
|
15
15
|
import { assignTypes } from './src/utilities/assignTypes.js'
|
|
16
16
|
import { calcPrecisionMultiplier } from './src/utilities/precisionMultiplier.js'
|
|
17
17
|
import { buildArray } from './src/utilities/assignTypes.js'
|
|
18
|
-
|
|
18
|
+
import { dateOutputFormaters } from './src/utilities/dateUtilities.js'
|
|
19
19
|
|
|
20
20
|
//precomputed
|
|
21
21
|
import { precomputeMovingAverages } from './src/moving-averages/movingAverages.js'
|
|
@@ -86,8 +86,13 @@ export default class OHLCV_INDICATORS {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
|
|
89
|
-
getDataAsCols(
|
|
89
|
+
getDataAsCols(options = {}) {
|
|
90
90
|
this.compute();
|
|
91
|
+
|
|
92
|
+
const {skipNull = true, dateFormat = 'string'} = options
|
|
93
|
+
|
|
94
|
+
validateArrayOptions(Object.keys(dateOutputFormaters), dateFormat, 'dateFormat', 'getDataAsCols')
|
|
95
|
+
validateObject(options, 'options', 'getDataAsCols')
|
|
91
96
|
|
|
92
97
|
const {
|
|
93
98
|
precisionMultiplier,
|
|
@@ -112,9 +117,17 @@ export default class OHLCV_INDICATORS {
|
|
|
112
117
|
|
|
113
118
|
for (let x = startIndex; x < len; x++)
|
|
114
119
|
{
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
120
|
+
if(shouldApplyPrecision)
|
|
121
|
+
{
|
|
122
|
+
result[key][x] = arr[x] / precisionMultiplier
|
|
123
|
+
}
|
|
124
|
+
else if(key === 'date')
|
|
125
|
+
{
|
|
126
|
+
result[key][x] = dateOutputFormaters[dateFormat](arr[x])
|
|
127
|
+
}
|
|
128
|
+
else{
|
|
129
|
+
result[key][x] = arr[x]
|
|
130
|
+
}
|
|
118
131
|
}
|
|
119
132
|
|
|
120
133
|
}
|
|
@@ -123,20 +136,38 @@ export default class OHLCV_INDICATORS {
|
|
|
123
136
|
}
|
|
124
137
|
|
|
125
138
|
|
|
126
|
-
getData(
|
|
139
|
+
getData(options = {}) {
|
|
127
140
|
|
|
128
141
|
//getData method returns the last object (row) of the new OHLCV with indicators: {open, high, low, close, rsi_14, bollinger_bands_upper}
|
|
129
142
|
this.compute()
|
|
130
143
|
|
|
131
|
-
|
|
144
|
+
const {skipNull = true, dateFormat = 'string'} = options
|
|
145
|
+
|
|
146
|
+
validateArrayOptions(Object.keys(dateOutputFormaters), dateFormat, 'dateFormat', 'getData')
|
|
147
|
+
validateObject(options, 'options', 'getData')
|
|
148
|
+
|
|
149
|
+
return verticalToHorizontal({
|
|
150
|
+
main: this,
|
|
151
|
+
skipNull,
|
|
152
|
+
startIndex: 0,
|
|
153
|
+
dateFormat
|
|
154
|
+
})
|
|
132
155
|
}
|
|
133
156
|
|
|
134
157
|
|
|
135
|
-
getLastValues(){
|
|
158
|
+
getLastValues(options = {}){
|
|
136
159
|
|
|
137
160
|
this.compute()
|
|
138
161
|
|
|
139
|
-
|
|
162
|
+
const {dateFormat = 'string'} = options
|
|
163
|
+
validateArrayOptions(Object.keys(dateOutputFormaters), dateFormat, 'dateFormat', 'getData')
|
|
164
|
+
|
|
165
|
+
return verticalToHorizontal({
|
|
166
|
+
skipNull: false,
|
|
167
|
+
main: this,
|
|
168
|
+
startIndex: this.len - 1,
|
|
169
|
+
dateFormat
|
|
170
|
+
})[0]
|
|
140
171
|
}
|
|
141
172
|
|
|
142
173
|
compute() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ohlcv-indicators",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.7",
|
|
4
4
|
"description": "A JavaScript library featuring optimized trading indicators for OHLCV arrays [{open, high, low, close, value}]. This library is optimized for backtesting and trading bot development.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
startIndex = 0
|
|
5
|
-
) => {
|
|
1
|
+
import { dateOutputFormaters } from "./dateUtilities.js"
|
|
2
|
+
|
|
3
|
+
export const verticalToHorizontal = ({main, skipNull = false, startIndex = 0, dateFormat}) => {
|
|
6
4
|
|
|
7
5
|
const {precisionMultiplier, priceBased, precision, verticalOhlcv, invalidValueIndex, len, verticalOhlcvKeyNames, verticalOhlcvTempCols} = main
|
|
8
6
|
|
|
@@ -19,9 +17,19 @@ export const verticalToHorizontal = (
|
|
|
19
17
|
|
|
20
18
|
for (let i = maxStartIndex; i < len; i++)
|
|
21
19
|
{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
if(shouldApplyPrecision)
|
|
21
|
+
{
|
|
22
|
+
result[i - maxStartIndex][key] = arr[i] / precisionMultiplier
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
else if(key === 'date')
|
|
26
|
+
{
|
|
27
|
+
result[i - maxStartIndex][key] = dateOutputFormaters[dateFormat](arr[i])
|
|
28
|
+
}
|
|
29
|
+
else
|
|
30
|
+
{
|
|
31
|
+
result[i - maxStartIndex][key] = arr[i]
|
|
32
|
+
}
|
|
25
33
|
}
|
|
26
34
|
}
|
|
27
35
|
|