6565)
6666
6767
68- class OHLC (Struct ):
68+ class OHLC (Struct , frozen = True ):
6969 '''
7070 Description of the flattened OHLC quote format.
7171
@@ -76,6 +76,8 @@ class OHLC(Struct):
7676 chan_id : int # internal kraken id
7777 chan_name : str # eg. ohlc-1 (name-interval)
7878 pair : str # fx pair
79+
80+ # unpacked from array
7981 time : float # Begin time of interval, in seconds since epoch
8082 etime : float # End time of interval, in seconds since epoch
8183 open : float # Open price of interval
@@ -85,8 +87,6 @@ class OHLC(Struct):
8587 vwap : float # Volume weighted average price within interval
8688 volume : float # Accumulated volume **within interval**
8789 count : int # Number of trades within interval
88- # (sampled) generated tick data
89- ticks : list [Any ] = []
9090
9191
9292async def stream_messages (
@@ -150,14 +150,15 @@ async def process_data_feed_msgs(
150150 pair
151151 ]:
152152 if 'ohlc' in chan_name :
153+ array : list = payload_array [0 ]
153154 ohlc = OHLC (
154155 chan_id ,
155156 chan_name ,
156157 pair ,
157- * payload_array [0 ]
158+ * map (float , array [:- 1 ]),
159+ count = array [- 1 ],
158160 )
159- ohlc .typecast ()
160- yield 'ohlc' , ohlc
161+ yield 'ohlc' , ohlc .copy ()
161162
162163 elif 'spread' in chan_name :
163164
@@ -430,7 +431,7 @@ async def subscribe(ws: NoBsWs):
430431 feed_is_live .set ()
431432
432433 # keep start of last interval for volume tracking
433- last_interval_start = ohlc_last .etime
434+ last_interval_start : float = ohlc_last .etime
434435
435436 # start streaming
436437 topic : str = mkt .bs_fqme
@@ -448,24 +449,23 @@ async def subscribe(ws: NoBsWs):
448449
449450 # new OHLC sample interval
450451 if quote .etime > last_interval_start :
451- last_interval_start = quote .etime
452- tick_volume = volume
452+ last_interval_start : float = quote .etime
453+ tick_volume : float = volume
453454
454455 else :
455456 # this is the tick volume *within the interval*
456- tick_volume = volume - ohlc_last .volume
457+ tick_volume : float = volume - ohlc_last .volume
457458
458459 ohlc_last = quote
459460 last = quote .close
460461
462+ quote = normalize (quote )
461463 if tick_volume :
462- quote . ticks . append ( {
464+ quote [ ' ticks' ] = [ {
463465 'type' : 'trade' ,
464466 'price' : last ,
465467 'size' : tick_volume ,
466- })
467-
468- quote = normalize (quote )
468+ }]
469469
470470 case 'l1' :
471471 # passthrough quote msg
0 commit comments