|
|
|
|
@ -7,16 +7,17 @@ import Brick.Main
@@ -7,16 +7,17 @@ import Brick.Main
|
|
|
|
|
import Brick.Types |
|
|
|
|
import Brick.Widgets.Border |
|
|
|
|
import Brick.Widgets.Core |
|
|
|
|
import Colog |
|
|
|
|
import Control.Concurrent |
|
|
|
|
import qualified Control.Concurrent.BoundedChan as BC |
|
|
|
|
import Control.Concurrent.BoundedChan qualified as BC |
|
|
|
|
import Control.Exception |
|
|
|
|
import Control.Monad |
|
|
|
|
import Data.Aeson |
|
|
|
|
import qualified Data.ByteString.Lazy as B |
|
|
|
|
import Data.ByteString.Lazy qualified as B |
|
|
|
|
import Data.IORef |
|
|
|
|
import qualified Data.List as L |
|
|
|
|
import qualified Data.Map.Strict as M |
|
|
|
|
import qualified Graphics.Vty as Vty |
|
|
|
|
import Data.List qualified as L |
|
|
|
|
import Data.Map.Strict qualified as M |
|
|
|
|
import Graphics.Vty qualified as Vty |
|
|
|
|
import Lens.Micro.Platform |
|
|
|
|
import Lens.Micro.TH |
|
|
|
|
import System.ZMQ4 |
|
|
|
|
@ -27,27 +28,35 @@ import ATrade.Types
@@ -27,27 +28,35 @@ import ATrade.Types
|
|
|
|
|
import Config |
|
|
|
|
import QuoteTable |
|
|
|
|
|
|
|
|
|
data Name = Viewport1 |
|
|
|
|
deriving (Show, Eq, Ord) |
|
|
|
|
data Name = Viewport1 deriving (Eq, Ord, Show) |
|
|
|
|
|
|
|
|
|
data AppEvent = QuoteTableUpdate QuoteTable |
|
|
|
|
data AppEvent |
|
|
|
|
= QuoteTableUpdate QuoteTable |
|
|
|
|
|
|
|
|
|
data AppState = AppState { |
|
|
|
|
_quotes :: QuoteTable |
|
|
|
|
} |
|
|
|
|
data AppState |
|
|
|
|
= AppState |
|
|
|
|
{ _quotes :: QuoteTable |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
makeLenses ''AppState |
|
|
|
|
|
|
|
|
|
qsThread :: IORef QuoteTable -> AppConfig -> IO () |
|
|
|
|
qsThread quotetable config = withContext $ \ctx -> do |
|
|
|
|
qschan <- BC.newBoundedChan 1000 |
|
|
|
|
bracket (startQuoteSourceClient qschan (config ^. tickers) ctx (config ^. quoteSourceEndpoint) defaultClientSecurityParams) stopQuoteSourceClient $ \_ -> forever $ do |
|
|
|
|
bracket (startQuoteSourceClient |
|
|
|
|
qschan |
|
|
|
|
(config ^. tickers) |
|
|
|
|
ctx |
|
|
|
|
(config ^. quoteSourceEndpoint) |
|
|
|
|
defaultClientSecurityParams |
|
|
|
|
emptyLogAction) stopQuoteSourceClient $ \_ -> forever $ do |
|
|
|
|
qsdata <- BC.readChan qschan |
|
|
|
|
case qsdata of |
|
|
|
|
QDTick tick -> handleNewTick quotetable tick |
|
|
|
|
_ -> return () |
|
|
|
|
where |
|
|
|
|
handleNewTick s t = atomicModifyIORef s $ \table -> (updateTable table t, ()) |
|
|
|
|
emptyLogAction = LogAction (\_ -> return ()) |
|
|
|
|
|
|
|
|
|
quoteTableWriterThread :: IORef QuoteTable -> BChan AppEvent -> IO () |
|
|
|
|
quoteTableWriterThread qtRef chan = forever $ do |
|
|
|
|
@ -75,7 +84,7 @@ main = do
@@ -75,7 +84,7 @@ main = do
|
|
|
|
|
initialVty <- buildVty |
|
|
|
|
qsThreadId <- forkIO $ qsThread quoteTableRef config |
|
|
|
|
qtwThreadId <- forkIO $ quoteTableWriterThread quoteTableRef eventChan |
|
|
|
|
void $ customMain buildVty (Just eventChan) app (initialState M.empty) |
|
|
|
|
void $ customMain initialVty buildVty (Just eventChan) app (initialState M.empty) |
|
|
|
|
where |
|
|
|
|
initialState ref = AppState ref |
|
|
|
|
draw :: AppState -> [Widget Name] |
|
|
|
|
|