Class: QuestradeApi::REST::Account

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

Overview

Author:

Constant Summary

Constants inherited from Base

Base::BASE_ENDPOINT

Instance Attribute Summary collapse

Attributes inherited from Base

#account_id, #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(authorization, params) ⇒ Account

Returns a new instance of Account.



15
16
17
18
19
20
21
22
23
# 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

Instance Attribute Details

#user_idObject

Returns the value of attribute user_id.



13
14
15
# File 'lib/questrade_api/rest/account.rb', line 13

def user_id
  @user_id
end

Class Method Details

.endpointObject



80
81
82
# File 'lib/questrade_api/rest/account.rb', line 80

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

.fetch(authorization) ⇒ OpenStruct(accounts: [QuestradeApi::REST::Account]), Faraday::Response

Fetch accounts for specific authorized user.

Parameters:

  • authorization

    is any object that responds to #access_token and #url

Returns:

  • (OpenStruct(accounts: [QuestradeApi::REST::Account]))

    if call to server is successful

  • (Faraday::Response)

    if call to server is not successful



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# 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

Instance Method Details

#activities(params) ⇒ OpenStruct(executions: [QuestradeApi::REST::Activity)]

Fetch activities associated with account.

Parameters:

  • see

    QuestradeApi::REST::Activity.fetch

Returns:



31
32
33
# File 'lib/questrade_api/rest/account.rb', line 31

def activities(params)
  QuestradeApi::REST::Activity.fetch(authorization, id, params)
end

#balancesOpenStruct(per_currency_balances)

Fetch balances associated with account.

Returns:

  • (OpenStruct(per_currency_balances))


47
48
49
# File 'lib/questrade_api/rest/account.rb', line 47

def balances
  QuestradeApi::REST::Balance.fetch(authorization, id)
end

#executions(params) ⇒ OpenStruct(executions: [QuestradeApi::REST::Execution)]

Fetch executions associated with account.

Parameters:

  • see

    QuestradeApi::REST::Execution.fetch

Returns:



40
41
42
# File 'lib/questrade_api/rest/account.rb', line 40

def executions(params)
  QuestradeApi::REST::Execution.fetch(authorization, id, params)
end

#positionsOpenStruct(positions: [QuestradeApi::REST::Position])

Fetch positions associated with account.

Returns:



54
55
56
# File 'lib/questrade_api/rest/account.rb', line 54

def positions
  QuestradeApi::REST::Position.fetch(authorization, id)
end