Sha256: 2fb8ba53115f60a2ebb143910e0cb05a95bb0600d24f8d399ee98fc741d40c5b

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

class ::IshManager::IroPursesController < IshManager::ApplicationController

  before_action :set_lists

  def create
    @iro_purse = Iro::Purse.new({
      profile_id: current_profile.id,
    })
    authorize! :create, @iro_purse

    if @iro_purse.update params[:iro_purse].permit!
      flash[:notice] = 'Successfully created iro_purse.'
      redirect_to action: :show, id: @iro_purse.id
    else
      flash[:alert] = "Cannot create iro_purse: #{@iro_purse.errors.full_messages.join(', ')}."
      render action: 'edit'
    end
  end

  def edit
    @iro_purse = Iro::Purse.find params[:id]
    authorize! :edit, @iro_purse
  end

  def new
    @iro_purse = Iro::Purse.new
    authorize! :new, @iro_purse
  end

  def show
    @purse = Iro::Purse.find params[:id]
    authorize! :my, @purse

    @strategies = @purse.strategies

    underlyings = Tda::Stock.get_quotes( @strategies.map(&:ticker).compact.uniq.join(",") )
    # json_puts! underlyings, 'out'
    underlyings.each do |ticker, v|
      Iro::CoveredCallStrategy.where( ticker: ticker ).update( current_underlying_strike: v[:mark] )
    end

    @positions = @purse.positions.order({ expires_on: :asc, strike: :asc })
    @positions.map &:refresh

    render @purse.parsed_config[:kind] || 'show'
  end

  def update
    @iro_purse = Iro::Purse.find params[:id]
    authorize! :update, @iro_purse

    if @iro_purse.update params[:iro_purse].permit!
      flash[:notice] = 'Successfully updated iro_purse.'
      redirect_to action: :show, id: @iro_purse.id
    else
      flash[:alert] = "Cannot update iro_purse: #{@iro_purse.errors.full_messages.join(', ')}."
      render action: 'edit'
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ish_manager-0.1.8.410 app/controllers/ish_manager/iro_purses_controller.rb
ish_manager-0.1.8.409 app/controllers/ish_manager/iro_purses_controller.rb