Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow show/hide closed positions #65

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/config/Config.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef CONFIG_HPP

Check notice on line 1 in include/config/Config.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on include/config/Config.hpp

File include/config/Config.hpp does not conform to LLVM style guidelines. (lines 8, 12, 13, 14, 15, 16, 18, 19, 20, 22, 24, 25, 26, 27, 28, 30, 32, 34, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 54, 55, 57, 59, 61, 62, 64, 66)
#define CONFIG_HPP

#include <memory>
#include <string>
#include <string_view>

#include "oatpp/core/Types.hpp"

Check failure on line 8 in include/config/Config.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

include/config/Config.hpp:8:10 [clang-diagnostic-error]

'oatpp/core/Types.hpp' file not found
#include "oatpp/parser/json/mapping/ObjectMapper.hpp"
#include "oatpp/core/macro/codegen.hpp"

Expand All @@ -19,12 +19,13 @@
: public oatpp::DTO
{

DTO_INIT(UserConfig, DTO)

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

View workflow job for this annotation

GitHub Actions / cpp-linter

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

use a trailing return type for this function

DTO_FIELD(Int32, Version);
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 @@ -37,14 +38,18 @@

void Load();

std::string GetKalshiApiUrl() const;

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

View workflow job for this annotation

GitHub Actions / cpp-linter

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

use a trailing return type for this function

std::string GetSslTrustStoreDir() const;

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

View workflow job for this annotation

GitHub Actions / cpp-linter

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

use a trailing return type for this function

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 All @@ -56,7 +61,7 @@
std::shared_ptr<oatpp::parser::json::mapping::ObjectMapper> m_objectMapper;
std::shared_ptr<UserConfig> m_activeConfig;

static std::shared_ptr<UserConfig> MakeDefaultConfig();

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

View workflow job for this annotation

GitHub Actions / cpp-linter

include/config/Config.hpp:64:44 [modernize-use-trailing-return-type]

use a trailing return type for this function
};
}

Expand Down
4 changes: 3 additions & 1 deletion include/ui/MainFrame.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef MAINFRAME_HPP

Check notice on line 1 in include/ui/MainFrame.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on include/ui/MainFrame.hpp

File include/ui/MainFrame.hpp does not conform to LLVM style guidelines. (lines 6, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 29, 31, 32, 33, 34, 36, 37, 38, 40, 42, 43, 45, 46, 47, 48, 49, 50, 52, 54, 55, 56, 57, 58, 59, 61)
#define MAINFRAME_HPP

#include <wx/wx.h>

Check failure on line 4 in include/ui/MainFrame.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

include/ui/MainFrame.hpp:4:10 [clang-diagnostic-error]

'wx/wx.h' file not found

#include "app_config.hpp"
#include "api/Api.hpp"
Expand All @@ -17,7 +17,8 @@
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 @@

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
@@ -1,19 +1,20 @@
#ifndef PORTFOLIOPANEL_HPP

Check notice on line 1 in include/ui/PortfolioPanel.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on include/ui/PortfolioPanel.hpp

File include/ui/PortfolioPanel.hpp does not conform to LLVM style guidelines. (lines 6, 7, 8, 9, 10, 12, 13, 14, 15, 17, 19, 20, 21, 23, 24, 26)
#define PORTFOLIOPANEL_HPP

#include <wx/wx.h>

Check failure on line 4 in include/ui/PortfolioPanel.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

include/ui/PortfolioPanel.hpp:4:10 [clang-diagnostic-error]

'wx/wx.h' file not found

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
@@ -1,7 +1,7 @@
#include <string>

Check notice on line 1 in src/config/Config.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on src/config/Config.cpp

File src/config/Config.cpp does not conform to LLVM style guidelines. (lines 6, 14, 15, 16, 17, 19, 20, 21, 22, 23, 24, 25, 26, 28, 29, 30, 31, 32, 33, 34, 36, 37, 38, 40, 41, 42, 43, 44, 45, 46, 48, 49, 50, 51, 52, 53, 55, 56, 58, 59, 60, 61, 62, 63, 64, 65, 66, 68, 69, 70, 72, 73, 74, 75, 76, 77, 78, 80, 82, 83, 85, 86, 87, 88, 90, 92, 94, 95, 96, 97, 98, 100, 101, 102, 103, 105, 106, 108, 109, 110, 111, 113, 115, 117, 118, 119, 120, 122, 124, 125, 126, 127, 129, 130, 131, 132, 134, 135, 136, 137, 139, 140, 141, 142, 144, 145, 146, 147, 149, 150, 151, 152, 154, 155, 156, 157, 159, 160, 161, 163, 164, 165, 166, 167, 169, 172)
#include <string_view>

#include <fmt/core.h>

Check failure on line 4 in src/config/Config.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

src/config/Config.cpp:4:10 [clang-diagnostic-error]

'fmt/core.h' file not found

#include "oatpp/core/async/Coroutine.hpp"
#include "oatpp/core/data/stream/FileStream.hpp"
Expand Down Expand Up @@ -141,11 +141,21 @@
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 @@
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
@@ -1,6 +1,6 @@
#include <algorithm>

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

View workflow job for this annotation

GitHub Actions / cpp-linter

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

File src/ui/MainFrame.cpp does not conform to LLVM style guidelines. (lines 6, 16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 29, 30, 32, 33, 34, 35, 36, 38, 40, 41, 43, 45, 46, 48, 50, 52, 53, 54, 56, 58, 60, 62, 64, 66, 67, 69, 71, 72, 73, 74, 75, 77, 79, 81, 82, 84, 86, 87, 89, 90, 91, 92, 93, 94, 95, 97, 98, 99, 101, 102, 104, 105, 106, 108, 109, 111, 112, 113, 114, 116, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 129, 130, 131, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 148, 149, 150, 152, 153, 154, 155, 156, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 173, 174, 175, 176, 177, 178, 180, 181, 182, 183, 184, 185, 187, 188, 189, 190, 191, 192, 194, 195, 196, 198, 199, 200, 201, 202, 203, 204, 205, 206, 208, 209, 211, 212, 213, 215, 216, 218, 219, 220, 221, 223, 224, 225, 226, 228, 229, 231, 232, 233, 234, 235, 236, 238, 239, 240, 242, 243, 244, 246, 247, 248, 250, 251, 252, 254, 255, 256, 258, 260, 261, 262, 264, 265, 266, 268, 269, 270, 272, 273, 274, 275, 276, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 301)

#include <wx/string.h>

Check failure on line 3 in src/ui/MainFrame.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

src/ui/MainFrame.cpp:3:10 [clang-diagnostic-error]

'wx/string.h' file not found
#include <wx/wx.h>

#include "api/Api.hpp"
Expand Down Expand Up @@ -55,6 +55,14 @@

///////////////////////////////////////////////////////////////////////////

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 @@
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 @@

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 @@
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 @@
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 @@

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
}
Loading