Class: RbtcArbitrage::CLI
- Inherits:
-
Thor
- Object
- Thor
- RbtcArbitrage::CLI
- Defined in:
- lib/rbtc_arbitrage/cli.rb
Instance Attribute Summary collapse
-
#mtgox ⇒ Object
Returns the value of attribute mtgox.
-
#stamp ⇒ Object
Returns the value of attribute stamp.
Instance Method Summary collapse
Instance Attribute Details
#mtgox ⇒ Object
Returns the value of attribute mtgox.
3 4 5 |
# File 'lib/rbtc_arbitrage/cli.rb', line 3 def mtgox @mtgox end |
#stamp ⇒ Object
Returns the value of attribute stamp.
3 4 5 |
# File 'lib/rbtc_arbitrage/cli.rb', line 3 def stamp @stamp end |
Instance Method Details
#trade ⇒ Object
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rbtc_arbitrage/cli.rb', line 9 def trade @stamp = {}; @mtgox = {} if [:live] validate_env get_balance end # puts "#{Time.now.strftime("%m/%d/%Y at %I:%M%p")}" # puts "Retrieving market information and balances" amount_to_buy = [:volume] stamp[:price] = Bitstamp.ticker.ask.to_f mtgox[:price] = MtGox.ticker.buy prices = [stamp[:price], mtgox[:price]] paid = prices.min * 1.005 * amount_to_buy received = prices.max * 0.994 * amount_to_buy puts "Bitstamp: $#{stamp[:price].round(2)}" puts "MtGox: $#{mtgox[:price].round(2)}" lower_ex, higher_ex = stamp[:price] < mtgox[:price] ? [Bitstamp, MtGox] : [MtGox, Bitstamp] puts "buying #{amount_to_buy} btc from #{lower_ex} for $#{paid.round(2)}" puts "selling #{amount_to_buy} btc on #{higher_ex} for $#{received.round(2)}" percent = ((received/paid - 1) * 100).round(2) puts "profit: $#{(received - paid).round(2)} (#{percent.round(2)}%)" if [:cutoff] > percent puts "Exiting because real profit (#{percent.round(2)}%) is less than cutoff (#{options[:cutoff].round(2)}%)" return 0 end if [:live] puts "Balances:" puts "stamp usd: $#{stamp[:usd].round(2)} btc: #{stamp[:usd].round(2)}" puts "mtgox usd: $#{mtgox[:usd].round(2)} btc: #{mtgox[:usd].round(2)}" if stamp[:price] < mtgox[:price] if paid > stamp[:usd] || amount_to_buy > mtgox[:btc] puts "Not enough funds. Exiting." else puts "Trading live!" Bitstamp.orders.buy amount_to_buy, stamp[:price] + 0.001 MtGox.sell! amount_to_buy, :market Bitstamp.transfer amount_to_buy, ENV['MTGOX_ADDRESS'] end else if paid > mtgox[:usd] || amount_to_buy > stamp[:btc] puts "Not enough funds. Exiting." else puts "Trading live!" MtGox.buy! amount_to_buy, :market Bitstamp.orders.sell amount_to_buy, stamp[:price] - 0.001 MtGox.withdraw amount_to_buy, ENV['BITSTAMP_ADDRESS'] end end end 0 end |