#ifndef QORDERLISTMANAGER_H #define QORDERLISTMANAGER_H #include #include #include #include #include struct OrderBookItem { double price = 0.0; double volume = 0.0; int orderCount = 0; QString orderId; bool isValid() const { return price > 0 && volume > 0 && !orderId.isEmpty(); } bool operator==(const OrderBookItem& other) const { return orderId == other.orderId; } }; class QOrderListManager : public QObject { Q_OBJECT public: enum OrderType { BidOrder, AskOrder }; Q_ENUM(OrderType) static QOrderListManager* instance(); static void destroy(); bool addOrder(OrderType type, const OrderBookItem& order); bool updateOrder(OrderType type, const QString& orderId, const OrderBookItem& newData); bool removeOrder(OrderType type, const QString& orderId); QSharedPointer getOrder(OrderType type, const QString& orderId) const; QMap>> getBidOrders() const; QMap>> getAskOrders() const; QMap getBidPriceLevels() const; QMap getAskPriceLevels() const; double getTotalBidVolume() const; double getTotalAskVolume() const; double getBestBidPrice() const; double getBestAskPrice() const; signals: void orderAdded(OrderType type, const OrderBookItem& order); void orderUpdated(OrderType type, const QString& orderId); void orderRemoved(OrderType type, const QString& orderId); void orderBookChanged(); private: explicit QOrderListManager(QObject* parent = nullptr); ~QOrderListManager(); void sortOrders(OrderType type); void calculatePriceLevels(); static QBasicAtomicPointer s_instance; static QMutex s_mutex; QMap>> m_bidOrders; QMap>> m_askOrders; QMap m_bidPriceLevels; QMap m_askPriceLevels; mutable QMutex m_orderMutex; Q_DISABLE_COPY(QOrderListManager) }; #endif