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/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(skipNull = true) {
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
- result[key][x] = (shouldApplyPrecision)
116
- ? arr[x] / precisionMultiplier
117
- : arr[x]
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(skipNull = true) {
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
- return verticalToHorizontal(skipNull, this, 0)
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
- return verticalToHorizontal(false, this, this.len - 1)[0]
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.6",
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,3 +1,10 @@
1
+ export const dateOutputFormaters = {
2
+ string: d => d.toISOString(),
3
+ milliseconds: d => d.getTime(),
4
+ seconds: d => d.getTime() / 1000,
5
+ object: d => d
6
+ }
7
+
1
8
  export const dateFormaters = {
2
9
  dateObject: d => d,
3
10
  dateMilliseconds: d => new Date(d),
@@ -1,8 +1,6 @@
1
- export const verticalToHorizontal = (
2
- skipNull = false,
3
- main,
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
- result[i - maxStartIndex][key] = (shouldApplyPrecision)
23
- ? arr[i] / precisionMultiplier
24
- : arr[i]
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