Skip to content

Commit

Permalink
Some fixes with const
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Sep 3, 2024
1 parent a7228ea commit 3b755e9
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Exchange/Account/Account.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Account : public AccountBase {
/**
* Returns serialized representation of the object instance.
*/
virtual SerializerNodeType Serialize(Serializer &_s) {
virtual SerializerNodeType Serialize(Serializer &_s) const {
_s.PassStruct(THIS_REF, "state", state);
return SerializerNodeObject;
}
Expand Down
18 changes: 9 additions & 9 deletions Exchange/Account/AccountBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,47 +71,47 @@ class AccountBase : public Dynamic {
/**
* Returns serialized representation of the object instance.
*/
virtual SerializerNodeType Serialize(Serializer &_s) = 0;
virtual SerializerNodeType Serialize(Serializer &_s) const = 0;

/* Virtual methods */

/**
* Returns balance value of the current account.
*/
virtual datetime GetDateTime() { return TimeCurrent(); };
virtual datetime GetDateTime() const { return TimeCurrent(); };

/**
* Returns balance value of the current account.
*/
virtual float GetBalance() = 0;
virtual float GetBalance() const = 0;

/**
* Returns credit value of the current account.
*/
virtual float GetCredit() = 0;
virtual float GetCredit() const = 0;

/**
* Returns profit value of the current account.
*/
virtual float GetProfit() = 0;
virtual float GetProfit() const = 0;

/**
* Returns equity value of the current account.
*/
virtual float GetEquity() = 0;
virtual float GetEquity() const = 0;

/**
* Returns margin value of the current account.
*/
virtual float GetMarginUsed() = 0;
virtual float GetMarginUsed() const = 0;

/**
* Returns free margin value of the current account.
*/
virtual float GetMarginFree() = 0;
virtual float GetMarginFree() const = 0;

/**
* Get account available margin.
*/
virtual float GetMarginAvail() = 0;
virtual float GetMarginAvail() const = 0;
};
14 changes: 7 additions & 7 deletions Exchange/Account/AccountForex.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,49 +64,49 @@ class AccountForex : public Account<AccountForexState, AccountForexEntry> {
/**
* Returns balance value of the current account.
*/
float GetBalance() {
float GetBalance() const {
return 0.0f;
}

/**
* Returns credit value of the current account.
*/
float GetCredit() {
float GetCredit() const {
return 0.0f;
}

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

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

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

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

/**
* Get account available margin.
*/
float GetMarginAvail() {
float GetMarginAvail() const {
return 0.0f;
}
};
62 changes: 31 additions & 31 deletions Exchange/Account/AccountMt.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ class AccountMt : public AccountBase {
* @return
* Returns account entry.
*/
AccountEntry GetEntry() {
AccountEntry GetEntry() const {
AccountEntry _entry;
_entry.dtime = TimeCurrent();
_entry.balance = GetBalance();
_entry.credit = GetCredit();
_entry.equity = GetEquity();
_entry.profit = GetProfit();
_entry.margin_used = GetMarginUsed();
_entry.margin_free = GetMarginFree();
_entry.margin_avail = GetMarginAvail();
_entry.dtime = AccountMt::GetDateTime();
_entry.balance = AccountMt::GetBalance();
_entry.credit = AccountMt::GetCredit();
_entry.equity = AccountMt::GetEquity();
_entry.profit = AccountMt::GetProfit();
_entry.margin_used = AccountMt::GetMarginUsed();
_entry.margin_free = AccountMt::GetMarginFree();
_entry.margin_avail = AccountMt::GetMarginAvail();
return _entry;
}

Expand All @@ -112,7 +112,7 @@ class AccountMt : public AccountBase {
* Returns the current account name.
*/
static string AccountName() { return AccountInfoString(ACCOUNT_NAME); }
string GetAccountName() { return AccountName(); }
string GetAccountName() const { return AccountName(); }

/**
* Returns the connected server name.
Expand All @@ -124,21 +124,21 @@ class AccountMt : public AccountBase {
* Returns currency name of the current account.
*/
static string AccountCurrency() { return AccountInfoString(ACCOUNT_CURRENCY); }
string GetCurrency() { return AccountCurrency(); }
string GetCurrency() const { return AccountCurrency(); }

/**
* Returns the brokerage company name where the current account was registered.
*/
static string AccountCompany() { return AccountInfoString(ACCOUNT_COMPANY); }
string GetCompanyName() { return AccountCompany(); }
string GetCompanyName() const { return AccountCompany(); }

/* Double getters */

/**
* Returns balance value of the current account.
*/
static double AccountBalance() { return AccountInfoDouble(ACCOUNT_BALANCE); }
float GetBalance() override {
float GetBalance() const override {
// @todo: Adds caching.
// return UpdateStats(ACC_BALANCE, AccountBalance());
return (float)AccountMt::AccountBalance();
Expand All @@ -148,7 +148,7 @@ class AccountMt : public AccountBase {
* Returns credit value of the current account.
*/
static double AccountCredit() { return AccountInfoDouble(ACCOUNT_CREDIT); }
float GetCredit() override {
float GetCredit() const override {
// @todo: Adds caching.
// return UpdateStats(ACC_CREDIT, AccountCredit());
return (float)AccountMt::AccountCredit();
Expand All @@ -158,7 +158,7 @@ class AccountMt : public AccountBase {
* Returns profit value of the current account.
*/
static double AccountProfit() { return AccountInfoDouble(ACCOUNT_PROFIT); }
float GetProfit() override {
float GetProfit() const override {
// @todo: Adds caching.
// return UpdateStats(ACC_PROFIT, AccountProfit());
return (float)AccountMt::AccountProfit();
Expand All @@ -168,7 +168,7 @@ class AccountMt : public AccountBase {
* Returns equity value of the current account.
*/
static double AccountEquity() { return AccountInfoDouble(ACCOUNT_EQUITY); }
float GetEquity() override {
float GetEquity() const override {
// @todo: Adds caching.
// return UpdateStats(ACC_EQUITY, AccountEquity());
return (float)AccountMt::AccountEquity();
Expand All @@ -178,7 +178,7 @@ class AccountMt : public AccountBase {
* Returns margin value of the current account.
*/
static double AccountMargin() { return AccountInfoDouble(ACCOUNT_MARGIN); }
float GetMarginUsed() {
float GetMarginUsed() const {
// @todo: Adds caching.
// return UpdateStats(ACC_MARGIN_USED, AccountMargin());
return (float)AccountMt::AccountMargin();
Expand All @@ -200,7 +200,7 @@ class AccountMt : public AccountBase {
* Returns free margin value of the current account.
*/
static double AccountFreeMargin() { return AccountInfoDouble(ACCOUNT_MARGIN_FREE); }
float GetMarginFree() override {
float GetMarginFree() const override {
// @todo: Adds caching.
// return UpdateStats(ACC_MARGIN_FREE, AccountFreeMargin());
return (float)AccountMt::AccountFreeMargin();
Expand All @@ -212,7 +212,7 @@ class AccountMt : public AccountBase {
* @return
* Account's free margin in percentage.
*/
double GetMarginFreeInPct() {
double GetMarginFreeInPct() const {
double _margin_free = GetMarginFree();
double _margin_avail = GetMarginAvail();
return _margin_avail > 0 ? 100 / _margin_avail * _margin_free : 0;
Expand All @@ -222,19 +222,19 @@ class AccountMt : public AccountBase {
* Returns the current account number.
*/
static int64 AccountNumber() { return AccountInfoInteger(ACCOUNT_LOGIN); }
int64 GetLogin() { return AccountNumber(); }
int64 GetLogin() const { return AccountNumber(); }

/**
* Returns leverage of the current account.
*/
static int64 AccountLeverage() { return AccountInfoInteger(ACCOUNT_LEVERAGE); }
int64 GetLeverage() { return AccountLeverage(); }
int64 GetLeverage() const { return AccountLeverage(); }

/**
* Returns the calculation mode for the Stop Out level.
*/
static int AccountStopoutMode() { return (int)AccountInfoInteger(ACCOUNT_MARGIN_SO_MODE); }
int GetStopoutMode() { return AccountStopoutMode(); }
int GetStopoutMode() const { return AccountStopoutMode(); }

/**
* Returns the value of the Stop Out level.
Expand All @@ -243,7 +243,7 @@ class AccountMt : public AccountBase {
* is expressed in percents or in the deposit currency.
*/
static double AccountStopoutLevel() { return AccountInfoDouble(ACCOUNT_MARGIN_SO_SO); }
double GetStopoutLevel() { return AccountStopoutLevel(); }
double GetStopoutLevel() const { return AccountStopoutLevel(); }

/**
* Get a maximum allowed number of active pending orders set by broker.
Expand All @@ -252,7 +252,7 @@ class AccountMt : public AccountBase {
* Returns the limit orders (0 for unlimited).
*/
static int64 AccountLimitOrders() { return AccountInfoInteger(ACCOUNT_LIMIT_ORDERS); }
int64 GetLimitOrders(unsigned int _max = 999) {
int64 GetLimitOrders(unsigned int _max = 999) const {
int64 _limit = AccountLimitOrders();
return _limit > 0 ? _limit : _max;
}
Expand All @@ -263,13 +263,13 @@ class AccountMt : public AccountBase {
* Get account total balance (including credit).
*/
static double AccountTotalBalance() { return AccountBalance() + AccountCredit(); }
float GetTotalBalance() { return (float)(GetBalance() + GetCredit()); }
float GetTotalBalance() const { return (float)(GetBalance() + GetCredit()); }

/**
* Get account available margin.
*/
static double AccountAvailMargin() { return fmin(AccountFreeMargin(), AccountTotalBalance()); }
float GetMarginAvail() override { return (float)AccountAvailMargin(); }
float GetMarginAvail() const override { return (float)AccountAvailMargin(); }

/**
* Returns the calculation mode of free margin allowed to open orders on the current account.
Expand Down Expand Up @@ -324,17 +324,17 @@ class AccountMt : public AccountBase {
/**
* Get account init balance.
*/
double GetInitBalance() { return init_balance; }
double GetInitBalance() const { return init_balance; }

/**
* Get account start balance.
*/
double GetStartBalance() { return start_balance; }
double GetStartBalance() const { return start_balance; }

/**
* Get account init credit.
*/
double GetStartCredit() { return start_credit; }
double GetStartCredit() const { return start_credit; }

/* Calculation methods */

Expand Down Expand Up @@ -388,7 +388,7 @@ class AccountMt : public AccountBase {
: -1);
#endif
}
double GetAccountFreeMarginCheck(ENUM_ORDER_TYPE _cmd, double _volume) {
double GetAccountFreeMarginCheck(ENUM_ORDER_TYPE _cmd, double _volume) const {
return AccountFreeMarginCheck(_Symbol, _cmd, _volume);
}

Expand Down Expand Up @@ -639,7 +639,7 @@ class AccountMt : public AccountBase {
/**
* Returns serialized representation of the object instance.
*/
SerializerNodeType Serialize(Serializer &_s) {
SerializerNodeType Serialize(Serializer &_s) const {
AccountEntry _entry = GetEntry();
_s.PassStruct(THIS_REF, "account-entry", _entry, SERIALIZER_FIELD_FLAG_DYNAMIC);
return SerializerNodeObject;
Expand Down
4 changes: 2 additions & 2 deletions Exchange/Exchange.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Exchange : public Taskable<DataParamEntry> {
* Adds account instance to the list.
*/
void AccountAdd(AccountParams &_aparams) {
AccountBase *_account = new AccountForex(/*_aparams*/);
AccountBase *_account = new AccountForex(_aparams);
AccountAdd(_account);
}

Expand Down Expand Up @@ -191,7 +191,7 @@ class Exchange : public Taskable<DataParamEntry> {
/**
* Returns serialized representation of the object instance.
*/
SerializerNodeType Serialize(Serializer &_s) {
SerializerNodeType Serialize(Serializer &_s) const {
_s.PassStruct(THIS_REF, "eparams", eparams);
_s.PassStruct(THIS_REF, "accounts", accounts);
//_s.PassStruct(THIS_REF, "symbols", symbols);
Expand Down
Loading

0 comments on commit 3b755e9

Please sign in to comment.