cryptum 0.0.355 → 0.0.357
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- metadata +13 -116
- data/.github/workflows/main.yml +0 -16
- data/.gitignore +0 -30
- data/.rspec +0 -3
- data/.rspec_status +0 -0
- data/.rubocop.yml +0 -31
- data/.rubocop_todo.yml +0 -32
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/CODE_OF_CONDUCT.md +0 -84
- data/Gemfile +0 -38
- data/LICENSE +0 -674
- data/README.md +0 -87
- data/Rakefile +0 -19
- data/bin/cryptum +0 -73
- data/bin/cryptum-forecast +0 -200
- data/bin/cryptum-repl +0 -73
- data/bin/cryptum_autoinc_version +0 -38
- data/build_cryptum_gem.sh +0 -58
- data/cryptum.gemspec +0 -52
- data/cryptum_container.sh +0 -1
- data/docker/cryptum.json +0 -60
- data/docker/cryptum_container.sh +0 -59
- data/docker/packer_secrets.json.EXAMPLE +0 -7
- data/docker/provisioners/cryptum.sh +0 -11
- data/docker/provisioners/docker_bashrc.sh +0 -2
- data/docker/provisioners/docker_rvm.sh +0 -22
- data/docker/provisioners/init_image.sh +0 -28
- data/docker/provisioners/post_install.sh +0 -6
- data/docker/provisioners/ruby.sh +0 -16
- data/docker/provisioners/upload_globals.sh +0 -49
- data/etc/bot_confs/.gitkeep +0 -0
- data/etc/bot_confs/BOT_CONF.TEMPLATE +0 -10
- data/etc/coinbase_pro.yaml.EXAMPLE +0 -8
- data/etc/open_ai.yaml.EXAMPLE +0 -1
- data/git_commit.sh +0 -22
- data/lib/cryptum/api.rb +0 -688
- data/lib/cryptum/bot_conf.rb +0 -197
- data/lib/cryptum/event/bot_conf.rb +0 -34
- data/lib/cryptum/event/buy.rb +0 -145
- data/lib/cryptum/event/cancel.rb +0 -35
- data/lib/cryptum/event/exit.rb +0 -35
- data/lib/cryptum/event/gtfo.rb +0 -36
- data/lib/cryptum/event/history.rb +0 -105
- data/lib/cryptum/event/key_press.rb +0 -64
- data/lib/cryptum/event/order_book.rb +0 -34
- data/lib/cryptum/event/pane.rb +0 -65
- data/lib/cryptum/event/parse.rb +0 -181
- data/lib/cryptum/event/scroll.rb +0 -200
- data/lib/cryptum/event/sell.rb +0 -124
- data/lib/cryptum/event.rb +0 -27
- data/lib/cryptum/log.rb +0 -34
- data/lib/cryptum/matrix.rb +0 -181
- data/lib/cryptum/open_ai.rb +0 -156
- data/lib/cryptum/option/choice.rb +0 -28
- data/lib/cryptum/option.rb +0 -206
- data/lib/cryptum/order_book/generate.rb +0 -114
- data/lib/cryptum/order_book/indicator.rb +0 -15
- data/lib/cryptum/order_book/market_trend.rb +0 -137
- data/lib/cryptum/order_book/profit_margin.rb +0 -55
- data/lib/cryptum/order_book.rb +0 -19
- data/lib/cryptum/portfolio/balance.rb +0 -123
- data/lib/cryptum/portfolio.rb +0 -15
- data/lib/cryptum/ui/command.rb +0 -314
- data/lib/cryptum/ui/key_press_event.rb +0 -33
- data/lib/cryptum/ui/market_trend.rb +0 -74
- data/lib/cryptum/ui/order_execute_details.rb +0 -297
- data/lib/cryptum/ui/order_execution.rb +0 -573
- data/lib/cryptum/ui/order_plan.rb +0 -503
- data/lib/cryptum/ui/order_plan_details.rb +0 -240
- data/lib/cryptum/ui/order_timer.rb +0 -121
- data/lib/cryptum/ui/portfolio.rb +0 -221
- data/lib/cryptum/ui/signal_engine.rb +0 -109
- data/lib/cryptum/ui/terminal_window.rb +0 -111
- data/lib/cryptum/ui/ticker.rb +0 -319
- data/lib/cryptum/ui.rb +0 -343
- data/lib/cryptum/version.rb +0 -5
- data/lib/cryptum/web_sock/coinbase.rb +0 -102
- data/lib/cryptum/web_sock/event_machine.rb +0 -274
- data/lib/cryptum/web_sock.rb +0 -16
- data/lib/cryptum.rb +0 -120
- data/order_books/.gitkeep +0 -0
- data/reinstall_cryptum_gemset.sh +0 -29
- data/spec/lib/cryptum/api_spec.rb +0 -10
- data/spec/lib/cryptum/event_spec.rb +0 -10
- data/spec/lib/cryptum/log_spec.rb +0 -10
- data/spec/lib/cryptum/option_spec.rb +0 -10
- data/spec/lib/cryptum/order_book/generate_spec.rb +0 -10
- data/spec/lib/cryptum/order_book/market_trend_spec.rb +0 -10
- data/spec/lib/cryptum/order_book_spec.rb +0 -10
- data/spec/lib/cryptum/ui/command_spec.rb +0 -10
- data/spec/lib/cryptum/ui/ticker_spec.rb +0 -10
- data/spec/lib/cryptum/ui_spec.rb +0 -10
- data/spec/lib/cryptum/web_sock_spec.rb +0 -10
- data/spec/lib/cryptum_spec.rb +0 -10
- data/spec/spec_helper.rb +0 -3
- data/upgrade_Gemfile_gems.sh +0 -20
- data/upgrade_cryptum.sh +0 -13
- data/upgrade_gem.sh +0 -4
- data/upgrade_ruby.sh +0 -45
@@ -1,573 +0,0 @@
|
|
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 OrderExecution
|
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
|
-
order_execute_win = opts[:order_execute_win]
|
18
|
-
env = opts[:env]
|
19
|
-
event_history = opts[:event_history]
|
20
|
-
indicator_status = opts[:indicator_status]
|
21
|
-
bot_conf = opts[:bot_conf]
|
22
|
-
|
23
|
-
event_type = event_history.event_type if option_choice.autotrade
|
24
|
-
event_side = event_history.event[:side].to_s.to_sym if option_choice.autotrade
|
25
|
-
event_reason = event_history.event[:reason].to_s.to_sym if option_choice.autotrade
|
26
|
-
|
27
|
-
ticker_price = event_history.order_book[:ticker_price].to_f
|
28
|
-
open_24h = event_history.order_book[:open_24h].to_f
|
29
|
-
this_product = event_history.order_book[:this_product]
|
30
|
-
min_market_funds = this_product[:min_market_funds]
|
31
|
-
base_increment = this_product[:base_increment]
|
32
|
-
quote_increment = this_product[:quote_increment]
|
33
|
-
crypto_smallest_decimal = base_increment.to_s.split('.')[-1].length
|
34
|
-
fiat_smallest_decimal = quote_increment.to_s.split('.')[-1].length
|
35
|
-
|
36
|
-
last_three_prices_arr = []
|
37
|
-
last_ticker_price = event_history.order_book[:ticker_price].to_f
|
38
|
-
second_to_last_ticker_price = event_history.order_book[:ticker_price_second_to_last].to_f
|
39
|
-
third_to_last_ticker_price = event_history.order_book[:ticker_price_third_to_last].to_f
|
40
|
-
last_three_prices_arr.push(last_ticker_price)
|
41
|
-
last_three_prices_arr.push(second_to_last_ticker_price)
|
42
|
-
last_three_prices_arr.push(third_to_last_ticker_price)
|
43
|
-
limit_price = last_three_prices_arr.sort[1]
|
44
|
-
return event_history unless limit_price.positive?
|
45
|
-
|
46
|
-
tpm = bot_conf[:target_profit_margin_percent].to_f
|
47
|
-
tpm_cast_as_decimal = tpm / 100
|
48
|
-
|
49
|
-
order_history_meta = event_history.order_book[:order_history_meta]
|
50
|
-
order_history = event_history.order_book[:order_history] if option_choice.autotrade
|
51
|
-
|
52
|
-
margin_percent_open_24h = (1 - (open_24h / ticker_price)) * 100
|
53
|
-
cast_margin_to_sec = margin_percent_open_24h * 0.1
|
54
|
-
|
55
|
-
# Reset times to max or default depending on
|
56
|
-
# BULL or BEAR market trend
|
57
|
-
event_history.bullish_trend = true if cast_margin_to_sec.positive?
|
58
|
-
event_history.bullish_trend = false if cast_margin_to_sec.negative?
|
59
|
-
|
60
|
-
buy_total = event_history.order_book[:market_trend][:buy].to_i
|
61
|
-
sell_total = event_history.order_book[:market_trend][:sell].to_i
|
62
|
-
|
63
|
-
if event_history.order_book[:order_plan].length.positive?
|
64
|
-
if event_history.order_ready
|
65
|
-
event_history.order_book[:last_order_exec] = Time.now.strftime(
|
66
|
-
'%Y-%m-%d %H:%M:%S.%N%z'
|
67
|
-
)
|
68
|
-
end
|
69
|
-
|
70
|
-
# BUY
|
71
|
-
# Reset times to max or default depending on
|
72
|
-
# BULL or BEAR market trend
|
73
|
-
event_history.time_between_orders = event_history.time_between_orders_max if buy_total >= sell_total &&
|
74
|
-
!event_history.bullish_trend
|
75
|
-
|
76
|
-
event_history.time_between_orders = event_history.time_between_orders_reset if sell_total > buy_total &&
|
77
|
-
!event_history.bullish_trend
|
78
|
-
|
79
|
-
if event_history.order_ready &&
|
80
|
-
indicator_status.action_signal == :buy &&
|
81
|
-
!event_history.red_pill
|
82
|
-
|
83
|
-
if option_choice.autotrade
|
84
|
-
this_order = event_history.order_book[:order_plan].first
|
85
|
-
|
86
|
-
price = format(
|
87
|
-
"%0.#{fiat_smallest_decimal}f",
|
88
|
-
limit_price
|
89
|
-
)
|
90
|
-
|
91
|
-
size = this_order[:invest].to_f / limit_price
|
92
|
-
|
93
|
-
loop do
|
94
|
-
size = size.to_f + base_increment.to_f
|
95
|
-
break if (size.to_f * price.to_f) > min_market_funds.to_f
|
96
|
-
end
|
97
|
-
|
98
|
-
size = format(
|
99
|
-
"%0.#{crypto_smallest_decimal}f",
|
100
|
-
size
|
101
|
-
)
|
102
|
-
|
103
|
-
fiat_invested_this_order = size.to_f * price.to_f
|
104
|
-
|
105
|
-
fiat_portfolio = event_history.order_book[:fiat_portfolio]
|
106
|
-
fiat_avail_to_trade = format('%0.2f', fiat_portfolio.first[:available])
|
107
|
-
|
108
|
-
event_history.red_pill = true if fiat_invested_this_order > fiat_avail_to_trade.to_f
|
109
|
-
|
110
|
-
unless event_history.red_pill
|
111
|
-
event_history = Cryptum::API.submit_limit_order(
|
112
|
-
option_choice: option_choice,
|
113
|
-
env: env,
|
114
|
-
price: price,
|
115
|
-
size: size,
|
116
|
-
buy_or_sell: :buy,
|
117
|
-
event_history: event_history,
|
118
|
-
bot_conf: bot_conf
|
119
|
-
)
|
120
|
-
end
|
121
|
-
else
|
122
|
-
this_order = event_history.order_book[:order_plan].shift
|
123
|
-
# Mock Order ID
|
124
|
-
this_order[:buy_order_id] = format(
|
125
|
-
'%0.6i',
|
126
|
-
Random.rand(0..999_999)
|
127
|
-
)
|
128
|
-
|
129
|
-
this_order[:price] = limit_price.to_s
|
130
|
-
this_order[:size] = format(
|
131
|
-
"%0.#{crypto_smallest_decimal}f",
|
132
|
-
this_order[:invest].to_f / limit_price
|
133
|
-
)
|
134
|
-
|
135
|
-
targ_price = limit_price + (limit_price * tpm_cast_as_decimal)
|
136
|
-
this_order[:tpm] = format(
|
137
|
-
'%0.2f',
|
138
|
-
tpm
|
139
|
-
)
|
140
|
-
this_order[:target_price] = format(
|
141
|
-
"%0.#{fiat_smallest_decimal}f",
|
142
|
-
targ_price
|
143
|
-
)
|
144
|
-
this_order[:color] = :cyan
|
145
|
-
order_history_meta.push(this_order)
|
146
|
-
end
|
147
|
-
|
148
|
-
# SAUCE 3
|
149
|
-
# Time between orders
|
150
|
-
# Increment n Seconds between buys to
|
151
|
-
# account for bearish and bullish trends
|
152
|
-
dynamic_time_increment = cast_margin_to_sec * -1
|
153
|
-
|
154
|
-
# Lets also take balance into play
|
155
|
-
balance_as_arbitrary_float = fiat_avail_to_trade.to_f / 1_000_000
|
156
|
-
tbo = dynamic_time_increment - balance_as_arbitrary_float
|
157
|
-
|
158
|
-
event_history.time_between_orders += tbo
|
159
|
-
|
160
|
-
# Time between orders should never
|
161
|
-
# be less than event_history.time_between_orders_min
|
162
|
-
event_history.time_between_orders = event_history.time_between_orders_min if event_history.time_between_orders < event_history.time_between_orders_min
|
163
|
-
# Time between orders should never
|
164
|
-
# be more than event_history.time_between_orders_max
|
165
|
-
event_history.time_between_orders = event_history.time_between_orders_max if event_history.time_between_orders > event_history.time_between_orders_max
|
166
|
-
end
|
167
|
-
|
168
|
-
# SELL
|
169
|
-
# Once buy arders are fulfilled submit a
|
170
|
-
# limit sell order for fulfillment
|
171
|
-
unless option_choice.autotrade
|
172
|
-
# Testing logic via Mock
|
173
|
-
event_type_arr = %i[received open done]
|
174
|
-
last_et_index = event_type_arr.length - 1
|
175
|
-
rand_et_index = Random.rand(0..last_et_index)
|
176
|
-
event_type = event_type_arr[rand_et_index]
|
177
|
-
|
178
|
-
event_side_arr = %i[buy sell]
|
179
|
-
last_es_index = event_side_arr.length - 1
|
180
|
-
rand_es_index = Random.rand(0..last_es_index)
|
181
|
-
event_side = event_type_arr[rand_es_index].to_s.to_sym
|
182
|
-
event_reason = 'mock'
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
# Update Completed Sell Orders w/ Green
|
187
|
-
if event_type == :open &&
|
188
|
-
event_side == :buy
|
189
|
-
|
190
|
-
buy_order_id = event_history.event[:order_id]
|
191
|
-
order_history_meta.each do |meta|
|
192
|
-
meta[:color] = :red if meta[:buy_order_id] == buy_order_id
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
if event_type == :done &&
|
197
|
-
event_side == :buy &&
|
198
|
-
event_reason == :canceled
|
199
|
-
|
200
|
-
buy_order_id = event_history.event[:order_id]
|
201
|
-
order_history_meta.each do |meta|
|
202
|
-
next unless meta[:buy_order_id] == buy_order_id
|
203
|
-
|
204
|
-
meta[:done_at] = Time.now.strftime('%Y-%m-%d %H:%M:%S.%N%z')
|
205
|
-
meta[:color] = :white
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
if event_type == :done &&
|
210
|
-
event_side == :buy &&
|
211
|
-
event_reason != :canceled
|
212
|
-
|
213
|
-
if option_choice.autotrade
|
214
|
-
order_ready_to_sell_arr = order_history_meta.select do |meta|
|
215
|
-
meta[:buy_order_id] == event_history.event[:order_id]
|
216
|
-
end
|
217
|
-
else
|
218
|
-
last_index = order_history_meta.length - 1
|
219
|
-
rand_index = Random.rand(0..last_index)
|
220
|
-
order_ready_to_sell_arr = [
|
221
|
-
order_history_meta[rand_index]
|
222
|
-
]
|
223
|
-
end
|
224
|
-
|
225
|
-
if order_ready_to_sell_arr.length.positive?
|
226
|
-
order_ready_to_sell = order_ready_to_sell_arr.first
|
227
|
-
buy_order_id = order_ready_to_sell[:buy_order_id]
|
228
|
-
|
229
|
-
if option_choice.autotrade
|
230
|
-
price = format(
|
231
|
-
"%0.#{fiat_smallest_decimal}f",
|
232
|
-
order_ready_to_sell[:target_price]
|
233
|
-
)
|
234
|
-
|
235
|
-
size = order_ready_to_sell[:size]
|
236
|
-
|
237
|
-
Cryptum::API.submit_limit_order(
|
238
|
-
option_choice: option_choice,
|
239
|
-
env: env,
|
240
|
-
price: price,
|
241
|
-
size: size,
|
242
|
-
buy_or_sell: :sell,
|
243
|
-
event_history: event_history,
|
244
|
-
bot_conf: bot_conf,
|
245
|
-
buy_order_id: buy_order_id
|
246
|
-
)
|
247
|
-
else
|
248
|
-
sell_order_id = format(
|
249
|
-
'%0.2i',
|
250
|
-
Random.rand(0..999_999)
|
251
|
-
)
|
252
|
-
|
253
|
-
event_history.order_book[:order_history_meta].each do |meta|
|
254
|
-
if meta[:buy_order_id] == buy_order_id
|
255
|
-
meta[:sell_order_id] = sell_order_id
|
256
|
-
meta[:color] = :yellow
|
257
|
-
end
|
258
|
-
end
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
# Update Canceled Sell Orders w/ Black &&
|
264
|
-
# Include done_at Timestamp for 24h gain calc
|
265
|
-
if event_type == :done &&
|
266
|
-
event_side == :sell &&
|
267
|
-
event_reason == :canceled
|
268
|
-
|
269
|
-
sell_order_id = event_history.event[:order_id]
|
270
|
-
order_history_meta.each do |meta|
|
271
|
-
next unless meta[:sell_order_id] == sell_order_id
|
272
|
-
|
273
|
-
meta[:done_at] = Time.now.strftime('%Y-%m-%d %H:%M:%S.%N%z')
|
274
|
-
|
275
|
-
# TODO: Retry sell order if the original sell order expires.
|
276
|
-
|
277
|
-
# Reinitiate GTFO if the previous GTFO Order Expires.
|
278
|
-
terminal_win.key_press_event.key_g = true if meta[:color] == :magenta
|
279
|
-
meta[:color] = :white
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
# Update Completed Sell Orders w/ Green &&
|
284
|
-
# Include done_at Timestamp for 24h gain calc
|
285
|
-
if event_type == :done &&
|
286
|
-
event_side == :sell &&
|
287
|
-
event_reason != :canceled
|
288
|
-
|
289
|
-
sell_order_id = event_history.event[:order_id]
|
290
|
-
order_history_meta.each do |meta|
|
291
|
-
next unless meta[:sell_order_id] == sell_order_id
|
292
|
-
|
293
|
-
meta[:done_at] = Time.now.strftime('%Y-%m-%d %H:%M:%S.%N%z')
|
294
|
-
meta[:color] = :green
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
# OK, now let's tally up everything...
|
299
|
-
twenty_four_hrs_ago = Time.now - 86_400
|
300
|
-
|
301
|
-
# Snag all sold orders
|
302
|
-
oh_meta_sold_arr = order_history_meta.select do |ohm|
|
303
|
-
ohm[:color].to_sym == :green && ohm.key?(:done_at)
|
304
|
-
end
|
305
|
-
|
306
|
-
# Snag all sold orders within past 24 hrs
|
307
|
-
ohm_sold_twenty_four_arr = []
|
308
|
-
unless oh_meta_sold_arr.empty?
|
309
|
-
ohm_sold_twenty_four_arr = oh_meta_sold_arr.select do |o|
|
310
|
-
Time.parse(o[:done_at]) >= twenty_four_hrs_ago
|
311
|
-
end
|
312
|
-
end
|
313
|
-
order_hist_meta_sold = ohm_sold_twenty_four_arr.length
|
314
|
-
|
315
|
-
# Snag all expired orders
|
316
|
-
oh_meta_expired_arr = order_history_meta.select do |ohm|
|
317
|
-
ohm[:color].to_sym == :white && ohm.key?(:done_at)
|
318
|
-
end
|
319
|
-
|
320
|
-
# Snag all expired orders within past 24 hrs
|
321
|
-
ohm_expire_twenty_four_arr = []
|
322
|
-
unless oh_meta_expired_arr.empty?
|
323
|
-
ohm_expire_twenty_four_arr = oh_meta_expired_arr.select do |o|
|
324
|
-
Time.parse(o[:done_at]) >= twenty_four_hrs_ago
|
325
|
-
end
|
326
|
-
end
|
327
|
-
order_hist_meta_expired = ohm_expire_twenty_four_arr.length
|
328
|
-
|
329
|
-
# Calculate gains within past 24 hrs
|
330
|
-
gains_24h_sum = ohm_sold_twenty_four_arr.map do |ohms|
|
331
|
-
ohms[:profit].to_f
|
332
|
-
end.sum
|
333
|
-
|
334
|
-
gains_24h_out = Cryptum.beautify_large_number(
|
335
|
-
value: format(
|
336
|
-
'%0.2f',
|
337
|
-
gains_24h_sum
|
338
|
-
)
|
339
|
-
)
|
340
|
-
|
341
|
-
total_to_sell = order_history.select do |oh|
|
342
|
-
oh[:status].to_sym == :open && oh[:side].to_sym == :sell
|
343
|
-
end.length
|
344
|
-
event_history.open_sell_orders = total_to_sell
|
345
|
-
# TODO: when event_history.open_sell_orders > event_history.open_sell_orders_max
|
346
|
-
# Capture highest amount to sell, cancel all orders, and create _one_ limit sell
|
347
|
-
# order set to a price of the previously captured highest amount to sell.
|
348
|
-
event_history.open_sell_orders_merge = true if total_to_sell > event_history.open_sell_orders_max
|
349
|
-
|
350
|
-
# TODO: Everything Above this Line Needs to be Indicators ^
|
351
|
-
|
352
|
-
# UI
|
353
|
-
col_just1 = (Curses.cols - Cryptum::UI.col_first) - 1
|
354
|
-
col_just4 = Curses.cols - Cryptum::UI.col_fourth
|
355
|
-
|
356
|
-
# ROW 1
|
357
|
-
out_line_no = 0
|
358
|
-
line_color = :white
|
359
|
-
header_color = :white
|
360
|
-
header_style = :bold
|
361
|
-
style = :bold
|
362
|
-
if event_history.order_execute_win_active
|
363
|
-
line_color = :blue
|
364
|
-
header_color = :blue
|
365
|
-
header_style = :reverse
|
366
|
-
end
|
367
|
-
|
368
|
-
Cryptum::UI.line(
|
369
|
-
ui_win: order_execute_win,
|
370
|
-
out_line_no: out_line_no,
|
371
|
-
color: line_color
|
372
|
-
)
|
373
|
-
|
374
|
-
# ROW 2
|
375
|
-
out_line_no += 1
|
376
|
-
order_execute_win.setpos(out_line_no, Cryptum::UI.col_first)
|
377
|
-
order_execute_win.clrtoeol
|
378
|
-
Cryptum::UI.colorize(
|
379
|
-
ui_win: order_execute_win,
|
380
|
-
color: header_color,
|
381
|
-
style: header_style,
|
382
|
-
string: ''.ljust(col_just1, ' ')
|
383
|
-
)
|
384
|
-
|
385
|
-
header_str = '- ORDER HISTORY -'
|
386
|
-
order_execute_win.setpos(
|
387
|
-
out_line_no,
|
388
|
-
Cryptum::UI.col_center(str: header_str)
|
389
|
-
)
|
390
|
-
|
391
|
-
Cryptum::UI.colorize(
|
392
|
-
ui_win: order_execute_win,
|
393
|
-
color: header_color,
|
394
|
-
style: header_style,
|
395
|
-
string: header_str
|
396
|
-
)
|
397
|
-
|
398
|
-
order_execute_win.setpos(out_line_no, Cryptum::UI.col_fourth)
|
399
|
-
order_execute_win.clrtoeol
|
400
|
-
Cryptum::UI.colorize(
|
401
|
-
ui_win: order_execute_win,
|
402
|
-
color: header_color,
|
403
|
-
style: header_style,
|
404
|
-
string: ''.ljust(col_just4, ' ')
|
405
|
-
)
|
406
|
-
|
407
|
-
# ROWS 3-10
|
408
|
-
remaining_blank_rows = 0
|
409
|
-
remaining_blank_rows = max_rows_to_display if order_history_meta.empty?
|
410
|
-
max_rows_to_display = event_history.order_execute_max_rows_to_display
|
411
|
-
first_row = event_history.order_execute_index_offset
|
412
|
-
last_row = first_row + max_rows_to_display
|
413
|
-
if last_row >= order_history_meta.length
|
414
|
-
last_row = order_history_meta.length - 1
|
415
|
-
event_history.order_execute_max_records_available_to_display = last_row if last_row < max_rows_to_display
|
416
|
-
first_row = last_row - event_history.order_execute_max_records_available_to_display
|
417
|
-
event_history.order_execute_index_offset = first_row
|
418
|
-
remaining_blank_rows = max_rows_to_display - last_row
|
419
|
-
end
|
420
|
-
|
421
|
-
if order_history_meta.any?
|
422
|
-
selected_order = event_history.order_execute_selected_data
|
423
|
-
order_history_meta.reverse[first_row..last_row].each do |meta|
|
424
|
-
out_line_no += 1
|
425
|
-
current_line = out_line_no - 2
|
426
|
-
|
427
|
-
style = :normal
|
428
|
-
if event_history.order_execute_row_to_select == current_line
|
429
|
-
style = :highlight
|
430
|
-
selected_order = meta
|
431
|
-
selected_order[:color] = meta[:color]
|
432
|
-
end
|
433
|
-
|
434
|
-
invest_out = Cryptum.beautify_large_number(
|
435
|
-
value: meta[:invest]
|
436
|
-
)
|
437
|
-
price_out = Cryptum.beautify_large_number(
|
438
|
-
value: meta[:price]
|
439
|
-
)
|
440
|
-
size_out = Cryptum.beautify_large_number(
|
441
|
-
value: meta[:size]
|
442
|
-
)
|
443
|
-
target_price_out = Cryptum.beautify_large_number(
|
444
|
-
value: meta[:target_price]
|
445
|
-
)
|
446
|
-
plan_no = meta[:plan_no]
|
447
|
-
|
448
|
-
buy_created_at_hash_arr = order_history.select do |oh|
|
449
|
-
oh[:id] == meta[:buy_order_id]
|
450
|
-
end
|
451
|
-
|
452
|
-
buy_created_at = '____-__-__ __:__:__'
|
453
|
-
unless buy_created_at_hash_arr.empty?
|
454
|
-
buy_created_at = Time.parse(
|
455
|
-
buy_created_at_hash_arr.first[:created_at]
|
456
|
-
).strftime('%Y-%m-%d %H:%M:%S')
|
457
|
-
end
|
458
|
-
|
459
|
-
invest = "$#{invest_out} @ "
|
460
|
-
tick = "$#{price_out} = "
|
461
|
-
size = "*#{size_out} + "
|
462
|
-
tpm_out = "#{meta[:tpm]}% = "
|
463
|
-
targ_tick = "$#{target_price_out}"
|
464
|
-
profit = "|Profit: $#{meta[:profit]}"
|
465
|
-
|
466
|
-
order_exec_ln = "#{buy_created_at}|#{invest}#{tick}#{size}#{tpm_out}#{targ_tick}#{profit}|#{plan_no}"
|
467
|
-
|
468
|
-
order_execute_win.setpos(out_line_no, Cryptum::UI.col_first)
|
469
|
-
order_execute_win.clrtoeol
|
470
|
-
Cryptum::UI.colorize(
|
471
|
-
ui_win: order_execute_win,
|
472
|
-
color: meta[:color],
|
473
|
-
style: style,
|
474
|
-
string: order_exec_ln.ljust(col_just1, '.')
|
475
|
-
)
|
476
|
-
|
477
|
-
Cryptum::UI.colorize(
|
478
|
-
ui_win: order_execute_win,
|
479
|
-
color: meta[:color],
|
480
|
-
style: style,
|
481
|
-
string: ''.ljust(col_just4, ' ')
|
482
|
-
)
|
483
|
-
end
|
484
|
-
event_history.order_execute_selected_data = selected_order
|
485
|
-
end
|
486
|
-
|
487
|
-
# Clear to SUMMARY
|
488
|
-
# (Only Applicable if order_book[:order_history_meta] < max_rows_to_display)
|
489
|
-
# out_line_no += 1
|
490
|
-
if remaining_blank_rows.positive?
|
491
|
-
rows_to_blank = out_line_no + remaining_blank_rows
|
492
|
-
out_line_no += 1
|
493
|
-
(out_line_no..rows_to_blank).each do |clr_line|
|
494
|
-
out_line_no = clr_line
|
495
|
-
order_execute_win.setpos(clr_line, Cryptum::UI.col_first)
|
496
|
-
order_execute_win.clrtoeol
|
497
|
-
Cryptum::UI.colorize(
|
498
|
-
ui_win: order_execute_win,
|
499
|
-
color: :white,
|
500
|
-
style: :normal,
|
501
|
-
string: ''.ljust(col_just1, ' ')
|
502
|
-
)
|
503
|
-
end
|
504
|
-
end
|
505
|
-
|
506
|
-
# ROW 10
|
507
|
-
out_line_no += 1
|
508
|
-
order_execute_win.setpos(out_line_no, Cryptum::UI.col_first)
|
509
|
-
order_execute_win.clrtoeol
|
510
|
-
Cryptum::UI.colorize(
|
511
|
-
ui_win: order_execute_win,
|
512
|
-
color: header_color,
|
513
|
-
style: header_style,
|
514
|
-
string: ''.ljust(col_just1, ' ')
|
515
|
-
)
|
516
|
-
|
517
|
-
header_str = "24 HR SUMMARY | Open Sell Orders: #{total_to_sell} | Sold: #{order_hist_meta_sold} | Gains: $#{gains_24h_out} | Expired: #{order_hist_meta_expired}"
|
518
|
-
order_execute_win.setpos(
|
519
|
-
out_line_no,
|
520
|
-
Cryptum::UI.col_center(str: header_str)
|
521
|
-
)
|
522
|
-
|
523
|
-
Cryptum::UI.colorize(
|
524
|
-
ui_win: order_execute_win,
|
525
|
-
color: header_color,
|
526
|
-
style: header_style,
|
527
|
-
string: header_str
|
528
|
-
)
|
529
|
-
|
530
|
-
order_execute_win.setpos(out_line_no, Cryptum::UI.col_fourth)
|
531
|
-
order_execute_win.clrtoeol
|
532
|
-
Cryptum::UI.colorize(
|
533
|
-
ui_win: order_execute_win,
|
534
|
-
color: header_color,
|
535
|
-
style: header_style,
|
536
|
-
string: ''.ljust(col_just4, ' ')
|
537
|
-
)
|
538
|
-
|
539
|
-
# ROW 11
|
540
|
-
out_line_no += 1
|
541
|
-
Cryptum::UI.line(
|
542
|
-
ui_win: order_execute_win,
|
543
|
-
out_line_no: out_line_no,
|
544
|
-
color: line_color
|
545
|
-
)
|
546
|
-
|
547
|
-
order_execute_win.refresh
|
548
|
-
|
549
|
-
# Reset Order Ready && Open Sell Orders Merge (If Applicable) Booleans
|
550
|
-
event_history.order_ready = false
|
551
|
-
event_history.open_sell_orders_merge = false
|
552
|
-
|
553
|
-
event_history
|
554
|
-
rescue Interrupt
|
555
|
-
# Exit Gracefully if CTRL+C is Pressed During Session
|
556
|
-
Cryptum.exit_gracefully(which_self: self)
|
557
|
-
rescue StandardError => e
|
558
|
-
raise e
|
559
|
-
end
|
560
|
-
|
561
|
-
# Display Usage for this Module
|
562
|
-
|
563
|
-
public_class_method def self.help
|
564
|
-
puts "USAGE:
|
565
|
-
#{self}.refresh(
|
566
|
-
order_book: 'required - Order Book Data Structure',
|
567
|
-
event: 'required - Event from Coinbase Web Socket'
|
568
|
-
)
|
569
|
-
"
|
570
|
-
end
|
571
|
-
end
|
572
|
-
end
|
573
|
-
end
|