cryptum 0.0.381 → 0.0.383

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 (59) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/.rubocop_todo.yml +11 -8
  4. data/Gemfile +1 -2
  5. data/bin/cryptum +2 -2
  6. data/lib/cryptum/api/exchange_rates.rb +0 -2
  7. data/lib/cryptum/api/orders.rb +9 -7
  8. data/lib/cryptum/api/portfolio.rb +0 -2
  9. data/lib/cryptum/api/rest.rb +3 -4
  10. data/lib/cryptum/api/signature.rb +0 -4
  11. data/lib/cryptum/api.rb +1 -40
  12. data/lib/cryptum/bot_conf.rb +14 -6
  13. data/lib/cryptum/event/exit.rb +1 -1
  14. data/lib/cryptum/event/history.rb +4 -1
  15. data/lib/cryptum/event/parse.rb +6 -6
  16. data/lib/cryptum/event.rb +0 -2
  17. data/lib/cryptum/log.rb +18 -4
  18. data/lib/cryptum/open_ai.rb +129 -32
  19. data/lib/cryptum/option/choice.rb +1 -1
  20. data/lib/cryptum/option/environment.rb +0 -2
  21. data/lib/cryptum/option/parser.rb +0 -2
  22. data/lib/cryptum/order_book/generate.rb +3 -8
  23. data/lib/cryptum/order_book.rb +0 -3
  24. data/lib/cryptum/portfolio.rb +0 -2
  25. data/lib/cryptum/ui/command.rb +1 -3
  26. data/lib/cryptum/ui/exit.rb +43 -0
  27. data/lib/cryptum/ui/key_press_event.rb +1 -1
  28. data/lib/cryptum/ui/market_trend.rb +4 -3
  29. data/lib/cryptum/ui/matrix.rb +185 -0
  30. data/lib/cryptum/ui/order/execute.rb +629 -0
  31. data/lib/cryptum/ui/order/execute_details.rb +300 -0
  32. data/lib/cryptum/ui/order/plan.rb +518 -0
  33. data/lib/cryptum/ui/order/plan_details.rb +243 -0
  34. data/lib/cryptum/ui/order/timer.rb +140 -0
  35. data/lib/cryptum/ui/order.rb +21 -0
  36. data/lib/cryptum/ui/portfolio.rb +5 -3
  37. data/lib/cryptum/ui/signal_engine.rb +1 -3
  38. data/lib/cryptum/ui/terminal_window.rb +1 -3
  39. data/lib/cryptum/ui/ticker.rb +4 -3
  40. data/lib/cryptum/ui.rb +17 -22
  41. data/lib/cryptum/version.rb +1 -1
  42. data/lib/cryptum/web_sock/coinbase.rb +1 -6
  43. data/lib/cryptum/web_sock/event_machine.rb +3 -7
  44. data/lib/cryptum.rb +16 -33
  45. data/spec/lib/cryptum/{matrix_spec.rb → ui/exit_spec.rb} +2 -2
  46. data/spec/lib/cryptum/ui/{order_plan_spec.rb → matrix_spec.rb} +2 -2
  47. data/spec/lib/cryptum/ui/{order_execute_details_spec.rb → order/execute_details_spec.rb} +2 -2
  48. data/spec/lib/cryptum/ui/{order_execution_spec.rb → order/execute_spec.rb} +2 -2
  49. data/spec/lib/cryptum/ui/{order_plan_details_spec.rb → order/plan_details_spec.rb} +2 -2
  50. data/spec/lib/cryptum/ui/order/plan_spec.rb +10 -0
  51. data/spec/lib/cryptum/ui/order/timer_spec.rb +10 -0
  52. data/spec/lib/cryptum/ui/{order_timer_spec.rb → order_spec.rb} +2 -2
  53. metadata +20 -30
  54. data/lib/cryptum/matrix.rb +0 -181
  55. data/lib/cryptum/ui/order_execute_details.rb +0 -297
  56. data/lib/cryptum/ui/order_execution.rb +0 -624
  57. data/lib/cryptum/ui/order_plan.rb +0 -514
  58. data/lib/cryptum/ui/order_plan_details.rb +0 -240
  59. data/lib/cryptum/ui/order_timer.rb +0 -136
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 866bb0c564c84fd84b9795396ffabf73483cea8c71171e3de935545c9a5a7736
4
- data.tar.gz: 060b3793c66b3a31d7747d5677de5f7b346d14ac00714357188239080a19bd5d
3
+ metadata.gz: 06a29115dd8895dca86ef8c6a0e8b506248dfdaa52c1a09b8d2625dd308a2b36
4
+ data.tar.gz: 41da5d973faa245b504288b2bee338b30ec50ed3b5688de053e6e588c28bb904
5
5
  SHA512:
6
- metadata.gz: 07c342bb8da387ff8fad07303102860758b5be1334d6558732255a2f743a607bb5a881968f1da1506bda887819d82cd6d5a473b19380f9641dac3b7d43c2ae81
7
- data.tar.gz: 928cd958349f76561e312529f3787d708924031ca6e73cec4c3314d59b639479d3c1997d70c6227e27360c66ceee038a5260ab61c3b4104f98fea7f764a50b1d
6
+ metadata.gz: b5f4925c93e418214bdc03923823224c124abee2acbb88ff6a8b29aba5d5072135bd2ee66639334eb6929edf94a0f4bd9b44c44d9bc7d00be5d4b2959e5f9e11
7
+ data.tar.gz: 671b415f45233e4719396ae939fbcd7cefa39ba04ef2d1a18024e5591d6aa8b98548fd6dfc443a961aabb164826381a1a9af0554ce1f009f79d06213486038d6
data/.rubocop.yml CHANGED
@@ -13,6 +13,8 @@ Metrics/BlockLength:
13
13
  Max: 256
14
14
  Metrics/BlockNesting:
15
15
  Max: 4
16
+ Metrics/ClassLength:
17
+ Max: 512
16
18
  Metrics/CyclomaticComplexity:
17
19
  Max: 128
18
20
  Metrics/MethodLength:
data/.rubocop_todo.yml CHANGED
@@ -1,26 +1,29 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2023-03-30 22:47:49 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
24
+
25
+ # Offense count: 1
26
+ # This cop supports safe autocorrection (--autocorrect).
27
+ Style/RedundantSelf:
28
+ Exclude:
29
+ - 'lib/cryptum/api.rb'
data/Gemfile CHANGED
@@ -32,7 +32,6 @@ gem 'rubocop-rspec', '2.19.0'
32
32
  gem 'ruby-prof', '1.6.1'
33
33
  gem 'rvm', '1.11.3.9'
34
34
  gem 'sinatra', '3.0.5'
35
- gem 'thin', '1.8.1'
35
+ gem 'thin', '1.8.2'
36
36
  gem 'tty-prompt', '0.23.1'
37
- gem 'tty-spinner', '0.9.3'
38
37
  gem 'websocket-extensions', '0.1.5'
data/bin/cryptum CHANGED
@@ -30,7 +30,7 @@ begin
30
30
  # Generate an Order Book for Session Tracking
31
31
  # Load previous order_book_justification from
32
32
  # Order Book File (if it exists)
33
- event_history = Cryptum::OrderBook::Generate.new_order_book(
33
+ event_history = Cryptum::OrderBook::Generate.new(
34
34
  start_time: start_time,
35
35
  option_choice: option_choice,
36
36
  env: env
@@ -61,7 +61,7 @@ begin
61
61
  )
62
62
  rescue Interrupt
63
63
  # Exit Gracefully if CTRL+C is Pressed During Session
64
- Cryptum.exit_gracefully(
64
+ Cryptum::UI::Exit.gracefully(
65
65
  which_self: self,
66
66
  event_history: event_history,
67
67
  option_choice: option_choice,
@@ -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
@@ -243,7 +237,15 @@ module Cryptum
243
237
 
244
238
  public_class_method def self.help
245
239
  puts "USAGE:
246
- profiles = #{self}.get_profiles(
240
+ event_history = #{self}.submit_limit_order(
241
+ env: 'required - Coinbase::Option::Environment.get Object'
242
+ )
243
+
244
+ canceled_order_id_arr = #{self}.cancel_all_open_orders(
245
+ env: 'required - Coinbase::Option::Environment.get Object'
246
+ )
247
+
248
+ event_history = #{self}.gtfo(
247
249
  env: 'required - Coinbase::Option::Environment.get Object'
248
250
  )
249
251
  "
@@ -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
@@ -18,41 +12,8 @@ module Cryptum
18
12
  require 'cryptum/api/rest'
19
13
  require 'cryptum/api/signature'
20
14
 
21
- # public_class_method def self.get_profiles(opts = {})
22
- # option_choice = opts[:option_choice]
23
- # env = opts[:env]
24
-
25
- # profiles_api_call = '/profiles'
26
-
27
- # # We don't always get fees back from Coinbase...
28
- # # This is a hack to ensure we do.
29
- # profiles = {}
30
- # # loop do
31
- # profiles = Cryptum::API::Rest.call(
32
- # option_choice: option_choice,
33
- # env: env,
34
- # http_method: :GET,
35
- # api_call: profiles_api_call
36
- # )
37
-
38
- # # break unless fees.empty?
39
-
40
- # # sleep 0.3
41
- # # end
42
-
43
- # profiles
44
- # rescue StandardError => e
45
- # raise e
46
- # end
47
-
48
- # Display Usage for this Module
49
-
50
15
  public_class_method def self.help
51
- puts "USAGE:
52
- profiles = #{self}.get_profiles(
53
- env: 'required - Coinbase::Option::Environment.get Object'
54
- )
55
- "
16
+ puts self.constants
56
17
  end
57
18
  end
58
19
  end
@@ -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
@@ -45,7 +43,11 @@ module Cryptum
45
43
  retry
46
44
  rescue Interrupt
47
45
  # Exit Gracefully if CTRL+C is Pressed During Session
48
- Cryptum.exit_gracefully(which_self: self)
46
+ Cryptum::UI::Exit.gracefully(
47
+ which_self: self,
48
+ event_history: event_history,
49
+ option_choice: option_choice
50
+ )
49
51
  rescue StandardError => e
50
52
  # Produce a Stacktrace for anything else
51
53
  Curses.close_screen
@@ -148,7 +150,11 @@ module Cryptum
148
150
  retry
149
151
  rescue Interrupt
150
152
  # Exit Gracefully if CTRL+C is Pressed During Session
151
- Cryptum.exit_gracefully(which_self: self)
153
+ Cryptum::UI::Exit.gracefully(
154
+ which_self: self,
155
+ event_history: event_history,
156
+ option_choice: option_choice
157
+ )
152
158
  rescue StandardError => e
153
159
  # Produce a Stacktrace for anything else
154
160
  Curses.close_screen
@@ -178,7 +184,10 @@ module Cryptum
178
184
  retry
179
185
  rescue Interrupt
180
186
  # Exit Gracefully if CTRL+C is Pressed During Session
181
- Cryptum.exit_gracefully(which_self: self)
187
+ Cryptum::UI::Exit.gracefully(
188
+ which_self: self,
189
+ option_choice: option_choice
190
+ )
182
191
  rescue StandardError => e
183
192
  # Produce a Stacktrace for anything else
184
193
  Curses.close_screen
@@ -189,7 +198,6 @@ module Cryptum
189
198
 
190
199
  public_class_method def self.help
191
200
  puts "USAGE:
192
- logger = #{self}.create()
193
201
  "
194
202
  end
195
203
  end
@@ -14,7 +14,7 @@ module Cryptum
14
14
  env = opts[:env]
15
15
 
16
16
  terminal_win.key_press_event.key_x = false
17
- Cryptum.exit_gracefully(
17
+ Cryptum::UI::Exit.gracefully(
18
18
  which_self: self,
19
19
  event_history: event_history,
20
20
  option_choice: option_choice,
@@ -195,7 +195,10 @@ module Cryptum
195
195
  end
196
196
  rescue Interrupt
197
197
  # Exit Gracefully if CTRL+C is Pressed During Session
198
- Cryptum.exit_gracefully(which_self: self)
198
+ Cryptum::UI::Exit.gracefully(
199
+ which_self: self,
200
+ option_choice: option_choice
201
+ )
199
202
  rescue StandardError => e
200
203
  # Produce a Stacktrace for anything else
201
204
  raise e
@@ -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,
@@ -152,7 +152,7 @@ module Cryptum
152
152
  event_history
153
153
  rescue Interrupt
154
154
  # Exit Gracefully if CTRL+C is Pressed During Session
155
- Cryptum.exit_gracefully(
155
+ Cryptum::UI::Exit.gracefully(
156
156
  which_self: self,
157
157
  event_history: event_history,
158
158
  option_choice: option_choice,
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
@@ -18,7 +18,7 @@ module Cryptum
18
18
 
19
19
  rescue Interrupt
20
20
  # Exit Gracefully if CTRL+C is Pressed During Session
21
- Cryptum.exit_gracefully(which_self: self)
21
+ Cryptum::UI::Exit.gracefully(which_self: self)
22
22
  rescue StandardError => e
23
23
  # Produce a Stacktrace for anything else
24
24
  Curses.close_screen
@@ -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,21 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'io/console'
4
- require 'json'
5
- require 'logger'
6
- require 'tty-spinner'
7
-
8
3
  module Cryptum
9
4
  # This module is used to define the Order Book Data Structure
10
5
  module OrderBook
11
6
  module Generate
12
7
  # Supported Method Parameters::
13
- # Cryptum::OrderBook.generate(
8
+ # Cryptum::OrderBook::Generate.new(
14
9
  # symbol: 'required - target symbol (e.g. btc-usd)',
15
10
  # this_product: 'required - this_product',
16
11
  # )
17
12
 
18
- public_class_method def self.new_order_book(opts = {})
13
+ public_class_method def self.new(opts = {})
19
14
  start_time = opts[:start_time]
20
15
  option_choice = opts[:option_choice]
21
16
  env = opts[:env]
@@ -103,7 +98,7 @@ module Cryptum
103
98
 
104
99
  public_class_method def self.help
105
100
  puts "USAGE:
106
- order_book = #{self}.new_order_book(
101
+ order_book = #{self}.new(
107
102
  symbol: 'required - target symbol (e.g. btc-usd)',
108
103
  this_product: 'required - this_product'
109
104
  )