alpaca_dart 0.0.1 copy "alpaca_dart: ^0.0.1" to clipboard
alpaca_dart: ^0.0.1 copied to clipboard

outdated

Dart wrapper for the Alpaca REST API.

A Dart wrapper for the Alpaca REST API.

Examples #

Fetch the last 2 closing prices for the S&P, Nasdaq, and Dow Jones indices.

import 'dart:convert';

import 'package:alpaca_dart/alpaca_dart.dart';

main() async {
  var alpaca = AlpacaApi(
    keyId: '...',
    secretKey: '...',
    paperTrading: true,
  );

  final accountResponse = await alpaca.getAccount();
  final account = jsonDecode(accountResponse.body);

  final status = account['status'] == 'ACTIVE' ? 'Active' : 'Inactive';

  print('Account ID: ${account['id']}');
  print('Account status: $status');
  print('Cash value: ${account['cash']}');
  print('Portfolio value: ${account['portfolio_value']}');
  print('\n');

  final watchlist = ['SPY', 'DIA', 'QQQ'];
  final timeframe = 'day', limit = 2;

  final barsResponse = await alpaca.getBars(timeframe, watchlist, limit: limit);
  final barsJson = jsonDecode(barsResponse.body);

  for (final symbol in watchlist) {
    final bars = barsJson[symbol];

    for (final bar in bars) {
      print('(${bar['t']}): ${bar['c']}');
    }
  }
}
}

Issues and bugs #

Please file feature requests and bugs at the issue tracker.

0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Dart wrapper for the Alpaca REST API.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

mockito

More

Packages that depend on alpaca_dart