Skip to content

Commit

Permalink
Trade: Adds getters for account parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Aug 2, 2021
1 parent 1b5e9c8 commit 83957e8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Account.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
8 changes: 8 additions & 0 deletions Trade.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ class Trade {

/* Getters */

/**
* Gets an account parameter value of double type.
*/
template <typename T>
T Get(ENUM_ACCOUNT_INFO_DOUBLE _param) {
return account.Get<T>(_param);
}

/**
* Gets a trade parameter value.
*/
Expand Down

0 comments on commit 83957e8

Please sign in to comment.