85 lines
2.6 KiB
MQL5
85 lines
2.6 KiB
MQL5
//+------------------------------------------------------------------+
| |||
//| OrderTracker.mqh |
| |||
//| Copyright 2025, MetaQuotes Ltd. |
| |||
//| https://www.mql5.com |
| |||
//+------------------------------------------------------------------+
| |||
#property copyright "Copyright 2025, MetaQuotes Ltd."
| |||
#property link "https://www.mql5.com"
| |||
#property version "1.00"
| |||
| |||
#include "../../Events/EventBus/EventBus.mqh"
| |||
#include "../../Events/Events/TradingEvents.mqh"
| |||
#include <Collection/DynamicArrayList.mqh>
| |||
| |||
struct PendingOrderRecord
| |||
{
| |||
ulong ticket;
| |||
string symbol;
| |||
ENUM_ORDER_TYPE type;
| |||
double volume;
| |||
double price;
| |||
double sl;
| |||
double tp;
| |||
datetime expiration;
| |||
string comment;
| |||
datetime placedTime;
| |||
};
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| |
| |||
//+------------------------------------------------------------------+
| |||
class OrderTracker : public IEventListener
| |||
{
| |||
private:
| |||
EventBus* m_bus;
| |||
CArrayList<PendingOrderRecord> m_orders;
| |||
| |||
int FindIndex(ulong ticket)
| |||
{
| |||
for(int i = 0; i < m_orders.Size(); i++)
| |||
if(m_orders.At(i).ticket == ticket)
| |||
return i;
| |||
return -1;
| |||
}
| |||
public:
| |||
OrderTracker() {}
| |||
~OrderTracker() {}
| |||
void Initialize(EventBus* bus) { m_bus = bus; }
| |||
| |||
virtual void OnEvent(AbstractEvent* event) override
| |||
{
| |||
if(event.GetType() == PENDING_ORDER_PLACED)
| |||
{
| |||
PendingOrderPlacedEvent* e = (PendingOrderPlacedEvent*)event;
| |||
| |||
PendingOrderRecord order;
| |||
order.ticket = e.GetTicket();
| |||
order.symbol = e.GetSymbolName();
| |||
order.type = e.GetTypeOrder();
| |||
order.volume = e.GetVolume();
| |||
order.price = e.GetPrice();
| |||
order.sl = e.GetSL();
| |||
order.tp = e.GetTP();
| |||
order.expiration = e.GetExpiration();
| |||
order.comment = e.GetComment();
| |||
order.placedTime = TimeCurrent();
| |||
| |||
m_orders.Add(order);
| |||
| |||
| |||
}
| |||
}
| |||
| |||
int GetPendingCount(string symbol = NULL)
| |||
{
| |||
| |||
if(symbol == NULL) return m_orders.Size();
| |||
| |||
int cnt = 0;
| |||
for(int i = 0; i < m_orders.Size(); i++)
| |||
if(m_orders.At(i).symbol == symbol) cnt++;
| |||
| |||
return cnt;
| |||
}
| |||
};
| |||
//+------------------------------------------------------------------+
|