66 lines
1.8 KiB
C++
66 lines
1.8 KiB
C++
/*
|
|
订单处理类
|
|
- 维护一个线程池,用于处理接收到的订单数据
|
|
- 检测大单
|
|
单笔订单股票数量大于指定阈值,会被认定为大单
|
|
*/
|
|
#ifndef QORDERPROCESSOR_H
|
|
#define QORDERPROCESSOR_H
|
|
|
|
#include <QObject>
|
|
#include <QVector>
|
|
#include <QThreadPool>
|
|
#include <QMutex>
|
|
#include <QtConcurrent\QtConcurrent>
|
|
#include "BZStruct.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;
|
|
}
|
|
|
|
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;
|
|
|
|
double QOrderProcessor::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;
|
|
};
|
|
|
|
#endif // QORDERPROCESSOR_H
|