cryptum 0.0.230
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +16 -0
- data/.gitignore +30 -0
- data/.rspec +3 -0
- data/.rspec_status +0 -0
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +250 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +36 -0
- data/LICENSE +674 -0
- data/README.md +72 -0
- data/Rakefile +19 -0
- data/bin/cryptum +72 -0
- data/bin/cryptum-forecast +199 -0
- data/bin/cryptum-repl +73 -0
- data/bin/cryptum_autoinc_version +38 -0
- data/build_cryptum_gem.sh +52 -0
- data/cryptum.gemspec +50 -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/git_commit.sh +22 -0
- data/lib/cryptum/api.rb +693 -0
- data/lib/cryptum/bot_conf.rb +76 -0
- data/lib/cryptum/event/buy.rb +144 -0
- data/lib/cryptum/event/cancel.rb +49 -0
- data/lib/cryptum/event/history.rb +64 -0
- data/lib/cryptum/event/key_press.rb +64 -0
- data/lib/cryptum/event/sell.rb +120 -0
- data/lib/cryptum/event.rb +168 -0
- data/lib/cryptum/log.rb +34 -0
- data/lib/cryptum/matrix.rb +181 -0
- data/lib/cryptum/option/choice.rb +26 -0
- data/lib/cryptum/option.rb +161 -0
- data/lib/cryptum/order_book/generate.rb +111 -0
- data/lib/cryptum/order_book/indicator.rb +16 -0
- data/lib/cryptum/order_book/market_trend.rb +161 -0
- data/lib/cryptum/order_book/profit_margin.rb +55 -0
- data/lib/cryptum/order_book/weighted_avg.rb +157 -0
- data/lib/cryptum/order_book.rb +156 -0
- data/lib/cryptum/portfolio/balance.rb +123 -0
- data/lib/cryptum/portfolio.rb +15 -0
- data/lib/cryptum/ui/command.rb +274 -0
- data/lib/cryptum/ui/key_press_event.rb +22 -0
- data/lib/cryptum/ui/market_trend.rb +117 -0
- data/lib/cryptum/ui/order_execution.rb +478 -0
- data/lib/cryptum/ui/order_plan.rb +376 -0
- data/lib/cryptum/ui/order_timer.rb +119 -0
- data/lib/cryptum/ui/portfolio.rb +231 -0
- data/lib/cryptum/ui/signal_engine.rb +122 -0
- data/lib/cryptum/ui/terminal_window.rb +95 -0
- data/lib/cryptum/ui/ticker.rb +317 -0
- data/lib/cryptum/ui.rb +306 -0
- data/lib/cryptum/version.rb +5 -0
- data/lib/cryptum/web_sock/coinbase.rb +94 -0
- data/lib/cryptum/web_sock/event_machine.rb +182 -0
- data/lib/cryptum/web_sock.rb +16 -0
- data/lib/cryptum.rb +183 -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 +46 -0
- metadata +472 -0
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faye/websocket'
|
4
|
+
|
5
|
+
module Cryptum
|
6
|
+
# This plugin is used to Establish a Web
|
7
|
+
# Socket Connection with Coinbase
|
8
|
+
module WebSock
|
9
|
+
module Coinbase
|
10
|
+
# Supported Method Parameters::
|
11
|
+
# Cryptum::WebSock.connect(
|
12
|
+
# )
|
13
|
+
public_class_method def self.connect(opts = {})
|
14
|
+
option_choice = opts[:option_choice]
|
15
|
+
env = opts[:env]
|
16
|
+
|
17
|
+
cb_pro_ws_feed = 'wss://ws-feed.pro.coinbase.com'
|
18
|
+
cb_pro_ws_feed = 'wss://ws-feed-public.sandbox.pro.coinbase.com' if env[:env] == :sandbox
|
19
|
+
if option_choice.proxy
|
20
|
+
tls_opts = {
|
21
|
+
verify_peer: false
|
22
|
+
}
|
23
|
+
|
24
|
+
proxy_opts = {
|
25
|
+
origin: option_choice.proxy
|
26
|
+
}
|
27
|
+
|
28
|
+
ws = Faye::WebSocket::Client.new(
|
29
|
+
cb_pro_ws_feed,
|
30
|
+
[],
|
31
|
+
tls: tls_opts,
|
32
|
+
proxy: proxy_opts,
|
33
|
+
ping: 30
|
34
|
+
)
|
35
|
+
else
|
36
|
+
ws = Faye::WebSocket::Client.new(
|
37
|
+
cb_pro_ws_feed,
|
38
|
+
[],
|
39
|
+
ping: 30
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
ws
|
44
|
+
rescue Interrupt
|
45
|
+
# Exit Gracefully if CTRL+C is Pressed During Session
|
46
|
+
Cryptum.exit_gracefully(which_self: self)
|
47
|
+
rescue StandardError => e
|
48
|
+
raise e
|
49
|
+
end
|
50
|
+
|
51
|
+
public_class_method def self.subscribe_message(opts = {})
|
52
|
+
option_choice = opts[:option_choice]
|
53
|
+
env = opts[:env]
|
54
|
+
product_id = option_choice.symbol.to_s.gsub('_', '-').upcase
|
55
|
+
|
56
|
+
api_secret = env[:api_secret]
|
57
|
+
api_signature_response = Cryptum::API.generate_signature(
|
58
|
+
api_secret: api_secret
|
59
|
+
)
|
60
|
+
api_key = env[:api_key]
|
61
|
+
api_passphrase = env[:api_passphrase]
|
62
|
+
api_timestamp = api_signature_response[:api_timestamp]
|
63
|
+
api_signature = api_signature_response[:api_signature]
|
64
|
+
|
65
|
+
"{
|
66
|
+
\"type\": \"subscribe\",
|
67
|
+
\"product_ids\": [
|
68
|
+
\"#{product_id}\"
|
69
|
+
],
|
70
|
+
\"channels\": [
|
71
|
+
\"heartbeat\",
|
72
|
+
\"level2\",
|
73
|
+
\"ticker\",
|
74
|
+
\"user\"
|
75
|
+
],
|
76
|
+
\"key\": \"#{api_key}\",
|
77
|
+
\"passphrase\": \"#{api_passphrase}\",
|
78
|
+
\"timestamp\": \"#{api_timestamp}\",
|
79
|
+
\"signature\": \"#{api_signature}\"
|
80
|
+
}"
|
81
|
+
rescue StandardError => e
|
82
|
+
raise e
|
83
|
+
end
|
84
|
+
|
85
|
+
# Display Usage for this Module
|
86
|
+
|
87
|
+
public_class_method def self.help
|
88
|
+
puts "USAGE:
|
89
|
+
logger = #{self}.create()
|
90
|
+
"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eventmachine'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Cryptum
|
7
|
+
# This plugin is used to Establish a Web
|
8
|
+
# Socket Connection with Coinbase
|
9
|
+
module WebSock
|
10
|
+
module EventMachine
|
11
|
+
# Supported Method Parameters::
|
12
|
+
# Cryptum::WS.run(
|
13
|
+
# )
|
14
|
+
public_class_method def self.run(opts = {})
|
15
|
+
env = opts[:env]
|
16
|
+
option_choice = opts[:option_choice]
|
17
|
+
terminal_win = opts[:terminal_win]
|
18
|
+
event_history = opts[:event_history]
|
19
|
+
indicator_status = opts[:indicator_status]
|
20
|
+
|
21
|
+
max_conn_attempts = 30
|
22
|
+
conn_attempt = 0
|
23
|
+
|
24
|
+
begin
|
25
|
+
conn_attempt += 1
|
26
|
+
event_history.reconnected = true if conn_attempt > 1
|
27
|
+
|
28
|
+
# Automatically Create Bot Configs if they don't
|
29
|
+
# Exist and Initialize Automated Trading Parameters
|
30
|
+
bot_conf = Cryptum.read_bot_conf(option_choice: option_choice)
|
31
|
+
|
32
|
+
EM.run do
|
33
|
+
# Iterate as fast as possible
|
34
|
+
# This ensures candle timing is accurate
|
35
|
+
# and everything is fast as possible
|
36
|
+
# Defaults to 100ms, 5ms is the lowest possible
|
37
|
+
delay_ms = 5
|
38
|
+
delay_ms_cast_as_decimal = delay_ms * 0.001
|
39
|
+
EM.set_quantum(delay_ms)
|
40
|
+
|
41
|
+
ws = Cryptum::WebSock::Coinbase.connect(
|
42
|
+
option_choice: option_choice,
|
43
|
+
env: env
|
44
|
+
)
|
45
|
+
|
46
|
+
ws.on :open do |_event|
|
47
|
+
ws.send(
|
48
|
+
Cryptum::WebSock::Coinbase.subscribe_message(
|
49
|
+
option_choice: option_choice,
|
50
|
+
env: env
|
51
|
+
)
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
ws.on :message do |event|
|
56
|
+
ai_enabled = bot_conf[:artifical_intelligence]
|
57
|
+
event_history.event = JSON.parse(
|
58
|
+
event.data,
|
59
|
+
symbolize_names: true
|
60
|
+
)
|
61
|
+
event_history.event_type = event_history.event[:type].to_s.to_sym
|
62
|
+
event_history = Cryptum::Event.parse(
|
63
|
+
env: env,
|
64
|
+
terminal_win: terminal_win,
|
65
|
+
option_choice: option_choice,
|
66
|
+
event_history: event_history,
|
67
|
+
indicator_status: indicator_status,
|
68
|
+
bot_conf: bot_conf,
|
69
|
+
ai_enabled: ai_enabled
|
70
|
+
)
|
71
|
+
|
72
|
+
# Decent for Debugging Events
|
73
|
+
# puts event_history.inspect
|
74
|
+
# Decent for Debugging MACD & RSI History
|
75
|
+
# puts indicator_status.inspect
|
76
|
+
|
77
|
+
# Detect Key Press Events
|
78
|
+
Cryptum::Event::KeyPress.detect(terminal_win: terminal_win)
|
79
|
+
|
80
|
+
# Get the F* Out (GTFO) when
|
81
|
+
# G is pressed
|
82
|
+
if terminal_win.key_press_event.key_g
|
83
|
+
event_history = Cryptum::API.gtfo(
|
84
|
+
option_choice: option_choice,
|
85
|
+
env: env,
|
86
|
+
event_history: event_history,
|
87
|
+
bot_conf: bot_conf
|
88
|
+
)
|
89
|
+
terminal_win.key_press_event.key_g = false
|
90
|
+
end
|
91
|
+
|
92
|
+
# Only Reload Bot Conf when
|
93
|
+
# R is Pressed
|
94
|
+
if terminal_win.key_press_event.key_r
|
95
|
+
bot_conf = Cryptum.read_bot_conf(option_choice: option_choice)
|
96
|
+
terminal_win.key_press_event.key_r = false
|
97
|
+
end
|
98
|
+
|
99
|
+
# Only Write Order Book to File when
|
100
|
+
# W is Pressed
|
101
|
+
if terminal_win.key_press_event.key_w
|
102
|
+
order_book_file = event_history.order_book[:path]
|
103
|
+
File.open(order_book_file, 'w') do |f|
|
104
|
+
f.puts event_history.order_book.to_json
|
105
|
+
end
|
106
|
+
terminal_win.key_press_event.key_w = false
|
107
|
+
end
|
108
|
+
|
109
|
+
# Exit if x is Pressed
|
110
|
+
if terminal_win.key_press_event.key_x
|
111
|
+
terminal_win.key_press_event.key_x = false
|
112
|
+
Cryptum.exit_gracefully(
|
113
|
+
which_self: self,
|
114
|
+
event_history: event_history,
|
115
|
+
option_choice: option_choice,
|
116
|
+
env: env
|
117
|
+
)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
ws.on :close do
|
122
|
+
raise Errno::ECONNRESET
|
123
|
+
end
|
124
|
+
|
125
|
+
EM.add_periodic_timer(delay_ms_cast_as_decimal) do
|
126
|
+
order_countdown = Cryptum::UI::OrderTimer.refresh(
|
127
|
+
option_choice: option_choice,
|
128
|
+
event_history: event_history,
|
129
|
+
order_timer_win: terminal_win.order_timer_section,
|
130
|
+
indicator_status: indicator_status,
|
131
|
+
key_press_event: terminal_win.key_press_event
|
132
|
+
)
|
133
|
+
|
134
|
+
event_history.order_ready = true if order_countdown.zero? ||
|
135
|
+
order_countdown.negative?
|
136
|
+
end
|
137
|
+
|
138
|
+
EM.add_periodic_timer(option_choice.market_trend_reset) do
|
139
|
+
Cryptum::OrderBook::MarketTrend.reset(
|
140
|
+
option_choice: option_choice,
|
141
|
+
terminal_win: terminal_win,
|
142
|
+
event_history: event_history,
|
143
|
+
bot_conf: bot_conf
|
144
|
+
)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
rescue Faye::WebSocket::API::ErrorEvent,
|
148
|
+
Errno::ECONNREFUSED,
|
149
|
+
Errno::ECONNRESET => e
|
150
|
+
|
151
|
+
File.open('/tmp/cryptum-errors.txt', 'a') do |f|
|
152
|
+
f.puts Time.now.strftime('%Y-%m-%d %H:%M:%S.%N %z')
|
153
|
+
f.puts "Module: #{self}"
|
154
|
+
f.puts "#{e}\n\n\n"
|
155
|
+
end
|
156
|
+
|
157
|
+
raise e if conn_attempt > max_conn_attempts
|
158
|
+
|
159
|
+
sleep 1
|
160
|
+
retry
|
161
|
+
end
|
162
|
+
rescue Interrupt
|
163
|
+
# Exit Gracefully if CTRL+C is Pressed During Session
|
164
|
+
Cryptum.exit_gracefully(
|
165
|
+
which_self: self,
|
166
|
+
event_history: event_history,
|
167
|
+
option_choice: option_choice,
|
168
|
+
env: env
|
169
|
+
)
|
170
|
+
rescue StandardError => e
|
171
|
+
raise e
|
172
|
+
end
|
173
|
+
|
174
|
+
# Display Usage for this Module
|
175
|
+
public_class_method def self.help
|
176
|
+
puts "USAGE:
|
177
|
+
logger = #{self}.create()
|
178
|
+
"
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cryptum
|
4
|
+
# This plugin is used to Establish a Web
|
5
|
+
# Socket Connection with Coinbase
|
6
|
+
module WebSock
|
7
|
+
autoload :Coinbase, 'cryptum/web_sock/coinbase'
|
8
|
+
autoload :EventMachine, 'cryptum/web_sock/event_machine'
|
9
|
+
|
10
|
+
# Display Usage for this Module
|
11
|
+
|
12
|
+
public_class_method def self.help
|
13
|
+
constants.sort
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/cryptum.rb
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cryptum/version'
|
4
|
+
require 'rbtrace'
|
5
|
+
require 'yaml'
|
6
|
+
require 'json'
|
7
|
+
require 'fileutils'
|
8
|
+
require 'tty-spinner'
|
9
|
+
|
10
|
+
# Root-Level Namespace for cryptum
|
11
|
+
module Cryptum
|
12
|
+
$stdout.sync = true
|
13
|
+
$stdout.flush
|
14
|
+
|
15
|
+
autoload :API, 'cryptum/api'
|
16
|
+
autoload :BotConf, 'cryptum/bot_conf'
|
17
|
+
autoload :Event, 'cryptum/event'
|
18
|
+
autoload :Indicator, 'cryptum/indicator'
|
19
|
+
autoload :Log, 'cryptum/log'
|
20
|
+
autoload :Matrix, 'cryptum/matrix'
|
21
|
+
autoload :Option, 'cryptum/option'
|
22
|
+
autoload :OrderBook, 'cryptum/order_book'
|
23
|
+
autoload :Portfolio, 'cryptum/portfolio'
|
24
|
+
autoload :ProbabilityEngine, 'cryptum/probability_engine'
|
25
|
+
autoload :UI, 'cryptum/ui'
|
26
|
+
autoload :WebSock, 'cryptum/web_sock'
|
27
|
+
|
28
|
+
public_class_method def self.bin
|
29
|
+
File.join root, 'bin'
|
30
|
+
end
|
31
|
+
|
32
|
+
public_class_method def self.etc
|
33
|
+
File.join root, 'etc'
|
34
|
+
end
|
35
|
+
|
36
|
+
public_class_method def self.lib
|
37
|
+
File.join root, 'lib'
|
38
|
+
end
|
39
|
+
|
40
|
+
public_class_method def self.order_book
|
41
|
+
File.join root, 'order_book'
|
42
|
+
end
|
43
|
+
|
44
|
+
public_class_method def self.root
|
45
|
+
File.dirname __dir__
|
46
|
+
end
|
47
|
+
|
48
|
+
public_class_method def self.open_symbol
|
49
|
+
"\u00f8"
|
50
|
+
end
|
51
|
+
|
52
|
+
public_class_method def self.up_arrow
|
53
|
+
"\u2191"
|
54
|
+
end
|
55
|
+
|
56
|
+
public_class_method def self.down_arrow
|
57
|
+
"\u2193"
|
58
|
+
end
|
59
|
+
|
60
|
+
public_class_method def self.flat_arrow
|
61
|
+
'_'
|
62
|
+
end
|
63
|
+
|
64
|
+
# Deserialize Cryptum Bot Conf
|
65
|
+
public_class_method def self.read_bot_conf(opts = {})
|
66
|
+
option_choice = opts[:option_choice]
|
67
|
+
|
68
|
+
bot_conf_file = "#{option_choice.repo_root}/etc/bot_confs/#{option_choice.symbol}_bot_conf.yaml"
|
69
|
+
unless File.exist?(bot_conf_file)
|
70
|
+
FileUtils.cp(
|
71
|
+
"#{option_choice.repo_root}/etc/bot_confs/BOT_CONF.TEMPLATE",
|
72
|
+
bot_conf_file
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
YAML.load_file(
|
77
|
+
bot_conf_file,
|
78
|
+
symbolize_names: true
|
79
|
+
)
|
80
|
+
rescue Errno::ENOENT, NoMethodError => e
|
81
|
+
File.open('/tmp/cryptum-errors.txt', 'a') do |f|
|
82
|
+
f.puts Time.now.strftime('%Y-%m-%d %H:%M:%S.%N %z')
|
83
|
+
f.puts "Module: #{self}"
|
84
|
+
f.puts "#{e}\n\n\n"
|
85
|
+
end
|
86
|
+
|
87
|
+
retry
|
88
|
+
rescue Interrupt
|
89
|
+
# Exit Gracefully if CTRL+C is Pressed During Session
|
90
|
+
Cryptum.exit_gracefully(which_self: self)
|
91
|
+
rescue StandardError => e
|
92
|
+
# Produce a Stacktrace for anything else
|
93
|
+
Curses.close_screen
|
94
|
+
raise e
|
95
|
+
end
|
96
|
+
|
97
|
+
# Update Key/Value Pair in Bot Conf and Serialize to YAML File
|
98
|
+
public_class_method def self.update_bot_conf_key(opts = {})
|
99
|
+
option_choice = opts[:option_choice]
|
100
|
+
bot_conf = opts[:bot_conf]
|
101
|
+
key = opts[:key].to_s.to_sym
|
102
|
+
value = opts[:value]
|
103
|
+
|
104
|
+
bot_conf_file = "#{option_choice.repo_root}/etc/bot_confs/#{option_choice.symbol}_bot_conf.yaml"
|
105
|
+
|
106
|
+
bot_conf[key] = value
|
107
|
+
File.write(bot_conf_file, bot_conf.to_yaml)
|
108
|
+
rescue Errno::ENOENT, NoMethodError => e
|
109
|
+
File.open('/tmp/cryptum-errors.txt', 'a') do |f|
|
110
|
+
f.puts Time.now.strftime('%Y-%m-%d %H:%M:%S.%N %z')
|
111
|
+
f.puts "Module: #{self}"
|
112
|
+
f.puts "#{e}\n\n\n"
|
113
|
+
end
|
114
|
+
|
115
|
+
retry
|
116
|
+
rescue Interrupt
|
117
|
+
# Exit Gracefully if CTRL+C is Pressed During Session
|
118
|
+
Cryptum.exit_gracefully(which_self: self)
|
119
|
+
rescue StandardError => e
|
120
|
+
# Produce a Stacktrace for anything else
|
121
|
+
Curses.close_screen
|
122
|
+
raise e
|
123
|
+
end
|
124
|
+
|
125
|
+
# Update Key/Value Pair in Bot Conf and Serialize to YAML File
|
126
|
+
public_class_method def self.beautify_large_number(opts = {})
|
127
|
+
value = opts[:value].to_s
|
128
|
+
|
129
|
+
split_str_num = value.split('.')
|
130
|
+
whole_num = split_str_num.first
|
131
|
+
fraction = 0
|
132
|
+
fraction = split_str_num.last if split_str_num.length > 1
|
133
|
+
|
134
|
+
is_negative = false
|
135
|
+
is_negative = true if whole_num.split('').first == '-'
|
136
|
+
whole_num = whole_num[1..] if is_negative
|
137
|
+
beautify_whole = whole_num.reverse.scan(/.{1,3}/).join(',').reverse
|
138
|
+
beautify_num = "#{beautify_whole}.#{fraction}" unless is_negative
|
139
|
+
beautify_num = "-#{beautify_whole}.#{fraction}" if is_negative
|
140
|
+
|
141
|
+
return beautify_num
|
142
|
+
rescue Interrupt
|
143
|
+
# Exit Gracefully if CTRL+C is Pressed During Session
|
144
|
+
Cryptum.exit_gracefully(which_self: self)
|
145
|
+
rescue StandardError => e
|
146
|
+
# Produce a Stacktrace for anything else
|
147
|
+
Curses.close_screen
|
148
|
+
raise e
|
149
|
+
end
|
150
|
+
|
151
|
+
public_class_method def self.exit_gracefully(opts = {})
|
152
|
+
which_self = opts[:which_self]
|
153
|
+
event_history = opts[:event_history]
|
154
|
+
option_choice = opts[:option_choice]
|
155
|
+
env = opts[:env]
|
156
|
+
|
157
|
+
# Clear out candle data to ensure
|
158
|
+
# Cryptum Statistics Only Apply to
|
159
|
+
# Live Sessions
|
160
|
+
if event_history
|
161
|
+
order_book_file = event_history.order_book[:path]
|
162
|
+
File.open(order_book_file, 'w') do |f|
|
163
|
+
f.puts event_history.order_book.to_json
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
Curses.close_screen
|
168
|
+
puts "Interrupt detected in #{which_self}...goodbye."
|
169
|
+
|
170
|
+
exit 0
|
171
|
+
rescue NameError
|
172
|
+
puts "\nInterrupt detected in #{which_self}...goodbye."
|
173
|
+
|
174
|
+
exit 0
|
175
|
+
rescue StandardError => e
|
176
|
+
# Produce a Stacktrace for anything else
|
177
|
+
raise e
|
178
|
+
end
|
179
|
+
|
180
|
+
public_class_method def self.help
|
181
|
+
constants.sort
|
182
|
+
end
|
183
|
+
end
|
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/bin/bash --login
|
2
|
+
# USE THIS SCRIPT WHEN UPGRADING VERSIONS IN Gemfile
|
3
|
+
if [[ $CRYPTUM_ROOT == '' ]]; then
|
4
|
+
if [[ ! -d '/opt/cryptum' ]]; then
|
5
|
+
cryptum_root=$(pwd)
|
6
|
+
else
|
7
|
+
cryptum_root='/opt/cryptum'
|
8
|
+
fi
|
9
|
+
else
|
10
|
+
cryptum_root="${CRYPTUM_ROOT}"
|
11
|
+
fi
|
12
|
+
|
13
|
+
if [[ -f '/etc/profile.d/rvm.sh' ]]; then
|
14
|
+
source /etc/profile.d/rvm.sh
|
15
|
+
fi
|
16
|
+
|
17
|
+
ruby_version=`cat ${cryptum_root}/.ruby-version`
|
18
|
+
ruby_gemset=`cat ${cryptum_root}/.ruby-gemset`
|
19
|
+
rvm use ruby-$ruby_version@global
|
20
|
+
rvm gemset --force delete $ruby_gemset
|
21
|
+
if [[ -f "${cryptum_root}/Gemfile.lock" ]]; then
|
22
|
+
rvmsudo rm $cryptum_root/Gemfile.lock
|
23
|
+
fi
|
24
|
+
|
25
|
+
rvm use ruby-$ruby_version@$ruby_gemset --create
|
26
|
+
export rvmsudo_secure_path=1
|
27
|
+
rvmsudo gem install bundler
|
28
|
+
rvmsudo bundle install
|
29
|
+
rvm --default ruby-$ruby_version@$ruby_gemset
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Cryptum::OrderBook::Generate do
|
6
|
+
it 'should display information for existing help method' do
|
7
|
+
help_response = Cryptum::OrderBook::Generate
|
8
|
+
expect(help_response).to respond_to :help
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Cryptum::OrderBook::MarketTrend do
|
6
|
+
it 'should display information for existing help method' do
|
7
|
+
help_response = Cryptum::OrderBook::MarketTrend
|
8
|
+
expect(help_response).to respond_to :help
|
9
|
+
end
|
10
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/bin/bash --login
|
2
|
+
cat Gemfile | awk '{print $2}' | grep -E "^'.+$" | grep -v -e rubygems.org | while read gem; do
|
3
|
+
this_gem=`echo $gem | sed "s/'//g" | sed 's/\,//g'`
|
4
|
+
latest_version=`gem search -r $this_gem | grep -E "^${this_gem}\s.+$" | awk '{print $2}' | sed 's/(//g' | sed 's/)//g' | sed 's/,//g'`
|
5
|
+
echo "${this_gem} => $latest_version"
|
6
|
+
os=`uname -s`
|
7
|
+
if [[ $os == 'Linux' ]]; then
|
8
|
+
if [[ $this_gem == 'bundler' ]]; then
|
9
|
+
sed -i "s/^gem '${this_gem}'.*$/gem '${this_gem}', '>=${latest_version}'/g" Gemfile
|
10
|
+
else
|
11
|
+
sed -i "s/^gem '${this_gem}'.*$/gem '${this_gem}', '${latest_version}'/g" Gemfile
|
12
|
+
fi
|
13
|
+
elif [[ $os == 'Darwin' ]]; then
|
14
|
+
if [[ $this_gem == 'bundler' ]]; then
|
15
|
+
sed -i '' "s/^gem '${this_gem}'.*$/gem '${this_gem}', '>=${latest_version}'/g" Gemfile
|
16
|
+
else
|
17
|
+
sed -i '' "s/^gem '${this_gem}'.*$/gem '${this_gem}', '${latest_version}'/g" Gemfile
|
18
|
+
fi
|
19
|
+
fi
|
20
|
+
done
|
data/upgrade_cryptum.sh
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/bin/bash --login
|
2
|
+
if [[ $CRYPTUM_ROOT == '' ]]; then
|
3
|
+
if [[ ! -d '/opt/cryptum' ]]; then
|
4
|
+
cryptum_root=$(pwd)
|
5
|
+
else
|
6
|
+
cryptum_root='/opt/cryptum'
|
7
|
+
fi
|
8
|
+
else
|
9
|
+
cryptum_root="${CRYPTUM_ROOT}"
|
10
|
+
fi
|
11
|
+
|
12
|
+
export rvmsudo_secure_path=1
|
13
|
+
rvmsudo /bin/bash --login -c "cd ${cryptum_root} && ./build_cryptum_gem.sh"
|