cryptum 0.0.379 → 0.0.381

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 (40) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/.rubocop_todo.yml +2 -17
  4. data/bin/cryptum +3 -3
  5. data/bin/cryptum-forecast +4 -4
  6. data/lib/cryptum/api/exchange_rates.rb +42 -0
  7. data/lib/cryptum/api/fees.rb +36 -0
  8. data/lib/cryptum/api/order_history.rb +56 -0
  9. data/lib/cryptum/api/orders.rb +253 -0
  10. data/lib/cryptum/api/portfolio.rb +79 -0
  11. data/lib/cryptum/api/products.rb +65 -0
  12. data/lib/cryptum/api/rest.rb +177 -0
  13. data/lib/cryptum/api/signature.rb +79 -0
  14. data/lib/cryptum/api.rb +10 -640
  15. data/lib/cryptum/event/buy.rb +1 -1
  16. data/lib/cryptum/event/cancel.rb +1 -1
  17. data/lib/cryptum/event/gtfo.rb +1 -1
  18. data/lib/cryptum/event/sell.rb +1 -1
  19. data/lib/cryptum/option/choice.rb +2 -2
  20. data/lib/cryptum/option/environment.rb +45 -0
  21. data/lib/cryptum/option/input_validation.rb +85 -0
  22. data/lib/cryptum/option/parser.rb +85 -0
  23. data/lib/cryptum/option.rb +3 -192
  24. data/lib/cryptum/order_book/generate.rb +1 -1
  25. data/lib/cryptum/portfolio/balance.rb +3 -5
  26. data/lib/cryptum/ui/order_execution.rb +2 -2
  27. data/lib/cryptum/version.rb +1 -1
  28. data/lib/cryptum/web_sock/coinbase.rb +1 -1
  29. data/spec/lib/cryptum/api/exchange_rates_spec.rb +10 -0
  30. data/spec/lib/cryptum/api/fees_spec.rb +10 -0
  31. data/spec/lib/cryptum/api/order_history_spec.rb +10 -0
  32. data/spec/lib/cryptum/api/orders_spec.rb +10 -0
  33. data/spec/lib/cryptum/api/portfolio_spec.rb +10 -0
  34. data/spec/lib/cryptum/api/products_spec.rb +10 -0
  35. data/spec/lib/cryptum/api/rest_spec.rb +10 -0
  36. data/spec/lib/cryptum/api/signature_spec.rb +10 -0
  37. data/spec/lib/cryptum/option/environment_spec.rb +10 -0
  38. data/spec/lib/cryptum/option/input_validation_spec.rb +10 -0
  39. data/spec/lib/cryptum/option/parser_spec.rb +10 -0
  40. metadata +24 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 267109002234d04e788a39303868e372163535eb908e5934bd19e6765f552ed4
4
- data.tar.gz: e5c9e401567e65691048b8c8131c39447202ce5ab5dfacfcd07d9fd5e0a4be7a
3
+ metadata.gz: 866bb0c564c84fd84b9795396ffabf73483cea8c71171e3de935545c9a5a7736
4
+ data.tar.gz: 060b3793c66b3a31d7747d5677de5f7b346d14ac00714357188239080a19bd5d
5
5
  SHA512:
6
- metadata.gz: 067a56f54d073b4d05d52d15cc06be7f5c91b58ccc6c5d0cb9a8f6da7ff1c57b9296772aedabc532a11dd30f2ef02489dd97b7fbb8038193fcfa805a3f58cc8e
7
- data.tar.gz: adda615b995b857cbe39ad49eeeb04307c3478c310a93e7fee25ae2d5f164bf9748db6cc0036e864eb9ea2c553b0a5741079f2007d09599170fb82ce07a31d30
6
+ metadata.gz: 07c342bb8da387ff8fad07303102860758b5be1334d6558732255a2f743a607bb5a881968f1da1506bda887819d82cd6d5a473b19380f9641dac3b7d43c2ae81
7
+ data.tar.gz: 928cd958349f76561e312529f3787d708924031ca6e73cec4c3314d59b639479d3c1997d70c6227e27360c66ceee038a5260ab61c3b4104f98fea7f764a50b1d
data/.rubocop.yml CHANGED
@@ -5,6 +5,8 @@ Layout:
5
5
  Max: 3000
6
6
  Layout/LineLength:
7
7
  Max: 256
8
+ Lint/UselessRescue:
9
+ Enabled: false
8
10
  Metrics/AbcSize:
9
11
  Max: 512
10
12
  Metrics/BlockLength:
data/.rubocop_todo.yml CHANGED
@@ -1,20 +1,11 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2023-03-29 14:29:26 UTC using RuboCop version 1.48.1.
3
+ # on 2023-03-30 22:47:49 UTC using RuboCop version 1.48.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 4
10
- Lint/UselessAssignment:
11
- Exclude:
12
- - 'lib/cryptum/api.rb'
13
-
14
- # Offense count: 58
15
- Lint/UselessRescue:
16
- Enabled: false
17
-
18
9
  # Offense count: 1
19
10
  # Configuration parameters: CountComments, CountAsOne.
20
11
  Metrics/ClassLength:
@@ -29,13 +20,7 @@ Style/ConditionalAssignment:
29
20
  - 'lib/cryptum/event/pane.rb'
30
21
  - 'lib/cryptum/ui/order_execute_details.rb'
31
22
 
32
- # Offense count: 23
23
+ # Offense count: 24
33
24
  # Configuration parameters: AllowedConstants.
34
25
  Style/Documentation:
35
26
  Enabled: false
36
-
37
- # Offense count: 1
38
- # This cop supports safe autocorrection (--autocorrect).
39
- Style/RedundantAssignment:
40
- Exclude:
41
- - 'lib/cryptum/api.rb'
data/bin/cryptum CHANGED
@@ -8,14 +8,14 @@ begin
8
8
  start_time = Time.now.strftime('%Y-%m-%d %H:%M:%S%z')
9
9
  # Initialize Driver Name & Parse cryptum Flags
10
10
  driver_name = File.basename($PROGRAM_NAME)
11
- option_choice = Cryptum::Option.parser(driver_name: driver_name)
11
+ option_choice = Cryptum::Option::Parser.get(driver_name: driver_name)
12
12
 
13
13
  # Initialize the Respective Environment / API Authentication Artifacts
14
- env = Cryptum::Option.get_env(option_choice: option_choice)
14
+ env = Cryptum::Option::Environment.get(option_choice: option_choice)
15
15
 
16
16
  # Dump out supported products if --list-products flag is passed and exit
17
17
  if option_choice.list_products
18
- Cryptum::Option.list_products_and_exit(
18
+ Cryptum::API::Products.list_and_exit(
19
19
  option_choice: option_choice,
20
20
  env: env
21
21
  )
data/bin/cryptum-forecast CHANGED
@@ -113,12 +113,12 @@ begin
113
113
  autotrade_cycle_tot = 1 unless option_choice.cycles_complete.to_i.positive?
114
114
 
115
115
  # Initialize the Respective Environment / API Authentication Artifacts
116
- env = Cryptum::Option.get_env(option_choice: option_choice)
116
+ env = Cryptum::Option::Environment.get(option_choice: option_choice)
117
117
 
118
118
  # Read in Bot Conf Values
119
119
  bot_conf = Cryptum::BotConf.read(option_choice: option_choice)
120
120
 
121
- products = Cryptum::API.get_products(
121
+ products = Cryptum::API::Products.get(
122
122
  option_choice: option_choice,
123
123
  env: env
124
124
  )
@@ -127,7 +127,7 @@ begin
127
127
  fiat = products.last[:quote_currency]
128
128
  fiat_portfolio_file = "#{option_choice.session_root}/order_books/#{fiat}_PORTFOLIO.json"
129
129
 
130
- # portfolio = Cryptum::API.get_portfolio(
130
+ # portfolio = Cryptum::API::Portfolio.get(
131
131
  # option_choice: option_choice,
132
132
  # env: env,
133
133
  # crypto: crypto,
@@ -149,7 +149,7 @@ begin
149
149
  gross_tpm = bot_conf[:target_profit_margin_percent].to_f / 100
150
150
  gross_tpm = option_choice.tpm.to_f if option_choice.tpm.to_f.positive?
151
151
 
152
- fees = Cryptum::API.get_fees(
152
+ fees = Cryptum::API::Fees.get(
153
153
  option_choice: option_choice,
154
154
  env: env
155
155
  )
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module Cryptum
6
+ # This module is used to Interact with the APIs
7
+ module API
8
+ # Module specifically related to orders history retrieval.
9
+ module ExchangeRates
10
+ # Obtain latest order history
11
+ public_class_method def self.get(opts = {})
12
+ option_choice = opts[:option_choice]
13
+ env = opts[:env]
14
+
15
+ api_endpoint = 'https://api.coinbase.com/v2'
16
+ exchange_rates_api_call = '/exchange-rates'
17
+
18
+ # We don't always get fees back from Coinbase...
19
+ # This is a hack to ensure we do.
20
+ Cryptum::API::Rest.call(
21
+ option_choice: option_choice,
22
+ env: env,
23
+ http_method: :GET,
24
+ api_endpoint: api_endpoint,
25
+ api_call: exchange_rates_api_call
26
+ )
27
+ rescue StandardError => e
28
+ raise e
29
+ end
30
+
31
+ # Display Usage for this Module
32
+ public_class_method def self.help
33
+ puts "USAGE:
34
+ fees = #{self}.get(
35
+ env: 'required - Coinbase::Option::Environment.get Object',
36
+ option_choice: 'required - Coinbase::Option::Choice Object'
37
+ )
38
+ "
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cryptum
4
+ # This module is used to Interact with the APIs
5
+ module API
6
+ # Module specifically related to orders history retrieval.
7
+ module Fees
8
+ # Obtain latest order history
9
+ public_class_method def self.get(opts = {})
10
+ option_choice = opts[:option_choice]
11
+ env = opts[:env]
12
+
13
+ fees_api_call = '/fees'
14
+
15
+ Cryptum::API::Rest.call(
16
+ option_choice: option_choice,
17
+ env: env,
18
+ http_method: :GET,
19
+ api_call: fees_api_call
20
+ )
21
+ rescue StandardError => e
22
+ raise e
23
+ end
24
+
25
+ # Display Usage for this Module
26
+ public_class_method def self.help
27
+ puts "USAGE:
28
+ fees = #{self}.get(
29
+ env: 'required - Coinbase::Option::Environment.get Object',
30
+ option_choice: 'required - Coinbase::Option::Choice Object'
31
+ )
32
+ "
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cryptum
4
+ # This module is used to Interact with the APIs
5
+ module API
6
+ # Module specifically related to orders history retrieval.
7
+ module OrderHistory
8
+ # Obtain latest order history
9
+ public_class_method def self.get(opts = {})
10
+ option_choice = opts[:option_choice]
11
+ env = opts[:env]
12
+
13
+ product_id = option_choice.symbol.to_s.gsub('_', '-').upcase
14
+
15
+ orders_api_call = '/orders'
16
+ params = {}
17
+ params[:product_id] = product_id
18
+ params[:status] = 'all'
19
+
20
+ order_history = Cryptum::API::Rest.call(
21
+ option_choice: option_choice,
22
+ env: env,
23
+ http_method: :GET,
24
+ api_call: orders_api_call,
25
+ params: params
26
+ )
27
+
28
+ # Cast UTC Timestamps as local times
29
+ order_history.each do |order|
30
+ order[:created_at] = Time.parse(
31
+ order[:created_at]
32
+ ).localtime.to_s
33
+
34
+ next unless order[:done_at]
35
+
36
+ order[:done_at] = Time.parse(
37
+ order[:done_at]
38
+ ).localtime.to_s
39
+ end
40
+
41
+ order_history
42
+ rescue StandardError => e
43
+ raise e
44
+ end
45
+
46
+ # Display Usage for this Module
47
+ public_class_method def self.help
48
+ puts "USAGE:
49
+ order_history = #{self}.get_order_history(
50
+ env: 'required - Coinbase::Option::Environment.get Object'
51
+ )
52
+ "
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,253 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'addressable'
4
+ require 'base64'
5
+ require 'json'
6
+ require 'openssl'
7
+ require 'rest-client'
8
+
9
+ module Cryptum
10
+ # This plugin is used to interact withbtje Coinbase REST API
11
+ module API
12
+ module Orders
13
+ public_class_method def self.submit_limit_order(opts = {})
14
+ option_choice = opts[:option_choice]
15
+ env = opts[:env]
16
+ price = opts[:price]
17
+ size = opts[:size]
18
+ buy_or_sell = opts[:buy_or_sell]
19
+ event_history = opts[:event_history]
20
+ bot_conf = opts[:bot_conf]
21
+ buy_order_id = opts[:buy_order_id]
22
+
23
+ tpm = bot_conf[:target_profit_margin_percent].to_f
24
+ tpm_cast_as_decimal = tpm / 100
25
+
26
+ product_id = option_choice.symbol.to_s.gsub('_', '-').upcase
27
+
28
+ this_product = event_history.order_book[:this_product]
29
+ base_increment = this_product[:base_increment]
30
+ quote_increment = this_product[:quote_increment]
31
+ # crypto_smallest_decimal = base_increment.to_s.split('.')[-1].length
32
+ fiat_smallest_decimal = quote_increment.to_s.split('.')[-1].length
33
+
34
+ order_hash = {}
35
+
36
+ order_hash[:type] = 'limit'
37
+ order_hash[:time_in_force] = 'GTC'
38
+
39
+ if buy_or_sell == :buy
40
+ order_hash[:time_in_force] = 'GTT'
41
+ order_hash[:cancel_after] = 'min'
42
+ end
43
+
44
+ order_hash[:size] = size
45
+ order_hash[:price] = price
46
+ order_hash[:side] = buy_or_sell
47
+ order_hash[:product_id] = product_id
48
+
49
+ http_body = order_hash.to_json
50
+
51
+ limit_order_resp = Cryptum::API::Rest.call(
52
+ option_choice: option_choice,
53
+ env: env,
54
+ http_method: :POST,
55
+ api_call: '/orders',
56
+ http_body: http_body,
57
+ base_increment: base_increment
58
+ )
59
+
60
+ # Populate Order ID on the Buy
61
+ # to know what to do on the Sell
62
+ case buy_or_sell
63
+ when :buy
64
+ this_order = event_history.order_book[:order_plan].shift
65
+ this_order[:buy_order_id] = limit_order_resp[:id]
66
+ this_order[:price] = price
67
+ targ_price = price.to_f + (price.to_f * tpm_cast_as_decimal)
68
+ this_order[:tpm] = format(
69
+ '%0.2f',
70
+ tpm
71
+ )
72
+ this_order[:target_price] = format(
73
+ "%0.#{fiat_smallest_decimal}f",
74
+ targ_price
75
+ )
76
+
77
+ this_order[:size] = size
78
+
79
+ this_order[:color] = :cyan
80
+ event_history.order_book[:order_history_meta].push(this_order)
81
+ when :sell
82
+ sell_order_id = limit_order_resp[:id]
83
+ event_history.order_book[:order_history_meta].each do |meta|
84
+ if meta[:buy_order_id] == buy_order_id
85
+ meta[:sell_order_id] = sell_order_id
86
+ meta[:color] = :yellow
87
+ end
88
+ end
89
+ end
90
+
91
+ event_history
92
+ rescue StandardError => e
93
+ raise e
94
+ end
95
+
96
+ # public_class_method def self.cancel_open_order(opts = {})
97
+ # env = opts[:env]
98
+ # option_choice = opts[:option_choice]
99
+ # order_id = opts[:order_id]
100
+ # order_type = opts[:order_type]
101
+ # product_id = option_choice.symbol.to_s.gsub('_', '-').upcase
102
+ # order_hash = {}
103
+ # order_hash[:product_id] = product_id
104
+ # params = order_hash
105
+ # Cryptum::API::Rest.call(
106
+ # env: env,
107
+ # http_method: :DELETE,
108
+ # api_call: "/orders/#{order_id}",
109
+ # option_choice: option_choice,
110
+ # params: params,
111
+ # order_type: order_type
112
+ # )
113
+ # rescue StandardError => e
114
+ # raise e
115
+ # end
116
+
117
+ public_class_method def self.cancel_all_open_orders(opts = {})
118
+ env = opts[:env]
119
+ option_choice = opts[:option_choice]
120
+ event_notes = opts[:event_notes]
121
+
122
+ product_id = option_choice.symbol.to_s.gsub('_', '-').upcase
123
+
124
+ order_hash = {}
125
+ order_hash[:product_id] = product_id
126
+
127
+ # http_body = order_hash.to_json
128
+ params = order_hash
129
+
130
+ canceled_order_id_arr = []
131
+ loop do
132
+ canceled_order_id_arr = Cryptum::API::Rest.call(
133
+ env: env,
134
+ http_method: :DELETE,
135
+ api_call: '/orders',
136
+ option_choice: option_choice,
137
+ params: params,
138
+ event_notes: event_notes
139
+ )
140
+
141
+ break if canceled_order_id_arr.empty?
142
+ end
143
+ canceled_order_id_arr
144
+ rescue StandardError => e
145
+ raise e
146
+ end
147
+
148
+ public_class_method def self.gtfo(opts = {})
149
+ option_choice = opts[:option_choice]
150
+ env = opts[:env]
151
+ event_history = opts[:event_history]
152
+
153
+ # Cancel all open orders
154
+ cancel_all_open_orders(
155
+ env: env,
156
+ option_choice: option_choice
157
+ )
158
+
159
+ product_id = option_choice.symbol.to_s.gsub('_', '-').upcase
160
+
161
+ this_product = event_history.order_book[:this_product]
162
+ base_increment = this_product[:base_increment]
163
+ quote_increment = this_product[:quote_increment]
164
+ crypto_smallest_decimal = base_increment.to_s.split('.')[-1].length
165
+ fiat_smallest_decimal = quote_increment.to_s.split('.')[-1].length
166
+
167
+ # TODO: Calculate / Price / Size
168
+ last_three_prices_arr = []
169
+ last_ticker_price = event_history.order_book[:ticker_price].to_f
170
+ second_to_last_ticker_price = event_history.order_book[:ticker_price_second_to_last].to_f
171
+ third_to_last_ticker_price = event_history.order_book[:ticker_price_third_to_last].to_f
172
+ last_three_prices_arr.push(last_ticker_price)
173
+ last_three_prices_arr.push(second_to_last_ticker_price)
174
+ last_three_prices_arr.push(third_to_last_ticker_price)
175
+ limit_price = last_three_prices_arr.sort[1]
176
+ price = format(
177
+ "%0.#{fiat_smallest_decimal}f",
178
+ limit_price
179
+ )
180
+
181
+ crypto_currency = option_choice.symbol.to_s.upcase.split('_').first.to_sym
182
+ portfolio = event_history.order_book[:portfolio]
183
+ this_account = portfolio.select do |account|
184
+ account[:currency] == crypto_currency.to_s
185
+ end
186
+ balance = format(
187
+ "%0.#{crypto_smallest_decimal}f",
188
+ this_account.first[:balance]
189
+ )
190
+
191
+ current_crypto_fiat_value = format(
192
+ '%0.2f',
193
+ balance.to_f * price.to_f
194
+ )
195
+
196
+ order_hash = {}
197
+
198
+ order_hash[:type] = 'limit'
199
+ order_hash[:time_in_force] = 'GTT'
200
+ order_hash[:cancel_after] = 'min'
201
+
202
+ order_hash[:size] = balance
203
+ order_hash[:price] = price
204
+ order_hash[:side] = :sell
205
+ order_hash[:product_id] = product_id
206
+
207
+ http_body = order_hash.to_json
208
+
209
+ limit_order_resp = Cryptum::API::Rest.call(
210
+ option_choice: option_choice,
211
+ env: env,
212
+ http_method: :POST,
213
+ api_call: '/orders',
214
+ http_body: http_body,
215
+ base_increment: base_increment
216
+ )
217
+
218
+ # Populate Order ID on the Buy
219
+ # to know what to do on the Sell
220
+ this_order = {}
221
+ this_order[:plan_no] = '0.0'
222
+ this_order[:fiat_available] = '0.00'
223
+ this_order[:risk_alloc] = current_crypto_fiat_value
224
+ this_order[:allocation_decimal] = '1.0'
225
+ this_order[:allocation_percent] = '100.0'
226
+ this_order[:invest] = current_crypto_fiat_value
227
+ this_order[:return] = current_crypto_fiat_value
228
+ this_order[:profit] = '0.0'
229
+ this_order[:buy_order_id] = 'N/A'
230
+ this_order[:price] = price
231
+ this_order[:tpm] = '0.00'
232
+ this_order[:target_price] = current_crypto_fiat_value
233
+ this_order[:size] = balance
234
+ this_order[:color] = :magenta
235
+ this_order[:sell_order_id] = limit_order_resp[:id]
236
+
237
+ event_history.order_book[:order_history_meta].push(this_order)
238
+
239
+ event_history
240
+ rescue StandardError => e
241
+ raise e
242
+ end
243
+
244
+ public_class_method def self.help
245
+ puts "USAGE:
246
+ profiles = #{self}.get_profiles(
247
+ env: 'required - Coinbase::Option::Environment.get Object'
248
+ )
249
+ "
250
+ end
251
+ end
252
+ end
253
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module Cryptum
6
+ # This module is used to Interact with the APIs
7
+ module API
8
+ # Module specifically related to orders history retrieval.
9
+ module Portfolio
10
+ # Obtain latest order history
11
+ public_class_method def self.get(opts = {})
12
+ option_choice = opts[:option_choice]
13
+ env = opts[:env]
14
+ crypto = opts[:crypto]
15
+ fiat = opts[:fiat]
16
+ fiat_portfolio_file = opts[:fiat_portfolio_file]
17
+ event_notes = opts[:event_notes]
18
+
19
+ # Retrieve Exchange Rates
20
+ exchange_rates_resp = Cryptum::API::ExchangeRates.get(
21
+ option_choice: option_choice,
22
+ env: env
23
+ )
24
+ exchange_rates = exchange_rates_resp[:data][:rates]
25
+
26
+ portfolio_complete_arr = Cryptum::API::Rest.call(
27
+ option_choice: option_choice,
28
+ env: env,
29
+ http_method: :GET,
30
+ api_call: '/accounts',
31
+ event_notes: event_notes
32
+ )
33
+ portfolio_complete_arr ||= []
34
+
35
+ all_products = portfolio_complete_arr.select do |products|
36
+ products if products[:balance].to_f.positive?
37
+ end
38
+
39
+ total_holdings = 0.00
40
+ all_products.each do |product|
41
+ currency = product[:currency].to_sym
42
+ this_exchange_rate = exchange_rates[currency].to_f
43
+ total_holdings += product[:balance].to_f / this_exchange_rate
44
+ end
45
+
46
+ crypto_portfolio = portfolio_complete_arr.select do |product|
47
+ product if product[:currency] == crypto
48
+ end
49
+
50
+ fiat_portfolio = portfolio_complete_arr.select do |product|
51
+ product if product[:currency] == fiat
52
+ end
53
+ fiat_portfolio.last[:total_holdings] = format(
54
+ '%0.8f',
55
+ total_holdings
56
+ )
57
+
58
+ File.write(
59
+ fiat_portfolio_file,
60
+ JSON.pretty_generate(fiat_portfolio)
61
+ )
62
+
63
+ crypto_portfolio
64
+ rescue StandardError => e
65
+ raise e
66
+ end
67
+
68
+ # Display Usage for this Module
69
+ public_class_method def self.help
70
+ puts "USAGE:
71
+ fees = #{self}.get(
72
+ env: 'required - Coinbase::Option::Environment.get Object',
73
+ option_choice: 'required - Coinbase::Option::Choice Object'
74
+ )
75
+ "
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cryptum
4
+ # This module is used to Interact with the APIs
5
+ module API
6
+ # Module specifically related to orders history retrieval.
7
+ module Products
8
+ # Obtain latest order history
9
+ public_class_method def self.get(opts = {})
10
+ option_choice = opts[:option_choice]
11
+ env = opts[:env]
12
+
13
+ products = Cryptum::API::Rest.call(
14
+ option_choice: option_choice,
15
+ env: env,
16
+ http_method: :GET,
17
+ api_call: '/products'
18
+ )
19
+
20
+ if products.length.positive?
21
+ supported_products_filter = products.select do |product|
22
+ product[:id].match?(/USD$/) &&
23
+ product[:status] == 'online' &&
24
+ product[:fx_stablecoin] == false
25
+ end
26
+ sorted_products = supported_products_filter.sort_by { |hash| hash[:id] }
27
+ end
28
+
29
+ sorted_products
30
+ rescue StandardError => e
31
+ raise e
32
+ end
33
+
34
+ # List Supported Cryptum Products and Exit
35
+ public_class_method def self.list_and_exit(opts = {})
36
+ option_choice = opts[:option_choice]
37
+ env = opts[:env]
38
+
39
+ puts "\n#{option_choice.driver_name} Supports the Following Products:"
40
+ products = get(
41
+ option_choice: option_choice,
42
+ env: env
43
+ )
44
+
45
+ products.map do |product|
46
+ puts product[:id].downcase
47
+ end
48
+
49
+ exit 0
50
+ rescue StandardError => e
51
+ raise e
52
+ end
53
+
54
+ # Display Usage for this Module
55
+ public_class_method def self.help
56
+ puts "USAGE:
57
+ fees = #{self}.get(
58
+ env: 'required - Coinbase::Option::Environment.get Object',
59
+ option_choice: 'required - Coinbase::Option::Choice Object'
60
+ )
61
+ "
62
+ end
63
+ end
64
+ end
65
+ end