56 行
2 KiB
MQL5
56 行
2 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| open-positions.mqh |
|
|
//| IOpenPositions interface + Real and Mock implementations |
|
|
//+------------------------------------------------------------------+
|
|
|
|
//+------------------------------------------------------------------+
|
|
class IOpenPositions
|
|
{
|
|
public:
|
|
virtual int Total() = 0;
|
|
virtual string GetSymbol(int index) = 0;
|
|
virtual long GetMagic(int index) = 0;
|
|
};
|
|
|
|
//+------------------------------------------------------------------+
|
|
class RealOpenPositions : public IOpenPositions
|
|
{
|
|
public:
|
|
int Total() override { return PositionsTotal(); }
|
|
string GetSymbol(int index) override { return PositionGetSymbol(index); }
|
|
long GetMagic(int index) override { PositionGetSymbol(index); return PositionGetInteger(POSITION_MAGIC); }
|
|
};
|
|
|
|
//+------------------------------------------------------------------+
|
|
struct MockPosition
|
|
{
|
|
string symbol;
|
|
long magic;
|
|
};
|
|
|
|
class MockOpenPositions : public IOpenPositions
|
|
{
|
|
MockPosition m_positions[];
|
|
int m_count;
|
|
int m_capacity;
|
|
|
|
public:
|
|
MockOpenPositions() : m_count(0), m_capacity(20) { ArrayResize(m_positions, m_capacity); }
|
|
|
|
void Add(string symbol, long magic)
|
|
{
|
|
if(m_count >= m_capacity)
|
|
{
|
|
m_capacity += 10;
|
|
ArrayResize(m_positions, m_capacity);
|
|
}
|
|
m_positions[m_count].symbol = symbol;
|
|
m_positions[m_count].magic = magic;
|
|
m_count++;
|
|
}
|
|
|
|
int Total() override { return m_count; }
|
|
string GetSymbol(int index) override { return (index < m_count) ? m_positions[index].symbol : ""; }
|
|
long GetMagic(int index) override { return (index < m_count) ? m_positions[index].magic : -1; }
|
|
};
|
|
//+------------------------------------------------------------------+
|