Update 更新文档
This commit is contained in:
272
TradingCore/common_structures/TradingStructures.h
Normal file
272
TradingCore/common_structures/TradingStructures.h
Normal file
@@ -0,0 +1,272 @@
|
||||
#ifndef TRADING_STRUCTURES_H
|
||||
#define TRADING_STRUCTURES_H
|
||||
|
||||
#include <QString>
|
||||
#include <QDateTime>
|
||||
#include <QVariant>
|
||||
#include <QMap>
|
||||
#include <QList>
|
||||
#include <QVector>
|
||||
|
||||
// Basic trading data types
|
||||
namespace Trading {
|
||||
|
||||
// Market types
|
||||
enum class MarketType {
|
||||
HK, // Hong Kong
|
||||
US, // United States
|
||||
CN, // China
|
||||
SG, // Singapore
|
||||
JP, // Japan
|
||||
Unknown
|
||||
};
|
||||
|
||||
// Order types
|
||||
enum class OrderType {
|
||||
Market,
|
||||
Limit,
|
||||
Stop,
|
||||
StopLimit,
|
||||
Iceberg,
|
||||
TWAP,
|
||||
VWAP,
|
||||
Unknown
|
||||
};
|
||||
|
||||
// Order status
|
||||
enum class OrderStatus {
|
||||
Pending,
|
||||
Submitted,
|
||||
PartiallyFilled,
|
||||
Filled,
|
||||
Cancelled,
|
||||
Rejected,
|
||||
Expired,
|
||||
Unknown
|
||||
};
|
||||
|
||||
// Order side
|
||||
enum class OrderSide {
|
||||
Buy,
|
||||
Sell,
|
||||
Short,
|
||||
Cover,
|
||||
Unknown
|
||||
};
|
||||
|
||||
// Basic stock information
|
||||
struct StockInfo {
|
||||
QString symbol;
|
||||
QString name;
|
||||
MarketType market;
|
||||
QString currency;
|
||||
double pricePrecision = 0.01;
|
||||
int quantityPrecision = 1;
|
||||
double minTradeAmount = 0.0;
|
||||
double maxTradeAmount = 0.0;
|
||||
bool isTradable = true;
|
||||
|
||||
StockInfo() = default;
|
||||
StockInfo(const QString& sym, const QString& nm, MarketType mkt)
|
||||
: symbol(sym), name(nm), market(mkt) {}
|
||||
};
|
||||
|
||||
// Real-time quote data
|
||||
struct QuoteData {
|
||||
QString symbol;
|
||||
QDateTime timestamp;
|
||||
double lastPrice = 0.0;
|
||||
double openPrice = 0.0;
|
||||
double highPrice = 0.0;
|
||||
double lowPrice = 0.0;
|
||||
double closePrice = 0.0;
|
||||
double volume = 0.0;
|
||||
double turnover = 0.0;
|
||||
double bidPrice = 0.0;
|
||||
double askPrice = 0.0;
|
||||
qint64 bidVolume = 0;
|
||||
qint64 askVolume = 0;
|
||||
double change = 0.0;
|
||||
double changePercent = 0.0;
|
||||
|
||||
bool isValid() const {
|
||||
return !symbol.isEmpty() && timestamp.isValid() && lastPrice > 0;
|
||||
}
|
||||
};
|
||||
|
||||
// Order book level
|
||||
struct OrderBookLevel {
|
||||
double price = 0.0;
|
||||
qint64 volume = 0;
|
||||
int orderCount = 0;
|
||||
|
||||
OrderBookLevel() = default;
|
||||
OrderBookLevel(double p, qint64 v, int count = 1)
|
||||
: price(p), volume(v), orderCount(count) {}
|
||||
};
|
||||
|
||||
// Complete order book
|
||||
struct OrderBook {
|
||||
QString symbol;
|
||||
QDateTime timestamp;
|
||||
QVector<OrderBookLevel> bids; // Buy side, sorted descending by price
|
||||
QVector<OrderBookLevel> asks; // Sell side, sorted ascending by price
|
||||
|
||||
bool isValid() const {
|
||||
return !symbol.isEmpty() && timestamp.isValid();
|
||||
}
|
||||
|
||||
double getSpread() const {
|
||||
if (bids.isEmpty() || asks.isEmpty()) return 0.0;
|
||||
return asks.first().price - bids.first().price;
|
||||
}
|
||||
|
||||
double getMidPrice() const {
|
||||
if (bids.isEmpty() || asks.isEmpty()) return 0.0;
|
||||
return (bids.first().price + asks.first().price) / 2.0;
|
||||
}
|
||||
};
|
||||
|
||||
// Trading order
|
||||
struct Order {
|
||||
QString orderId;
|
||||
QString symbol;
|
||||
OrderType type = OrderType::Limit;
|
||||
OrderSide side = OrderSide::Buy;
|
||||
OrderStatus status = OrderStatus::Pending;
|
||||
double price = 0.0;
|
||||
qint64 quantity = 0;
|
||||
qint64 filledQuantity = 0;
|
||||
double filledAmount = 0.0;
|
||||
QDateTime createTime;
|
||||
QDateTime updateTime;
|
||||
QString accountId;
|
||||
QString strategyId;
|
||||
QVariant customData;
|
||||
|
||||
bool isValid() const {
|
||||
return !orderId.isEmpty() && !symbol.isEmpty() && quantity > 0;
|
||||
}
|
||||
|
||||
double getAveragePrice() const {
|
||||
return filledQuantity > 0 ? filledAmount / filledQuantity : 0.0;
|
||||
}
|
||||
|
||||
qint64 getRemainingQuantity() const {
|
||||
return quantity - filledQuantity;
|
||||
}
|
||||
};
|
||||
|
||||
// Trade execution
|
||||
struct Trade {
|
||||
QString tradeId;
|
||||
QString orderId;
|
||||
QString symbol;
|
||||
OrderSide side = OrderSide::Buy;
|
||||
double price = 0.0;
|
||||
qint64 quantity = 0;
|
||||
double amount = 0.0;
|
||||
QDateTime tradeTime;
|
||||
QString exchangeId;
|
||||
|
||||
bool isValid() const {
|
||||
return !tradeId.isEmpty() && !orderId.isEmpty() && quantity > 0 && price > 0;
|
||||
}
|
||||
};
|
||||
|
||||
// Position information
|
||||
struct Position {
|
||||
QString symbol;
|
||||
QString accountId;
|
||||
qint64 quantity = 0;
|
||||
qint64 availableQuantity = 0;
|
||||
double averagePrice = 0.0;
|
||||
double marketValue = 0.0;
|
||||
double unrealizedPnl = 0.0;
|
||||
double realizedPnl = 0.0;
|
||||
QDateTime updateTime;
|
||||
|
||||
bool isValid() const {
|
||||
return !symbol.isEmpty() && !accountId.isEmpty();
|
||||
}
|
||||
};
|
||||
|
||||
// Account information
|
||||
struct AccountInfo {
|
||||
QString accountId;
|
||||
QString accountName;
|
||||
double totalAssets = 0.0;
|
||||
double availableCash = 0.0;
|
||||
double frozenCash = 0.0;
|
||||
double margin = 0.0;
|
||||
double totalPnl = 0.0;
|
||||
double todayPnl = 0.0;
|
||||
QDateTime updateTime;
|
||||
|
||||
bool isValid() const {
|
||||
return !accountId.isEmpty();
|
||||
}
|
||||
};
|
||||
|
||||
// System configuration
|
||||
struct SystemConfig {
|
||||
// Trading parameters
|
||||
double defaultOrderSize = 1000;
|
||||
double maxOrderSize = 10000;
|
||||
double minOrderSize = 100;
|
||||
int orderTimeoutSeconds = 30;
|
||||
|
||||
// Risk parameters
|
||||
double maxPositionValue = 1000000.0;
|
||||
double maxDailyLoss = 50000.0;
|
||||
double maxSingleOrderValue = 100000.0;
|
||||
|
||||
// Connection parameters
|
||||
int heartbeatIntervalMs = 5000;
|
||||
int reconnectTimeoutMs = 10000;
|
||||
int maxReconnectAttempts = 3;
|
||||
|
||||
// Data parameters
|
||||
int dataBufferSize = 10000;
|
||||
int maxDataRatePerSecond = 1000;
|
||||
bool enableDataCompression = true;
|
||||
|
||||
// Logging parameters
|
||||
bool enableDebugLog = false;
|
||||
int logRetentionDays = 30;
|
||||
QString logLevel = "INFO";
|
||||
};
|
||||
|
||||
// Performance metrics
|
||||
struct PerformanceMetrics {
|
||||
double totalReturn = 0.0;
|
||||
double dailyReturn = 0.0;
|
||||
double sharpeRatio = 0.0;
|
||||
double maxDrawdown = 0.0;
|
||||
double winRate = 0.0;
|
||||
double profitFactor = 0.0;
|
||||
int totalTrades = 0;
|
||||
int winningTrades = 0;
|
||||
int losingTrades = 0;
|
||||
double averageWin = 0.0;
|
||||
double averageLoss = 0.0;
|
||||
QDateTime periodStart;
|
||||
QDateTime periodEnd;
|
||||
|
||||
void updateMetrics(bool isWin, double pnl) {
|
||||
totalTrades++;
|
||||
if (isWin) {
|
||||
winningTrades++;
|
||||
averageWin = (averageWin * (winningTrades - 1) + pnl) / winningTrades;
|
||||
} else {
|
||||
losingTrades++;
|
||||
averageLoss = (averageLoss * (losingTrades - 1) + pnl) / losingTrades;
|
||||
}
|
||||
winRate = static_cast<double>(winningTrades) / totalTrades;
|
||||
profitFactor = (averageWin * winningTrades) / (std::abs(averageLoss) * losingTrades);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Trading
|
||||
|
||||
#endif // TRADING_STRUCTURES_H
|
||||
Reference in New Issue
Block a user