class QuestradeApi::REST::Account

@author Bruno Meira <goesmeira@gmail.com>

Attributes

user_id[RW]

Public Class Methods

endpoint() click to toggle source
# File lib/questrade_api/rest/account.rb, line 80
def self.endpoint
  "#{BASE_ENDPOINT}/accounts"
end
fetch(authorization) click to toggle source

Fetch accounts for specific authorized user.

@param authorization is any object that

responds to #access_token and #url

@return [OpenStruct(accounts: [QuestradeApi::REST::Account])] if call to server is successful @return [Faraday::Response] if call to server is not successful

Calls superclass method QuestradeApi::REST::Base#fetch
# File lib/questrade_api/rest/account.rb, line 65
def self.fetch(authorization)
  response = super(access_token: authorization.access_token,
                   endpoint: endpoint,
                   url: authorization.url)

  result = OpenStruct.new(accounts: [])

  if response.status == 200
    result.accounts = parse_accounts(authorization, response.body)
    response = result
  end

  response
end
new(authorization, params) click to toggle source
Calls superclass method QuestradeApi::REST::Base::new
# File lib/questrade_api/rest/account.rb, line 15
def initialize(authorization, params)
  super(authorization)

  @id = params[:id]
  @user_id = params[:user_id]

  @raw_body = params[:data]
  build_data(params[:data]) if @raw_body
end

Private Class Methods

parse_accounts(authorization, body) click to toggle source
# File lib/questrade_api/rest/account.rb, line 84
def self.parse_accounts(authorization, body)
  raw = JSON.parse(body)
  clients = []

  raw['accounts'].each do |client|
    clients << new(authorization,
                   id: client['number'],
                   user_id: raw['userId'],
                   data: client)
  end

  clients
end

Public Instance Methods

activities(params) click to toggle source

Fetch activities associated with account.

@param see QuestradeApi::REST::Activity.fetch

@return [OpenStruct(executions: [QuestradeApi::REST::Activity)]

# File lib/questrade_api/rest/account.rb, line 31
def activities(params)
  QuestradeApi::REST::Activity.fetch(authorization, id, params)
end
balances() click to toggle source

Fetch balances associated with account.

@return [OpenStruct(per_currency_balances)]

# File lib/questrade_api/rest/account.rb, line 47
def balances
  QuestradeApi::REST::Balance.fetch(authorization, id)
end
executions(params) click to toggle source

Fetch executions associated with account.

@param see QuestradeApi::REST::Execution.fetch

@return [OpenStruct(executions: [QuestradeApi::REST::Execution)]

# File lib/questrade_api/rest/account.rb, line 40
def executions(params)
  QuestradeApi::REST::Execution.fetch(authorization, id, params)
end
positions() click to toggle source

Fetch positions associated with account.

@return [OpenStruct(positions: [QuestradeApi::REST::Position])]

# File lib/questrade_api/rest/account.rb, line 54
def positions
  QuestradeApi::REST::Position.fetch(authorization, id)
end