Class: SnapTrade::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/snaptrade/models/account.rb

Overview

A single account at a brokerage.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Account

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/snaptrade/models/account.rb', line 130

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `SnapTrade::Account` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!self.class.attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `SnapTrade::Account`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

  if attributes.key?(:'id')
    self.id = attributes[:'id']
  end

  if attributes.key?(:'brokerage_authorization')
    self.brokerage_authorization = attributes[:'brokerage_authorization']
  end

  if attributes.key?(:'name')
    self.name = attributes[:'name']
  end

  if attributes.key?(:'number')
    self.number = attributes[:'number']
  end

  if attributes.key?(:'institution_account_id')
    self. = attributes[:'institution_account_id']
  end

  if attributes.key?(:'institution_name')
    self.institution_name = attributes[:'institution_name']
  end

  if attributes.key?(:'created_date')
    self.created_date = attributes[:'created_date']
  end

  if attributes.key?(:'funding_date')
    self.funding_date = attributes[:'funding_date']
  end

  if attributes.key?(:'opening_date')
    self.opening_date = attributes[:'opening_date']
  end

  if attributes.key?(:'sync_status')
    self.sync_status = attributes[:'sync_status']
  end

  if attributes.key?(:'balance')
    self.balance = attributes[:'balance']
  end

  if attributes.key?(:'status')
    self.status = attributes[:'status']
  end

  if attributes.key?(:'raw_type')
    self.raw_type = attributes[:'raw_type']
  end

  if attributes.key?(:'meta')
    if (value = attributes[:'meta']).is_a?(Hash)
      self.meta = value
    end
  end

  if attributes.key?(:'portfolio_group')
    self.portfolio_group = attributes[:'portfolio_group']
  end

  if attributes.key?(:'cash_restrictions')
    if (value = attributes[:'cash_restrictions']).is_a?(Array)
      self.cash_restrictions = value
    end
  end

  if attributes.key?(:'is_paper')
    self.is_paper = attributes[:'is_paper']
  end
end

Instance Attribute Details

#balanceObject

Returns the value of attribute balance.



45
46
47
# File 'lib/snaptrade/models/account.rb', line 45

def balance
  @balance
end

#brokerage_authorizationObject

Unique identifier for the connection. This is the UUID used to reference the connection in SnapTrade.



20
21
22
# File 'lib/snaptrade/models/account.rb', line 20

def brokerage_authorization
  @brokerage_authorization
end

#cash_restrictionsObject

This field is deprecated.



60
61
62
# File 'lib/snaptrade/models/account.rb', line 60

def cash_restrictions
  @cash_restrictions
end

#created_dateObject

Timestamp in [ISO 8601](en.wikipedia.org/wiki/ISO_8601) format indicating when the account was created in SnapTrade. This is not the account opening date at the brokerage.



35
36
37
# File 'lib/snaptrade/models/account.rb', line 35

def created_date
  @created_date
end

#funding_dateObject

Timestamp in [ISO 8601](en.wikipedia.org/wiki/ISO_8601) format indicating when the account was funded.



38
39
40
# File 'lib/snaptrade/models/account.rb', line 38

def funding_date
  @funding_date
end

#idObject

Unique identifier for the connected brokerage account. This is the UUID used to reference the account in SnapTrade. This ID should not change for as long as the connection stays active. If the connection is deleted and re-added, a new account ID will be generated.



17
18
19
# File 'lib/snaptrade/models/account.rb', line 17

def id
  @id
end

#institution_account_idObject

A stable and unique account identifier provided by the institution. Will be set to null if not provided. When present, can be used to check if a user has connected the same brokerage account across multiple connections.



29
30
31
# File 'lib/snaptrade/models/account.rb', line 29

def 
  @institution_account_id
end

#institution_nameObject

The name of the brokerage that holds the account.



32
33
34
# File 'lib/snaptrade/models/account.rb', line 32

def institution_name
  @institution_name
end

#is_paperObject

Indicates whether the account is a paper (simulated) trading account.



63
64
65
# File 'lib/snaptrade/models/account.rb', line 63

def is_paper
  @is_paper
end

#metaObject

Additional information about the account, such as account type, status, etc. This information is specific to the brokerage and there’s no standard format for this data. This field is deprecated and subject to removal in a future version.



54
55
56
# File 'lib/snaptrade/models/account.rb', line 54

def meta
  @meta
end

#nameObject

A display name for the account. Either assigned by the user or by the brokerage itself. For certain brokerages, SnapTrade appends the brokerage name to the account name for clarity.



23
24
25
# File 'lib/snaptrade/models/account.rb', line 23

def name
  @name
end

#numberObject

The account number assigned by the brokerage. For some brokerages, this field may be masked for security reasons.



26
27
28
# File 'lib/snaptrade/models/account.rb', line 26

def number
  @number
end

#opening_dateObject

Timestamp in [ISO 8601](en.wikipedia.org/wiki/ISO_8601) format indicating when the account was opened at the brokerage.



41
42
43
# File 'lib/snaptrade/models/account.rb', line 41

def opening_date
  @opening_date
end

#portfolio_groupObject

Portfolio Group ID. Portfolio Groups have been deprecated. Please contact support if you have a use case for it.



57
58
59
# File 'lib/snaptrade/models/account.rb', line 57

def portfolio_group
  @portfolio_group
end

#raw_typeObject

The account type as provided by the brokerage



51
52
53
# File 'lib/snaptrade/models/account.rb', line 51

def raw_type
  @raw_type
end

#statusObject

The current status of the account. Can be either "open", "closed", "archived" or null if the status is unknown or not provided by the brokerage.



48
49
50
# File 'lib/snaptrade/models/account.rb', line 48

def status
  @status
end

#sync_statusObject

Returns the value of attribute sync_status.



43
44
45
# File 'lib/snaptrade/models/account.rb', line 43

def sync_status
  @sync_status
end

Class Method Details

.acceptable_attributesObject

Returns all the JSON keys this model knows about



89
90
91
# File 'lib/snaptrade/models/account.rb', line 89

def self.acceptable_attributes
  attribute_map.values
end

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/snaptrade/models/account.rb', line 66

def self.attribute_map
  {
    :'id' => :'id',
    :'brokerage_authorization' => :'brokerage_authorization',
    :'name' => :'name',
    :'number' => :'number',
    :'institution_account_id' => :'institution_account_id',
    :'institution_name' => :'institution_name',
    :'created_date' => :'created_date',
    :'funding_date' => :'funding_date',
    :'opening_date' => :'opening_date',
    :'sync_status' => :'sync_status',
    :'balance' => :'balance',
    :'status' => :'status',
    :'raw_type' => :'raw_type',
    :'meta' => :'meta',
    :'portfolio_group' => :'portfolio_group',
    :'cash_restrictions' => :'cash_restrictions',
    :'is_paper' => :'is_paper'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



308
309
310
# File 'lib/snaptrade/models/account.rb', line 308

def self.build_from_hash(attributes)
  new.build_from_hash(attributes)
end

.openapi_nullableObject

List of attributes with nullable: true



117
118
119
120
121
122
123
124
125
126
# File 'lib/snaptrade/models/account.rb', line 117

def self.openapi_nullable
  Set.new([
    :'name',
    :'institution_account_id',
    :'funding_date',
    :'opening_date',
    :'status',
    :'raw_type',
  ])
end

.openapi_typesObject

Attribute type mapping.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/snaptrade/models/account.rb', line 94

def self.openapi_types
  {
    :'id' => :'String',
    :'brokerage_authorization' => :'String',
    :'name' => :'String',
    :'number' => :'String',
    :'institution_account_id' => :'String',
    :'institution_name' => :'String',
    :'created_date' => :'Time',
    :'funding_date' => :'Time',
    :'opening_date' => :'Time',
    :'sync_status' => :'AccountSyncStatus',
    :'balance' => :'AccountBalance',
    :'status' => :'AccountStatus',
    :'raw_type' => :'String',
    :'meta' => :'Hash<String, Object>',
    :'portfolio_group' => :'String',
    :'cash_restrictions' => :'Array<String>',
    :'is_paper' => :'Boolean'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/snaptrade/models/account.rb', line 271

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      id == o.id &&
      brokerage_authorization == o.brokerage_authorization &&
      name == o.name &&
      number == o.number &&
       == o. &&
      institution_name == o.institution_name &&
      created_date == o.created_date &&
      funding_date == o.funding_date &&
      opening_date == o.opening_date &&
      sync_status == o.sync_status &&
      balance == o.balance &&
      status == o.status &&
      raw_type == o.raw_type &&
      meta == o.meta &&
      portfolio_group == o.portfolio_group &&
      cash_restrictions == o.cash_restrictions &&
      is_paper == o.is_paper
end

#_deserialize(type, value) ⇒ Object

Deserializes the data based on type

Parameters:

  • string

    type Data type

  • string

    value Value to be deserialized

Returns:

  • (Object)

    Deserialized data



339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'lib/snaptrade/models/account.rb', line 339

def _deserialize(type, value)
  case type.to_sym
  when :Time
    Time.parse(value)
  when :Date
    Date.parse(value)
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :Boolean
    if value.to_s =~ /\A(true|t|yes|y|1)\z/i
      true
    else
      false
    end
  when :Object
    # generic object (usually a Hash), return directly
    value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    # models (e.g. Pet) or oneOf
    klass = SnapTrade.const_get(type)
    klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
  end
end

#_to_hash(value) ⇒ Hash

Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value

Parameters:

  • value (Object)

    Any valid value

Returns:

  • (Hash)

    Returns the value in the form of hash



410
411
412
413
414
415
416
417
418
419
420
421
422
# File 'lib/snaptrade/models/account.rb', line 410

def _to_hash(value)
  if value.is_a?(Array)
    value.compact.map { |v| _to_hash(v) }
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.each { |k, v| hash[k] = _to_hash(v) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash
  else
    value
  end
end

#build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/snaptrade/models/account.rb', line 315

def build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  attributes = attributes.transform_keys(&:to_sym)
  self.class.openapi_types.each_pair do |key, type|
    if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
      self.send("#{key}=", nil)
    elsif type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[self.class.attribute_map[key]].is_a?(Array)
        self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
      end
    elsif !attributes[self.class.attribute_map[key]].nil?
      self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
    end
  end

  self
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


295
296
297
# File 'lib/snaptrade/models/account.rb', line 295

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



301
302
303
# File 'lib/snaptrade/models/account.rb', line 301

def hash
  [id, brokerage_authorization, name, number, , institution_name, created_date, funding_date, opening_date, sync_status, balance, status, raw_type, meta, portfolio_group, cash_restrictions, is_paper].hash
end

#list_invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/snaptrade/models/account.rb', line 218

def list_invalid_properties
  invalid_properties = Array.new
  if @id.nil?
    invalid_properties.push('invalid value for "id", id cannot be nil.')
  end

  if @brokerage_authorization.nil?
    invalid_properties.push('invalid value for "brokerage_authorization", brokerage_authorization cannot be nil.')
  end

  if @number.nil?
    invalid_properties.push('invalid value for "number", number cannot be nil.')
  end

  if @institution_name.nil?
    invalid_properties.push('invalid value for "institution_name", institution_name cannot be nil.')
  end

  if @created_date.nil?
    invalid_properties.push('invalid value for "created_date", created_date cannot be nil.')
  end

  if @sync_status.nil?
    invalid_properties.push('invalid value for "sync_status", sync_status cannot be nil.')
  end

  if @balance.nil?
    invalid_properties.push('invalid value for "balance", balance cannot be nil.')
  end

  if @is_paper.nil?
    invalid_properties.push('invalid value for "is_paper", is_paper cannot be nil.')
  end

  invalid_properties
end

#to_bodyHash

to_body is an alias to to_hash (backward compatibility)

Returns:

  • (Hash)

    Returns the object in the form of hash



386
387
388
# File 'lib/snaptrade/models/account.rb', line 386

def to_body
  to_hash
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



392
393
394
395
396
397
398
399
400
401
402
403
404
# File 'lib/snaptrade/models/account.rb', line 392

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end

    hash[param] = _to_hash(value)
  end
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



380
381
382
# File 'lib/snaptrade/models/account.rb', line 380

def to_s
  to_hash.to_s
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



257
258
259
260
261
262
263
264
265
266
267
# File 'lib/snaptrade/models/account.rb', line 257

def valid?
  return false if @id.nil?
  return false if @brokerage_authorization.nil?
  return false if @number.nil?
  return false if @institution_name.nil?
  return false if @created_date.nil?
  return false if @sync_status.nil?
  return false if @balance.nil?
  return false if @is_paper.nil?
  true
end