Browse Source

Update for new libatrade

master
Denis Tereshkin 11 months ago
parent
commit
fefd0974d0
  1. 8
      src/ATrade/Driver/Junction.hs
  2. 6
      src/ATrade/Driver/Junction/BrokerService.hs
  3. 5
      src/ATrade/Driver/Junction/JunctionMonad.hs

8
src/ATrade/Driver/Junction.hs

@ -162,8 +162,7 @@ junctionMain descriptors = do
handleRemoteControl 1000 handleRemoteControl 1000
where where
startRobots :: ProgramConfiguration -> JunctionM () startRobots :: ProgramConfiguration -> JunctionM ()
startRobots cfg = forM_ (instances cfg) $ \inst -> do startRobots cfg = forM_ (instances cfg) startRobot
startRobot inst
withJunction :: JunctionEnv -> JunctionM () -> IO () withJunction :: JunctionEnv -> JunctionM () -> IO ()
withJunction env = (`runReaderT` env) . unJunctionM withJunction env = (`runReaderT` env) . unJunctionM
@ -200,12 +199,9 @@ junctionMain descriptors = do
securityParameters <- loadBrokerSecurityParameters cfg securityParameters <- loadBrokerSecurityParameters cfg
bracket bracket
(startBrokerClient (startBrokerClient
(encodeUtf8 $ brokerIdentity cfg) (brokerIdentity cfg)
ctx
(brokerEndpoint cfg) (brokerEndpoint cfg)
(brokerNotificationEndpoint cfg)
[handleBrokerNotification robotsMap ordersMap handled logger'] [handleBrokerNotification robotsMap ordersMap handled logger']
securityParameters
logger') logger')
stopBrokerClient f stopBrokerClient f

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

@ -40,7 +40,7 @@ submitOrder service identity order = do
liftIO $ atomicModifyIORef' (orderMap service) (\s -> (M.insert oid identity s, ())) liftIO $ atomicModifyIORef' (orderMap service) (\s -> (M.insert oid identity s, ()))
r <- liftIO $ Bro.submitOrder (broker service) order { orderId = oid } r <- liftIO $ Bro.submitOrder (broker service) order { orderId = oid }
case r of case r of
Left err -> logWarning "BrokerServer" $ "Submit order error: " <> err Left err -> logWarning "BrokerService" $ "Submit order error: " <> err
_ -> return () _ -> return ()
return oid return oid
where where
@ -50,7 +50,7 @@ cancelOrder :: (MonadIO m, WithLog env Message m) => BrokerService -> OrderId ->
cancelOrder service oid = do cancelOrder service oid = do
r <- liftIO $ Bro.cancelOrder (broker service) oid r <- liftIO $ Bro.cancelOrder (broker service) oid
case r of case r of
Left err -> logWarning "BrokerServer" $ "Submit order error: " <> err Left err -> logWarning "BrokerServer" $ "Cancel order error: " <> err
_ -> return () _ -> return ()
return () return ()
@ -59,6 +59,6 @@ getNotifications service = do
v <- liftIO $ Bro.getNotifications (broker service) v <- liftIO $ Bro.getNotifications (broker service)
case v of case v of
Left err -> do Left err -> do
logWarning "BrokerServer" $ "Submit order error: " <> err logWarning "BrokerServer" $ "Get notifications order error: " <> err
return [] return []
Right n -> return n Right n -> return n

5
src/ATrade/Driver/Junction/JunctionMonad.hs

@ -18,8 +18,7 @@ import ATrade.Broker.Client (BrokerClientHandle
import ATrade.Driver.Junction.BrokerService (BrokerService) import ATrade.Driver.Junction.BrokerService (BrokerService)
import ATrade.Driver.Junction.ProgramConfiguration (ProgramConfiguration (logBasePath)) import ATrade.Driver.Junction.ProgramConfiguration (ProgramConfiguration (logBasePath))
import ATrade.Driver.Junction.QuoteStream (QuoteStream (addSubscription, removeSubscription), import ATrade.Driver.Junction.QuoteStream (QuoteStream (addSubscription, removeSubscription),
QuoteSubscription (QuoteSubscription), QuoteSubscription (QuoteSubscription))
SubscriptionId (SubscriptionId))
import ATrade.Driver.Junction.QuoteThread (QuoteThreadHandle) import ATrade.Driver.Junction.QuoteThread (QuoteThreadHandle)
import qualified ATrade.Driver.Junction.QuoteThread as QT import qualified ATrade.Driver.Junction.QuoteThread as QT
import ATrade.Driver.Junction.RobotDriverThread (RobotDriverHandle, RobotEnv (RobotEnv), import ATrade.Driver.Junction.RobotDriverThread (RobotDriverHandle, RobotEnv (RobotEnv),
@ -89,9 +88,9 @@ import Prelude hiding (log,
readFile) readFile)
import System.IO (BufferMode (LineBuffering), import System.IO (BufferMode (LineBuffering),
IOMode (AppendMode), IOMode (AppendMode),
hClose,
hSetBuffering, hSetBuffering,
openFile) openFile)
import System.IO (hClose)
import System.ZMQ4 (Router, Socket) import System.ZMQ4 (Router, Socket)
import UnliftIO (MonadUnliftIO) import UnliftIO (MonadUnliftIO)
import UnliftIO.Exception (catchAny, import UnliftIO.Exception (catchAny,

Loading…
Cancel
Save