k_line_entity.dart 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import '../entity/k_entity.dart';
  2. class KLineEntity extends KEntity {
  3. late double open;
  4. late double high;
  5. late double low;
  6. late double close;
  7. late double vol;
  8. late double? amount;
  9. // late double? turnover;
  10. double? change;
  11. double? ratio;
  12. int? time;
  13. KLineEntity.fromCustom({
  14. this.amount,
  15. required this.open,
  16. required this.close,
  17. this.change,
  18. this.ratio,
  19. required this.time,
  20. required this.high,
  21. required this.low,
  22. required this.vol,
  23. });
  24. KLineEntity.fromJson(Map<String, dynamic> json) {
  25. open = json['open']?.toDouble() ?? 0;
  26. high = json['high']?.toDouble() ?? 0;
  27. low = json['low']?.toDouble() ?? 0;
  28. close = json['close']?.toDouble() ?? 0;
  29. vol = json['vol']?.toDouble() ?? 0;
  30. amount = json['amount']?.toDouble();
  31. int? tempTime = json['time']?.toInt();
  32. //兼容火币数据
  33. if (tempTime == null) {
  34. tempTime = json['id']?.toInt() ?? 0;
  35. tempTime = tempTime! * 1000;
  36. }
  37. time = tempTime;
  38. ratio = json['ratio']?.toDouble();
  39. change = json['change']?.toDouble();
  40. }
  41. Map<String, dynamic> toJson() {
  42. final Map<String, dynamic> data = new Map<String, dynamic>();
  43. data['time'] = this.time;
  44. data['open'] = this.open;
  45. data['close'] = this.close;
  46. data['high'] = this.high;
  47. data['low'] = this.low;
  48. data['vol'] = this.vol;
  49. data['amount'] = this.amount;
  50. data['ratio'] = this.ratio;
  51. data['change'] = this.change;
  52. return data;
  53. }
  54. @override
  55. String toString() {
  56. return 'MarketModel{open: $open, high: $high, low: $low, close: $close, vol: $vol, time: $time, amount: $amount, ratio: $ratio, change: $change}';
  57. }
  58. }