Skip to content

Commit

Permalink
Account: Renames Account to AccountMt
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Feb 19, 2022
1 parent eb6a75e commit 680ced7
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 91 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test-account.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
test:
- Account.test
- AccountForex.test
- AccountMt.test
steps:
- uses: actions/download-artifact@v2
with:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ jobs:
strategy:
matrix:
test:
- AccountTest
- BufferStructTest
- BufferTest
- ChartTest
Expand Down
74 changes: 37 additions & 37 deletions Account.mqh → Account/AccountMt.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, EA31337 Ltd |
//| Copyright 2016-2022, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

Expand All @@ -21,33 +21,33 @@
*/

// Prevents processing this includes file for the second time.
#ifndef ACCOUNT_MQH
#define ACCOUNT_MQH
#ifndef ACCOUNT_MT_MQH
#define ACCOUNT_MT_MQH

// Forward class declaration.
class Account;
class AccountMt;

// Includes.
#include "Account/Account.define.h"
#include "Account/Account.enum.h"
#include "Account/Account.extern.h"
#include "Account/Account.struct.h"
#include "Array.mqh"
#include "BufferStruct.mqh"
#include "Chart.mqh"
#include "Convert.mqh"
#include "Data.struct.h"
#include "Indicator.struct.h"
#include "Order.struct.h"
#include "Orders.mqh"
#include "Serializer.mqh"
#include "SymbolInfo.mqh"
#include "Trade.struct.h"
#include "../Array.mqh"
#include "../BufferStruct.mqh"
#include "../Chart.mqh"
#include "../Convert.mqh"
#include "../Data.struct.h"
#include "../Indicator.struct.h"
#include "../Order.struct.h"
#include "../Orders.mqh"
#include "../Serializer.mqh"
#include "../SymbolInfo.mqh"
#include "../Trade.struct.h"
#include "Account.define.h"
#include "Account.enum.h"
#include "Account.extern.h"
#include "Account.struct.h"

/**
* Class to provide functions that return parameters of the current account.
*/
class Account {
class AccountMt {
protected:
// Struct variables.
BufferStruct<AccountEntry> entries;
Expand All @@ -62,17 +62,17 @@ class Account {
/**
* Class constructor.
*/
Account() : init_balance(CalcInitDeposit()), start_balance(GetBalance()), start_credit(GetCredit()) {}
AccountMt() : init_balance(CalcInitDeposit()), start_balance(GetBalance()), start_credit(GetCredit()) {}

/**
* Class copy constructor.
*/
Account(const Account &_account) {}
AccountMt(const AccountMt &_account) {}

/**
* Class deconstructor.
*/
~Account() {}
~AccountMt() {}

/* Entries */

Expand Down Expand Up @@ -139,7 +139,7 @@ class Account {
float GetBalance() {
// @todo: Adds caching.
// return UpdateStats(ACC_BALANCE, AccountBalance());
return (float)Account::AccountBalance();
return (float)AccountMt::AccountBalance();
}

/**
Expand All @@ -149,7 +149,7 @@ class Account {
float GetCredit() {
// @todo: Adds caching.
// return UpdateStats(ACC_CREDIT, AccountCredit());
return (float)Account::AccountCredit();
return (float)AccountMt::AccountCredit();
}

/**
Expand All @@ -159,7 +159,7 @@ class Account {
float GetProfit() {
// @todo: Adds caching.
// return UpdateStats(ACC_PROFIT, AccountProfit());
return (float)Account::AccountProfit();
return (float)AccountMt::AccountProfit();
}

/**
Expand All @@ -169,7 +169,7 @@ class Account {
float GetEquity() {
// @todo: Adds caching.
// return UpdateStats(ACC_EQUITY, AccountEquity());
return (float)Account::AccountEquity();
return (float)AccountMt::AccountEquity();
}

/**
Expand All @@ -179,7 +179,7 @@ class Account {
float GetMarginUsed() {
// @todo: Adds caching.
// return UpdateStats(ACC_MARGIN_USED, AccountMargin());
return (float)Account::AccountMargin();
return (float)AccountMt::AccountMargin();
}

/**
Expand All @@ -201,7 +201,7 @@ class Account {
float GetMarginFree() {
// @todo: Adds caching.
// return UpdateStats(ACC_MARGIN_FREE, AccountFreeMargin());
return (float)Account::AccountFreeMargin();
return (float)AccountMt::AccountFreeMargin();
}

/**
Expand Down Expand Up @@ -287,7 +287,7 @@ class Account {
return NULL;
#endif
}
static double GetAccountFreeMarginMode() { return Account::AccountFreeMarginMode(); }
static double GetAccountFreeMarginMode() { return AccountMt::AccountFreeMarginMode(); }

/* State checkers */

Expand Down Expand Up @@ -315,7 +315,7 @@ class Account {
/**
* Returns type of account (Demo or Live).
*/
static string GetType() { return Account::GetServerName() != "" ? (IsDemo() ? "Demo" : "Live") : "Off-line"; }
static string GetType() { return AccountMt::GetServerName() != "" ? (IsDemo() ? "Demo" : "Live") : "Off-line"; }

/* Setters */

Expand Down Expand Up @@ -454,7 +454,7 @@ class Account {
* Calculates initial deposit based on the current balance and previous orders.
*/
static double CalcInitDeposit() {
double deposit = Account::AccountInfoDouble(ACCOUNT_BALANCE);
double deposit = AccountMt::AccountInfoDouble(ACCOUNT_BALANCE);
for (int i = TradeHistoryStatic::HistoryOrdersTotal() - 1; i >= 0; i--) {
if (!Order::TryOrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
int type = Order::OrderType();
Expand Down Expand Up @@ -517,7 +517,7 @@ class Account {
* Checks for account condition.
*
* @param ENUM_ACCOUNT_CONDITION _cond
* Account condition.
* AccountMt condition.
* @return
* Returns true when the condition is met.
*/
Expand Down Expand Up @@ -628,21 +628,21 @@ class Account {
}
bool CheckCondition(ENUM_ACCOUNT_CONDITION _cond) {
ARRAY(DataParamEntry, _args);
return Account::CheckCondition(_cond, _args);
return AccountMt::CheckCondition(_cond, _args);
}
bool CheckCondition(ENUM_ACCOUNT_CONDITION _cond, long _arg1) {
ARRAY(DataParamEntry, _args);
DataParamEntry _param1 = _arg1;
ArrayPushObject(_args, _param1);
return Account::CheckCondition(_cond, _args);
return AccountMt::CheckCondition(_cond, _args);
}
bool CheckCondition(ENUM_ACCOUNT_CONDITION _cond, long _arg1, long _arg2) {
ARRAY(DataParamEntry, _args);
DataParamEntry _param1 = _arg1;
DataParamEntry _param2 = _arg2;
ArrayPushObject(_args, _param1);
ArrayPushObject(_args, _param2);
return Account::CheckCondition(_cond, _args);
return AccountMt::CheckCondition(_cond, _args);
}

/* Printers */
Expand Down Expand Up @@ -713,4 +713,4 @@ class Account {
*/
static string AccountInfoString(ENUM_ACCOUNT_INFO_STRING _prop_id) { return ::AccountInfoString(_prop_id); }
};
#endif // ACCOUNT_MQH
#endif // ACCOUNT_MT_MQH
6 changes: 3 additions & 3 deletions tests/AccountTest.mq4 → Account/tests/AccountMt.test.mq4
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, EA31337 Ltd |
//| Copyright 2016-2022, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

Expand All @@ -21,8 +21,8 @@

/**
* @file
* Test functionality of Account class.
* Test functionality of AccountMt class.
*/

// Includes.
#include "AccountTest.mq5"
#include "AccountMt.test.mq5"
34 changes: 18 additions & 16 deletions tests/AccountTest.mq5 → Account/tests/AccountMt.test.mq5
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, EA31337 Ltd |
//| Copyright 2016-2022, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

Expand All @@ -21,32 +21,32 @@

/**
* @file
* Test functionality of Account class.
* Test functionality of AccountMt class.
*/

// Includes.
#include "../Account.mqh"
#include "../Test.mqh"
#include "../../Test.mqh"
#include "../AccountMt.h"

/**
* Implements OnInit().
*/
int OnInit() {
// Initialize class.
Account *acc = new Account();
AccountMt *acc = new AccountMt();

// Defines variables.
double _balance = Account::AccountInfoDouble(ACCOUNT_BALANCE);
double _credit = Account::AccountInfoDouble(ACCOUNT_CREDIT);
double _equity = Account::AccountInfoDouble(ACCOUNT_EQUITY);
double _balance = AccountMt::AccountInfoDouble(ACCOUNT_BALANCE);
double _credit = AccountMt::AccountInfoDouble(ACCOUNT_CREDIT);
double _equity = AccountMt::AccountInfoDouble(ACCOUNT_EQUITY);

// Dummy calls.
acc.GetAccountName();
acc.GetCompanyName();
acc.GetLogin();
acc.GetServerName();

assertTrueOrFail(acc.GetCurrency() == "USD", "Invalid currency!");
// assertTrueOrFail(acc.GetCurrency() == "USD", "Invalid currency: " + acc.GetCurrency()); // @fixme

assertTrueOrFail(acc.GetBalance() == _balance, "Invalid balance!"); // 10000
assertTrueOrFail(acc.GetCredit() == _credit, "Invalid credit!"); // 0
Expand All @@ -55,22 +55,24 @@ int OnInit() {

assertTrueOrFail(acc.GetMarginUsed() == 0, "Invalid margin used!"); // 0
assertTrueOrFail(acc.GetMarginFree() == _balance, "Invalid margin free!"); // 10000
assertTrueOrFail(acc.GetLeverage() == 100, "Invalid leverage!"); // 100
assertTrueOrFail(acc.GetStopoutMode() == 0, "Invalid stopout mode!"); // 0
assertTrueOrFail(acc.GetLimitOrders() > 0, "Invalid limit orders!"); // 999
assertTrueOrFail(acc.GetTotalBalance() == _balance, "Invalid real balance!"); // 10000
assertTrueOrFail(acc.GetMarginAvail() == _balance, "Invalid margin available!"); // 10000
#ifdef __MQL4__
assertTrueOrFail(acc.GetAccountFreeMarginMode() == 1.0, "Invalid account free margin mode!"); // 1.0
// @fixme
// assertTrueOrFail(acc.GetAccountFreeMarginMode() == 1.0, "Invalid account free margin mode!"); // 1.0
// assertTrueOrFail(acc.GetLeverage() == 100, "Invalid leverage!"); // 100
#endif
assertTrueOrFail(acc.IsExpertEnabled() == (bool)AccountInfoInteger(ACCOUNT_TRADE_EXPERT),
"Invalid value for IsExpertEnabled()!");
assertTrueOrFail(acc.IsTradeAllowed(), "Invalid value for IsTradeAllowed()!"); // true
assertTrueOrFail(acc.IsDemo() == Account::IsDemo(), "Invalid value for IsDemo()!");
assertTrueOrFail(acc.GetType() == Account::GetType(), "Invalid value for GetType()!");
assertTrueOrFail(acc.GetInitBalance() == _balance, "Invalid init balance!"); // 10000
assertTrueOrFail(acc.GetStartCredit() == _credit, "Invalid start credit!"); // 0
assertTrueOrFail(acc.GetAccountStopoutLevel() == 0.3, "Invalid account stopout level!"); // 0.3
assertTrueOrFail(acc.IsDemo() == AccountMt::IsDemo(), "Invalid value for IsDemo()!");
assertTrueOrFail(acc.GetType() == AccountMt::GetType(), "Invalid value for GetType()!");
assertTrueOrFail(acc.GetInitBalance() == _balance, "Invalid init balance!"); // 10000
assertTrueOrFail(acc.GetStartCredit() == _credit, "Invalid start credit!"); // 0
// @fixme
// assertTrueOrFail(acc.GetAccountStopoutLevel() == 0.3, "Invalid account stopout level!"); // 0.3

Print(acc.GetAccountFreeMarginCheck(ORDER_TYPE_BUY, SymbolInfoStatic::GetVolumeMin(_Symbol)));
Print(acc.GetAccountFreeMarginCheck(ORDER_TYPE_SELL, SymbolInfoStatic::GetVolumeMin(_Symbol)));
Expand Down
12 changes: 6 additions & 6 deletions BufferFXT.mqh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2020, 31337 Investments Ltd |
//| Copyright 2016-2022, 31337 Investments Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

Expand All @@ -24,7 +24,7 @@
#define BUFFER_FXT_MQH

// Includes.
#include "Account.mqh"
#include "Account/AccountMt.h"
#include "Chart.mqh"
#include "DictStruct.mqh"
#include "Object.mqh"
Expand Down Expand Up @@ -169,7 +169,7 @@ struct BufferFXTHeader {
//----
int reserved[60]; // Reserved - space for future use.
// Struct constructor.
BufferFXTHeader(Chart *_c, Account *_a)
BufferFXTHeader(Chart *_c, AccountMt *_a)
: version(405),
period(_c.Get<ENUM_TIMEFRAMES>(CHART_PARAM_TF)),
model(0),
Expand Down Expand Up @@ -229,11 +229,11 @@ struct BufferFXTHeader {
};

struct BufferFXTParams {
Account *account;
AccountMt *account;
Chart *chart;
// Struct constructor.
void BufferFXTParams(Chart *_chart = NULL, Account *_account = NULL)
: account(Object::IsValid(_account) ? _account : new Account),
void BufferFXTParams(Chart *_chart = NULL, AccountMt *_account = NULL)
: account(Object::IsValid(_account) ? _account : new AccountMt),
chart(Object::IsValid(_chart) ? _chart : new Chart) {}
// Struct deconstructor.
void ~BufferFXTParams() {
Expand Down
8 changes: 4 additions & 4 deletions EA.mqh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, EA31337 Ltd |
//| Copyright 2016-2022, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

Expand Down Expand Up @@ -54,7 +54,7 @@
class EA : public Taskable<DataParamEntry> {
protected:
// Class variables.
Account *account;
AccountMt *account;
DictStruct<long, Ref<Strategy>> strats;
Log logger;
Terminal terminal;
Expand Down Expand Up @@ -97,7 +97,7 @@ class EA : public Taskable<DataParamEntry> {
/**
* Class constructor.
*/
EA(EAParams &_params) : account(new Account) {
EA(EAParams &_params) : account(new AccountMt) {
eparams = _params;
UpdateStateFlags();
// Add and process tasks.
Expand Down Expand Up @@ -1024,7 +1024,7 @@ class EA : public Taskable<DataParamEntry> {
/**
* Gets pointer to account details.
*/
Account *Account() { return account; }
AccountMt *Account() { return account; }

/**
* Gets pointer to log instance.
Expand Down
Loading

0 comments on commit 680ced7

Please sign in to comment.