Browse Source

QuoteSourceThread: request both ticks and bars

master
Denis Tereshkin 7 years ago
parent
commit
a1322161a5
  1. 8
      src/ATrade/Driver/Real/QuoteSourceThread.hs

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

@ -13,6 +13,7 @@ import ATrade.RoboCom.Types
import ATrade.Types import ATrade.Types
import Data.IORef import Data.IORef
import Data.Maybe
import qualified Data.Text as T import qualified Data.Text as T
import Control.Concurrent hiding (readChan, writeChan, import Control.Concurrent hiding (readChan, writeChan,
@ -36,12 +37,14 @@ startQuoteSourceThread ctx qsEp strategy eventChan agg tickFilter maybeSourceTim
case qdata of case qdata of
QDTick tick -> when (goodTick tick) $ do QDTick tick -> when (goodTick tick) $ do
writeChan eventChan (NewTick tick) writeChan eventChan (NewTick tick)
when (isNothing maybeSourceTimeframe) $ do
aggValue <- readIORef agg aggValue <- readIORef agg
case handleTick tick aggValue of case handleTick tick aggValue of
(Just bar, !newAggValue) -> writeChan eventChan (NewBar bar) >> writeIORef agg newAggValue (Just bar, !newAggValue) -> writeChan eventChan (NewBar bar) >> writeIORef agg newAggValue
(Nothing, !newAggValue) -> writeIORef agg newAggValue (Nothing, !newAggValue) -> writeIORef agg newAggValue
QDBar (_, bar) -> do QDBar (_, bar) -> do
aggValue <- readIORef agg aggValue <- readIORef agg
when (isJust maybeSourceTimeframe) $ do
case handleBar bar aggValue of case handleBar bar aggValue of
(Just bar', !newAggValue) -> writeChan eventChan (NewBar bar') >> writeIORef agg newAggValue (Just bar', !newAggValue) -> writeChan eventChan (NewBar bar') >> writeIORef agg newAggValue
(Nothing, !newAggValue) -> writeIORef agg newAggValue) (Nothing, !newAggValue) -> writeIORef agg newAggValue)
@ -49,8 +52,5 @@ startQuoteSourceThread ctx qsEp strategy eventChan agg tickFilter maybeSourceTim
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))
tickersList' = fmap code . (tickers . strategyInstanceParams) $ strategy tickersList = fmap code . (tickers . strategyInstanceParams) $ strategy
tickersList = case maybeSourceTimeframe of
Just tf -> fmap (\x -> T.append x (T.pack $ ":" ++ show tf ++ ";")) tickersList'
_ -> tickersList'

Loading…
Cancel
Save