在 JS 中转换 OHLC 中的连续股票数据(开盘价、最高价、最低价、收盘价)



>我有一个以下格式的连续数据流,我想根据定义的时间片(如 5 分钟、10 分钟、30 分钟等(将其转换为开盘价、最高价、最低价和收盘价。同时,还应根据选择的时间片对buy_quantity和sell_quantity进行汇总。 在Javascript中,在来自websocket的连续实时数据流上执行此操作的最有效方法是什么? 为了增加复杂性,我至少有 50 种不同的股票代码或instrument_token。 理想的解决方案是类似于 python 熊猫包中可用的解决方案——这是一个示例 https://www.quantinsti.com/blog/tick-tick-ohlc-data-pandas-tutorial/

{ 
"_id" : "Q6GinQQKKnfA7FrAT", 
"instrument_token" : NumberInt(11552514), 
"last_price" : 10711.8, 
"buy_quantity" : NumberInt(714225), 
"sell_quantity" : NumberInt(488775), 
"buySellRatio" : 1.4612551787632346, 
"timestamp" : "2018 07 03 07:54:52", 
"oi" : NumberInt(20539500), 
"oi_day_high" : NumberInt(20539500), 
"oi_day_low" : NumberInt(19809750)
}
{ 
"_id" : "Dwez3LuqLsB6MZRnB", 
"instrument_token" : NumberInt(11552002), 
"last_price" : NumberInt(26329), 
"buy_quantity" : NumberInt(185520), 
"sell_quantity" : NumberInt(201080), 
"buySellRatio" : 0.9226178635369008, 
"timestamp" : "2018 07 03 07:54:52", 
"oi" : NumberInt(2163040), 
"oi_day_high" : NumberInt(2170680), 
"oi_day_low" : NumberInt(2018440)
}
{ 
"_id" : "tcDfqRPk3qs2mYmow", 
"instrument_token" : NumberInt(11552514), 
"last_price" : 10711.95, 
"buy_quantity" : NumberInt(713775), 
"sell_quantity" : NumberInt(490125), 
"buySellRatio" : 1.4563121652639632, 
"timestamp" : "2018 07 03 07:54:53", 
"oi" : NumberInt(20539500), 
"oi_day_high" : NumberInt(20539500), 
"oi_day_low" : NumberInt(19809750)
}

有两个部分:
1. 合并数据 2. 在图表中显示数据

为了合并数据,高效的数据结构可能如下所示:

data.slice.roundedtime.id

通过这种方式,您不必使用循环进行搜索,而是可以在浏览输入数据时处理每个记住的值。

{
"5": { // this line once, for all 5 minutes increments
"2018 07 03 07:50:00": { // this line each 5 minutes
"Q6GinQQKKnfA7FrAT": { // this line for each 5 minutes each ticker 
"volume": 123,
"high": 20539500,
"low": 19809750
},
"SecondTicker": {
"volume": 12,
"high": 1234,
"low": 123
}
},
"2018 07 03 07:45:00": {
"Q6GinQQKKnfA7FrAT": {
"volume": 123,
"high": 20539500,
"low": 19809750
}
}
},
"15": { // this line once, for all 15 minutes increments
"2018 07 03 07:45:00": {
"Q6GinQQKKnfA7FrAT": {
"volume": 123,
"high": 20539500,
"low": 19809750
}
}
}
}

数据量对于浏览器来说不是问题。浏览器页面正在运行且未刷新的每 24 小时,我们有:24 小时 * (2 + 6 + 12( 切片 * 50 个不同的报价 = 24000 条记录。

可以计算 15 分钟和 30 分钟的聚合,而不是记住。这是一个细节。

相关内容

最新更新