111
This commit is contained in:
@@ -14,6 +14,12 @@ class Coin {
|
||||
final double? volume24h;
|
||||
final int status;
|
||||
final int sort;
|
||||
final int isPlatform;
|
||||
final double? todayProfitRate; // 今日盈利比率(平台代币)
|
||||
final String? tradeStartAm;
|
||||
final String? tradeEndAm;
|
||||
final String? tradeStartPm;
|
||||
final String? tradeEndPm;
|
||||
|
||||
Coin({
|
||||
required this.id,
|
||||
@@ -30,6 +36,12 @@ class Coin {
|
||||
this.volume24h,
|
||||
required this.status,
|
||||
this.sort = 0,
|
||||
this.isPlatform = 0,
|
||||
this.todayProfitRate,
|
||||
this.tradeStartAm,
|
||||
this.tradeEndAm,
|
||||
this.tradeStartPm,
|
||||
this.tradeEndPm,
|
||||
});
|
||||
|
||||
factory Coin.fromJson(Map<String, dynamic> json) {
|
||||
@@ -48,6 +60,12 @@ class Coin {
|
||||
volume24h: (json['volume24h'] as num?)?.toDouble(),
|
||||
status: json['status'] as int? ?? 1,
|
||||
sort: json['sort'] as int? ?? 0,
|
||||
isPlatform: json['isPlatform'] as int? ?? 0,
|
||||
todayProfitRate: (json['todayProfitRate'] as num?)?.toDouble(),
|
||||
tradeStartAm: json['tradeStartAm'] as String?,
|
||||
tradeEndAm: json['tradeEndAm'] as String?,
|
||||
tradeStartPm: json['tradeStartPm'] as String?,
|
||||
tradeEndPm: json['tradeEndPm'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -67,6 +85,7 @@ class Coin {
|
||||
'volume24h': volume24h,
|
||||
'status': status,
|
||||
'sort': sort,
|
||||
'isPlatform': isPlatform,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ class OrderTrade {
|
||||
final String price;
|
||||
final String quantity;
|
||||
final String amount;
|
||||
final int status; // 1=待處理, 2=已完成, 3=已取消
|
||||
final int status; // 0=委托中, 1=已成交, 2=失败, 3=已取消
|
||||
final int? orderType; // 1=市价单, 2=限价单
|
||||
final DateTime? createTime;
|
||||
final DateTime? updateTime;
|
||||
|
||||
@@ -22,6 +23,7 @@ class OrderTrade {
|
||||
required this.quantity,
|
||||
required this.amount,
|
||||
required this.status,
|
||||
this.orderType,
|
||||
this.createTime,
|
||||
this.updateTime,
|
||||
});
|
||||
@@ -37,6 +39,7 @@ class OrderTrade {
|
||||
quantity: json['quantity']?.toString() ?? '0',
|
||||
amount: json['amount']?.toString() ?? '0.00',
|
||||
status: json['status'] as int? ?? 1,
|
||||
orderType: json['orderType'] as int?,
|
||||
createTime: json['createTime'] != null
|
||||
? DateTime.tryParse(json['createTime'])
|
||||
: null,
|
||||
@@ -52,10 +55,12 @@ class OrderTrade {
|
||||
/// 狀態文字
|
||||
String get statusText {
|
||||
switch (status) {
|
||||
case 0:
|
||||
return '委托中';
|
||||
case 1:
|
||||
return '待處理';
|
||||
return '已成交';
|
||||
case 2:
|
||||
return '已完成';
|
||||
return '失败';
|
||||
case 3:
|
||||
return '已取消';
|
||||
default:
|
||||
@@ -63,8 +68,14 @@ class OrderTrade {
|
||||
}
|
||||
}
|
||||
|
||||
/// 是否为委托中
|
||||
bool get isPending => status == 0;
|
||||
|
||||
/// 是否為買入
|
||||
bool get isBuy => direction == 1;
|
||||
|
||||
/// 订单类型文字
|
||||
String get orderTypeText => orderType == 2 ? '限价' : '市价';
|
||||
}
|
||||
|
||||
/// 充提訂單模型
|
||||
|
||||
@@ -53,4 +53,17 @@ class MarketService {
|
||||
}
|
||||
return ApiResponse.fail(response.message ?? '搜索失敗');
|
||||
}
|
||||
|
||||
/// 獲取訂單簿深度
|
||||
Future<ApiResponse<Map<String, dynamic>>> getDepth(String code) async {
|
||||
final response = await _client.get<Map<String, dynamic>>(
|
||||
ApiEndpoints.marketDepth,
|
||||
queryParameters: {'code': code},
|
||||
);
|
||||
|
||||
if (response.success && response.data != null) {
|
||||
return ApiResponse.success(response.data!, response.message);
|
||||
}
|
||||
return ApiResponse.fail(response.message ?? '獲取深度失敗');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ class TradeService {
|
||||
required String coinCode,
|
||||
required String price,
|
||||
required String quantity,
|
||||
int orderType = 1, // 1=市价单, 2=限价单
|
||||
}) async {
|
||||
return _client.post<Map<String, dynamic>>(
|
||||
ApiEndpoints.buy,
|
||||
@@ -21,6 +22,7 @@ class TradeService {
|
||||
'coinCode': coinCode,
|
||||
'price': price,
|
||||
'quantity': quantity,
|
||||
'orderType': orderType,
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -30,6 +32,7 @@ class TradeService {
|
||||
required String coinCode,
|
||||
required String price,
|
||||
required String quantity,
|
||||
int orderType = 1, // 1=市价单, 2=限价单
|
||||
}) async {
|
||||
return _client.post<Map<String, dynamic>>(
|
||||
ApiEndpoints.sell,
|
||||
@@ -37,6 +40,7 @@ class TradeService {
|
||||
'coinCode': coinCode,
|
||||
'price': price,
|
||||
'quantity': quantity,
|
||||
'orderType': orderType,
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -76,4 +80,12 @@ class TradeService {
|
||||
}
|
||||
return ApiResponse.fail(response.message ?? '獲取訂單詳情失敗');
|
||||
}
|
||||
|
||||
/// 撤销限价委托
|
||||
Future<ApiResponse<Map<String, dynamic>>> cancelOrder(String orderNo) async {
|
||||
return _client.post<Map<String, dynamic>>(
|
||||
ApiEndpoints.tradeCancel,
|
||||
data: {'orderNo': orderNo},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user