This script will send you an email when stock price falls off a certain tresholds.
Set your own thresholds changing the "low" & "high" values.
Set your preferred stock symbol changing "EBAY" to "GOOGLE" for example. Is easeally extendable to support several stock symbols. I can post a second script if there's enough demand.
To set it up running every day, use windows Task Scheduler or CRON for linux and mac machines.
It does require the ruby mailfactory gem, use "gem install mailfactory" to get it on your machine, and also add in your email server configuration.
host = "finance.google.com"
link = "/finance?q="+ symbol.upcase
begin
# Create a new HTTP connection
httpCon = Net::HTTP.new( host, 80 )
# Perform a HEAD request
resp = httpCon.get( link, nil )
value = (resp.body.scan /class="pr"[^>]*([^<]*)/).flatten.to_s.gsub(">", "").to_f
print " current stock price is " + value.to_s + " (from finance.google.com)\n"
return value
end
end
begin
mail = MailFactory.new()
mail.to = 'myself@gmail.com'
mail.from = "ebaystock@alerts.com"
mail.subject = subject
mail.html = message
Net::SMTP.start('yourmailserver') do |smtp|
smtp.send_message(mail.to_s(), mail.from, mail.to )
end
rescue StandardError => e
puts "Error sending mail"
raise e
end
end
begin
low = 23.0
high = 27.0
name = "EBAY"
price = get_stock_quote(name)
send_stock_alert(" Stock Alert: ") unless price.between? low, high
end
No comments:
Post a Comment