Class: RRR
- Inherits:
-
Object
- Object
- RRR
- Defined in:
- lib/rirera.rb
Instance Method Summary collapse
- #decorate ⇒ Object
- #get_break_even(total_commission, volume, amount) ⇒ Object
- #get_broker(broker, conf) ⇒ Object
- #get_total_commission(amount, actual_price, target_price, conf, broker) ⇒ Object
-
#initialize(broker) ⇒ RRR
constructor
A new instance of RRR.
- #print_result(volume, amount, max_gain, loss, total_commission, break_even_price) ⇒ Object
- #print_rrr(rrr) ⇒ Object
- #test_input(actual_price, stop_loss) ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize(broker) ⇒ RRR
Returns a new instance of RRR.
7 8 9 |
# File 'lib/rirera.rb', line 7 def initialize(broker) @broker = broker end |
Instance Method Details
#decorate ⇒ Object
25 26 27 28 29 |
# File 'lib/rirera.rb', line 25 def decorate 12.times do print "#" end end |
#get_break_even(total_commission, volume, amount) ⇒ Object
78 79 80 |
# File 'lib/rirera.rb', line 78 def get_break_even(total_commission, volume, amount) ((volume + total_commission) / amount).round(2) end |
#get_broker(broker, conf) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/rirera.rb', line 17 def get_broker(broker, conf) unless conf['broker'][@broker].nil? @broker else abort "Not a valid broker" end end |
#get_total_commission(amount, actual_price, target_price, conf, broker) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rirera.rb', line 56 def get_total_commission(amount, actual_price, target_price, conf, broker) # calculate order pricing basic_price = conf['broker'][broker]['basic_price'] commission_rate = conf['broker'][broker]['commission_rate'] volume_rate_buy = (amount * actual_price * commission_rate).round(2) volume_rate_sell = (amount * target_price * commission_rate).round(2) total_commission = 0.0 [volume_rate_buy, volume_rate_sell].each do |vr| if (vr + basic_price) > conf['broker'][broker]['min_rate'] if (vr + basic_price) > conf['broker'][broker]['max_rate'] total_commission += conf['broker'][broker]['max_rate'] else total_commission += (basic_price + vr) end else total_commission += conf['broker'][broker]['min_rate'] end end total_commission.round(2) end |
#print_result(volume, amount, max_gain, loss, total_commission, break_even_price) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rirera.rb', line 39 def print_result(volume, amount, max_gain, loss, total_commission, break_even_price) puts "" puts "" puts "Volume: #{volume}" puts "Amount: #{amount}" puts "Gain: #{max_gain}".green puts "Loss: #{loss}".red puts "Commission: #{total_commission}".magenta puts "Break Even: #{break_even_price}".blue puts "" puts "Again? (y/n)" end |
#print_rrr(rrr) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/rirera.rb', line 31 def print_rrr(rrr) decorate print "\n# RRR: " print "#{rrr}".yellow puts " #" decorate end |
#test_input(actual_price, stop_loss) ⇒ Object
52 53 54 |
# File 'lib/rirera.rb', line 52 def test_input(actual_price, stop_loss) abort "Stop Loss has to be lower than Price" unless stop_loss < actual_price end |
#usage ⇒ Object
11 12 13 14 15 |
# File 'lib/rirera.rb', line 11 def usage puts "Usage:" puts "./rirera broker_name" exit end |