app/controllers/iro/positions_controller.rb in iron_warbler-2.0.7.26 vs app/controllers/iro/positions_controller.rb in iron_warbler-2.0.7.27

- old
+ new

@@ -2,18 +2,19 @@ class Iro::PositionsController < Iro::ApplicationController before_action :set_lists def create pos = @position = Iro::Position.new pos_params + authorize! :create, @position + o_attrs = { expires_on: pos.expires_on, - put_call: pos.put_call, + put_call: pos.put_call, # I need this. _vp_ 2024-04-26 stock_id: pos.stock_id, } pos.inner = Iro::Option.new params[:inner].permit!.merge( o_attrs ) pos.outer = Iro::Option.new params[:outer].permit!.merge( o_attrs ) - authorize! :create, @position if @position.save flash_notice @position redirect_to controller: :purses, action: :show, id: @position.purse_id.to_s else @@ -34,26 +35,29 @@ @position = Iro::Position.find params[:id] authorize! :edit, @position end def new - strategy = Iro::Strategy.find params[:position][:strategy_id] - @position = Iro::Position.new( params[:position].permit!.merge({ - status: :active, - inner: Iro::Option.new, - outer: Iro::Option.new, - stock_id: strategy.stock_id, + strategy = Iro::Strategy.find params[:position][:strategy_id] + @position = strategy.next_position + @position ||= Iro::Position.new( params[:position].permit!.merge({ + status: Iro::Position::STATUS_PROPOSED, + # inner: Iro::Option.new, + # outer: Iro::Option.new, + stock_id: strategy.stock_id, }) ) authorize! :new, @posision - if params[:id] - old = Iro::Position.find params[:id] - old = old.attributes - old.delete :_id - puts! old, 'old' - @position = Iro::Position.new old - end + @position.calc_nxt + + # if params[:id] + # old = Iro::Position.find params[:id] + # old = old.attributes + # old.delete :_id + # puts! old, 'old' + # @position = Iro::Position.new old + # end end def prepare @position = Iro::Position.find params[:id] authorize! :roll, @position @@ -65,11 +69,11 @@ ## dealing with too many strikes in the chain while true @nn = ( @position.purse.n_next_positions/2 ).ceil upper = Tda::Option.get_quote({ - contractType: @position.put_call, + contractType: @position.inner.put_call, strike: @prev.inner.strike + @nn*@stock.options_price_increment, expirationDate: @prev.next_expires_on, ticker: @stock.ticker, }) if !upper.symbol @@ -79,11 +83,11 @@ @purse.n_next_positions = 1 if @purse.n_next_positions < 1 @purse.save! next end lower = Tda::Option.get_quote({ - contractType: @position.put_call, + contractType: @position.inner.put_call, strike: @prev.inner.strike - @nn*@stock.options_price_increment, expirationDate: @prev.next_expires_on, ticker: @stock.ticker, }) if !lower.symbol @@ -244,10 +248,11 @@ @positions.push next_ end @positions = @positions.reverse end alias_method :_prepare_short_debit_put_spread, :_prepare_long_debit_call_spread + alias_method :_prepare_short_credit_call_spread, :_prepare_long_debit_call_spread def sync @position = pos = Iro::Position.find params[:id] authorize! :refresh, @position @@ -269,12 +274,10 @@ authorize! :update, @position if @position.update pos_params o_attrs = { expires_on: pos.expires_on, - put_call: pos.put_call, - stock_id: pos.stock_id, } pos.inner.update params[:inner].permit!.merge( o_attrs ) pos.outer.update params[:outer].permit!.merge( o_attrs ) flash_notice @position @@ -291,12 +294,15 @@ ## private ## private def pos_params - params[:position].permit( :purse_id, :status, :stock_id, - :strategy_id, :expires_on, :quantity, :begin_on, + params[:position].permit( :begin_on, + :expires_on, :long_or_short, + :purse_id, + :quantity, + :status, :stock_id, :strategy_id, ) end def price pos = @position