Sha256: a4006974d434518d41ba7ec9233b96be69a8cfb2786bcd148fdca1f1eaec9a4d
Contents?: true
Size: 2 KB
Versions: 6
Compression:
Stored size: 2 KB
Contents
namespace :iro do desc 'recommend position actions' task recommend_position_actions: :environment do Iro::Position.active.where({ kind: 'covered_call' }).map &:should_roll? end desc 'refresh positions' task refresh_positions: :environment do Iro::Position.active.where({ kind: 'covered_call' }).map &:refresh end desc 'watch positions' task watch_positions: :environment do while true if in_business positions = Iro::Position.active.where({ kind: 'covered_call' }) positions.each do |position| out = Tda::Option.get_quote({ contractType: 'CALL', strike: position.strike, expirationDate: position.expires_on, ticker: position.ticker, }) position.update({ end_delta: out[:delta], end_price: out[:last], }) end print '.' end sleep 60 # seconds end end desc 'watch stocks' task watch_stocks: :environment do while true begin Timeout::timeout( 10 ) do TDA::Api.get_quotes Iro::Stock.active.map(&:ticker).join(",") end rescue Exception => e puts! e, 'Error in iro:watch_stocks' # Wco::Exceptionist.notify(e, 'Error in iro:watch_stocks') end sleep Iro::Stock::SLEEP_TIME_SECONDS end end desc 'alerts' task alerts: :environment do print 'iro:alerts' while true Iro::Alert.active.each do |alert| # price = Iro::Stock.latest( alert.ticker ).price price = Tda::Api.get_quote( alert.symbol ).last if alert.direction == Iro::Alert::DIRECTION_ABOVE && price >= alert.strike || alert.direction == Iro::Alert::DIRECTION_BELOW && price <= alert.strike Iro::AlertMailer.stock_alert( alert ).deliver_later alert.update({ status: Iro::Alert::STATUS_INACTIVE }) print '^' end end print '.' sleep Iro::Alert::SLEEP_TIME_SECONDS end end end
Version data entries
6 entries across 6 versions & 1 rubygems