This commit is contained in:
sion
2026-04-21 08:12:17 +08:00
parent 5264043c21
commit 685202dd55
247 changed files with 18661 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
/// 訂單簿級別
class OrderBookLevel {
final double price;
final double quantity;
final double cumulative;
const OrderBookLevel({
required this.price,
required this.quantity,
this.cumulative = 0,
});
factory OrderBookLevel.fromJson(Map<String, dynamic> json) {
return OrderBookLevel(
price: (json['price'] as num).toDouble(),
quantity: (json['quantity'] as num).toDouble(),
cumulative: (json['cumulative'] as num?)?.toDouble() ?? 0,
);
}
String get formattedPrice {
if (price >= 1000) return price.toStringAsFixed(2);
return price.toStringAsFixed(4);
}
String get formattedQuantity {
if (quantity >= 1000) return quantity.toStringAsFixed(0);
if (quantity >= 1) return quantity.toStringAsFixed(2);
return quantity.toStringAsFixed(4);
}
}
/// 訂單簿深度(含實時價格)
class OrderBookDepth {
final List<OrderBookLevel> asks;
final List<OrderBookLevel> bids;
final double spread;
final double spreadPercent;
final double currentPrice;
final double change24h;
final double high24h;
final double low24h;
final double volume24h;
final String tradingStatus; // "trading" / "lunch_break" / "closed"
final double? targetLow;
final double? targetHigh;
final double? targetClose;
const OrderBookDepth({
required this.asks,
required this.bids,
required this.spread,
required this.spreadPercent,
this.currentPrice = 0,
this.change24h = 0,
this.high24h = 0,
this.low24h = 0,
this.volume24h = 0,
this.tradingStatus = 'trading',
this.targetLow,
this.targetHigh,
this.targetClose,
});
factory OrderBookDepth.fromJson(Map<String, dynamic> json) {
final asksList = (json['asks'] as List?)
?.map((e) => OrderBookLevel.fromJson(e as Map<String, dynamic>))
.toList() ??
[];
final bidsList = (json['bids'] as List?)
?.map((e) => OrderBookLevel.fromJson(e as Map<String, dynamic>))
.toList() ??
[];
return OrderBookDepth(
asks: asksList,
bids: bidsList,
spread: (json['spread'] as num?)?.toDouble() ?? 0,
spreadPercent: (json['spreadPercent'] as num?)?.toDouble() ?? 0,
currentPrice: (json['currentPrice'] as num?)?.toDouble() ?? 0,
change24h: (json['change24h'] as num?)?.toDouble() ?? 0,
high24h: (json['high24h'] as num?)?.toDouble() ?? 0,
low24h: (json['low24h'] as num?)?.toDouble() ?? 0,
volume24h: (json['volume24h'] as num?)?.toDouble() ?? 0,
tradingStatus: json['tradingStatus'] as String? ?? 'trading',
targetLow: (json['targetLow'] as num?)?.toDouble(),
targetHigh: (json['targetHigh'] as num?)?.toDouble(),
targetClose: (json['targetClose'] as num?)?.toDouble(),
);
}
}