Class: MyTradeWizard::TradingSystem

Inherits:
Object
  • Object
show all
Includes:
DateTime, TechnicalIndicator
Defined in:
lib/mytradewizard/trading_system.rb

Direct Known Subclasses

FutureTradingSystem, StockTradingSystem

Constant Summary

Constants included from DateTime

DateTime::HR

Instance Method Summary collapse

Methods included from TechnicalIndicator

#SMA

Methods included from DateTime

#at, #friday, #idle

Constructor Details

#initializeTradingSystem

Returns a new instance of TradingSystem.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/mytradewizard/trading_system.rb', line 7

def initialize
  @ib = MyTradeWizard::InteractiveBrokers.new
  @ib_ruby = @ib.connect
  @environment = MyTradeWizard::Configuration::ENVIRONMENT
  @account = MyTradeWizard::Configuration::InteractiveBrokers::ACCOUNT.empty? ? @ib.accounts.first : MyTradeWizard::Configuration::InteractiveBrokers::ACCOUNT
  @logger = Logger.new("/mtw/sys/#{self.class.to_s.downcase}/log/#{Time.now.strftime('%Y%m%d-%H%M')}") unless test?
  @email = MyTradeWizard::Email.new
  @email.subject = (production?) ? self.class.to_s : "#{@environment.upcase} #{self.class.to_s}"
  @email.body = ""
  @orders = []
end

Instance Method Details

#email(msg = nil) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/mytradewizard/trading_system.rb', line 35

def email(msg = nil)
  if msg.nil?
    return @email
  else
    @email.body = msg
    @email.send
  end
end

#output(msg) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/mytradewizard/trading_system.rb', line 27

def output(msg)
  if @logger.present?
    @logger.info msg
  else
    puts msg
  end
end

#place_market_order(action, quantity, contract) ⇒ Object



23
24
25
# File 'lib/mytradewizard/trading_system.rb', line 23

def place_market_order(action, quantity, contract)
  @ib.place_market_order(@account, action, quantity, contract)
end

#positionsObject



19
20
21
# File 'lib/mytradewizard/trading_system.rb', line 19

def positions
  @positions = @ib.positions(@account)
end

#production?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/mytradewizard/trading_system.rb', line 48

def production?
  @environment == 'production'
end

#test?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/mytradewizard/trading_system.rb', line 44

def test?
  @environment == 'local'
end