companyNews method

  1. @override
Future<List<News>> companyNews(
  1. SecurityIdentifier id
)
override

The news method is used to get the news for a given stock symbol.

The id argument is used to specify the stock id.

// Get news for Apple
final client = BavestRestClient(api_key);
final news = client.news(SecurityIdentifier(symbol: "AAPL"));

Implementation

@override
Future<List<News>> companyNews(SecurityIdentifier id) async {
  const url = '$_baseUrl/stock/news';
  final params = id.toJson();

  var response = await _post(url, params);
  if (_isSuccess(response)) {
    dynamic data = jsonDecode(response!.data);
    return data.map<News>((e) => News.fromJson(e)).toList();
  }

  throw Exception("Failed to get news for $id");
}