Class: IshManager::IroOptionGetsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ish_manager/iro_option_gets_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#basic_auth, #home, #tinymce

Instance Method Details

#createObject

before_action :set_lists



6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/ish_manager/iro_option_gets_controller.rb', line 6

def create
  @item = Iro::OptionGet.new params[:iro_option_get].permit!
  @item.kind = Iro::OptionGet::KIND_GET_CHAINS
  authorize! :create, @item
  flag = @item.save
  if flag
    flash[:notice] = 'Created option_get.'
  else
    flash[:alert] = "Cannot create option_get: #{@item.errors.full_messages.join(', ')}."
  end
  redirect_to action: 'index', controller: 'ish_manager/iro_watches'
end

#max_painObject



19
20
21
22
23
24
25
26
27
28
29
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/controllers/ish_manager/iro_option_gets_controller.rb', line 19

def max_pain
  @ticker = params[:ticker]
  @date = params[:date].to_time.to_i

  ## 1689364800000
  ##  Fri, 14 Jul 2023 15:00:00.000000000 CDT -05:00

  authorize! :max_pain, Iro::Iro

  @expirationDate = ( params[:date].to_date + 15.hours ).to_time.to_i * 1000 # '1689364800000'
  # expirationDate = '1689969600000'
  # expirationDate = '1690574400000'
  @all_items = {}

  calls_sql = "select distinct symbol, strikePrice, putCall, openInterest
    from iro_option_price_items
    where expirationDate = #{@expirationDate} and putCall = 'CALL' and ticker = '#{@ticker}'
    group by symbol, strikePrice, putCall
    order by putCall, strikePrice, created_at desc;"
  @calls_items = []
  @calls_array = ActiveRecord::Base.connection.execute(calls_sql)
  calls_subtotal = 0
  @calls_array.each do |_item|
    item = {
      symbol: _item[0],
      strikePrice: _item[1],
      putCall: _item[2],
      oi: _item[3],
    }
    item[:subtotal] = item[:strikePrice] * 100 * item[:oi]
    calls_subtotal = calls_subtotal + item[:subtotal]
    item[:total] = calls_subtotal
    puts! item, 'item'
    @calls_items.push( item )

    @all_items[item[:strikePrice]] ||= {
      subtotal: 0,
      strikePrice: item[:strikePrice],
    }
    @all_items[item[:strikePrice]][:calls_subtotal] = calls_subtotal
    @all_items[item[:strikePrice]][:calls_oi] = item[:oi]
    @all_items[item[:strikePrice]][:subtotal] = @all_items[item[:strikePrice]][:subtotal] + calls_subtotal
  end

  puts_sql = "select distinct symbol, strikePrice, putCall, openInterest
    from iro_option_price_items
    where expirationDate = #{@expirationDate} and putCall = 'PUT' and ticker = '#{@ticker}'
    group by symbol, strikePrice, putCall
    order by putCall, strikePrice, created_at desc;"
  @puts_items = []
  @puts_array = ActiveRecord::Base.connection.execute(puts_sql)
  puts_subtotal = 0
  @puts_array.each do |_item|
    item = {
      symbol: _item[0],
      strikePrice: _item[1],
      putCall: _item[2],
      oi: _item[3],
    }
    item[:subtotal] = item[:strikePrice] * 100 * item[:oi]
    puts_subtotal = puts_subtotal + item[:subtotal]
    item[:total] = puts_subtotal
    puts! item, 'item'
    @puts_items.push( item )

    @all_items[item[:strikePrice]] ||= {
      subtotal: 0,
      strikePrice: item[:strikePrice],
    }
    @all_items[item[:strikePrice]][:puts_subtotal] = puts_subtotal
    @all_items[item[:strikePrice]][:puts_oi] = item[:oi]
    @all_items[item[:strikePrice]][:subtotal] = @all_items[item[:strikePrice]][:subtotal] + puts_subtotal
  end


  render 'ish_manager/iro_watches/max_pain'
end