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 +4 -4
- data/lib/cryptum/api/rest.rb +1 -1
- data/lib/cryptum/bot_conf.rb +3 -15
- data/lib/cryptum/log.rb +43 -21
- data/lib/cryptum/massage.rb +53 -0
- data/lib/cryptum/ui/order/execute.rb +19 -7
- data/lib/cryptum/version.rb +1 -1
- data/lib/cryptum.rb +1 -0
- data/spec/lib/cryptum/massage_spec.rb +10 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0913d8426c5c821f0c2d2dc00a3b18dc0d8fbb39c29c609bba2d21141221f9d9'
|
4
|
+
data.tar.gz: 3fdb1a3d5ca383f0ef86c0161ce3edc0c4f42132f654db0717e84d0cc1c8f839
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9d418bbbb759a3f3db5b4b2807c95936c5a114306631e053c63652b6d893e611ef2605c9a910847b51af3c291fde6ac3f1b72568a8f7c4a19b0c904778ba16d
|
7
|
+
data.tar.gz: d7a91468fcc01eb19588fc349bf6608b067c5f0f1f3c5138ea18ae11524cc902a7346f65d9ee04ca22a76fd204947583de38474e83e972984cd428cceb7c71a9
|
data/lib/cryptum/api/rest.rb
CHANGED
@@ -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
|
data/lib/cryptum/bot_conf.rb
CHANGED
@@ -34,11 +34,7 @@ module Cryptum
|
|
34
34
|
|
35
35
|
bot_conf
|
36
36
|
rescue Errno::ENOENT, NoMethodError => e
|
37
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
66
|
-
|
67
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
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
|
|
data/lib/cryptum/version.rb
CHANGED
data/lib/cryptum.rb
CHANGED
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.
|
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-
|
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
|