From e2cdffc1f68cbf9b0bb7dbf41dee460c35fb636d Mon Sep 17 00:00:00 2001 From: Denis Tereshkin Date: Thu, 2 Dec 2021 21:27:13 +0700 Subject: [PATCH] junction: send getNotifications periodically --- src/ATrade/Driver/Junction.hs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ATrade/Driver/Junction.hs b/src/ATrade/Driver/Junction.hs index e482c71..a136ba6 100644 --- a/src/ATrade/Driver/Junction.hs +++ b/src/ATrade/Driver/Junction.hs @@ -15,9 +15,10 @@ import ATrade.Broker.Client (BrokerClientHandle startBrokerClient, stopBrokerClient) import ATrade.Broker.Protocol (Notification (OrderNotification, TradeNotification), - NotificationSqnum, + NotificationSqnum (unNotificationSqnum), getNotificationSqnum) import ATrade.Driver.Junction.BrokerService (BrokerService, + getNotifications, mkBrokerService) import ATrade.Driver.Junction.ProgramConfiguration (ProgramConfiguration (..), ProgramOptions (ProgramOptions, configPath)) @@ -214,8 +215,10 @@ junctionMain descriptors = do withJunction env $ do startRobots h cfg barsMap broService forever $ do + notifications <- liftIO $ getNotifications broService + forM_ notifications (liftIO . handleBrokerNotification robotsMap ordersMap handledNotifications (logger h)) saveRobots - liftIO $ threadDelay 5000000 + liftIO $ threadDelay 1000000 where saveRobots :: JunctionM () saveRobots = do @@ -264,7 +267,7 @@ junctionMain descriptors = do Notification -> IO () handleBrokerNotification robotsRef ordersMapRef handled logger notification= do - logWith logger Trace "Junction" $ "Incoming notification: " <> (T.pack . show) notification + logWith logger Trace "Junction" $ "Incoming notification: " <> (T.pack . show . unNotificationSqnum . getNotificationSqnum) notification whenM (notMember (getNotificationSqnum notification) <$> readIORef handled) $ do robotsMap <- readIORef robotsRef ordersMap <- readIORef ordersMapRef