/// 訂單簿級別 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 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 asks; final List 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 json) { final asksList = (json['asks'] as List?) ?.map((e) => OrderBookLevel.fromJson(e as Map)) .toList() ?? []; final bidsList = (json['bids'] as List?) ?.map((e) => OrderBookLevel.fromJson(e as Map)) .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(), ); } }