0.01
No release in over 3 years
Low commit activity in last 3 years
An elegant Ruby gem to interact with Questrade API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.5
~> 0.47
~> 2.3

Runtime

~> 0.9
 Project Readme

Gem Version Build Status Code Climate

The Questrade Ruby Api Gem

A Ruby interface to use the Questrade API.

Quick Start

gem 'questrade_api'
  • Run Bundle to install gem
$ bundle

Authorization

  • After getting the refresh token from Questrade, you are now ready to ask for an access token. In order to fetch an access token, copy the snippet of code below and replace the example token with your refresh token.
# By default this API calls the practice(demo) endpoint.
client = QuestradeApi::Client.new(refresh_token: 'XXXX')

# If you want to call the live platform you need to pass :live as a parameter. Ex:
client = QuestradeApi::Client.new(refresh_token: 'XXXX', :live)

# Both calls automatically ask for a new access token


# In case you already have an access token and a api_server, you can instead use:
client = QuestradeApi::Client.new(access_token: 'XXXX', api_server: 'XXXX', :live)

# To ask for a new access token(Questrade invalidates tokens every 30 mins), simply call:
client.refresh_token # Make sure client has a valid refresh_token

Some examples:

  • After fetching a valid access token, you are now ready to use the API. Below you can find a few examples of the calls you can make with the gem.
# Get Questrade's current server time
client.time

# list of all accounts
client.accounts

# List of all balances of an specific account
client.balances('account_id')

# List of positions of an specific account
client.positions('account_id')

# Activities of an specific period of time for an specific account
client.activities('account_id', startTime: DateTime.yesterday.to_s, endTime: DateTime.now.to_s)

# Symbol by ID
client.symbol('id')

# Symbols by name
client.symbols(names: ['AAPL'])

# Search symbols by prefix
client.search_symbols(prefix: 'BMO')

# List of quotes
client.quotes(['123', '456'])

# Quote details
client.quote('123')

# Quote Options
filters = [{
            "optionType": "Call",
            "underlyingId": 27426,
            "expiryDate": "2017-01-20T00:00:00.000000-05:00",
            "minstrikePrice": 70,
            "maxstrikePrice": 80
          }]

option_ids = [123,456]
client.quote_options(filters, option_ids)

# Quote Strategies
variants =
[
  {
    "variantId": 1,
    "strategy": "Custom",
    "legs": [{ "symbolId": 27426, "ratio": 1000, "action": "Buy" },
             { "symbolId": 10550014, "ratio": 10, "action": "Sell" }]
  }
 ]
client.quote_strategies(variants)

# Historical Market in candlestick format
client.candles('123', startTime: DateTime.yesterday.to_s, endTime: DateTime.now.to_s)

# In case you already have a valid access token and its respective URL, you can use the QuestradeApi::REST objects. Example:
# authorization can be any object that responds to url and access_token
authorization = QuestradeApi::Authorization.new(access_token: 'access_token', api_server: 'url')
accounts = QuestradeApi::REST::Account.fetch(authorization)

For more advanced options, check out our documentation.

Current Status

This Project is under development and some endpoints are still not accessible through the gem. Check the tables below for more details.

Account Calls

Endpoint Development Documentation
/time DONE DONE
/accounts DONE DONE
/accounts/:id/positions DONE DONE
/accounts/:id/balances DONE DONE
/accounts/:id/executions DONE DONE
/accounts/:id/orders DONE DONE
/accounts/:id/activities DONE DONE

Market Calls

Endpoint Development Documentation
/symbols/ DONE
/symbols/:id DONE
/symbols/search DONE
/symbols/:id/options DONE
/markets DONE
/markets/quotes/ DONE
/markets/quotes/:id DONE
/markets/quotes/options DONE
/markets/quotes/strategies DONE
/markets/candles/:id DONE

Order Calls

Endpoint Development Documentation
POST accounts/:id/orders
POST accounts/:id/orders/impact
DELETE accounts/:id/orders
POST accounts/:id/orders/brackets
POST accounts/:id/orders/strategy

Contributing

Contributions are more than welcome. The only thing we ask is that before you send a Pull Request, please check if you completed the steps below:

  1. Write and/or update affected tests
  2. Write and/or update documentation
  3. Run RuboCop and update code, if needed
  4. Run test suite
  5. Test if the changes are working properly and didn't break any affected area

Note

This is an open-source project, licensed under the MIT License(see LICENSE), and was developed as a labour of love. We are not responsible for any damages, capital losses, or any claim caused by the use of this gem.

USE IT AT YOUR OWN RISK.