getTrades method
Retrieves all trades from the Haveno gRPC server.
This method sends a GetTradesRequest to fetch all available trades. If the Haveno client is not connected, a DaemonNotConnectedException is thrown.
Example:
final trades = await tradesService.getTrades();
if (trades != null) {
for (final trade in trades) {
print('Trade ID: ${trade.tradeId}');
}
}
Returns:
- A
Future
containing aList<TradeInfo>
of available trades. - An empty list if an error occurs.
Throws:
- DaemonNotConnectedException if the client is not connected to the gRPC server.
Implementation
Future<List<TradeInfo>?> getTrades() async {
if (!havenoChannel.isConnected) {
throw DaemonNotConnectedException();
}
try {
final getTradesReply =
await havenoChannel.tradesClient!.getTrades(GetTradesRequest());
return getTradesReply.trades;
} on GrpcError catch (e) {
handleGrpcError(e);
}
return [];
}