diff --git a/robocom-zero.cabal b/robocom-zero.cabal index 1cf364c..790315b 100644 --- a/robocom-zero.cabal +++ b/robocom-zero.cabal @@ -42,7 +42,7 @@ library , ATrade.Driver.Junction.RemoteControl , ATrade.Driver.Junction.JunctionMonad build-depends: base >= 4.7 && < 5 - , libatrade >= 0.13.0.0 && < 0.14.0.0 + , libatrade >= 0.15.0.0 && < 0.16.0.0 , text , text-icu , lens diff --git a/src/ATrade/Driver/Junction.hs b/src/ATrade/Driver/Junction.hs index b5de445..8ddebb1 100644 --- a/src/ATrade/Driver/Junction.hs +++ b/src/ATrade/Driver/Junction.hs @@ -156,7 +156,7 @@ junctionMain descriptors = do withJunction env $ do startRobots cfg forever $ do - notifications <- liftIO $ getNotifications broService + notifications <- getNotifications broService forM_ notifications (liftIO . handleBrokerNotification robotsMap ordersMap handledNotifications globalLogger) saveRobots handleRemoteControl 1000 diff --git a/src/ATrade/Driver/Junction/BrokerService.hs b/src/ATrade/Driver/Junction/BrokerService.hs index a03f085..ab07ba0 100644 --- a/src/ATrade/Driver/Junction/BrokerService.hs +++ b/src/ATrade/Driver/Junction/BrokerService.hs @@ -12,7 +12,7 @@ module ATrade.Driver.Junction.BrokerService import qualified ATrade.Broker.Client as Bro import ATrade.Broker.Protocol (Notification (..)) -import ATrade.Logging (Message, logDebug) +import ATrade.Logging (Message, logDebug, logWarning) import ATrade.Types (Order (..), OrderId) import Colog (WithLog) import Control.Monad.IO.Class (MonadIO (liftIO)) @@ -38,19 +38,27 @@ submitOrder service identity order = do oid <- nextOrderId service logDebug "BrokerService" $ "New order, id: " <> (T.pack . show) oid liftIO $ atomicModifyIORef' (orderMap service) (\s -> (M.insert oid identity s, ())) - _ <- liftIO $ Bro.submitOrder (broker service) order { orderId = oid } + r <- liftIO $ Bro.submitOrder (broker service) order { orderId = oid } + case r of + Left err -> logWarning "BrokerServer" $ "Submit order error: " <> err + _ -> return () return oid where nextOrderId srv = liftIO $ atomicModifyIORef' (orderIdCounter srv) (\s -> (s + 1, s)) -cancelOrder :: BrokerService -> OrderId -> IO () +cancelOrder :: (MonadIO m, WithLog env Message m) => BrokerService -> OrderId -> m () cancelOrder service oid = do - _ <- Bro.cancelOrder (broker service) oid + r <- liftIO $ Bro.cancelOrder (broker service) oid + case r of + Left err -> logWarning "BrokerServer" $ "Submit order error: " <> err + _ -> return () return () -getNotifications :: BrokerService -> IO [Notification] +getNotifications :: (MonadIO m, WithLog env Message m) => BrokerService -> m [Notification] getNotifications service = do - v <- Bro.getNotifications (broker service) + v <- liftIO $ Bro.getNotifications (broker service) case v of - Left _ -> return [] + Left err -> do + logWarning "BrokerServer" $ "Submit order error: " <> err + return [] Right n -> return n diff --git a/src/ATrade/Driver/Junction/RobotDriverThread.hs b/src/ATrade/Driver/Junction/RobotDriverThread.hs index f3ff50c..0bb526a 100644 --- a/src/ATrade/Driver/Junction/RobotDriverThread.hs +++ b/src/ATrade/Driver/Junction/RobotDriverThread.hs @@ -177,7 +177,7 @@ instance MonadRobot (RobotM c s) c s where cancelOrder oid = do bro <- asks brokerService - liftIO . void $ Bro.cancelOrder bro oid + Bro.cancelOrder bro oid appendToLog s t = do instId <- _seInstanceId <$> (asks env >>= liftIO . readIORef)