Module: Cryptum::BotConf
- Defined in:
- lib/cryptum/bot_conf.rb
Overview
This plugin is used to read and update bot conf files.
Class Method Summary collapse
-
.help ⇒ Object
Display Usage for this Module.
-
.read(opts = {}) ⇒ Object
Deserialize Cryptum Bot Conf.
-
.recalculate_tpm(opts = {}) ⇒ Object
SAUCE 1 Calculate Target Profit Margin Percent Based Upon Observed Margins of Change in the Past 24hrs.
-
.update(opts = {}) ⇒ Object
Update Key/Value Pair in Bot Conf and Serialize to YAML File.
Class Method Details
.help ⇒ Object
Display Usage for this Module
165 166 167 168 |
# File 'lib/cryptum/bot_conf.rb', line 165 public_class_method def self.help puts "USAGE: " end |
.read(opts = {}) ⇒ Object
Deserialize Cryptum Bot Conf
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cryptum/bot_conf.rb', line 7 public_class_method def self.read(opts = {}) option_choice = opts[:option_choice] event_history = opts[:event_history] session_root = option_choice.session_root symbol = option_choice.symbol bot_conf_file = "#{session_root}/etc/bot_confs/#{symbol}_bot_conf.yaml" unless File.exist?(bot_conf_file) FileUtils.cp( "#{session_root}/etc/bot_confs/BOT_CONF.TEMPLATE", bot_conf_file ) end bot_conf = YAML.load_file( bot_conf_file, symbolize_names: true ) ai_enabled = bot_conf[:artifical_intelligence] if ai_enabled && event_history bot_conf = Cryptum::BotConf.recalculate_tpm( option_choice: option_choice, event_history: event_history, bot_conf: bot_conf ) end bot_conf rescue Errno::ENOENT, NoMethodError => e Cryptum::Log.append(level: :error, msg: e, which_self: self, event_history: event_history) retry rescue Interrupt, StandardError => e # Produce a Stacktrace for anything else Cryptum::Log.append(level: :error, msg: e, which_self: self, event_history: event_history) end |
.recalculate_tpm(opts = {}) ⇒ Object
SAUCE 1 Calculate Target Profit Margin Percent Based Upon Observed Margins of Change in the Past 24hrs.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/cryptum/bot_conf.rb', line 48 public_class_method def self.recalculate_tpm(opts = {}) option_choice = opts[:option_choice] event_history = opts[:event_history] bot_conf = opts[:bot_conf] # BE EXTREMELY CAREFUL CHANGING THIS VALUE AS IT DICTATES # THE TARGET PRICE AND SUBSEQUENT TIME IT TAKES FOR AN OPEN # SELL ORDER TO BE TRIGGERED!!! SHOULD NEVER BE > 1 gross_tpm = bot_conf[:target_profit_margin_percent].to_f fees = event_history.order_book[:fees] maker_rate = 0.004 maker_rate = fees[:maker_fee_rate].to_f unless fees.empty? taker_rate = 0.006 taker_rate = fees[:taker_fee_rate].to_f unless fees.empty? # Absolute Bare Minimum TPM (Promotes Volume & Reduces Fees) default_net_tpm = 1.0 + (maker_rate + taker_rate) # Set default_net_tpm if AI is true in bot_conf. low_24h = event_history.order_book[:low_24h].to_f high_24h = event_history.order_book[:high_24h].to_f case option_choice.market_trend_reset when 604_800 # 1W Chart ai_net_tpm = ((1 - (low_24h / high_24h)) * 100) * 7 when 86_400 # 1D Chart ai_net_tpm = (1 - (low_24h / high_24h)) * 100 when 14_400 # 4H Chart ai_net_tpm = ((1 - (low_24h / high_24h)) * 100) / 6 when 10_800 # 3H Chart ai_net_tpm = ((1 - (low_24h / high_24h)) * 100) / 8 when 7_200 # 2H Chart ai_net_tpm = ((1 - (low_24h / high_24h)) * 100) / 12 when 3_600 # 1H Chart ai_net_tpm = ((1 - (low_24h / high_24h)) * 100) / 24 when 2_700 # 45m Chart ai_net_tpm = (((1 - (low_24h / high_24h)) * 100) / 24) * 0.75 when 1_800 # 30m Chart ai_net_tpm = (((1 - (low_24h / high_24h)) * 100) / 24) * 0.5 when 900 # 15m Chart ai_net_tpm = (((1 - (low_24h / high_24h)) * 100) / 24) * 0.25 when 300 # 5m Chart ai_net_tpm = (((1 - (low_24h / high_24h)) * 100) / 24) * 0.083 when 180 # 3m Chart ai_net_tpm = (((1 - (low_24h / high_24h)) * 100) / 24) * 0.05 when 60 # 1m Chart ai_net_tpm = (((1 - (low_24h / high_24h)) * 100) / 24) * 0.017 end conservative_tpm_hedge = 0.75 ai_net_tpm *= conservative_tpm_hedge default_net_tpm = ai_net_tpm if ai_net_tpm > default_net_tpm min_gross_tpm = format( '%0.2f', default_net_tpm ) if min_gross_tpm != gross_tpm.to_s bot_conf[:target_profit_margin_percent] = min_gross_tpm.to_f Cryptum::BotConf.update( option_choice: option_choice, bot_conf: bot_conf, key: :target_profit_margin_percent, value: min_gross_tpm.to_f ) end bot_conf rescue Errno::ENOENT, NoMethodError => e Cryptum::Log.append(level: :error, msg: e, which_self: self, event_history: event_history) retry rescue Interrupt, StandardError => e # Produce a Stacktrace for anything else Cryptum::Log.append(level: :error, msg: e, which_self: self, event_history: event_history) end |
.update(opts = {}) ⇒ Object
Update Key/Value Pair in Bot Conf and Serialize to YAML File
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/cryptum/bot_conf.rb', line 141 public_class_method def self.update(opts = {}) option_choice = opts[:option_choice] event_history = opts[:event_history] bot_conf = opts[:bot_conf] key = opts[:key].to_s.to_sym value = opts[:value] session_root = option_choice.session_root symbol = option_choice.symbol bot_conf_file = "#{session_root}/etc/bot_confs/#{symbol}_bot_conf.yaml" bot_conf[key] = value File.write(bot_conf_file, bot_conf.to_yaml) rescue Errno::ENOENT, NoMethodError => e Cryptum::Log.append(level: :error, msg: e, which_self: self, event_history: event_history) retry rescue Interrupt, StandardError => e # Produce a Stacktrace for anything else Cryptum::Log.append(level: :error, msg: e, which_self: self, event_history: event_history) end |