Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

alpaca-trade-api

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alpaca-trade-api

  • 0.8.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Alpaca::Trade::Api

This is a high-level Ruby wrapper for Alpaca trading API. This implementation only supports the Web API v2 API, there is no plan to support Web API v1.

Installation

Add this line to your application's Gemfile:

gem 'alpaca-trade-api'

And then execute:

$ bundle

Or install it yourself as:

$ gem install alpaca-trade-api

Usage

Configuration

By default, the library is configured to use the Paper Trading host - https://paper-api.alpaca.markets - as the endpoint it connects to, and loads both the key id and secret key from the following environment variables: ALPACA_API_KEY_ID and ALPACA_API_SECRET_KEY. To configure the library differently:

Alpaca::Trade::Api.configure do |config|
  config.endpoint = 'https://api.alpaca.markets'
  config.key_id = 'A_KEY_ID'
  config.key_secret = 'A_S3CRET'
end

Example

Here's an example on how to use the library to read details of an account's orders in paper trading.

require 'alpaca/trade/api'

Alpaca::Trade::Api.configure do |config|
  config.endpoint = 'https://paper-api.alpaca.markets'
  config.key_id = 'xxxxxxxx'
  config.key_secret = 'xxxxx'
end

client =  Alpaca::Trade::Api::Client.new
puts client.orders.last.inspect

Supported endpoints

Here's a table with all currently supported endpoints in this library:

ObjectActionMethod
Account[GET] Get the accountClient#account
Account Activities[GET] Get a list of account activitiesClient#account_activities(activity_type:)
Orders[GET] Get a list of ordersClient#orders
[POST] Request a new orderClient#new_order
[GET] Get an orderClient#order(id:)
[GET] Get an order by client order idClient#order(id:)
[PATCH] Replace an orderClient#replace_order
[DELETE] Cancel all ordersClient#cancel_orders
[DELETE] Cancel an orderClient#cancel_order(id:)
Positions[GET] Get open positionsClient#positions
[GET] Get an open positionClient#position(symbol:)
[DELETE] Close all positionsClient#close_positions
[DELETE] Close a positionClient#close_position(symbol:)
Assets[GET] Get assetsClient#assets
[GET] Get assets/:idClient#asset(symbol:)
[GET] Get an assetClient#asset(symbol:)
Calendar[GET] Get the calendarClient#calendar(start_date:, end_date:)
Clock[GET] Get the clockClient#clock
Bars[GET] Get a list of barsClient#bars(timeframe, symbols, limit:)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ccjr/alpaca-trade-api.

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 29 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc