Module: Cryptum

Defined in:
lib/cryptum.rb,
lib/cryptum/ui.rb,
lib/cryptum/api.rb,
lib/cryptum/log.rb,
lib/cryptum/event.rb,
lib/cryptum/matrix.rb,
lib/cryptum/option.rb,
lib/cryptum/version.rb,
lib/cryptum/bot_conf.rb,
lib/cryptum/web_sock.rb,
lib/cryptum/event/buy.rb,
lib/cryptum/portfolio.rb,
lib/cryptum/ui/ticker.rb,
lib/cryptum/event/sell.rb,
lib/cryptum/order_book.rb,
lib/cryptum/ui/command.rb,
lib/cryptum/event/cancel.rb,
lib/cryptum/ui/portfolio.rb,
lib/cryptum/event/history.rb,
lib/cryptum/option/choice.rb,
lib/cryptum/ui/order_plan.rb,
lib/cryptum/ui/order_timer.rb,
lib/cryptum/event/key_press.rb,
lib/cryptum/ui/market_trend.rb,
lib/cryptum/ui/signal_engine.rb,
lib/cryptum/portfolio/balance.rb,
lib/cryptum/web_sock/coinbase.rb,
lib/cryptum/ui/key_press_event.rb,
lib/cryptum/ui/order_execution.rb,
lib/cryptum/ui/terminal_window.rb,
lib/cryptum/order_book/generate.rb,
lib/cryptum/order_book/indicator.rb,
lib/cryptum/web_sock/event_machine.rb,
lib/cryptum/order_book/market_trend.rb,
lib/cryptum/order_book/weighted_avg.rb,
lib/cryptum/order_book/profit_margin.rb

Overview

Root-Level Namespace for cryptum

Defined Under Namespace

Modules: API, BotConf, Event, Log, Matrix, Option, OrderBook, Portfolio, UI, WebSock

Constant Summary collapse

VERSION =
'0.0.243'

Class Method Summary collapse

Class Method Details

.beautify_large_number(opts = {}) ⇒ Object

Update Key/Value Pair in Bot Conf and Serialize to YAML File



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/cryptum.rb', line 126

public_class_method def self.beautify_large_number(opts = {})
  value = opts[:value].to_s

  split_str_num = value.split('.')
  whole_num = split_str_num.first
  fraction = 0
  fraction = split_str_num.last if split_str_num.length > 1

  is_negative = false
  is_negative = true if whole_num.split('').first == '-'
  whole_num = whole_num[1..] if is_negative
  beautify_whole = whole_num.reverse.scan(/.{1,3}/).join(',').reverse
  beautify_num = "#{beautify_whole}.#{fraction}" unless is_negative
  beautify_num = "-#{beautify_whole}.#{fraction}" if is_negative

  return beautify_num
rescue Interrupt
  # Exit Gracefully if CTRL+C is Pressed During Session
  Cryptum.exit_gracefully(which_self: self)
rescue StandardError => e
  # Produce a Stacktrace for anything else
  Curses.close_screen
  raise e
end

.binObject



28
29
30
# File 'lib/cryptum.rb', line 28

public_class_method def self.bin
  File.join root, 'bin'
end

.down_arrowObject



56
57
58
# File 'lib/cryptum.rb', line 56

public_class_method def self.down_arrow
  "\u2193"
end

.etcObject



32
33
34
# File 'lib/cryptum.rb', line 32

public_class_method def self.etc
  File.join root, 'etc'
end

.exit_gracefully(opts = {}) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/cryptum.rb', line 151

public_class_method def self.exit_gracefully(opts = {})
  which_self = opts[:which_self]
  event_history = opts[:event_history]
  option_choice = opts[:option_choice]
  env = opts[:env]

  # Clear out candle data to ensure
  # Cryptum Statistics Only Apply to
  # Live Sessions
  if event_history
    order_book_file = event_history.order_book[:path]
    File.open(order_book_file, 'w') do |f|
      f.puts event_history.order_book.to_json
    end
  end

  Curses.close_screen
  puts "Interrupt detected in #{which_self}...goodbye."

  exit 0
rescue NameError
  puts "\nInterrupt detected in #{which_self}...goodbye."

  exit 0
rescue StandardError => e
  # Produce a Stacktrace for anything else
  raise e
end

.flat_arrowObject



60
61
62
# File 'lib/cryptum.rb', line 60

public_class_method def self.flat_arrow
  '_'
end

.helpObject



180
181
182
# File 'lib/cryptum.rb', line 180

public_class_method def self.help
  constants.sort
end

.libObject



36
37
38
# File 'lib/cryptum.rb', line 36

public_class_method def self.lib
  File.join root, 'lib'
end

.open_symbolObject



48
49
50
# File 'lib/cryptum.rb', line 48

public_class_method def self.open_symbol
  "\u00f8"
end

.order_bookObject



40
41
42
# File 'lib/cryptum.rb', line 40

public_class_method def self.order_book
  File.join root, 'order_book'
end

.read_bot_conf(opts = {}) ⇒ Object

Deserialize Cryptum Bot Conf



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
# File 'lib/cryptum.rb', line 65

public_class_method def self.read_bot_conf(opts = {})
  option_choice = opts[:option_choice]

  bot_conf_file = "#{option_choice.repo_root}/etc/bot_confs/#{option_choice.symbol}_bot_conf.yaml"
  unless File.exist?(bot_conf_file)
    FileUtils.cp(
      "#{option_choice.repo_root}/etc/bot_confs/BOT_CONF.TEMPLATE",
      bot_conf_file
    )
  end

  YAML.load_file(
    bot_conf_file,
    symbolize_names: true
  )
rescue Errno::ENOENT, NoMethodError => e
  File.open('/tmp/cryptum-errors.txt', 'a') do |f|
    f.puts Time.now.strftime('%Y-%m-%d %H:%M:%S.%N %z')
    f.puts "Module: #{self}"
    f.puts "#{e}\n\n\n"
  end

  retry
rescue Interrupt
  # Exit Gracefully if CTRL+C is Pressed During Session
  Cryptum.exit_gracefully(which_self: self)
rescue StandardError => e
  # Produce a Stacktrace for anything else
  Curses.close_screen
  raise e
end

.rootObject



44
45
46
# File 'lib/cryptum.rb', line 44

public_class_method def self.root
  File.dirname __dir__
end

.up_arrowObject



52
53
54
# File 'lib/cryptum.rb', line 52

public_class_method def self.up_arrow
  "\u2191"
end

.update_bot_conf_key(opts = {}) ⇒ Object

Update Key/Value Pair in Bot Conf and Serialize to YAML File



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
# File 'lib/cryptum.rb', line 98

public_class_method def self.update_bot_conf_key(opts = {})
  option_choice = opts[:option_choice]
  bot_conf = opts[:bot_conf]
  key = opts[:key].to_s.to_sym
  value = opts[:value]

  bot_conf_file = "#{option_choice.repo_root}/etc/bot_confs/#{option_choice.symbol}_bot_conf.yaml"

  bot_conf[key] = value
  File.write(bot_conf_file, bot_conf.to_yaml)
rescue Errno::ENOENT, NoMethodError => e
  File.open('/tmp/cryptum-errors.txt', 'a') do |f|
    f.puts Time.now.strftime('%Y-%m-%d %H:%M:%S.%N %z')
    f.puts "Module: #{self}"
    f.puts "#{e}\n\n\n"
  end

  retry
rescue Interrupt
  # Exit Gracefully if CTRL+C is Pressed During Session
  Cryptum.exit_gracefully(which_self: self)
rescue StandardError => e
  # Produce a Stacktrace for anything else
  Curses.close_screen
  raise e
end