Class: Fsxtrader::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/fsxtrader/application.rb

Instance Method Summary collapse

Constructor Details

#initializeApplication

Initializes a new Fsxtrader::Application object.

Note: this should always get called via a Singleton in the main Fsxtrader module as such: Fsxtrader.application.run



10
11
# File 'lib/fsxtrader/application.rb', line 10

def initialize
end

Instance Method Details

#editObject

Edit the fsx trader config file (using the system editor)



79
80
81
82
83
# File 'lib/fsxtrader/application.rb', line 79

def edit
  puts "Editing FSX Trader..."
  editor = ENV['editor'] || 'vi'
  system "#{editor} #{self.default_config_path}"
end

#goObject

Runs the main FSX Trader application

  • loads config file and checks for trade triggers

  • pulls down any applicable stock quotes

  • makes trades if any trade conditions have been met



89
90
91
92
# File 'lib/fsxtrader/application.rb', line 89

def go
  puts "Running FSX Trader..."
  trader = Fsxtrader::Trader.new(@options)
end

#helpObject

Displays the help text



49
50
51
# File 'lib/fsxtrader/application.rb', line 49

def help
  puts help_txt
end

#runObject

Main FSX Trader Application entry point.

  • Parses command-line options and calls methods accordingly



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
44
45
46
# File 'lib/fsxtrader/application.rb', line 15

def run
  @options = CoolOptions.parse!("[options] (setup|edit|help|run)") do |o|
    o.desc help_txt
    o.on "(v)erbose",              "Turn on verbose mode",                                       false
    o.on "config-path PATH",       "Path to config file",        self.default_config_path

    o.after do |r|
      if (r.config_path == self.default_config_path) && !File.exist?(self.default_config_path)
        setup
        exit
      end
      unless File.exist?(r.config_path)
        o.error("\nERROR: Invalid config file path: #{r.config_path}\nRun 'fsxtrader setup' to create the default config file.")
      end
      r.action = ARGV.shift || 'run'
    end
  end

  case @options.action
  when 'setup'
    setup
  when 'edit'
    edit
  when 'run'
    go
  when 'help'
    help
  else
    help
  end

end

#setupObject

Creates the default config file in: ~/fsx_config.yml



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fsxtrader/application.rb', line 54

def setup
  File.open(self.default_config_path, 'w') do |f|
    f.puts self.sample_config
  end

  puts '
Default config file has been created in:

  ~/.fsx_config.yml

Edit this file with any text editor or run:

  fsxtrader edit

Note: Be sure to edit your Facebook credentials in the config file!


To run FSX Trader and trigger actionable trades:

  fsxtrader

'
end