current state

This commit is contained in:
2022-07-18 17:50:28 +02:00
parent befb1ab1eb
commit 80b5f09d95
11 changed files with 158 additions and 223 deletions

View File

@ -22,7 +22,7 @@ data FillerException = QuitFiller
instance Exception FillerException
deriving via Integer instance Hashable Day
--deriving via Integer instance Hashable Day
newChart :: IBContract -> RIO App ()
newChart contract = do

View File

@ -11,11 +11,12 @@ import Data.Aeson (encodeFile)
import Data.Bits
import Data.FingerTree (ViewL(..), ViewR(..), viewl, viewr, split, FingerTree)
import DearImGui
import DearImGui.Plot
import DearImGui.OpenGL3
import DearImGui.GLFW
import DearImGui.SDL
import Graphics.GL
import SDL
import Data.StateVar
import qualified Graphics.UI.GLFW as GLFW
import qualified Data.Text as T
import qualified Data.HashMap.Strict as HM
import qualified Data.FingerTree as FT
@ -30,29 +31,42 @@ run = do
-- close connections to IB
shutdownApp :: RIO App ()
shutdownApp = do
win <- appWindow <$> ask
-- save settings & config
(V2 w h) <- liftIO $ get $ windowSize win
settings <- appSettings <$> ask
refs <- appRefs <$> ask
host' <- liftIO . readTVarIO . twsConnectionRefsHost . twsConnectionRefs $ refs
port' <- liftIO . readTVarIO . twsConnectionRefsPort . twsConnectionRefs $ refs
let settings' = settings & windowParams . windowWidth .~ fromIntegral w
& windowParams . windowHeight .~ fromIntegral h
& twsConnection . host .~ T.pack host'
& twsConnection . port .~ T.pack port'
liftIO $ encodeFile "settings.json" settings'
logInfo $ display ("Settings Saved" :: Text)
-- save cached data
logInfo $ display $ T.pack $ ppShow settings'
renderLoop :: RIO App ()
renderLoop = do
win <- appWindow <$> ask
liftIO GLFW.pollEvents
close <- liftIO $ GLFW.windowShouldClose win
let checkEvents = do
pollEventWithImGui >>= \case
Nothing ->
return False
Just event ->
(isQuit event ||) <$> checkEvents
isQuit event =
SDL.eventPayload event == SDL.QuitEvent
close <- liftIO checkEvents
if close
then do
-- save settings & config
(w,h) <- liftIO $ GLFW.getWindowSize win
settings <- appSettings <$> ask
refs <- appRefs <$> ask
host' <- liftIO . readTVarIO . twsConnectionRefsHost . twsConnectionRefs $ refs
port' <- liftIO . readTVarIO . twsConnectionRefsPort . twsConnectionRefs $ refs
let settings' = settings & windowParams . windowWidth .~ w
& windowParams . windowHeight .~ h
& twsConnection . host .~ T.pack host'
& twsConnection . port .~ T.pack port'
liftIO $ encodeFile "settings.json" settings'
logInfo $ display ("Settings Saved" :: Text)
-- save cached data
logInfo $ display $ T.pack $ ppShow settings'
then shutdownApp
else do
refs' <- appRefs <$> ask
data' <- appData <$> ask
@ -61,7 +75,7 @@ renderLoop = do
-- Tell ImGui we're starting a new frame
liftIO $ do
openGL3NewFrame
glfwNewFrame
sdl2NewFrame
newFrame
@ -70,7 +84,7 @@ renderLoop = do
withMenuOpen "File" $ do
menuItem "Quit" >>= \case
False -> return ()
True -> liftIO $ GLFW.setWindowShouldClose win True
True -> shutdownApp
let cr = twsConnectionRefs refs'
accs <- fmap HM.keys $ liftIO $ readTVarIO $ Types.accounts data'
withComboOpen "Account" (maybe "Select account" T.unpack selectedAccount) $ do
@ -146,12 +160,12 @@ renderLoop = do
forM_ ((accs HM.! aid) ^.. accountPortfolio . traverse) $ \(IBPortfolioValue c p mp mv ac up rp) ->
do
tableNextRow
whenM tableNextColumn (text $ T.unpack $ localSymbol c)
whenM tableNextColumn (text $ show p)
whenM tableNextColumn (text $ show up)
whenM tableNextColumn (text $ show rp)
whenM tableNextColumn (text $ show mp)
whenM tableNextColumn (text $ show mv)
tableNextColumn $ text $ T.unpack $ localSymbol c
tableNextColumn $ text $ show p
tableNextColumn $ text $ show up
tableNextColumn $ text $ show rp
tableNextColumn $ text $ show mp
tableNextColumn $ text $ show mv
bracket_ (begin "Search Symbols") end $ do
readTVarIO (currentAccount refs') >>= \case
@ -177,7 +191,7 @@ renderLoop = do
tableSetupColumn "Primary exchange"
tableSetupColumn "Currency"
tableSetupColumn "Available derivatives"
withSortableTable $ \(mustSort, sortSpecs) -> do
withSortableTable $ \mustSort sortSpecs -> do
when mustSort $ liftIO $ pPrint sortSpecs
tableHeadersRow
lResult <- readTVarIO $ symbolLookupResults data'
@ -190,9 +204,9 @@ renderLoop = do
True -> do
logInfo $ display $ "new chart open for: " <> _symbol
newChart $ def { conId = _symbolId, symbol = _symbol, secType = _secType, exchange = "SMART", primaryExchange = _primaryExchange, currency = _currency}
let printDatum x = whenM tableNextColumn $ text $ T.unpack x
let printDatum x = tableNextColumn $ text $ T.unpack x
tableNextRow
whenM tableNextColumn $ do
tableNextColumn $ do
void $ selectableWith (defSelectableOptions { flags = ImGuiSelectableFlags_SpanAllColumns }) (T.unpack _symbol)
openPopupOnItemClick popupName ImGuiPopupFlags_MouseButtonRight
printDatum _secType
@ -217,7 +231,7 @@ renderLoop = do
showDemoWindow
-- Show the ImPlot demo window
--showPlotDemoWindow
showPlotDemoWindow
-- Render
liftIO $ glClear GL_COLOR_BUFFER_BIT
@ -225,6 +239,6 @@ renderLoop = do
render
liftIO $ openGL3RenderDrawData =<< getDrawData
liftIO $ GLFW.swapBuffers win
liftIO $ glSwapWindow win
renderLoop

View File

@ -18,7 +18,7 @@ import Data.Time
import Data.FingerTree
import Data.Semigroup
import GHC.Generics
import Graphics.UI.GLFW (Window)
import SDL (Window)
import DearImGui
import RIO
import RIO.Process