From ac4785e5a0a59fe226a46a421a51d052f9c3b49a Mon Sep 17 00:00:00 2001 From: Denis Tereshkin Date: Tue, 4 Jan 2022 22:11:51 +0700 Subject: [PATCH] junction: startRobot refactoring --- src/ATrade/Driver/Junction.hs | 9 +++++---- src/ATrade/Driver/Junction/JunctionMonad.hs | 6 ++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/ATrade/Driver/Junction.hs b/src/ATrade/Driver/Junction.hs index f1eb142..127b57d 100644 --- a/src/ATrade/Driver/Junction.hs +++ b/src/ATrade/Driver/Junction.hs @@ -147,6 +147,7 @@ junctionMain descriptors = do peRobots = robotsMap, peRemoteControlSocket = rcSocket, peLogAction = junctionLogAction, + peIoLogAction = globalLogger, peProgramConfiguration = cfg, peBarsMap = barsMap, peTickerInfoMap = tickerInfoMap, @@ -154,16 +155,16 @@ junctionMain descriptors = do peDescriptors = descriptors } withJunction env $ do - startRobots (hoistLogAction liftIO globalLogger) cfg + startRobots cfg forever $ do notifications <- liftIO $ getNotifications broService forM_ notifications (liftIO . handleBrokerNotification robotsMap ordersMap handledNotifications globalLogger) saveRobots handleRemoteControl 1000000 where - startRobots :: LogAction IO Message -> ProgramConfiguration -> JunctionM () - startRobots gLogger cfg = forM_ (instances cfg) $ \inst -> do - startRobot gLogger inst + startRobots :: ProgramConfiguration -> JunctionM () + startRobots cfg = forM_ (instances cfg) $ \inst -> do + startRobot inst withJunction :: JunctionEnv -> JunctionM () -> IO () withJunction env = (`runReaderT` env) . unJunctionM diff --git a/src/ATrade/Driver/Junction/JunctionMonad.hs b/src/ATrade/Driver/Junction/JunctionMonad.hs index 173c142..22d0df9 100644 --- a/src/ATrade/Driver/Junction/JunctionMonad.hs +++ b/src/ATrade/Driver/Junction/JunctionMonad.hs @@ -94,6 +94,7 @@ data JunctionEnv = peRobots :: IORef (M.Map T.Text RobotDriverHandle), peRemoteControlSocket :: Socket Rep, peLogAction :: LogAction JunctionM Message, + peIoLogAction :: LogAction IO Message, peProgramConfiguration :: ProgramConfiguration, peBarsMap :: IORef Bars, peTickerInfoMap :: IORef TickerInfoMap, @@ -151,8 +152,9 @@ instance QuoteStream JunctionM where qt <- asks peQuoteThread QT.removeSubscription qt subId -startRobot :: LogAction IO Message -> StrategyInstanceDescriptor -> JunctionM () -startRobot ioLogger inst = do +startRobot :: StrategyInstanceDescriptor -> JunctionM () +startRobot inst = do + ioLogger <- asks peIoLogAction descriptors <- asks peDescriptors cfg <- asks peProgramConfiguration barsMap <- asks peBarsMap