Update 更新文档
This commit is contained in:
91
TradingCore/data_processing/OrderProcessor.h
Normal file
91
TradingCore/data_processing/OrderProcessor.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
订单处理类
|
||||
- 维护一个线程池,用于处理接收到的订单数据
|
||||
- 检测大单
|
||||
单笔订单股票数量大于指定阈值,会被认定为大单
|
||||
*/
|
||||
#ifndef QORDERPROCESSOR_H
|
||||
#define QORDERPROCESSOR_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
#include <QThreadPool>
|
||||
#include <QMutex>
|
||||
#include <QCache>
|
||||
#include <QtConcurrent\QtConcurrent>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include "BZStruct.h"
|
||||
#include "qeventbus.h"
|
||||
#include "ObjectPool.h"
|
||||
|
||||
#include "tool.h"
|
||||
#include "..\Sqbase\OrderBookParser.h"
|
||||
|
||||
class QOrderProcessor : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QOrderProcessor(QObject *parent = nullptr);
|
||||
~QOrderProcessor();
|
||||
|
||||
void setProcessingEnabled(bool enabled);
|
||||
void processOrderBook(const Qot_UpdateOrderBook::Response &stRsp);
|
||||
|
||||
//void batchProcess(const QVector<QByteArray>& jsonDataList);
|
||||
void setreplyCodeQuantity(QMap<QString, float> CodeQuantity)
|
||||
{
|
||||
m_replyCodeQuantity = CodeQuantity;
|
||||
}
|
||||
|
||||
// 性能监控接口
|
||||
size_t getCacheHitRate() const { return m_cacheHits; }
|
||||
size_t getCacheMissRate() const { return m_cacheMisses; }
|
||||
double getCacheHitRatio() const {
|
||||
return (m_cacheHits + m_cacheMisses) > 0 ?
|
||||
static_cast<double>(m_cacheHits) / (m_cacheHits + m_cacheMisses) : 0.0;
|
||||
}
|
||||
|
||||
public:
|
||||
OrderBookParser parser;
|
||||
|
||||
signals:
|
||||
// 基础信号
|
||||
void maxOrderReady(BigOrderInfo bigOrderInfo);
|
||||
|
||||
// 状态信号
|
||||
void processingStarted(const QString& code);
|
||||
void processingFinished(const QString& code);
|
||||
void errorOccurred(const QString& code, const QString& error);
|
||||
|
||||
private:
|
||||
QVector<BigOrderInfo> findExtremeOrders(const OrderBookData& data) const;
|
||||
OrderBookEntry findMaxVolumeItemEx(const QVector<OrderBookEntry>& items, double volumeRatio) const;
|
||||
QVector<BigOrderInfo> findMaxVolumeItem(const OrderBookData& data) const;
|
||||
OrderBookEntry findMinPriceItem(const QVector<OrderBookEntry>& items) const;
|
||||
|
||||
// 缓存相关方法
|
||||
bool getCachedResult(const QString& cacheKey, QVector<BigOrderInfo>& result) const;
|
||||
void cacheResult(const QString& cacheKey, const QVector<BigOrderInfo>& result) const;
|
||||
|
||||
double sumQuantity(const QVector<OrderBookEntry>& items) const;
|
||||
|
||||
void internalProcess(const OrderBookData& orderData);
|
||||
|
||||
QThreadPool m_threadPool;
|
||||
mutable QMutex m_dataMutex;
|
||||
bool m_enabled = true;
|
||||
QSet<QString> m_processingCodes;
|
||||
|
||||
QMap<QString, float> m_replyCodeQuantity;
|
||||
|
||||
// 性能优化成员 - 手动缓存实现
|
||||
mutable QMap<QString, QVector<BigOrderInfo>> m_orderCache;
|
||||
mutable QList<QString> m_cacheKeys;
|
||||
mutable size_t m_cacheHits = 0;
|
||||
mutable size_t m_cacheMisses = 0;
|
||||
mutable QMutex m_cacheMutex;
|
||||
size_t m_cacheMaxSize = 200;
|
||||
};
|
||||
|
||||
#endif // QORDERPROCESSOR_H
|
||||
Reference in New Issue
Block a user