class Livermore::AbstractStrategy

Constants

TICK_TIME

Attributes

config[R]
context[R]

Public Class Methods

new(context, config_path) click to toggle source
# File lib/livermore/strategies/abstract_strategy.rb, line 7
def initialize(context, config_path)
  @context = context
  @config = YAML.load_file(config_path || default_config_path)
end

Public Instance Methods

method_missing(method, *args) click to toggle source
Calls superclass method
# File lib/livermore/strategies/abstract_strategy.rb, line 16
def method_missing(method, *args)
  if @context.respond_to?(method)
    @context.send(method, *args)
  else
    super
  end
end
trade() click to toggle source
# File lib/livermore/strategies/abstract_strategy.rb, line 12
def trade
  raise 'Abstract method called'
end

Private Instance Methods

default_config_path() click to toggle source
# File lib/livermore/strategies/abstract_strategy.rb, line 26
def default_config_path
  "strategies/#{underscore}.yml"
end
info() click to toggle source
# File lib/livermore/strategies/abstract_strategy.rb, line 34
def info
  raise 'Abstract method called'
end
tick() click to toggle source
# File lib/livermore/strategies/abstract_strategy.rb, line 38
def tick
  print "\033[2J"
  sleep TICK_TIME

  print info.map(&:colorize).join("\n") + "\r\033[#{info.count - 1}A"
  $stdout.flush
end
underscore() click to toggle source
# File lib/livermore/strategies/abstract_strategy.rb, line 30
def underscore
  self.class.to_s.split('::').last.gsub(/([a-z])([A-Z])/, '\1_\2').downcase
end