snaptrade 2.0.106 → 2.0.107

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.
@@ -0,0 +1,408 @@
1
+ =begin
2
+ #SnapTrade
3
+
4
+ #Connect brokerage accounts to your app for live positions and trading
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+ Contact: api@snaptrade.com
8
+ =end
9
+
10
+ require 'cgi'
11
+
12
+ module SnapTrade
13
+ class CryptoTradingApi
14
+ attr_accessor :api_client
15
+
16
+ def initialize(api_client = ApiClient.default)
17
+ @api_client = api_client
18
+ end
19
+
20
+ # Get cryptocurrency pair quote
21
+ #
22
+ # Gets a quote for the specified account.
23
+ #
24
+ # @param user_id [String]
25
+ # @param user_secret [String]
26
+ # @param account_id [String]
27
+ # @param instrument_symbol [String]
28
+ # @param [Hash] extra additional parameters to pass along through :header_params, :query_params, or parameter name
29
+ def get_cryptocurrency_pair_quote(user_id:, user_secret:, account_id:, instrument_symbol:, extra: {})
30
+ data, _status_code, _headers = get_cryptocurrency_pair_quote_with_http_info_impl(user_id, user_secret, account_id, instrument_symbol, extra)
31
+ data
32
+ end
33
+
34
+ # Get cryptocurrency pair quote
35
+ #
36
+ # Gets a quote for the specified account.
37
+ #
38
+ # @param user_id [String]
39
+ # @param user_secret [String]
40
+ # @param account_id [String]
41
+ # @param instrument_symbol [String]
42
+ # @param [Hash] extra additional parameters to pass along through :header_params, :query_params, or parameter name
43
+ def get_cryptocurrency_pair_quote_with_http_info(user_id:, user_secret:, account_id:, instrument_symbol:, extra: {})
44
+ get_cryptocurrency_pair_quote_with_http_info_impl(user_id, user_secret, account_id, instrument_symbol, extra)
45
+ end
46
+
47
+ # Get cryptocurrency pair quote
48
+ # Gets a quote for the specified account.
49
+ # @param user_id [String]
50
+ # @param user_secret [String]
51
+ # @param account_id [String]
52
+ # @param instrument_symbol [String]
53
+ # @param [Hash] opts the optional parameters
54
+ # @return [CryptocurrencyPairQuote]
55
+ private def get_cryptocurrency_pair_quote_impl(user_id, user_secret, account_id, instrument_symbol, opts = {})
56
+ data, _status_code, _headers = get_cryptocurrency_pair_quote_with_http_info(user_id, user_secret, account_id, instrument_symbol, opts)
57
+ data
58
+ end
59
+
60
+ # Get cryptocurrency pair quote
61
+ # Gets a quote for the specified account.
62
+ # @param user_id [String]
63
+ # @param user_secret [String]
64
+ # @param account_id [String]
65
+ # @param instrument_symbol [String]
66
+ # @param [Hash] opts the optional parameters
67
+ # @return [Array<(CryptocurrencyPairQuote, Integer, Hash)>] CryptocurrencyPairQuote data, response status code and response headers
68
+ private def get_cryptocurrency_pair_quote_with_http_info_impl(user_id, user_secret, account_id, instrument_symbol, opts = {})
69
+ if @api_client.config.debugging
70
+ @api_client.config.logger.debug 'Calling API: CryptoTradingApi.get_cryptocurrency_pair_quote ...'
71
+ end
72
+ # verify the required parameter 'user_id' is set
73
+ if @api_client.config.client_side_validation && user_id.nil?
74
+ fail ArgumentError, "Missing the required parameter 'user_id' when calling CryptoTradingApi.get_cryptocurrency_pair_quote"
75
+ end
76
+ # verify the required parameter 'user_secret' is set
77
+ if @api_client.config.client_side_validation && user_secret.nil?
78
+ fail ArgumentError, "Missing the required parameter 'user_secret' when calling CryptoTradingApi.get_cryptocurrency_pair_quote"
79
+ end
80
+ # verify the required parameter 'account_id' is set
81
+ if @api_client.config.client_side_validation && account_id.nil?
82
+ fail ArgumentError, "Missing the required parameter 'account_id' when calling CryptoTradingApi.get_cryptocurrency_pair_quote"
83
+ end
84
+ # verify the required parameter 'instrument_symbol' is set
85
+ if @api_client.config.client_side_validation && instrument_symbol.nil?
86
+ fail ArgumentError, "Missing the required parameter 'instrument_symbol' when calling CryptoTradingApi.get_cryptocurrency_pair_quote"
87
+ end
88
+ # resource path
89
+ local_var_path = '/accounts/{accountId}/trading/instruments/cryptocurrencyPairs/{instrumentSymbol}/quote'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s)).sub('{' + 'instrumentSymbol' + '}', CGI.escape(instrument_symbol.to_s))
90
+
91
+ # query parameters
92
+ query_params = opts[:query_params] || {}
93
+ query_params[:'userId'] = user_id
94
+ query_params[:'userSecret'] = user_secret
95
+
96
+ # header parameters
97
+ header_params = opts[:header_params] || {}
98
+ # HTTP header 'Accept' (if needed)
99
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
100
+
101
+ # form parameters
102
+ form_params = opts[:form_params] || {}
103
+
104
+ # http body (model)
105
+ post_body = opts[:debug_body]
106
+
107
+ # return_type
108
+ return_type = opts[:debug_return_type] || 'CryptocurrencyPairQuote'
109
+
110
+ # auth_names
111
+ auth_names = opts[:debug_auth_names] || ['PartnerClientId', 'PartnerSignature', 'PartnerTimestamp']
112
+
113
+ new_options = opts.merge(
114
+ :operation => :"CryptoTradingApi.get_cryptocurrency_pair_quote",
115
+ :header_params => header_params,
116
+ :query_params => query_params,
117
+ :form_params => form_params,
118
+ :body => post_body,
119
+ :auth_names => auth_names,
120
+ :return_type => return_type
121
+ )
122
+
123
+ data, status_code, headers, response = @api_client.call_api(:GET, local_var_path, new_options)
124
+ if @api_client.config.debugging
125
+ @api_client.config.logger.debug "API called: CryptoTradingApi#get_cryptocurrency_pair_quote\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
126
+ end
127
+ return data, status_code, headers, response
128
+ end
129
+
130
+
131
+ # Place order
132
+ #
133
+ # Places an order in the specified account.
134
+ # This endpoint does not compute the impact to the account balance from the order before submitting the order.
135
+ #
136
+ # @param instrument [TradingInstrument]
137
+ # @param side [ActionStrict] The action describes the intent or side of a trade. This is either `BUY` or `SELL`.
138
+ # @param type [SimpleOrderFormType] The type of order to place.
139
+ # @param time_in_force [SimpleOrderFormTimeInForce] The Time in Force type for the order. This field indicates how long the order will remain active before it is executed or expires. - `GTC` - Good Til Canceled. The order is valid until it is executed or canceled. - `FOK` - Fill Or Kill. The order must be executed in its entirety immediately or be canceled completely. - `IOC` - Immediate Or Cancel. The order must be executed immediately. Any portion of the order that cannot be filled immediately will be canceled. - `GTD` - Good Til Date. The order is valid until the specified date.
140
+ # @param amount [Float] The amount of the base currency to buy or sell.
141
+ # @param user_id [String]
142
+ # @param user_secret [String]
143
+ # @param account_id [String]
144
+ # @param limit_price [Float] The limit price. Required if the order type is LIMIT, STOP_LOSS_LIMIT or TAKE_PROFIT_LIMIT.
145
+ # @param stop_price [Float] The stop price. Required if the order type is STOP_LOSS_MARKET, STOP_LOSS_LIMIT, TAKE_PROFIT_MARKET or TAKE_PROFIT_LIMIT.
146
+ # @param post_only [Boolean] Valid and required only for order type LIMIT. If true orders that would be filled immediately are rejected to avoid incurring TAKER fees.
147
+ # @param expiration_date [Time] The expiration date of the order. Required if the time_in_force is GTD.
148
+ # @param body [SimpleOrderForm]
149
+ # @param [Hash] extra additional parameters to pass along through :header_params, :query_params, or parameter name
150
+ def place_simple_order(instrument:, side:, type:, time_in_force:, amount:, user_id:, user_secret:, account_id:, limit_price: SENTINEL, stop_price: SENTINEL, post_only: SENTINEL, expiration_date: SENTINEL, extra: {})
151
+ _body = {}
152
+ _body[:instrument] = instrument if instrument != SENTINEL
153
+ _body[:side] = side if side != SENTINEL
154
+ _body[:type] = type if type != SENTINEL
155
+ _body[:time_in_force] = time_in_force if time_in_force != SENTINEL
156
+ _body[:amount] = amount if amount != SENTINEL
157
+ _body[:limit_price] = limit_price if limit_price != SENTINEL
158
+ _body[:stop_price] = stop_price if stop_price != SENTINEL
159
+ _body[:post_only] = post_only if post_only != SENTINEL
160
+ _body[:expiration_date] = expiration_date if expiration_date != SENTINEL
161
+ simple_order_form = _body
162
+ data, _status_code, _headers = place_simple_order_with_http_info_impl(user_id, user_secret, account_id, simple_order_form, extra)
163
+ data
164
+ end
165
+
166
+ # Place order
167
+ #
168
+ # Places an order in the specified account.
169
+ # This endpoint does not compute the impact to the account balance from the order before submitting the order.
170
+ #
171
+ # @param instrument [TradingInstrument]
172
+ # @param side [ActionStrict] The action describes the intent or side of a trade. This is either `BUY` or `SELL`.
173
+ # @param type [SimpleOrderFormType] The type of order to place.
174
+ # @param time_in_force [SimpleOrderFormTimeInForce] The Time in Force type for the order. This field indicates how long the order will remain active before it is executed or expires. - `GTC` - Good Til Canceled. The order is valid until it is executed or canceled. - `FOK` - Fill Or Kill. The order must be executed in its entirety immediately or be canceled completely. - `IOC` - Immediate Or Cancel. The order must be executed immediately. Any portion of the order that cannot be filled immediately will be canceled. - `GTD` - Good Til Date. The order is valid until the specified date.
175
+ # @param amount [Float] The amount of the base currency to buy or sell.
176
+ # @param user_id [String]
177
+ # @param user_secret [String]
178
+ # @param account_id [String]
179
+ # @param limit_price [Float] The limit price. Required if the order type is LIMIT, STOP_LOSS_LIMIT or TAKE_PROFIT_LIMIT.
180
+ # @param stop_price [Float] The stop price. Required if the order type is STOP_LOSS_MARKET, STOP_LOSS_LIMIT, TAKE_PROFIT_MARKET or TAKE_PROFIT_LIMIT.
181
+ # @param post_only [Boolean] Valid and required only for order type LIMIT. If true orders that would be filled immediately are rejected to avoid incurring TAKER fees.
182
+ # @param expiration_date [Time] The expiration date of the order. Required if the time_in_force is GTD.
183
+ # @param body [SimpleOrderForm]
184
+ # @param [Hash] extra additional parameters to pass along through :header_params, :query_params, or parameter name
185
+ def place_simple_order_with_http_info(instrument:, side:, type:, time_in_force:, amount:, user_id:, user_secret:, account_id:, limit_price: SENTINEL, stop_price: SENTINEL, post_only: SENTINEL, expiration_date: SENTINEL, extra: {})
186
+ _body = {}
187
+ _body[:instrument] = instrument if instrument != SENTINEL
188
+ _body[:side] = side if side != SENTINEL
189
+ _body[:type] = type if type != SENTINEL
190
+ _body[:time_in_force] = time_in_force if time_in_force != SENTINEL
191
+ _body[:amount] = amount if amount != SENTINEL
192
+ _body[:limit_price] = limit_price if limit_price != SENTINEL
193
+ _body[:stop_price] = stop_price if stop_price != SENTINEL
194
+ _body[:post_only] = post_only if post_only != SENTINEL
195
+ _body[:expiration_date] = expiration_date if expiration_date != SENTINEL
196
+ simple_order_form = _body
197
+ place_simple_order_with_http_info_impl(user_id, user_secret, account_id, simple_order_form, extra)
198
+ end
199
+
200
+ # Place order
201
+ # Places an order in the specified account. This endpoint does not compute the impact to the account balance from the order before submitting the order.
202
+ # @param user_id [String]
203
+ # @param user_secret [String]
204
+ # @param account_id [String]
205
+ # @param simple_order_form [SimpleOrderForm]
206
+ # @param [Hash] opts the optional parameters
207
+ # @return [OrderUpdatedResponse]
208
+ private def place_simple_order_impl(user_id, user_secret, account_id, simple_order_form, opts = {})
209
+ data, _status_code, _headers = place_simple_order_with_http_info(user_id, user_secret, account_id, simple_order_form, opts)
210
+ data
211
+ end
212
+
213
+ # Place order
214
+ # Places an order in the specified account. This endpoint does not compute the impact to the account balance from the order before submitting the order.
215
+ # @param user_id [String]
216
+ # @param user_secret [String]
217
+ # @param account_id [String]
218
+ # @param simple_order_form [SimpleOrderForm]
219
+ # @param [Hash] opts the optional parameters
220
+ # @return [Array<(OrderUpdatedResponse, Integer, Hash)>] OrderUpdatedResponse data, response status code and response headers
221
+ private def place_simple_order_with_http_info_impl(user_id, user_secret, account_id, simple_order_form, opts = {})
222
+ if @api_client.config.debugging
223
+ @api_client.config.logger.debug 'Calling API: CryptoTradingApi.place_simple_order ...'
224
+ end
225
+ # verify the required parameter 'user_id' is set
226
+ if @api_client.config.client_side_validation && user_id.nil?
227
+ fail ArgumentError, "Missing the required parameter 'user_id' when calling CryptoTradingApi.place_simple_order"
228
+ end
229
+ # verify the required parameter 'user_secret' is set
230
+ if @api_client.config.client_side_validation && user_secret.nil?
231
+ fail ArgumentError, "Missing the required parameter 'user_secret' when calling CryptoTradingApi.place_simple_order"
232
+ end
233
+ # verify the required parameter 'account_id' is set
234
+ if @api_client.config.client_side_validation && account_id.nil?
235
+ fail ArgumentError, "Missing the required parameter 'account_id' when calling CryptoTradingApi.place_simple_order"
236
+ end
237
+ # verify the required parameter 'simple_order_form' is set
238
+ if @api_client.config.client_side_validation && simple_order_form.nil?
239
+ fail ArgumentError, "Missing the required parameter 'simple_order_form' when calling CryptoTradingApi.place_simple_order"
240
+ end
241
+ # resource path
242
+ local_var_path = '/accounts/{accountId}/trading/simple'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
243
+
244
+ # query parameters
245
+ query_params = opts[:query_params] || {}
246
+ query_params[:'userId'] = user_id
247
+ query_params[:'userSecret'] = user_secret
248
+
249
+ # header parameters
250
+ header_params = opts[:header_params] || {}
251
+ # HTTP header 'Accept' (if needed)
252
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
253
+ # HTTP header 'Content-Type'
254
+ content_type = @api_client.select_header_content_type(['application/json'])
255
+ if !content_type.nil?
256
+ header_params['Content-Type'] = content_type
257
+ end
258
+
259
+ # form parameters
260
+ form_params = opts[:form_params] || {}
261
+
262
+ # http body (model)
263
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(simple_order_form)
264
+
265
+ # return_type
266
+ return_type = opts[:debug_return_type] || 'OrderUpdatedResponse'
267
+
268
+ # auth_names
269
+ auth_names = opts[:debug_auth_names] || ['PartnerClientId', 'PartnerSignature', 'PartnerTimestamp']
270
+
271
+ new_options = opts.merge(
272
+ :operation => :"CryptoTradingApi.place_simple_order",
273
+ :header_params => header_params,
274
+ :query_params => query_params,
275
+ :form_params => form_params,
276
+ :body => post_body,
277
+ :auth_names => auth_names,
278
+ :return_type => return_type
279
+ )
280
+
281
+ data, status_code, headers, response = @api_client.call_api(:POST, local_var_path, new_options)
282
+ if @api_client.config.debugging
283
+ @api_client.config.logger.debug "API called: CryptoTradingApi#place_simple_order\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
284
+ end
285
+ return data, status_code, headers, response
286
+ end
287
+
288
+
289
+ # Search cryptocurrency pairs instruments
290
+ #
291
+ # Searches cryptocurrency pairs instruments accessible to the specified account.
292
+ #
293
+ # @param user_id [String]
294
+ # @param user_secret [String]
295
+ # @param account_id [String]
296
+ # @param base [String]
297
+ # @param quote [String]
298
+ # @param [Hash] extra additional parameters to pass along through :header_params, :query_params, or parameter name
299
+ def search_cryptocurrency_pair_instruments(user_id:, user_secret:, account_id:, base: SENTINEL, quote: SENTINEL, extra: {})
300
+ extra[:base] = base if base != SENTINEL
301
+ extra[:quote] = quote if quote != SENTINEL
302
+ data, _status_code, _headers = search_cryptocurrency_pair_instruments_with_http_info_impl(user_id, user_secret, account_id, extra)
303
+ data
304
+ end
305
+
306
+ # Search cryptocurrency pairs instruments
307
+ #
308
+ # Searches cryptocurrency pairs instruments accessible to the specified account.
309
+ #
310
+ # @param user_id [String]
311
+ # @param user_secret [String]
312
+ # @param account_id [String]
313
+ # @param base [String]
314
+ # @param quote [String]
315
+ # @param [Hash] extra additional parameters to pass along through :header_params, :query_params, or parameter name
316
+ def search_cryptocurrency_pair_instruments_with_http_info(user_id:, user_secret:, account_id:, base: SENTINEL, quote: SENTINEL, extra: {})
317
+ extra[:base] = base if base != SENTINEL
318
+ extra[:quote] = quote if quote != SENTINEL
319
+ search_cryptocurrency_pair_instruments_with_http_info_impl(user_id, user_secret, account_id, extra)
320
+ end
321
+
322
+ # Search cryptocurrency pairs instruments
323
+ # Searches cryptocurrency pairs instruments accessible to the specified account.
324
+ # @param user_id [String]
325
+ # @param user_secret [String]
326
+ # @param account_id [String]
327
+ # @param [Hash] opts the optional parameters
328
+ # @option opts [String] :base
329
+ # @option opts [String] :quote
330
+ # @return [TradingSearchCryptocurrencyPairInstruments200Response]
331
+ private def search_cryptocurrency_pair_instruments_impl(user_id, user_secret, account_id, opts = {})
332
+ data, _status_code, _headers = search_cryptocurrency_pair_instruments_with_http_info(user_id, user_secret, account_id, opts)
333
+ data
334
+ end
335
+
336
+ # Search cryptocurrency pairs instruments
337
+ # Searches cryptocurrency pairs instruments accessible to the specified account.
338
+ # @param user_id [String]
339
+ # @param user_secret [String]
340
+ # @param account_id [String]
341
+ # @param [Hash] opts the optional parameters
342
+ # @option opts [String] :base
343
+ # @option opts [String] :quote
344
+ # @return [Array<(TradingSearchCryptocurrencyPairInstruments200Response, Integer, Hash)>] TradingSearchCryptocurrencyPairInstruments200Response data, response status code and response headers
345
+ private def search_cryptocurrency_pair_instruments_with_http_info_impl(user_id, user_secret, account_id, opts = {})
346
+ if @api_client.config.debugging
347
+ @api_client.config.logger.debug 'Calling API: CryptoTradingApi.search_cryptocurrency_pair_instruments ...'
348
+ end
349
+ # verify the required parameter 'user_id' is set
350
+ if @api_client.config.client_side_validation && user_id.nil?
351
+ fail ArgumentError, "Missing the required parameter 'user_id' when calling CryptoTradingApi.search_cryptocurrency_pair_instruments"
352
+ end
353
+ # verify the required parameter 'user_secret' is set
354
+ if @api_client.config.client_side_validation && user_secret.nil?
355
+ fail ArgumentError, "Missing the required parameter 'user_secret' when calling CryptoTradingApi.search_cryptocurrency_pair_instruments"
356
+ end
357
+ # verify the required parameter 'account_id' is set
358
+ if @api_client.config.client_side_validation && account_id.nil?
359
+ fail ArgumentError, "Missing the required parameter 'account_id' when calling CryptoTradingApi.search_cryptocurrency_pair_instruments"
360
+ end
361
+ # resource path
362
+ local_var_path = '/accounts/{accountId}/trading/instruments/cryptocurrencyPairs'.sub('{' + 'accountId' + '}', CGI.escape(account_id.to_s))
363
+
364
+ # query parameters
365
+ query_params = opts[:query_params] || {}
366
+ query_params[:'userId'] = user_id
367
+ query_params[:'userSecret'] = user_secret
368
+ query_params[:'base'] = opts[:'base'] if !opts[:'base'].nil?
369
+ query_params[:'quote'] = opts[:'quote'] if !opts[:'quote'].nil?
370
+
371
+ # header parameters
372
+ header_params = opts[:header_params] || {}
373
+ # HTTP header 'Accept' (if needed)
374
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
375
+
376
+ # form parameters
377
+ form_params = opts[:form_params] || {}
378
+
379
+ # http body (model)
380
+ post_body = opts[:debug_body]
381
+
382
+ # return_type
383
+ return_type = opts[:debug_return_type] || 'TradingSearchCryptocurrencyPairInstruments200Response'
384
+
385
+ # auth_names
386
+ auth_names = opts[:debug_auth_names] || ['PartnerClientId', 'PartnerSignature', 'PartnerTimestamp']
387
+
388
+ new_options = opts.merge(
389
+ :operation => :"CryptoTradingApi.search_cryptocurrency_pair_instruments",
390
+ :header_params => header_params,
391
+ :query_params => query_params,
392
+ :form_params => form_params,
393
+ :body => post_body,
394
+ :auth_names => auth_names,
395
+ :return_type => return_type
396
+ )
397
+
398
+ data, status_code, headers, response = @api_client.call_api(:GET, local_var_path, new_options)
399
+ if @api_client.config.debugging
400
+ @api_client.config.logger.debug "API called: CryptoTradingApi#search_cryptocurrency_pair_instruments\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
401
+ end
402
+ return data, status_code, headers, response
403
+ end
404
+ end
405
+
406
+ # top-level client access to avoid having the user to insantiate their own API instances
407
+ CryptoTrading = CryptoTradingApi::new
408
+ end