68 lines
1.7 KiB
Dart
68 lines
1.7 KiB
Dart
import 'package:equatable/equatable.dart';
|
|
|
|
enum OrderType { buy, sell }
|
|
enum OrderStatus { pending, partial, filled, cancelled }
|
|
|
|
class TradeOrder extends Equatable {
|
|
/// 订单ID
|
|
final String id;
|
|
/// 订单号
|
|
final String orderNo;
|
|
/// 订单类型
|
|
final OrderType orderType;
|
|
/// 订单状态
|
|
final OrderStatus status;
|
|
/// 价格
|
|
final String price;
|
|
/// 数量
|
|
final String quantity;
|
|
/// 已成交数量
|
|
final String filledQuantity;
|
|
/// 剩余数量
|
|
final String remainingQuantity;
|
|
/// 平均成交价格
|
|
final String averagePrice;
|
|
/// 总金额
|
|
final String totalAmount;
|
|
/// 创建时间
|
|
final DateTime createdAt;
|
|
/// 完成时间
|
|
final DateTime? completedAt;
|
|
/// 取消时间
|
|
final DateTime? cancelledAt;
|
|
|
|
const TradeOrder({
|
|
required this.id,
|
|
required this.orderNo,
|
|
required this.orderType,
|
|
required this.status,
|
|
required this.price,
|
|
required this.quantity,
|
|
required this.filledQuantity,
|
|
required this.remainingQuantity,
|
|
required this.averagePrice,
|
|
required this.totalAmount,
|
|
required this.createdAt,
|
|
this.completedAt,
|
|
this.cancelledAt,
|
|
});
|
|
|
|
bool get isBuy => orderType == OrderType.buy;
|
|
bool get isSell => orderType == OrderType.sell;
|
|
bool get isPending => status == OrderStatus.pending;
|
|
bool get isPartial => status == OrderStatus.partial;
|
|
bool get isFilled => status == OrderStatus.filled;
|
|
bool get isCancelled => status == OrderStatus.cancelled;
|
|
|
|
/// 成交进度百分比
|
|
double get fillProgress {
|
|
final qty = double.tryParse(quantity) ?? 0;
|
|
final filled = double.tryParse(filledQuantity) ?? 0;
|
|
if (qty == 0) return 0;
|
|
return filled / qty;
|
|
}
|
|
|
|
@override
|
|
List<Object?> get props => [id, orderNo, orderType, status, price, quantity];
|
|
}
|