Skip to content

Commit

Permalink
Fixes Exchange.test.mq5
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed May 3, 2024
1 parent 3165600 commit ec02ca7
Showing 1 changed file with 83 additions and 46 deletions.
129 changes: 83 additions & 46 deletions Exchange/tests/Exchange.test.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -30,50 +30,87 @@
#include "../Exchange.h"

// Test classes.
class AccountDummy : public AccountBase {}; // <AccountForexState, AccountForexEntry>
class ExchangeDummy : public Exchange {};
class SymbolDummy : public SymbolInfo {};
class TradeDummy : public Trade {
public:
TradeDummy(IndicatorBase *_indi_candle) : Trade(_indi_candle) {}
};

// Global variables.
ExchangeDummy ex_dummy;

// Test dummy Exchange.
bool TestExchange01() {
bool _result = true;
// Initialize a dummy Exchange instance.
Ref<ExchangeDummy> exchange = new ExchangeDummy();

// Attach instances of dummy accounts.
Ref<AccountDummy> account01 = new AccountDummy();
Ref<AccountDummy> account02 = new AccountDummy();
exchange REF_DEREF AccountAdd(account01.Ptr(), "Account01");
exchange REF_DEREF AccountAdd(account02.Ptr(), "Account02");

// Attach instances of dummy symbols.
Ref<SymbolDummy> symbol01 = new SymbolDummy();
Ref<SymbolDummy> symbol02 = new SymbolDummy();
exchange REF_DEREF SymbolAdd(symbol01.Ptr(), "Symbol01");
exchange REF_DEREF SymbolAdd(symbol02.Ptr(), "Symbol02");

// Attach instances of dummy trades.
Ref<TradeDummy> trade01 = new TradeDummy(Platform::FetchDefaultCandleIndicator(_Symbol, PERIOD_CURRENT));
Ref<TradeDummy> trade02 = new TradeDummy(Platform::FetchDefaultCandleIndicator(_Symbol, PERIOD_CURRENT));

exchange REF_DEREF TradeAdd(trade01.Ptr(), "Trade01");
exchange REF_DEREF TradeAdd(trade02.Ptr(), "Trade02");
return _result;
}
class AccountDummy : public AccountBase {
/**
* Returns balance value of the current account.
*/
float GetBalance() { return 0; }

/**
* Implements OnInit().
*/
int OnInit() {
Platform::Init();
bool _result = true;
assertTrueOrFail(TestExchange01(), "Fail!");
return _result && GetLastError() == 0 ? INIT_SUCCEEDED : INIT_FAILED;
}
/**
* Returns credit value of the current account.
*/
float GetCredit() { return 0; }

/**
* Returns profit value of the current account.
*/
float GetProfit() { return 0; }

/**
* Returns equity value of the current account.
*/
float GetEquity() { return 0; }

/**
* Returns margin value of the current account.
*/
float GetMarginUsed() { return 0; }

/**
* Returns free margin value of the current account.
*/
float GetMarginFree() { return 0; }

/**
* Get account available margin.
*/
float GetMarginAvail() {
return 0;
{}
}; // <AccountForexState, AccountForexEntry>
class ExchangeDummy : public Exchange {};
class SymbolDummy : public SymbolInfo {};
class TradeDummy : public Trade {
public:
TradeDummy(IndicatorBase *_indi_candle) : Trade(_indi_candle) {}
};

// Global variables.
ExchangeDummy ex_dummy;

// Test dummy Exchange.
bool TestExchange01() {
bool _result = true;
// Initialize a dummy Exchange instance.
Ref<ExchangeDummy> exchange = new ExchangeDummy();

// Attach instances of dummy accounts.
Ref<AccountDummy> account01 = new AccountDummy();
Ref<AccountDummy> account02 = new AccountDummy();
exchange REF_DEREF AccountAdd(account01.Ptr(), "Account01");
exchange REF_DEREF AccountAdd(account02.Ptr(), "Account02");

// Attach instances of dummy symbols.
Ref<SymbolDummy> symbol01 = new SymbolDummy();
Ref<SymbolDummy> symbol02 = new SymbolDummy();
exchange REF_DEREF SymbolAdd(symbol01.Ptr(), "Symbol01");
exchange REF_DEREF SymbolAdd(symbol02.Ptr(), "Symbol02");

// Attach instances of dummy trades.
Ref<TradeDummy> trade01 = new TradeDummy(Platform::FetchDefaultCandleIndicator(_Symbol, PERIOD_CURRENT));
Ref<TradeDummy> trade02 = new TradeDummy(Platform::FetchDefaultCandleIndicator(_Symbol, PERIOD_CURRENT));

exchange REF_DEREF TradeAdd(trade01.Ptr(), "Trade01");
exchange REF_DEREF TradeAdd(trade02.Ptr(), "Trade02");
return _result;
}

/**
* Implements OnInit().
*/
int OnInit() {
Platform::Init();
bool _result = true;
assertTrueOrFail(TestExchange01(), "Fail!");
return _result && GetLastError() == 0 ? INIT_SUCCEEDED : INIT_FAILED;
}

0 comments on commit ec02ca7

Please sign in to comment.