snaptrade 3.0.40 → 3.0.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +47 -2
  3. data/lib/snaptrade/api/account_information_api.rb +123 -0
  4. data/lib/snaptrade/models/account_balances_v2_response.rb +306 -0
  5. data/lib/snaptrade/models/account_balances_v2_response_buying_power_inner.rb +252 -0
  6. data/lib/snaptrade/models/account_balances_v2_response_cash_inner.rb +244 -0
  7. data/lib/snaptrade/models/account_balances_v2_response_cash_or_margin.rb +38 -0
  8. data/lib/snaptrade/models/account_balances_v2_response_data_freshness.rb +223 -0
  9. data/lib/snaptrade/models/account_balances_v2_response_margin.rb +221 -0
  10. data/lib/snaptrade/models/account_balances_v2_response_net_value.rb +244 -0
  11. data/lib/snaptrade/models/balance_v2_currency_amount.rb +236 -0
  12. data/lib/snaptrade/models/balance_v2_money.rb +237 -0
  13. data/lib/snaptrade/models/basis.rb +38 -0
  14. data/lib/snaptrade/version.rb +1 -1
  15. data/lib/snaptrade.rb +10 -0
  16. data/spec/api/account_information_api_spec.rb +14 -0
  17. data/spec/models/account_balances_v2_response_buying_power_inner_spec.rb +41 -0
  18. data/spec/models/account_balances_v2_response_cash_inner_spec.rb +35 -0
  19. data/spec/models/account_balances_v2_response_cash_or_margin_spec.rb +23 -0
  20. data/spec/models/account_balances_v2_response_data_freshness_spec.rb +29 -0
  21. data/spec/models/account_balances_v2_response_margin_spec.rb +29 -0
  22. data/spec/models/account_balances_v2_response_net_value_spec.rb +35 -0
  23. data/spec/models/account_balances_v2_response_spec.rb +65 -0
  24. data/spec/models/balance_v2_currency_amount_spec.rb +35 -0
  25. data/spec/models/balance_v2_money_spec.rb +35 -0
  26. data/spec/models/basis_spec.rb +23 -0
  27. metadata +267 -237
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f3c2a81303bacea58de773eb20f9ac8de21c7f6acd132e5d5372a559d76347c
4
- data.tar.gz: d5f314d2dc136528bdef3904746dcfcb3721eca2511b22009f2afaa59b50a45c
3
+ metadata.gz: 259eb257284767acbee75826a15896abc4384d04c19d77eb00c398cba3b423ba
4
+ data.tar.gz: c845086679b3fb579de413879b24717cc86bb080951e913f5d0eb17fb4165d68
5
5
  SHA512:
6
- metadata.gz: 2607f2409b19c68ecd258aff4fcdb99ae7a32151dc98f345b6edc4a9109f1d78a851b9566b74a63afed53867e110e141c2b5f03d31280e883af35b9ddbc62557
7
- data.tar.gz: 8e4fa025cd0601842e802dd2c6b17dbf8ac39289d76a7dbd594b5603f22dd3a0a221878e6f334dc8dc391768e2bc8e1501e4218cbb49be26333825920f0f397b
6
+ metadata.gz: 5ca0512b36e8f1c48643392070042d9b4d21e8776956da342520d95bf50abebd7474fbd7d90804b88d0b7dd9a6d0cc009dc2881f8f73b143a048b6612afdbd7c
7
+ data.tar.gz: 00471b506ed00b533537ebfc49b22dd740b5261f1673cdd5748aff0de6a21c493bc5218cd55e50f21335f8f317ff8a5f66bd9575211a5470c52cf07df6f55909
data/README.md CHANGED
@@ -63,7 +63,7 @@ backoff with jitter rather than from the headers.
63
63
  See https://docs.snaptrade.com/docs/ratelimiting.
64
64
 
65
65
 
66
- [![npm](https://img.shields.io/badge/gem-v3.0.40-blue)](https://rubygems.org/gems/snaptrade/versions/3.0.40)
66
+ [![npm](https://img.shields.io/badge/gem-v3.0.42-blue)](https://rubygems.org/gems/snaptrade/versions/3.0.42)
67
67
  [![More Info](https://img.shields.io/badge/More%20Info-Click%20Here-orange)](https://snaptrade.com/)
68
68
 
69
69
  </div>
@@ -78,6 +78,7 @@ See https://docs.snaptrade.com/docs/ratelimiting.
78
78
  - [Reference](#reference)
79
79
  * [`snaptrade.account_information.get_account_activities`](#snaptradeaccount_informationget_account_activities)
80
80
  * [`snaptrade.account_information.get_account_balance_history`](#snaptradeaccount_informationget_account_balance_history)
81
+ * [`snaptrade.account_information.get_account_balances_v2`](#snaptradeaccount_informationget_account_balances_v2)
81
82
  * [`snaptrade.account_information.get_account_details`](#snaptradeaccount_informationget_account_details)
82
83
  * [`snaptrade.account_information.get_all_account_positions`](#snaptradeaccount_informationget_all_account_positions)
83
84
  * [`snaptrade.account_information.get_user_account_balance`](#snaptradeaccount_informationget_user_account_balance)
@@ -144,7 +145,7 @@ See https://docs.snaptrade.com/docs/ratelimiting.
144
145
  Add to Gemfile:
145
146
 
146
147
  ```ruby
147
- gem 'snaptrade', '~> 3.0.40'
148
+ gem 'snaptrade', '~> 3.0.42'
148
149
  ```
149
150
 
150
151
  ## Getting Started<a id="getting-started"></a>
@@ -310,6 +311,50 @@ p result
310
311
  ---
311
312
 
312
313
 
314
+ ### `snaptrade.account_information.get_account_balances_v2`<a id="snaptradeaccount_informationget_account_balances_v2"></a>
315
+
316
+ Returns the account's balances in a single snapshot: total net value, cash per currency, buying power, and margin details for margin accounts. Every field is always present and is `null` when the institution doesn't report it.
317
+
318
+ **Beta:** this endpoint is only available for partners it has been enabled for. Please contact the SnapTrade team to enable it. The response schema may change.
319
+
320
+ Check your API key on the [Customer Dashboard billing page](https://dashboard.snaptrade.com/settings/billing) to see if you have real-time data access:
321
+ - If you do, this endpoint returns real-time data.
322
+ - If you don't, Daily data is cached and refreshed once a day. Exact refresh timing may vary by institution. If you need real-time, use the [manual refresh](/reference/Connections/Connections_refreshBrokerageAuthorization) endpoint.
323
+
324
+ `data_freshness.as_of` is the time the returned data was fetched from the institution.
325
+
326
+ If the connection has become disabled, it can no longer access the latest data from the institution, but will continue to return the last available cached state. Please see [this guide](/docs/fix-broken-connections) on how to fix a disabled connection.
327
+
328
+
329
+ #### 🛠️ Usage<a id="🛠️-usage"></a>
330
+
331
+ ```ruby
332
+ result = snaptrade.account_information.get_account_balances_v2(
333
+ user_id: "snaptrade-user-123",
334
+ user_secret: "adf2aa34-8219-40f7-a6b3-60156985cc61",
335
+ account_id: "917c8734-8470-4a3e-a18f-57c3f2ee6631",
336
+ )
337
+ p result
338
+ ```
339
+
340
+ #### ⚙️ Parameters<a id="⚙️-parameters"></a>
341
+
342
+ ##### user_id: `String`<a id="user_id-string"></a>
343
+ ##### user_secret: `String`<a id="user_secret-string"></a>
344
+ ##### account_id: `String`<a id="account_id-string"></a>
345
+ #### 🔄 Return<a id="🔄-return"></a>
346
+
347
+ [AccountBalancesV2Response](./lib/snaptrade/models/account_balances_v2_response.rb)
348
+
349
+ #### 🌐 Endpoint<a id="🌐-endpoint"></a>
350
+
351
+ `/accounts/{accountId}/balances/v2` `GET`
352
+
353
+ [🔙 **Back to Table of Contents**](#table-of-contents)
354
+
355
+ ---
356
+
357
+
313
358
  ### `snaptrade.account_information.get_account_details`<a id="snaptradeaccount_informationget_account_details"></a>
314
359
 
315
360
  Returns the specified account for the authenticated user. The account can be an investment, deposit, or line of credit account. Use the `kind` discriminator to determine the schema for the account.
@@ -290,6 +290,129 @@ module SnapTrade
290
290
  end
291
291
 
292
292
 
293
+ # Get account balances
294
+ #
295
+ # Returns the account's balances in a single snapshot: total net value, cash per currency, buying power, and margin details for margin accounts. Every field is always present and is `null` when the institution doesn't report it.
296
+ #
297
+ # **Beta:** this endpoint is only available for partners it has been enabled for. Please contact the SnapTrade team to enable it. The response schema may change.
298
+ #
299
+ # Check your API key on the [Customer Dashboard billing page](https://dashboard.snaptrade.com/settings/billing) to see if you have real-time data access:
300
+ # - If you do, this endpoint returns real-time data.
301
+ # - If you don't, Daily data is cached and refreshed once a day. Exact refresh timing may vary by institution. If you need real-time, use the [manual refresh](/reference/Connections/Connections_refreshBrokerageAuthorization) endpoint.
302
+ #
303
+ # `data_freshness.as_of` is the time the returned data was fetched from the institution.
304
+ #
305
+ # If the connection has become disabled, it can no longer access the latest data from the institution, but will continue to return the last available cached state. Please see [this guide](/docs/fix-broken-connections) on how to fix a disabled connection.
306
+ #
307
+ # @param user_id [String]
308
+ # @param user_secret [String]
309
+ # @param account_id [String]
310
+ # @param [Hash] extra additional parameters to pass along through :header_params, :query_params, or parameter name
311
+ def get_account_balances_v2(user_id:, user_secret:, account_id:, extra: {})
312
+ data, _status_code, _headers = get_account_balances_v2_with_http_info_impl(user_id, user_secret, account_id, extra)
313
+ data
314
+ end
315
+
316
+ # Get account balances
317
+ #
318
+ # Returns the account's balances in a single snapshot: total net value, cash per currency, buying power, and margin details for margin accounts. Every field is always present and is `null` when the institution doesn't report it.
319
+ #
320
+ # **Beta:** this endpoint is only available for partners it has been enabled for. Please contact the SnapTrade team to enable it. The response schema may change.
321
+ #
322
+ # Check your API key on the [Customer Dashboard billing page](https://dashboard.snaptrade.com/settings/billing) to see if you have real-time data access:
323
+ # - If you do, this endpoint returns real-time data.
324
+ # - If you don't, Daily data is cached and refreshed once a day. Exact refresh timing may vary by institution. If you need real-time, use the [manual refresh](/reference/Connections/Connections_refreshBrokerageAuthorization) endpoint.
325
+ #
326
+ # `data_freshness.as_of` is the time the returned data was fetched from the institution.
327
+ #
328
+ # If the connection has become disabled, it can no longer access the latest data from the institution, but will continue to return the last available cached state. Please see [this guide](/docs/fix-broken-connections) on how to fix a disabled connection.
329
+ #
330
+ # @param user_id [String]
331
+ # @param user_secret [String]
332
+ # @param account_id [String]
333
+ # @param [Hash] extra additional parameters to pass along through :header_params, :query_params, or parameter name
334
+ def get_account_balances_v2_with_http_info(user_id:, user_secret:, account_id:, extra: {})
335
+ get_account_balances_v2_with_http_info_impl(user_id, user_secret, account_id, extra)
336
+ end
337
+
338
+ # Get account balances
339
+ # Returns the account's balances in a single snapshot: total net value, cash per currency, buying power, and margin details for margin accounts. Every field is always present and is `null` when the institution doesn't report it. **Beta:** this endpoint is only available for partners it has been enabled for. Please contact the SnapTrade team to enable it. The response schema may change. Check your API key on the [Customer Dashboard billing page](https://dashboard.snaptrade.com/settings/billing) to see if you have real-time data access: - If you do, this endpoint returns real-time data. - If you don't, Daily data is cached and refreshed once a day. Exact refresh timing may vary by institution. If you need real-time, use the [manual refresh](/reference/Connections/Connections_refreshBrokerageAuthorization) endpoint. `data_freshness.as_of` is the time the returned data was fetched from the institution. If the connection has become disabled, it can no longer access the latest data from the institution, but will continue to return the last available cached state. Please see [this guide](/docs/fix-broken-connections) on how to fix a disabled connection.
340
+ # @param user_id [String]
341
+ # @param user_secret [String]
342
+ # @param account_id [String]
343
+ # @param [Hash] opts the optional parameters
344
+ # @return [AccountBalancesV2Response]
345
+ private def get_account_balances_v2_impl(user_id, user_secret, account_id, opts = {})
346
+ data, _status_code, _headers = get_account_balances_v2_with_http_info(user_id, user_secret, account_id, opts)
347
+ data
348
+ end
349
+
350
+ # Get account balances
351
+ # Returns the account&#39;s balances in a single snapshot: total net value, cash per currency, buying power, and margin details for margin accounts. Every field is always present and is &#x60;null&#x60; when the institution doesn&#39;t report it. **Beta:** this endpoint is only available for partners it has been enabled for. Please contact the SnapTrade team to enable it. The response schema may change. Check your API key on the [Customer Dashboard billing page](https://dashboard.snaptrade.com/settings/billing) to see if you have real-time data access: - If you do, this endpoint returns real-time data. - If you don&#39;t, Daily data is cached and refreshed once a day. Exact refresh timing may vary by institution. If you need real-time, use the [manual refresh](/reference/Connections/Connections_refreshBrokerageAuthorization) endpoint. &#x60;data_freshness.as_of&#x60; is the time the returned data was fetched from the institution. If the connection has become disabled, it can no longer access the latest data from the institution, but will continue to return the last available cached state. Please see [this guide](/docs/fix-broken-connections) on how to fix a disabled connection.
352
+ # @param user_id [String]
353
+ # @param user_secret [String]
354
+ # @param account_id [String]
355
+ # @param [Hash] opts the optional parameters
356
+ # @return [Array<(AccountBalancesV2Response, Integer, Hash)>] AccountBalancesV2Response data, response status code and response headers
357
+ private def get_account_balances_v2_with_http_info_impl(user_id, user_secret, account_id, opts = {})
358
+ if @api_client.config.debugging
359
+ @api_client.config.logger.debug 'Calling API: AccountInformationApi.get_account_balances_v2 ...'
360
+ end
361
+ # verify the required parameter 'user_id' is set
362
+ if @api_client.config.client_side_validation && user_id.nil?
363
+ fail ArgumentError, "Missing the required parameter 'user_id' when calling AccountInformationApi.get_account_balances_v2"
364
+ end
365
+ # verify the required parameter 'user_secret' is set
366
+ if @api_client.config.client_side_validation && user_secret.nil?
367
+ fail ArgumentError, "Missing the required parameter 'user_secret' when calling AccountInformationApi.get_account_balances_v2"
368
+ end
369
+ # verify the required parameter 'account_id' is set
370
+ if @api_client.config.client_side_validation && account_id.nil?
371
+ fail ArgumentError, "Missing the required parameter 'account_id' when calling AccountInformationApi.get_account_balances_v2"
372
+ end
373
+ # resource path
374
+ local_var_path = '/accounts/{accountId}/balances/v2'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
375
+
376
+ # query parameters
377
+ query_params = opts[:query_params] || {}
378
+ query_params[:'userId'] = user_id
379
+ query_params[:'userSecret'] = user_secret
380
+
381
+ # header parameters
382
+ header_params = opts[:header_params] || {}
383
+ # HTTP header 'Accept' (if needed)
384
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
385
+
386
+ # form parameters
387
+ form_params = opts[:form_params] || {}
388
+
389
+ # http body (model)
390
+ post_body = opts[:debug_body]
391
+
392
+ # return_type
393
+ return_type = opts[:debug_return_type] || 'AccountBalancesV2Response'
394
+
395
+ # auth_names
396
+ auth_names = opts[:debug_auth_names] || ['PartnerClientId', 'PartnerSignature', 'PartnerTimestamp']
397
+
398
+ new_options = opts.merge(
399
+ :operation => :"AccountInformationApi.get_account_balances_v2",
400
+ :header_params => header_params,
401
+ :query_params => query_params,
402
+ :form_params => form_params,
403
+ :body => post_body,
404
+ :auth_names => auth_names,
405
+ :return_type => return_type
406
+ )
407
+
408
+ data, status_code, headers, response = @api_client.call_api(:GET, local_var_path, new_options)
409
+ if @api_client.config.debugging
410
+ @api_client.config.logger.debug "API called: AccountInformationApi#get_account_balances_v2\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
411
+ end
412
+ return data, status_code, headers, response
413
+ end
414
+
415
+
293
416
  # Get account details
294
417
  #
295
418
  # Returns the specified account for the authenticated user. The account can be an investment, deposit, or line of credit account. Use the `kind` discriminator to determine the schema for the account.
@@ -0,0 +1,306 @@
1
+ =begin
2
+ #SnapTrade
3
+
4
+ #Connect brokerage accounts to your app for live positions and trading. ## Rate limiting Two limits apply to requests signed with your `clientId`. The stricter one wins, and exceeding either returns `429 Too Many Requests`. - **Customer-level** — 250 requests/minute by default, scoped to your `clientId` and applied across all endpoints. Reported in `X-RateLimit-Limit`, `X-RateLimit-Remaining` and `X-RateLimit-Reset`. - **Account-level** — 10 requests/minute per account, scoped to (`clientId`, `accountId`). All covered operations for one account draw on the same bucket — reading balances and reading positions share it — and enforcement does not depend on the HTTP method, so updating an account consumes the same bucket as reading it. Only enforced for Personal users, and only for integrations it has been rolled out to — it is not yet in force for every Personal integration. It also does not apply on every operation that documents a 429 below. Where it applies it is reported in `X-RateLimit-Account-Limit`, `X-RateLimit-Account-Remaining` and `X-RateLimit-Account-Reset`. Do not read the absence of those headers as proof the limit is off — some configurations omit the rate limit headers while still enforcing the limit, so header absence tells you nothing about your allowance. On a 429, `X-RateLimit-Remaining: 0` means you hit the customer-level limit and `X-RateLimit-Account-Remaining: 0` means the account-level one. Wait for the corresponding `*-Reset` value (seconds) before retrying, or fall back to exponential backoff with jitter. Not every 429 is explained by those headers. A separate per-authenticated-user limit, reported in no `X-RateLimit-*` header, covers OAuth-authenticated requests and signed requests in configurations where the customer-level limit is not in effect — on the operations that use the default throttles. A few operations override those and are governed by the customer-level limit alone. The two do not stack: a signed request governed by the customer-level limit above is not additionally subject to the per-user one. If a 429 arrives with no header at zero — or with no `X-RateLimit-*` headers at all — honour `Retry-After` and back off. Treat the remaining counts as a hint, not a guarantee that the next request will succeed. Because the customer-level limit applies everywhere, any signed request can return 429. **OAuth-authenticated requests are an exception.** They are not subject to the customer-level limit and do not receive `X-RateLimit-Limit`, `X-RateLimit-Remaining` or `X-RateLimit-Reset` — do not wait on those headers or design around a customer-level allowance on this path. The account-level limit still applies to them on the account-data endpoints above, reported in the `X-RateLimit-Account-*` headers. On operations using the default throttles the per-user limit above applies to them as well, so an OAuth request can be rejected while the account headers still show capacity; on the few operations that override those throttles, OAuth callers have no per-user ceiling at all. Drive retries from `Retry-After` and exponential backoff with jitter rather than from the headers. See https://docs.snaptrade.com/docs/ratelimiting.
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+ Contact: api@snaptrade.com
8
+ =end
9
+
10
+ require 'date'
11
+ require 'time'
12
+
13
+ module SnapTrade
14
+ # Balances for a single account, fetched together as one snapshot.
15
+ class AccountBalancesV2Response
16
+ # Unique identifier for the connected brokerage account. This is the UUID used to reference the account in SnapTrade.
17
+ attr_accessor :account_id
18
+
19
+ # Whether the account is a cash or margin account. Same values as `cash_or_margin` on the [get account details](/reference/Account%20Information/AccountInformation_getAccountDetails) endpoint.
20
+ attr_accessor :cash_or_margin
21
+
22
+ attr_accessor :net_value
23
+
24
+ # Cash held in the account, one entry per currency. Some institutions allow holding multiple currencies in the same account.
25
+ attr_accessor :cash
26
+
27
+ # How much the account can spend on new purchases, one entry per currency. Amounts are in different currencies and shouldn't be added together. Null when it can't be determined. - **Cash accounts:** one entry per currency held, never more than the cash in that currency. Each entry is the settled cash available to spend in that currency where the institution reports it; otherwise it's the institution's buying power or cash, which may include proceeds from trades that haven't settled. Check `basis`. - **Margin accounts:** usually a single entry: the institution's buying power for positions held overnight, based on the account's total equity. Buying power for trades opened and closed on the same day can be higher and isn't included.
28
+ attr_accessor :buying_power
29
+
30
+ attr_accessor :margin
31
+
32
+ attr_accessor :data_freshness
33
+
34
+ # Attribute mapping from ruby-style variable name to JSON key.
35
+ def self.attribute_map
36
+ {
37
+ :'account_id' => :'account_id',
38
+ :'cash_or_margin' => :'cash_or_margin',
39
+ :'net_value' => :'net_value',
40
+ :'cash' => :'cash',
41
+ :'buying_power' => :'buying_power',
42
+ :'margin' => :'margin',
43
+ :'data_freshness' => :'data_freshness'
44
+ }
45
+ end
46
+
47
+ # Returns all the JSON keys this model knows about
48
+ def self.acceptable_attributes
49
+ attribute_map.values
50
+ end
51
+
52
+ # Attribute type mapping.
53
+ def self.openapi_types
54
+ {
55
+ :'account_id' => :'String',
56
+ :'cash_or_margin' => :'AccountBalancesV2ResponseCashOrMargin',
57
+ :'net_value' => :'AccountBalancesV2ResponseNetValue',
58
+ :'cash' => :'Array<AccountBalancesV2ResponseCashInner>',
59
+ :'buying_power' => :'Array<AccountBalancesV2ResponseBuyingPowerInner>',
60
+ :'margin' => :'AccountBalancesV2ResponseMargin',
61
+ :'data_freshness' => :'AccountBalancesV2ResponseDataFreshness'
62
+ }
63
+ end
64
+
65
+ # List of attributes with nullable: true
66
+ def self.openapi_nullable
67
+ Set.new([
68
+ :'buying_power',
69
+ :'margin',
70
+ ])
71
+ end
72
+
73
+ # Initializes the object
74
+ # @param [Hash] attributes Model attributes in the form of hash
75
+ def initialize(attributes = {})
76
+ if (!attributes.is_a?(Hash))
77
+ fail ArgumentError, "The input argument (attributes) must be a hash in `SnapTrade::AccountBalancesV2Response` initialize method"
78
+ end
79
+
80
+ # check to see if the attribute exists and convert string to symbol for hash key
81
+ attributes = attributes.each_with_object({}) { |(k, v), h|
82
+ if (!self.class.attribute_map.key?(k.to_sym))
83
+ fail ArgumentError, "`#{k}` is not a valid attribute in `SnapTrade::AccountBalancesV2Response`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
84
+ end
85
+ h[k.to_sym] = v
86
+ }
87
+
88
+ if attributes.key?(:'account_id')
89
+ self.account_id = attributes[:'account_id']
90
+ end
91
+
92
+ if attributes.key?(:'cash_or_margin')
93
+ self.cash_or_margin = attributes[:'cash_or_margin']
94
+ end
95
+
96
+ if attributes.key?(:'net_value')
97
+ self.net_value = attributes[:'net_value']
98
+ end
99
+
100
+ if attributes.key?(:'cash')
101
+ if (value = attributes[:'cash']).is_a?(Array)
102
+ self.cash = value
103
+ end
104
+ end
105
+
106
+ if attributes.key?(:'buying_power')
107
+ if (value = attributes[:'buying_power']).is_a?(Array)
108
+ self.buying_power = value
109
+ end
110
+ end
111
+
112
+ if attributes.key?(:'margin')
113
+ self.margin = attributes[:'margin']
114
+ end
115
+
116
+ if attributes.key?(:'data_freshness')
117
+ self.data_freshness = attributes[:'data_freshness']
118
+ end
119
+ end
120
+
121
+ # Show invalid properties with the reasons. Usually used together with valid?
122
+ # @return Array for valid properties with the reasons
123
+ def list_invalid_properties
124
+ invalid_properties = Array.new
125
+ if @account_id.nil?
126
+ invalid_properties.push('invalid value for "account_id", account_id cannot be nil.')
127
+ end
128
+
129
+ if @cash_or_margin.nil?
130
+ invalid_properties.push('invalid value for "cash_or_margin", cash_or_margin cannot be nil.')
131
+ end
132
+
133
+ if @net_value.nil?
134
+ invalid_properties.push('invalid value for "net_value", net_value cannot be nil.')
135
+ end
136
+
137
+ if @cash.nil?
138
+ invalid_properties.push('invalid value for "cash", cash cannot be nil.')
139
+ end
140
+
141
+ if @data_freshness.nil?
142
+ invalid_properties.push('invalid value for "data_freshness", data_freshness cannot be nil.')
143
+ end
144
+
145
+ invalid_properties
146
+ end
147
+
148
+ # Check to see if the all the properties in the model are valid
149
+ # @return true if the model is valid
150
+ def valid?
151
+ return false if @account_id.nil?
152
+ return false if @cash_or_margin.nil?
153
+ return false if @net_value.nil?
154
+ return false if @cash.nil?
155
+ return false if @data_freshness.nil?
156
+ true
157
+ end
158
+
159
+ # Checks equality by comparing each attribute.
160
+ # @param [Object] Object to be compared
161
+ def ==(o)
162
+ return true if self.equal?(o)
163
+ self.class == o.class &&
164
+ account_id == o.account_id &&
165
+ cash_or_margin == o.cash_or_margin &&
166
+ net_value == o.net_value &&
167
+ cash == o.cash &&
168
+ buying_power == o.buying_power &&
169
+ margin == o.margin &&
170
+ data_freshness == o.data_freshness
171
+ end
172
+
173
+ # @see the `==` method
174
+ # @param [Object] Object to be compared
175
+ def eql?(o)
176
+ self == o
177
+ end
178
+
179
+ # Calculates hash code according to all attributes.
180
+ # @return [Integer] Hash code
181
+ def hash
182
+ [account_id, cash_or_margin, net_value, cash, buying_power, margin, data_freshness].hash
183
+ end
184
+
185
+ # Builds the object from hash
186
+ # @param [Hash] attributes Model attributes in the form of hash
187
+ # @return [Object] Returns the model itself
188
+ def self.build_from_hash(attributes)
189
+ new.build_from_hash(attributes)
190
+ end
191
+
192
+ # Builds the object from hash
193
+ # @param [Hash] attributes Model attributes in the form of hash
194
+ # @return [Object] Returns the model itself
195
+ def build_from_hash(attributes)
196
+ return nil unless attributes.is_a?(Hash)
197
+ attributes = attributes.transform_keys(&:to_sym)
198
+ self.class.openapi_types.each_pair do |key, type|
199
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
200
+ self.send("#{key}=", nil)
201
+ elsif type =~ /\AArray<(.*)>/i
202
+ # check to ensure the input is an array given that the attribute
203
+ # is documented as an array but the input is not
204
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
205
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
206
+ end
207
+ elsif !attributes[self.class.attribute_map[key]].nil?
208
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
209
+ end
210
+ end
211
+
212
+ self
213
+ end
214
+
215
+ # Deserializes the data based on type
216
+ # @param string type Data type
217
+ # @param string value Value to be deserialized
218
+ # @return [Object] Deserialized data
219
+ def _deserialize(type, value)
220
+ case type.to_sym
221
+ when :Time
222
+ Time.parse(value)
223
+ when :Date
224
+ Date.parse(value)
225
+ when :String
226
+ value.to_s
227
+ when :Integer
228
+ value.to_i
229
+ when :Float
230
+ value.to_f
231
+ when :Boolean
232
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
233
+ true
234
+ else
235
+ false
236
+ end
237
+ when :Object
238
+ # generic object (usually a Hash), return directly
239
+ value
240
+ when /\AArray<(?<inner_type>.+)>\z/
241
+ inner_type = Regexp.last_match[:inner_type]
242
+ value.map { |v| _deserialize(inner_type, v) }
243
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
244
+ k_type = Regexp.last_match[:k_type]
245
+ v_type = Regexp.last_match[:v_type]
246
+ {}.tap do |hash|
247
+ value.each do |k, v|
248
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
249
+ end
250
+ end
251
+ else # model
252
+ # models (e.g. Pet) or oneOf
253
+ klass = SnapTrade.const_get(type)
254
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
255
+ end
256
+ end
257
+
258
+ # Returns the string representation of the object
259
+ # @return [String] String presentation of the object
260
+ def to_s
261
+ to_hash.to_s
262
+ end
263
+
264
+ # to_body is an alias to to_hash (backward compatibility)
265
+ # @return [Hash] Returns the object in the form of hash
266
+ def to_body
267
+ to_hash
268
+ end
269
+
270
+ # Returns the object in the form of hash
271
+ # @return [Hash] Returns the object in the form of hash
272
+ def to_hash
273
+ hash = {}
274
+ self.class.attribute_map.each_pair do |attr, param|
275
+ value = self.send(attr)
276
+ if value.nil?
277
+ is_nullable = self.class.openapi_nullable.include?(attr)
278
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
279
+ end
280
+
281
+ hash[param] = _to_hash(value)
282
+ end
283
+ hash
284
+ end
285
+
286
+ # Outputs non-array value in the form of hash
287
+ # For object, use to_hash. Otherwise, just return the value
288
+ # @param [Object] value Any valid value
289
+ # @return [Hash] Returns the value in the form of hash
290
+ def _to_hash(value)
291
+ if value.is_a?(Array)
292
+ value.compact.map { |v| _to_hash(v) }
293
+ elsif value.is_a?(Hash)
294
+ {}.tap do |hash|
295
+ value.each { |k, v| hash[k] = _to_hash(v) }
296
+ end
297
+ elsif value.respond_to? :to_hash
298
+ value.to_hash
299
+ else
300
+ value
301
+ end
302
+ end
303
+
304
+ end
305
+
306
+ end