Giter Club home page Giter Club logo

alpaca-trade-api's Introduction

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:

Object Action Method
Account [GET] Get the account Client#account
Account Activities [GET] Get a list of account activities Client#account_activities(activity_type:)
Orders [GET] Get a list of orders Client#orders
[POST] Request a new order Client#new_order
[GET] Get an order Client#order(id:)
[GET] Get an order by client order id Client#order(id:)
[PATCH] Replace an order Client#replace_order
[DELETE] Cancel all orders Client#cancel_orders
[DELETE] Cancel an order Client#cancel_order(id:)
Positions [GET] Get open positions Client#positions
[GET] Get an open position Client#position(symbol:)
[DELETE] Close all positions Client#close_positions
[DELETE] Close a position Client#close_position(symbol:)
Assets [GET] Get assets Client#assets
[GET] Get assets/:id Client#asset(symbol:)
[GET] Get an asset Client#asset(symbol:)
Calendar [GET] Get the calendar Client#calendar(start_date:, end_date:)
Clock [GET] Get the clock Client#clock
Bars [GET] Get a list of bars Client#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.

alpaca-trade-api's People

Contributors

ccjr avatar travishooper avatar nathanworden avatar elcarneiro avatar dependabot[bot] 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.