cryptum 0.0.382 → 0.0.384

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 (52) 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 +2 -8
  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/buy.rb +11 -115
  11. data/lib/cryptum/event/exit.rb +1 -1
  12. data/lib/cryptum/event/order_book.rb +1 -1
  13. data/lib/cryptum/event/parse.rb +6 -6
  14. data/lib/cryptum/event/sell.rb +15 -96
  15. data/lib/cryptum/event.rb +0 -2
  16. data/lib/cryptum/log.rb +18 -4
  17. data/lib/cryptum/open_ai.rb +129 -32
  18. data/lib/cryptum/option/environment.rb +0 -2
  19. data/lib/cryptum/option/parser.rb +0 -2
  20. data/lib/cryptum/order_book/generate.rb +0 -4
  21. data/lib/cryptum/order_book.rb +0 -3
  22. data/lib/cryptum/portfolio.rb +0 -2
  23. data/lib/cryptum/ui/command.rb +0 -2
  24. data/lib/cryptum/ui/market_trend.rb +0 -2
  25. data/lib/cryptum/ui/matrix.rb +0 -2
  26. data/lib/cryptum/ui/order/execute.rb +627 -0
  27. data/lib/cryptum/ui/order/execute_details.rb +300 -0
  28. data/lib/cryptum/ui/order/plan.rb +518 -0
  29. data/lib/cryptum/ui/order/plan_details.rb +243 -0
  30. data/lib/cryptum/ui/order/timer.rb +140 -0
  31. data/lib/cryptum/ui/order.rb +21 -0
  32. data/lib/cryptum/ui/portfolio.rb +0 -2
  33. data/lib/cryptum/ui/signal_engine.rb +0 -2
  34. data/lib/cryptum/ui/terminal_window.rb +0 -2
  35. data/lib/cryptum/ui/ticker.rb +0 -2
  36. data/lib/cryptum/ui.rb +1 -8
  37. data/lib/cryptum/version.rb +1 -1
  38. data/lib/cryptum/web_sock/coinbase.rb +0 -5
  39. data/lib/cryptum/web_sock/event_machine.rb +2 -6
  40. data/lib/cryptum.rb +16 -2
  41. data/spec/lib/cryptum/ui/{order_execute_details_spec.rb → order/execute_details_spec.rb} +2 -2
  42. data/spec/lib/cryptum/ui/{order_execution_spec.rb → order/execute_spec.rb} +2 -2
  43. data/spec/lib/cryptum/ui/order/plan_details_spec.rb +10 -0
  44. data/spec/lib/cryptum/ui/{order_timer_spec.rb → order/plan_spec.rb} +2 -2
  45. data/spec/lib/cryptum/ui/{order_plan_details_spec.rb → order/timer_spec.rb} +2 -2
  46. data/spec/lib/cryptum/ui/{order_plan_spec.rb → order_spec.rb} +2 -2
  47. metadata +13 -11
  48. data/lib/cryptum/ui/order_execute_details.rb +0 -300
  49. data/lib/cryptum/ui/order_execution.rb +0 -629
  50. data/lib/cryptum/ui/order_plan.rb +0 -518
  51. data/lib/cryptum/ui/order_plan_details.rb +0 -243
  52. data/lib/cryptum/ui/order_timer.rb +0 -140
@@ -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