cryptum 0.0.315 → 0.0.317

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: 5782ff4633552d6cde3f64425b5b51f03582a75d6c11554583468c8f63250720
4
- data.tar.gz: 9f2dd4006140a57225b7cfbf6ea4a58bce3953de8ffd2ddc408e65699ed89bb9
3
+ metadata.gz: 21019d21efe2f9b6f57931e4ecd21f1758ef861a20af354c7e43c6ec063ece44
4
+ data.tar.gz: 49f15b9df605188849e95939d592697137b5535604bb91e7cc3b20fe36d6dbdc
5
5
  SHA512:
6
- metadata.gz: 1bb9a76cd89fdecda6135b5e68371b062a71b565e8e786f330361a2b21e9cf5a65f4b29cd2bfa496ac7ac3acd28883686779af458be1e92588b273d9e8b5ccfa
7
- data.tar.gz: 6b581cb215d04766cbdc1d20cbeda2b34bc577ad9c8bd6b407b74184a376a958f2a7f718de4dc4e956bba39ced88ea27bae602d98346bb041c65eaba2d4d5804
6
+ metadata.gz: fab20878493d8432e677f334e847ff48458b54b220dd7d9d36a40097885f765476d519b0127156e26cb03c68e9574b979aaa383945f67242c28a747f912e8a49
7
+ data.tar.gz: '03891b81736314f1506f7491ff4e6e19a14f453f5277b1a76c4900a024e24d21939d52bf2b4768dc625190f70d666132eef33df413325c586427e423ab584cab'
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) to preserve
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
- bot_conf: bot_conf,
44
- terminal_win: terminal_win
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
- # is Generated via Coinbase Pro
48
+ # Generated via Coinbase Pro
51
49
  # Web Socket HTTP Responses
52
50
  # Refresh UI with Event Data
53
51
  # Update "Status Indicators"
@@ -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
- Cryptum.read_bot_conf(option_choice: option_choice)
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
@@ -19,7 +19,6 @@ module Cryptum
19
19
  start_time = opts[:start_time]
20
20
  option_choice = opts[:option_choice]
21
21
  env = opts[:env]
22
- # bot_conf = opts[:bot_conf]
23
22
 
24
23
  order_book_file = "#{option_choice.repo_root}/order_books/#{option_choice.symbol}.ORDER_BOOK.json"
25
24
 
@@ -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
@@ -294,7 +294,6 @@ module Cryptum
294
294
  string: red_pill_alert
295
295
  )
296
296
 
297
- order_plan_win.setpos(out_line_no, Cryptum::UI.col_fourth)
298
297
  Cryptum::UI.colorize(
299
298
  ui_win: order_plan_win,
300
299
  color: :red,
@@ -410,7 +409,7 @@ module Cryptum
410
409
  style: style,
411
410
  string: "#{order_plan_invest}#{order_plan_return}".ljust(col_just1, '.')
412
411
  )
413
- order_plan_win.setpos(out_line_no, Cryptum::UI.col_fourth)
412
+
414
413
  Cryptum::UI.colorize(
415
414
  ui_win: order_plan_win,
416
415
  color: plan_color,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cryptum
4
- VERSION = '0.0.315'
4
+ VERSION = '0.0.317'
5
5
  end
@@ -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
- # 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
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
 
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.315
4
+ version: 0.0.317
5
5
  platform: ruby
6
6
  authors:
7
7
  - 0day Inc.