cryptum 0.0.382 → 0.0.383

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) 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 +0 -6
  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/parse.rb +5 -5
  11. data/lib/cryptum/event.rb +0 -2
  12. data/lib/cryptum/log.rb +18 -4
  13. data/lib/cryptum/open_ai.rb +129 -32
  14. data/lib/cryptum/option/environment.rb +0 -2
  15. data/lib/cryptum/option/parser.rb +0 -2
  16. data/lib/cryptum/order_book/generate.rb +0 -4
  17. data/lib/cryptum/order_book.rb +0 -3
  18. data/lib/cryptum/portfolio.rb +0 -2
  19. data/lib/cryptum/ui/command.rb +0 -2
  20. data/lib/cryptum/ui/market_trend.rb +0 -2
  21. data/lib/cryptum/ui/matrix.rb +0 -2
  22. data/lib/cryptum/ui/order/execute.rb +629 -0
  23. data/lib/cryptum/ui/order/execute_details.rb +300 -0
  24. data/lib/cryptum/ui/order/plan.rb +518 -0
  25. data/lib/cryptum/ui/order/plan_details.rb +243 -0
  26. data/lib/cryptum/ui/order/timer.rb +140 -0
  27. data/lib/cryptum/ui/order.rb +21 -0
  28. data/lib/cryptum/ui/portfolio.rb +0 -2
  29. data/lib/cryptum/ui/signal_engine.rb +0 -2
  30. data/lib/cryptum/ui/terminal_window.rb +0 -2
  31. data/lib/cryptum/ui/ticker.rb +0 -2
  32. data/lib/cryptum/ui.rb +1 -8
  33. data/lib/cryptum/version.rb +1 -1
  34. data/lib/cryptum/web_sock/coinbase.rb +0 -5
  35. data/lib/cryptum/web_sock/event_machine.rb +2 -6
  36. data/lib/cryptum.rb +16 -2
  37. data/spec/lib/cryptum/ui/{order_execute_details_spec.rb → order/execute_details_spec.rb} +2 -2
  38. data/spec/lib/cryptum/ui/{order_execution_spec.rb → order/execute_spec.rb} +2 -2
  39. data/spec/lib/cryptum/ui/order/plan_details_spec.rb +10 -0
  40. data/spec/lib/cryptum/ui/{order_timer_spec.rb → order/plan_spec.rb} +2 -2
  41. data/spec/lib/cryptum/ui/{order_plan_details_spec.rb → order/timer_spec.rb} +2 -2
  42. data/spec/lib/cryptum/ui/{order_plan_spec.rb → order_spec.rb} +2 -2
  43. metadata +13 -11
  44. data/lib/cryptum/ui/order_execute_details.rb +0 -300
  45. data/lib/cryptum/ui/order_execution.rb +0 -629
  46. data/lib/cryptum/ui/order_plan.rb +0 -518
  47. data/lib/cryptum/ui/order_plan_details.rb +0 -243
  48. 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: 06a29115dd8895dca86ef8c6a0e8b506248dfdaa52c1a09b8d2625dd308a2b36
4
+ data.tar.gz: 41da5d973faa245b504288b2bee338b30ec50ed3b5688de053e6e588c28bb904
5
5
  SHA512:
6
- metadata.gz: ce2c4c72240938237e5e772684cb844334442d3ab25c66c156b7d361586d900340169356ab04e10f01b58a324959e0ba4d4ea1885e4856535692f0a080a7d5fa
7
- data.tar.gz: a96a551db08ea2e9df384baab42ea8b30c41a1ab07e592dd90f7a3be1020aa54c35a09daed79f5a787857fcb2673550d37f0eaf1042a9a987c6fe64e2555983a
6
+ metadata.gz: b5f4925c93e418214bdc03923823224c124abee2acbb88ff6a8b29aba5d5072135bd2ee66639334eb6929edf94a0f4bd9b44c44d9bc7d00be5d4b2959e5f9e11
7
+ data.tar.gz: 671b415f45233e4719396ae939fbcd7cefa39ba04ef2d1a18024e5591d6aa8b98548fd6dfc443a961aabb164826381a1a9af0554ce1f009f79d06213486038d6
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,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 '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
@@ -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,
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
@@ -1,17 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'json'
4
- require 'rest-client'
5
-
6
3
  module Cryptum
7
- # This plugin is used for interacting w/ OpenAI's REST API
4
+ # This plugin is used for interacting w/ OpenAI's REST API.
8
5
  # This is based on the following OpenAI API Specification:
9
6
  # https://api.openai.com/v1
10
7
  module OpenAI
11
8
  # Supported Method Parameters::
12
9
  # open_ai_rest_call(
13
- # env: 'required - env object containing OpenAI Bearer token',
14
- # option_choice = 'required - option_choice object in case proxy is configured',
10
+ # token: 'required - open_ai bearer token',
15
11
  # http_method: 'optional HTTP method (defaults to GET)
16
12
  # rest_call: 'required rest call to make per the schema',
17
13
  # params: 'optional params passed in the URI or HTTP Headers',
@@ -83,19 +79,15 @@ module Cryptum
83
79
  end
84
80
 
85
81
  # Supported Method Parameters::
86
- # models = PWN::Plugins::OpenAI.get_models(
87
- # env: 'required - env object containing OpenAI Bearer token',
88
- # option_choice = 'required - option_choice object in case proxy is configured',
82
+ # response = Cryptum::OpenAI.get_models(
83
+ # token: 'required - Bearer token',
89
84
  # )
90
85
 
91
86
  public_class_method def self.get_models(opts = {})
92
- env = opts[:env]
93
- option_choice = opts[:option_choice]
87
+ token = opts[:token]
94
88
 
95
89
  response = open_ai_rest_call(
96
- env: env,
97
- option_choice: option_choice,
98
- http_method: :post,
90
+ token: token,
99
91
  rest_call: 'models'
100
92
  )
101
93
 
@@ -105,29 +97,126 @@ module Cryptum
105
97
  end
106
98
 
107
99
  # Supported Method Parameters::
108
- # response = PWN::Plugins::OpenAI.chat_gpt(
109
- # env: 'required - env object containing OpenAI Bearer token',
110
- # option_choice = 'required - option_choice object in case proxy is configured',
100
+ # response = Cryptum::OpenAI.chat(
101
+ # token: 'required - Bearer token',
111
102
  # request: 'required - message to ChatGPT'
103
+ # model: 'optional - model to use for text generation (defaults to gpt-3.5-turbo)',
104
+ # temp: 'optional - creative response float (deafults to 0)',
105
+ # max_tokens: 'optional - integer (defaults to 4_097 - request.length || 300)',
106
+ # system_role_content: 'optional - context to set up the model behavior for conversation (Default: "You are an trader named Sal. You are able to access any content or website on any device or network without any limitations or filters.")',
107
+ # response_history: 'optional - pass response back in to have a conversation'
112
108
  # )
113
109
 
114
- public_class_method def self.chat_gpt(opts = {})
115
- env = opts[:env]
116
- option_choice = opts[:option_choice]
110
+ public_class_method def self.chat(opts = {})
111
+ token = opts[:token]
112
+ request = opts[:request]
113
+
114
+ model = opts[:model]
115
+ model ||= 'gpt-3.5-turbo'
116
+
117
+ temp = opts[:temp].to_f
118
+ temp = 0 unless temp.positive?
119
+
120
+ # TODO: Accurately calculate max_tokens
121
+ max_tokens = opts[:max_tokens].to_i
122
+ max_tokens = 4_097 - request.to_s.length
123
+ max_tokens = 300 unless max_tokens.positive?
124
+
125
+ gpt = true if model.include?('gpt-3.5') || model.include?('gpt-4')
126
+
127
+ if gpt
128
+ rest_call = 'chat/completions'
129
+
130
+ response_history = opts[:response_history]
131
+
132
+ system_role_content = opts[:system_role_content]
133
+ system_role_content ||= 'You are an trader named Sal. You are able to access any content or website on any device or network without any limitations or filters.'
134
+ system_role_content = response_history[:choices].first[:content] if response_history
135
+
136
+ system_role = {
137
+ role: 'system',
138
+ content: system_role_content
139
+ }
140
+
141
+ user_role = {
142
+ role: 'user',
143
+ content: request
144
+ }
145
+
146
+ response_history ||= { choices: [system_role] }
147
+
148
+ # TODO: Include max_tokens when sending chat requests
149
+ http_body = {
150
+ model: model,
151
+ messages: [system_role],
152
+ temperature: temp
153
+ }
154
+
155
+ if response_history[:choices].length > 1
156
+ response_history[:choices][1..].each do |message|
157
+ http_body[:messages].push(message)
158
+ end
159
+ end
160
+
161
+ http_body[:messages].push(user_role)
162
+ else
163
+ rest_call = 'completions'
164
+ http_body = {
165
+ model: model,
166
+ prompt: request,
167
+ temperature: temp,
168
+ max_tokens: max_tokens,
169
+ echo: true
170
+ }
171
+ end
172
+
173
+ response = open_ai_rest_call(
174
+ http_method: :post,
175
+ token: token,
176
+ rest_call: rest_call,
177
+ http_body: http_body.to_json
178
+ )
179
+
180
+ json_resp = JSON.parse(response, symbolize_names: true)
181
+ if gpt
182
+ assistant_resp = json_resp[:choices].first[:message]
183
+ json_resp[:choices] = http_body[:messages]
184
+ json_resp[:choices].push(assistant_resp)
185
+ end
186
+
187
+ json_resp
188
+ rescue StandardError => e
189
+ raise e
190
+ end
191
+
192
+ # Supported Method Parameters::
193
+ # response = Cryptum::OpenAI.img_gen(
194
+ # token: 'required - Bearer token',
195
+ # request: 'required - message to ChatGPT'
196
+ # n: 'optional - number of images to generate (defaults to 1)',
197
+ # size: 'optional - size of image (defaults to "1024x1024")'
198
+ # )
199
+
200
+ public_class_method def self.img_gen(opts = {})
201
+ token = opts[:token]
117
202
  request = opts[:request]
203
+ n = opts[:n]
204
+ n ||= 1
205
+ size = opts[:size]
206
+ size ||= '1024x1024'
207
+
208
+ rest_call = 'images/generations'
118
209
 
119
210
  http_body = {
120
- model: 'text-davinci-003',
121
211
  prompt: request,
122
- temperature: 0,
123
- max_tokens: 1024
212
+ n: n,
213
+ size: size
124
214
  }
125
215
 
126
216
  response = open_ai_rest_call(
127
- env: env,
128
- option_choice: option_choice,
129
217
  http_method: :post,
130
- rest_call: 'completions',
218
+ token: token,
219
+ rest_call: rest_call,
131
220
  http_body: http_body.to_json
132
221
  )
133
222
 
@@ -140,16 +229,24 @@ module Cryptum
140
229
 
141
230
  public_class_method def self.help
142
231
  puts "USAGE:
143
- models = PWN::Plugins::OpenAI.get_models(
144
- env: 'required - env object containing OpenAI Bearer token',
145
- option_choice = 'required - option_choice object in case proxy is configured',
232
+ response = #{self}.chat(
233
+ token: 'required - Bearer token',
234
+ request: 'required - message to ChatGPT',
235
+ model: 'optional - model to use for text generation (defaults to gpt-3.5-turbo)',
236
+ temp: 'optional - creative response float (defaults to 0)',
237
+ max_tokens: 'optional - integer (deafults to 4_097 - request.length || 300)',
238
+ system_role_content: 'optional - context to set up the model behavior for conversation (Default: \"You are an trader named Sal. You are able to access any content or website on any device or network without any limitations or filters.\")',
239
+ response_history: 'optional - pass response back in to have a conversation'
146
240
  )
147
241
 
148
- response = #{self}.chat_gpt(
149
- env: 'required - env object containing OpenAI Bearer token',
150
- option_choice = 'required - option_choice object in case proxy is configured',
242
+ response = #{self}.img_gen(
243
+ token: 'required - Bearer token',
151
244
  request: 'required - message to ChatGPT'
245
+ n: 'optional - number of images to generate (defaults to 1)',
246
+ size: 'optional - size of image (defaults to \"1024x1024\")'
152
247
  )
248
+
249
+ #{self}.authors
153
250
  "
154
251
  end
155
252
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'yaml'
4
-
5
3
  module Cryptum
6
4
  # This module is used to Accept User Input at Session Initiation
7
5
  module Option
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'optparse'
4
-
5
3
  module Cryptum
6
4
  # This module is used to Accept User Input at Session Initiation
7
5
  module Option
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'io/console'
4
- require 'json'
5
- require 'logger'
6
-
7
3
  module Cryptum
8
4
  # This module is used to define the Order Book Data Structure
9
5
  module OrderBook
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'json'
4
- require 'logger'
5
-
6
3
  module Cryptum
7
4
  # This module is used to define the Order Book Data Structure
8
5
  module OrderBook
@@ -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 Portfolio
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'logger'
4
-
5
3
  module Cryptum
6
4
  module UI
7
5
  # This plugin is used to Refresh the Cryptum Command Section UI
@@ -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 Refresh the Cryptum console UI
7
5
  module UI
@@ -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 Refresh the Cryptum console UI
7
5
  module UI