takeOffer method
Takes an offer by providing the offer ID, payment account ID, and amount.
Sends a TakeOfferRequest to take an offer, and if successful, returns the details of the trade. If the client is not connected, a DaemonNotConnectedException is thrown.
Example:
final trade = await tradesService.takeOffer('offerId', 'paymentId', amount);
print('Trade ID: ${trade?.tradeId}');
Returns:
- A
Future
containing theTradeInfo
if the offer is successfully taken. null
if an error occurs.
Implementation
Future<TradeInfo?> takeOffer(
String? offerId, String? paymentAccountId, fixnum.Int64 amount) async {
if (!havenoChannel.isConnected) {
throw DaemonNotConnectedException();
}
try {
final takeOfferReply = await havenoChannel.tradesClient!.takeOffer(
TakeOfferRequest(
offerId: offerId,
paymentAccountId: paymentAccountId,
amount: amount));
return takeOfferReply.trade;
} on GrpcError catch (e) {
handleGrpcError(e);
return null;
}
}