cryptum 0.0.358 → 0.0.360
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +16 -0
- data/.gitignore +30 -0
- data/.rspec +3 -0
- data/.rspec_status +0 -0
- data/.rubocop.yml +31 -0
- data/.rubocop_todo.yml +36 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +38 -0
- data/LICENSE +674 -0
- data/README.md +87 -0
- data/Rakefile +19 -0
- data/bin/cryptum +73 -0
- data/bin/cryptum-forecast +200 -0
- data/bin/cryptum-repl +73 -0
- data/bin/cryptum_autoinc_version +38 -0
- data/build_cryptum_gem.sh +58 -0
- data/cryptum.gemspec +52 -0
- data/cryptum_container.sh +1 -0
- data/docker/cryptum.json +60 -0
- data/docker/cryptum_container.sh +59 -0
- data/docker/packer_secrets.json.EXAMPLE +7 -0
- data/docker/provisioners/cryptum.sh +11 -0
- data/docker/provisioners/docker_bashrc.sh +2 -0
- data/docker/provisioners/docker_rvm.sh +22 -0
- data/docker/provisioners/init_image.sh +28 -0
- data/docker/provisioners/post_install.sh +6 -0
- data/docker/provisioners/ruby.sh +16 -0
- data/docker/provisioners/upload_globals.sh +49 -0
- data/etc/bot_confs/.gitkeep +0 -0
- data/etc/bot_confs/BOT_CONF.TEMPLATE +10 -0
- data/etc/coinbase_pro.yaml.EXAMPLE +8 -0
- data/etc/open_ai.yaml.EXAMPLE +1 -0
- data/git_commit.sh +22 -0
- data/lib/cryptum/api.rb +688 -0
- data/lib/cryptum/bot_conf.rb +197 -0
- data/lib/cryptum/event/bot_conf.rb +34 -0
- data/lib/cryptum/event/buy.rb +145 -0
- data/lib/cryptum/event/cancel.rb +35 -0
- data/lib/cryptum/event/exit.rb +35 -0
- data/lib/cryptum/event/gtfo.rb +36 -0
- data/lib/cryptum/event/history.rb +108 -0
- data/lib/cryptum/event/key_press.rb +64 -0
- data/lib/cryptum/event/order_book.rb +34 -0
- data/lib/cryptum/event/pane.rb +65 -0
- data/lib/cryptum/event/parse.rb +181 -0
- data/lib/cryptum/event/scroll.rb +200 -0
- data/lib/cryptum/event/sell.rb +124 -0
- data/lib/cryptum/event.rb +27 -0
- data/lib/cryptum/log.rb +34 -0
- data/lib/cryptum/matrix.rb +181 -0
- data/lib/cryptum/open_ai.rb +156 -0
- data/lib/cryptum/option/choice.rb +28 -0
- data/lib/cryptum/option.rb +206 -0
- data/lib/cryptum/order_book/generate.rb +114 -0
- data/lib/cryptum/order_book/indicator.rb +15 -0
- data/lib/cryptum/order_book/market_trend.rb +137 -0
- data/lib/cryptum/order_book/profit_margin.rb +55 -0
- data/lib/cryptum/order_book.rb +19 -0
- data/lib/cryptum/portfolio/balance.rb +123 -0
- data/lib/cryptum/portfolio.rb +15 -0
- data/lib/cryptum/ui/command.rb +314 -0
- data/lib/cryptum/ui/key_press_event.rb +33 -0
- data/lib/cryptum/ui/market_trend.rb +77 -0
- data/lib/cryptum/ui/order_execute_details.rb +297 -0
- data/lib/cryptum/ui/order_execution.rb +573 -0
- data/lib/cryptum/ui/order_plan.rb +512 -0
- data/lib/cryptum/ui/order_plan_details.rb +240 -0
- data/lib/cryptum/ui/order_timer.rb +136 -0
- data/lib/cryptum/ui/portfolio.rb +221 -0
- data/lib/cryptum/ui/signal_engine.rb +109 -0
- data/lib/cryptum/ui/terminal_window.rb +111 -0
- data/lib/cryptum/ui/ticker.rb +319 -0
- data/lib/cryptum/ui.rb +343 -0
- data/lib/cryptum/version.rb +5 -0
- data/lib/cryptum/web_sock/coinbase.rb +104 -0
- data/lib/cryptum/web_sock/event_machine.rb +276 -0
- data/lib/cryptum/web_sock.rb +16 -0
- data/lib/cryptum.rb +120 -0
- data/order_books/.gitkeep +0 -0
- data/reinstall_cryptum_gemset.sh +29 -0
- data/spec/lib/cryptum/api_spec.rb +10 -0
- data/spec/lib/cryptum/event_spec.rb +10 -0
- data/spec/lib/cryptum/log_spec.rb +10 -0
- data/spec/lib/cryptum/option_spec.rb +10 -0
- data/spec/lib/cryptum/order_book/generate_spec.rb +10 -0
- data/spec/lib/cryptum/order_book/market_trend_spec.rb +10 -0
- data/spec/lib/cryptum/order_book_spec.rb +10 -0
- data/spec/lib/cryptum/ui/command_spec.rb +10 -0
- data/spec/lib/cryptum/ui/ticker_spec.rb +10 -0
- data/spec/lib/cryptum/ui_spec.rb +10 -0
- data/spec/lib/cryptum/web_sock_spec.rb +10 -0
- data/spec/lib/cryptum_spec.rb +10 -0
- data/spec/spec_helper.rb +3 -0
- data/upgrade_Gemfile_gems.sh +20 -0
- data/upgrade_cryptum.sh +13 -0
- data/upgrade_gem.sh +4 -0
- data/upgrade_ruby.sh +45 -0
- metadata +112 -9
@@ -0,0 +1,240 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
module Cryptum
|
6
|
+
module UI
|
7
|
+
# This plugin is used to Display Order Plan Details
|
8
|
+
# selected from the Order Plan Window Pane.
|
9
|
+
module OrderPlanDetails
|
10
|
+
# Supported Method Parameters::
|
11
|
+
# Cryptum::UI::OrderPlanDetails.refresh(
|
12
|
+
# )
|
13
|
+
|
14
|
+
public_class_method def self.refresh(opts = {})
|
15
|
+
event_history = opts[:event_history]
|
16
|
+
order_plan_details_win = opts[:order_plan_details_win]
|
17
|
+
|
18
|
+
order = event_history.order_plan_selected_data
|
19
|
+
tpm = order[:tpm]
|
20
|
+
autotrade_percent = order[:autotrade_percent]
|
21
|
+
order_color = order[:color]
|
22
|
+
|
23
|
+
fiat_avail_out = Cryptum.beautify_large_number(
|
24
|
+
value: order[:fiat_available]
|
25
|
+
)
|
26
|
+
risk_alloc_out = Cryptum.beautify_large_number(
|
27
|
+
value: order[:risk_alloc]
|
28
|
+
)
|
29
|
+
slice_alloc_out = Cryptum.beautify_large_number(
|
30
|
+
value: order[:slice_alloc]
|
31
|
+
)
|
32
|
+
previous_slice_invest_out = Cryptum.beautify_large_number(
|
33
|
+
value: order[:previous_slice_invest]
|
34
|
+
)
|
35
|
+
invest_out = Cryptum.beautify_large_number(
|
36
|
+
value: order[:invest]
|
37
|
+
)
|
38
|
+
profit_out = Cryptum.beautify_large_number(
|
39
|
+
value: order[:profit]
|
40
|
+
)
|
41
|
+
tpm_out = format('%0.2f', tpm)
|
42
|
+
return_out = Cryptum.beautify_large_number(
|
43
|
+
value: order[:return]
|
44
|
+
)
|
45
|
+
autotrade_ln1_details = "1. Autotrade is set to #{autotrade_percent}% of $#{fiat_avail_out}, making $#{risk_alloc_out} available for this slice in"
|
46
|
+
autotrade_ln2_details = ' the order plan.'
|
47
|
+
if order[:last_slice]
|
48
|
+
slice_alloc_ln1_details = "2. Since $#{risk_alloc_out} is the remaining amount within the criteria defined in the Autotrade % above,"
|
49
|
+
slice_alloc_ln2_details = " $#{invest_out} will be allocated for this slice."
|
50
|
+
else
|
51
|
+
slice_alloc_ln1_details = "2. With $#{risk_alloc_out} available and a slice allocation of #{order[:allocation_percent]}%, $#{slice_alloc_out} plus the previous"
|
52
|
+
slice_alloc_ln2_details = " slice of $#{previous_slice_invest_out} results in $#{invest_out} being allocated for this slice."
|
53
|
+
end
|
54
|
+
profit_ln1_details = "3. With a slice allocation of $#{invest_out}, plus a TPM equal to #{tpm_out}%, $#{return_out} will be returned"
|
55
|
+
profit_ln2_details = " once sold. With $#{invest_out} invested, the gross profit equals $#{profit_out}, minus any Maker &"
|
56
|
+
profit_ln3_details = ' Taker (transaction) fees.'
|
57
|
+
|
58
|
+
# UI
|
59
|
+
col_just1 = (Curses.cols - Cryptum::UI.col_first) - 1
|
60
|
+
|
61
|
+
# ROW 1
|
62
|
+
out_line_no = 0
|
63
|
+
line_color = order_color
|
64
|
+
header_color = order_color
|
65
|
+
header_style = :bold
|
66
|
+
style = :bold
|
67
|
+
header_style = :reverse if event_history.order_plan_details_win_active
|
68
|
+
|
69
|
+
Cryptum::UI.line(
|
70
|
+
ui_win: order_plan_details_win,
|
71
|
+
out_line_no: out_line_no,
|
72
|
+
color: line_color
|
73
|
+
)
|
74
|
+
|
75
|
+
# ROW 2
|
76
|
+
out_line_no += 1
|
77
|
+
order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first)
|
78
|
+
order_plan_details_win.clrtoeol
|
79
|
+
Cryptum::UI.colorize(
|
80
|
+
ui_win: order_plan_details_win,
|
81
|
+
color: header_color,
|
82
|
+
style: header_style,
|
83
|
+
string: ''.ljust(col_just1, ' ')
|
84
|
+
)
|
85
|
+
|
86
|
+
header_str = "- ORDER SLICE ##{order[:plan_no]} DETAILS -"
|
87
|
+
order_plan_details_win.setpos(
|
88
|
+
out_line_no,
|
89
|
+
Cryptum::UI.col_center(str: header_str)
|
90
|
+
)
|
91
|
+
|
92
|
+
Cryptum::UI.colorize(
|
93
|
+
ui_win: order_plan_details_win,
|
94
|
+
color: order_color,
|
95
|
+
style: header_style,
|
96
|
+
string: header_str
|
97
|
+
)
|
98
|
+
|
99
|
+
# ROW 3
|
100
|
+
out_line_no += 1
|
101
|
+
order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first)
|
102
|
+
order_plan_details_win.clrtoeol
|
103
|
+
|
104
|
+
Cryptum::UI.colorize(
|
105
|
+
ui_win: order_plan_details_win,
|
106
|
+
color: order_color,
|
107
|
+
style: style,
|
108
|
+
string: autotrade_ln1_details.ljust(col_just1, ' ')
|
109
|
+
)
|
110
|
+
|
111
|
+
# ROW 4
|
112
|
+
out_line_no += 1
|
113
|
+
order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first)
|
114
|
+
order_plan_details_win.clrtoeol
|
115
|
+
|
116
|
+
Cryptum::UI.colorize(
|
117
|
+
ui_win: order_plan_details_win,
|
118
|
+
color: order_color,
|
119
|
+
style: style,
|
120
|
+
string: autotrade_ln2_details.ljust(col_just1, ' ')
|
121
|
+
)
|
122
|
+
|
123
|
+
# ROW 5
|
124
|
+
out_line_no += 1
|
125
|
+
order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first)
|
126
|
+
order_plan_details_win.clrtoeol
|
127
|
+
|
128
|
+
Cryptum::UI.colorize(
|
129
|
+
ui_win: order_plan_details_win,
|
130
|
+
color: order_color,
|
131
|
+
style: style,
|
132
|
+
string: slice_alloc_ln1_details.ljust(col_just1, ' ')
|
133
|
+
)
|
134
|
+
|
135
|
+
# ROW 6
|
136
|
+
out_line_no += 1
|
137
|
+
order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first)
|
138
|
+
order_plan_details_win.clrtoeol
|
139
|
+
|
140
|
+
Cryptum::UI.colorize(
|
141
|
+
ui_win: order_plan_details_win,
|
142
|
+
color: order_color,
|
143
|
+
style: style,
|
144
|
+
string: slice_alloc_ln2_details.ljust(col_just1, ' ')
|
145
|
+
)
|
146
|
+
|
147
|
+
# ROW 7
|
148
|
+
out_line_no += 1
|
149
|
+
order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first)
|
150
|
+
order_plan_details_win.clrtoeol
|
151
|
+
|
152
|
+
Cryptum::UI.colorize(
|
153
|
+
ui_win: order_plan_details_win,
|
154
|
+
color: order_color,
|
155
|
+
style: style,
|
156
|
+
string: profit_ln1_details.ljust(col_just1, ' ')
|
157
|
+
)
|
158
|
+
|
159
|
+
# ROW 8
|
160
|
+
out_line_no += 1
|
161
|
+
order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first)
|
162
|
+
order_plan_details_win.clrtoeol
|
163
|
+
|
164
|
+
Cryptum::UI.colorize(
|
165
|
+
ui_win: order_plan_details_win,
|
166
|
+
color: order_color,
|
167
|
+
style: style,
|
168
|
+
string: profit_ln2_details.ljust(col_just1, ' ')
|
169
|
+
)
|
170
|
+
|
171
|
+
# ROW 9
|
172
|
+
out_line_no += 1
|
173
|
+
order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first)
|
174
|
+
order_plan_details_win.clrtoeol
|
175
|
+
|
176
|
+
Cryptum::UI.colorize(
|
177
|
+
ui_win: order_plan_details_win,
|
178
|
+
color: order_color,
|
179
|
+
style: style,
|
180
|
+
string: profit_ln3_details.ljust(col_just1, ' ')
|
181
|
+
)
|
182
|
+
|
183
|
+
# Clear to OK ROW
|
184
|
+
ok_row = 9
|
185
|
+
out_line_no += 1
|
186
|
+
to_ok_row = ok_row - 1
|
187
|
+
(out_line_no..to_ok_row).each do |clr_line|
|
188
|
+
order_plan_details_win.setpos(clr_line, Cryptum::UI.col_first)
|
189
|
+
Cryptum::UI.colorize(
|
190
|
+
ui_win: order_plan_details_win,
|
191
|
+
color: order_color,
|
192
|
+
style: :normal,
|
193
|
+
string: ''.ljust(col_just1, ' ')
|
194
|
+
)
|
195
|
+
end
|
196
|
+
|
197
|
+
# OK ROW
|
198
|
+
out_line_no = ok_row
|
199
|
+
order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first)
|
200
|
+
order_plan_details_win.clrtoeol
|
201
|
+
Cryptum::UI.colorize(
|
202
|
+
ui_win: order_plan_details_win,
|
203
|
+
color: order_color,
|
204
|
+
string: ''.ljust(col_just1, ' ')
|
205
|
+
)
|
206
|
+
|
207
|
+
header_str = '- OK -'
|
208
|
+
order_plan_details_win.setpos(
|
209
|
+
out_line_no,
|
210
|
+
Cryptum::UI.col_center(str: header_str)
|
211
|
+
)
|
212
|
+
|
213
|
+
Cryptum::UI.colorize(
|
214
|
+
ui_win: order_plan_details_win,
|
215
|
+
color: order_color,
|
216
|
+
style: :reverse,
|
217
|
+
string: header_str
|
218
|
+
)
|
219
|
+
|
220
|
+
order_plan_details_win.refresh
|
221
|
+
|
222
|
+
event_history
|
223
|
+
rescue Interrupt
|
224
|
+
# Exit Gracefully if CTRL+C is Pressed During Session
|
225
|
+
Cryptum.exit_gracefully(which_self: self)
|
226
|
+
rescue StandardError => e
|
227
|
+
raise e
|
228
|
+
end
|
229
|
+
|
230
|
+
# Display Usage for this Module
|
231
|
+
|
232
|
+
public_class_method def self.help
|
233
|
+
puts "USAGE:
|
234
|
+
#{self}.refresh(
|
235
|
+
)
|
236
|
+
"
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
module Cryptum
|
6
|
+
module UI
|
7
|
+
# This plugin is used to Refresh the Cryptum Status Section UI
|
8
|
+
module OrderTimer
|
9
|
+
# Supported Method Parameters::
|
10
|
+
# Cryptum::UI::Timer.refresh(
|
11
|
+
# )
|
12
|
+
|
13
|
+
public_class_method def self.refresh(opts = {})
|
14
|
+
option_choice = opts[:option_choice]
|
15
|
+
event_history = opts[:event_history]
|
16
|
+
order_timer_win = opts[:order_timer_win]
|
17
|
+
indicator_status = opts[:indicator_status]
|
18
|
+
|
19
|
+
last_trend_reset_time = event_history.order_book[:last_trend_reset]
|
20
|
+
last_order_exec_time = event_history.order_book[:last_order_exec]
|
21
|
+
|
22
|
+
# Market Trend Reset Timer
|
23
|
+
time_between_trend_reset = option_choice.market_trend_reset
|
24
|
+
trend_timer_begin = Time.parse(last_trend_reset_time)
|
25
|
+
trend_timer_end = trend_timer_begin + time_between_trend_reset
|
26
|
+
trend_time_remaining = trend_timer_end - Time.now
|
27
|
+
|
28
|
+
if trend_time_remaining.zero? || trend_time_remaining.negative?
|
29
|
+
event_history.order_book[:market_trend][:buy] = 0
|
30
|
+
event_history.order_book[:market_trend][:sell] = 0
|
31
|
+
event_history.order_book[:last_trend_reset] = Time.now.strftime(
|
32
|
+
'%Y-%m-%d %H:%M:%S.%N%z'
|
33
|
+
)
|
34
|
+
|
35
|
+
last_trend_reset_time = event_history.order_book[:last_trend_reset]
|
36
|
+
time_between_trend_reset = option_choice.market_trend_reset
|
37
|
+
trend_timer_begin = Time.parse(last_trend_reset_time)
|
38
|
+
trend_timer_end = trend_timer_begin + time_between_trend_reset
|
39
|
+
trend_time_remaining = trend_timer_end - Time.now
|
40
|
+
end
|
41
|
+
|
42
|
+
trend_countdown = Cryptum.beautify_large_number(
|
43
|
+
value: format('%0.2f', trend_time_remaining)
|
44
|
+
)
|
45
|
+
|
46
|
+
# Market Trend Reset Timer
|
47
|
+
time_between_order_exec = event_history.time_between_orders
|
48
|
+
time_between_order_exec_out = Cryptum.beautify_large_number(
|
49
|
+
value: format('%0.2f', time_between_order_exec)
|
50
|
+
)
|
51
|
+
order_begin_time = Time.parse(last_order_exec_time)
|
52
|
+
order_end_time = order_begin_time + time_between_order_exec
|
53
|
+
order_exec_time_remaining = order_end_time - Time.now
|
54
|
+
order_countdown = Cryptum.beautify_large_number(
|
55
|
+
value: format('%0.2f', order_exec_time_remaining)
|
56
|
+
)
|
57
|
+
|
58
|
+
buy_total = event_history.order_book[:market_trend][:buy].to_i
|
59
|
+
sell_total = event_history.order_book[:market_trend][:sell].to_i
|
60
|
+
|
61
|
+
color = :white
|
62
|
+
color = indicator_status.market_trend[:color] if indicator_status.market_trend
|
63
|
+
case color
|
64
|
+
when :green
|
65
|
+
# TODO: add condition to check if open sell orders exist.
|
66
|
+
# If so intent should be something like, "- SEE ORDER HISTORY -"
|
67
|
+
# Otherwise, intent should be something like, "- WAIT FOR MARKET TREND SHIFT -"
|
68
|
+
intent = "- SEE ORDER HISTORY #{Cryptum.down_arrow} -"
|
69
|
+
else
|
70
|
+
speed = 'FAST'
|
71
|
+
speed = 'SLOW' if buy_total >= sell_total
|
72
|
+
|
73
|
+
intent = "- #{speed} BUY: #{order_countdown} of #{time_between_order_exec_out} -"
|
74
|
+
intent = '- BUYING PAUSED -' if event_history.red_pill
|
75
|
+
end
|
76
|
+
|
77
|
+
# Have a Clock
|
78
|
+
clock = Time.now.strftime('%Y-%m-%d %H:%M:%S%z')
|
79
|
+
|
80
|
+
# UI
|
81
|
+
col_just4 = (Curses.cols - Cryptum::UI.col_fourth) - 1
|
82
|
+
|
83
|
+
# ROW 1
|
84
|
+
# COLUMN 1
|
85
|
+
out_line_no = 0
|
86
|
+
order_timer_win.setpos(out_line_no, Cryptum::UI.col_first)
|
87
|
+
order_timer_win.clrtoeol
|
88
|
+
Cryptum::UI.colorize(
|
89
|
+
ui_win: order_timer_win,
|
90
|
+
color: :white,
|
91
|
+
style: :bold,
|
92
|
+
string: "#{option_choice.market_trend_reset_label} M. Trend Rst: #{trend_countdown}"
|
93
|
+
)
|
94
|
+
|
95
|
+
# COLUMN 2
|
96
|
+
order_timer_win.setpos(
|
97
|
+
out_line_no,
|
98
|
+
Cryptum::UI.col_center(str: intent)
|
99
|
+
)
|
100
|
+
Cryptum::UI.colorize(
|
101
|
+
ui_win: order_timer_win,
|
102
|
+
color: :white,
|
103
|
+
style: :bold,
|
104
|
+
string: intent
|
105
|
+
)
|
106
|
+
|
107
|
+
# COLUMN 3
|
108
|
+
order_timer_win.setpos(out_line_no, Cryptum::UI.col_fourth)
|
109
|
+
Cryptum::UI.colorize(
|
110
|
+
ui_win: order_timer_win,
|
111
|
+
color: :white,
|
112
|
+
style: :bold,
|
113
|
+
string: clock.rjust(col_just4)
|
114
|
+
)
|
115
|
+
|
116
|
+
order_timer_win.refresh
|
117
|
+
|
118
|
+
order_countdown.to_f
|
119
|
+
rescue Interrupt
|
120
|
+
# Exit Gracefully if CTRL+C is Pressed During Session
|
121
|
+
Cryptum.exit_gracefully(which_self: self)
|
122
|
+
rescue StandardError => e
|
123
|
+
raise e
|
124
|
+
end
|
125
|
+
|
126
|
+
# Display Usage for this Module
|
127
|
+
|
128
|
+
public_class_method def self.help
|
129
|
+
puts "USAGE:
|
130
|
+
#{self}.refresh(
|
131
|
+
)
|
132
|
+
"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,221 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
module Cryptum
|
6
|
+
# This plugin is used to Refresh the Cryptum console UI
|
7
|
+
module UI
|
8
|
+
module Portfolio
|
9
|
+
# Supported Method Parameters::
|
10
|
+
# Cryptum::UI::Candle.refresh(
|
11
|
+
# order_book: 'required - Order Book Data Structure',
|
12
|
+
# event: 'required - Event from Coinbase Web Socket'
|
13
|
+
# )
|
14
|
+
|
15
|
+
public_class_method def self.refresh(opts = {})
|
16
|
+
option_choice = opts[:option_choice]
|
17
|
+
portfolio_win = opts[:portfolio_win]
|
18
|
+
event_history = opts[:event_history]
|
19
|
+
bot_conf = opts[:bot_conf]
|
20
|
+
|
21
|
+
ticker_price = event_history.order_book[:ticker_price].to_f
|
22
|
+
this_product = event_history.order_book[:this_product]
|
23
|
+
symbol_out = this_product[:id]
|
24
|
+
base_increment = this_product[:base_increment]
|
25
|
+
|
26
|
+
crypto_smallest_decimal = base_increment.to_s.split('.')[-1].length
|
27
|
+
|
28
|
+
autotrade_percent = format(
|
29
|
+
'%0.2f',
|
30
|
+
bot_conf[:autotrade_portfolio_percent].to_f
|
31
|
+
)
|
32
|
+
|
33
|
+
tpm = format(
|
34
|
+
'%0.2f',
|
35
|
+
bot_conf[:target_profit_margin_percent]
|
36
|
+
)
|
37
|
+
|
38
|
+
crypto_currency = option_choice.symbol.to_s.upcase.split('_').first.to_sym
|
39
|
+
portfolio = event_history.order_book[:portfolio]
|
40
|
+
this_account = portfolio.select do |account|
|
41
|
+
account[:currency] == crypto_currency.to_s
|
42
|
+
end
|
43
|
+
raise "ID for Crypto Currency, #{crypto_currency} Not Found" if this_account.empty?
|
44
|
+
|
45
|
+
balance = format("%0.#{crypto_smallest_decimal}f", this_account.first[:balance])
|
46
|
+
balance_out = Cryptum.beautify_large_number(
|
47
|
+
value: balance
|
48
|
+
)
|
49
|
+
avail_for_trade = format("%0.#{crypto_smallest_decimal}f", this_account.first[:available])
|
50
|
+
avail_for_trade_out = Cryptum.beautify_large_number(
|
51
|
+
value: avail_for_trade
|
52
|
+
)
|
53
|
+
|
54
|
+
fiat_portfolio = event_history.order_book[:fiat_portfolio]
|
55
|
+
fiat = option_choice.symbol.to_s.upcase.split('_').last.to_sym
|
56
|
+
total_holdings = format('%0.2f', fiat_portfolio.first[:total_holdings])
|
57
|
+
total_holdings_out = Cryptum.beautify_large_number(
|
58
|
+
value: total_holdings
|
59
|
+
)
|
60
|
+
fiat_balance = format('%0.2f', fiat_portfolio.first[:balance])
|
61
|
+
fiat_balance_out = Cryptum.beautify_large_number(
|
62
|
+
value: fiat_balance
|
63
|
+
)
|
64
|
+
fiat_avail_for_trade = format('%0.2f', fiat_portfolio.first[:available])
|
65
|
+
fiat_avail_for_trade_out = Cryptum.beautify_large_number(
|
66
|
+
value: fiat_avail_for_trade
|
67
|
+
)
|
68
|
+
|
69
|
+
fees = event_history.order_book[:fees]
|
70
|
+
maker_fee = format('%0.2f', fees[:maker_fee_rate].to_f * 100)
|
71
|
+
taker_fee = format('%0.2f', fees[:taker_fee_rate].to_f * 100)
|
72
|
+
volume_tier = format('%0.2f', fees[:usd_volume].to_f)
|
73
|
+
volume_tier_out = Cryptum.beautify_large_number(
|
74
|
+
value: volume_tier
|
75
|
+
)
|
76
|
+
|
77
|
+
current_crypto_fiat_value = format(
|
78
|
+
'%0.2f',
|
79
|
+
balance.to_f * ticker_price
|
80
|
+
)
|
81
|
+
current_crypto_fiat_value_out = Cryptum.beautify_large_number(
|
82
|
+
value: current_crypto_fiat_value
|
83
|
+
)
|
84
|
+
|
85
|
+
fiat_budget = fiat_avail_for_trade.to_f
|
86
|
+
current_fiat_invested_percent = format(
|
87
|
+
'%0.2f',
|
88
|
+
(1 - (fiat_budget / total_holdings.to_f)) * 100
|
89
|
+
)
|
90
|
+
|
91
|
+
crypto_invested_percent = format(
|
92
|
+
'%0.2f',
|
93
|
+
current_crypto_fiat_value.to_f.fdiv(total_holdings.to_f) * 100
|
94
|
+
)
|
95
|
+
# TODO: Everything Above this Line Needs to be Indicators ^
|
96
|
+
|
97
|
+
# UI
|
98
|
+
col_just3 = (Curses.cols - Cryptum::UI.col_third) - 1
|
99
|
+
|
100
|
+
# ROW 1
|
101
|
+
out_line_no = 0
|
102
|
+
Cryptum::UI.line(
|
103
|
+
ui_win: portfolio_win,
|
104
|
+
out_line_no: out_line_no
|
105
|
+
)
|
106
|
+
|
107
|
+
# ROW 2
|
108
|
+
out_line_no += 1
|
109
|
+
portfolio_win.setpos(out_line_no, Cryptum::UI.col_first)
|
110
|
+
portfolio_win.clrtoeol
|
111
|
+
Cryptum::UI.colorize(
|
112
|
+
ui_win: portfolio_win,
|
113
|
+
color: :white,
|
114
|
+
style: :bold,
|
115
|
+
string: "Portfolio | % Tied Up | % #{symbol_out}:"
|
116
|
+
)
|
117
|
+
|
118
|
+
portfolio_win.setpos(out_line_no, Cryptum::UI.col_third)
|
119
|
+
Cryptum::UI.colorize(
|
120
|
+
ui_win: portfolio_win,
|
121
|
+
color: :white,
|
122
|
+
string: "$#{total_holdings_out} | #{current_fiat_invested_percent}% | #{crypto_invested_percent}%".rjust(col_just3, '.')
|
123
|
+
)
|
124
|
+
|
125
|
+
# ROW 3
|
126
|
+
out_line_no += 1
|
127
|
+
portfolio_win.setpos(out_line_no, Cryptum::UI.col_first)
|
128
|
+
portfolio_win.clrtoeol
|
129
|
+
Cryptum::UI.colorize(
|
130
|
+
ui_win: portfolio_win,
|
131
|
+
color: :cyan,
|
132
|
+
string: 'TPM % | Autotrade %:'
|
133
|
+
)
|
134
|
+
|
135
|
+
portfolio_win.setpos(out_line_no, Cryptum::UI.col_third)
|
136
|
+
Cryptum::UI.colorize(
|
137
|
+
ui_win: portfolio_win,
|
138
|
+
color: :cyan,
|
139
|
+
string: "#{tpm}% | #{autotrade_percent}%".rjust(col_just3, '.')
|
140
|
+
)
|
141
|
+
|
142
|
+
# ROW 4
|
143
|
+
out_line_no += 1
|
144
|
+
portfolio_win.setpos(out_line_no, Cryptum::UI.col_first)
|
145
|
+
portfolio_win.clrtoeol
|
146
|
+
Cryptum::UI.colorize(
|
147
|
+
ui_win: portfolio_win,
|
148
|
+
color: :green,
|
149
|
+
style: :bold,
|
150
|
+
string: "#{fiat} Bal | Tradeable:"
|
151
|
+
)
|
152
|
+
|
153
|
+
portfolio_win.setpos(out_line_no, Cryptum::UI.col_third)
|
154
|
+
Cryptum::UI.colorize(
|
155
|
+
ui_win: portfolio_win,
|
156
|
+
color: :green,
|
157
|
+
string: "$#{fiat_balance_out} | $#{fiat_avail_for_trade_out}".rjust(
|
158
|
+
col_just3,
|
159
|
+
'.'
|
160
|
+
)
|
161
|
+
)
|
162
|
+
|
163
|
+
# ROW 5
|
164
|
+
out_line_no += 1
|
165
|
+
portfolio_win.setpos(out_line_no, Cryptum::UI.col_first)
|
166
|
+
portfolio_win.clrtoeol
|
167
|
+
Cryptum::UI.colorize(
|
168
|
+
ui_win: portfolio_win,
|
169
|
+
color: :yellow,
|
170
|
+
style: :bold,
|
171
|
+
string: 'Crypto Val | Bal | Tradeable:'
|
172
|
+
)
|
173
|
+
|
174
|
+
portfolio_win.setpos(out_line_no, Cryptum::UI.col_third)
|
175
|
+
Cryptum::UI.colorize(
|
176
|
+
ui_win: portfolio_win,
|
177
|
+
color: :yellow,
|
178
|
+
string: "$#{current_crypto_fiat_value_out} | *#{balance_out} | *#{avail_for_trade_out}".rjust(col_just3, '.')
|
179
|
+
)
|
180
|
+
|
181
|
+
# ROW 6
|
182
|
+
out_line_no += 1
|
183
|
+
portfolio_win.setpos(out_line_no, Cryptum::UI.col_first)
|
184
|
+
portfolio_win.clrtoeol
|
185
|
+
Cryptum::UI.colorize(
|
186
|
+
ui_win: portfolio_win,
|
187
|
+
color: :red,
|
188
|
+
style: :bold,
|
189
|
+
string: 'Maker & Taker Fees | My Volume:'
|
190
|
+
)
|
191
|
+
|
192
|
+
portfolio_win.setpos(out_line_no, Cryptum::UI.col_third)
|
193
|
+
Cryptum::UI.colorize(
|
194
|
+
ui_win: portfolio_win,
|
195
|
+
color: :red,
|
196
|
+
string: "#{maker_fee}% & #{taker_fee}% | $#{volume_tier_out}".rjust(col_just3, '.')
|
197
|
+
)
|
198
|
+
|
199
|
+
portfolio_win.refresh
|
200
|
+
|
201
|
+
event_history
|
202
|
+
rescue Interrupt
|
203
|
+
# Exit Gracefully if CTRL+C is Pressed During Session
|
204
|
+
Cryptum.exit_gracefully(which_self: self)
|
205
|
+
rescue StandardError => e
|
206
|
+
raise e
|
207
|
+
end
|
208
|
+
|
209
|
+
# Display Usage for this Module
|
210
|
+
|
211
|
+
public_class_method def self.help
|
212
|
+
puts "USAGE:
|
213
|
+
#{self}.refresh(
|
214
|
+
order_book: 'required - Order Book Data Structure',
|
215
|
+
event: 'required - Event from Coinbase Web Socket'
|
216
|
+
)
|
217
|
+
"
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
module Cryptum
|
6
|
+
# This plugin is used to Refresh the Cryptum console UI
|
7
|
+
module UI
|
8
|
+
module SignalEngine
|
9
|
+
# Supported Method Parameters::
|
10
|
+
# Cryptum::UI::Candle.refresh(
|
11
|
+
# order_book: 'required - Order Book Data Structure',
|
12
|
+
# event: 'required - Event from Coinbase Web Socket'
|
13
|
+
# )
|
14
|
+
|
15
|
+
public_class_method def self.refresh(opts = {})
|
16
|
+
signal_engine_win = opts[:signal_engine_win]
|
17
|
+
indicator_status = opts[:indicator_status]
|
18
|
+
|
19
|
+
color = :white
|
20
|
+
color = indicator_status.market_trend[:color] if indicator_status.market_trend
|
21
|
+
|
22
|
+
indicator_status.last_action_signal = indicator_status.action_signal
|
23
|
+
|
24
|
+
case color
|
25
|
+
when :green
|
26
|
+
signal_color = :green
|
27
|
+
action_signal = :sell
|
28
|
+
when :yellow
|
29
|
+
signal_color = :yellow
|
30
|
+
action_signal = :hold
|
31
|
+
when :red
|
32
|
+
signal_color = :cyan
|
33
|
+
action_signal = :buy
|
34
|
+
else
|
35
|
+
signal_color = :white
|
36
|
+
action_signal = :skip
|
37
|
+
end
|
38
|
+
|
39
|
+
action_signal_out = "SIGNAL >>> #{action_signal.to_s.upcase} <<< ENGINE"
|
40
|
+
# TODO: Everything Above this Line Needs to be Indicators ^
|
41
|
+
|
42
|
+
# UI
|
43
|
+
col_just1 = (Curses.cols - Cryptum::UI.col_first) - 1
|
44
|
+
col_just4 = Curses.cols - Cryptum::UI.col_fourth
|
45
|
+
|
46
|
+
# ROW 1
|
47
|
+
out_line_no = 0
|
48
|
+
Cryptum::UI.line(
|
49
|
+
ui_win: signal_engine_win,
|
50
|
+
out_line_no: out_line_no
|
51
|
+
)
|
52
|
+
|
53
|
+
# ROW 2
|
54
|
+
out_line_no += 1
|
55
|
+
signal_engine_win.setpos(out_line_no, Cryptum::UI.col_first)
|
56
|
+
signal_engine_win.clrtoeol
|
57
|
+
|
58
|
+
Cryptum::UI.colorize(
|
59
|
+
ui_win: signal_engine_win,
|
60
|
+
color: signal_color,
|
61
|
+
style: :reverse,
|
62
|
+
string: ''.ljust(col_just1, ' ')
|
63
|
+
)
|
64
|
+
|
65
|
+
signal_engine_win.setpos(
|
66
|
+
out_line_no,
|
67
|
+
Cryptum::UI.col_center(str: action_signal_out)
|
68
|
+
)
|
69
|
+
|
70
|
+
Cryptum::UI.colorize(
|
71
|
+
ui_win: signal_engine_win,
|
72
|
+
color: signal_color,
|
73
|
+
style: :reverse,
|
74
|
+
string: action_signal_out
|
75
|
+
)
|
76
|
+
|
77
|
+
signal_engine_win.setpos(out_line_no, Cryptum::UI.col_fourth)
|
78
|
+
Cryptum::UI.colorize(
|
79
|
+
ui_win: signal_engine_win,
|
80
|
+
color: signal_color,
|
81
|
+
style: :reverse,
|
82
|
+
string: ''.ljust(col_just4, ' ')
|
83
|
+
)
|
84
|
+
|
85
|
+
signal_engine_win.refresh
|
86
|
+
|
87
|
+
indicator_status.action_signal = action_signal
|
88
|
+
|
89
|
+
indicator_status
|
90
|
+
rescue Interrupt
|
91
|
+
# Exit Gracefully if CTRL+C is Pressed During Session
|
92
|
+
Cryptum.exit_gracefully(which_self: self)
|
93
|
+
rescue StandardError => e
|
94
|
+
raise e
|
95
|
+
end
|
96
|
+
|
97
|
+
# Display Usage for this Module
|
98
|
+
|
99
|
+
public_class_method def self.help
|
100
|
+
puts "USAGE:
|
101
|
+
#{self}.refresh(
|
102
|
+
order_book: 'required - Order Book Data Structure',
|
103
|
+
event: 'required - Event from Coinbase Web Socket'
|
104
|
+
)
|
105
|
+
"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|