Browse Source

junction: startRobot refactoring

master
Denis Tereshkin 4 years ago
parent
commit
ac4785e5a0
  1. 9
      src/ATrade/Driver/Junction.hs
  2. 6
      src/ATrade/Driver/Junction/JunctionMonad.hs

9
src/ATrade/Driver/Junction.hs

@ -147,6 +147,7 @@ junctionMain descriptors = do
peRobots = robotsMap, peRobots = robotsMap,
peRemoteControlSocket = rcSocket, peRemoteControlSocket = rcSocket,
peLogAction = junctionLogAction, peLogAction = junctionLogAction,
peIoLogAction = globalLogger,
peProgramConfiguration = cfg, peProgramConfiguration = cfg,
peBarsMap = barsMap, peBarsMap = barsMap,
peTickerInfoMap = tickerInfoMap, peTickerInfoMap = tickerInfoMap,
@ -154,16 +155,16 @@ junctionMain descriptors = do
peDescriptors = descriptors peDescriptors = descriptors
} }
withJunction env $ do withJunction env $ do
startRobots (hoistLogAction liftIO globalLogger) cfg startRobots cfg
forever $ do forever $ do
notifications <- liftIO $ getNotifications broService notifications <- liftIO $ getNotifications broService
forM_ notifications (liftIO . handleBrokerNotification robotsMap ordersMap handledNotifications globalLogger) forM_ notifications (liftIO . handleBrokerNotification robotsMap ordersMap handledNotifications globalLogger)
saveRobots saveRobots
handleRemoteControl 1000000 handleRemoteControl 1000000
where where
startRobots :: LogAction IO Message -> ProgramConfiguration -> JunctionM () startRobots :: ProgramConfiguration -> JunctionM ()
startRobots gLogger cfg = forM_ (instances cfg) $ \inst -> do startRobots cfg = forM_ (instances cfg) $ \inst -> do
startRobot gLogger inst startRobot inst
withJunction :: JunctionEnv -> JunctionM () -> IO () withJunction :: JunctionEnv -> JunctionM () -> IO ()
withJunction env = (`runReaderT` env) . unJunctionM withJunction env = (`runReaderT` env) . unJunctionM

6
src/ATrade/Driver/Junction/JunctionMonad.hs

@ -94,6 +94,7 @@ data JunctionEnv =
peRobots :: IORef (M.Map T.Text RobotDriverHandle), peRobots :: IORef (M.Map T.Text RobotDriverHandle),
peRemoteControlSocket :: Socket Rep, peRemoteControlSocket :: Socket Rep,
peLogAction :: LogAction JunctionM Message, peLogAction :: LogAction JunctionM Message,
peIoLogAction :: LogAction IO Message,
peProgramConfiguration :: ProgramConfiguration, peProgramConfiguration :: ProgramConfiguration,
peBarsMap :: IORef Bars, peBarsMap :: IORef Bars,
peTickerInfoMap :: IORef TickerInfoMap, peTickerInfoMap :: IORef TickerInfoMap,
@ -151,8 +152,9 @@ instance QuoteStream JunctionM where
qt <- asks peQuoteThread qt <- asks peQuoteThread
QT.removeSubscription qt subId QT.removeSubscription qt subId
startRobot :: LogAction IO Message -> StrategyInstanceDescriptor -> JunctionM () startRobot :: StrategyInstanceDescriptor -> JunctionM ()
startRobot ioLogger inst = do startRobot inst = do
ioLogger <- asks peIoLogAction
descriptors <- asks peDescriptors descriptors <- asks peDescriptors
cfg <- asks peProgramConfiguration cfg <- asks peProgramConfiguration
barsMap <- asks peBarsMap barsMap <- asks peBarsMap

Loading…
Cancel
Save