Class: QuestradeApi::REST::Balance

Inherits:
Base
  • Object
show all
Defined in:
lib/questrade_api/rest/balance.rb

Overview

Author:

Constant Summary

Constants inherited from Base

QuestradeApi::REST::Base::BASE_ENDPOINT

Instance Attribute Summary collapse

Attributes inherited from Base

#authorization, #connection, #data, #endpoint, #id, #raw_body

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#build_attributes, #build_data, connection, #fetch, post, #url

Constructor Details

#initialize(params) ⇒ Balance

Returns a new instance of Balance.



9
10
11
12
13
14
# File 'lib/questrade_api/rest/balance.rb', line 9

def initialize(params)
  @account_id = params[:account_id]

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

Instance Attribute Details

#account_idObject

Returns the value of attribute account_id.



7
8
9
# File 'lib/questrade_api/rest/balance.rb', line 7

def 
  @account_id
end

Class Method Details

.endpoint(account_id) ⇒ Object



42
43
44
# File 'lib/questrade_api/rest/balance.rb', line 42

def self.endpoint()
  "#{BASE_ENDPOINT}/accounts/#{}/balances"
end

.fetch(authorization, account_number) ⇒ OpenStruct(per_currency_balances, combined_balances, sod_per_currency_balances, sod_combined_balances), Faraday::Response

Fetch account balances

Parameters:

  • authorization (QuestradeApi::Authorization)

    with the authorized #access_token and #url.

  • account_number (String)

    with the account the activities will be fetched

Returns:

  • (OpenStruct(per_currency_balances, combined_balances, sod_per_currency_balances, sod_combined_balances))

    If call succeeds. Each method returns an array of QuestradeApi::REST::Balance

  • (Faraday::Response)

    if call fails.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/questrade_api/rest/balance.rb', line 23

def self.fetch(authorization, )
  response = super(access_token: authorization.access_token,
                   endpoint: endpoint(),
                   url: authorization.url)

  result = OpenStruct.new(per_currency_balances: [],
                          combined_balances: [],
                          sod_per_currency_balances: [],
                          sod_combined_balances: [])

  if response.status == 200
    parse_balances(, response.body).each do |key, value|
      result.send("#{key}=", value)
    end
  end

  result
end