Git Product home page Git Product logo

flutter_alpaca_markets's Introduction

Alpaca Markets

pub package

Contributors Forks Stargazers Issues MIT License

Introduction

A wrapper for the Alpaca Markets trading APIs. Provides an easy dart-specific way of working with the broker, trading, and market data requests.

For information on Alpaca Markets and their APIs, see the documentation on Alpaca Market's Overview.

Prerequisites

The APIs require that you signup as either a trader or a broker, depending on the type of app you are developing. Visit https://alpaca.markets/ to sign up.

Usage

To use this plugin, add alpaca_markets as a dependency in your pubspec.yaml file.

Examples

Here are small examples that show you how to use the API. The examples provided do not show all return values, parameters, and even functions that are available. Please review the documentation for additional information.

Create a context

Use your generated live and/or paper keys to create a context for querying.

import 'package:alpaca_markets/alpaca_markets.dart' as alpaca;

alpaca.Context liveContext = alpaca.createLiveContext(
        "<Insert live key>", "<Insert live secret key>");

alpaca.Context paperContext = alpaca.createPaperContext(
        "<Insert paper key>", "<Insert paper secret key>");

Retrieve and update account info and assets

The Account and AccountConfigs classes are available for viewing the fields of data.

alpaca.Account? account = await alpaca.getAccount();
alpaca.AccountConfigs? configs = await alpaca.getAccountConfigs();
await alpaca.updateAccountConfigs(tradeConfirmEmail: "none");

Asset retrieval

Additional parameters for the getAssets() request include asset status, asset class, and exchange filters.

The Asset class is available for viewing the fields of data.

alpaca.Asset? asset = await alpaca.getAsset("GRMN");
List<alpaca.Asset>? assets = await alpaca.getAssets();

Portfolio operations

Additional parameters for the getPortfolioHistory() request can be found in the documentation.

The PortfolioHistory class is available for viewing the fields of data.

alpaca.PortfolioHistory? portfolioHistory = await alpaca.getPortfolioHistory();

Add, edit, and delete watchlists

A watchlist can be added to an Alpaca account through their web portal, but the APIs can provide multiple watchlists and support them all using the following example.

// Create a watchlist
alpaca.Watchlist? watchlist = await alpaca.createWatchlist("My Watchlist", symbols: ["AAPL", "GOOG"]);
// Get the watchlists
List<alpaca.Watchlist>? watchlists = await alpaca.getWatchlists(withAssets: false);
watchlist = await alpaca.getWatchlist(watchlist?.id);
// Update the watchlist name and symbols
await alpaca.updateWatchlist(watchlist?.id, name: "My Watchlist Plus", symbols: ["GRMN", "TSLA"]);
// Add a new symbol
await alpaca.addWatchlistSymbol(watchlist?.id, "GME");
// Delete the symbol
await alpaca.deleteWatchlistSymbol(watchlist?.id, "GME");
// Delete the watchlist
await alpaca.deleteWatchlist(watchlist?.id);
// Delete all watchlists
await alpaca.deleteAllWatchlists();

Calendar and market clock

The calendar API provides a way to request a range of dates that the market is open for, with the date, open, and close timestamps. The market clock is the current time, whether the market is open, when the market opens next, and when the market closes next.

/// Retrieve a specific date
alpaca.Calendar? calendar = await alpaca.getCalendarDate(const DateTime(2022, 11, 1));
/// Retrieves a range of dates
List<alpaca.Calendar>? calendars = await alpaca.getCalendarDates(
    start: const DateTime(2022, 10, 25), end: const DateTime(2022, 10, 31));
/// Retrieve the market clock
alpaca.Clock? clock = await alpaca.getMarketClock();

Announcements

Additional parameters for the getAnnouncements().

The Announcement class is available for viewing the fields of data.

List<alpaca.Announcement>? announcements = await alpaca.getAnnouncements("Dividend",
        DateTime.now().subtract(const Duration(days: 75)), DateTime.now());
alpaca.Announcement? announcement = await alpaca.getAnnouncement(id);

Appreciation and Proposals

When we work on a project, any internal library we create that could benefit the community will be made public for free use. Please consider contributing, as work does go into creating and maintaining this library. As always, if something could be improved, please create an issue for it in the project repo and we'll be happy to discuss!

flutter_alpaca_markets's People

Contributors

graybrandonh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.