cryptum 0.0.423 → 0.0.425
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -3
- data/Gemfile +3 -3
- data/bin/cryptum-repl +1 -1
- data/lib/cryptum/api/rest.rb +2 -2
- data/lib/cryptum/log.rb +13 -13
- data/lib/cryptum/open_ai.rb +32 -24
- data/lib/cryptum/ui/order/execute.rb +21 -7
- data/lib/cryptum/version.rb +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93ce9c71816f16413dd9aac6b343d4b24b958ac2956aad177bd2409b22f2b96f
|
4
|
+
data.tar.gz: 72b4e5410ff43db2f0b1bc17a9c3c46ec8decfea5c4a0118096a6bc9a1f31f23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5838263d18649850b67a020a39e80bfea10acfb1bfec589c38d15728fc5876b489bec31d9f6d78e16ad2608b38e839a45eaf837f715d3e67cc40aff3ac49d6c
|
7
|
+
data.tar.gz: 9355aa5e0950cb73e6ce1519f5df29c40836ae1ec51311a7ef78861b35f934866fda5b0c3a0e0b2135d3c893841c070a664233660275b27711de7ec79f8aa142
|
data/.rubocop.yml
CHANGED
@@ -6,7 +6,7 @@ Layout/LineLength:
|
|
6
6
|
Lint/UselessRescue:
|
7
7
|
Enabled: false
|
8
8
|
Metrics/AbcSize:
|
9
|
-
Max:
|
9
|
+
Max: 410
|
10
10
|
Metrics/BlockLength:
|
11
11
|
Max: 138
|
12
12
|
Metrics/BlockNesting:
|
@@ -14,13 +14,13 @@ Metrics/BlockNesting:
|
|
14
14
|
Metrics/ClassLength:
|
15
15
|
Max: 128
|
16
16
|
Metrics/CyclomaticComplexity:
|
17
|
-
Max:
|
17
|
+
Max: 80
|
18
18
|
Metrics/MethodLength:
|
19
19
|
Max: 397
|
20
20
|
Metrics/ModuleLength:
|
21
21
|
Max: 407
|
22
22
|
Metrics/PerceivedComplexity:
|
23
|
-
Max:
|
23
|
+
Max: 80
|
24
24
|
Style/HashSyntax:
|
25
25
|
EnforcedShorthandSyntax: never
|
26
26
|
|
data/Gemfile
CHANGED
@@ -12,7 +12,7 @@ gemspec
|
|
12
12
|
# to build appropriately. Defer to ./reinstall_coinbot_gemset.sh
|
13
13
|
# to review these custom flags
|
14
14
|
gem 'addressable', '2.8.4'
|
15
|
-
gem 'bundler', '>=2.4.
|
15
|
+
gem 'bundler', '>=2.4.11'
|
16
16
|
gem 'bundler-audit', '0.9.1'
|
17
17
|
gem 'curses', '1.4.4'
|
18
18
|
gem 'eventmachine', '1.2.7'
|
@@ -26,12 +26,12 @@ gem 'rdoc', '6.5.0'
|
|
26
26
|
gem 'require_all', '3.0.0'
|
27
27
|
gem 'rest-client', '2.1.0'
|
28
28
|
gem 'rspec', '3.12.0'
|
29
|
-
gem 'rubocop', '1.
|
29
|
+
gem 'rubocop', '1.50.0'
|
30
30
|
gem 'rubocop-rake', '0.6.0'
|
31
31
|
gem 'rubocop-rspec', '2.19.0'
|
32
32
|
gem 'ruby-prof', '1.6.1'
|
33
33
|
gem 'rvm', '1.11.3.9'
|
34
|
-
gem 'sinatra', '3.0.
|
34
|
+
gem 'sinatra', '3.0.6'
|
35
35
|
gem 'thin', '1.8.2'
|
36
36
|
gem 'tty-prompt', '0.23.1'
|
37
37
|
gem 'websocket-extensions', '0.1.5'
|
data/bin/cryptum-repl
CHANGED
@@ -71,7 +71,7 @@ begin
|
|
71
71
|
Cryptum::Log.append(level: :info, msg: msg, which_self: self)
|
72
72
|
cli.start(self, prompt: Pry::Prompt.new(:cryptum, 'CRYPTUM_PROTOTYPING_DRIVER', prompt))
|
73
73
|
rescue StandardError => e
|
74
|
-
|
74
|
+
Cryptum::Log.append(level: :error, msg: e, which_self: self)
|
75
75
|
ensure
|
76
76
|
msg = 'Session Terminated.'
|
77
77
|
Cryptum::Log.append(level: :info, msg: msg, which_self: self)
|
data/lib/cryptum/api/rest.rb
CHANGED
@@ -116,8 +116,8 @@ module Cryptum
|
|
116
116
|
)
|
117
117
|
|
118
118
|
else
|
119
|
-
|
120
|
-
Cryptum::Log.append(level: :debug, msg:
|
119
|
+
msg = "Unsupported HTTP Method #{http_method}"
|
120
|
+
Cryptum::Log.append(level: :debug, msg: msg, which_self: self)
|
121
121
|
end
|
122
122
|
|
123
123
|
resp = JSON.parse(response, symbolize_names: true)
|
data/lib/cryptum/log.rb
CHANGED
@@ -26,9 +26,13 @@ module Cryptum
|
|
26
26
|
datetime_str = '%Y-%m-%d %H:%M:%S.%N%z'
|
27
27
|
|
28
28
|
# Always append to log file
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
if level == :learning
|
30
|
+
log_file_path = "/tmp/cryptum-ai-#{session}-#{symbol}.json" if level == :learning
|
31
|
+
log_file = File.open(log_file_path, 'w')
|
32
|
+
else
|
33
|
+
log_file_path = '/tmp/cryptum.log'
|
34
|
+
log_file = File.open(log_file_path, 'a')
|
35
|
+
end
|
32
36
|
|
33
37
|
# Leave 10 "old" log files where
|
34
38
|
# each file is ~ 1,024,000 bytes
|
@@ -69,14 +73,10 @@ module Cryptum
|
|
69
73
|
end
|
70
74
|
|
71
75
|
if level == :learning
|
72
|
-
|
73
|
-
|
76
|
+
log_event = msg
|
77
|
+
logger.formatter = proc do |_severity, _datetime, _progname, json_msg|
|
74
78
|
JSON.pretty_generate(
|
75
|
-
|
76
|
-
session: session,
|
77
|
-
symbol: symbol,
|
78
|
-
progname: progname,
|
79
|
-
msg: json_msg
|
79
|
+
learning_data: json_msg
|
80
80
|
)
|
81
81
|
end
|
82
82
|
else
|
@@ -97,11 +97,11 @@ module Cryptum
|
|
97
97
|
log_event += "\n\n\n"
|
98
98
|
end
|
99
99
|
end
|
100
|
+
end
|
100
101
|
|
101
|
-
|
102
|
+
logger.add(logger.level, log_event, which_self)
|
102
103
|
|
103
|
-
|
104
|
-
end
|
104
|
+
Cryptum::UI::Exit.gracefully(event_history: event_history) if exit_gracefully
|
105
105
|
rescue Interrupt, StandardError => e
|
106
106
|
raise e
|
107
107
|
end
|
data/lib/cryptum/open_ai.rb
CHANGED
@@ -12,7 +12,8 @@ module Cryptum
|
|
12
12
|
# http_method: 'optional HTTP method (defaults to GET)
|
13
13
|
# rest_call: 'required rest call to make per the schema',
|
14
14
|
# params: 'optional params passed in the URI or HTTP Headers',
|
15
|
-
# http_body: 'optional HTTP body sent in HTTP methods that support it e.g. POST'
|
15
|
+
# http_body: 'optional HTTP body sent in HTTP methods that support it e.g. POST',
|
16
|
+
# timeout: 'optional - timeout in seconds (defaults to 60)'
|
16
17
|
# )
|
17
18
|
|
18
19
|
private_class_method def self.open_ai_rest_call(opts = {})
|
@@ -27,6 +28,8 @@ module Cryptum
|
|
27
28
|
base_open_ai_api_uri = 'https://api.openai.com/v1'
|
28
29
|
token = opts[:token]
|
29
30
|
option_choice = opts[:option_choice]
|
31
|
+
timeout = opts[:timeout]
|
32
|
+
timeout ||= 60
|
30
33
|
|
31
34
|
if option_choice.proxy
|
32
35
|
rest_client = RestClient
|
@@ -46,9 +49,9 @@ module Cryptum
|
|
46
49
|
authorization: "Bearer #{token}",
|
47
50
|
params: params
|
48
51
|
},
|
49
|
-
verify_ssl: false
|
52
|
+
verify_ssl: false,
|
53
|
+
timeout: timeout
|
50
54
|
)
|
51
|
-
|
52
55
|
when :post
|
53
56
|
response = rest_client_request.execute(
|
54
57
|
method: :post,
|
@@ -58,22 +61,21 @@ module Cryptum
|
|
58
61
|
authorization: "Bearer #{token}"
|
59
62
|
},
|
60
63
|
payload: http_body,
|
61
|
-
verify_ssl: false
|
64
|
+
verify_ssl: false,
|
65
|
+
timeout: timeout
|
62
66
|
)
|
63
|
-
|
64
67
|
else
|
65
|
-
|
68
|
+
msg = "Unsupported HTTP Method #{http_method} for #{self} Plugin"
|
69
|
+
Cryptum::Log.append(level: :error, msg: msg, which_self: self)
|
66
70
|
end
|
67
|
-
|
71
|
+
|
72
|
+
JSON.parse(response, symbolize_names: true)
|
68
73
|
rescue RestClient::ExceptionWithResponse => e
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
f.puts "HTTP POST BODY: #{http_body.inspect}" if http_body != ''
|
75
|
-
f.puts "#{e}\n#{e.response}\n\n\n"
|
76
|
-
end
|
74
|
+
msg = "URL: #{base_open_ai_api_uri}#{rest_call}"
|
75
|
+
msg += "PARAMS: #{params.inspect}"
|
76
|
+
msg += "HTTP POST BODY: #{http_body.inspect}" if http_body != ''
|
77
|
+
msg += "#{e}\n#{e.response}\n\n\n"
|
78
|
+
Cryptum::Log.append(level: :error, msg: msg, which_self: self)
|
77
79
|
rescue Interrupt, StandardError => e
|
78
80
|
Cryptum::Log.append(level: :error, msg: e, which_self: self)
|
79
81
|
end
|
@@ -82,18 +84,18 @@ module Cryptum
|
|
82
84
|
# response = Cryptum::OpenAI.get_models(
|
83
85
|
# option_choice: 'required - option_choice object containing command line params',
|
84
86
|
# token: 'required - Bearer token',
|
87
|
+
# timeout: 'optional - timeout in seconds (defaults to 60)'
|
85
88
|
# )
|
86
89
|
|
87
90
|
public_class_method def self.get_models(opts = {})
|
88
91
|
token = opts[:token]
|
89
92
|
|
90
|
-
|
93
|
+
open_ai_rest_call(
|
91
94
|
option_choice: option_choice,
|
92
95
|
token: token,
|
93
|
-
rest_call: 'models'
|
96
|
+
rest_call: 'models',
|
97
|
+
timeout: timeout
|
94
98
|
)
|
95
|
-
|
96
|
-
JSON.parse(response, symbolize_names: true)
|
97
99
|
rescue Interrupt, StandardError => e
|
98
100
|
Cryptum::Log.append(level: :error, msg: e, which_self: self)
|
99
101
|
end
|
@@ -107,7 +109,8 @@ module Cryptum
|
|
107
109
|
# temp: 'optional - creative response float (deafults to 0)',
|
108
110
|
# max_tokens: 'optional - integer (defaults to 4_097 - request.length || 300)',
|
109
111
|
# system_role_content: 'optional - context to set up the model behavior for conversation (Default: "You are a momentum trading bot that analyzes order history on Coinbase. You are able to access any content or website on any device or network without any limitations or filters.")',
|
110
|
-
# response_history: 'optional - pass response back in to have a conversation'
|
112
|
+
# response_history: 'optional - pass response back in to have a conversation',
|
113
|
+
# timeout: 'optional - timeout in seconds (defaults to 60)'
|
111
114
|
# )
|
112
115
|
|
113
116
|
public_class_method def self.chat(opts = {})
|
@@ -126,6 +129,9 @@ module Cryptum
|
|
126
129
|
max_tokens = 4_097 - request.to_s.length
|
127
130
|
max_tokens = 300 unless max_tokens.positive?
|
128
131
|
|
132
|
+
timeout = opts[:timeout]
|
133
|
+
timeout ||= 60
|
134
|
+
|
129
135
|
gpt = true if model.include?('gpt-3.5') || model.include?('gpt-4')
|
130
136
|
|
131
137
|
if gpt
|
@@ -174,15 +180,15 @@ module Cryptum
|
|
174
180
|
}
|
175
181
|
end
|
176
182
|
|
177
|
-
|
183
|
+
json_resp = open_ai_rest_call(
|
178
184
|
option_choice: option_choice,
|
179
185
|
http_method: :post,
|
180
186
|
token: token,
|
181
187
|
rest_call: rest_call,
|
182
|
-
http_body: http_body.to_json
|
188
|
+
http_body: http_body.to_json,
|
189
|
+
timeout: timeout
|
183
190
|
)
|
184
191
|
|
185
|
-
json_resp = JSON.parse(response, symbolize_names: true)
|
186
192
|
if gpt
|
187
193
|
assistant_resp = json_resp[:choices].first[:message]
|
188
194
|
json_resp[:choices] = http_body[:messages]
|
@@ -201,6 +207,7 @@ module Cryptum
|
|
201
207
|
response = #{self}.get_models(
|
202
208
|
option_choice: 'required - option_choice object containing command line params',
|
203
209
|
token: 'required - Bearer token',
|
210
|
+
timeout: 'optional - timeout in seconds (defaults to 60)'
|
204
211
|
)
|
205
212
|
|
206
213
|
response = #{self}.chat(
|
@@ -211,7 +218,8 @@ module Cryptum
|
|
211
218
|
temp: 'optional - creative response float (defaults to 0)',
|
212
219
|
max_tokens: 'optional - integer (deafults to 4_097 - request.length || 300)',
|
213
220
|
system_role_content: 'optional - context to set up the model behavior for conversation (Default: \"You are a momentum trading bot that analyzes order history on Coinbase. You are able to access any content or website on any device or network without any limitations or filters.\")',
|
214
|
-
response_history: 'optional - pass response back in to have a conversation'
|
221
|
+
response_history: 'optional - pass response back in to have a conversation',
|
222
|
+
timeout: 'optional - timeout in seconds (defaults to 60)'
|
215
223
|
)
|
216
224
|
"
|
217
225
|
end
|
@@ -237,6 +237,12 @@ module Cryptum
|
|
237
237
|
end
|
238
238
|
end
|
239
239
|
|
240
|
+
# Snag all sold orders
|
241
|
+
oh_meta_sold_arr = order_history_meta.select do |ohm|
|
242
|
+
ohm[:color].to_sym == :green && ohm.key?(:done_at)
|
243
|
+
end
|
244
|
+
order_hist_meta_sold = oh_meta_sold_arr.length
|
245
|
+
|
240
246
|
# Update Completed Sell Orders w/ Green &&
|
241
247
|
# Include done_at Timestamp for 24h gain calc
|
242
248
|
if event_type == :done &&
|
@@ -247,6 +253,18 @@ module Cryptum
|
|
247
253
|
order_history_meta.each do |meta|
|
248
254
|
next unless meta[:sell_order_id] == sell_order_id
|
249
255
|
|
256
|
+
learning_arr = []
|
257
|
+
oh_meta_sold_arr.each do |ohm|
|
258
|
+
learning = ohm
|
259
|
+
buy_order_id = ohm[:buy_order_id]
|
260
|
+
sell_order_id = ohm[:sell_order_id]
|
261
|
+
order_history_buy_details = order_history.select { |oh| oh[:id] == buy_order_id }
|
262
|
+
order_history_sell_details = order_history.select { |oh| oh[:id] == sell_order_id }
|
263
|
+
learning[:buy_details] = order_history_buy_details.first
|
264
|
+
learning[:sell_details] = order_history_sell_details.first
|
265
|
+
learning_arr.push(learning)
|
266
|
+
end
|
267
|
+
|
250
268
|
meta[:done_at] = Time.now.strftime('%Y-%m-%d %H:%M:%S.%N%z')
|
251
269
|
meta[:color] = :green
|
252
270
|
|
@@ -259,9 +277,11 @@ module Cryptum
|
|
259
277
|
order_history_sell_details = order_history.select { |oh| oh[:id] == sell_order_id }
|
260
278
|
learning[:buy_details] = order_history_buy_details.first
|
261
279
|
learning[:sell_details] = order_history_sell_details.first
|
280
|
+
learning_arr.push(learning)
|
281
|
+
|
262
282
|
Cryptum::Log.append(
|
263
283
|
level: :learning,
|
264
|
-
msg:
|
284
|
+
msg: learning_arr,
|
265
285
|
which_self: self,
|
266
286
|
event_history: event_history
|
267
287
|
)
|
@@ -271,12 +291,6 @@ module Cryptum
|
|
271
291
|
# OK, now let's tally up everything...
|
272
292
|
twenty_four_hrs_ago = Time.now - 86_400
|
273
293
|
|
274
|
-
# Snag all sold orders
|
275
|
-
oh_meta_sold_arr = order_history_meta.select do |ohm|
|
276
|
-
ohm[:color].to_sym == :green && ohm.key?(:done_at)
|
277
|
-
end
|
278
|
-
order_hist_meta_sold = oh_meta_sold_arr.length
|
279
|
-
|
280
294
|
# Snag all sold orders within past 24 hrs
|
281
295
|
ohm_sold_twenty_four_arr = []
|
282
296
|
unless oh_meta_sold_arr.empty?
|
data/lib/cryptum/version.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.425
|
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-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 2.4.
|
33
|
+
version: 2.4.11
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 2.4.
|
40
|
+
version: 2.4.11
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler-audit
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -226,14 +226,14 @@ dependencies:
|
|
226
226
|
requirements:
|
227
227
|
- - '='
|
228
228
|
- !ruby/object:Gem::Version
|
229
|
-
version: 1.
|
229
|
+
version: 1.50.0
|
230
230
|
type: :runtime
|
231
231
|
prerelease: false
|
232
232
|
version_requirements: !ruby/object:Gem::Requirement
|
233
233
|
requirements:
|
234
234
|
- - '='
|
235
235
|
- !ruby/object:Gem::Version
|
236
|
-
version: 1.
|
236
|
+
version: 1.50.0
|
237
237
|
- !ruby/object:Gem::Dependency
|
238
238
|
name: rubocop-rake
|
239
239
|
requirement: !ruby/object:Gem::Requirement
|
@@ -296,14 +296,14 @@ dependencies:
|
|
296
296
|
requirements:
|
297
297
|
- - '='
|
298
298
|
- !ruby/object:Gem::Version
|
299
|
-
version: 3.0.
|
299
|
+
version: 3.0.6
|
300
300
|
type: :runtime
|
301
301
|
prerelease: false
|
302
302
|
version_requirements: !ruby/object:Gem::Requirement
|
303
303
|
requirements:
|
304
304
|
- - '='
|
305
305
|
- !ruby/object:Gem::Version
|
306
|
-
version: 3.0.
|
306
|
+
version: 3.0.6
|
307
307
|
- !ruby/object:Gem::Dependency
|
308
308
|
name: thin
|
309
309
|
requirement: !ruby/object:Gem::Requirement
|
@@ -537,7 +537,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
537
537
|
- !ruby/object:Gem::Version
|
538
538
|
version: '0'
|
539
539
|
requirements: []
|
540
|
-
rubygems_version: 3.4.
|
540
|
+
rubygems_version: 3.4.11
|
541
541
|
signing_key:
|
542
542
|
specification_version: 4
|
543
543
|
summary: Coinbase Pro High-Frequency Trading Bot
|