ish_manager 0.1.8.403 → 0.1.8.405

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a3b2381f54eb7b66d392fbaa4051bd78ee53f1ad8b455f8a55db82a0c9fca62
4
- data.tar.gz: 65a33aebdf8b15526dee6e37f62824b304f2a0672eef3e55ebd866dd072d5fe8
3
+ metadata.gz: 70242298b4fbef9e7055284f6e8a603aa20e5ce5782c82cd2461bd69717e7a4f
4
+ data.tar.gz: 8f9d6291f35c98cafc912b3f331421d74ab8048f699ddc52b198b2f2fffc00d0
5
5
  SHA512:
6
- metadata.gz: a7284a7a74330a4878a4b2136e17aa3c8ac47079fcbb36fb758c7c8b8252bbcc84eb66c578789971af86bad0fa2b39568285d72024be5185fb7f632c01d5beaa
7
- data.tar.gz: 047b94313ffef19b69373fdc99d918d9c4f9c4ab76e87d75256e086a8d0e9b12a0c891eb02bc259c32a8edb5bbc6b870733fc485b8cee2765300c58b147c9075
6
+ metadata.gz: 66421a7174df41ff783faafc109ef30f61ccbe0035cfdb91ad9ac8c16f0f3c7dfaf59af82b74854cf849b881762a88cb2a93e5a4df4d56299f180476127778cd
7
+ data.tar.gz: 488f4c3488c0e389c070a12979083e39c026579773c164dc6134fa3f0a48b472a1ec1f14dc8c906ec95a8127694cbec58cb90db999fc82f75c8641711e6d0638
@@ -1,19 +1,59 @@
1
1
 
2
- .iro-purses-my {
3
- font-size: 16px; // @TODO: make uniform _vp_ 2023-03-19
2
+ .iro-purses-show {
3
+ font-size: 14px;
4
4
 
5
5
  table {
6
+ .id {
7
+ width: 20px;
8
+ }
9
+ .strategy {
10
+ width: 30px;
11
+ }
12
+
13
+ thead {
14
+ position: relative;
15
+ height: 50px;
16
+
17
+
18
+ .id,
19
+ .ticker,
20
+ .days-left,
21
+ .to-close,
22
+ .must-roll {
23
+ top: 0;
24
+ }
25
+
26
+ .price {
27
+ background: cyan;
28
+ }
29
+
30
+ td > div {
31
+ // border: 1px solid green;
32
+
33
+ position: absolute;
34
+ }
35
+ }
36
+
6
37
 
7
38
  td {
8
39
  padding: 0 .5em;
9
40
  }
10
41
 
11
42
  tbody {
43
+ .begin-delta {
44
+ min-width: 20px;
45
+ }
12
46
  .must-roll,
13
47
  .next-symbol {
14
48
  text-align: center;
15
49
  }
16
50
 
51
+ .must-roll,
52
+ .should-roll,
53
+ .next-symbol {
54
+ background: #eee;
55
+ }
56
+
17
57
  .net,
18
58
  .netp {
19
59
  font-weight: bold;
@@ -28,22 +68,31 @@
28
68
  }
29
69
 
30
70
 
31
-
32
- .must-roll,
33
- .should-roll,
34
- .next-symbol {
35
- background: #eee;
36
- }
37
-
38
71
  .q {
39
72
  font-weight: bold;
40
73
  }
41
74
 
42
- .strategy {
43
- pre {
44
- font-size: 12px;
45
- background: #eee;
46
- }
75
+ .strategies {
76
+
77
+ display: flex;
78
+ flex-wrap: wrap;
47
79
  }
48
80
 
49
81
  }
82
+ .iro-strategies-edit,
83
+ .iro-strategies-new {
84
+ display: flex;
85
+ flex-direction: column;
86
+ align-items: flex-start;
87
+ }
88
+ .iro-strategies--form {
89
+ border: 1px solid blue;
90
+ border-radius: 0.5em;
91
+ padding: 0.5em;
92
+ margin-right: .5em;
93
+
94
+ .field {
95
+ display: flex;
96
+ justify-content: space-between;
97
+ }
98
+ }
@@ -6,23 +6,20 @@ class ::IshManager::IroPursesController < IshManager::ApplicationController
6
6
  def show
7
7
  @purse = Iro::Purse.find_or_create_by({ user_id: current_user.id })
8
8
  authorize! :my, @purse
9
- @positions = @purse.positions.order({ expires_on: :asc, strike: :asc })
10
- @positions.map &:refresh
9
+
11
10
  @strategies = Iro::CoveredCallStrategy.where({
12
11
  iro_purse_id: Iro::Purse.find_by( user_id: current_user.id ).id,
13
12
  })
13
+
14
+ underlyings = Tda::Stock.get_quotes( @strategies.map(&:ticker).compact.uniq.join(",") )
15
+ # json_puts! underlyings, 'out'
16
+ underlyings.each do |ticker, v|
17
+ Iro::CoveredCallStrategy.where( ticker: ticker ).update( current_underlying_strike: v[:mark] )
18
+ end
19
+
20
+ @positions = @purse.positions.order({ expires_on: :asc, strike: :asc })
21
+ @positions.active.map &:refresh
14
22
  end
15
23
 
16
24
  end
17
25
 
18
- =begin
19
- @strategy = {
20
- buffer_above_water: 0.49, # be this much $ above current price, in next position
21
- next_max_delta: 0.25, # of next position
22
- next_min_price: 16,
23
- threshold_delta: 0.14, # should roll at this delta
24
- threshold_netp: 0.69, # should roll at the net %
25
- target_profilt: 0.19, # unused
26
- current_underlying_strike: 16.6,
27
- }
28
- =end
@@ -30,10 +30,6 @@ module IshManager
30
30
  # "/manager/email_contexts/for_lead/#{lead.id.to_s}"
31
31
  # end
32
32
 
33
- def pretty_date input
34
- return input.strftime("%Y-%m-%d")
35
- end
36
-
37
33
  def pp_errors errors
38
34
  return errors
39
35
  end
@@ -53,6 +49,12 @@ module IshManager
53
49
  date&.strftime('%Y-%m-%d')
54
50
  end
55
51
  def pp_date a; pretty_date a; end
52
+ def pp_datetime date
53
+ date&.strftime('%Y-%m-%d %l:%M%P %z')
54
+ end
55
+ def pp_time date
56
+ date&.strftime('%l:%M%P %z')
57
+ end
56
58
 
57
59
  def pp_amount a
58
60
  return '-' if !a
@@ -12,7 +12,7 @@ module IshManager
12
12
  @gallery_path = IshManager::Engine.routes.url_helpers.gallery_path(@gallery.slug)
13
13
  mail( :to => '314658@gmail.com',
14
14
  :bcc => profiles.map { |p| p.email },
15
- :subject => 'You got new shared galleries on pi manager' ).deliver
15
+ :subject => 'You got new shared galleries on pi manager' )
16
16
  end
17
17
 
18
18
  def option_alert option
@@ -32,7 +32,7 @@ module IshManager
32
32
  end
33
33
 
34
34
  def test_email
35
- mail( to: 'piousbox@gmail.com', subject: "Test email at #{Time.now}" )
35
+ mail( to: DEFAULT_RECIPIENT, subject: "Test email at #{Time.now}" )
36
36
  end
37
37
 
38
38
  end
@@ -54,8 +54,9 @@ class IshManager::OfficeMailer < IshManager::ApplicationMailer
54
54
  template_name: template )
55
55
  end
56
56
 
57
+ ## 2023-04-02 _vp_ Continue.
57
58
  def send_context_email ctx_id
58
- @ctx = ::Ish::EmailContext.find ctx_id
59
+ @ctx = Ctx.find ctx_id
59
60
  ac = ActionController::Base.new
60
61
  ac.instance_variable_set( :@ctx, @ctx )
61
62
 
@@ -69,18 +70,3 @@ class IshManager::OfficeMailer < IshManager::ApplicationMailer
69
70
  end
70
71
 
71
72
  end
72
-
73
-
74
- ## 2022-11-10 _vp_ backup
75
- # def send_context_email ctx_id
76
- # @email_ctx = ::Ish::EmailContext.find ctx_id
77
- # template = "render/_#{@email_ctx.email_template.slug}"
78
- # ac = ActionController::Base.new
79
- # ac.instance_variable_set( :@email_ctx, @email_ctx )
80
- # rendered_str = ac.render_to_string("ish_manager/email_templates/_#{@email_ctx.email_template.slug}")
81
- # @email_ctx.update( rendered_str: rendered_str, sent_at: Time.now )
82
- # mail( to: @email_ctx.to_email,
83
- # bcc: 'piousbox@gmail.com',
84
- # subject: @email_ctx.subject,
85
- # template_name: template )
86
- # end
@@ -3,6 +3,7 @@
3
3
  Debug
4
4
  .application--debug
5
5
  %ul.browser-default
6
+ %li= link_to 'sidekiq', '/sidekiq', target: :_blank
6
7
  %li= params.inspect
7
8
  %li Cached? #{Rails.application.config.action_controller.perform_caching} :: Cache key: #{@cache_key.inspect}
8
9
  %li= "Env: #{Rails.env}"
@@ -44,7 +44,9 @@
44
44
  = link_to email_context_path(ctx) do
45
45
  = ctx.subject ? ctx.subject : "t| #{ctx.tmpl.subject}"
46
46
  %td= ctx.email_template.slug
47
- %td= pp_date ctx.send_at
47
+ %td.send_at
48
+ .a= pp_date ctx.send_at
49
+ .a= pp_time ctx.send_at
48
50
  %td= pp_date ctx.sent_at
49
51
 
50
52
 
@@ -3,7 +3,7 @@
3
3
 
4
4
  .iro-positions--form
5
5
  = form_for position, as: :position, url: url do |f|
6
- .flex-row
6
+ .a
7
7
  .field Position ##{position.id}
8
8
  .field
9
9
  = f.label :strategy
@@ -19,9 +19,14 @@
19
19
  .field
20
20
  = f.label :expires_on
21
21
  = f.text_field :expires_on
22
+
23
+ .field
24
+ = f.label :quantity
25
+ = f.number_field :quantity
26
+
22
27
  .field
23
28
  = f.label :status
24
- = f.select :status, options_for_select( Iro::Position.statuses_list, selected: position.status ), {}, class: 'select2'
29
+ = f.select :status, options_for_select( Iro::Position.states_list, selected: position.status ), {}, class: 'select2'
25
30
 
26
31
  .field
27
32
  = f.label :opened_price
@@ -1,3 +1,3 @@
1
1
 
2
- .iro-positions-edit.padded
2
+ .iro-positions-edit.max-width
3
3
  = render 'form', position: @position
@@ -1,41 +1,58 @@
1
1
 
2
- .iro-purses-my.padded
3
- .header
4
- %h2.title Purse value: $#{@purse.current_value}
2
+ .iro-purses-show.padded
3
+ .max-width
4
+ .header
5
+ %h4.title Purse value: $#{@purse.current_value}
5
6
 
6
- .strategies
7
- .title Strategies
7
+
8
+ %h5.collapse-expand#strategies Strategies #{link_to '[+]', new_iro_strategy_path}
9
+ .strategies.items
8
10
  - @strategies.each do |strat|
9
- .strategy
10
- = link_to '[~]', edit_iro_strategy_path( strat )
11
- <pre>#{JSON.pretty_generate( strat.display_attrs )}</pre>
11
+ -# .strategy.item
12
+ -# = link_to '[~]', edit_iro_strategy_path( strat )
13
+ -# <pre>#{JSON.pretty_generate( strat.display_attrs )}</pre>
14
+ .strategy.item= render 'ish_manager/iro_strategies/form', strategy: strat
12
15
 
13
16
 
17
+ %h5.collapse-expand#positions
18
+ Positions (#{@positions.length})
19
+ = link_to '[+]', new_iro_position_path
14
20
  .positions
15
- %h3
16
- Positions (#{@positions.length})
17
- = link_to '[+]', new_iro_position_path
21
+
18
22
 
19
23
  %table.bordered
20
24
  %thead
21
25
  %tr
22
- %td id
23
- %td Strategy
24
- %td Ticker
26
+ %td
27
+ .id id
28
+ %td
29
+ .strategy Strategy
30
+ %td
31
+ .ticker Ticker
25
32
  %td Kind/Type
26
33
  %td Strike
27
34
  %td ExpiresOn
28
- %td Days Left
29
- %td.q Q
30
- %td Begin On
31
- %td Begin $
32
- %td Begin #{"\u0394"}
33
- %td Current $
35
+ %td
36
+ .days-left Days Left
37
+ %td
38
+ .q Q
39
+ %td
40
+ .begin-on Begin On
41
+ %td
42
+ .price Price
43
+ %td
44
+ .to-open To Open
45
+ %td
46
+ .begin-delta #{"\u0394"}
47
+ %td
48
+ .to-close Current $ <br />(To Close)
34
49
  %td.net Net
35
50
  %td.netp % Net
36
- %td Curr #{"\u0394"}
37
- %td Days at Open
38
- %td.must-roll Must roll?
51
+ %td #{"\u0394"}
52
+ %td
53
+ .days-at-open Days@Open
54
+ %td
55
+ .must-roll Must roll?
39
56
  %td.should-roll Should roll?
40
57
  %td.next-symbol Next Symbol
41
58
  %td.next-outcome Next Outcome
@@ -43,19 +60,20 @@
43
60
  %tbody
44
61
  - @positions.each do |p|
45
62
  %tr
46
- %td
63
+ %td.id
47
64
  = p.id
48
65
  = link_to '[~]', edit_iro_position_path(p)
49
- %td= p.strategy
66
+ %td.strategy= link_to p.strategy, edit_iro_strategy_path(p.strategy)
50
67
  %td= p.ticker
51
68
  %td= p.type == "Iro::CoveredCall" ? "CALL" : "other"
52
69
  %td= p.strike
53
70
  %td= p.expires_on.strftime('%b %d')
54
- %td= (p.expires_on.to_date - Time.now.to_date).to_i
71
+ %td.days-left= (p.expires_on.to_date - Time.now.to_date).to_i
55
72
  %td.q= p.quantity
56
- %td= pp_date p.opened_on
57
- %td= p.opened_price
58
- %td= sprintf('%.2f', p.opened_delta ) rescue nil
73
+ %td.begin-on= pp_date p.opened_on
74
+ %td.price= p.opened_price
75
+ %td.to-open= pp_amount( p.opened_price * 100 * p.quantity )
76
+ %td.begin-delta= sprintf('%.2f', p.opened_delta ) rescue nil
59
77
  %td= pp_money p.current_price
60
78
  %td.net= pp_money ( p.opened_price - p.current_price ) * 100 - 1.3
61
79
  %td.netp= pp_percent ( p.opened_price - p.current_price ) / p.opened_price
@@ -2,6 +2,15 @@
2
2
  - url = strategy.new_record? ? iro_strategies_path : iro_strategy_path(strategy)
3
3
  .iro-strategies--form
4
4
  = form_for strategy, url: url, as: :iro_strategy do |f|
5
+ .field
6
+ = "#{strategy.id}." if strategy.id
7
+ = f.label :slug
8
+ = f.text_field :slug
9
+ .actions
10
+ = f.submit 'Submit', :data => { :confirm => 'Are you sure?' }
11
+ .field
12
+ = f.label :ticker
13
+ = f.text_field :ticker
5
14
  .field
6
15
  = f.label :buffer_above_water
7
16
  = f.number_field :buffer_above_water, placeholder: "0.49", step: 0.01
@@ -17,12 +26,7 @@
17
26
  .field
18
27
  = f.label :threshold_netp
19
28
  = f.number_field :threshold_netp, placeholder: "0.69", step: 0.01
20
- .field
21
- = f.label :target_profit
22
- = f.number_field :target_profit, placeholder: "0.19", step: 0.01
23
29
  .field
24
30
  = f.label :current_underlying_strike
25
31
  = f.number_field :current_underlying_strike, placeholder: "16.66", step: 0.01
26
32
 
27
- .actions
28
- = f.submit 'Submit'
@@ -1,9 +1,4 @@
1
1
 
2
- def puts! a, b=''
3
- puts "+++ +++ #{b}"
4
- puts a.inspect
5
- end
6
-
7
2
  namespace :office do
8
3
 
9
4
  desc 'scheduled email actions, rolling perform'
@@ -11,34 +6,10 @@ namespace :office do
11
6
  while true do
12
7
 
13
8
  Sch.active.where({ :perform_at.lte => Time.now }).each do |sch|
14
- sch.update_attributes({ state: Sch::STATE_INACTIVE })
15
9
 
16
- # send now
17
- ctx = Ctx.new({
18
- email_template_id: sch.act.tmpl.id,
19
- lead_id: sch.lead.id,
20
- send_at: Time.now,
21
- subject: sch.act.tmpl.subject,
22
- from_email: sch.act.tmpl.from_email,
23
- scheduled_email_action_id: sch.act.id,
24
- })
25
- ctx.save!
26
-
27
- # schedule next actions & update the action
28
- sch.act.ties.each do |tie|
29
- next_act = tie.next_email_action
30
- next_at = eval(tie.next_at_exe)
31
- next_sch = Sch.find_or_initialize_by({
32
- lead_id: sch.lead_id,
33
- email_action_id: next_act.id,
34
- })
35
- next_sch.perform_at = next_at
36
- next_sch.state = Sch::STATE_ACTIVE
37
- next_sch.save!
38
- end
10
+ sch.send_and_roll
39
11
 
40
12
  print '+'
41
-
42
13
  end
43
14
 
44
15
  # sleep 1.minute
@@ -47,13 +18,15 @@ namespace :office do
47
18
  end
48
19
  end
49
20
 
21
+ ## 2023-04-02 _vp_ Continue.
50
22
  desc "send emails"
51
- task email_worker: :environment do
23
+ task ctxs: :environment do
52
24
  while true do
53
25
 
54
26
  ctxs = ::Ish::EmailContext.scheduled.notsent
55
27
  ctxs.map do |ctx|
56
- IshManager::OfficeMailer.send_context_email( ctx[:id].to_s ).deliver_later
28
+ out = IshManager::OfficeMailer.send_context_email( ctx[:id].to_s )
29
+ Rails.env.production? ? out.deliver_later : out.deliver_now
57
30
  print '^'
58
31
  end
59
32
 
@@ -30,5 +30,25 @@ namespace :migrate do
30
30
  end
31
31
  end
32
32
 
33
+ desc "every user needs a user_profile"
34
+ task :generate_user_profiles => :environment do
35
+ User.all.map do |u|
36
+ unless u.profile
37
+ p = ::Ish::UserProfile.new :email => u.email, :user => u, :role_name => :guy
38
+ u.profile = p
39
+ u.save && p.save && print('.')
40
+ end
41
+ end
42
+ puts 'OK'
43
+ end
44
+
45
+ desc 'assign my creator_profile to Gameui::Marker where missing'
46
+ task :gameui_markers_creator_profile => :environment do
47
+ ms = Gameui::Marker.where( creator_profile_id: nil )
48
+ profile = User.find_by( email: 'piousbox@gmail.com' ).profile
49
+ ms.update_all( creator_profile_id: profile.id )
50
+ end
51
+
52
+
33
53
  end
34
54
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ish_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8.403
4
+ version: 0.1.8.405
5
5
  platform: ruby
6
6
  authors:
7
7
  - piousbox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-01 00:00:00.000000000 Z
11
+ date: 2023-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -598,7 +598,6 @@ files:
598
598
  - lib/systemd/system/stockwatcher.service
599
599
  - lib/systemd/system/watch_stocks.service
600
600
  - lib/tasks-done/migrate.rake
601
- - lib/tasks/ish_manager_tasks.rake
602
601
  - lib/tasks/office_tasks.rake
603
602
  homepage: http://wasya.co
604
603
  licenses:
@@ -1,29 +0,0 @@
1
-
2
- def puts! a, b=''
3
- puts "+++ +++ #{b}"
4
- puts a.inspect
5
- end
6
-
7
- namespace :ish_manager do
8
-
9
- desc "every user needs a user_profile"
10
- task :generate_user_profiles => :environment do
11
- User.all.map do |u|
12
- unless u.profile
13
- p = ::Ish::UserProfile.new :email => u.email, :user => u, :role_name => :guy
14
- u.profile = p
15
- u.save && p.save && print('.')
16
- end
17
- end
18
- puts 'OK'
19
- end
20
-
21
- desc 'assign my creator_profile to Gameui::Marker where missing'
22
- task :gameui_markers_creator_profile => :environment do
23
- ms = Gameui::Marker.where( creator_profile_id: nil )
24
- profile = User.find_by( email: 'piousbox@gmail.com' ).profile
25
- ms.update_all( creator_profile_id: profile.id )
26
- end
27
-
28
-
29
- end