Browse Source

Filter incoming bars by timeframe

stable
Denis Tereshkin 6 years ago
parent
commit
21cbcf7826
  1. 12
      src/ATrade/Driver/Real/QuoteSourceThread.hs

12
src/ATrade/Driver/Real/QuoteSourceThread.hs

@ -44,12 +44,14 @@ startQuoteSourceThread ctx qsEp strategy eventChan agg tickFilter maybeSourceTim
(Just bar, !newAggValue) -> writeIORef agg newAggValue >> writeChan eventChan (NewBar bar) (Just bar, !newAggValue) -> writeIORef agg newAggValue >> writeChan eventChan (NewBar bar)
(Nothing, !newAggValue) -> writeIORef agg newAggValue (Nothing, !newAggValue) -> writeIORef agg newAggValue
Just _ -> return () Just _ -> return ()
QDBar (_, bar) -> do QDBar (incomingTf, bar) -> do
aggValue <- readIORef agg aggValue <- readIORef agg
when (isJust maybeSourceTimeframe) $ do case maybeSourceTimeframe of
case handleBar bar aggValue of Just tf -> when (tf == unBarTimeframe incomingTf) $
(Just bar', !newAggValue) -> writeIORef agg newAggValue >> writeChan eventChan (NewBar bar') case handleBar bar aggValue of
(Nothing, !newAggValue) -> writeIORef agg newAggValue) (Just bar', !newAggValue) -> writeIORef agg newAggValue >> writeChan eventChan (NewBar bar')
(Nothing, !newAggValue) -> writeIORef agg newAggValue
_ -> return ())
where where
goodTick tick = tickFilter tick && goodTick tick = tickFilter tick &&
(datatype tick /= LastTradePrice || (datatype tick == LastTradePrice && volume tick > 0)) (datatype tick /= LastTradePrice || (datatype tick == LastTradePrice && volume tick > 0))

Loading…
Cancel
Save