39 lines
984 B
Dart
39 lines
984 B
Dart
/// K 线数据模型
|
|
class Candle {
|
|
final int timestamp; // 毫秒时间戳
|
|
final double open;
|
|
final double high;
|
|
final double low;
|
|
final double close;
|
|
final double volume;
|
|
|
|
const Candle({
|
|
required this.timestamp,
|
|
required this.open,
|
|
required this.high,
|
|
required this.low,
|
|
required this.close,
|
|
required this.volume,
|
|
});
|
|
|
|
factory Candle.fromJson(Map<String, dynamic> json) {
|
|
return Candle(
|
|
timestamp: json['timestamp'] as int? ?? json['time'] as int? ?? 0,
|
|
open: (json['open'] as num?)?.toDouble() ?? 0,
|
|
high: (json['high'] as num?)?.toDouble() ?? 0,
|
|
low: (json['low'] as num?)?.toDouble() ?? 0,
|
|
close: (json['close'] as num?)?.toDouble() ?? 0,
|
|
volume: (json['volume'] as num?)?.toDouble() ?? 0,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'timestamp': timestamp,
|
|
'open': open,
|
|
'high': high,
|
|
'low': low,
|
|
'close': close,
|
|
'volume': volume,
|
|
};
|
|
}
|