Class: Iro::Api::StocksController
- Inherits:
-
Iro::ApiController
- Object
- Iro::ApiController
- Iro::Api::StocksController
- Defined in:
- app/controllers/iro/api/stocks_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #max_pain ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/controllers/iro/api/stocks_controller.rb', line 67 def create @stock = Iro::Stock.new(stock_params) :create, @stock if @stock.save flash_notice @stock else flash_alert @stock end redirect_to action: :index end |
#destroy ⇒ Object
90 91 92 93 |
# File 'app/controllers/iro/api/stocks_controller.rb', line 90 def destroy @stock.destroy redirect_to stocks_url, notice: 'Stock was successfully destroyed.' end |
#edit ⇒ Object
64 65 |
# File 'app/controllers/iro/api/stocks_controller.rb', line 64 def edit end |
#index ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'app/controllers/iro/api/stocks_controller.rb', line 5 def index @stocks = Iro::Stock.active :index, Iro::Stock respond_to do |format| format.html format.json end end |
#max_pain ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/iro/api/stocks_controller.rb', line 15 def max_pain :max_pain, @stock hash = Tda::Option.get_chains({ ticker: @stock.ticker }) # hash = JSON.parse File.read './trash.json' @max_pain = Iro::Option.max_pain hash respond_to do |format| format.html format.json do render layout: false end end end |
#new ⇒ Object
59 60 61 62 |
# File 'app/controllers/iro/api/stocks_controller.rb', line 59 def new @stock = Iro::Stock.new :new, @stock end |
#show ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/iro/api/stocks_controller.rb', line 30 def show :show, @stock end_on = Time.now.to_date.in_time_zone('UTC') begin_on = ( Time.now - 1.year ).to_date.in_time_zone('UTC') begin_on = params[:begin_on].to_date.in_time_zone('UTC') if params[:begin_on] end_on = params[:end_on].to_date.in_time_zone('UTC') if params[:end_on] case params[:period] when '1-mo' begin_on = ( Time.now - 30.days ).to_date.in_time_zone('UTC') # end_on = Time.now.to_date.in_time_zone('UTC') when '3-mo' begin_on = ( Time.now - 90.days ).to_date.in_time_zone('UTC') # end_on = Time.now.to_date.in_time_zone('UTC') when '1-yr' begin_on = ( Time.now - 1.year ).to_date.in_time_zone('UTC') # end_on = Time.now.to_date.in_time_zone('UTC') when '5-yr' begin_on = ( Time.now - 5.years ).to_date.in_time_zone('UTC') end @datapoints = Iro::Datapoint.where({ :quote_at.gte => begin_on, :quote_at.lte => end_on, symbol: params[:ticker], }).order_by({ quote_at: :asc }) end |
#update ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'app/controllers/iro/api/stocks_controller.rb', line 79 def update @stock = Iro::Stock.find params[:id] :update, @stock if @stock.update(stock_params) flash_notice @stock else flash_alert @stock end redirect_to request.referrer end |