Files
QTradeProgram/cleaned_source_code/QMainwindow/BZStruct.h

72 lines
1.9 KiB
C
Raw Normal View History

2026-02-25 23:01:42 +08:00
#pragma once
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonDocument>
#include <QVector>
struct OrderDetail {
double volume = 0.0;
long long orderId = 0;
};
struct OrderBookEntry {
double price = 0.0;
double volume = 0.0;
int orderCount = 0;
QString code = "";
QVector<OrderDetail> details;
bool isValid() const {
return price > 0 && volume > 0 && !details.isEmpty();
}
};
struct OrderBookData {
QString name = "";
QString code = "";
QString askTime = "";
QString bidTime = "";
QVector<OrderBookEntry> bids;
QVector<OrderBookEntry> asks;
void clear() {
bids.clear();
asks.clear();
}
bool isEmpty() const { return bids.isEmpty() && asks.isEmpty(); }
};
struct BigOrderInfo {
double price = 0.0;
double volume = 0.0;
long long orderId = 0;
int nBigOrderType = 1;
int level = 1;
bool isBigOrder = false;
QString name = "";
QString code = "";
QString svrRecvTime = "";
QJsonObject toJson() const {
return{
{ "isBigOrder", isBigOrder },
{ "nBigOrderType", nBigOrderType },
{ "orderId", orderId },
{ "name", name },
{ "code", code },
{ "price", price },
{ "volume", volume },
{ "level", level },
{ "svrRecvTime", svrRecvTime }
};
}
static BigOrderInfo fromJson(const QJsonObject& json) {
BigOrderInfo info;
info.isBigOrder = json.value("isBigOrder").toBool(false);
info.nBigOrderType = json.value("nBigOrderType").toInt(1);
bool ok = false;
info.orderId = json.value("orderId").toString().toLongLong(&ok);
if (!ok) info.orderId = 0;
info.name = json.value("name").toString("");
info.code = json.value("code").toString("");
info.price = json.value("price").toDouble(0.0);
info.volume = json.value("volume").toDouble(0.0);
info.level = json.value("level").toInt(1);
info.svrRecvTime = json.value("svrRecvTime").toString("");
return info;
}
};
Q_DECLARE_METATYPE(BigOrderInfo)