forked from klinecharts/samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneratedKLineDataList.js
More file actions
31 lines (31 loc) · 1023 Bytes
/
Copy pathgeneratedKLineDataList.js
File metadata and controls
31 lines (31 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
export default function (baseTimestamp = Date.now(), basePrice = 5000, dataSize = 800) {
const dataList = []
let timestamp = Math.floor(baseTimestamp / 60 / 1000) * 60 * 1000
let baseValue = basePrice
const prices = []
for (let i = 0; i < dataSize; i++) {
baseValue = baseValue + Math.random() * 20 - 10
for (let j = 0; j < 4; j++) {
prices[j] = (Math.random() - 0.5) * 12 + baseValue
}
prices.sort()
const openIdx = +Math.round(Math.random() * 3).toFixed(0)
let closeIdx = +Math.round(Math.random() * 2).toFixed(0)
if (closeIdx === openIdx) {
closeIdx++
}
const volume = Math.random() * 50 + 10
const kLineModel = {
open: prices[openIdx],
low: prices[0],
high: prices[3],
close: prices[closeIdx],
volume: volume,
timestamp
}
timestamp -= 60 * 1000
kLineModel.turnover = (kLineModel.open + kLineModel.close + kLineModel.high + kLineModel.low) / 4 * volume
dataList.unshift(kLineModel)
}
return dataList
}