diff --git a/include/config/Config.hpp b/include/config/Config.hpp index 966d3da..fb42671 100644 --- a/include/config/Config.hpp +++ b/include/config/Config.hpp @@ -25,6 +25,7 @@ namespace kdeck DTO_FIELD(String, KalshiApiUrl); DTO_FIELD(String, SslTrustStoreDir); DTO_FIELD(String, Email); + DTO_FIELD(Boolean, ShowClosedPositions); }; @@ -43,8 +44,12 @@ namespace kdeck std::string GetEmail() const; + bool GetShowClosedPositions() const; + void SetEmail(std::string email); + void SetShowClosedPositions(bool doShow); + private: static constexpr int32_t kConfigVersion = 1; static constexpr std::string_view kConfigFilename = "config.json"; diff --git a/include/ui/MainFrame.hpp b/include/ui/MainFrame.hpp index a9cb86b..b7ce182 100644 --- a/include/ui/MainFrame.hpp +++ b/include/ui/MainFrame.hpp @@ -17,7 +17,8 @@ namespace kdeck ID_Logout = wxID_HIGHEST + 2, ID_Exchange_Announcements = wxID_HIGHEST + 3, ID_Exchange_Schedule = wxID_HIGHEST + 4, - ID_Exchange_Status = wxID_HIGHEST + 5 + ID_Exchange_Status = wxID_HIGHEST + 5, + ID_View_ShowClosedPositions = wxID_HIGHEST + 6, }; class MainFrame : public wxFrame @@ -34,6 +35,7 @@ namespace kdeck wxMenuItem *mnuLogin; wxMenuItem *mnuLogout; + wxMenuItem *mnuShowClosedPositions; PortfolioPanel* pnlPortfolio; diff --git a/include/ui/PortfolioPanel.hpp b/include/ui/PortfolioPanel.hpp index c6cfc4a..18f3fb6 100644 --- a/include/ui/PortfolioPanel.hpp +++ b/include/ui/PortfolioPanel.hpp @@ -7,13 +7,14 @@ namespace kdeck { class Api; class BalancePanel; + class Config; class PortfolioPanel : public wxScrolledWindow { public: PortfolioPanel(wxWindow* parent, wxWindowID winid = wxID_ANY); - void UpdateStuff(Api* api); + void UpdateStuff(const Config* config, Api* api); private: BalancePanel* pnlBalance; diff --git a/src/config/Config.cpp b/src/config/Config.cpp index efd3297..9a80278 100644 --- a/src/config/Config.cpp +++ b/src/config/Config.cpp @@ -141,11 +141,21 @@ namespace kdeck return m_activeConfig->Email ? m_activeConfig->Email->c_str() : m_defaultConfig->Email->c_str(); } + bool Config::GetShowClosedPositions() const + { + return m_activeConfig->ShowClosedPositions ? m_activeConfig->ShowClosedPositions : m_defaultConfig->ShowClosedPositions; + } + void Config::SetEmail(std::string email) { m_activeConfig->Email = oatpp::String{email}; } + void Config::SetShowClosedPositions(bool doShow) + { + m_activeConfig->ShowClosedPositions = doShow; + } + std::shared_ptr Config::MakeDefaultConfig() { auto config = UserConfig::createShared(); @@ -154,6 +164,7 @@ namespace kdeck config->KalshiApiUrl = std::string{kKalshiApiUrl}; config->SslTrustStoreDir = std::string{kSslTrustStoreDir}; config->Email = std::string{}; + config->ShowClosedPositions = false; return config.getPtr(); } diff --git a/src/ui/MainFrame.cpp b/src/ui/MainFrame.cpp index 40d1de0..993db75 100644 --- a/src/ui/MainFrame.cpp +++ b/src/ui/MainFrame.cpp @@ -55,6 +55,14 @@ namespace kdeck /////////////////////////////////////////////////////////////////////////// + wxMenu *menuView = new wxMenu; + + mnuShowClosedPositions = menuView->AppendCheckItem(ID_View_ShowClosedPositions, "Show Closed Positions", "Show Closed Positions"); + + mnuShowClosedPositions->Enable(false); + + /////////////////////////////////////////////////////////////////////////// + wxMenu *menuHelp = new wxMenu; menuHelp->Append(wxID_ABOUT); @@ -63,6 +71,7 @@ namespace kdeck wxMenuBar *menuBar = new wxMenuBar; menuBar->Append(menuFile, "&File"); menuBar->Append(menuExchange, "&Exchange"); + menuBar->Append(menuView, "&View"); menuBar->Append(menuHelp, "&Help"); SetMenuBar(menuBar); @@ -87,10 +96,13 @@ namespace kdeck void MainFrame::UpdateStuff() { - pnlPortfolio->UpdateStuff(&api); + pnlPortfolio->UpdateStuff(&config, &api); mnuLogin->Enable(!api.IsLoggedIn()); mnuLogout->Enable(api.IsLoggedIn()); + + mnuShowClosedPositions->Enable(api.IsLoggedIn()); + mnuShowClosedPositions->Check(config.GetShowClosedPositions()); } // helpers //////////////////////////////////////////////////////////////////// @@ -239,6 +251,12 @@ namespace kdeck case ID_Exchange_Status: DoShowExchangeStatus(); + break; + case ID_View_ShowClosedPositions: + config.SetShowClosedPositions(mnuShowClosedPositions->IsChecked()); + + UpdateStuff(); + break; case wxID_ABOUT: wxMessageBox(wxString::Format("%s v%s", kProjectName, kProjectVersion), wxString::Format("About %s", kProjectName), wxOK | wxICON_INFORMATION); diff --git a/src/ui/PortfolioPanel.cpp b/src/ui/PortfolioPanel.cpp index 6fa1922..aa6e42b 100644 --- a/src/ui/PortfolioPanel.cpp +++ b/src/ui/PortfolioPanel.cpp @@ -1,6 +1,7 @@ #include #include "api/Api.hpp" +#include "config/Config.hpp" #include "ui/BalancePanel.hpp" #include "ui/PortfolioPanel.hpp" #include "ui/EventPositionPanel.hpp" @@ -38,7 +39,7 @@ namespace kdeck SetScrollRate(10, 10); } - void PortfolioPanel::UpdateStuff(Api* api) + void PortfolioPanel::UpdateStuff(const Config* config, Api* api) { pnlBalance->UpdateStuff(api); @@ -56,10 +57,20 @@ namespace kdeck for (auto event : api->GetEventPositions()) { + if (0 == *event->event_exposure && !config->GetShowClosedPositions()) + { + continue; + } + boxSizer->Add(new EventPositionPanel(pnlPositions, wxID_ANY, event), flags); for (auto market : api->GetMarketPositions(*event->event_ticker)) { + if (0 == *market->market_exposure && !config->GetShowClosedPositions()) + { + continue; + } + boxSizer->Add(new MarketPositionPanel(pnlPositions, wxID_ANY, market), flags); } } diff --git a/utils/config.json.example b/utils/config.json.example index a8914bb..2c29784 100644 --- a/utils/config.json.example +++ b/utils/config.json.example @@ -1,5 +1,6 @@ { "Version": 1, "KalshiApiUrl": "https://demo-api.kalshi.co/trade-api/v2", - "SslTrustStoreDir": "/etc/ssl/certs" + "SslTrustStoreDir": "/etc/ssl/certs", + "ShowClosedPositions": false }