Sha256: e04286b8b79b039cc7edbc8722f77f2cab564f59481b9ceb1ca649bd2a9dc686

Contents?: true

Size: 1.6 KB

Versions: 5

Compression:

Stored size: 1.6 KB

Contents

namespace :iro do

  desc 'alerts'
  task alerts: :environment do
    print 'iro:alerts'
    while true
      Iro::Alert.active.each do |alert|
        alert.do_run
      end

      print '.'
      sleep Rails.env.production? ? 60 : 15
    end
  end

  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
          outs = Tda::Stock.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

      print '.'
      sleep 15 # *60 # 15 min
    end
  end

end


Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
iron_warbler-2.0.7.33 lib/tasks/iro_tasks.rake
iron_warbler-2.0.7.32 lib/tasks/iro_tasks.rake
iron_warbler-2.0.7.31 lib/tasks/iro_tasks.rake
iron_warbler-2.0.7.30 lib/tasks/iro_tasks.rake
iron_warbler-2.0.7.29 lib/tasks/iro_tasks.rake