Sha256: 2d81f72d3ce706a80135a49a43746609890611bfb7501f7f36bcf46600ffa346

Contents?: true

Size: 1.92 KB

Versions: 2

Compression:

Stored size: 1.92 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 'Get BTC, ETH price from coinmarketcap'
  task :get_coins => :environment do
    while true

      ::Iro::Iro.get_coins

      print '.'
      # sleep 5 * 60 ## 5 minutes
      sleep 55 * 60 ## 1 hr
    end
  end

  desc 'get coins once'
  task :get_coins_once => :environment do
    ::Iro::Iro.get_coins
    print '^'
  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

2 entries across 2 versions & 1 rubygems

Version Path
iron_warbler-2.0.7.35 lib/tasks/iro_tasks.rake
iron_warbler-2.0.7.34 lib/tasks/iro_tasks.rake