getTrades method

Future<List<TradeInfo>?> getTrades()

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 a List<TradeInfo> of available trades.
  • An empty list if an error occurs.

Throws:

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 [];
}