从接收tick数据到生成1分钟K线的实时处理
Posted
技术标签:
【中文标题】从接收tick数据到生成1分钟K线的实时处理【英文标题】:the real-time processing from receiving tick data to generating 1-minute K-line 【发布时间】:2021-12-07 02:17:53 【问题描述】:分时数据的结构与K线的数据结构不同。什么时候进行拦截转换,能说说大致的流程吗?
我目前收到滴答数据并已将其实时写入滴答(流数据表)。如果订阅,是否需要先接收(所有数据字段),然后转换成准备表(如交易者),其中只有几个必填字段,最后聚合生成烛台表。
【问题讨论】:
【参考方案1】:请参考以下代码:
tbColNames=`TradingDay`InstrumentID`ExchangeID`ExchangeInstID`LastPrice`Volume`Amount`OpenPosition`PreSettlementPrice`PreClosePrice`PreOpenInterest`OpenPrice`HighestPrice`LowestPrice`TotalVolume`TotalTurnover`OpenInterest`ClosePrice`SettlementPrice`UpperLimitPrice`LowerLimitPrice`ActionTime`RecvTime`BidPrice1`BidVolume1`AskPrice1`AskVolume1`BidPrice2`BidVolume2`AskPrice2`AskVolume2`BidPrice3`BidVolume3`AskPrice3`AskVolume3`BidPrice4`BidVolume4`AskPrice4`AskVolume4`BidPrice5`BidVolume5`AskPrice5`AskVolume5`AveragePrice`PreDelta`CurrDelta`RecordNo`TotalRecordNo`InDbTime
tbColTypes=[DATE,SYMBOL,SYMBOL,SYMBOL,DOUBLE,INT,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,INT,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,TIMESTAMP, TIMESTAMP,DOUBLE,INT,DOUBLE,INT,DOUBLE,INT,DOUBLE,INT,DOUBLE,INT,DOUBLE,INT,DOUBLE,INT,DOUBLE,INT,DOUBLE,INT,DOUBLE,INT,DOUBLE,DOUBLE,DOUBLE,INT,INT,TIMESTAMP]
tbTicks = streamTable(100000:0,tbColNames,tbColTypes)
enableTableShareAndPersistence(table=tbTicks, tableName=`ticks, cacheSize=2000000, retentionMinutes=4320 )
barColNames=`UpdateTime`InstrumentID`Open`High`Low`Close`Volume`Amount`OpenPosition`TradingDay
barColTypes=[TIMESTAMP,SYMBOL,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,INT,DOUBLE,DATE]
share streamTable(100:0, barColNames, barColTypes) as traders
metrics=<[
first(LastPrice),
max(LastPrice),
min(LastPrice),
last(LastPrice),
sum(Volume),
sum(Amount),
sum(OpenPosition),
last(TradingDay)]>
tsAggrKline = createTimeSeriesAggregator(name="aggr_kline_min01", windowSize=600000, step=600000, metrics=metrics, dummyTable=ticks, outputTable=traders, timeColumn=`InDbTime, keyColumn=`InstrumentID,updateTime=500, useWindowStartTime=true)
subscribeTable(tableName="ticks", actionName="act_tsaggr", offset=-1, handler=append!getStreamEngine("aggr_kline_min01"), batchSize=1000, throttle=1, hash=0, msgAsTable=true)
【讨论】:
以上是关于从接收tick数据到生成1分钟K线的实时处理的主要内容,如果未能解决你的问题,请参考以下文章
三分钟搭建websocket实时在线聊天,项目经理也不敢这么写