iron_warbler 2.0.7.7 → 2.0.7.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +3 -16
  3. data/app/assets/javascript/iron_warbler/application.js +3 -0
  4. data/app/assets/stylesheets/iron_warbler/positions.scss +47 -0
  5. data/app/assets/stylesheets/iron_warbler/strategies.scss +0 -0
  6. data/app/assets/stylesheets/iron_warbler/utils.css +44 -0
  7. data/app/controllers/iro/alerts_controller.rb +6 -6
  8. data/app/controllers/iro/application_controller.rb +3 -2
  9. data/app/controllers/iro/datapoints_controller.rb +0 -2
  10. data/app/controllers/iro/positions_controller.rb +62 -0
  11. data/app/controllers/iro/profiles_controller.rb +0 -2
  12. data/app/controllers/iro/purses_controller.rb +65 -0
  13. data/app/controllers/iro/stocks_controller.rb +11 -4
  14. data/app/controllers/iro/strategies_controller.rb +66 -0
  15. data/app/models/iro/alert.rb +15 -4
  16. data/app/models/iro/datapoint.rb +108 -3
  17. data/app/models/iro/date.rb +10 -0
  18. data/app/models/iro/option.rb +13 -5
  19. data/app/models/iro/position.rb +222 -0
  20. data/app/models/iro/price_item.rb +5 -2
  21. data/app/models/iro/purse.rb +17 -0
  22. data/app/models/iro/stock.rb +19 -8
  23. data/app/models/iro/strategy.rb +38 -0
  24. data/app/models/tda/option.rb +137 -0
  25. data/app/views/iro/_analytics.erb +16 -0
  26. data/app/views/iro/_main_header.haml +23 -0
  27. data/app/views/iro/alerts/index.haml +1 -1
  28. data/app/views/iro/positions/_form.haml +59 -0
  29. data/app/views/iro/positions/_reasons.haml +4 -0
  30. data/app/views/iro/positions/_table.haml +137 -0
  31. data/app/views/iro/positions/edit.haml +4 -0
  32. data/app/views/iro/positions/new.haml +4 -0
  33. data/app/views/iro/purses/_form.haml +9 -0
  34. data/app/views/iro/purses/edit.haml +3 -0
  35. data/app/views/iro/purses/index.haml +11 -0
  36. data/app/views/iro/purses/show.haml +10 -0
  37. data/app/views/iro/stocks/_form.haml +4 -0
  38. data/app/views/iro/strategies/_form.haml +37 -0
  39. data/app/views/iro/strategies/_header.haml +8 -0
  40. data/app/views/iro/strategies/_show.haml +18 -0
  41. data/app/views/iro/strategies/_table.haml +18 -0
  42. data/app/views/iro/strategies/edit.haml +3 -0
  43. data/app/views/iro/strategies/new.haml +3 -0
  44. data/app/views/layouts/iro/application.haml +48 -13
  45. data/config/initializers/assets.rb +10 -0
  46. data/config/routes.rb +6 -0
  47. data/lib/iron_warbler.rb +4 -1
  48. data/lib/tasks/db_tasks.rake +54 -1
  49. data/lib/tasks/iro_tasks.rake +35 -0
  50. data/lib/tasks/iro_tasks.rake-old +128 -0
  51. metadata +122 -40
  52. data/app/assets/stylesheets/iron_warbler/main.css +0 -13
  53. data/app/assets/stylesheets/scaffold.css +0 -80
  54. data/app/models/iro/application_record.rb +0 -4
  55. data/app/models/iro/profile.rb +0 -4
  56. data/app/views/iro/alerts/edit.html.erb +0 -6
  57. data/app/views/iro/alerts/new.html.erb +0 -5
  58. data/app/views/iro/alerts/show.html.erb +0 -34
  59. data/app/views/iro/profiles/_form.html.erb +0 -32
  60. data/app/views/iro/profiles/edit.html.erb +0 -6
  61. data/app/views/iro/profiles/index.html.erb +0 -31
  62. data/app/views/iro/profiles/new.html.erb +0 -5
  63. data/app/views/iro/profiles/show.html.erb +0 -19
  64. data/db/migrate/20231210204830_create_iro_profiles.rb +0 -12
  65. data/db/migrate/20231210205837_create_iro_alerts.rb +0 -16
  66. data/db/migrate/20231219204329_create_dates.rb +0 -13
  67. data/db/migrate/20231219205644_create_datapoint.rb +0 -15
  68. data/db/migrate/20231220193201_create_stocks.rb +0 -11
  69. data/db/migrate/20231220194903_add_alert_status.rb +0 -5
  70. data/db/migrate/20231220223730_create_iro_price_item.rb +0 -57
  71. /data/app/models/tda/{api.rb → stock.rb} +0 -0
@@ -0,0 +1,137 @@
1
+
2
+ .positions--table
3
+
4
+ %h5 Positions
5
+ %table.bordered
6
+ %tr
7
+ %th  
8
+ %th
9
+ .status
10
+ Status
11
+ %br
12
+ Strategy
13
+ %th.ticker
14
+ .a Ticker
15
+ %th
16
+ .kind
17
+ Kind
18
+ -# covered call (mounted elephant),
19
+ -# reckless defence (credit put spread) (spearman)
20
+ -# reckless re-defence (soaring eagle)
21
+ %th.strike
22
+ .a Strike
23
+ %th
24
+ .expires_on Expires On
25
+ %th
26
+ .end_n_days End N Days
27
+ %th
28
+ .quantity Q
29
+
30
+ %th
31
+ .begin_on begin_on
32
+ %th.begin_price
33
+ .a Begin price
34
+ %th.to_open
35
+ .a To open
36
+ %th
37
+ .begin_delta begin_delta
38
+
39
+ %th
40
+ .end_price End Price
41
+ %th
42
+ .net_amount Net Amount
43
+ %th
44
+ .net_percent Net %
45
+ %th.end_delta
46
+ .a end_delta
47
+ -# %th
48
+ -# .end_n_days End n days
49
+ -# %th
50
+ -# .end_on End on
51
+ %th.should_rollp
52
+ .a should_rollp
53
+ %th.next_position
54
+ .a
55
+ next_symbol
56
+ %br
57
+ next_delta
58
+ %br
59
+ next_outcome
60
+
61
+ - positions.each_with_index do |position, idx|
62
+ - if idx > 0
63
+ - prev_position = positions[idx-1]
64
+ - if prev_position && position[:expires_on] != prev_position[:expires_on]
65
+ %tr
66
+ %td{ colspan: 18 }
67
+ %hr
68
+
69
+ %tr
70
+ %td.actions
71
+ .flex-row
72
+ = button_to 'x', position_path(position), method: :delete, data: { confirm: 'Are you sure?' }
73
+ = link_to '[~]', edit_position_path(position)
74
+ - if position.next_reasons.present? && position.should_rollp && position.should_rollp > 0.5
75
+ = button_to 'Roll', roll_position_path(position)
76
+ - if position.next_reasons.present?
77
+ .collapse-expand{ id: "ce-p-#{position.id}" } [Reasons]
78
+ = render '/iro/positions/reasons', reasons: position.next_reasons
79
+
80
+
81
+ %td.status.strategy
82
+ = position.status
83
+ -# %br
84
+ -# = link_to "[~ #{position.strategy}]", edit_strategy_path(position.strategy)
85
+ .collapse-expand{ id: "ce-pos-reasons-#{position.id}" }
86
+ [#{position.strategy}]
87
+ = render '/iro/strategies/show', strategy: position.strategy
88
+
89
+ %td.ticker
90
+ = position.ticker
91
+ %br
92
+ = pp_amount position.current_underlying_strike
93
+ %td.kind.mini
94
+ = position.kind
95
+ %td.strike
96
+ = pp_amount position.strike
97
+ %td.expires_on.mini
98
+ = position.expires_on rescue nil
99
+ %td.end_n_days
100
+ -# = ( position.expires_on.to_date - position.begin_on.to_date ).to_i
101
+ %b= ( position.expires_on.to_date - Time.now.to_date ).to_i
102
+ %td= position.quantity
103
+
104
+ %td.begin_on.mini
105
+ = position.begin_on rescue nil
106
+ %td.begin_price
107
+ = pp_amount position.begin_price
108
+ %td.to_open
109
+ = pp_amount( position.begin_price * 100 * position.quantity )
110
+ %td= position.begin_delta
111
+
112
+ %td.end_price
113
+ = pp_amount position.end_price
114
+ %td.net_amount
115
+ = pp_amount ( position.begin_price - position.end_price ) * 100 * position.quantity rescue nil
116
+ %td.net_percent
117
+ = pp_percent( ( position.begin_price - position.end_price ) / position.begin_price ) rescue nil
118
+ %td.end_delta= position.end_delta
119
+ -# %td.end_n_days  
120
+ -# %td.end_on  
121
+
122
+ %td.should_rollp
123
+ = pp_percent position.should_rollp rescue nil
124
+ %td.next_position.mini
125
+ .a= position.next_symbol
126
+ .a= position.next_delta
127
+ .a
128
+ = pp_amount position.next_mark
129
+ \=>
130
+ = pp_amount position.next_outcome * 100 * position.quantity rescue nil
131
+
132
+
133
+
134
+
135
+
136
+
137
+
@@ -0,0 +1,4 @@
1
+
2
+ .positions-edit.maxwidth
3
+
4
+ = render 'form', position: @position
@@ -0,0 +1,4 @@
1
+
2
+ .positions-new.maxwidth
3
+ %h5 New Position
4
+ = render 'form', position: @position
@@ -0,0 +1,9 @@
1
+
2
+ .iro-purses--form
3
+ = form_for purse do |f|
4
+ .flex-row
5
+ .field
6
+ %label Slug
7
+ = f.text_field :slug
8
+ .actions
9
+ = f.submit
@@ -0,0 +1,3 @@
1
+
2
+ .purses-edit.maxwidth
3
+ = render 'form', purse: @purse
@@ -0,0 +1,11 @@
1
+
2
+ .iro-purses--index.maxwidth
3
+ %h5 Iro Purses
4
+
5
+ %ul
6
+ - @purses.each do |purse|
7
+ %li
8
+ = link_to '[~]', edit_purse_path(purse)
9
+ = link_to purse.slug, purse_path(purse)
10
+
11
+ %li= render 'iro/purses/form', purse: Iro::Purse.new
@@ -0,0 +1,10 @@
1
+
2
+ .purses-show.padded
3
+
4
+ .maxwidth
5
+ .header
6
+ %h5.title Purse `#{@purse.slug}` (#{@purse.positions.length})
7
+ %ul.menu-secondary
8
+ %li= link_to '[+position]', new_position_path({ purse_id: @purse.id })
9
+
10
+ = render '/iro/positions/table', positions: @purse.positions
@@ -11,5 +11,9 @@
11
11
  .field
12
12
  = f.label :ticker
13
13
  = f.text_field :ticker
14
+
15
+ .field
16
+ %label Last
17
+ = f.number_field :last, placeholder: '80.0', step: 0.01
14
18
  .actions
15
19
  = f.submit
@@ -0,0 +1,37 @@
1
+
2
+ .strategies--form
3
+ = form_for strategy do |f|
4
+ .actions
5
+ = f.submit
6
+
7
+ .field
8
+ %label Ticker
9
+ = f.select :ticker, options_for_select( @tickers_list, selected: strategy.ticker )
10
+
11
+ .field
12
+ %label slug
13
+ = f.text_field :slug
14
+
15
+ .field
16
+ = f.label :buffer_above_water
17
+ = f.number_field :buffer_above_water, placeholder: "0.49", step: 0.01
18
+ .field
19
+ = f.label :next_max_delta
20
+ = f.number_field :next_max_delta, placeholder: "0.25", step: 0.01
21
+ .field
22
+ = f.label :next_min_strike
23
+ = f.number_field :next_min_strike, placeholder: "20.0", step: 0.01
24
+ .field
25
+ = f.label :threshold_delta
26
+ = f.number_field :threshold_delta, placeholder: "0.14", step: 0.01
27
+ .field
28
+ = f.label :threshold_netp
29
+ = f.number_field :threshold_netp, placeholder: "0.69", step: 0.01
30
+ -# .field
31
+ -# = f.label :current_underlying_strike
32
+ -# = f.number_field :current_underlying_strike, placeholder: "16.66", step: 0.01
33
+
34
+ .actions
35
+ = f.submit
36
+
37
+
@@ -0,0 +1,8 @@
1
+
2
+ = link_to "Strategies (#{Iro::Strategy.all.length})", strategies_path
3
+ .inline-search
4
+ = form_tag strategies_path, method: :get do
5
+ = text_field_tag :q
6
+ = link_to '[+]', new_strategy_path
7
+
8
+
@@ -0,0 +1,18 @@
1
+
2
+ .strategies--show.modal-absolute.hide
3
+ .header
4
+ Strategy
5
+ = link_to '[~]', edit_strategy_path(strategy)
6
+ = strategy
7
+ %ul
8
+ %li <b>ticker:</b> #{strategy.ticker}
9
+ %li <b>slug:</b> #{strategy.slug}
10
+
11
+ %li <b>buffer_above_water:</b> #{strategy.buffer_above_water}
12
+
13
+ %li <b>next_max_delta:</b> #{strategy.next_max_delta}
14
+ %li <b>next_min_strike:</b> #{strategy.next_min_strike}
15
+
16
+ %li <b>threshold_delta:</b> #{strategy.threshold_delta}
17
+ %li <b>threshold_netp:</b> #{strategy.threshold_netp}
18
+
@@ -0,0 +1,18 @@
1
+
2
+ - strategies ||= @strategies
3
+
4
+ .strategies--table
5
+
6
+ %table.bordered
7
+ %tr
8
+ %th &nbsp;
9
+ %th ticker
10
+ %th slug
11
+ %th next_max_delta
12
+ - strategies.each do |sss|
13
+ %tr
14
+ %td= link_to '[~]', edit_strategy_path(sss)
15
+ %td= sss.ticker
16
+ %td= sss.slug
17
+ %td= sss.next_max_delta
18
+
@@ -0,0 +1,3 @@
1
+
2
+ .strategies-edit.maxwidth
3
+ = render 'form', strategy: @strategy
@@ -0,0 +1,3 @@
1
+
2
+ .maxwidth
3
+ = render 'form', strategy: @strategy
@@ -1,18 +1,53 @@
1
1
  !!!
2
2
  %html
3
3
  %head
4
- %meta{content: "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
5
- %title Iron Warbler
4
+ %title #{@page_title} | Iron Warbler
5
+ %link{ :rel => 'icon', :href => "/favicon_#{ENV['RAILS_ENV']}.gif" }
6
+ %meta{ :name => :viewport, :content => 'width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=2' }
7
+ %meta{ :charset => 'UTF-8' }
8
+ %meta{ :description => @page_description }
9
+
10
+ = javascript_include_tag "//code.jquery.com/jquery-3.3.1.min.js"
11
+
12
+ %script{ :src => "//cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js" }
13
+ = stylesheet_link_tag "//cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css"
14
+
15
+ = stylesheet_link_tag "//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css", :media => 'all'
16
+ = stylesheet_link_tag "//fonts.googleapis.com/icon?family=Material+Icons"
17
+
18
+ = stylesheet_link_tag "//cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css"
19
+ = javascript_include_tag "//cdn.jsdelivr.net/npm/popper.js@1.14.7/dist/umd/popper.min.js"
20
+ = javascript_include_tag "//cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/js/bootstrap.min.js"
21
+
22
+ = stylesheet_link_tag "//cdn.jsdelivr.net/npm/select2@4.0.0/dist/css/select2.min.css"
23
+ = javascript_include_tag "//cdn.jsdelivr.net/npm/select2@4.0.0/dist/js/select2.min.js"
24
+
25
+ = stylesheet_link_tag "//cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote.min.css"
26
+ = javascript_include_tag "//cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote.min.js"
27
+
28
+ = javascript_include_tag "wco/application"
29
+ = stylesheet_link_tag "wco/application", media: "all"
30
+
31
+ = javascript_include_tag "iron_warbler/application"
32
+ = stylesheet_link_tag "iron_warbler/application", media: "all"
33
+
34
+ -# %script{crossorigin: "", src: "https://unpkg.com/react@18/umd/react.development.js"}
35
+ -# %script{crossorigin: "", src: "https://unpkg.com/react-dom@18/umd/react-dom.development.js"}
36
+ -# %script{src: "https://unpkg.com/prop-types@15.6/prop-types.min.js"}
37
+ -# %script{src: "https://unpkg.com/axios/dist/axios.min.js"}
38
+ -# %script{src: "https://unpkg.com/recharts/umd/Recharts.js"}
39
+
6
40
  = csrf_meta_tags
7
41
  = csp_meta_tag
8
- = stylesheet_link_tag "iron_warbler/application", media: "all"
9
- %body
10
- .main-menu
11
- %h5 Main Menu
12
- %ul
13
- %li= link_to 'Home - Dashboard', root_path
14
- %li= link_to 'Stocks', stocks_path
15
- -# %li= link_to 'Options', options_path
16
- %li Max Pain
17
- %li= link_to 'Alerts', alerts_path
18
- = yield
42
+ %body{ class: [ params[:controller].gsub("wco_email/",""), "#{params[:controller].gsub("wco_email/","")}-#{params[:action]}", params[:action], "application-fullwidth" ] }
43
+
44
+ = render "/wco/main_header"
45
+ = render "/iro/main_header"
46
+ = render '/wco/alerts_notices' if notice || alert
47
+ %hr
48
+
49
+ %span.absolute.collapse-expand#mainW
50
+ = yield
51
+
52
+ = render '/wco/main_footer'
53
+ = render '/iro/analytics' if Rails.env.production?
@@ -0,0 +1,10 @@
1
+
2
+ Rails.application.config.assets.version = '1.0'
3
+
4
+ Rails.application.config.assets.precompile += %w(
5
+ wco/application.js
6
+ wco/application.css
7
+
8
+ iron_warbler/application.js
9
+ iron_warbler/application.css
10
+ );
data/config/routes.rb CHANGED
@@ -8,7 +8,13 @@ Iro::Engine.routes.draw do
8
8
  get 'datapoints', to: '/iro/datapoints#index'
9
9
 
10
10
  resources :option_watches
11
+
12
+ post 'positions/:id/roll', to: 'positions#roll', as: :roll_position
13
+ resources :positions
11
14
  resources :profiles
15
+ resources :purses
16
+
12
17
  resources :stocks
18
+ resources :strategies
13
19
 
14
20
  end
data/lib/iron_warbler.rb CHANGED
@@ -1,5 +1,8 @@
1
1
 
2
- require "active_record/railtie"
2
+ require 'business_time'
3
+
3
4
  require 'haml'
4
5
 
6
+ require 'mongoid'
7
+
5
8
  require "iro/engine"
@@ -1,9 +1,33 @@
1
1
 
2
2
  namespace :db do
3
3
 
4
- desc 'create calendar'
4
+ desc 'test'
5
+ task test: :environment do
6
+ Iro::Datapoint.test
7
+ end
8
+
9
+ desc 'create calendar mdb'
5
10
  task create_calendar: :environment do
6
11
 
12
+ year = 2023
13
+ d = "#{year}-01-01".to_date
14
+ out = ""
15
+ 368.times do
16
+ if d.strftime('%Y').to_i == year+1
17
+ break
18
+ end
19
+
20
+ Iro::Date.create({ date: d.strftime('%Y-%m-%d') })
21
+ print '.'
22
+
23
+ d = d + 1.day
24
+ end
25
+
26
+ end
27
+
28
+ desc 'create calendar sql'
29
+ task create_calendar_sql: :environment do
30
+
7
31
  year = 2023
8
32
  d = "#{year}-01-01".to_date
9
33
  out = ""
@@ -24,4 +48,33 @@ namespace :db do
24
48
  `mv /opt/tmp/#{year}_calendar.sql doc/`
25
49
 
26
50
  end
51
+
52
+ desc 'test datapoints'
53
+ task create_test_datapoints: :environment do
54
+ datapoint = Iro::Datapoint.create({
55
+ date: '2023-12-28',
56
+ created_at: '2023-12-28 01:00:00',
57
+ kind: 'some-type',
58
+ value: 115,
59
+ })
60
+ datapoint = Iro::Datapoint.create({
61
+ date: '2023-12-28',
62
+ created_at: '2023-12-28 02:00:00',
63
+ kind: 'some-type',
64
+ value: 116,
65
+ })
66
+ datapoint = Iro::Datapoint.create({
67
+ date: '2023-12-30',
68
+ created_at: '2023-12-30 01:00:00',
69
+ kind: 'some-type',
70
+ value: 117,
71
+ })
72
+ datapoint = Iro::Datapoint.create({
73
+ date: '2023-12-30',
74
+ created_at: '2023-12-30 02:00:00',
75
+ kind: 'some-type',
76
+ value: 118,
77
+ })
78
+ end
79
+
27
80
  end
@@ -1,6 +1,41 @@
1
1
 
2
2
  namespace :iro do
3
3
 
4
+ desc 'recommend position actions'
5
+ task recommend_position_actions: :environment do
6
+ Iro::Position.active.where({ kind: 'covered_call' }).map &:should_roll?
7
+ end
8
+
9
+ desc 'refresh positions'
10
+ task refresh_positions: :environment do
11
+ Iro::Position.active.where({ kind: 'covered_call' }).map &:refresh
12
+ end
13
+
14
+ desc 'watch positions'
15
+ task watch_positions: :environment do
16
+ while true
17
+ if in_business
18
+
19
+ positions = Iro::Position.active.where({ kind: 'covered_call' })
20
+ positions.each do |position|
21
+ out = Tda::Option.get_quote({
22
+ contractType: 'CALL',
23
+ strike: position.strike,
24
+ expirationDate: position.expires_on,
25
+ ticker: position.ticker,
26
+ })
27
+ position.update({
28
+ end_delta: out[:delta],
29
+ end_price: out[:last],
30
+ })
31
+ end
32
+
33
+ print '.'
34
+ end
35
+ sleep 60 # seconds
36
+ end
37
+ end
38
+
4
39
  desc 'watch stocks'
5
40
  task watch_stocks: :environment do
6
41
  while true
@@ -0,0 +1,128 @@
1
+
2
+ namespace :iro do
3
+
4
+ ## 2023-03-31 _vp_ Continue.
5
+ # if Time.now.in_time_zone > Time.now.in_time_zone.beginning_of_day + 8.5.hours &&
6
+ # Time.now.in_time_zone < Time.now.in_time_zone.beginning_of_day + 15.hours
7
+ # end
8
+ #
9
+ desc 'alert on stock price action'
10
+ task alert_stocks: :environment do
11
+ while true
12
+
13
+ ::Iro::Iro.alert_stocks
14
+
15
+ print '.'
16
+ sleep 45 # seconds
17
+ end
18
+ end
19
+
20
+ ## 2023-03-31 _vp_ Done, unused.
21
+ desc 'alert stocks test'
22
+ task alert_stocks_test: :environment do
23
+ tickers_str = Iro::OptionWatch.active.where( kind: ::Iro::OptionWatch::KIND_STOCK ).map(&:ticker).join(',')
24
+ if tickers_str.present?
25
+
26
+ out = Tda::Stock.get_quotes( tickers_str )
27
+ Iro::OptionWatch.active.where( kind: ::Iro::OptionWatch::KIND_STOCK ).each do |watch|
28
+
29
+ if watch.direction == Iro::OptionWatch::DIRECTION_ABOVE && out[watch.ticker][:mark] >= watch.mark ||
30
+ watch.direction == Iro::OptionWatch::DIRECTION_BELOW && out[watch.ticker][:mark] <= watch.mark
31
+
32
+ IshManager::ApplicationMailer.stock_alert( watch.id.to_s ).deliver_later
33
+ watch.update_attributes({ state: Iro::OptionWatch::STATE_INACTIVE })
34
+
35
+ end
36
+ end
37
+
38
+ end
39
+ end
40
+
41
+ ## 2023-02-04 _vp_ :: Continue
42
+ ## 2023-02-06 _vp_ :: LFG
43
+ desc 'The runner that populates the db for graphing'
44
+ task :get_chains => :environment do
45
+ while true
46
+
47
+ ::Iro::Iro.get_chains
48
+
49
+ print '.'
50
+ # sleep 5 * 60 # 5 minutes
51
+ sleep 55 * 60 # 1 hr
52
+ end
53
+ end
54
+
55
+ desc 'Get BTC, ETH price from coinmarketcap'
56
+ task :get_coins => :environment do
57
+ while true
58
+
59
+ ::Iro::Iro.get_coins
60
+
61
+ print '.'
62
+ # sleep 5 * 60 # 5 minutes
63
+ sleep 55 * 60 # 1 hr
64
+ end
65
+ end
66
+
67
+ desc 'Get COP from currencyfreaks, cron'
68
+ task :get_currencies => :environment do
69
+ ::Iro::Iro.get_currencies
70
+ puts 'ok'
71
+ end
72
+
73
+ desc 'get gme short %'
74
+ task :get_gme_short_availability_and_fee => :environment do
75
+ errors = ::Iro::Iro.get_gme_short_availability_and_fee
76
+ puts errors.presence || '.'
77
+ end
78
+
79
+ ## 2023-03-10 _vp_ Continue.
80
+ desc 'get stocks'
81
+ task get_stocks: :environment do
82
+ while true
83
+
84
+ ::Iro::Iro.get_stocks
85
+
86
+ print '.'
87
+ # sleep 45 # seconds
88
+ sleep 55 * 60 # 1 hr
89
+ end
90
+ end
91
+
92
+ ## 2023-02-06 _vp_ :: Continue
93
+ ## 2023-02-08 _vp_ :: Continue
94
+ ## 2023-03-18 _vp_ :: Continue
95
+ ## 2023-03-19 _vp_ :: Continue, it's intense
96
+ desc 'watch positions'
97
+ task watch_positions: :environment do
98
+ while true
99
+
100
+ ::Iro::CoveredCall.active.each do |position|
101
+ position.refresh
102
+ if position.should_roll?
103
+
104
+ position.update({
105
+ next_delta: position.next_position[:delta],
106
+ next_outcome: position.next_outcome,
107
+ next_symbol: position.next_symbol,
108
+ status: Iro::Position::STATE_PROPOSED,
109
+ })
110
+
111
+ out = IroMailer.should_roll({
112
+ next_symbol: position.next_symbol,
113
+ prev_symbol: position.prev_symbol,
114
+ })
115
+ Rails.env.production? ? out.deliver_later : out.deliver_now
116
+
117
+ print '+'
118
+ end
119
+ end
120
+
121
+ print '.'
122
+ sleep 15 * 60 # 15 min
123
+ # sleep 60 * 60 # 1 hr
124
+ end
125
+ end
126
+
127
+
128
+ end