cryptum 0.0.382 → 0.0.384
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +5 -8
- data/lib/cryptum/api/exchange_rates.rb +0 -2
- data/lib/cryptum/api/orders.rb +2 -8
- data/lib/cryptum/api/portfolio.rb +0 -2
- data/lib/cryptum/api/rest.rb +3 -4
- data/lib/cryptum/api/signature.rb +0 -4
- data/lib/cryptum/api.rb +0 -6
- data/lib/cryptum/bot_conf.rb +0 -3
- data/lib/cryptum/event/buy.rb +11 -115
- data/lib/cryptum/event/exit.rb +1 -1
- data/lib/cryptum/event/order_book.rb +1 -1
- data/lib/cryptum/event/parse.rb +6 -6
- data/lib/cryptum/event/sell.rb +15 -96
- data/lib/cryptum/event.rb +0 -2
- data/lib/cryptum/log.rb +18 -4
- data/lib/cryptum/open_ai.rb +129 -32
- data/lib/cryptum/option/environment.rb +0 -2
- data/lib/cryptum/option/parser.rb +0 -2
- data/lib/cryptum/order_book/generate.rb +0 -4
- data/lib/cryptum/order_book.rb +0 -3
- data/lib/cryptum/portfolio.rb +0 -2
- data/lib/cryptum/ui/command.rb +0 -2
- data/lib/cryptum/ui/market_trend.rb +0 -2
- data/lib/cryptum/ui/matrix.rb +0 -2
- data/lib/cryptum/ui/order/execute.rb +627 -0
- data/lib/cryptum/ui/order/execute_details.rb +300 -0
- data/lib/cryptum/ui/order/plan.rb +518 -0
- data/lib/cryptum/ui/order/plan_details.rb +243 -0
- data/lib/cryptum/ui/order/timer.rb +140 -0
- data/lib/cryptum/ui/order.rb +21 -0
- data/lib/cryptum/ui/portfolio.rb +0 -2
- data/lib/cryptum/ui/signal_engine.rb +0 -2
- data/lib/cryptum/ui/terminal_window.rb +0 -2
- data/lib/cryptum/ui/ticker.rb +0 -2
- data/lib/cryptum/ui.rb +1 -8
- data/lib/cryptum/version.rb +1 -1
- data/lib/cryptum/web_sock/coinbase.rb +0 -5
- data/lib/cryptum/web_sock/event_machine.rb +2 -6
- data/lib/cryptum.rb +16 -2
- data/spec/lib/cryptum/ui/{order_execute_details_spec.rb → order/execute_details_spec.rb} +2 -2
- data/spec/lib/cryptum/ui/{order_execution_spec.rb → order/execute_spec.rb} +2 -2
- data/spec/lib/cryptum/ui/order/plan_details_spec.rb +10 -0
- data/spec/lib/cryptum/ui/{order_timer_spec.rb → order/plan_spec.rb} +2 -2
- data/spec/lib/cryptum/ui/{order_plan_details_spec.rb → order/timer_spec.rb} +2 -2
- data/spec/lib/cryptum/ui/{order_plan_spec.rb → order_spec.rb} +2 -2
- metadata +13 -11
- data/lib/cryptum/ui/order_execute_details.rb +0 -300
- data/lib/cryptum/ui/order_execution.rb +0 -629
- data/lib/cryptum/ui/order_plan.rb +0 -518
- data/lib/cryptum/ui/order_plan_details.rb +0 -243
- data/lib/cryptum/ui/order_timer.rb +0 -140
data/lib/cryptum/open_ai.rb
CHANGED
@@ -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
|
-
#
|
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
|
-
#
|
87
|
-
#
|
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
|
-
|
93
|
-
option_choice = opts[:option_choice]
|
87
|
+
token = opts[:token]
|
94
88
|
|
95
89
|
response = open_ai_rest_call(
|
96
|
-
|
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 =
|
109
|
-
#
|
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.
|
115
|
-
|
116
|
-
|
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
|
-
|
123
|
-
|
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
|
-
|
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
|
-
|
144
|
-
|
145
|
-
|
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}.
|
149
|
-
|
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
|
data/lib/cryptum/order_book.rb
CHANGED
data/lib/cryptum/portfolio.rb
CHANGED
data/lib/cryptum/ui/command.rb
CHANGED