From eb61223e181e667fcd8e48f909903281c9774f65 Mon Sep 17 00:00:00 2001 From: Denis Tereshkin Date: Mon, 26 Aug 2019 14:56:21 +0700 Subject: [PATCH] Real: read params from IORef --- src/ATrade/Driver/Real.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ATrade/Driver/Real.hs b/src/ATrade/Driver/Real.hs index 8877cdc..8a312ba 100644 --- a/src/ATrade/Driver/Real.hs +++ b/src/ATrade/Driver/Real.hs @@ -144,7 +144,6 @@ storeState params stateRef timersRef = do return () #endif - gracefulShutdown :: (ToJSON s) => Params -> IORef s -> IORef [UTCTime] -> MVar () -> Signal -> IO () gracefulShutdown params stateRef timersRef shutdownMv _ = do infoM "main" "Shutdown, saving state" @@ -179,6 +178,7 @@ robotMain dataDownloadDelta defaultState initCallback callback = do let strategy = mkBarStrategy instanceParams dataDownloadDelta updatedConfig stratState callback stateRef <- newIORef stratState + configRef <- newIORef config timersRef <- newIORef timersState shutdownMv <- newEmptyMVar installHandler sigINT (gracefulShutdown params stateRef timersRef shutdownMv) @@ -191,7 +191,7 @@ robotMain dataDownloadDelta defaultState initCallback callback = do storeState params stateRef timersRef debugM "main" "Starting strategy driver" - barStrategyDriver (sourceBarTimeframe params) tickFilter strategy stateRef timersRef shutdownMv `finally` killThread stateSavingThread + barStrategyDriver (sourceBarTimeframe params) tickFilter strategy configRef stateRef timersRef shutdownMv `finally` killThread stateSavingThread where tickFilter :: Tick -> Bool tickFilter tick = @@ -293,8 +293,8 @@ mkBarStrategy instanceParams dd params initialState cb = BarStrategy { -- | Main function which handles incoming events (ticks/orders), passes them to strategy callback -- and executes returned strategy actions -barStrategyDriver :: Maybe Int -> (Tick -> Bool) -> Strategy c s -> IORef s -> IORef [UTCTime] -> MVar () -> IO () -barStrategyDriver mbSourceTimeframe tickFilter strategy stateRef timersRef shutdownVar = do +barStrategyDriver :: Maybe Int -> (Tick -> Bool) -> Strategy c s -> IORef c -> IORef s -> IORef [UTCTime] -> MVar () -> IO () +barStrategyDriver mbSourceTimeframe tickFilter strategy configRef stateRef timersRef shutdownVar = do -- Make channels -- Event channel is for strategy events, like new tick arrival, or order execution notification eventChan <- BC.newBoundedChan 1000 @@ -347,8 +347,8 @@ barStrategyDriver mbSourceTimeframe tickFilter strategy stateRef timersRef shutd if event /= Shutdown then do currentBars <- bars <$> readIORef agg - let params = strategyParams strategy' - let curState = currentState strategy' + params <- readIORef configRef + curState <- readIORef stateRef let instId = strategyInstanceId . strategyInstanceParams $ strategy' let acc = strategyAccount . strategyInstanceParams $ strategy' let vol = strategyVolume . strategyInstanceParams $ strategy'