cryptum 0.0.230

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/main.yml +16 -0
  3. data/.gitignore +30 -0
  4. data/.rspec +3 -0
  5. data/.rspec_status +0 -0
  6. data/.rubocop.yml +5 -0
  7. data/.rubocop_todo.yml +250 -0
  8. data/.ruby-gemset +1 -0
  9. data/.ruby-version +1 -0
  10. data/CODE_OF_CONDUCT.md +84 -0
  11. data/Gemfile +36 -0
  12. data/LICENSE +674 -0
  13. data/README.md +72 -0
  14. data/Rakefile +19 -0
  15. data/bin/cryptum +72 -0
  16. data/bin/cryptum-forecast +199 -0
  17. data/bin/cryptum-repl +73 -0
  18. data/bin/cryptum_autoinc_version +38 -0
  19. data/build_cryptum_gem.sh +52 -0
  20. data/cryptum.gemspec +50 -0
  21. data/cryptum_container.sh +1 -0
  22. data/docker/cryptum.json +60 -0
  23. data/docker/cryptum_container.sh +59 -0
  24. data/docker/packer_secrets.json.EXAMPLE +7 -0
  25. data/docker/provisioners/cryptum.sh +11 -0
  26. data/docker/provisioners/docker_bashrc.sh +2 -0
  27. data/docker/provisioners/docker_rvm.sh +22 -0
  28. data/docker/provisioners/init_image.sh +28 -0
  29. data/docker/provisioners/post_install.sh +6 -0
  30. data/docker/provisioners/ruby.sh +16 -0
  31. data/docker/provisioners/upload_globals.sh +49 -0
  32. data/etc/bot_confs/.gitkeep +0 -0
  33. data/etc/bot_confs/BOT_CONF.TEMPLATE +10 -0
  34. data/etc/coinbase_pro.yaml.EXAMPLE +8 -0
  35. data/git_commit.sh +22 -0
  36. data/lib/cryptum/api.rb +693 -0
  37. data/lib/cryptum/bot_conf.rb +76 -0
  38. data/lib/cryptum/event/buy.rb +144 -0
  39. data/lib/cryptum/event/cancel.rb +49 -0
  40. data/lib/cryptum/event/history.rb +64 -0
  41. data/lib/cryptum/event/key_press.rb +64 -0
  42. data/lib/cryptum/event/sell.rb +120 -0
  43. data/lib/cryptum/event.rb +168 -0
  44. data/lib/cryptum/log.rb +34 -0
  45. data/lib/cryptum/matrix.rb +181 -0
  46. data/lib/cryptum/option/choice.rb +26 -0
  47. data/lib/cryptum/option.rb +161 -0
  48. data/lib/cryptum/order_book/generate.rb +111 -0
  49. data/lib/cryptum/order_book/indicator.rb +16 -0
  50. data/lib/cryptum/order_book/market_trend.rb +161 -0
  51. data/lib/cryptum/order_book/profit_margin.rb +55 -0
  52. data/lib/cryptum/order_book/weighted_avg.rb +157 -0
  53. data/lib/cryptum/order_book.rb +156 -0
  54. data/lib/cryptum/portfolio/balance.rb +123 -0
  55. data/lib/cryptum/portfolio.rb +15 -0
  56. data/lib/cryptum/ui/command.rb +274 -0
  57. data/lib/cryptum/ui/key_press_event.rb +22 -0
  58. data/lib/cryptum/ui/market_trend.rb +117 -0
  59. data/lib/cryptum/ui/order_execution.rb +478 -0
  60. data/lib/cryptum/ui/order_plan.rb +376 -0
  61. data/lib/cryptum/ui/order_timer.rb +119 -0
  62. data/lib/cryptum/ui/portfolio.rb +231 -0
  63. data/lib/cryptum/ui/signal_engine.rb +122 -0
  64. data/lib/cryptum/ui/terminal_window.rb +95 -0
  65. data/lib/cryptum/ui/ticker.rb +317 -0
  66. data/lib/cryptum/ui.rb +306 -0
  67. data/lib/cryptum/version.rb +5 -0
  68. data/lib/cryptum/web_sock/coinbase.rb +94 -0
  69. data/lib/cryptum/web_sock/event_machine.rb +182 -0
  70. data/lib/cryptum/web_sock.rb +16 -0
  71. data/lib/cryptum.rb +183 -0
  72. data/order_books/.gitkeep +0 -0
  73. data/reinstall_cryptum_gemset.sh +29 -0
  74. data/spec/lib/cryptum/api_spec.rb +10 -0
  75. data/spec/lib/cryptum/event_spec.rb +10 -0
  76. data/spec/lib/cryptum/log_spec.rb +10 -0
  77. data/spec/lib/cryptum/option_spec.rb +10 -0
  78. data/spec/lib/cryptum/order_book/generate_spec.rb +10 -0
  79. data/spec/lib/cryptum/order_book/market_trend_spec.rb +10 -0
  80. data/spec/lib/cryptum/order_book_spec.rb +10 -0
  81. data/spec/lib/cryptum/ui/command_spec.rb +10 -0
  82. data/spec/lib/cryptum/ui/ticker_spec.rb +10 -0
  83. data/spec/lib/cryptum/ui_spec.rb +10 -0
  84. data/spec/lib/cryptum/web_sock_spec.rb +10 -0
  85. data/spec/lib/cryptum_spec.rb +10 -0
  86. data/spec/spec_helper.rb +3 -0
  87. data/upgrade_Gemfile_gems.sh +20 -0
  88. data/upgrade_cryptum.sh +13 -0
  89. data/upgrade_gem.sh +4 -0
  90. data/upgrade_ruby.sh +46 -0
  91. metadata +472 -0
@@ -0,0 +1,231 @@
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
+ key_press_event = opts[:key_press_event]
20
+ indicator_status = opts[:indicator_status]
21
+ bot_conf = opts[:bot_conf]
22
+ fiat_portfolio_file = opts[:fiat_portfolio_file]
23
+
24
+ ticker_price = event_history.order_book[:ticker_price].to_f
25
+ this_product = event_history.order_book[:this_product]
26
+ symbol_out = this_product[:id]
27
+ quote_increment = this_product[:quote_increment]
28
+ base_increment = this_product[:base_increment]
29
+
30
+ fiat_smallest_decimal = quote_increment.to_s.split('.')[-1].length
31
+ crypto_smallest_decimal = base_increment.to_s.split('.')[-1].length
32
+
33
+ autotrade_percent = format(
34
+ '%0.2f',
35
+ bot_conf[:autotrade_portfolio_percent].to_f
36
+ )
37
+
38
+ tpm = format(
39
+ '%0.2f',
40
+ bot_conf[:target_profit_margin_percent]
41
+ )
42
+
43
+ tpm_cast_as_decimal = tpm.to_f / 100
44
+
45
+ crypto_currency = option_choice.symbol.to_s.upcase.split('_').first.to_sym
46
+ portfolio = event_history.order_book[:portfolio]
47
+ this_account = portfolio.select do |account|
48
+ account[:currency] == crypto_currency.to_s
49
+ end
50
+ raise "ID for Crypto Currency, #{crypto_currency} Not Found" if this_account.empty?
51
+
52
+ balance = format("%0.#{crypto_smallest_decimal}f", this_account.first[:balance])
53
+ balance_out = Cryptum.beautify_large_number(
54
+ value: balance
55
+ )
56
+ avail_for_trade = format("%0.#{crypto_smallest_decimal}f", this_account.first[:available])
57
+ avail_for_trade_out = Cryptum.beautify_large_number(
58
+ value: avail_for_trade
59
+ )
60
+
61
+ fiat_portfolio = event_history.order_book[:fiat_portfolio]
62
+ fiat = option_choice.symbol.to_s.upcase.split('_').last.to_sym
63
+ total_holdings = format('%0.2f', fiat_portfolio.first[:total_holdings])
64
+ total_holdings_out = Cryptum.beautify_large_number(
65
+ value: total_holdings
66
+ )
67
+ fiat_balance = format('%0.2f', fiat_portfolio.first[:balance])
68
+ fiat_balance_out = Cryptum.beautify_large_number(
69
+ value: fiat_balance
70
+ )
71
+ fiat_avail_for_trade = format('%0.2f', fiat_portfolio.first[:available])
72
+ fiat_avail_for_trade_out = Cryptum.beautify_large_number(
73
+ value: fiat_avail_for_trade
74
+ )
75
+
76
+ fees = event_history.order_book[:fees]
77
+ maker_fee = format('%0.2f', fees[:maker_fee_rate].to_f * 100)
78
+ taker_fee = format('%0.2f', fees[:taker_fee_rate].to_f * 100)
79
+ volume_tier = format('%0.2f', fees[:usd_volume].to_f)
80
+ volume_tier_out = Cryptum.beautify_large_number(
81
+ value: volume_tier
82
+ )
83
+
84
+ current_crypto_fiat_value = format(
85
+ '%0.2f',
86
+ balance.to_f * ticker_price
87
+ )
88
+ current_crypto_fiat_value_out = Cryptum.beautify_large_number(
89
+ value: current_crypto_fiat_value
90
+ )
91
+
92
+ fiat_budget = fiat_avail_for_trade.to_f
93
+ current_fiat_invested_percent = format(
94
+ '%0.2f',
95
+ (1 - (fiat_budget / total_holdings.to_f)) * 100
96
+ )
97
+
98
+ crypto_invested_percent = format(
99
+ '%0.2f',
100
+ (current_crypto_fiat_value.to_f / total_holdings.to_f) * 100
101
+ )
102
+ # TODO: Everything Above this Line Needs to be Indicators ^
103
+
104
+ # UI
105
+ col_just3 = (Curses.cols - Cryptum::UI.col_third) - 1
106
+
107
+ Cryptum::UI.detect_key_press_in_ui(
108
+ key_press_event: key_press_event,
109
+ ui_win: portfolio_win
110
+ )
111
+
112
+ # ROW 1
113
+ out_line_no = 0
114
+ Cryptum::UI.line(
115
+ ui_win: portfolio_win,
116
+ out_line_no: out_line_no
117
+ )
118
+
119
+ # ROW 2
120
+ out_line_no += 1
121
+ portfolio_win.setpos(out_line_no, Cryptum::UI.col_first)
122
+ portfolio_win.clrtoeol
123
+ Cryptum::UI.colorize(
124
+ ui_win: portfolio_win,
125
+ color: :white,
126
+ style: :bold,
127
+ string: "Portfolio | % Tied Up | % #{symbol_out}:"
128
+ )
129
+
130
+ portfolio_win.setpos(out_line_no, Cryptum::UI.col_third)
131
+ Cryptum::UI.colorize(
132
+ ui_win: portfolio_win,
133
+ color: :white,
134
+ string: "$#{total_holdings_out} | #{current_fiat_invested_percent}% | #{crypto_invested_percent}%".rjust(col_just3, '.')
135
+ )
136
+
137
+ # ROW 3
138
+ out_line_no += 1
139
+ portfolio_win.setpos(out_line_no, Cryptum::UI.col_first)
140
+ portfolio_win.clrtoeol
141
+ Cryptum::UI.colorize(
142
+ ui_win: portfolio_win,
143
+ color: :cyan,
144
+ string: "TPM % | Autotrade %:"
145
+ )
146
+
147
+ portfolio_win.setpos(out_line_no, Cryptum::UI.col_third)
148
+ Cryptum::UI.colorize(
149
+ ui_win: portfolio_win,
150
+ color: :cyan,
151
+ string: "#{tpm}% | #{autotrade_percent}%".rjust(col_just3, '.')
152
+ )
153
+
154
+ # ROW 4
155
+ out_line_no += 1
156
+ portfolio_win.setpos(out_line_no, Cryptum::UI.col_first)
157
+ portfolio_win.clrtoeol
158
+ Cryptum::UI.colorize(
159
+ ui_win: portfolio_win,
160
+ color: :green,
161
+ style: :bold,
162
+ string: "#{fiat} Bal | Tradeable:"
163
+ )
164
+
165
+ portfolio_win.setpos(out_line_no, Cryptum::UI.col_third)
166
+ Cryptum::UI.colorize(
167
+ ui_win: portfolio_win,
168
+ color: :green,
169
+ string: "$#{fiat_balance_out} | $#{fiat_avail_for_trade_out}".rjust(
170
+ col_just3,
171
+ '.'
172
+ )
173
+ )
174
+
175
+ # ROW 5
176
+ out_line_no += 1
177
+ portfolio_win.setpos(out_line_no, Cryptum::UI.col_first)
178
+ portfolio_win.clrtoeol
179
+ Cryptum::UI.colorize(
180
+ ui_win: portfolio_win,
181
+ color: :yellow,
182
+ style: :bold,
183
+ string: 'Crypto Val | Bal | Tradeable:'
184
+ )
185
+
186
+ portfolio_win.setpos(out_line_no, Cryptum::UI.col_third)
187
+ Cryptum::UI.colorize(
188
+ ui_win: portfolio_win,
189
+ color: :yellow,
190
+ string: "$#{current_crypto_fiat_value_out} | *#{balance_out} | *#{avail_for_trade_out}".rjust(col_just3, '.')
191
+ )
192
+
193
+ # ROW 6
194
+ out_line_no += 1
195
+ portfolio_win.setpos(out_line_no, Cryptum::UI.col_first)
196
+ portfolio_win.clrtoeol
197
+ Cryptum::UI.colorize(
198
+ ui_win: portfolio_win,
199
+ color: :red,
200
+ style: :bold,
201
+ string: 'Maker & Taker Fees | My Volume:'
202
+ )
203
+
204
+ portfolio_win.setpos(out_line_no, Cryptum::UI.col_third)
205
+ Cryptum::UI.colorize(
206
+ ui_win: portfolio_win,
207
+ color: :red,
208
+ string: "#{maker_fee}% & #{taker_fee}% | $#{volume_tier_out}".rjust(col_just3, '.')
209
+ )
210
+
211
+ portfolio_win.refresh
212
+ rescue Interrupt
213
+ # Exit Gracefully if CTRL+C is Pressed During Session
214
+ Cryptum.exit_gracefully(which_self: self)
215
+ rescue StandardError => e
216
+ raise e
217
+ end
218
+
219
+ # Display Usage for this Module
220
+
221
+ public_class_method def self.help
222
+ puts "USAGE:
223
+ #{self}.refresh(
224
+ order_book: 'required - Order Book Data Structure',
225
+ event: 'required - Event from Coinbase Web Socket'
226
+ )
227
+ "
228
+ end
229
+ end
230
+ end
231
+ end
@@ -0,0 +1,122 @@
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
+ option_choice = opts[:option_choice]
17
+ signal_engine_win = opts[:signal_engine_win]
18
+ event_history = opts[:event_history]
19
+ key_press_event = opts[:key_press_event]
20
+ indicator_status = opts[:indicator_status]
21
+ bot_conf = opts[:bot_conf]
22
+ fiat_portfolio_file = opts[:fiat_portfolio_file]
23
+
24
+ color = :white
25
+ color = indicator_status.market_trend[:color] if indicator_status.market_trend
26
+
27
+ indicator_status.last_action_signal = indicator_status.action_signal
28
+
29
+ case color
30
+ when :green
31
+ signal_color = :green
32
+ action_signal = :sell
33
+ when :yellow
34
+ signal_color = :yellow
35
+ action_signal = :hold
36
+ when :red
37
+ signal_color = :cyan
38
+ action_signal = :buy
39
+ else
40
+ signal_color = :white
41
+ action_signal = :skip
42
+ end
43
+
44
+ action_signal_out = "SIGNAL >>> #{action_signal.to_s.upcase} <<< ENGINE"
45
+ # TODO: Everything Above this Line Needs to be Indicators ^
46
+
47
+ # UI
48
+ col_just1 = (Curses.cols - Cryptum::UI.col_first) - 1
49
+ # col_just1 = 12
50
+ col_just2 = 14
51
+ col_just3 = (Curses.cols - Cryptum::UI.col_third) - 1
52
+ col_just4 = Curses.cols - Cryptum::UI.col_fourth
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
+ # ROW 1
60
+ out_line_no = 0
61
+ Cryptum::UI.line(
62
+ ui_win: signal_engine_win,
63
+ out_line_no: out_line_no
64
+ )
65
+
66
+ # ROW 2
67
+ out_line_no += 1
68
+ signal_engine_win.setpos(out_line_no, Cryptum::UI.col_first)
69
+ signal_engine_win.clrtoeol
70
+
71
+ Cryptum::UI.colorize(
72
+ ui_win: signal_engine_win,
73
+ color: signal_color,
74
+ style: :reverse,
75
+ string: ''.ljust(col_just1, ' ')
76
+ )
77
+
78
+ signal_engine_win.setpos(
79
+ out_line_no,
80
+ Cryptum::UI.col_center(str: action_signal_out)
81
+ )
82
+
83
+ Cryptum::UI.colorize(
84
+ ui_win: signal_engine_win,
85
+ color: signal_color,
86
+ style: :reverse,
87
+ string: action_signal_out
88
+ )
89
+
90
+ signal_engine_win.setpos(out_line_no, Cryptum::UI.col_fourth)
91
+ Cryptum::UI.colorize(
92
+ ui_win: signal_engine_win,
93
+ color: signal_color,
94
+ style: :reverse,
95
+ string: ''.ljust(col_just4, ' ')
96
+ )
97
+
98
+ signal_engine_win.refresh
99
+
100
+ indicator_status.action_signal = action_signal
101
+
102
+ indicator_status
103
+ rescue Interrupt
104
+ # Exit Gracefully if CTRL+C is Pressed During Session
105
+ Cryptum.exit_gracefully(which_self: self)
106
+ rescue StandardError => e
107
+ raise e
108
+ end
109
+
110
+ # Display Usage for this Module
111
+
112
+ public_class_method def self.help
113
+ puts "USAGE:
114
+ #{self}.refresh(
115
+ order_book: 'required - Order Book Data Structure',
116
+ event: 'required - Event from Coinbase Web Socket'
117
+ )
118
+ "
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+
5
+ module Cryptum
6
+ module UI
7
+ # This Class is Used by Cryptum::Event to
8
+ # Detect when the Terminal Window is Resized
9
+ class TerminalWindow
10
+ attr_accessor :cols,
11
+ :key_press_event,
12
+ :ticker_ui_resize,
13
+ :ticker_section,
14
+ :portfolio_section,
15
+ :order_plan_section,
16
+ :order_timer_section,
17
+ :market_trend_section,
18
+ :market_trend_ui_resize,
19
+ :signal_engine_section,
20
+ :order_execute_section,
21
+ :command_section
22
+
23
+ def initialize
24
+ # Persist the column width of the terminal window
25
+ # for resize detection in Cryptum::Event
26
+ self.cols = Curses.cols
27
+
28
+ self.key_press_event = Cryptum::UI::KeyPressEvent.new
29
+
30
+ self.ticker_section = Cryptum::UI.window(
31
+ height: 7,
32
+ width: 0,
33
+ top: 0,
34
+ left: 0
35
+ )
36
+
37
+ self.portfolio_section = Cryptum::UI.window(
38
+ height: 6,
39
+ width: 0,
40
+ top: 7,
41
+ left: 0
42
+ )
43
+
44
+ self.order_plan_section = Cryptum::UI.window(
45
+ height: 10,
46
+ width: 0,
47
+ top: 13,
48
+ left: 0
49
+ )
50
+
51
+ self.order_timer_section = Cryptum::UI.window(
52
+ height: 2,
53
+ width: 0,
54
+ top: 23,
55
+ left: 0
56
+ )
57
+
58
+ self.market_trend_section = Cryptum::UI.window(
59
+ height: 2,
60
+ width: 0,
61
+ top: 25,
62
+ left: 0
63
+ )
64
+
65
+ self.signal_engine_section = Cryptum::UI.window(
66
+ height: 2,
67
+ width: 0,
68
+ top: 27,
69
+ left: 0
70
+ )
71
+
72
+ self.order_execute_section = Cryptum::UI.window(
73
+ height: 10,
74
+ width: 0,
75
+ top: 29,
76
+ left: 0
77
+ )
78
+
79
+ self.command_section = Cryptum::UI.window(
80
+ height: 4,
81
+ width: 0,
82
+ top: 39,
83
+ left: 0
84
+ )
85
+ end
86
+ rescue Interrupt
87
+ # Exit Gracefully if CTRL+C is Pressed During Session
88
+ Cryptum.exit_gracefully(which_self: self)
89
+ rescue StandardError => e
90
+ # Produce a Stacktrace for anything else
91
+ Curses.close_screen
92
+ raise e
93
+ end
94
+ end
95
+ end