app/controllers/iro/api/stocks_controller.rb in iron_warbler-2.0.7.41 vs app/controllers/iro/api/stocks_controller.rb in iron_warbler-2.0.7.42
- old
+ new
@@ -1,9 +1,26 @@
class Iro::Api::StocksController < Iro::ApiController
before_action :set_stock, only: [:destroy, :edit, :max_pain, :show, :update ]
+ def create
+ @stock = Iro::Stock.new(stock_params)
+ authorize! :create, @stock
+
+ if @stock.save
+ flash_notice @stock
+ else
+ flash_alert @stock
+ end
+ redirect_to action: :index
+ end
+
+ def destroy
+ @stock.destroy
+ redirect_to stocks_url, notice: 'Stock was successfully destroyed.'
+ end
+
def index
@stocks = Iro::Stock.active
authorize! :index, Iro::Stock
respond_to do |format|
@@ -12,12 +29,13 @@
end
end
def max_pain
authorize! :max_pain, @stock
+ Iro::Iro.schwab_sync
- hash = Tda::Option.get_chains({ ticker: @stock.ticker })
+ hash = Tda::Option.get_chains({ ticker: @stock.ticker, force: false })
# hash = JSON.parse File.read './trash.json'
@max_pain = Iro::Option.max_pain hash
respond_to do |format|
format.html
@@ -25,10 +43,16 @@
render layout: false
end
end
end
+ def new
+ @stock = Iro::Stock.new
+ authorize! :new, @stock
+ end
+
+
def show
authorize! :show, @stock
end_on = Time.now.to_date.in_time_zone('UTC')
begin_on = ( Time.now - 1.year ).to_date.in_time_zone('UTC')
@@ -54,30 +78,10 @@
:quote_at.lte => end_on,
symbol: params[:ticker],
}).order_by({ quote_at: :asc })
end
- def new
- @stock = Iro::Stock.new
- authorize! :new, @stock
- end
-
- def edit
- end
-
- def create
- @stock = Iro::Stock.new(stock_params)
- authorize! :create, @stock
-
- if @stock.save
- flash_notice @stock
- else
- flash_alert @stock
- end
- redirect_to action: :index
- end
-
def update
@stock = Iro::Stock.find params[:id]
authorize! :update, @stock
if @stock.update(stock_params)
flash_notice @stock
@@ -85,13 +89,10 @@
flash_alert @stock
end
redirect_to request.referrer
end
- def destroy
- @stock.destroy
- redirect_to stocks_url, notice: 'Stock was successfully destroyed.'
- end
+
##
## private
##
private