From 83957e8c091b8399a7e65efcf4f13180e0aa2633 Mon Sep 17 00:00:00 2001 From: kenorb Date: Mon, 2 Aug 2021 20:13:43 +0100 Subject: [PATCH] Trade: Adds getters for account parameters --- Account.struct.h | 30 ++++++++++++++++++++++++++++++ Trade.mqh | 8 ++++++++ 2 files changed, 38 insertions(+) diff --git a/Account.struct.h b/Account.struct.h index 48baf5c45..5e0e03e22 100644 --- a/Account.struct.h +++ b/Account.struct.h @@ -60,4 +60,34 @@ struct AccountEntry { _s.Pass(THIS_REF, "margin_avail", margin_avail, SERIALIZER_FIELD_FLAG_DYNAMIC); return SerializerNodeObject; } + /* Getters */ + double Get(ENUM_ACCOUNT_INFO_DOUBLE _param) { + switch (_param) { + case ACCOUNT_BALANCE: + // Account balance in the deposit currency (double). + return balance; + case ACCOUNT_CREDIT: + // Account credit in the deposit currency (double). + return credit; + case ACCOUNT_PROFIT: + // Current profit of an account in the deposit currency (double). + return profit; + case ACCOUNT_EQUITY: + // Account equity in the deposit currency (double). + return equity; + case ACCOUNT_MARGIN: + // Account margin used in the deposit currency (double). + return margin_used; + case ACCOUNT_MARGIN_FREE: + // Free margin of an account in the deposit currency (double). + return margin_free; + case ACCOUNT_MARGIN_LEVEL: + // Account margin level in percents (double). + return margin_avail; + default: + break; + } + SetUserError(ERR_INVALID_PARAMETER); + return WRONG_VALUE; + } }; diff --git a/Trade.mqh b/Trade.mqh index 716be4769..16aba48de 100644 --- a/Trade.mqh +++ b/Trade.mqh @@ -91,6 +91,14 @@ class Trade { /* Getters */ + /** + * Gets an account parameter value of double type. + */ + template + T Get(ENUM_ACCOUNT_INFO_DOUBLE _param) { + return account.Get(_param); + } + /** * Gets a trade parameter value. */