Browse Source

junction: send getNotifications periodically

junction
Denis Tereshkin 4 years ago
parent
commit
e2cdffc1f6
  1. 9
      src/ATrade/Driver/Junction.hs

9
src/ATrade/Driver/Junction.hs

@ -15,9 +15,10 @@ import ATrade.Broker.Client (BrokerClientHandle
startBrokerClient, startBrokerClient,
stopBrokerClient) stopBrokerClient)
import ATrade.Broker.Protocol (Notification (OrderNotification, TradeNotification), import ATrade.Broker.Protocol (Notification (OrderNotification, TradeNotification),
NotificationSqnum, NotificationSqnum (unNotificationSqnum),
getNotificationSqnum) getNotificationSqnum)
import ATrade.Driver.Junction.BrokerService (BrokerService, import ATrade.Driver.Junction.BrokerService (BrokerService,
getNotifications,
mkBrokerService) mkBrokerService)
import ATrade.Driver.Junction.ProgramConfiguration (ProgramConfiguration (..), import ATrade.Driver.Junction.ProgramConfiguration (ProgramConfiguration (..),
ProgramOptions (ProgramOptions, configPath)) ProgramOptions (ProgramOptions, configPath))
@ -214,8 +215,10 @@ junctionMain descriptors = do
withJunction env $ do withJunction env $ do
startRobots h cfg barsMap broService startRobots h cfg barsMap broService
forever $ do forever $ do
notifications <- liftIO $ getNotifications broService
forM_ notifications (liftIO . handleBrokerNotification robotsMap ordersMap handledNotifications (logger h))
saveRobots saveRobots
liftIO $ threadDelay 5000000 liftIO $ threadDelay 1000000
where where
saveRobots :: JunctionM () saveRobots :: JunctionM ()
saveRobots = do saveRobots = do
@ -264,7 +267,7 @@ junctionMain descriptors = do
Notification -> Notification ->
IO () IO ()
handleBrokerNotification robotsRef ordersMapRef handled logger notification= do 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 whenM (notMember (getNotificationSqnum notification) <$> readIORef handled) $ do
robotsMap <- readIORef robotsRef robotsMap <- readIORef robotsRef
ordersMap <- readIORef ordersMapRef ordersMap <- readIORef ordersMapRef

Loading…
Cancel
Save