cryptum 0.0.261 → 0.0.263

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d760ea86d8e98005d157ecee37d0b52fbd89bc44bc5c093bac8201020dfee8c
4
- data.tar.gz: e6e52346266ac38bf4f3e71535a17a6891388f27e06884985f35c7f09a957d6f
3
+ metadata.gz: 964e7e911ec59fd45c799018361f287fa4d088d191429fa852ef484ce6493512
4
+ data.tar.gz: '099f7606a4a5bfadb7568937bd5ecec633dcba367e9d887346751351f0a1c7d3'
5
5
  SHA512:
6
- metadata.gz: bffdfad77d1716fd242f4441a271066851c397fe44f3e3ec828b22bf8688236c98bd5b22d27e18da526c4c6bd445731351913eea9cb38b982216b459571a9fc5
7
- data.tar.gz: dd2c16cbdb3ebdf0349cde5e5e9f4a08ad2f436bceed8994b44695ebbadec9552848e0a0ddb85da5dd408f9050b5ea5dbc598edeb7177cb705e034b952107e73
6
+ metadata.gz: 855783f7c86bc37eab235e1316f09a4d05b58cefb193060707f1d4e101ed5f7e274b6cb9877e399d71a20a2ca7c501a83079c81204dc6f528335e622c8981ce0
7
+ data.tar.gz: '0128192ed17dda41b7d3376244643168a38b2bd1274509d1e89d6b951729d582d8d016f1effbbc52f1787ad10aa2aa0896258cb00d6ae067ae1df0ba7fcf395c'
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2022-12-02 18:49:14 UTC using RuboCop version 1.39.0.
3
+ # on 2022-12-02 23:03:00 UTC using RuboCop version 1.39.0.
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
@@ -102,7 +102,7 @@ Layout/TrailingWhitespace:
102
102
  - 'lib/cryptum/ui/order_plan.rb'
103
103
  - 'lib/cryptum/ui/order_timer.rb'
104
104
 
105
- # Offense count: 54
105
+ # Offense count: 66
106
106
  Lint/UselessAssignment:
107
107
  Exclude:
108
108
  - 'bin/cryptum-forecast'
@@ -110,51 +110,52 @@ Lint/UselessAssignment:
110
110
  - 'lib/cryptum/api.rb'
111
111
  - 'lib/cryptum/event.rb'
112
112
  - 'lib/cryptum/event/buy.rb'
113
- - 'lib/cryptum/event/cancel.rb'
113
+ - 'lib/cryptum/event/scroll.rb'
114
114
  - 'lib/cryptum/order_book/generate.rb'
115
115
  - 'lib/cryptum/order_book/market_trend.rb'
116
116
  - 'lib/cryptum/ui/market_trend.rb'
117
117
  - 'lib/cryptum/ui/order_execution.rb'
118
118
  - 'lib/cryptum/ui/order_plan.rb'
119
+ - 'lib/cryptum/ui/order_timer.rb'
119
120
  - 'lib/cryptum/ui/portfolio.rb'
120
121
  - 'lib/cryptum/ui/signal_engine.rb'
121
122
  - 'lib/cryptum/ui/ticker.rb'
122
123
 
123
- # Offense count: 39
124
+ # Offense count: 41
124
125
  # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, CountRepeatedAttributes.
125
126
  Metrics/AbcSize:
126
- Max: 401
127
+ Max: 400
127
128
 
128
129
  # Offense count: 7
129
130
  # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
130
131
  # AllowedMethods: refine
131
132
  Metrics/BlockLength:
132
- Max: 139
133
+ Max: 145
133
134
 
134
135
  # Offense count: 4
135
136
  # Configuration parameters: CountBlocks.
136
137
  Metrics/BlockNesting:
137
138
  Max: 4
138
139
 
139
- # Offense count: 16
140
+ # Offense count: 18
140
141
  # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods.
141
142
  Metrics/CyclomaticComplexity:
142
- Max: 72
143
+ Max: 73
143
144
 
144
- # Offense count: 56
145
+ # Offense count: 60
145
146
  # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
146
147
  Metrics/MethodLength:
147
- Max: 391
148
+ Max: 383
148
149
 
149
150
  # Offense count: 15
150
151
  # Configuration parameters: CountComments, CountAsOne.
151
152
  Metrics/ModuleLength:
152
153
  Max: 538
153
154
 
154
- # Offense count: 17
155
+ # Offense count: 18
155
156
  # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods.
156
157
  Metrics/PerceivedComplexity:
157
- Max: 75
158
+ Max: 76
158
159
 
159
160
  # Offense count: 1
160
161
  # This cop supports safe autocorrection (--autocorrect).
@@ -221,14 +222,12 @@ Style/StringChars:
221
222
  Exclude:
222
223
  - 'lib/cryptum.rb'
223
224
 
224
- # Offense count: 3
225
+ # Offense count: 1
225
226
  # This cop supports safe autocorrection (--autocorrect).
226
227
  # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
227
228
  # SupportedStyles: single_quotes, double_quotes
228
229
  Style/StringLiterals:
229
230
  Exclude:
230
- - 'lib/cryptum/ui/order_execution.rb'
231
- - 'lib/cryptum/ui/order_timer.rb'
232
231
  - 'lib/cryptum/ui/portfolio.rb'
233
232
 
234
233
  # Offense count: 2
@@ -247,7 +246,7 @@ Style/TrailingCommaInArrayLiteral:
247
246
  Exclude:
248
247
  - 'lib/cryptum/matrix.rb'
249
248
 
250
- # Offense count: 14
249
+ # Offense count: 15
251
250
  # This cop supports safe autocorrection (--autocorrect).
252
251
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
253
252
  # URISchemes: http, https
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cryptum
4
+ # This plugin is used to Reload the Bot Conf When the "r" Key is Pressed
5
+ module Event
6
+ module BotConf
7
+ # Supported Method Parameters::
8
+ # Cryptum::Event::BotConf.reload(
9
+ # )
10
+ public_class_method def self.reload(opts = {})
11
+ terminal_win = opts[:terminal_win]
12
+ option_choice = opts[:option_choice]
13
+
14
+ terminal_win.key_press_event.key_r = false
15
+ Cryptum.read_bot_conf(option_choice: option_choice)
16
+ rescue StandardError => e
17
+ raise e
18
+ end
19
+
20
+ # Display Usage for this Module
21
+ public_class_method def self.help
22
+ puts "USAGE:
23
+ bot_conf = #{self}.reload()
24
+ "
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,18 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cryptum
4
- # This plugin is used to Cancel Open Limit Orders
4
+ # This plugin is used to Reload the Bot Conf When the "C" Key is Pressed
5
5
  module Event
6
6
  module Cancel
7
7
  # Supported Method Parameters::
8
8
  # Cryptum::Event::Cancel.open_orders(
9
9
  # )
10
10
  public_class_method def self.open_orders(opts = {})
11
+ terminal_win = opts[:terminal_win]
11
12
  option_choice = opts[:option_choice]
12
13
  env = opts[:env]
13
- event_history = opts[:event_history]
14
- order_type = opts[:order_type]
15
- order_action = opts[:order_action]
14
+ # event_history = opts[:event_history]
15
+ # order_type = opts[:order_type]
16
+ # order_action = opts[:order_action]
16
17
 
17
18
  # Consume Latest Order History Justification from
18
19
  # Order Book & cancel orders tagged as pie
@@ -25,14 +26,20 @@ module Cryptum
25
26
  # )
26
27
 
27
28
  # event_history
28
- event_history.order_canceled = true
29
- event_history.event_notes = "{ \"event_type\": \"#{event_history.event_type}\", \"cancel\": \"#{event_history.order_canceled}\", \"submitted\": \"#{event_history.order_submitted}\" }" if option_choice.proxy
29
+ # event_history.order_canceled = true
30
+ # event_history.event_notes = "{ \"event_type\": \"#{event_history.event_type}\", \"cancel\": \"#{event_history.order_canceled}\", \"submitted\": \"#{event_history.order_submitted}\" }" if option_choice.proxy
30
31
 
32
+ # Cryptum::API.cancel_all_open_orders(
33
+ # env: env,
34
+ # option_choice: option_choice,
35
+ # order_type: order_type,
36
+ # event_notes: event_history.event_notes
37
+ # )
38
+
39
+ terminal_win.key_press_event.key_c = false
31
40
  Cryptum::API.cancel_all_open_orders(
32
41
  env: env,
33
- option_choice: option_choice,
34
- order_type: order_type,
35
- event_notes: event_history.event_notes
42
+ option_choice: option_choice
36
43
  )
37
44
  rescue StandardError => e
38
45
  raise e
@@ -41,7 +48,7 @@ module Cryptum
41
48
  # Display Usage for this Module
42
49
  public_class_method def self.help
43
50
  puts "USAGE:
44
- event_history = #{self}.crypto()
51
+ #{self}.open_orders()
45
52
  "
46
53
  end
47
54
  end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cryptum
4
+ # This plugin is used to Exit Cryptum Gracefully When the "x" Key is Pressed
5
+ module Event
6
+ module Exit
7
+ # Supported Method Parameters::
8
+ # Cryptum::Event::BotConf.gracefully(
9
+ # )
10
+ public_class_method def self.gracefully(opts = {})
11
+ terminal_win = opts[:terminal_win]
12
+ event_history = opts[:event_history]
13
+ option_choice = opts[:option_choice]
14
+ env = opts[:env]
15
+
16
+ terminal_win.key_press_event.key_x = false
17
+ Cryptum.exit_gracefully(
18
+ which_self: self,
19
+ event_history: event_history,
20
+ option_choice: option_choice,
21
+ env: env
22
+ )
23
+ rescue StandardError => e
24
+ raise e
25
+ end
26
+
27
+ # Display Usage for this Module
28
+ public_class_method def self.help
29
+ puts "USAGE:
30
+ #{self}.gracefully()
31
+ "
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cryptum
4
+ # This plugin is used to Get the F* Out (GTFO) when the "G" Key is Pressed
5
+ module Event
6
+ module GTFO
7
+ # Supported Method Parameters::
8
+ # Cryptum::Event::GTFO.now(
9
+ # )
10
+ public_class_method def self.now(opts = {})
11
+ terminal_win = opts[:terminal_win]
12
+ option_choice = opts[:option_choice]
13
+ env = opts[:env]
14
+ event_history = opts[:event_history]
15
+ bot_conf = opts[:bot_conf]
16
+
17
+ terminal_win.key_press_event.key_g = false
18
+ Cryptum::API.gtfo(
19
+ option_choice: option_choice,
20
+ env: env,
21
+ event_history: event_history,
22
+ bot_conf: bot_conf
23
+ )
24
+ rescue StandardError => e
25
+ raise e
26
+ end
27
+
28
+ # Display Usage for this Module
29
+ public_class_method def self.help
30
+ puts "USAGE:
31
+ bot_conf = #{self}.now()
32
+ "
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cryptum
4
- # This plugin is used to Cancel Open Limit Orders
4
+ # This plugin is used to Track Event History
5
5
  module Event
6
6
  # Keep Last Event History When Terminal Resize Occuers
7
7
  class History
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cryptum
4
- # This plugin is used to Cancel Open Limit Orders
4
+ # This plugin is used to Detect if any Keys were Pressed on the Keyboard
5
5
  module Event
6
6
  module KeyPress
7
7
  # Supported Method Parameters::
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cryptum
4
+ # This plugin is used to Write the Order Book from Memory
5
+ # to File When the "w" Key is Pressed
6
+ module Event
7
+ module OrderBook
8
+ # Supported Method Parameters::
9
+ # Cryptum::Event::BotConf.write(
10
+ # )
11
+ public_class_method def self.write(opts = {})
12
+ terminal_win = opts[:terminal_win]
13
+ event_history = opts[:event_history]
14
+
15
+ terminal_win.key_press_event.key_w = false
16
+ order_book_file = event_history.order_book[:path]
17
+ File.open(order_book_file, 'w') do |f|
18
+ f.puts event_history.order_book.to_json
19
+ end
20
+ rescue StandardError => e
21
+ raise e
22
+ end
23
+
24
+ # Display Usage for this Module
25
+ public_class_method def self.help
26
+ puts "USAGE:
27
+ #{self}.write()
28
+ "
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cryptum
4
+ # This plugin is used to Switch through Order Plan / Order History
5
+ # Window Panes when the TAB Key is Pressed.
6
+ module Event
7
+ module Pane
8
+ # Supported Method Parameters::
9
+ # Cryptum::Event::Pane.switch(
10
+ # )
11
+ public_class_method def self.switch(opts = {})
12
+ terminal_win = opts[:terminal_win]
13
+ event_history = opts[:event_history]
14
+
15
+ terminal_win.key_press_event.key_tab = false
16
+
17
+ if event_history.order_plan_win_active
18
+ event_history.order_plan_win_active = false
19
+ event_history.order_execute_win_active = true
20
+ else
21
+ event_history.order_plan_win_active = true
22
+ event_history.order_execute_win_active = false
23
+ end
24
+ rescue StandardError => e
25
+ raise e
26
+ end
27
+
28
+ # Display Usage for this Module
29
+ public_class_method def self.help
30
+ puts "USAGE:
31
+ #{self}.switch()
32
+ "
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,140 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cryptum
4
+ # This plugin is used to Scroll through Order Plan
5
+ # Order Plan and Order History Window Panes
6
+ # to File When the "w" Key is Pressed
7
+ module Event
8
+ module Scroll
9
+ # Supported Method Parameters::
10
+ # Cryptum::Event::Scroll.up(
11
+ # )
12
+ public_class_method def self.up(opts = {})
13
+ terminal_win = opts[:terminal_win]
14
+ event_history = opts[:event_history]
15
+
16
+ terminal_win.key_press_event.key_ansi = false
17
+ terminal_win.key_press_event.key_esc = false
18
+ terminal_win.key_press_event.key_up_arrow = false
19
+
20
+ if event_history.order_plan_win_active
21
+ event_history.order_plan_row_to_select -= 1
22
+ event_history.order_plan_index_offset -= 1 if event_history.order_plan_row_to_select.negative?
23
+ event_history.order_plan_index_offset = 0 if event_history.order_plan_index_offset.negative?
24
+ event_history.order_plan_row_to_select = 0 if event_history.order_plan_row_to_select.negative?
25
+ end
26
+
27
+ if event_history.order_execute_win_active
28
+ event_history.order_execute_row_to_select -= 1
29
+ event_history.order_execute_index_offset -= 1 if event_history.order_execute_row_to_select.negative?
30
+ event_history.order_execute_index_offset = 0 if event_history.order_execute_index_offset.negative?
31
+ event_history.order_execute_row_to_select = 0 if event_history.order_execute_row_to_select.negative?
32
+ end
33
+ rescue StandardError => e
34
+ raise e
35
+ end
36
+
37
+ # Supported Method Parameters::
38
+ # Cryptum::Event::Scroll.down(
39
+ # )
40
+ public_class_method def self.down(opts = {})
41
+ terminal_win = opts[:terminal_win]
42
+ event_history = opts[:event_history]
43
+
44
+ terminal_win.key_press_event.key_ansi = false
45
+ terminal_win.key_press_event.key_esc = false
46
+ terminal_win.key_press_event.key_down_arrow = false
47
+
48
+ if event_history.order_plan_win_active
49
+ event_history.order_plan_row_to_select += 1
50
+ event_history.order_plan_index_offset += 1 if event_history.order_plan_row_to_select > event_history.order_plan_max_rows_to_display
51
+ event_history.order_plan_row_to_select = event_history.order_plan_max_rows_to_display if event_history.order_plan_row_to_select > event_history.order_plan_max_rows_to_display
52
+ end
53
+
54
+ if event_history.order_execute_win_active
55
+ event_history.order_execute_row_to_select += 1
56
+ event_history.order_execute_index_offset += 1 if event_history.order_execute_row_to_select > event_history.order_execute_max_rows_to_display
57
+ event_history.order_execute_row_to_select = event_history.order_execute_max_rows_to_display if event_history.order_execute_row_to_select > event_history.order_execute_max_rows_to_display
58
+ end
59
+ rescue StandardError => e
60
+ raise e
61
+ end
62
+
63
+ # Supported Method Parameters::
64
+ # Cryptum::Event::Scroll.page_up(
65
+ # )
66
+ public_class_method def self.page_up(opts = {})
67
+ terminal_win = opts[:terminal_win]
68
+ event_history = opts[:event_history]
69
+
70
+ terminal_win.key_press_event.key_ansi = false
71
+ terminal_win.key_press_event.key_esc = false
72
+ terminal_win.key_press_event.key_page_up = false
73
+
74
+ File.write('/tmp/key_page_up.DETECTED', nil)
75
+ rescue StandardError => e
76
+ raise e
77
+ end
78
+
79
+ # Supported Method Parameters::
80
+ # Cryptum::Event::Scroll.page_down(
81
+ # )
82
+ public_class_method def self.page_down(opts = {})
83
+ terminal_win = opts[:terminal_win]
84
+ event_history = opts[:event_history]
85
+
86
+ terminal_win.key_press_event.key_ansi = false
87
+ terminal_win.key_press_event.key_esc = false
88
+ terminal_win.key_press_event.key_page_down = false
89
+
90
+ File.write('/tmp/key_page_down.DETECTED', nil)
91
+ rescue StandardError => e
92
+ raise e
93
+ end
94
+
95
+ # Supported Method Parameters::
96
+ # Cryptum::Event::Scroll.top(
97
+ # )
98
+ public_class_method def self.top(opts = {})
99
+ terminal_win = opts[:terminal_win]
100
+ event_history = opts[:event_history]
101
+
102
+ terminal_win.key_press_event.key_ansi = false
103
+ terminal_win.key_press_event.key_esc = false
104
+ terminal_win.key_press_event.key_home = false
105
+
106
+ File.write('/tmp/key_home.DETECTED', nil)
107
+ rescue StandardError => e
108
+ raise e
109
+ end
110
+
111
+ # Supported Method Parameters::
112
+ # Cryptum::Event::Scroll.bottom(
113
+ # )
114
+ public_class_method def self.bottom(opts = {})
115
+ terminal_win = opts[:terminal_win]
116
+ event_history = opts[:event_history]
117
+
118
+ terminal_win.key_press_event.key_ansi = false
119
+ terminal_win.key_press_event.key_esc = false
120
+ terminal_win.key_press_event.key_end = false
121
+
122
+ File.write('/tmp/key_end.DETECTED', nil)
123
+ rescue StandardError => e
124
+ raise e
125
+ end
126
+
127
+ # Display Usage for this Module
128
+ public_class_method def self.help
129
+ puts "USAGE:
130
+ #{self}.up()
131
+ #{self}.down()
132
+ #{self}.page_up()
133
+ #{self}.page_down()
134
+ #{self}.top()
135
+ #{self}.bottom()
136
+ "
137
+ end
138
+ end
139
+ end
140
+ end
data/lib/cryptum/event.rb CHANGED
@@ -5,10 +5,16 @@ require 'logger'
5
5
  module Cryptum
6
6
  # This plugin is used to parse Coinbase Pro Web Socket Events in the HTTP Response
7
7
  module Event
8
+ autoload :BotConf, 'cryptum/event/bot_conf'
8
9
  autoload :Buy, 'cryptum/event/buy'
9
- autoload :Buy, 'cryptum/event/cancel'
10
+ autoload :Cancel, 'cryptum/event/cancel'
11
+ autoload :Exit, 'cryptum/event/exit'
12
+ autoload :GTFO, 'cryptum/event/gtfo'
10
13
  autoload :History, 'cryptum/event/history'
11
14
  autoload :KeyPress, 'cryptum/event/key_press'
15
+ autoload :OrderBook, 'cryptum/event/order_book'
16
+ autoload :Pane, 'cryptum/event/pane'
17
+ autoload :Scroll, 'cryptum/event/scroll'
12
18
  autoload :Sell, 'cryptum/event/sell'
13
19
 
14
20
  # Supported Method Parameters::
@@ -31,9 +37,6 @@ module Cryptum
31
37
  fiat = this_product[:quote_currency]
32
38
  fiat_portfolio_file = "#{option_choice.repo_root}/order_books/#{fiat}_PORTFOLIO.json"
33
39
 
34
- # Detect Key Press Events
35
- Cryptum::Event::KeyPress.detect(terminal_win: terminal_win)
36
-
37
40
  # Determine if Summary UI needs updated data
38
41
  event_history = Cryptum::Portfolio::Balance.refresh(
39
42
  env: env,
@@ -12,7 +12,12 @@ module Cryptum
12
12
  :key_x,
13
13
  :key_ansi,
14
14
  :key_down_arrow,
15
+ :key_end,
16
+ :key_enter,
15
17
  :key_esc,
18
+ :key_home,
19
+ :key_page_down,
20
+ :key_page_up,
16
21
  :key_tab,
17
22
  :key_up_arrow
18
23
 
@@ -53,11 +53,6 @@ module Cryptum
53
53
  col_just3_alt = (Curses.cols - Cryptum::UI.col_third) - 1
54
54
  col_just4 = Curses.cols - Cryptum::UI.col_fourth
55
55
 
56
- Cryptum::UI.detect_key_press_in_ui(
57
- key_press_event: key_press_event,
58
- ui_win: market_trend_win
59
- )
60
-
61
56
  # ROW 1
62
57
  out_line_no = 0
63
58
  Cryptum::UI.line(
@@ -369,11 +369,6 @@ module Cryptum
369
369
  col_just3 = (Curses.cols - Cryptum::UI.col_third) - 1
370
370
  col_just4 = Curses.cols - Cryptum::UI.col_fourth
371
371
 
372
- Cryptum::UI.detect_key_press_in_ui(
373
- key_press_event: key_press_event,
374
- ui_win: order_execute_win
375
- )
376
-
377
372
  # ROW 1
378
373
  out_line_no = 0
379
374
  line_color = :white
@@ -425,60 +420,62 @@ module Cryptum
425
420
  event_history.order_execute_index_offset = first_row
426
421
  end
427
422
 
428
- order_history_meta.reverse[first_row..last_row].each do |meta|
429
- out_line_no += 1
430
- current_line = out_line_no - 2
423
+ if order_history_meta.any?
424
+ order_history_meta.reverse[first_row..last_row].each do |meta|
425
+ out_line_no += 1
426
+ current_line = out_line_no - 2
431
427
 
432
- style = :normal
433
- style = :highlight if event_history.order_execute_row_to_select == current_line
434
- risk_alloc_out = Cryptum.beautify_large_number(
435
- value: meta[:risk_alloc]
436
- )
437
- invest_out = Cryptum.beautify_large_number(
438
- value: meta[:invest]
439
- )
440
- price_out = Cryptum.beautify_large_number(
441
- value: meta[:price]
442
- )
443
- size_out = Cryptum.beautify_large_number(
444
- value: meta[:size]
445
- )
446
- target_price_out = Cryptum.beautify_large_number(
447
- value: meta[:target_price]
448
- )
449
- profit_out = Cryptum.beautify_large_number(
450
- value: meta[:profit]
451
- )
452
- plan_no = "#{meta[:plan_no]}|"
428
+ style = :normal
429
+ style = :highlight if event_history.order_execute_row_to_select == current_line
430
+ risk_alloc_out = Cryptum.beautify_large_number(
431
+ value: meta[:risk_alloc]
432
+ )
433
+ invest_out = Cryptum.beautify_large_number(
434
+ value: meta[:invest]
435
+ )
436
+ price_out = Cryptum.beautify_large_number(
437
+ value: meta[:price]
438
+ )
439
+ size_out = Cryptum.beautify_large_number(
440
+ value: meta[:size]
441
+ )
442
+ target_price_out = Cryptum.beautify_large_number(
443
+ value: meta[:target_price]
444
+ )
445
+ profit_out = Cryptum.beautify_large_number(
446
+ value: meta[:profit]
447
+ )
448
+ plan_no = "#{meta[:plan_no]}|"
453
449
 
454
- buy_created_at_hash_arr = order_history.select do |oh|
455
- oh[:id] == meta[:buy_order_id]
456
- end
450
+ buy_created_at_hash_arr = order_history.select do |oh|
451
+ oh[:id] == meta[:buy_order_id]
452
+ end
457
453
 
458
- buy_created_at = '____-__-__ __:__:__'
459
- unless buy_created_at_hash_arr.empty?
460
- buy_created_at = Time.parse(
461
- buy_created_at_hash_arr.first[:created_at]
462
- ).strftime('%Y-%m-%d %H:%M:%S')
463
- end
454
+ buy_created_at = '____-__-__ __:__:__'
455
+ unless buy_created_at_hash_arr.empty?
456
+ buy_created_at = Time.parse(
457
+ buy_created_at_hash_arr.first[:created_at]
458
+ ).strftime('%Y-%m-%d %H:%M:%S')
459
+ end
464
460
 
465
- invest = "$#{invest_out} @ "
466
- tick = "$#{price_out} = "
467
- size = "*#{size_out} + "
468
- tpm_out = "#{meta[:tpm]}% = "
469
- targ_tick = "$#{target_price_out}"
470
- profit = "|Profit: $#{meta[:profit]}"
471
-
472
- order_exec_ln = "#{buy_created_at}|#{invest}#{tick}#{size}#{tpm_out}#{targ_tick}#{profit}"
473
-
474
- order_execute_win.setpos(out_line_no, Cryptum::UI.col_first)
475
- order_execute_win.clrtoeol
476
- Cryptum::UI.colorize(
477
- ui_win: order_execute_win,
478
- color: meta[:color],
479
- style: style,
480
- string: order_exec_ln.ljust(col_just1, '.')
481
- )
461
+ invest = "$#{invest_out} @ "
462
+ tick = "$#{price_out} = "
463
+ size = "*#{size_out} + "
464
+ tpm_out = "#{meta[:tpm]}% = "
465
+ targ_tick = "$#{target_price_out}"
466
+ profit = "|Profit: $#{meta[:profit]}"
467
+
468
+ order_exec_ln = "#{buy_created_at}|#{invest}#{tick}#{size}#{tpm_out}#{targ_tick}#{profit}"
469
+
470
+ order_execute_win.setpos(out_line_no, Cryptum::UI.col_first)
471
+ order_execute_win.clrtoeol
472
+ Cryptum::UI.colorize(
473
+ ui_win: order_execute_win,
474
+ color: meta[:color],
475
+ style: style,
476
+ string: order_exec_ln.ljust(col_just1, '.')
477
+ )
478
+ end
482
479
  end
483
480
 
484
481
  # ROW 10
@@ -80,7 +80,8 @@ module Cryptum
80
80
 
81
81
  event_history.red_pill = true if crypto_invested_percent.to_f > autotrade_percent
82
82
 
83
- if crypto_invested_percent.to_f <= autotrade_percent && (
83
+ if crypto_invested_percent.to_f <= autotrade_percent &&
84
+ autotrade_percent.positive? && (
84
85
  order_plan.empty? || (
85
86
  indicator_status.action_signal == :buy &&
86
87
  indicator_status.last_action_signal == :sell
@@ -148,7 +149,7 @@ module Cryptum
148
149
  end
149
150
 
150
151
  red_pill_alert = '| RED PILL ALERT |'
151
- red_pill_msg = "% #{symbol_out} > Autotrade %"
152
+ red_pill_msg = '- Autotrade % Exhausted -'
152
153
  event_history.red_pill = true if order_plan.empty?
153
154
 
154
155
  if event_history.red_pill
@@ -192,11 +193,6 @@ module Cryptum
192
193
  col_just3 = (Curses.cols - Cryptum::UI.col_third) - 1
193
194
  col_just4 = Curses.cols - Cryptum::UI.col_fourth
194
195
 
195
- Cryptum::UI.detect_key_press_in_ui(
196
- key_press_event: key_press_event,
197
- ui_win: order_plan_win
198
- )
199
-
200
196
  # ROW 1
201
197
  out_line_no = 0
202
198
  line_color = :white
@@ -226,7 +222,7 @@ module Cryptum
226
222
  string: ''.ljust(col_just1, ' ')
227
223
  )
228
224
 
229
- header_str = "- ORDER PLAN: Cycle ##{order_plan_prefix} -"
225
+ header_str = "- ORDER PLAN | CYCLE ##{order_plan_prefix} -"
230
226
  order_plan_win.setpos(
231
227
  out_line_no,
232
228
  Cryptum::UI.col_center(str: header_str)
@@ -389,7 +385,7 @@ module Cryptum
389
385
  string: ''.ljust(col_just1, ' ')
390
386
  )
391
387
 
392
- header_str = "CYCLE SUMMARY | Risk Allocated: $#{order_plan_volume_out} | Slices: #{max_order_plan_slices} | Profit: $#{order_plan_profit_sum_out} | #{order_plan_exec_percent}% Done"
388
+ header_str = "CYCLE SUMMARY | Slices: #{max_order_plan_slices} | Risk Allocated: $#{order_plan_volume_out} | Profit: $#{order_plan_profit_sum_out} | #{order_plan_exec_percent}% Done"
393
389
  order_plan_win.setpos(
394
390
  out_line_no,
395
391
  Cryptum::UI.col_center(str: header_str)
@@ -20,11 +20,6 @@ module Cryptum
20
20
  last_trend_reset_time = event_history.order_book[:last_trend_reset]
21
21
  last_order_exec_time = event_history.order_book[:last_order_exec]
22
22
 
23
- Cryptum::UI.detect_key_press_in_ui(
24
- key_press_event: key_press_event,
25
- ui_win: order_timer_win
26
- )
27
-
28
23
  # Market Trend Reset Timer
29
24
  time_between_trend_reset = option_choice.market_trend_reset
30
25
  trend_timer_begin = Time.parse(last_trend_reset_time)
@@ -104,11 +104,6 @@ module Cryptum
104
104
  # UI
105
105
  col_just3 = (Curses.cols - Cryptum::UI.col_third) - 1
106
106
 
107
- Cryptum::UI.detect_key_press_in_ui(
108
- key_press_event: key_press_event,
109
- ui_win: portfolio_win
110
- )
111
-
112
107
  # ROW 1
113
108
  out_line_no = 0
114
109
  Cryptum::UI.line(
@@ -51,11 +51,6 @@ module Cryptum
51
51
  col_just3 = (Curses.cols - Cryptum::UI.col_third) - 1
52
52
  col_just4 = Curses.cols - Cryptum::UI.col_fourth
53
53
 
54
- Cryptum::UI.detect_key_press_in_ui(
55
- key_press_event: key_press_event,
56
- ui_win: signal_engine_win
57
- )
58
-
59
54
  # ROW 1
60
55
  out_line_no = 0
61
56
  Cryptum::UI.line(
@@ -149,11 +149,6 @@ module Cryptum
149
149
  col_just3_alt = (Curses.cols - Cryptum::UI.col_third) - 1
150
150
  col_just4 = (Curses.cols - Cryptum::UI.col_fourth) - 1
151
151
 
152
- Cryptum::UI.detect_key_press_in_ui(
153
- key_press_event: key_press_event,
154
- ui_win: ticker_win
155
- )
156
-
157
152
  # ROW 1
158
153
  out_line_no = 0
159
154
  Cryptum::UI.line(
data/lib/cryptum/ui.rb CHANGED
@@ -277,7 +277,7 @@ module Cryptum
277
277
  # f.puts key_press.class
278
278
  # f.print key_press.inspect
279
279
  # f.puts "\n\n\n"
280
- # end
280
+ # end
281
281
  # end
282
282
 
283
283
  case key_press
@@ -293,16 +293,30 @@ module Cryptum
293
293
  key_press_event.key_w = true
294
294
  when 'x'
295
295
  key_press_event.key_x = true
296
- when "\t"
297
- key_press_event.key_tab = true
298
296
  when "\e"
299
297
  key_press_event.key_esc = true
298
+ when "\n"
299
+ key_press_event.key_enter = true
300
+ when "\t"
301
+ key_press_event.key_tab = true
300
302
  end
301
303
 
302
- # What a hack to detect up / down arrow key presses.
303
- key_press_event.key_ansi = true if key_press_event.key_esc && key_press == '['
304
- key_press_event.key_up_arrow = true if key_press_event.key_ansi && key_press == 'A'
305
- key_press_event.key_down_arrow = true if key_press_event.key_ansi && key_press == 'B'
304
+ # What a hack to detect special keys (-.-)
305
+ if key_press_event.key_esc
306
+ key_press_event.key_ansi = true if key_press == '['
307
+ if key_press_event.key_ansi
308
+ key_press_event.key_up_arrow = true if key_press == 'A'
309
+ key_press_event.key_down_arrow = true if key_press == 'B'
310
+ # NOTE: the ~ at the end of these keys are ignored
311
+ # which may result in other keys working in place of them
312
+ # e.g. home is \e[1~ but we know it's home as soon as
313
+ # \e[1 is detected.
314
+ key_press_event.key_page_up = true if key_press == '5'
315
+ key_press_event.key_page_down = true if key_press == '6'
316
+ key_press_event.key_home = true if key_press == '1'
317
+ key_press_event.key_end = true if key_press == '4'
318
+ end
319
+ end
306
320
 
307
321
  key_press_event
308
322
  rescue Interrupt
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cryptum
4
- VERSION = '0.0.261'
4
+ VERSION = '0.0.263'
5
5
  end
@@ -53,6 +53,11 @@ module Cryptum
53
53
  end
54
54
 
55
55
  ws.on :message do |event|
56
+ # TODO: The Speed of the UI is dictated by the
57
+ # Frequency of WebSocket Messages Coming Through.
58
+ # Explore another way to decouple required events
59
+ # (such as keypresses) from only being triggered
60
+ # when messages come through.
56
61
  ai_enabled = bot_conf[:artifical_intelligence]
57
62
 
58
63
  event_history.event = JSON.parse(
@@ -70,114 +75,120 @@ module Cryptum
70
75
  ai_enabled: ai_enabled
71
76
  )
72
77
 
73
- # Decent for Debugging Events
74
- # puts event_history.inspect
75
- # Decent for Debugging MACD & RSI History
76
- # puts indicator_status.inspect
77
-
78
78
  # Detect Key Press Events
79
79
  Cryptum::Event::KeyPress.detect(terminal_win: terminal_win)
80
80
 
81
81
  # Cancel ALL Open Orders when
82
82
  # C is pressed
83
83
  if terminal_win.key_press_event.key_c
84
- Cryptum::API.cancel_all_open_orders(
85
- env: env,
86
- option_choice: option_choice
84
+ Cryptum::Event::Cancel.open_orders(
85
+ terminal_win: terminal_win,
86
+ option_choice: option_choice,
87
+ env: env
87
88
  )
88
- terminal_win.key_press_event.key_c = false
89
89
  end
90
90
 
91
91
  # Get the F* Out (GTFO) when
92
92
  # G is pressed
93
93
  if terminal_win.key_press_event.key_g
94
- event_history = Cryptum::API.gtfo(
94
+ event_history = Cryptum::Event::GTFO.now(
95
+ terminal_win: terminal_win,
95
96
  option_choice: option_choice,
96
97
  env: env,
97
98
  event_history: event_history,
98
99
  bot_conf: bot_conf
99
100
  )
100
- terminal_win.key_press_event.key_g = false
101
101
  end
102
102
 
103
- # Only Reload Bot Conf when
104
- # R is Pressed
103
+ # Reload Bot Conf when r is Pressed
105
104
  if terminal_win.key_press_event.key_r
106
- bot_conf = Cryptum.read_bot_conf(option_choice: option_choice)
107
- terminal_win.key_press_event.key_r = false
105
+ bot_conf = Cryptum::Event::BotConf.reload(
106
+ terminal_win: terminal_win,
107
+ option_choice: option_choice
108
+ )
108
109
  end
109
110
 
110
111
  # Only Write Order Book to File when
111
112
  # W is Pressed
112
113
  if terminal_win.key_press_event.key_w
113
- order_book_file = event_history.order_book[:path]
114
- File.open(order_book_file, 'w') do |f|
115
- f.puts event_history.order_book.to_json
116
- end
117
- terminal_win.key_press_event.key_w = false
114
+ Cryptum::Event::OrderBook.write(
115
+ terminal_win: terminal_win,
116
+ event_history: event_history
117
+ )
118
118
  end
119
119
 
120
120
  # Exit if x is Pressed
121
121
  if terminal_win.key_press_event.key_x
122
- terminal_win.key_press_event.key_x = false
123
- Cryptum.exit_gracefully(
124
- which_self: self,
122
+ Cryptum::Event::Exit.gracefully(
123
+ terminal_win: terminal_win,
125
124
  event_history: event_history,
126
125
  option_choice: option_choice,
127
126
  env: env
128
127
  )
129
128
  end
130
129
 
131
- # Scroll Down Order Plan / Order Execution Window Panes
132
- if terminal_win.key_press_event.key_down_arrow
133
- terminal_win.key_press_event.key_ansi = false
134
- terminal_win.key_press_event.key_esc = false
135
- terminal_win.key_press_event.key_down_arrow = false
136
- if event_history.order_plan_win_active
137
- event_history.order_plan_row_to_select += 1
138
- event_history.order_plan_index_offset += 1 if event_history.order_plan_row_to_select > event_history.order_plan_max_rows_to_display
139
- event_history.order_plan_row_to_select = event_history.order_plan_max_rows_to_display if event_history.order_plan_row_to_select > event_history.order_plan_max_rows_to_display
140
- end
141
-
142
- if event_history.order_execute_win_active
143
- event_history.order_execute_row_to_select += 1
144
- event_history.order_execute_index_offset += 1 if event_history.order_execute_row_to_select > event_history.order_execute_max_rows_to_display
145
- event_history.order_execute_row_to_select = event_history.order_execute_max_rows_to_display if event_history.order_execute_row_to_select > event_history.order_execute_max_rows_to_display
146
- end
147
- end
148
-
149
130
  # TAB through Order Plan / Order Execution Window Panes
150
131
  if terminal_win.key_press_event.key_tab
151
- terminal_win.key_press_event.key_tab = false
152
-
153
- if event_history.order_plan_win_active
154
- event_history.order_plan_win_active = false
155
- event_history.order_execute_win_active = true
156
- else
157
- event_history.order_plan_win_active = true
158
- event_history.order_execute_win_active = false
159
- end
132
+ Cryptum::Event::Pane.switch(
133
+ terminal_win: terminal_win,
134
+ event_history: event_history
135
+ )
160
136
  end
161
137
 
162
138
  # Scroll Up Order Plan / Order Execution Window Panes
163
139
  if terminal_win.key_press_event.key_up_arrow
140
+ Cryptum::Event::Scroll.up(
141
+ terminal_win: terminal_win,
142
+ event_history: event_history
143
+ )
144
+ end
145
+
146
+ # Scroll Down Order Plan / Order Execution Window Panes
147
+ if terminal_win.key_press_event.key_down_arrow
148
+ Cryptum::Event::Scroll.down(
149
+ terminal_win: terminal_win,
150
+ event_history: event_history
151
+ )
152
+ end
153
+
154
+ # Scroll Up Order Plan / Order Execution Window Panes Faster
155
+ if terminal_win.key_press_event.key_page_up
156
+ Cryptum::Event::Scroll.page_up(
157
+ terminal_win: terminal_win,
158
+ event_history: event_history
159
+ )
160
+ end
161
+
162
+ # Scroll Down Order Plan / Order Execution Window Panes Faster
163
+ if terminal_win.key_press_event.key_page_down
164
+ Cryptum::Event::Scroll.page_down(
165
+ terminal_win: terminal_win,
166
+ event_history: event_history
167
+ )
168
+ end
169
+
170
+ # Scroll to Top of Order Plan / Order Execution Window Panes
171
+ if terminal_win.key_press_event.key_home
172
+ Cryptum::Event::Scroll.top(
173
+ terminal_win: terminal_win,
174
+ event_history: event_history
175
+ )
176
+ end
177
+
178
+ # Scroll to Bottom of Order Plan / Order Execution Window Panes
179
+ if terminal_win.key_press_event.key_end
180
+ Cryptum::Event::Scroll.bottom(
181
+ terminal_win: terminal_win,
182
+ event_history: event_history
183
+ )
184
+ end
185
+
186
+ # Open / Close Order Plan / Order Execution Details Window
187
+ if terminal_win.key_press_event.key_enter
164
188
  terminal_win.key_press_event.key_ansi = false
165
189
  terminal_win.key_press_event.key_esc = false
166
- terminal_win.key_press_event.key_up_arrow = false
167
-
168
- if event_history.order_plan_win_active
169
- event_history.order_plan_row_to_select -= 1
170
- event_history.order_plan_index_offset -= 1 if event_history.order_plan_row_to_select.negative?
171
- event_history.order_plan_index_offset = 0 if event_history.order_plan_index_offset.negative?
172
- event_history.order_plan_row_to_select = 0 if event_history.order_plan_row_to_select.negative?
173
- end
174
-
175
- if event_history.order_execute_win_active
176
- event_history.order_execute_row_to_select -= 1
177
- event_history.order_execute_index_offset -= 1 if event_history.order_execute_row_to_select.negative?
178
- event_history.order_execute_index_offset = 0 if event_history.order_execute_index_offset.negative?
179
- event_history.order_execute_row_to_select = 0 if event_history.order_execute_row_to_select.negative?
180
- end
190
+ terminal_win.key_press_event.key_enter = false
191
+ File.write('/tmp/key_enter.DETECTED', nil)
181
192
  end
182
193
  end
183
194
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cryptum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.261
4
+ version: 0.0.263
5
5
  platform: ruby
6
6
  authors:
7
7
  - 0day Inc.
@@ -381,10 +381,16 @@ files:
381
381
  - lib/cryptum/api.rb
382
382
  - lib/cryptum/bot_conf.rb
383
383
  - lib/cryptum/event.rb
384
+ - lib/cryptum/event/bot_conf.rb
384
385
  - lib/cryptum/event/buy.rb
385
386
  - lib/cryptum/event/cancel.rb
387
+ - lib/cryptum/event/exit.rb
388
+ - lib/cryptum/event/gtfo.rb
386
389
  - lib/cryptum/event/history.rb
387
390
  - lib/cryptum/event/key_press.rb
391
+ - lib/cryptum/event/order_book.rb
392
+ - lib/cryptum/event/pane.rb
393
+ - lib/cryptum/event/scroll.rb
388
394
  - lib/cryptum/event/sell.rb
389
395
  - lib/cryptum/log.rb
390
396
  - lib/cryptum/matrix.rb