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

2
src/ATrade/Driver/Junction.hs

@ -156,7 +156,7 @@ junctionMain descriptors = do @@ -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

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

@ -12,7 +12,7 @@ module ATrade.Driver.Junction.BrokerService @@ -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 @@ -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

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

@ -177,7 +177,7 @@ instance MonadRobot (RobotM c s) c s where @@ -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)

Loading…
Cancel
Save