splits method

  1. @override
Future<Splits> splits(
  1. SecurityIdentifier id, {
  2. int years = 1,
})
override

The splits method is used to get the splits for a given stock symbol. The id argument is used to specify the stock id. The years argument is used to specify the number of years to get the splits for.

// Get splits for Apple in the last 5 years
final client = BavestRestClient(api_key);
final splits = client.splits(SecurityIdentifier(symbol: "AAPL"), years: 5);

Implementation

@override
Future<Splits> splits(SecurityIdentifier id, {final int years = 1}) async {
  const url = '$_baseUrl/stock/split';
  var from = DateTime.now()
      .subtract(Duration(days: 365 * years))
      .millisecondsSinceEpoch;
  var to = DateTime.now().millisecondsSinceEpoch;
  final params = {
    'from': from.toString(),
    'to': to.toString(),
  }..addAll(id.toJson());

  var response = await _post(url, params);
  if (_isSuccess(response)) {
    return Splits.fromJson(jsonDecode(response!.data));
  }

  throw Exception("could not receive esg data for $id");
}