From 4d82a19cc6b561b18fcd15f52fed04b677fec8bb Mon Sep 17 00:00:00 2001 From: Denis Tereshkin Date: Sun, 12 Dec 2021 18:46:51 +0700 Subject: [PATCH] junction: account configuration --- robocom-zero.cabal | 2 +- src/ATrade/Driver/Junction.hs | 4 ++-- src/ATrade/Driver/Junction/QuoteThread.hs | 12 +++++++----- src/ATrade/Driver/Junction/Types.hs | 1 + 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/robocom-zero.cabal b/robocom-zero.cabal index 2b91f61..04fd3b6 100644 --- a/robocom-zero.cabal +++ b/robocom-zero.cabal @@ -40,7 +40,7 @@ library , ATrade.Quotes.TickerInfoProvider other-modules: Paths_robocom_zero build-depends: base >= 4.7 && < 5 - , libatrade >= 0.11.0.0 && < 0.12.0.0 + , libatrade >= 0.12.0.0 && < 0.13.0.0 , text , text-icu , lens diff --git a/src/ATrade/Driver/Junction.hs b/src/ATrade/Driver/Junction.hs index f832c86..45276be 100644 --- a/src/ATrade/Driver/Junction.hs +++ b/src/ATrade/Driver/Junction.hs @@ -204,7 +204,7 @@ junctionMain descriptors = do ordersMap <- newIORef M.empty handledNotifications <- newIORef S.empty withBroker cfg ctx robotsMap ordersMap handledNotifications (logger h) $ \bro -> - withQThread downloaderEnv barsMap cfg ctx $ \qt -> do + withQThread downloaderEnv barsMap cfg ctx (logger h) $ \qt -> do broService <- mkBrokerService bro ordersMap let junctionLogAction = logger h let env = @@ -254,7 +254,7 @@ junctionMain descriptors = do stratEnv <- liftIO $ newIORef StrategyEnvironment { _seInstanceId = strategyId inst, - _seAccount = "test", -- TODO configure + _seAccount = accountId inst, _seVolume = 1, _seLastTimestamp = now } diff --git a/src/ATrade/Driver/Junction/QuoteThread.hs b/src/ATrade/Driver/Junction/QuoteThread.hs index bd3090f..baa5230 100644 --- a/src/ATrade/Driver/Junction/QuoteThread.hs +++ b/src/ATrade/Driver/Junction/QuoteThread.hs @@ -92,11 +92,12 @@ startQuoteThread :: (MonadIO m, T.Text -> ClientSecurityParams -> (m1 () -> IO ()) -> + LogAction IO Message -> m QuoteThreadHandle -startQuoteThread barsRef ctx ep secparams downloadThreadRunner = do +startQuoteThread barsRef ctx ep secparams downloadThreadRunner logger = do chan <- liftIO $ newBoundedChan 2000 dChan <- liftIO $ newBoundedChan 2000 - qsc <- liftIO $ startQuoteSourceClient chan [] ctx ep secparams + qsc <- liftIO $ startQuoteSourceClient chan [] ctx ep secparams logger env <- liftIO $ QuoteThreadEnv barsRef <$> newIORef HM.empty <*> pure qsc <*> newIORef M.empty <*> pure dChan tid <- liftIO . forkIO $ quoteThread env chan downloaderTid <- liftIO . forkIO $ downloadThreadRunner (downloaderThread env dChan) @@ -199,8 +200,8 @@ instance TickerInfoProvider DownloaderM where (fromInteger $ tiLotSize ti) (tiTickSize ti) -withQThread :: DownloaderEnv -> IORef Bars -> ProgramConfiguration -> Context -> (QuoteThreadHandle -> IO ()) -> IO () -withQThread env barsMap cfg ctx f = do +withQThread :: DownloaderEnv -> IORef Bars -> ProgramConfiguration -> Context -> LogAction IO Message -> (QuoteThreadHandle -> IO ()) -> IO () +withQThread env barsMap cfg ctx logger f = do securityParameters <- loadSecurityParameters bracket (startQuoteThread @@ -208,7 +209,8 @@ withQThread env barsMap cfg ctx f = do ctx (quotesourceEndpoint cfg) securityParameters - (runDownloaderM env)) + (runDownloaderM env) + logger) stopQuoteThread f where loadSecurityParameters = diff --git a/src/ATrade/Driver/Junction/Types.hs b/src/ATrade/Driver/Junction/Types.hs index d16f76e..8054daf 100644 --- a/src/ATrade/Driver/Junction/Types.hs +++ b/src/ATrade/Driver/Junction/Types.hs @@ -56,6 +56,7 @@ instance (FromDhall c) => FromDhall (BigConfig c) data StrategyInstanceDescriptor = StrategyInstanceDescriptor { + accountId :: T.Text, strategyId :: T.Text, strategyBaseName :: T.Text, configKey :: T.Text,