Skip to content

Commit

Permalink
Allow show/hide closed positions (#65)
Browse files Browse the repository at this point in the history
* Add config option to show closed positions.

* Add menu item toggle to show/hide closed positions.
  • Loading branch information
krazkidd authored Jul 22, 2024
1 parent c8c9dd7 commit ebca9e1
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 5 deletions.
5 changes: 5 additions & 0 deletions include/config/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace kdeck
DTO_FIELD(String, KalshiApiUrl);

Check warning on line 25 in include/config/Config.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

include/config/Config.hpp:25:13 [modernize-use-trailing-return-type]

use a trailing return type for this function
DTO_FIELD(String, SslTrustStoreDir);

Check warning on line 26 in include/config/Config.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

include/config/Config.hpp:26:13 [modernize-use-trailing-return-type]

use a trailing return type for this function
DTO_FIELD(String, Email);

Check warning on line 27 in include/config/Config.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

include/config/Config.hpp:27:13 [modernize-use-trailing-return-type]

use a trailing return type for this function
DTO_FIELD(Boolean, ShowClosedPositions);

Check warning on line 28 in include/config/Config.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

include/config/Config.hpp:28:13 [modernize-use-trailing-return-type]

use a trailing return type for this function

};

Expand All @@ -43,8 +44,12 @@ namespace kdeck

std::string GetEmail() const;

Check warning on line 45 in include/config/Config.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

include/config/Config.hpp:45:21 [modernize-use-trailing-return-type]

use a trailing return type for this function

bool GetShowClosedPositions() const;

Check warning on line 47 in include/config/Config.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

include/config/Config.hpp:47:14 [modernize-use-trailing-return-type]

use a trailing return type for this function

void SetEmail(std::string email);

void SetShowClosedPositions(bool doShow);

private:
static constexpr int32_t kConfigVersion = 1;
static constexpr std::string_view kConfigFilename = "config.json";
Expand Down
4 changes: 3 additions & 1 deletion include/ui/MainFrame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,6 +35,7 @@ namespace kdeck

wxMenuItem *mnuLogin;
wxMenuItem *mnuLogout;
wxMenuItem *mnuShowClosedPositions;

PortfolioPanel* pnlPortfolio;

Expand Down
3 changes: 2 additions & 1 deletion include/ui/PortfolioPanel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions src/config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::UserConfig> Config::MakeDefaultConfig()
{
auto config = UserConfig::createShared();
Expand All @@ -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();
}
Expand Down
20 changes: 19 additions & 1 deletion src/ui/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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 ////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 12 additions & 1 deletion src/ui/PortfolioPanel.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <wx/wx.h>

Check notice on line 1 in src/ui/PortfolioPanel.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on src/ui/PortfolioPanel.cpp

File src/ui/PortfolioPanel.cpp does not conform to LLVM style guidelines. (lines 3, 11, 12, 13, 14, 16, 17, 18, 19, 20, 22, 23, 25, 26, 27, 29, 31, 33, 35, 36, 38, 39, 40, 42, 43, 44, 46, 48, 49, 50, 51, 52, 54, 56, 58, 59, 60, 61, 62, 63, 65, 67, 68, 69, 70, 71, 72, 74, 75, 76, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 89)

Check failure on line 1 in src/ui/PortfolioPanel.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

src/ui/PortfolioPanel.cpp:1:10 [clang-diagnostic-error]

'wx/wx.h' file not found

#include "api/Api.hpp"
#include "config/Config.hpp"
#include "ui/BalancePanel.hpp"
#include "ui/PortfolioPanel.hpp"
#include "ui/EventPositionPanel.hpp"
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}
}
Expand Down
3 changes: 2 additions & 1 deletion utils/config.json.example
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit ebca9e1

Please sign in to comment.