You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
3.7 KiB
76 lines
3.7 KiB
|
|
module Main (main) where |
|
|
|
import ATrade (libatrade_gitrev, |
|
libatrade_version) |
|
import ATrade.Broker.Protocol (NotificationSqnum (NotificationSqnum)) |
|
import ATrade.Broker.Server (startBrokerServer, |
|
stopBrokerServer) |
|
import ATrade.Logging (Message (..), Severity (Info), |
|
logWith) |
|
import ATrade.Logging (fmtMessage) |
|
import ATrade.QuoteSource.Server (startQuoteSourceServer, |
|
stopQuoteSourceServer) |
|
import ATrade.Types (defaultServerSecurityParams) |
|
import Colog (LogAction, logTextStdout, |
|
(>$<)) |
|
import Colog.Actions (logTextHandle) |
|
import Config (TransaqConnectorConfig (..), |
|
loadConfig) |
|
import Control.Concurrent (threadDelay) |
|
import Control.Concurrent.BoundedChan (newBoundedChan) |
|
import Control.Exception (bracket) |
|
import Control.Monad (forever, void) |
|
import Control.Monad.IO.Class (MonadIO) |
|
import qualified Data.Text as T |
|
import Data.Version (showVersion) |
|
import Debug.EventCounters (initEventCounters) |
|
import HistoryProviderServer (withHistoryProviderServer) |
|
import Prelude hiding (log) |
|
import System.IO (Handle, IOMode (AppendMode), |
|
withFile) |
|
import System.ZMQ4 (withContext) |
|
import TickerInfoServer (withTickerInfoServer) |
|
import qualified TXMLConnector as Connector |
|
import Version (transaqConnectorVersionText) |
|
|
|
mkLogger :: (MonadIO m) => Handle -> LogAction m Message |
|
mkLogger h = fmtMessage >$< (logTextStdout <> logTextHandle h) |
|
|
|
main :: IO () |
|
main = do |
|
initEventCounters |
|
cfg <- loadConfig "transaq-connector.dhall" |
|
withFile "transaq-connector.log" AppendMode $ \logH -> do |
|
let logger = mkLogger logH |
|
let log = logWith logger |
|
log Info "main" $ "Starting transaq-connector-" <> |
|
transaqConnectorVersionText <> |
|
"; libatrade-" <> |
|
(T.pack . showVersion) libatrade_version <> |
|
"(" <> |
|
T.pack libatrade_gitrev <> |
|
")" |
|
void $ withContext $ \ctx -> do |
|
qssChannel <- newBoundedChan 50000 |
|
bracket (startQuoteSourceServer |
|
qssChannel |
|
ctx |
|
(quotesourceEndpoint cfg) |
|
defaultServerSecurityParams) |
|
stopQuoteSourceServer $ \_ -> withTickerInfoServer logger ctx (tisEndpoint cfg) $ \tisH -> do |
|
txml <- Connector.start logger cfg qssChannel tisH |
|
bracket (startBrokerServer |
|
[Connector.makeBrokerBackend txml (account cfg)] |
|
ctx |
|
(brokerEndpoint cfg) |
|
(brokerNotificationsEndpoint cfg) |
|
(NotificationSqnum 1) |
|
[] |
|
defaultServerSecurityParams |
|
logger) stopBrokerServer $ \_ -> do |
|
withHistoryProviderServer ctx (historyProviderEndpoint cfg) txml logger id $ \_ -> do |
|
forever $ threadDelay 1000000 |
|
log Info "main" "Shutting down" |
|
|
|
|
|
|