Skip to content

Commit

Permalink
Add: Net Liquidation and Excess Liquidity values will now display at …
Browse files Browse the repository at this point in the history
…top of Active Trades window.
  • Loading branch information
PaulSquires committed Aug 24, 2023
1 parent aecacea commit 9c5f38a
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 13 deletions.
44 changes: 38 additions & 6 deletions IB-Tracker/src/ActiveTrades/ActiveTrades.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ void ActiveTrades_OnPaint(HWND hwnd)
Graphics graphics(hdc);

// Create the background brush
Color backColor(COLOR_GRAYDARK);
Color backColor(COLOR_BLACK);
SolidBrush backBrush(backColor);

// Paint the background using brush.
Expand All @@ -969,6 +969,20 @@ void ActiveTrades_OnPaint(HWND hwnd)


// ========================================================================================
// Show/Hide the Net and Excess liquidity labels and values.
// ========================================================================================
void ActiveTrades_ShowHideLiquidityLabels(HWND hwnd)
{
int nShow = (tws_isConnected()) ? SW_SHOW : SW_HIDE;

ShowWindow(GetDlgItem(hwnd, IDC_TRADES_NETLIQUIDATION), nShow);
ShowWindow(GetDlgItem(hwnd, IDC_TRADES_NETLIQUIDATION_VALUE), nShow);
ShowWindow(GetDlgItem(hwnd, IDC_TRADES_EXCESSLIQUIDITY), nShow);
ShowWindow(GetDlgItem(hwnd, IDC_TRADES_EXCESSLIQUIDITY_VALUE), nShow);
}


// ========================================================================================
// Process WM_SIZE message for window/dialog: ActiveTrades
// ========================================================================================
void ActiveTrades_OnSize(HWND hwnd, UINT state, int cx, int cy)
Expand All @@ -982,15 +996,18 @@ void ActiveTrades_OnSize(HWND hwnd, UINT state, int cx, int cy)
// If no entries exist for the ListBox then don't show any child controls
int showflag = (ListBox_GetCount(hListBox) <= 1) ? SWP_HIDEWINDOW : SWP_SHOWWINDOW;

HDWP hdwp = BeginDeferWindowPos(5);
HDWP hdwp = BeginDeferWindowPos(10);

// Move and size the top label into place
hdwp = DeferWindowPos(hdwp, GetDlgItem(hwnd, IDC_TRADES_LABEL), 0,
0, 0, cx, margin, SWP_NOZORDER | SWP_SHOWWINDOW);
// Move and size the top labels into place
hdwp = DeferWindowPos(hdwp, GetDlgItem(hwnd, IDC_TRADES_LABEL), 0, 0, 0, 200, margin, SWP_NOZORDER | SWP_SHOWWINDOW);
hdwp = DeferWindowPos(hdwp, GetDlgItem(hwnd, IDC_TRADES_NETLIQUIDATION), 0, 610, 0, 75, margin, SWP_NOZORDER);
hdwp = DeferWindowPos(hdwp, GetDlgItem(hwnd, IDC_TRADES_NETLIQUIDATION_VALUE), 0, 685, 0, 100, margin, SWP_NOZORDER);
hdwp = DeferWindowPos(hdwp, GetDlgItem(hwnd, IDC_TRADES_EXCESSLIQUIDITY), 0, 780, 0, 95, margin, SWP_NOZORDER);
hdwp = DeferWindowPos(hdwp, GetDlgItem(hwnd, IDC_TRADES_EXCESSLIQUIDITY_VALUE), 0, 875, 0, 100, margin, SWP_NOZORDER);

// Do not call the calcVThumbRect() function during a scrollbar move. This WM_SIZE
// gets triggered when the ListBox WM_DRAWITEM fires. If we do another calcVThumbRect()
// calcualtion then the scrollbar will appear "jumpy" under the user's mouse cursor.
// calculation then the scrollbar will appear "jumpy" under the user's mouse cursor.
bool bShowScrollBar = false;
CustomVScrollBar* pData = CustomVScrollBar_GetPointer(hCustomVScrollBar);
if (pData != nullptr) {
Expand Down Expand Up @@ -1018,6 +1035,9 @@ void ActiveTrades_OnSize(HWND hwnd, UINT state, int cx, int cy)
SWP_NOZORDER | showflag);

EndDeferWindowPos(hdwp);

ActiveTrades_ShowHideLiquidityLabels(hwnd);

}


Expand All @@ -1031,6 +1051,18 @@ BOOL ActiveTrades_OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
HWND hCtl = CustomLabel_SimpleLabel(hwnd, IDC_TRADES_LABEL, L"Active Trades",
COLOR_WHITELIGHT, COLOR_BLACK);

hCtl = CustomLabel_SimpleLabel(hwnd, IDC_TRADES_NETLIQUIDATION, L"Net Liq:",
COLOR_WHITEDARK, COLOR_BLACK);

hCtl = CustomLabel_SimpleLabel(hwnd, IDC_TRADES_NETLIQUIDATION_VALUE, L"",
COLOR_WHITELIGHT, COLOR_BLACK);

hCtl = CustomLabel_SimpleLabel(hwnd, IDC_TRADES_EXCESSLIQUIDITY, L"Excess Liq:",
COLOR_WHITEDARK, COLOR_BLACK);

hCtl = CustomLabel_SimpleLabel(hwnd, IDC_TRADES_EXCESSLIQUIDITY_VALUE, L"",
COLOR_WHITELIGHT, COLOR_BLACK);

// Create an Ownerdraw fixed row sized listbox that we will use to custom
// paint our various open trades.
hCtl =
Expand Down
4 changes: 4 additions & 0 deletions IB-Tracker/src/ActiveTrades/ActiveTrades.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ constexpr int IDC_TRADES_LISTBOX = 100;
constexpr int IDC_TRADES_LABEL = 101;
constexpr int IDC_TRADES_CUSTOMVSCROLLBAR = 102;
constexpr int IDC_TRADES_HEADER = 103;
constexpr int IDC_TRADES_NETLIQUIDATION = 104;
constexpr int IDC_TRADES_NETLIQUIDATION_VALUE = 105;
constexpr int IDC_TRADES_EXCESSLIQUIDITY = 106;
constexpr int IDC_TRADES_EXCESSLIQUIDITY_VALUE = 107;

constexpr int ACTIVETRADES_LISTBOX_ROWHEIGHT = 24;
constexpr int ACTIVETRADES_MARGIN = 24;
Expand Down
2 changes: 1 addition & 1 deletion IB-Tracker/src/Config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SOFTWARE.

#pragma once

constexpr std::wstring version = L"2.3.1";
constexpr std::wstring version = L"2.3.2";

bool SaveConfig();
bool LoadConfig();
Expand Down
58 changes: 52 additions & 6 deletions IB-Tracker/src/MainWindow/tws-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ SOFTWARE.
#include "Reconcile/Reconcile.h"
#include "Utilities/IntelDecimal.h"
#include "SideMenu/SideMenu.h"
#include "CustomLabel/CustomLabel.h"

#include "tws-api/EClientSocket.h"
#include "tws-api/EPosixClientSocketPlatform.h"
Expand Down Expand Up @@ -339,6 +340,9 @@ bool tws_connect()

StartMonitorThread();

// Request Account Summary in order to get liquity amounts
client.requestAccountSummary();

// Destroy any existing ListBox line data
// This will also clear the LineData pointers and cancel any previous market data
PrevMarketDataLoaded = false;
Expand Down Expand Up @@ -614,6 +618,11 @@ void TwsClient::requestPositions()
m_pClient->reqPositions();
}

void TwsClient::requestAccountSummary()
{
m_pClient->reqAccountSummary(1000, "All", "NetLiquidation,ExcessLiquidity");
}



//////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -961,6 +970,49 @@ void TwsClient::tickOptionComputation(TickerId tickerId, TickType tickType, int
if (isThreadPaused) return;
}

#include "MainWindow/MainWindow.h"

void TwsClient::accountSummary(int reqId, const std::string& account, const std::string& tag, const std::string& value, const std::string& currency)
{
// Values will return immediately when first requested and then everytime they change or 3 minutes.

// std::cout << "reqId: " << reqId << " account: " << account << " tag: " << tag << " value: " << value << " currency: " << currency << std::endl;

std::wstring wszValue = ansi2unicode(value);

// Get the value and convert it into K amounts
double amount = AfxValDouble(wszValue);
if (amount > 1000) {
amount = amount / 1000;
wszValue = AfxMoney(amount, false, 1) + L"K";
}
else {
wszValue = AfxMoney(amount, false);
}


if (AfxStringCompareI(tag, "NetLiquidation")) {
//std::cout << "reqId: " << reqId << " account: " << account << " tag: " << tag << " value: " << value << " currency: " << currency << std::endl;
CustomLabel_SetText(GetDlgItem(HWND_ACTIVETRADES, IDC_TRADES_NETLIQUIDATION_VALUE), wszValue);
ShowWindow(GetDlgItem(HWND_ACTIVETRADES, IDC_TRADES_EXCESSLIQUIDITY_VALUE), SW_SHOW);
}

if (AfxStringCompareI(tag, "ExcessLiquidity")) {
CustomLabel_SetText(GetDlgItem(HWND_ACTIVETRADES, IDC_TRADES_EXCESSLIQUIDITY_VALUE), wszValue);
//CustomLabel_SetText(GetDlgItem(HWND_ACTIVETRADES, IDC_TRADES_EXCESSLIQUIDITY_VALUE), L"12345");
ShowWindow(GetDlgItem(HWND_ACTIVETRADES, IDC_TRADES_EXCESSLIQUIDITY_VALUE), SW_SHOW);
}

}

void TwsClient::accountSummaryEnd(int reqId) {
std::cout << "account summary end" << std::endl;
}





void TwsClient::tickSize(TickerId tickerId, TickType field, Decimal size) {
if (isThreadPaused) return;
//std::cout << "tickSize id: " << tickerId << " size: " << (int)intelDecimalToDouble(size) << std::endl;
Expand Down Expand Up @@ -1070,12 +1122,6 @@ void TwsClient::marketDataType(TickerId reqId, int marketDataType) {
void TwsClient::commissionReport(const CommissionReport& commissionReport) {
}

void TwsClient::accountSummary(int reqId, const std::string& account, const std::string& tag, const std::string& value, const std::string& currency) {
}

void TwsClient::accountSummaryEnd(int reqId) {
}

void TwsClient::verifyMessageAPI(const std::string& apiData) {
}

Expand Down
1 change: 1 addition & 0 deletions IB-Tracker/src/MainWindow/tws-client.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class TwsClient : public EWrapper
void requestPositions();
void cancelPortfolioUpdates();
void requestPortfolioUpdates();
void requestAccountSummary();
void pingTWS() const;

public:
Expand Down

0 comments on commit 9c5f38a

Please sign in to comment.