Skip to content

Commit

Permalink
trade: add pool constructor options (#33)
Browse files Browse the repository at this point in the history
Changes:
* downgrade OrderPool to interface;
* add OrderPoolMatcher class;
* introduce OrderMatcher optional parameter for TradingPool and HistoryPool constructors.
  • Loading branch information
yerden authored and dingmaotu committed Apr 2, 2018
1 parent 897edfd commit 3c09910
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions Trade/OrderPool.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,43 @@
//| OrderPoolIter or the macro foreachorder to iterate through an |
//| order pool. |
//+------------------------------------------------------------------+
class OrderPool: public OrderMatcher
interface OrderPool: public OrderMatcher
{
int total() const;
bool select(int i) const;
};
//+------------------------------------------------------------------+
//| The pool of orders with supplied predefined matcher |
//+------------------------------------------------------------------+
class OrderPoolMatcher: public OrderPool
{
private:
const OrderMatcher *m_om;
public:
virtual int total() const=0;
virtual bool select(int i) const=0;
virtual bool matches() const=0;
OrderPoolMatcher(const OrderMatcher *m):m_om(m){}
virtual bool matches() const {return m_om?m_om.matches():true;}
};
//+------------------------------------------------------------------+
//| The pool of orders from the Terminal order history tab |
//+------------------------------------------------------------------+
class HistoryPool: public OrderPool
class HistoryPool: public OrderPoolMatcher
{
public:
HistoryPool():OrderPoolMatcher(NULL){}
HistoryPool(const OrderMatcher *m):OrderPoolMatcher(m){}
int total() const final {return OrdersHistoryTotal();}
bool select(int i) const final {return OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);}
virtual bool matches() const {return true;}
};
//+------------------------------------------------------------------+
//| Currently active orders |
//+------------------------------------------------------------------+
class TradingPool: public OrderPool
class TradingPool: public OrderPoolMatcher
{
public:
TradingPool():OrderPoolMatcher(NULL){}
TradingPool(const OrderMatcher *m):OrderPoolMatcher(m){}
int total() const final {return OrdersTotal();}
bool select(int i) const final {return OrderSelect(i,SELECT_BY_POS,MODE_TRADES);}
virtual bool matches() const {return true;}
};
//+------------------------------------------------------------------+
//| For internal use: iterate through an OrderPool |
Expand Down

0 comments on commit 3c09910

Please sign in to comment.