Class: MyTradeWizard::StockTradingSystem
Constant Summary
Constants included
from WatchLists
WatchLists::DOW30, WatchLists::NAZ100, WatchLists::SP500
Constants included
from DateTime
DateTime::HR
Instance Attribute Summary collapse
Instance Method Summary
collapse
#email, #output, #place_market_order, #positions, #production?, #test?
#SMA
Methods included from DateTime
#at, #friday, #idle
Constructor Details
Returns a new instance of StockTradingSystem.
11
12
13
14
15
16
|
# File 'lib/mytradewizard/stock_trading_system.rb', line 11
def initialize
super
@watchlist = MyTradeWizard::WatchList.new
@data = nil
end
|
Instance Attribute Details
#position_size=(value) ⇒ Object
Sets the attribute position_size
9
10
11
|
# File 'lib/mytradewizard/stock_trading_system.rb', line 9
def position_size=(value)
@position_size = value
end
|
#watchlist ⇒ Object
Returns the value of attribute watchlist.
8
9
10
|
# File 'lib/mytradewizard/stock_trading_system.rb', line 8
def watchlist
@watchlist
end
|
Instance Method Details
#buy(stock) ⇒ Object
38
39
40
41
42
43
|
# File 'lib/mytradewizard/stock_trading_system.rb', line 38
def buy(stock)
order = MyTradeWizard::Order.new
order.action = MyTradeWizard::Action.new("BUY")
order.stock = stock
return order
end
|
#close(day) ⇒ Object
34
35
36
|
# File 'lib/mytradewizard/stock_trading_system.rb', line 34
def close(day)
@data.day(day).close
end
|
#days(daily_range) ⇒ Object
30
31
32
|
# File 'lib/mytradewizard/stock_trading_system.rb', line 30
def days(daily_range)
@data.days(daily_range)
end
|
#place(orders) ⇒ Object
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/mytradewizard/stock_trading_system.rb', line 50
def place(orders)
total_buying_power = @ib.buying_power(@account)
buying_power_per_order = total_buying_power / orders.length
orders.each do |order|
order.quantity = (buying_power_per_order / order.stock.price).floor
email << "#{order.action} #{order.quantity} #{order.stock.symbol}"
place_market_order order.action.to_s, order.quantity, order.stock.contract
end
email.send
end
|
#preload(days, stock) ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/mytradewizard/stock_trading_system.rb', line 18
def preload(days, stock)
@stock = stock
@data = MyTradeWizard::Yahoo.OHLC(stock.symbol, days)
if @data.length < days
puts "ERROR: Only #{@data.length}/#{days} days of data for #{stock.symbol}"
end
end
|
#sell(position) ⇒ Object
45
46
47
48
|
# File 'lib/mytradewizard/stock_trading_system.rb', line 45
def sell(position)
email << "SELL #{position.size} #{position.stock.symbol}"
place_market_order "SELL", position.size, position.stock.contract
end
|
#t ⇒ Object
26
27
28
|
# File 'lib/mytradewizard/stock_trading_system.rb', line 26
def t
@data.today
end
|