getTradeStatistics method
Retrieves trade statistics from the Haveno gRPC server.
This method sends a GetTradeStatisticsRequest to the Haveno server and expects
a GetTradeStatisticsReply in response, containing a list of TradeStatistics3
.
If the client is not connected to the gRPC server, a DaemonNotConnectedException
is thrown.
Example:
try {
final tradeStats = await tradeClient.getTradeStatistics();
if (tradeStats != null) {
for (final stat in tradeStats) {
print('Total Trades: ${stat.totalTrades}');
}
}
} catch (e) {
print('Error fetching trade statistics: $e');
}
Returns:
- A
Future
that resolves to aList<TradeStatistics3>?
containing the trade statistics, or an empty list[]
if no statistics are found or an error occurs.
Throws:
- DaemonNotConnectedException if the Haveno client is not connected to the server.
- Catches
GrpcError
to handle any gRPC-specific errors.
Implementation
Future<List<TradeStatistics3>?> getTradeStatistics() async {
// Ensure the Haveno client is connected.
if (!havenoChannel.isConnected) {
throw DaemonNotConnectedException();
}
try {
// Get the trade statistics client from Haveno.
GetTradeStatisticsClient? tradeStatisticsClient =
havenoChannel.tradeStatisticsClient;
// Request trade statistics from the server.
GetTradeStatisticsReply? tradeStatisticsReply =
await tradeStatisticsClient
?.getTradeStatistics(GetTradeStatisticsRequest());
// Return the list of trade statistics from the response.
return tradeStatisticsReply!.tradeStatistics;
} on GrpcError catch (e) {
// Handle gRPC errors using the GrpcErrorHandler mixin.
handleGrpcError(e);
}
// Return an empty list if an error occurs.
return [];
}