snaptrade 3.0.59 → 3.0.61
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.
- checksums.yaml +4 -4
- data/README.md +63 -2
- data/lib/snaptrade/api/account_information_api.rb +154 -0
- data/lib/snaptrade/models/account_transactions_response.rb +239 -0
- data/lib/snaptrade/models/account_transactions_response_pagination.rb +244 -0
- data/lib/snaptrade/models/activity.rb +351 -0
- data/lib/snaptrade/version.rb +1 -1
- data/lib/snaptrade.rb +3 -0
- data/spec/api/account_information_api_spec.rb +19 -0
- data/spec/models/account_transactions_response_pagination_spec.rb +41 -0
- data/spec/models/account_transactions_response_spec.rb +35 -0
- data/spec/models/activity_spec.rb +89 -0
- metadata +302 -293
|
@@ -0,0 +1,244 @@
|
|
|
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
|
+
class AccountTransactionsResponsePagination
|
|
15
|
+
# The starting point of the paginated results.
|
|
16
|
+
attr_accessor :offset
|
|
17
|
+
|
|
18
|
+
# The maximum number of items to return in the response.
|
|
19
|
+
attr_accessor :limit
|
|
20
|
+
|
|
21
|
+
# The total number of items available to be returned over the API.
|
|
22
|
+
attr_accessor :total
|
|
23
|
+
|
|
24
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
|
25
|
+
def self.attribute_map
|
|
26
|
+
{
|
|
27
|
+
:'offset' => :'offset',
|
|
28
|
+
:'limit' => :'limit',
|
|
29
|
+
:'total' => :'total'
|
|
30
|
+
}
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Returns all the JSON keys this model knows about
|
|
34
|
+
def self.acceptable_attributes
|
|
35
|
+
attribute_map.values
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Attribute type mapping.
|
|
39
|
+
def self.openapi_types
|
|
40
|
+
{
|
|
41
|
+
:'offset' => :'Integer',
|
|
42
|
+
:'limit' => :'Integer',
|
|
43
|
+
:'total' => :'Integer'
|
|
44
|
+
}
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# List of attributes with nullable: true
|
|
48
|
+
def self.openapi_nullable
|
|
49
|
+
Set.new([
|
|
50
|
+
])
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# List of class defined in allOf (OpenAPI v3)
|
|
54
|
+
def self.openapi_all_of
|
|
55
|
+
[
|
|
56
|
+
:'PaginationDetails'
|
|
57
|
+
]
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Initializes the object
|
|
61
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
|
62
|
+
def initialize(attributes = {})
|
|
63
|
+
if (!attributes.is_a?(Hash))
|
|
64
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `SnapTrade::AccountTransactionsResponsePagination` initialize method"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
|
68
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
|
69
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
|
70
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `SnapTrade::AccountTransactionsResponsePagination`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
|
71
|
+
end
|
|
72
|
+
h[k.to_sym] = v
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if attributes.key?(:'offset')
|
|
76
|
+
self.offset = attributes[:'offset']
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
if attributes.key?(:'limit')
|
|
80
|
+
self.limit = attributes[:'limit']
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
if attributes.key?(:'total')
|
|
84
|
+
self.total = attributes[:'total']
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
|
89
|
+
# @return Array for valid properties with the reasons
|
|
90
|
+
def list_invalid_properties
|
|
91
|
+
invalid_properties = Array.new
|
|
92
|
+
invalid_properties
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Check to see if the all the properties in the model are valid
|
|
96
|
+
# @return true if the model is valid
|
|
97
|
+
def valid?
|
|
98
|
+
true
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Checks equality by comparing each attribute.
|
|
102
|
+
# @param [Object] Object to be compared
|
|
103
|
+
def ==(o)
|
|
104
|
+
return true if self.equal?(o)
|
|
105
|
+
self.class == o.class &&
|
|
106
|
+
offset == o.offset &&
|
|
107
|
+
limit == o.limit &&
|
|
108
|
+
total == o.total
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# @see the `==` method
|
|
112
|
+
# @param [Object] Object to be compared
|
|
113
|
+
def eql?(o)
|
|
114
|
+
self == o
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Calculates hash code according to all attributes.
|
|
118
|
+
# @return [Integer] Hash code
|
|
119
|
+
def hash
|
|
120
|
+
[offset, limit, total].hash
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# Builds the object from hash
|
|
124
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
|
125
|
+
# @return [Object] Returns the model itself
|
|
126
|
+
def self.build_from_hash(attributes)
|
|
127
|
+
new.build_from_hash(attributes)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Builds the object from hash
|
|
131
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
|
132
|
+
# @return [Object] Returns the model itself
|
|
133
|
+
def build_from_hash(attributes)
|
|
134
|
+
return nil unless attributes.is_a?(Hash)
|
|
135
|
+
attributes = attributes.transform_keys(&:to_sym)
|
|
136
|
+
self.class.openapi_types.each_pair do |key, type|
|
|
137
|
+
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
|
|
138
|
+
self.send("#{key}=", nil)
|
|
139
|
+
elsif type =~ /\AArray<(.*)>/i
|
|
140
|
+
# check to ensure the input is an array given that the attribute
|
|
141
|
+
# is documented as an array but the input is not
|
|
142
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
|
143
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
|
144
|
+
end
|
|
145
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
|
146
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
self
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# Deserializes the data based on type
|
|
154
|
+
# @param string type Data type
|
|
155
|
+
# @param string value Value to be deserialized
|
|
156
|
+
# @return [Object] Deserialized data
|
|
157
|
+
def _deserialize(type, value)
|
|
158
|
+
case type.to_sym
|
|
159
|
+
when :Time
|
|
160
|
+
Time.parse(value)
|
|
161
|
+
when :Date
|
|
162
|
+
Date.parse(value)
|
|
163
|
+
when :String
|
|
164
|
+
value.to_s
|
|
165
|
+
when :Integer
|
|
166
|
+
value.to_i
|
|
167
|
+
when :Float
|
|
168
|
+
value.to_f
|
|
169
|
+
when :Boolean
|
|
170
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
|
171
|
+
true
|
|
172
|
+
else
|
|
173
|
+
false
|
|
174
|
+
end
|
|
175
|
+
when :Object
|
|
176
|
+
# generic object (usually a Hash), return directly
|
|
177
|
+
value
|
|
178
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
|
179
|
+
inner_type = Regexp.last_match[:inner_type]
|
|
180
|
+
value.map { |v| _deserialize(inner_type, v) }
|
|
181
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
|
182
|
+
k_type = Regexp.last_match[:k_type]
|
|
183
|
+
v_type = Regexp.last_match[:v_type]
|
|
184
|
+
{}.tap do |hash|
|
|
185
|
+
value.each do |k, v|
|
|
186
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
else # model
|
|
190
|
+
# models (e.g. Pet) or oneOf
|
|
191
|
+
klass = SnapTrade.const_get(type)
|
|
192
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# Returns the string representation of the object
|
|
197
|
+
# @return [String] String presentation of the object
|
|
198
|
+
def to_s
|
|
199
|
+
to_hash.to_s
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
# to_body is an alias to to_hash (backward compatibility)
|
|
203
|
+
# @return [Hash] Returns the object in the form of hash
|
|
204
|
+
def to_body
|
|
205
|
+
to_hash
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
# Returns the object in the form of hash
|
|
209
|
+
# @return [Hash] Returns the object in the form of hash
|
|
210
|
+
def to_hash
|
|
211
|
+
hash = {}
|
|
212
|
+
self.class.attribute_map.each_pair do |attr, param|
|
|
213
|
+
value = self.send(attr)
|
|
214
|
+
if value.nil?
|
|
215
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
|
216
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
hash[param] = _to_hash(value)
|
|
220
|
+
end
|
|
221
|
+
hash
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
# Outputs non-array value in the form of hash
|
|
225
|
+
# For object, use to_hash. Otherwise, just return the value
|
|
226
|
+
# @param [Object] value Any valid value
|
|
227
|
+
# @return [Hash] Returns the value in the form of hash
|
|
228
|
+
def _to_hash(value)
|
|
229
|
+
if value.is_a?(Array)
|
|
230
|
+
value.compact.map { |v| _to_hash(v) }
|
|
231
|
+
elsif value.is_a?(Hash)
|
|
232
|
+
{}.tap do |hash|
|
|
233
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
|
234
|
+
end
|
|
235
|
+
elsif value.respond_to? :to_hash
|
|
236
|
+
value.to_hash
|
|
237
|
+
else
|
|
238
|
+
value
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
end
|
|
@@ -0,0 +1,351 @@
|
|
|
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
|
+
# A recorded transaction in a brokerage account.
|
|
15
|
+
class Activity
|
|
16
|
+
# Brokerage transaction reference, when available. Related transactions such as a fill and a fee can share this value.
|
|
17
|
+
attr_accessor :transaction_id
|
|
18
|
+
|
|
19
|
+
# Best-effort activity classification. A reported option action takes precedence over its base type. Common values include BUY, SELL, BUY_TO_OPEN, BUY_TO_CLOSE, SELL_TO_OPEN, SELL_TO_CLOSE, DIVIDEND, INTEREST, CONTRIBUTION, WITHDRAWAL, TRANSFER and FEE. Clients must accept unfamiliar values.
|
|
20
|
+
attr_accessor :type
|
|
21
|
+
|
|
22
|
+
# Recorded trade date and time in UTC. Precision depends on what the brokerage supplies.
|
|
23
|
+
attr_accessor :date
|
|
24
|
+
|
|
25
|
+
# Brokerage activity description, including an unresolved brokerage symbol's name when available.
|
|
26
|
+
attr_accessor :description
|
|
27
|
+
|
|
28
|
+
attr_accessor :instrument
|
|
29
|
+
|
|
30
|
+
attr_accessor :priced_in
|
|
31
|
+
|
|
32
|
+
# Signed amount recorded for the transaction. Use this value directly. Price, units and fees may be insufficient to reconstruct it.
|
|
33
|
+
attr_accessor :amount
|
|
34
|
+
|
|
35
|
+
# Recorded unit price. For options this is the price per underlying share. Some missing brokerage prices are stored as zero.
|
|
36
|
+
attr_accessor :price
|
|
37
|
+
|
|
38
|
+
# Signed quantity recorded for the transaction. For options the quantity counts contracts.
|
|
39
|
+
attr_accessor :units
|
|
40
|
+
|
|
41
|
+
# Recorded fee. Some missing brokerage fees are stored as zero.
|
|
42
|
+
attr_accessor :fee
|
|
43
|
+
|
|
44
|
+
# Foreign exchange rate recorded for the transaction, when available.
|
|
45
|
+
attr_accessor :fx_rate
|
|
46
|
+
|
|
47
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
|
48
|
+
def self.attribute_map
|
|
49
|
+
{
|
|
50
|
+
:'transaction_id' => :'transaction_id',
|
|
51
|
+
:'type' => :'type',
|
|
52
|
+
:'date' => :'date',
|
|
53
|
+
:'description' => :'description',
|
|
54
|
+
:'instrument' => :'instrument',
|
|
55
|
+
:'priced_in' => :'priced_in',
|
|
56
|
+
:'amount' => :'amount',
|
|
57
|
+
:'price' => :'price',
|
|
58
|
+
:'units' => :'units',
|
|
59
|
+
:'fee' => :'fee',
|
|
60
|
+
:'fx_rate' => :'fx_rate'
|
|
61
|
+
}
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Returns all the JSON keys this model knows about
|
|
65
|
+
def self.acceptable_attributes
|
|
66
|
+
attribute_map.values
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Attribute type mapping.
|
|
70
|
+
def self.openapi_types
|
|
71
|
+
{
|
|
72
|
+
:'transaction_id' => :'String',
|
|
73
|
+
:'type' => :'String',
|
|
74
|
+
:'date' => :'Time',
|
|
75
|
+
:'description' => :'String',
|
|
76
|
+
:'instrument' => :'Instrument',
|
|
77
|
+
:'priced_in' => :'PricedInInstrument',
|
|
78
|
+
:'amount' => :'Float',
|
|
79
|
+
:'price' => :'Float',
|
|
80
|
+
:'units' => :'Float',
|
|
81
|
+
:'fee' => :'Float',
|
|
82
|
+
:'fx_rate' => :'Float'
|
|
83
|
+
}
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# List of attributes with nullable: true
|
|
87
|
+
def self.openapi_nullable
|
|
88
|
+
Set.new([
|
|
89
|
+
:'transaction_id',
|
|
90
|
+
:'instrument',
|
|
91
|
+
:'priced_in',
|
|
92
|
+
:'price',
|
|
93
|
+
:'fx_rate'
|
|
94
|
+
])
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Initializes the object
|
|
98
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
|
99
|
+
def initialize(attributes = {})
|
|
100
|
+
if (!attributes.is_a?(Hash))
|
|
101
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `SnapTrade::Activity` initialize method"
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
|
105
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
|
106
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
|
107
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `SnapTrade::Activity`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
|
108
|
+
end
|
|
109
|
+
h[k.to_sym] = v
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if attributes.key?(:'transaction_id')
|
|
113
|
+
self.transaction_id = attributes[:'transaction_id']
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
if attributes.key?(:'type')
|
|
117
|
+
self.type = attributes[:'type']
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
if attributes.key?(:'date')
|
|
121
|
+
self.date = attributes[:'date']
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
if attributes.key?(:'description')
|
|
125
|
+
self.description = attributes[:'description']
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
if attributes.key?(:'instrument')
|
|
129
|
+
self.instrument = attributes[:'instrument']
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
if attributes.key?(:'priced_in')
|
|
133
|
+
self.priced_in = attributes[:'priced_in']
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
if attributes.key?(:'amount')
|
|
137
|
+
self.amount = attributes[:'amount']
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
if attributes.key?(:'price')
|
|
141
|
+
self.price = attributes[:'price']
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
if attributes.key?(:'units')
|
|
145
|
+
self.units = attributes[:'units']
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
if attributes.key?(:'fee')
|
|
149
|
+
self.fee = attributes[:'fee']
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
if attributes.key?(:'fx_rate')
|
|
153
|
+
self.fx_rate = attributes[:'fx_rate']
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
|
158
|
+
# @return Array for valid properties with the reasons
|
|
159
|
+
def list_invalid_properties
|
|
160
|
+
invalid_properties = Array.new
|
|
161
|
+
if @type.nil?
|
|
162
|
+
invalid_properties.push('invalid value for "type", type cannot be nil.')
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
if @date.nil?
|
|
166
|
+
invalid_properties.push('invalid value for "date", date cannot be nil.')
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
if @description.nil?
|
|
170
|
+
invalid_properties.push('invalid value for "description", description cannot be nil.')
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
if @amount.nil?
|
|
174
|
+
invalid_properties.push('invalid value for "amount", amount cannot be nil.')
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
if @units.nil?
|
|
178
|
+
invalid_properties.push('invalid value for "units", units cannot be nil.')
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
if @fee.nil?
|
|
182
|
+
invalid_properties.push('invalid value for "fee", fee cannot be nil.')
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
invalid_properties
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# Check to see if the all the properties in the model are valid
|
|
189
|
+
# @return true if the model is valid
|
|
190
|
+
def valid?
|
|
191
|
+
return false if @type.nil?
|
|
192
|
+
return false if @date.nil?
|
|
193
|
+
return false if @description.nil?
|
|
194
|
+
return false if @amount.nil?
|
|
195
|
+
return false if @units.nil?
|
|
196
|
+
return false if @fee.nil?
|
|
197
|
+
true
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# Checks equality by comparing each attribute.
|
|
201
|
+
# @param [Object] Object to be compared
|
|
202
|
+
def ==(o)
|
|
203
|
+
return true if self.equal?(o)
|
|
204
|
+
self.class == o.class &&
|
|
205
|
+
transaction_id == o.transaction_id &&
|
|
206
|
+
type == o.type &&
|
|
207
|
+
date == o.date &&
|
|
208
|
+
description == o.description &&
|
|
209
|
+
instrument == o.instrument &&
|
|
210
|
+
priced_in == o.priced_in &&
|
|
211
|
+
amount == o.amount &&
|
|
212
|
+
price == o.price &&
|
|
213
|
+
units == o.units &&
|
|
214
|
+
fee == o.fee &&
|
|
215
|
+
fx_rate == o.fx_rate
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# @see the `==` method
|
|
219
|
+
# @param [Object] Object to be compared
|
|
220
|
+
def eql?(o)
|
|
221
|
+
self == o
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
# Calculates hash code according to all attributes.
|
|
225
|
+
# @return [Integer] Hash code
|
|
226
|
+
def hash
|
|
227
|
+
[transaction_id, type, date, description, instrument, priced_in, amount, price, units, fee, fx_rate].hash
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
# Builds the object from hash
|
|
231
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
|
232
|
+
# @return [Object] Returns the model itself
|
|
233
|
+
def self.build_from_hash(attributes)
|
|
234
|
+
new.build_from_hash(attributes)
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
# Builds the object from hash
|
|
238
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
|
239
|
+
# @return [Object] Returns the model itself
|
|
240
|
+
def build_from_hash(attributes)
|
|
241
|
+
return nil unless attributes.is_a?(Hash)
|
|
242
|
+
attributes = attributes.transform_keys(&:to_sym)
|
|
243
|
+
self.class.openapi_types.each_pair do |key, type|
|
|
244
|
+
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
|
|
245
|
+
self.send("#{key}=", nil)
|
|
246
|
+
elsif type =~ /\AArray<(.*)>/i
|
|
247
|
+
# check to ensure the input is an array given that the attribute
|
|
248
|
+
# is documented as an array but the input is not
|
|
249
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
|
250
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
|
251
|
+
end
|
|
252
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
|
253
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
self
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
# Deserializes the data based on type
|
|
261
|
+
# @param string type Data type
|
|
262
|
+
# @param string value Value to be deserialized
|
|
263
|
+
# @return [Object] Deserialized data
|
|
264
|
+
def _deserialize(type, value)
|
|
265
|
+
case type.to_sym
|
|
266
|
+
when :Time
|
|
267
|
+
Time.parse(value)
|
|
268
|
+
when :Date
|
|
269
|
+
Date.parse(value)
|
|
270
|
+
when :String
|
|
271
|
+
value.to_s
|
|
272
|
+
when :Integer
|
|
273
|
+
value.to_i
|
|
274
|
+
when :Float
|
|
275
|
+
value.to_f
|
|
276
|
+
when :Boolean
|
|
277
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
|
278
|
+
true
|
|
279
|
+
else
|
|
280
|
+
false
|
|
281
|
+
end
|
|
282
|
+
when :Object
|
|
283
|
+
# generic object (usually a Hash), return directly
|
|
284
|
+
value
|
|
285
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
|
286
|
+
inner_type = Regexp.last_match[:inner_type]
|
|
287
|
+
value.map { |v| _deserialize(inner_type, v) }
|
|
288
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
|
289
|
+
k_type = Regexp.last_match[:k_type]
|
|
290
|
+
v_type = Regexp.last_match[:v_type]
|
|
291
|
+
{}.tap do |hash|
|
|
292
|
+
value.each do |k, v|
|
|
293
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
|
294
|
+
end
|
|
295
|
+
end
|
|
296
|
+
else # model
|
|
297
|
+
# models (e.g. Pet) or oneOf
|
|
298
|
+
klass = SnapTrade.const_get(type)
|
|
299
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
# Returns the string representation of the object
|
|
304
|
+
# @return [String] String presentation of the object
|
|
305
|
+
def to_s
|
|
306
|
+
to_hash.to_s
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
# to_body is an alias to to_hash (backward compatibility)
|
|
310
|
+
# @return [Hash] Returns the object in the form of hash
|
|
311
|
+
def to_body
|
|
312
|
+
to_hash
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
# Returns the object in the form of hash
|
|
316
|
+
# @return [Hash] Returns the object in the form of hash
|
|
317
|
+
def to_hash
|
|
318
|
+
hash = {}
|
|
319
|
+
self.class.attribute_map.each_pair do |attr, param|
|
|
320
|
+
value = self.send(attr)
|
|
321
|
+
if value.nil?
|
|
322
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
|
323
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
hash[param] = _to_hash(value)
|
|
327
|
+
end
|
|
328
|
+
hash
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
# Outputs non-array value in the form of hash
|
|
332
|
+
# For object, use to_hash. Otherwise, just return the value
|
|
333
|
+
# @param [Object] value Any valid value
|
|
334
|
+
# @return [Hash] Returns the value in the form of hash
|
|
335
|
+
def _to_hash(value)
|
|
336
|
+
if value.is_a?(Array)
|
|
337
|
+
value.compact.map { |v| _to_hash(v) }
|
|
338
|
+
elsif value.is_a?(Hash)
|
|
339
|
+
{}.tap do |hash|
|
|
340
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
|
341
|
+
end
|
|
342
|
+
elsif value.respond_to? :to_hash
|
|
343
|
+
value.to_hash
|
|
344
|
+
else
|
|
345
|
+
value
|
|
346
|
+
end
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
end
|
data/lib/snaptrade/version.rb
CHANGED
data/lib/snaptrade.rb
CHANGED
|
@@ -53,6 +53,8 @@ require 'snaptrade/models/account_position'
|
|
|
53
53
|
require 'snaptrade/models/account_simple'
|
|
54
54
|
require 'snaptrade/models/account_status'
|
|
55
55
|
require 'snaptrade/models/account_sync_status'
|
|
56
|
+
require 'snaptrade/models/account_transactions_response'
|
|
57
|
+
require 'snaptrade/models/account_transactions_response_pagination'
|
|
56
58
|
require 'snaptrade/models/account_universal_activity'
|
|
57
59
|
require 'snaptrade/models/account_universal_activity_currency'
|
|
58
60
|
require 'snaptrade/models/account_universal_activity_currency_universal_symbol'
|
|
@@ -62,6 +64,7 @@ require 'snaptrade/models/account_value_history_item'
|
|
|
62
64
|
require 'snaptrade/models/account_value_history_response'
|
|
63
65
|
require 'snaptrade/models/action_strict'
|
|
64
66
|
require 'snaptrade/models/action_strict_with_options'
|
|
67
|
+
require 'snaptrade/models/activity'
|
|
65
68
|
require 'snaptrade/models/adr_instrument'
|
|
66
69
|
require 'snaptrade/models/adr_instrument_kind'
|
|
67
70
|
require 'snaptrade/models/all_account_orders_response'
|
|
@@ -103,6 +103,25 @@ describe 'AccountInformationApi' do
|
|
|
103
103
|
end
|
|
104
104
|
end
|
|
105
105
|
|
|
106
|
+
# unit tests for get_account_transactions
|
|
107
|
+
# List account transactions
|
|
108
|
+
# Returns the account's cached transaction history, most recent trade date first. Transactions with the same timestamp are ordered by descending internal activity ID. History refreshes daily. Timing and available history depend on the brokerage. A disabled connection continues to return its last cached history.
|
|
109
|
+
# @param account_id
|
|
110
|
+
# @param user_id
|
|
111
|
+
# @param user_secret
|
|
112
|
+
# @param [Hash] opts the optional parameters
|
|
113
|
+
# @option opts [Date] :start_date First trade date to include (UTC). Defaults to the earliest available transaction.
|
|
114
|
+
# @option opts [Date] :end_date Last trade date to include (UTC). Defaults to the latest available transaction.
|
|
115
|
+
# @option opts [String] :type Comma-separated activity types. A transaction matches its base type or its option action, case-insensitively. For example, BUY includes opening and closing option purchases, while BUY_TO_OPEN selects only opening purchases. A transaction matching multiple values appears once.
|
|
116
|
+
# @option opts [Integer] :offset Number of matching transactions to skip.
|
|
117
|
+
# @option opts [Integer] :limit Maximum number of transactions to return in this page.
|
|
118
|
+
# @return [AccountTransactionsResponse]
|
|
119
|
+
describe 'get_account_transactions test' do
|
|
120
|
+
it 'should work' do
|
|
121
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
106
125
|
# unit tests for get_all_account_orders
|
|
107
126
|
# List all account orders
|
|
108
127
|
# Returns a list of recent orders in the specified account, in the same `kind`-discriminated format as `/accounts/{accountId}/positions/all`. Every order carries a `legs` list with at least one leg. Each leg's `instrument` uses the same `Instrument` union as positions; switch on `instrument.kind` to know which fields are present. Multi-leg orders (spreads, strangles, covered calls) are a single order with multiple legs. Orders that belong to a complex order group (OCO, OTO, OTOCO) share a `group.id`. `order_type` is an object discriminated by `kind`. Each kind declares the price fields it requires (`limit_price` on `limit`, `stop_price` on `stop`, both on `stop_limit`, `trail` on `trailing_stop`), so a consumer never has to null-check a price that cannot exist for that kind. When the brokerage reports an order type we cannot normalize, `kind` is `other` and the brokerage's own label is in `raw_type`. **Beta:** this endpoint and its response schema may change. If the connection has become disabled, it can no longer access the latest data from the brokerage, 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.
|