copy_account.dart 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /// 跟单账户权益
  2. class CopyAccount {
  3. final double equity; // 总权益 USDT
  4. final double todayPnl; // 今日盈亏 USDT
  5. final double totalPnl; // 总盈亏 USDT
  6. final double todayFee; // 今日手续费 USDT
  7. final double cumulativePnl; // 累计跟单收益 USDT
  8. final double availableBalance; // 可用资产 USDT
  9. final double unrealizedPnl; // 未实现盈亏 USDT
  10. const CopyAccount({
  11. required this.equity,
  12. required this.todayPnl,
  13. required this.totalPnl,
  14. required this.todayFee,
  15. this.cumulativePnl = 0,
  16. this.availableBalance = 0,
  17. this.unrealizedPnl = 0,
  18. });
  19. CopyAccount copyWith({double? unrealizedPnl}) => CopyAccount(
  20. equity: equity,
  21. todayPnl: todayPnl,
  22. totalPnl: totalPnl,
  23. todayFee: todayFee,
  24. cumulativePnl: cumulativePnl,
  25. availableBalance: availableBalance,
  26. unrealizedPnl: unrealizedPnl ?? this.unrealizedPnl,
  27. );
  28. /// 从 API follow-wallet/get 响应构建
  29. /// Android 字段映射(FollowRes.kt FollowWallet):
  30. /// totalRevenue → 累计跟单收益(Kotlin 属性名 totalProfit,但 JSON key 是 totalRevenue)
  31. /// currentRevenue → 未实现盈亏
  32. /// currentCapital → 账户权益
  33. /// availableBalance → 可用资产
  34. factory CopyAccount.fromApi(Map<String, dynamic> json) {
  35. double _d(String key) =>
  36. double.tryParse((json[key] ?? '0').toString()) ?? 0.0;
  37. return CopyAccount(
  38. equity: _d('currentCapital'),
  39. todayPnl: _d('currentRevenue'),
  40. totalPnl: _d('totalRevenue'),
  41. todayFee: 0,
  42. cumulativePnl: _d('totalRevenue'),
  43. availableBalance: _d('availableBalance'),
  44. unrealizedPnl: _d('currentRevenue'),
  45. );
  46. }
  47. }