Browse Source

Junction: log errors from BrokerClient

master
Denis Tereshkin 2 years ago
parent
commit
4d596709c1
  1. 2
      robocom-zero.cabal
  2. 2
      src/ATrade/Driver/Junction.hs
  3. 22
      src/ATrade/Driver/Junction/BrokerService.hs
  4. 2
      src/ATrade/Driver/Junction/RobotDriverThread.hs

2
robocom-zero.cabal

@ -42,7 +42,7 @@ library
, ATrade.Driver.Junction.RemoteControl , ATrade.Driver.Junction.RemoteControl
, ATrade.Driver.Junction.JunctionMonad , ATrade.Driver.Junction.JunctionMonad
build-depends: base >= 4.7 && < 5 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
, text-icu , text-icu
, lens , lens

2
src/ATrade/Driver/Junction.hs

@ -156,7 +156,7 @@ junctionMain descriptors = do
withJunction env $ do withJunction env $ do
startRobots cfg startRobots cfg
forever $ do forever $ do
notifications <- liftIO $ getNotifications broService notifications <- getNotifications broService
forM_ notifications (liftIO . handleBrokerNotification robotsMap ordersMap handledNotifications globalLogger) forM_ notifications (liftIO . handleBrokerNotification robotsMap ordersMap handledNotifications globalLogger)
saveRobots saveRobots
handleRemoteControl 1000 handleRemoteControl 1000

22
src/ATrade/Driver/Junction/BrokerService.hs

@ -12,7 +12,7 @@ module ATrade.Driver.Junction.BrokerService
import qualified ATrade.Broker.Client as Bro import qualified ATrade.Broker.Client as Bro
import ATrade.Broker.Protocol (Notification (..)) import ATrade.Broker.Protocol (Notification (..))
import ATrade.Logging (Message, logDebug) import ATrade.Logging (Message, logDebug, logWarning)
import ATrade.Types (Order (..), OrderId) import ATrade.Types (Order (..), OrderId)
import Colog (WithLog) import Colog (WithLog)
import Control.Monad.IO.Class (MonadIO (liftIO)) import Control.Monad.IO.Class (MonadIO (liftIO))
@ -38,19 +38,27 @@ submitOrder service identity order = do
oid <- nextOrderId service oid <- nextOrderId service
logDebug "BrokerService" $ "New order, id: " <> (T.pack . show) oid logDebug "BrokerService" $ "New order, id: " <> (T.pack . show) oid
liftIO $ atomicModifyIORef' (orderMap service) (\s -> (M.insert oid identity s, ())) 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 return oid
where where
nextOrderId srv = liftIO $ atomicModifyIORef' (orderIdCounter srv) (\s -> (s + 1, s)) 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 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 () return ()
getNotifications :: BrokerService -> IO [Notification] getNotifications :: (MonadIO m, WithLog env Message m) => BrokerService -> m [Notification]
getNotifications service = do getNotifications service = do
v <- Bro.getNotifications (broker service) v <- liftIO $ Bro.getNotifications (broker service)
case v of case v of
Left _ -> return [] Left err -> do
logWarning "BrokerServer" $ "Submit order error: " <> err
return []
Right n -> return n Right n -> return n

2
src/ATrade/Driver/Junction/RobotDriverThread.hs

@ -177,7 +177,7 @@ instance MonadRobot (RobotM c s) c s where
cancelOrder oid = do cancelOrder oid = do
bro <- asks brokerService bro <- asks brokerService
liftIO . void $ Bro.cancelOrder bro oid Bro.cancelOrder bro oid
appendToLog s t = do appendToLog s t = do
instId <- _seInstanceId <$> (asks env >>= liftIO . readIORef) instId <- _seInstanceId <$> (asks env >>= liftIO . readIORef)

Loading…
Cancel
Save