cryptum 0.0.315 → 0.0.316
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/cryptum +10 -12
- data/lib/cryptum/bot_conf.rb +116 -1
- data/lib/cryptum/event/bot_conf.rb +5 -1
- data/lib/cryptum/order_book/generate.rb +0 -1
- data/lib/cryptum/order_book/market_trend.rb +0 -82
- data/lib/cryptum/version.rb +1 -1
- data/lib/cryptum/web_sock/event_machine.rb +2 -13
- data/lib/cryptum.rb +1 -62
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff0744e9eb4220001908e4fdf5f93d9a0b5ebb8e223df6bbe376b959b79f940c
|
4
|
+
data.tar.gz: 4135f6a98003e8f014eb907b3ad2797ea6207553e6f00e39e0b5794828d223df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ee568899797cb81ffe7c99cb75d1b480ed2707e1cccca6e6da7e0f2a09bdb53fa1ccd542b6de47eb24c68450613e581b951828c04b6dd8d1cd2728b05315116
|
7
|
+
data.tar.gz: a35534a28bb3aa8dd0bf81b8a8bd8c415217d8bd56ad3fcb2ea79c47506a5347b9cc230acc0ffcbe3f1fe57a2e646cb48ff114bb1e3ec969b2a012df83798468
|
data/bin/cryptum
CHANGED
@@ -24,30 +24,28 @@ begin
|
|
24
24
|
# Instantiate Our Status Indicators & History Objects
|
25
25
|
indicator_status = Cryptum::OrderBook::Indicator.new
|
26
26
|
|
27
|
-
# Automatically Create Bot Confs if they don't
|
28
|
-
# Exist and Initialize Automated Trading Parameters
|
29
|
-
bot_conf = Cryptum::BotConf.read(option_choice: option_choice)
|
30
|
-
|
31
27
|
# Initialize Curses UI
|
32
28
|
terminal_win = Cryptum::UI.init
|
33
29
|
|
34
30
|
# Generate an Order Book for Session Tracking
|
35
31
|
# Load previous order_book_justification from
|
36
|
-
# Order Book File (if it exists)
|
37
|
-
# Order Tags and load last 180 candles from
|
38
|
-
# Coinbase
|
32
|
+
# Order Book File (if it exists)
|
39
33
|
event_history = Cryptum::OrderBook::Generate.new_order_book(
|
40
34
|
start_time: start_time,
|
41
35
|
option_choice: option_choice,
|
42
|
-
env: env
|
43
|
-
|
44
|
-
|
36
|
+
env: env
|
37
|
+
)
|
38
|
+
|
39
|
+
# Automatically Create Bot Confs if they don't
|
40
|
+
# Exist and Initialize Automated Trading Parameters
|
41
|
+
bot_conf = Cryptum::BotConf.read(
|
42
|
+
option_choice: option_choice,
|
43
|
+
event_history: event_history
|
45
44
|
)
|
46
|
-
terminal_win.key_press_event.key_w = true
|
47
45
|
|
48
46
|
# Connect to WebSocket
|
49
47
|
# Trigger Events as Event Data
|
50
|
-
#
|
48
|
+
# Generated via Coinbase Pro
|
51
49
|
# Web Socket HTTP Responses
|
52
50
|
# Refresh UI with Event Data
|
53
51
|
# Update "Status Indicators"
|
data/lib/cryptum/bot_conf.rb
CHANGED
@@ -8,6 +8,7 @@ module Cryptum
|
|
8
8
|
# Deserialize Cryptum Bot Conf
|
9
9
|
public_class_method def self.read(opts = {})
|
10
10
|
option_choice = opts[:option_choice]
|
11
|
+
event_history = opts[:event_history]
|
11
12
|
|
12
13
|
bot_conf_file = "#{option_choice.repo_root}/etc/bot_confs/#{option_choice.symbol}_bot_conf.yaml"
|
13
14
|
unless File.exist?(bot_conf_file)
|
@@ -17,10 +18,123 @@ module Cryptum
|
|
17
18
|
)
|
18
19
|
end
|
19
20
|
|
20
|
-
YAML.load_file(
|
21
|
+
bot_conf = YAML.load_file(
|
21
22
|
bot_conf_file,
|
22
23
|
symbolize_names: true
|
23
24
|
)
|
25
|
+
|
26
|
+
ai_enabled = bot_conf[:artifical_intelligence]
|
27
|
+
if ai_enabled && event_history
|
28
|
+
bot_conf = Cryptum::BotConf.recalculate_tpm(
|
29
|
+
option_choice: option_choice,
|
30
|
+
event_history: event_history,
|
31
|
+
bot_conf: bot_conf
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
bot_conf
|
36
|
+
rescue Errno::ENOENT, NoMethodError => e
|
37
|
+
File.open('/tmp/cryptum-errors.txt', 'a') do |f|
|
38
|
+
f.puts Time.now.strftime('%Y-%m-%d %H:%M:%S.%N %z')
|
39
|
+
f.puts "Module: #{self}"
|
40
|
+
f.puts "#{e}\n\n\n"
|
41
|
+
end
|
42
|
+
|
43
|
+
retry
|
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
|
+
# Produce a Stacktrace for anything else
|
49
|
+
Curses.close_screen
|
50
|
+
raise e
|
51
|
+
end
|
52
|
+
|
53
|
+
# Update Key/Value Pair in Bot Conf and Serialize to YAML File
|
54
|
+
public_class_method def self.recalculate_tpm(opts = {})
|
55
|
+
option_choice = opts[:option_choice]
|
56
|
+
event_history = opts[:event_history]
|
57
|
+
bot_conf = opts[:bot_conf]
|
58
|
+
|
59
|
+
# BE EXTREMELY CAREFUL CHANGING THIS VALUE AS IT DICTATES
|
60
|
+
# THE TARGET PRICE AND SUBSEQUENT TIME IT TAKES FOR AN OPEN
|
61
|
+
# SELL ORDER TO BE TRIGGERED!!! SHOULD NEVER BE > 1
|
62
|
+
default_net_tpm = 1.0
|
63
|
+
maker_rate = 0.4
|
64
|
+
taker_rate = 0.6
|
65
|
+
|
66
|
+
gross_tpm = bot_conf[:target_profit_margin_percent].to_f
|
67
|
+
|
68
|
+
# Refactor TPM to be 1.0 > than fee tier,
|
69
|
+
# particularly as fee tier goes up or down
|
70
|
+
fees = event_history.order_book[:fees]
|
71
|
+
maker_rate = fees[:maker_fee_rate].to_f unless fees.empty?
|
72
|
+
# maker_fee = format('%0.2f', maker_rate * 100)
|
73
|
+
|
74
|
+
taker_rate = fees[:taker_fee_rate].to_f unless fees.empty?
|
75
|
+
# taker_fee = format('%0.2f', taker_rate * 100)
|
76
|
+
|
77
|
+
# Set default_net_tpm if AI is true in bot_conf.
|
78
|
+
low_24h = event_history.order_book[:low_24h].to_f
|
79
|
+
high_24h = event_history.order_book[:high_24h].to_f
|
80
|
+
|
81
|
+
case option_choice.market_trend_reset
|
82
|
+
when 604_800
|
83
|
+
# 1W Chart
|
84
|
+
ai_net_tpm = ((1 - (low_24h / high_24h)) * 100) * 7
|
85
|
+
when 86_400
|
86
|
+
# 1D Chart
|
87
|
+
ai_net_tpm = (1 - (low_24h / high_24h)) * 100
|
88
|
+
when 14_400
|
89
|
+
# 4H Chart
|
90
|
+
ai_net_tpm = ((1 - (low_24h / high_24h)) * 100) / 6
|
91
|
+
when 10_800
|
92
|
+
# 3H Chart
|
93
|
+
ai_net_tpm = ((1 - (low_24h / high_24h)) * 100) / 8
|
94
|
+
when 7_200
|
95
|
+
# 2H Chart
|
96
|
+
ai_net_tpm = ((1 - (low_24h / high_24h)) * 100) / 12
|
97
|
+
when 3_600
|
98
|
+
# 1H Chart
|
99
|
+
ai_net_tpm = ((1 - (low_24h / high_24h)) * 100) / 24
|
100
|
+
when 2_700
|
101
|
+
# 45m Chart
|
102
|
+
ai_net_tpm = (((1 - (low_24h / high_24h)) * 100) / 24) * 0.75
|
103
|
+
when 1_800
|
104
|
+
# 30m Chart
|
105
|
+
ai_net_tpm = (((1 - (low_24h / high_24h)) * 100) / 24) * 0.5
|
106
|
+
when 900
|
107
|
+
# 15m Chart
|
108
|
+
ai_net_tpm = (((1 - (low_24h / high_24h)) * 100) / 24) * 0.25
|
109
|
+
when 300
|
110
|
+
# 5m Chart
|
111
|
+
ai_net_tpm = (((1 - (low_24h / high_24h)) * 100) / 24) * 0.083
|
112
|
+
when 180
|
113
|
+
# 3m Chart
|
114
|
+
ai_net_tpm = (((1 - (low_24h / high_24h)) * 100) / 24) * 0.05
|
115
|
+
when 60
|
116
|
+
# 1m Chart
|
117
|
+
ai_net_tpm = (((1 - (low_24h / high_24h)) * 100) / 24) * 0.017
|
118
|
+
end
|
119
|
+
|
120
|
+
default_net_tpm = ai_net_tpm if ai_net_tpm > default_net_tpm
|
121
|
+
|
122
|
+
min_gross_tpm = format(
|
123
|
+
'%0.2f',
|
124
|
+
(maker_rate.to_f + taker_rate.to_f) + default_net_tpm
|
125
|
+
)
|
126
|
+
|
127
|
+
if min_gross_tpm != gross_tpm.to_s
|
128
|
+
bot_conf[:target_profit_margin_percent] = min_gross_tpm.to_f
|
129
|
+
Cryptum::BotConf.update(
|
130
|
+
option_choice: option_choice,
|
131
|
+
bot_conf: bot_conf,
|
132
|
+
key: :target_profit_margin_percent,
|
133
|
+
value: min_gross_tpm.to_f
|
134
|
+
)
|
135
|
+
end
|
136
|
+
|
137
|
+
bot_conf
|
24
138
|
rescue Errno::ENOENT, NoMethodError => e
|
25
139
|
File.open('/tmp/cryptum-errors.txt', 'a') do |f|
|
26
140
|
f.puts Time.now.strftime('%Y-%m-%d %H:%M:%S.%N %z')
|
@@ -65,6 +179,7 @@ module Cryptum
|
|
65
179
|
Curses.close_screen
|
66
180
|
raise e
|
67
181
|
end
|
182
|
+
|
68
183
|
# Display Usage for this Module
|
69
184
|
|
70
185
|
public_class_method def self.help
|
@@ -14,7 +14,11 @@ module Cryptum
|
|
14
14
|
|
15
15
|
event_history.recalculate_order_plan = true
|
16
16
|
terminal_win.key_press_event.key_r = false
|
17
|
-
|
17
|
+
|
18
|
+
Cryptum::BotConf.read(
|
19
|
+
option_choice: option_choice,
|
20
|
+
event_history: event_history
|
21
|
+
)
|
18
22
|
rescue StandardError => e
|
19
23
|
raise e
|
20
24
|
end
|
@@ -65,13 +65,8 @@ module Cryptum
|
|
65
65
|
public_class_method def self.reset(opts = {})
|
66
66
|
# IT IS ABSOLUTELY CRITICAL THIS METHOD IS AS FAST AS POSSIBLE
|
67
67
|
# TO AVOID TICKER PRICE SYNCING ISSUES.
|
68
|
-
option_choice = opts[:option_choice]
|
69
|
-
# terminal_win = opts[:terminal_win]
|
70
68
|
event_history = opts[:event_history]
|
71
|
-
bot_conf = opts[:bot_conf]
|
72
69
|
|
73
|
-
ai_enabled = bot_conf[:artifical_intelligence]
|
74
|
-
gross_tpm = bot_conf[:target_profit_margin_percent].to_f
|
75
70
|
# order_history = event_history.order_book[:order_history]
|
76
71
|
# order_history_meta = event_history.order_book[:order_history_meta]
|
77
72
|
|
@@ -109,83 +104,6 @@ module Cryptum
|
|
109
104
|
# end
|
110
105
|
# event_history.order_book[:order_history_meta] = order_history_meta
|
111
106
|
|
112
|
-
# Refactor TPM to be 0.01 > than fee tier,
|
113
|
-
# particularly as fee tier goes up or down
|
114
|
-
fees = event_history.order_book[:fees]
|
115
|
-
maker_rate = 0.4
|
116
|
-
maker_rate = fees[:maker_fee_rate].to_f unless fees.empty?
|
117
|
-
maker_fee = format('%0.2f', maker_rate * 100)
|
118
|
-
|
119
|
-
taker_rate = 0.6
|
120
|
-
taker_rate = fees[:taker_fee_rate].to_f unless fees.empty?
|
121
|
-
taker_fee = format('%0.2f', taker_rate * 100)
|
122
|
-
# BE EXTREMELY CAREFUL CHANGING THIS VALUE AS IT DICTATES
|
123
|
-
# THE TARGET PRICE AND SUBSEQUENT TIME IT TAKES FOR AN OPEN
|
124
|
-
# SELL ORDER TO BE TRIGGERED!!! SHOULD NEVER BE > 1
|
125
|
-
default_net_tpm = 1
|
126
|
-
|
127
|
-
if ai_enabled
|
128
|
-
# Set default_net_tpm if AI is true in bot_conf.
|
129
|
-
low_24h = event_history.order_book[:low_24h].to_f
|
130
|
-
high_24h = event_history.order_book[:high_24h].to_f
|
131
|
-
|
132
|
-
case option_choice.market_trend_reset
|
133
|
-
when 604_800
|
134
|
-
# 1W Chart
|
135
|
-
ai_net_tpm = ((1 - (low_24h / high_24h)) * 100) * 7
|
136
|
-
when 86_400
|
137
|
-
# 1D Chart
|
138
|
-
ai_net_tpm = (1 - (low_24h / high_24h)) * 100
|
139
|
-
when 14_400
|
140
|
-
# 4H Chart
|
141
|
-
ai_net_tpm = ((1 - (low_24h / high_24h)) * 100) / 6
|
142
|
-
when 10_800
|
143
|
-
# 3H Chart
|
144
|
-
ai_net_tpm = ((1 - (low_24h / high_24h)) * 100) / 8
|
145
|
-
when 7_200
|
146
|
-
# 2H Chart
|
147
|
-
ai_net_tpm = ((1 - (low_24h / high_24h)) * 100) / 12
|
148
|
-
when 3_600
|
149
|
-
# 1H Chart
|
150
|
-
ai_net_tpm = ((1 - (low_24h / high_24h)) * 100) / 24
|
151
|
-
when 2_700
|
152
|
-
# 45m Chart
|
153
|
-
ai_net_tpm = (((1 - (low_24h / high_24h)) * 100) / 24) * 0.75
|
154
|
-
when 1_800
|
155
|
-
# 30m Chart
|
156
|
-
ai_net_tpm = (((1 - (low_24h / high_24h)) * 100) / 24) * 0.5
|
157
|
-
when 900
|
158
|
-
# 15m Chart
|
159
|
-
ai_net_tpm = (((1 - (low_24h / high_24h)) * 100) / 24) * 0.25
|
160
|
-
when 300
|
161
|
-
# 5m Chart
|
162
|
-
ai_net_tpm = (((1 - (low_24h / high_24h)) * 100) / 24) * 0.083
|
163
|
-
when 180
|
164
|
-
# 3m Chart
|
165
|
-
ai_net_tpm = (((1 - (low_24h / high_24h)) * 100) / 24) * 0.05
|
166
|
-
when 60
|
167
|
-
# 1m Chart
|
168
|
-
ai_net_tpm = (((1 - (low_24h / high_24h)) * 100) / 24) * 0.017
|
169
|
-
end
|
170
|
-
|
171
|
-
default_net_tpm = ai_net_tpm if ai_net_tpm > default_net_tpm
|
172
|
-
end
|
173
|
-
|
174
|
-
min_gross_tpm = format(
|
175
|
-
'%0.2f',
|
176
|
-
(maker_fee.to_f + taker_fee.to_f) + default_net_tpm
|
177
|
-
)
|
178
|
-
|
179
|
-
if ai_enabled && min_gross_tpm != gross_tpm.to_s
|
180
|
-
bot_conf[:target_profit_margin_percent] = min_gross_tpm.to_f
|
181
|
-
Cryptum::BotConf.update(
|
182
|
-
option_choice: option_choice,
|
183
|
-
bot_conf: bot_conf,
|
184
|
-
key: :target_profit_margin_percent,
|
185
|
-
value: min_gross_tpm.to_f
|
186
|
-
)
|
187
|
-
end
|
188
|
-
|
189
107
|
# Reset Market Trend Counter
|
190
108
|
event_history.order_book[:market_trend][:buy] = 0
|
191
109
|
event_history.order_book[:market_trend][:sell] = 0
|
data/lib/cryptum/version.rb
CHANGED
@@ -17,6 +17,7 @@ module Cryptum
|
|
17
17
|
terminal_win = opts[:terminal_win]
|
18
18
|
event_history = opts[:event_history]
|
19
19
|
indicator_status = opts[:indicator_status]
|
20
|
+
bot_conf = opts[:bot_conf]
|
20
21
|
|
21
22
|
max_conn_attempts = 30
|
22
23
|
conn_attempt = 0
|
@@ -25,10 +26,6 @@ module Cryptum
|
|
25
26
|
conn_attempt += 1
|
26
27
|
event_history.reconnected = true if conn_attempt > 1
|
27
28
|
|
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
29
|
EM.run do
|
33
30
|
# Iterate as fast as possible
|
34
31
|
# This ensures candle timing is accurate
|
@@ -215,19 +212,11 @@ module Cryptum
|
|
215
212
|
# Reload Bot Conf (i.e. Risk Allocation),
|
216
213
|
# Recalculate Order Plan, and Write to File
|
217
214
|
terminal_win.key_press_event.key_r = true
|
218
|
-
|
219
|
-
# Write Order Book to Disk
|
220
|
-
# terminal_win.key_press_event.key_w = true
|
221
215
|
end
|
222
216
|
end
|
223
217
|
|
224
218
|
EM.add_periodic_timer(option_choice.market_trend_reset) do
|
225
|
-
Cryptum::OrderBook::MarketTrend.reset(
|
226
|
-
option_choice: option_choice,
|
227
|
-
terminal_win: terminal_win,
|
228
|
-
event_history: event_history,
|
229
|
-
bot_conf: bot_conf
|
230
|
-
)
|
219
|
+
Cryptum::OrderBook::MarketTrend.reset(event_history: event_history)
|
231
220
|
|
232
221
|
# Reload Bot Conf (i.e. Risk Allocation)
|
233
222
|
# Recalculate Order Plan, and Write to File
|
data/lib/cryptum.rb
CHANGED
@@ -61,68 +61,7 @@ module Cryptum
|
|
61
61
|
'_'
|
62
62
|
end
|
63
63
|
|
64
|
-
#
|
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
|
64
|
+
# Add Commas to Large Numbers to Make it Easier to Read
|
126
65
|
public_class_method def self.beautify_large_number(opts = {})
|
127
66
|
value = opts[:value].to_s
|
128
67
|
|