Class: MyTradeWizard::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/mytradewizard/action.rb

Instance Method Summary collapse

Constructor Details

#initialize(signal) ⇒ Action

Returns a new instance of Action.



4
5
6
7
8
9
10
11
12
13
# File 'lib/mytradewizard/action.rb', line 4

def initialize(signal)
  case signal
  when "BUY"
    @signal = 1
  when "SELL"
    @signal = -1
  else
    @signal = signal
  end
end

Instance Method Details

#nil?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/mytradewizard/action.rb', line 34

def nil?
  @signal == 0
end

#reverseObject



30
31
32
# File 'lib/mytradewizard/action.rb', line 30

def reverse
  return MyTradeWizard::Action.new(-@signal)
end

#reverse!Object



25
26
27
28
# File 'lib/mytradewizard/action.rb', line 25

def reverse!
  @signal = -@signal
  return self
end

#to_sObject



15
16
17
18
19
20
21
22
23
# File 'lib/mytradewizard/action.rb', line 15

def to_s
  if @signal > 0
    return "BUY"
  elsif @signal < 0
    return "SELL"
  else
    return "None"
  end
end