cryptum 0.0.382 → 0.0.384

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 (52) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +5 -8
  3. data/lib/cryptum/api/exchange_rates.rb +0 -2
  4. data/lib/cryptum/api/orders.rb +2 -8
  5. data/lib/cryptum/api/portfolio.rb +0 -2
  6. data/lib/cryptum/api/rest.rb +3 -4
  7. data/lib/cryptum/api/signature.rb +0 -4
  8. data/lib/cryptum/api.rb +0 -6
  9. data/lib/cryptum/bot_conf.rb +0 -3
  10. data/lib/cryptum/event/buy.rb +11 -115
  11. data/lib/cryptum/event/exit.rb +1 -1
  12. data/lib/cryptum/event/order_book.rb +1 -1
  13. data/lib/cryptum/event/parse.rb +6 -6
  14. data/lib/cryptum/event/sell.rb +15 -96
  15. data/lib/cryptum/event.rb +0 -2
  16. data/lib/cryptum/log.rb +18 -4
  17. data/lib/cryptum/open_ai.rb +129 -32
  18. data/lib/cryptum/option/environment.rb +0 -2
  19. data/lib/cryptum/option/parser.rb +0 -2
  20. data/lib/cryptum/order_book/generate.rb +0 -4
  21. data/lib/cryptum/order_book.rb +0 -3
  22. data/lib/cryptum/portfolio.rb +0 -2
  23. data/lib/cryptum/ui/command.rb +0 -2
  24. data/lib/cryptum/ui/market_trend.rb +0 -2
  25. data/lib/cryptum/ui/matrix.rb +0 -2
  26. data/lib/cryptum/ui/order/execute.rb +627 -0
  27. data/lib/cryptum/ui/order/execute_details.rb +300 -0
  28. data/lib/cryptum/ui/order/plan.rb +518 -0
  29. data/lib/cryptum/ui/order/plan_details.rb +243 -0
  30. data/lib/cryptum/ui/order/timer.rb +140 -0
  31. data/lib/cryptum/ui/order.rb +21 -0
  32. data/lib/cryptum/ui/portfolio.rb +0 -2
  33. data/lib/cryptum/ui/signal_engine.rb +0 -2
  34. data/lib/cryptum/ui/terminal_window.rb +0 -2
  35. data/lib/cryptum/ui/ticker.rb +0 -2
  36. data/lib/cryptum/ui.rb +1 -8
  37. data/lib/cryptum/version.rb +1 -1
  38. data/lib/cryptum/web_sock/coinbase.rb +0 -5
  39. data/lib/cryptum/web_sock/event_machine.rb +2 -6
  40. data/lib/cryptum.rb +16 -2
  41. data/spec/lib/cryptum/ui/{order_execute_details_spec.rb → order/execute_details_spec.rb} +2 -2
  42. data/spec/lib/cryptum/ui/{order_execution_spec.rb → order/execute_spec.rb} +2 -2
  43. data/spec/lib/cryptum/ui/order/plan_details_spec.rb +10 -0
  44. data/spec/lib/cryptum/ui/{order_timer_spec.rb → order/plan_spec.rb} +2 -2
  45. data/spec/lib/cryptum/ui/{order_plan_details_spec.rb → order/timer_spec.rb} +2 -2
  46. data/spec/lib/cryptum/ui/{order_plan_spec.rb → order_spec.rb} +2 -2
  47. metadata +13 -11
  48. data/lib/cryptum/ui/order_execute_details.rb +0 -300
  49. data/lib/cryptum/ui/order_execution.rb +0 -629
  50. data/lib/cryptum/ui/order_plan.rb +0 -518
  51. data/lib/cryptum/ui/order_plan_details.rb +0 -243
  52. data/lib/cryptum/ui/order_timer.rb +0 -140
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba56f01c0c210153ad8a00b6d1ecb4f0d85c5d4f33dcc36c5edadc2943ed7c09
4
- data.tar.gz: bd994aa742cb92dd98157b7eb3d1df8e43b0db0afa37079a6f205147189b10f8
3
+ metadata.gz: 5d8298d19d8db14b27d22dc465df09455fb209218ebbeeddf1987e66042af09d
4
+ data.tar.gz: 4e19eb6374a6161b0a72c8d42da7897868252efffb886a414d22a173368a6238
5
5
  SHA512:
6
- metadata.gz: ce2c4c72240938237e5e772684cb844334442d3ab25c66c156b7d361586d900340169356ab04e10f01b58a324959e0ba4d4ea1885e4856535692f0a080a7d5fa
7
- data.tar.gz: a96a551db08ea2e9df384baab42ea8b30c41a1ab07e592dd90f7a3be1020aa54c35a09daed79f5a787857fcb2673550d37f0eaf1042a9a987c6fe64e2555983a
6
+ metadata.gz: 1fdf711cf9326842f480b14b37f4b9c826d164b8f64965cfdc25269165c97e7e2b1de2f48b0238b239da45903232117dba59cb65b59028e7057410fdb3ee3be5
7
+ data.tar.gz: fb896a3349b440c7ab8010fb6d2a95d30bfa13683000250f4ca7deb7ab538ce42a89164ff41941805e54f8d2331d717833ec00ca093965e466d55dc6b9304610
data/.rubocop_todo.yml CHANGED
@@ -1,26 +1,23 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2023-03-31 15:11:10 UTC using RuboCop version 1.48.1.
3
+ # on 2023-03-31 21:49:04 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: 1
10
- # Configuration parameters: CountComments, CountAsOne.
11
- Metrics/ClassLength:
12
- Max: 131
13
-
14
- # Offense count: 4
9
+ # Offense count: 7
15
10
  # This cop supports safe autocorrection (--autocorrect).
16
11
  # Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
17
12
  # SupportedStyles: assign_to_condition, assign_inside_condition
18
13
  Style/ConditionalAssignment:
19
14
  Exclude:
20
15
  - 'lib/cryptum/event/pane.rb'
16
+ - 'lib/cryptum/log.rb'
17
+ - 'lib/cryptum/ui/order/execute_details.rb'
21
18
  - 'lib/cryptum/ui/order_execute_details.rb'
22
19
 
23
- # Offense count: 24
20
+ # Offense count: 30
24
21
  # Configuration parameters: AllowedConstants.
25
22
  Style/Documentation:
26
23
  Enabled: false
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'json'
4
-
5
3
  module Cryptum
6
4
  # This module is used to Interact with the APIs
7
5
  module API
@@ -1,16 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'addressable'
4
- require 'base64'
5
- require 'json'
6
- require 'openssl'
7
- require 'rest-client'
8
-
9
3
  module Cryptum
10
4
  # This plugin is used to interact withbtje Coinbase REST API
11
5
  module API
12
6
  module Orders
13
- public_class_method def self.submit_limit_order(opts = {})
7
+ public_class_method def self.submit_limit(opts = {})
14
8
  option_choice = opts[:option_choice]
15
9
  env = opts[:env]
16
10
  price = opts[:price]
@@ -243,7 +237,7 @@ module Cryptum
243
237
 
244
238
  public_class_method def self.help
245
239
  puts "USAGE:
246
- event_history = #{self}.submit_limit_order(
240
+ event_history = #{self}.submit_limit(
247
241
  env: 'required - Coinbase::Option::Environment.get Object'
248
242
  )
249
243
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'json'
4
-
5
3
  module Cryptum
6
4
  # This module is used to Interact with the APIs
7
5
  module API
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rest-client'
4
- require 'json'
5
-
6
3
  module Cryptum
7
4
  # This module is used to Interact with the APIs
8
5
  module API
@@ -119,7 +116,9 @@ module Cryptum
119
116
  )
120
117
 
121
118
  else
122
- raise @@logger.error("Unsupported HTTP Method #{http_method} for #{self} Plugin")
119
+ File.open('/tmp/cryptum-errors.txt', 'a') do |f|
120
+ f.puts "Unsupported HTTP Method #{http_method} for #{self} Plugin"
121
+ end
123
122
  end
124
123
 
125
124
  resp = JSON.parse(response, symbolize_names: true)
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'addressable'
4
- require 'base64'
5
- require 'openssl'
6
-
7
3
  module Cryptum
8
4
  # This module is used to Interact with the APIs
9
5
  module API
data/lib/cryptum/api.rb CHANGED
@@ -1,11 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'addressable'
4
- require 'base64'
5
- require 'json'
6
- require 'openssl'
7
- require 'rest-client'
8
-
9
3
  module Cryptum
10
4
  # This plugin is used to interact withbtje Coinbase REST API
11
5
  module API
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'logger'
4
-
5
3
  module Cryptum
6
4
  # This plugin is used to read and update bot conf files.
7
5
  module BotConf
@@ -200,7 +198,6 @@ module Cryptum
200
198
 
201
199
  public_class_method def self.help
202
200
  puts "USAGE:
203
- logger = #{self}.create()
204
201
  "
205
202
  end
206
203
  end
@@ -12,124 +12,20 @@ module Cryptum
12
12
  public_class_method def self.crypto(opts = {})
13
13
  option_choice = opts[:option_choice]
14
14
  env = opts[:env]
15
- bot_conf = opts[:bot_conf]
15
+ price = opts[:price]
16
+ size = opts[:size]
16
17
  event_history = opts[:event_history]
17
- order_type = opts[:order_type]
18
- fiat_smallest_decimal = opts[:fiat_smallest_decimal]
19
- # fiat_portfolio_file = opts[:fiat_portfolio_file]
20
- order_history = opts[:order_history]
21
- crypto_smallest_decimal = opts[:crypto_smallest_decimal]
22
- # base_min_size = opts[:base_min_size]
23
- min_market_funds = this_product[:min_market_funds]
24
- indicator_status = opts[:indicator_status]
25
-
26
- # Initialize some bot_conf variables
27
- pie_in_sky_buy_percent = bot_conf[:pie_in_sky_buy_percent].to_f
28
- autotrade_portfolio_percent = bot_conf[:autotrade_portfolio_percent].to_f
29
- # target_profit_margin_percent = bot_conf[:target_profit_margin_percent].to_f
30
-
31
- crypto_currency = option_choice.symbol.to_s.upcase.split('_').first
32
- portfolio = event_history.order_book[:portfolio]
33
- symbol_portfolio = portfolio.select do |this_portfolio|
34
- this_portfolio if this_portfolio[:currency] == crypto_currency
35
- end
36
-
37
- symbol_balance = format(
38
- '%0.8f',
39
- symbol_portfolio.first[:balance].to_f
40
- ).to_f
41
-
42
- # 2. Calculate Price, Size, Fees
43
- # Get the middle of last 3 ticker prices
44
- # to avoid over purcase blips.
45
- last_three_prices_arr = []
46
- last_ticker_price = event_history.order_book[:ticker_price].to_f
47
- second_to_last_ticker_price = event_history.order_book[:ticker_price_second_to_last].to_f
48
- third_to_last_ticker_price = event_history.order_book[:ticker_price_third_to_last].to_f
49
- last_three_prices_arr.push(last_ticker_price)
50
- last_three_prices_arr.push(second_to_last_ticker_price)
51
- last_three_prices_arr.push(third_to_last_ticker_price)
52
-
53
- case order_type
54
- when :pie
55
- limit_price = last_three_prices_arr.sort[1]
56
- pie_in_sky_buy_percent_cast_as_decimal = format(
57
- '%0.2f',
58
- pie_in_sky_buy_percent * 0.01
59
- ).to_f
60
-
61
- limit_price -= (limit_price * pie_in_sky_buy_percent_cast_as_decimal)
62
- when :tpm
63
- limit_price = last_three_prices_arr.sort[1]
64
- when :gtfo
65
- # price = format("%0.#{fiat_smallest_decimal}f", limit_price)
66
- raise "ERROR: Why is a Buy Submitted for #{order_type}?"
67
- else
68
- raise "ERROR: Unknown order_type: #{order_type}"
69
- end
70
-
71
- price = format("%0.#{fiat_smallest_decimal}f", limit_price)
72
-
73
- # TODO: Determine if our N% Autotrade
74
- # Threshold has already been met
75
- # Buying Crypto w/ Fiat
76
- autotrade_portfolio_percent_cast_as_decimal = format(
77
- '%0.7f',
78
- autotrade_portfolio_percent * 0.01
79
- ).to_f
80
-
81
- fiat_portfolio = event_history.order_book[:fiat_portfolio]
82
- fiat_balance_available = format(
83
- "%0.#{fiat_smallest_decimal}f",
84
- fiat_portfolio.first[:available]
85
- ).to_f
86
-
87
- # Make sure size is within constraints
88
- # of autotrade_portfolio_percent
89
- total_limit_buy_orders_open = order_history.select do |orders|
90
- orders[:type] == 'limit' &&
91
- orders[:side] == 'buy' &&
92
- orders[:status] == 'open'
93
- end
94
-
95
- total_limit_buy_order_open_tot = total_limit_buy_orders_open.length
96
- total_limit_buy_orders_open_size = total_limit_buy_orders_open.inject(0) do |sum, hash|
97
- sum + hash[:size].to_f
98
- end.to_f
18
+ bot_conf = opts[:bot_conf]
99
19
 
100
- fiat_to_autotrade = fiat_balance_available * autotrade_portfolio_percent_cast_as_decimal
101
- calc_fiat_to_buy = (fiat_to_autotrade / last_ticker_price) - symbol_balance
102
- size = format(
103
- "%0.#{crypto_smallest_decimal}f",
104
- calc_fiat_to_buy - total_limit_buy_orders_open_size
20
+ Cryptum::API::Orders.submit_limit(
21
+ option_choice: option_choice,
22
+ env: env,
23
+ price: price,
24
+ size: size,
25
+ buy_or_sell: :buy,
26
+ event_history: event_history,
27
+ bot_conf: bot_conf
105
28
  )
106
-
107
- if min_market_funds.to_i >= 1
108
- size = (
109
- (calc_fiat_to_buy - total_limit_buy_orders_open_size).to_i - min_market_funds.to_i
110
- ).to_s
111
- end
112
-
113
- if size.to_f >= min_market_funds.to_f &&
114
- total_limit_buy_order_open_tot.zero? &&
115
- price.to_f.positive?
116
- # SUBMIT BUY ORDER
117
- event_history.order_submitted = true
118
- event_history.event_notes = "{ \"event_type\": \"#{event_history.event_type}\", \"cancel\": \"#{event_history.order_canceled}\", \"submitted\": \"#{event_history.order_submitted}\" }" if option_choice.proxy
119
-
120
- event_history = Cryptum::API::Orders.submit_limit_order(
121
- option_choice: option_choice,
122
- env: env,
123
- price: price,
124
- size: size,
125
- buy_or_sell: :buy,
126
- order_type: order_type,
127
- event_history: event_history,
128
- indicator_status: indicator_status
129
- )
130
- end
131
-
132
- event_history
133
29
  rescue StandardError => e
134
30
  raise e
135
31
  end
@@ -5,7 +5,7 @@ module Cryptum
5
5
  module Event
6
6
  module Exit
7
7
  # Supported Method Parameters::
8
- # Cryptum::Event::BotConf.gracefully(
8
+ # Cryptum::Event::Exit.gracefully(
9
9
  # )
10
10
  public_class_method def self.gracefully(opts = {})
11
11
  terminal_win = opts[:terminal_win]
@@ -6,7 +6,7 @@ module Cryptum
6
6
  module Event
7
7
  module OrderBook
8
8
  # Supported Method Parameters::
9
- # Cryptum::Event::BotConf.write(
9
+ # Cryptum::Event::OrderBook.write(
10
10
  # )
11
11
  public_class_method def self.write(opts = {})
12
12
  terminal_win = opts[:terminal_win]
@@ -5,7 +5,7 @@ module Cryptum
5
5
  module Event
6
6
  module Parse
7
7
  # Supported Method Parameters::
8
- # Cryptum::Event::Pane.websocket_msg(
8
+ # Cryptum::Event::Parse.websocket_msg(
9
9
  # )
10
10
  public_class_method def self.websocket_msg(opts = {})
11
11
  env = opts[:env]
@@ -60,7 +60,7 @@ module Cryptum
60
60
  )
61
61
  end
62
62
 
63
- Cryptum::UI::OrderTimer.refresh(
63
+ Cryptum::UI::Order::Timer.refresh(
64
64
  option_choice: option_choice,
65
65
  event_history: event_history,
66
66
  order_timer_win: terminal_win.order_timer_section,
@@ -95,7 +95,7 @@ module Cryptum
95
95
  )
96
96
 
97
97
  unless event_history.order_plan_details_win_active
98
- event_history = Cryptum::UI::OrderPlan.refresh(
98
+ event_history = Cryptum::UI::Order::Plan.refresh(
99
99
  option_choice: option_choice,
100
100
  order_plan_win: terminal_win.order_plan_section,
101
101
  env: env,
@@ -113,7 +113,7 @@ module Cryptum
113
113
  end
114
114
 
115
115
  if event_history.order_plan_details_win_active
116
- event_history = Cryptum::UI::OrderPlanDetails.refresh(
116
+ event_history = Cryptum::UI::Order::PlanDetails.refresh(
117
117
  option_choice: option_choice,
118
118
  order_plan_details_win: terminal_win.order_plan_details_section,
119
119
  event_history: event_history,
@@ -122,7 +122,7 @@ module Cryptum
122
122
  end
123
123
 
124
124
  unless event_history.order_execute_details_win_active
125
- event_history = Cryptum::UI::OrderExecution.refresh(
125
+ event_history = Cryptum::UI::Order::Execute.refresh(
126
126
  option_choice: option_choice,
127
127
  order_execute_win: terminal_win.order_execute_section,
128
128
  env: env,
@@ -135,7 +135,7 @@ module Cryptum
135
135
  end
136
136
 
137
137
  if event_history.order_execute_details_win_active
138
- event_history = Cryptum::UI::OrderExecuteDetails.refresh(
138
+ event_history = Cryptum::UI::Order::ExecuteDetails.refresh(
139
139
  option_choice: option_choice,
140
140
  order_execute_details_win: terminal_win.order_execute_details_section,
141
141
  event_history: event_history,
@@ -12,103 +12,22 @@ module Cryptum
12
12
  public_class_method def self.crypto(opts = {})
13
13
  option_choice = opts[:option_choice]
14
14
  env = opts[:env]
15
- bot_conf = opts[:bot_conf]
16
- stuck_in_pos_status = opts[:stuck_in_pos_status]
15
+ price = opts[:price]
16
+ size = opts[:size]
17
17
  event_history = opts[:event_history]
18
- order_type = opts[:order_type]
19
- fiat_smallest_decimal = opts[:fiat_smallest_decimal]
20
- crypto_smallest_decimal = opts[:crypto_smallest_decimal]
21
- # base_min_size = opts[:base_min_size]
22
- min_market_funds = this_product[:min_market_funds]
23
- indicator_status = opts[:indicator_status]
24
- quote_increment = opts[:quote_increment]
25
-
26
- # Initialize some bot_conf variables
27
- pie_in_sky_sell_percent = bot_conf[:pie_in_sky_sell_percent].to_f
28
-
29
- crypto_currency = option_choice.symbol.to_s.upcase.split('_').first
30
- portfolio = event_history.order_book[:portfolio]
31
- symbol_portfolio = portfolio.select do |this_portfolio|
32
- this_portfolio if this_portfolio[:currency] == crypto_currency
33
- end
34
-
35
- symbol_balance_available = format(
36
- '%0.8f',
37
- symbol_portfolio.first[:available].to_f
38
- ).to_f
39
-
40
- # 2. Calculate Price, Size, Fees
41
- # Get the middle of last 3 ticker prices
42
- # to avoid over purcase blips.
43
- last_three_prices_arr = []
44
- last_ticker_price = event_history.order_book[:ticker_price].to_f
45
- second_to_last_ticker_price = event_history.order_book[:ticker_price_second_to_last].to_f
46
- third_to_last_ticker_price = event_history.order_book[:ticker_price_third_to_last].to_f
47
- last_three_prices_arr.push(last_ticker_price)
48
- last_three_prices_arr.push(second_to_last_ticker_price)
49
- last_three_prices_arr.push(third_to_last_ticker_price)
50
- # limit_price = last_three_prices_arr.min
51
- # limit_price = last_three_prices_arr.max
52
-
53
- # Obtain our Target Price based on TPM configurations
54
- target_symbol_price = stuck_in_pos_status[:target_symbol_price].to_f
55
-
56
- case order_type
57
- when :pie
58
- pie_in_sky_sell_percent_cast_as_decimal = format(
59
- '%0.2f',
60
- pie_in_sky_sell_percent * 0.01
61
- ).to_f
62
-
63
- target_profit = target_symbol_price * pie_in_sky_sell_percent_cast_as_decimal
64
- limit_price = target_symbol_price + target_profit
65
-
66
- when :tpm
67
- limit_price = target_symbol_price
68
- # TODO: Ensure previous order price
69
- # on last _open order_ if applicable
70
- # is greater than this one.
71
- order_type = :tpm
72
- when :gtfo
73
- # Attempt to get in front of falling price.
74
- limit_price = last_three_prices_arr.sort[1]
75
- gtfo_price = limit_price -= quote_increment.to_f
76
- limit_price = gtfo_price if gtfo_price.positive?
77
- else
78
- raise "ERROR: Unknown order_type: #{order_type}"
79
- end
80
-
81
- price = format("%0.#{fiat_smallest_decimal}f", limit_price)
82
-
83
- # Selling Available Crytpo Balance in its Entirety
84
- # We Will Likely Want to Change this in the Future.
85
- size = format(
86
- "%0.#{crypto_smallest_decimal}f",
87
- symbol_balance_available.floor(crypto_smallest_decimal)
18
+ bot_conf = opts[:bot_conf]
19
+ buy_order_id = opts[:buy_order_id]
20
+
21
+ Cryptum::API::Orders.submit_limit(
22
+ option_choice: option_choice,
23
+ env: env,
24
+ price: price,
25
+ size: size,
26
+ buy_or_sell: :sell,
27
+ event_history: event_history,
28
+ bot_conf: bot_conf,
29
+ buy_order_id: buy_order_id
88
30
  )
89
-
90
- size = symbol_balance_available if min_market_funds.to_i == 1
91
-
92
- if size.to_f >= min_market_funds.to_f &&
93
- price.to_f.positive?
94
-
95
- # SUBMIT SELL ORDER
96
- event_history.order_submitted = true
97
- event_history.event_notes = "{ \"event_type\": \"#{event_history.event_type}\", \"cancel\": \"#{event_history.order_canceled}\", \"submitted\": \"#{event_history.order_submitted}\" }" if option_choice.proxy
98
-
99
- event_history = Cryptum::API::Orders.submit_limit_order(
100
- option_choice: option_choice,
101
- env: env,
102
- price: price,
103
- size: size,
104
- buy_or_sell: :sell,
105
- order_type: order_type,
106
- event_history: event_history,
107
- indicator_status: indicator_status
108
- )
109
- end
110
-
111
- event_history
112
31
  rescue StandardError => e
113
32
  raise e
114
33
  end
@@ -116,7 +35,7 @@ module Cryptum
116
35
  # Display Usage for this Module
117
36
  public_class_method def self.help
118
37
  puts "USAGE:
119
- order_book = #{self}.crypto()
38
+ event_history = #{self}.crypto()
120
39
  "
121
40
  end
122
41
  end
data/lib/cryptum/event.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'logger'
4
-
5
3
  module Cryptum
6
4
  # This plugin is used to parse Coinbase Pro Web Socket Events in the HTTP Response
7
5
  module Event
data/lib/cryptum/log.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'logger'
4
-
5
3
  module Cryptum
6
4
  # This plugin is used to instantiate a Cryptum logger with a custom message format
7
5
  module Log
@@ -10,8 +8,24 @@ module Cryptum
10
8
  # )
11
9
  public_class_method def self.create
12
10
  logger = Logger.new($stdout)
13
- logger.level = Logger::INFO
14
- logger.datetime_format = '%Y-%m-%d %H:%M:%S'
11
+ level = opts[:level]
12
+
13
+ case level.to_s.downcase.to_sym
14
+ when :debug
15
+ logger.level = Logger::DEBUG
16
+ when :error
17
+ logger.level = Logger::ERROR
18
+ when :fatal
19
+ logger.level = Logger::FATAL
20
+ when :unknown
21
+ logger.level = Logger::UNKNOWN
22
+ when :warn
23
+ logger.level = Logger::WARN
24
+ else
25
+ logger.level = Logger::INFO
26
+ end
27
+
28
+ logger.datetime_format = '%Y-%m-%d %H:%M:%S.%N'
15
29
 
16
30
  logger.formatter = proc do |severity, _datetime, _progname, msg|
17
31
  # TODO: Include datetime & progname vars