Class: StockPivot::Cli

Inherits:
Thor
  • Object
show all
Includes:
ActiveSupport::NumberHelper, Thor::Actions
Defined in:
lib/stock_pivot/cli.rb

Instance Method Summary collapse

Instance Method Details

#trade(symbol, margin_balance) ⇒ Object



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
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
# File 'lib/stock_pivot/cli.rb', line 16

def trade(symbol, margin_balance)
  args = {}
  args[:symbol] = symbol.upcase
  args[:margin_balance] = margin_balance.to_d

  args[:margin_ratio] = options[:margin_ratio] if options[:margin_ratio]
  args[:risk_ratio] = options[:risk_ratio] if options[:risk_ratio]
  args[:commission] = options[:commission] if options[:commission]

  quotes = StockPivot::Quotes.feed(symbol)

  if quotes.size > 0
    args[:quotes] = quotes
    trading = StockPivot::Trading.new(args)

    say "\n"
    say '-' * 80
    say "\n"

    say Rainbow("Margin balance: #{number_to_currency(trading.margin_balance)}").yellow
    say Rainbow("Margin ratio: #{number_to_percentage(trading.margin_ratio)}").yellow
    say Rainbow("Buying power: #{number_to_currency(trading.buying_power)}").cyan
    say Rainbow("Buying power risk ratio: #{number_to_percentage(trading.risk_ratio)}").yellow
    say Rainbow("Margin risk amount: (#{number_to_currency(trading.risk_amount)})").magenta
    say Rainbow("Trade commission (open/close): (#{number_to_currency(trading.commission * 2)})").magenta

    say "\n"
    say '-' * 80
    say "\n"

    say Rainbow("Symbol: #{trading.last_eod.symbol}").yellow
    say Rainbow("EOD date: #{trading.last_eod.trade_date}").yellow
    say Rainbow("Risk range: #{number_to_currency(trading.last_eod.range)}").yellow

    say "\n"
    say '-' * 80
    say "\n"

    say Rainbow("Long trade:").cyan.underline
    say Rainbow("#1 - BUY: #{trading.long_share_size}s @ #{trading.last_eod.high} EXP DAY - TO OPEN").green
    say Rainbow("#2 - SELL: #{trading.long_share_size}s @ #{trading.last_eod.low} EXP GTC - TO CLOSE").magenta
    say Rainbow("** ALL IN").yellow.underline if trading.long_all_in
    say Rainbow("** Long trade risk amount: (#{number_to_currency(trading.long_risk_amount)})").white
    say "\n"
    say Rainbow("Long 3X [Risk reward/Profit target] - OCO:").cyan.underline
    say Rainbow("#3 - Profit target - SELL: #{trading.long_share_size}s @ #{trading.last_eod.high + (trading.last_eod.range * 3.00)} EXP GTC - TO CLOSE").magenta
    say Rainbow("Possible profit amount: #{number_to_currency(trading.long_risk_amount * 3.00)}").white

    say "\n"
    say '-' * 80
    say "\n"

    say Rainbow("Short trade:").cyan.underline
    say Rainbow("#1 - SELL: #{trading.short_share_size}s @ #{trading.last_eod.low} EXP DAY - TO OPEN").magenta
    say Rainbow("#2 - BUY: #{trading.short_share_size}s @ #{trading.last_eod.high} EXP GTC - TO CLOSE").green
    say Rainbow("** ALL IN").yellow.underline if trading.short_all_in
    say Rainbow("** Short trade risk amount: (#{number_to_currency(trading.short_risk_amount)})").white
    say "\n"
    say Rainbow("Short 3X [Risk reward/Profit target] - OCO:").cyan.underline
    say Rainbow("#3 - Profit target - BUY: #{trading.short_share_size}s @ #{trading.last_eod.low - (trading.last_eod.range * 3.00)} EXP GTC - TO CLOSE").green
    say Rainbow("Possible profit amount: #{number_to_currency(trading.short_risk_amount * 3.00)}").white

    say "\n"
    say '-' * 80
    say "\n"

  else
    say "\n"
    say Rainbow("No quotes found for symbol: #{symbol}").yellow
    say "\n\n"

  end

  #puts "Margin ratio"
end