Update 更新文档
This commit is contained in:
62
cleaned_source_code/Sqbase/qorderlistmanager.h
Normal file
62
cleaned_source_code/Sqbase/qorderlistmanager.h
Normal file
@@ -0,0 +1,62 @@
|
||||
#ifndef QORDERLISTMANAGER_H
|
||||
#define QORDERLISTMANAGER_H
|
||||
#include <QObject>
|
||||
#include <QMap>
|
||||
#include <QMutex>
|
||||
#include <QSharedPointer>
|
||||
#include <QDateTime>
|
||||
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<OrderBookItem> getOrder(OrderType type, const QString& orderId) const;
|
||||
QMap<double, QList<QSharedPointer<OrderBookItem>>> getBidOrders() const;
|
||||
QMap<double, QList<QSharedPointer<OrderBookItem>>> getAskOrders() const;
|
||||
QMap<double, double> getBidPriceLevels() const;
|
||||
QMap<double, double> 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<QOrderListManager> s_instance;
|
||||
static QMutex s_mutex;
|
||||
QMap<double, QList<QSharedPointer<OrderBookItem>>> m_bidOrders;
|
||||
QMap<double, QList<QSharedPointer<OrderBookItem>>> m_askOrders;
|
||||
QMap<double, double> m_bidPriceLevels;
|
||||
QMap<double, double> m_askPriceLevels;
|
||||
mutable QMutex m_orderMutex;
|
||||
Q_DISABLE_COPY(QOrderListManager)
|
||||
};
|
||||
#endif
|
||||
Reference in New Issue
Block a user