peersWidget method
The peersWidget endpoint returns a list of peers for a given stock symbol. The list contains the symbol, name and logo of the peers.
The id
argument is used to specify the stock id.
// Get peers for Apple
final client = BavestRestClient(api_key);
final peers = client.peersWidget(SecurityIdentifier(symbol: "AAPL"));
Implementation
@override
Future<List<PeersWidget>> peersWidget(SecurityIdentifier id) async {
const url = '$_baseUrl/widgets/stock/peers';
final params = id.toJson();
var response = await _post(url, params);
if (_isSuccess(response)) {
dynamic peers = jsonDecode(response!.data);
if (peers is List) {
return peers.map((e) => PeersWidget.fromJson(e)).toList();
} else {
return [PeersWidget.fromJson(peers)];
}
}
throw Exception("could not get data for $id");
}