cryptum 0.0.403 → 0.0.404

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c3ddca0be68aa66c07bd2f5b508e528ba5e9e8fe66d795ac248ee8fc513d17c
4
- data.tar.gz: 5edc469a75086a30f35303c8f9f48a9b8abc8b7ccb59d73d1761261d93512deb
3
+ metadata.gz: '0913d8426c5c821f0c2d2dc00a3b18dc0d8fbb39c29c609bba2d21141221f9d9'
4
+ data.tar.gz: 3fdb1a3d5ca383f0ef86c0161ce3edc0c4f42132f654db0717e84d0cc1c8f839
5
5
  SHA512:
6
- metadata.gz: f13fa02e5df897194257171a571f31c9a43aca37a186c1a5135ca1c7e38ecded4f0f104d90dec190bfd43d292c3c824ec85161b37de53f4fccf21dc46eb5e3e5
7
- data.tar.gz: e20536c4410634a48727e02ff9068d728c637319b8ea8600336ba18051d86104183c9a9c7eb7c4a73e603e738f5e76f5ce5ceee2334b94fb0eae4628b6b44fcd
6
+ metadata.gz: d9d418bbbb759a3f3db5b4b2807c95936c5a114306631e053c63652b6d893e611ef2605c9a910847b51af3c291fde6ac3f1b72568a8f7c4a19b0c904778ba16d
7
+ data.tar.gz: d7a91468fcc01eb19588fc349bf6608b067c5f0f1f3c5138ea18ae11524cc902a7346f65d9ee04ca22a76fd204947583de38474e83e972984cd428cceb7c71a9
@@ -158,7 +158,7 @@ module Cryptum
158
158
  sleep 1
159
159
  retry
160
160
  rescue Interrupt, StandardError => e
161
- Cryptum::Log.append(level: error, msg: e, which_self: self)
161
+ Cryptum::Log.append(level: :error, msg: e, which_self: self)
162
162
  end
163
163
 
164
164
  # Display Usage for this Module
@@ -34,11 +34,7 @@ module Cryptum
34
34
 
35
35
  bot_conf
36
36
  rescue Errno::ENOENT, NoMethodError => e
37
- File.open('/tmp/cryptum-errors.txt', 'a') do |f|
38
- f.puts Time.now.strftime('%Y-%m-%d %H:%M:%S.%N %z')
39
- f.puts "Module: #{self}"
40
- f.puts "#{e}\n\n\n"
41
- end
37
+ Cryptum::Log.append(level: :error, msg: e, which_self: self, event_history: event_history)
42
38
 
43
39
  retry
44
40
  rescue Interrupt, StandardError => e
@@ -133,11 +129,7 @@ module Cryptum
133
129
 
134
130
  bot_conf
135
131
  rescue Errno::ENOENT, NoMethodError => e
136
- File.open('/tmp/cryptum-errors.txt', 'a') do |f|
137
- f.puts Time.now.strftime('%Y-%m-%d %H:%M:%S.%N %z')
138
- f.puts "Module: #{self}"
139
- f.puts "#{e}\n\n\n"
140
- end
132
+ Cryptum::Log.append(level: :error, msg: e, which_self: self, event_history: event_history)
141
133
 
142
134
  retry
143
135
  rescue Interrupt, StandardError => e
@@ -160,11 +152,7 @@ module Cryptum
160
152
  bot_conf[key] = value
161
153
  File.write(bot_conf_file, bot_conf.to_yaml)
162
154
  rescue Errno::ENOENT, NoMethodError => e
163
- File.open('/tmp/cryptum-errors.txt', 'a') do |f|
164
- f.puts Time.now.strftime('%Y-%m-%d %H:%M:%S.%N %z')
165
- f.puts "Module: #{self}"
166
- f.puts "#{e}\n\n\n"
167
- end
155
+ Cryptum::Log.append(level: :error, msg: e, which_self: self, event_history: event_history)
168
156
 
169
157
  retry
170
158
  rescue Interrupt, StandardError => e
data/lib/cryptum/log.rb CHANGED
@@ -12,8 +12,20 @@ module Cryptum
12
12
  which_self = opts[:which_self].to_s
13
13
  event_history = opts[:event_history]
14
14
 
15
+ # Only attempt to exit gracefully if level == :error
16
+ exit_gracefully = false
17
+
18
+ if event_history.respond_to?('order_book')
19
+ session = event_history.order_book[:path].split('/').first
20
+ symbol = event_history.order_book[:symbol]
21
+ end
22
+
23
+ # Define Date / Time Format
24
+ datetime_str = '%Y-%m-%d %H:%M:%S.%N%z'
25
+
15
26
  # Always append to log file
16
27
  log_file = File.open('/tmp/cryptum.log', 'a')
28
+ log_file = File.open("/tmp/cryptum-ai-#{session}-#{symbol}.json", 'a') if level == :learning
17
29
 
18
30
  # Leave 10 "old" log files where
19
31
  # each file is ~ 1,024,000 bytes
@@ -22,9 +34,7 @@ module Cryptum
22
34
  10,
23
35
  1_024_000
24
36
  )
25
-
26
- # Only attempt to exit gracefully if level == :error
27
- exit_gracefully = false
37
+ logger.datetime_format = datetime_str
28
38
 
29
39
  case level
30
40
  when :debug
@@ -38,37 +48,49 @@ module Cryptum
38
48
  # triggered. This prevents infintely attempting to
39
49
  # exit if something in the module fails.
40
50
  logger.level = Logger::FATAL
51
+ when :info, :learning
52
+ logger.level = Logger::INFO
41
53
  when :unknown
42
54
  logger.level = Logger::UNKNOWN
43
55
  when :warn
44
56
  logger.level = Logger::WARN
45
- when :info
46
- logger.level = Logger::INFO
47
57
  else
48
58
  level_error = "ERROR: Invalid log level. Valid options are:\n"
49
59
  level_error += ":info\n:warn\n:unknown\n:fatal\n:error\n:debug"
50
60
  raise level_error
51
61
  end
52
62
 
53
- logger.datetime_format = '%Y-%m-%d %H:%M:%S.%N'
54
- log_event = ''
55
- if event_history.respond_to?('order_book')
56
- log_event = "session: #{event_history.order_book[:path].split('/').first}, "
57
- log_event += "symbol: #{event_history.order_book[:symbol]}"
58
- end
59
-
60
- if msg.instance_of?(Interrupt)
61
- log_event += ' => CTRL+C Detected...Exiting Session.'
62
- logger.level = Logger::WARN
63
- exit_gracefully = true
63
+ if level == :learning
64
+ logger.formatter = proc do |_severity, datetime, progname, json_msg|
65
+ date = datetime.strftime(datetime_str)
66
+ JSON.pretty_generate(
67
+ date: date,
68
+ session: session,
69
+ symbol: symbol,
70
+ progname: progname,
71
+ msg: json_msg
72
+ )
73
+ end
64
74
  else
65
- log_event += " => #{msg}"
66
- log_event += " => \n\t#{msg.backtrace.join("\n\t")}\n\n\n" if msg.respond_to?('backtrace')
67
- end
75
+ log_event = ''
76
+ if event_history.respond_to?('order_book')
77
+ log_event = "session: #{session}, "
78
+ log_event += "symbol: #{symbol}"
79
+ end
68
80
 
69
- logger.add(logger.level, log_event, which_self)
81
+ if msg.instance_of?(Interrupt)
82
+ log_event += ' => CTRL+C Detected...Exiting Session.'
83
+ logger.level = Logger::WARN
84
+ exit_gracefully = true
85
+ else
86
+ log_event += " => #{msg}"
87
+ log_event += " => \n\t#{msg.backtrace.join("\n\t")}\n\n\n" if msg.respond_to?('backtrace')
88
+ end
70
89
 
71
- Cryptum::UI::Exit.gracefully(event_history: event_history) if exit_gracefully
90
+ logger.add(logger.level, log_event, which_self)
91
+
92
+ Cryptum::UI::Exit.gracefully(event_history: event_history) if exit_gracefully
93
+ end
72
94
  rescue Interrupt, StandardError => e
73
95
  raise e
74
96
  end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cryptum
4
+ # Load in a Data Structure and Convert Strings to Integers or Floats if Possible.
5
+ module Massage
6
+ # Supported Method Parameters::
7
+ # number = numeric(
8
+ # struct: 'required - data structure to massage'
9
+ # )
10
+ private_class_method def self.numeric(opts = {})
11
+ struct = opts[:struct]
12
+
13
+ Integer(struct)
14
+ rescue StandardError
15
+ Float(struct)
16
+ end
17
+
18
+ # Supported Method Parameters::
19
+ # massaged_data = Cryptum::Massage.data(
20
+ # struct: 'required - data structure to massage'
21
+ # )
22
+ public_class_method def self.data(opts = {})
23
+ struct = opts[:struct]
24
+
25
+ case struct
26
+ when String
27
+ begin
28
+ numeric(struct: struct)
29
+ rescue StandardError
30
+ struct
31
+ end
32
+ when Array
33
+ struct.map { |i| data(struct: i) }
34
+ when Hash
35
+ struct.merge(struct) { |_k, v| data(struct: v) }
36
+ else
37
+ struct
38
+ end
39
+ rescue Interrupt, StandardError => e
40
+ Cryptum::Log.append(level: :error, msg: e, which_self: self)
41
+ end
42
+
43
+ # Display Usage for this Module
44
+
45
+ public_class_method def self.help
46
+ puts "USAGE:
47
+ massaged_data = Cryptum::Massage.data(
48
+ struct: 'required - data structure to massage'
49
+ )
50
+ "
51
+ end
52
+ end
53
+ end
@@ -95,13 +95,19 @@ module Cryptum
95
95
 
96
96
  limit_price = last_purchase_price - quote_increment.to_f if last_purchase_price.positive? && last_purchase_price < limit_price
97
97
 
98
- # Debug last order
99
- File.open('/tmp/cryptum-errors.txt', 'a') do |f|
100
- f.puts "Last Order: #{last_order}"
101
- f.puts "Last Purchase Price: #{last_purchase_price}"
102
- f.puts "Limit Price (Should be <= quote_increment-- ^): #{limit_price}"
103
- f.puts "\n\n\n"
104
- end
98
+ # Debug last order -------------------------------#
99
+ debug_last_order = "Last Order: #{last_order}"
100
+ debug_last_order += "Last Purchase Price: #{last_purchase_price}"
101
+ debug_last_order += "Limit Price (Should be <= quote_increment-- ^): #{limit_price}"
102
+ debug_last_order += "\n\n\n"
103
+
104
+ Cryptum::Log.append(
105
+ level: :debug,
106
+ msg: debug_last_order,
107
+ which_self: self,
108
+ event_history: event_history
109
+ )
110
+ #-------------------------------------------------#
105
111
 
106
112
  price = format(
107
113
  "%0.#{fiat_smallest_decimal}f",
@@ -243,6 +249,12 @@ module Cryptum
243
249
 
244
250
  meta[:done_at] = Time.now.strftime('%Y-%m-%d %H:%M:%S.%N%z')
245
251
  meta[:color] = :green
252
+ Cryptum::Log.append(
253
+ level: :learning,
254
+ msg: meta,
255
+ which_self: self,
256
+ event_history: event_history
257
+ )
246
258
  end
247
259
  end
248
260
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cryptum
4
- VERSION = '0.0.403'
4
+ VERSION = '0.0.404'
5
5
  end
data/lib/cryptum.rb CHANGED
@@ -27,6 +27,7 @@ module Cryptum
27
27
  require 'cryptum/bot_conf'
28
28
  require 'cryptum/event'
29
29
  require 'cryptum/log'
30
+ require 'cryptum/massage'
30
31
  require 'cryptum/open_ai'
31
32
  require 'cryptum/option'
32
33
  require 'cryptum/order_book'
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Cryptum::Massage do
6
+ it 'should display information for existing help method' do
7
+ help_response = Cryptum::Massage
8
+ expect(help_response).to respond_to :help
9
+ end
10
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cryptum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.403
4
+ version: 0.0.404
5
5
  platform: ruby
6
6
  authors:
7
7
  - 0day Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-05 00:00:00.000000000 Z
11
+ date: 2023-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -417,6 +417,7 @@ files:
417
417
  - lib/cryptum/event/scroll.rb
418
418
  - lib/cryptum/event/sell.rb
419
419
  - lib/cryptum/log.rb
420
+ - lib/cryptum/massage.rb
420
421
  - lib/cryptum/open_ai.rb
421
422
  - lib/cryptum/option.rb
422
423
  - lib/cryptum/option/choice.rb
@@ -476,6 +477,7 @@ files:
476
477
  - spec/lib/cryptum/event/sell_spec.rb
477
478
  - spec/lib/cryptum/event_spec.rb
478
479
  - spec/lib/cryptum/log_spec.rb
480
+ - spec/lib/cryptum/massage_spec.rb
479
481
  - spec/lib/cryptum/open_ai_spec.rb
480
482
  - spec/lib/cryptum/option/choice_spec.rb
481
483
  - spec/lib/cryptum/option/environment_spec.rb