Class: TradeOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/trades/options.rb

Constant Summary collapse

MARKETS =

Define markets, market aliases and currencies

%w[mtgoxUSD thUSD mtgoxEUR virwoxSLL mtgoxGBP intrsngGBP 
virtexCAD btceUSD cbxUSD btcexUSD btcdeEUR wbxAUD mtgoxRUB bitmarketEUR 
mtgoxPLN thEUR mtgoxCAD intrsngUSD mtgoxAUD intrsngEUR btcnCNY thAUD 
bitstampUSD mtgoxHKD intsngPLN bitmarketUSD bitnzNZD thLRUSD thINR rockSSL 
mtgoxSGD b2cUSD aqoinEUR mtgoxSEK ruxumUSD thCLP mrcdBRL mtgoxCNY mtgoxCHF 
mtgoxDKK bitfloorUSD ruxumJPY bitmarketAUD mtgoxJPY ruxumZAR bitmarketPLN 
ruxumSEK ruxumRUB rockEUR mtgoxNZD rockUSD ruxumCHF bbmBRL globalPLN 
globalGBP bitmarketRUB ruxumHUF mtgoxTHB ruxumAUD ruxumEUR globalEUR 
bitmarketGBP ruxumGBP ruxumPLN ruxumSGD ruxumTHB ruxumUAH globalUSD]
ALIASES =
{"mtgox" => "mtgoxUSD", "th" => "thUSD", "tradehill" => "thUSD"}
CURRENCIES =
{
  "usd" => "USD", "dollar" => "USD", "us" => "USD",
  "eur" => "EUR", "euro" => "EUR", "euros" => "EUR",
  "gbp" => "GBP", "pound" => "GBP",
  "ssl" => "SSL", "secondlife" => "SSL",
  "cny" => "CNY", 
  "cad" => "CAD", "canadian" => "CAD",
  "aud" => "AUD", "australian" => "AUD", "aus" => "AUD",
  "rub" => "RUB", "russian" => "RUB", "rubble" => "RUB",
  "pln" => "PLN", "polish" => "PLN",
  "hkd" => "HKD", "hongkong" => "HKD",
  "nzd" => "NZD", "newzealand" => "NZD", "nz" => "NZD",
  "sgd" => "SGD",
  "sek" => "SEK",
  "clp" => "CLP",
  "brl" => "BRL",
  "chf" => "CHF",
  "dkk" => "DKK",
  "jpy" => "JPY", "yen" => "JPY", "japan" => "JPY",
  "zar" => "ZAR",
  "huf" => "HUF",
  "thb" => "THB",
  "uah" => "UAH"
}

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object



41
42
43
44
45
46
47
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
# File 'lib/trades/options.rb', line 41

def self.parse(args)
  # Default options
  options            = OpenStruct.new
  options.filter     = :markets
  options.markets    = []
  options.currencies = []

  opts = OptionParser.new do |opts|
  	opts.banner = "Usage: trades [options]\n\n"

    opts.separator "Options:"

    # Filter on market
    opts.on("-m", "--market MARKET", MARKETS, ALIASES, 
      "Filter on MARKET") do |m|
      options.markets << m # << because of multiple currencies
    end

    # Filter on currency
    opts.on("-c", "--currency CURRENCY", CURRENCIES.values.uniq, CURRENCIES, 
  	  "Filter on CURRENCY") do |c|
  	  options.filter = :currencies # default is :markets
  	  options.currencies << c # << because of multiple currencies
    end

  	# Logging
  	opts.on("-l", "--log [FILENAME]", "Log the results to FILENAME") do |file|
  		file = "/var/log/trades.log" if file.nil?
  		options.log    = true
  		options.logger = Logger.new File.new(file, 'a+')
  		options.logger.formatter = proc { |s, d, p, m| "#{m}\n" }
  	end

    # Help
    opts.on_tail("-h", "--help", "Show this message") do
      puts "#{opts}\n\nMore info: https://github.com/britishtea/Trades"
      exit
    end
    
    # List of markets
    opts.on_tail("--markets", "Show a list of all markets") do
      puts "Markets: #{MARKETS.join ', '}\n\nAliases:"
      ALIASES.each { |x,y| puts "#{x} for #{y}" }
      exit
    end
    
    # List of currencies
    opts.on_tail("--currencies", "Show a list of all currencies") do
      puts "Currencies: #{CURRENCIES.values.uniq.join ', '}"
      exit
    end
  end

  opts.parse!(args)
  options
end