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 @@ -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 @@ -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

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

@ -94,6 +94,7 @@ data JunctionEnv = @@ -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 @@ -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

Loading…
Cancel
Save