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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2159d8b3de0e6eac4b368c066b2b30cf695947f269d473d95ed5534886a8b9fc
4
- data.tar.gz: a4ce089651c5002e8aa1fd16bc6c169a8851f9b242a08fb00b34a1564c7d0ee1
3
+ metadata.gz: 179360dc9b7500f3725379c3c25e6a43c0f5b4bcf4fff1d16f1b23022fe1e8dc
4
+ data.tar.gz: e0800a507ec076cb0f819838c83a01d4ba75130b81fd4c86fe1e2fa1acdc905c
5
5
  SHA512:
6
- metadata.gz: 104699e1860d29ac33ddcc8db3280718aa39500c49bd9d36fc860837bb05f1181690a48c67a3b8d2a83cf5be7d42bb8f767f7ed5a1dac57b411029a94e56e34f
7
- data.tar.gz: af0e81f2ed886ef36680bf946a9c1188858e0eaf3a6a8ed368ad56e23959c644b3e739dc56d15de9622c568b99ff4990b6f64fab6e95c84312ebf98788f8ee94
6
+ metadata.gz: '08052f61264a239d4e07bc14564e1f54c624d627c947f1ab7cce88a7e6ddffeaac64d92d91393c8f8842e0d7c8db236f1b0ec589a9b3e9251a00dd17a0f7232e'
7
+ data.tar.gz: 29772fd02c33118fb73797a981a4b03d0bbe561ab645623c4fd5abb0dc7fa0f2a6e9c7fd1bcb5cd918c873751d05210574ff38281e1ebfa72656357970dcb468
data/Rakefile CHANGED
@@ -1,18 +1,5 @@
1
- require "bundler/setup"
2
1
 
3
- APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
- load "rails/tasks/engine.rake"
2
+ require_relative 'test/dummy/config/application'
5
3
 
6
- load "rails/tasks/statistics.rake"
7
-
8
- require "bundler/gem_tasks"
9
-
10
- require "rake/testtask"
11
-
12
- Rake::TestTask.new(:test) do |t|
13
- t.libs << 'test'
14
- t.pattern = 'test/**/*_test.rb'
15
- t.verbose = false
16
- end
17
-
18
- task default: :test
4
+ # Rails.application.initialize!
5
+ Rails.application.load_tasks
@@ -0,0 +1,3 @@
1
+
2
+ // console.log('Loaded iron_warbler/application.js')
3
+
@@ -0,0 +1,47 @@
1
+
2
+ .positions--table {
3
+
4
+ table {
5
+ td {
6
+ text-align: center;
7
+ }
8
+ td.actions,
9
+ td.next_position,
10
+ td.strategy,
11
+ ._ {
12
+ text-align: left;
13
+ }
14
+ th {
15
+ border: 1px solid red;
16
+
17
+ > * {
18
+ border: 1px solid yellow;
19
+ // background: #ddd;
20
+
21
+ transform-origin: 0 0;
22
+ rotate: -40deg;
23
+
24
+ padding: .4em 0;
25
+ width: 120px;
26
+
27
+ }
28
+
29
+ }
30
+
31
+ th.begin_price {
32
+ > div {
33
+ background: cyan;
34
+ }
35
+ }
36
+
37
+ th.end_delta {
38
+ width: 50px;
39
+ }
40
+ th.next_position {
41
+ width: 160px;
42
+ }
43
+ th.next_symbol {
44
+ width: 120px;
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,44 @@
1
+
2
+ /* F */
3
+
4
+ .flex-row {
5
+ display: flex;
6
+ margin-bottom: 0.4em;
7
+ }
8
+ .field {
9
+ min-width: 100px;
10
+ margin-right: 1em;
11
+ }
12
+
13
+ /* M */
14
+
15
+ .modal-absolute {
16
+ border: 1px solid green;
17
+ border-radius: 5px;
18
+ box-shadow: 2px 2px;
19
+
20
+ padding: 0.5em;
21
+
22
+ position: absolute;
23
+
24
+ min-width: 200px;
25
+ width: 400px;
26
+
27
+ min-height: 200px;
28
+ height: 300px;
29
+ /* overflow: auto; */
30
+
31
+ background: white;
32
+
33
+ z-index: 2;
34
+
35
+ }
36
+
37
+
38
+
39
+ /* W */
40
+
41
+ .w-min-50px {
42
+ min-width: 50px;
43
+ }
44
+
@@ -4,7 +4,8 @@ class Iro::AlertsController < Iro::ApplicationController
4
4
  before_action :set_lists
5
5
 
6
6
  def create
7
- @alert = Iro::Alert.new(alert_params)
7
+ @alert = Iro::Alert.new params[:alert].permit!
8
+ authorize! :create, @alert
8
9
  if @alert.save
9
10
  redirect_to action: :index, notice: 'Alert was successfully created.'
10
11
  else
@@ -14,17 +15,20 @@ class Iro::AlertsController < Iro::ApplicationController
14
15
 
15
16
  def destroy
16
17
  @alert = Iro::Alert.find(params[:id])
18
+ authorize! :destroy, @alert
17
19
  @alert.destroy
18
20
  redirect_to action: :index, notice: 'Alert was successfully destroyed.'
19
21
  end
20
22
 
21
23
  def index
22
24
  @alerts = Iro::Alert.all
25
+ authorize! :index, Iro::Alert
23
26
  end
24
27
 
25
28
  def update
26
29
  @alert = Iro::Alert.find(params[:id])
27
- if @alert.update(alert_params)
30
+ authorize! :update, @alert
31
+ if @alert.update params[:alert].permit!
28
32
  redirect_to action: :index, notice: 'Alert was successfully updated.'
29
33
  else
30
34
  render :edit
@@ -36,10 +40,6 @@ class Iro::AlertsController < Iro::ApplicationController
36
40
  ##
37
41
  private
38
42
 
39
- def alert_params
40
- params.require(:alert).permit(:class_name, :kind, :symbol, :direction, :strike, :profile_id)
41
- end
42
-
43
43
  def set_lists
44
44
  # @profiles_list = Wco::Profile.list
45
45
  @stocks_list = [[nil,nil]] + Iro::Stock.active.map { |s| [ s.ticker, s.ticker ] }
@@ -1,9 +1,10 @@
1
1
 
2
2
 
3
- class Iro::ApplicationController < ActionController::Base
4
- # layout 'iro/application'
3
+ class Iro::ApplicationController < Wco::ApplicationController
4
+ layout 'iro/application'
5
5
 
6
6
  def home
7
+ authorize! :home, Iro
7
8
  end
8
9
 
9
10
  end
@@ -1,6 +1,4 @@
1
1
 
2
- # require_dependency "iro/application_controller"
3
-
4
2
  class Iro::DatapointsController < Iro::ApplicationController
5
3
 
6
4
  ## params: d, k, v
@@ -0,0 +1,62 @@
1
+
2
+ class Iro::PositionsController < Iro::ApplicationController
3
+
4
+ before_action :set_lists
5
+
6
+ def new
7
+ @position = Iro::Position.new purse_id: params[:purse_id]
8
+ authorize! :new, @posision
9
+ end
10
+
11
+ def create
12
+ @position = Iro::Position.new params[:position].permit!
13
+ authorize! :create, @position
14
+
15
+ if @position.save
16
+ flash_notice @position
17
+ redirect_to controller: :purses, action: :show, id: @position.purse_id.to_s
18
+ else
19
+ flash_alert @position
20
+ redirect_to request.referrer
21
+ end
22
+ end
23
+
24
+ def destroy
25
+ @position = Iro::Position.find params[:id]
26
+ authorize! :destroy, @position
27
+ @position.delete
28
+ flash_notice "Probably ok"
29
+ redirect_to request.referrer
30
+ end
31
+
32
+ def edit
33
+ @position = Iro::Position.find params[:id]
34
+ authorize! :edit, @position
35
+
36
+ @strategies_list = Iro::Strategy.for_ticker( @position.ticker ).list
37
+ end
38
+
39
+ def update
40
+ @position = Iro::Position.find params[:id]
41
+ authorize! :update, @position
42
+
43
+ if @position.update params[:position].permit!
44
+ flash_notice @position
45
+ redirect_to controller: :purses, action: :show, id: @position.purse_id.to_s
46
+ else
47
+ flash_alert @position
48
+ redirect_to request.referrer
49
+ end
50
+ end
51
+
52
+ ##
53
+ ## private
54
+ ##
55
+ private
56
+
57
+ def set_lists
58
+ @strategies_list = Iro::Strategy.list
59
+ @tickers_list = Iro::Stock.tickers_list
60
+ end
61
+
62
+ end
@@ -1,6 +1,4 @@
1
1
 
2
- # require_dependency "iro/application_controller"
3
-
4
2
  class Iro::ProfilesController < Iro::ApplicationController
5
3
  before_action :set_profile, only: [:show, :edit, :update, :destroy]
6
4
 
@@ -0,0 +1,65 @@
1
+
2
+ class Iro::PursesController < Iro::ApplicationController
3
+
4
+ before_action :set_lists
5
+
6
+ def create
7
+ @purse = Iro::Purse.new params[:purse].permit!
8
+ authorize! :create, @purse
9
+ if @purse.save
10
+ redirect_to action: :index, notice: 'Purse was successfully created.'
11
+ else
12
+ render :new
13
+ end
14
+ end
15
+
16
+ def destroy
17
+ @purse = Iro::Purse.find(params[:id])
18
+ authorize! :destroy, @purse
19
+ @purse.destroy
20
+ redirect_to action: :index, notice: 'Purse was successfully destroyed.'
21
+ end
22
+
23
+ def edit
24
+ @purse = Iro::Purse.find(params[:id])
25
+ authorize! :edit, @purse
26
+
27
+
28
+ end
29
+
30
+ def index
31
+ @purses = Iro::Purse.all
32
+ authorize! :index, Iro::Purse
33
+ end
34
+
35
+ def show
36
+ @purse = Iro::Purse.find(params[:id])
37
+ authorize! :show, @purse
38
+
39
+ @positions = Iro::Position.all
40
+ end
41
+
42
+ def update
43
+ @purse = Iro::Purse.find(params[:id])
44
+ authorize! :update, @purse
45
+ if @purse.update params[:purse].permit!
46
+ redirect_to action: :index, notice: 'Purse was successfully updated.'
47
+ else
48
+ render :edit
49
+ end
50
+ end
51
+
52
+ ##
53
+ ## private
54
+ ##
55
+ private
56
+
57
+ def set_lists
58
+ # @profiles_list = Wco::Profile.list
59
+ @stocks_list = [[nil,nil]] + Iro::Stock.active.map { |s| [ s.ticker, s.ticker ] }
60
+
61
+ end
62
+
63
+
64
+ end
65
+
@@ -4,6 +4,7 @@ class Iro::StocksController < Iro::ApplicationController
4
4
 
5
5
  def index
6
6
  @stocks = Iro::Stock.all
7
+ authorize! :index, Iro::Stock
7
8
  end
8
9
 
9
10
  def show
@@ -11,6 +12,7 @@ class Iro::StocksController < Iro::ApplicationController
11
12
 
12
13
  def new
13
14
  @stock = Iro::Stock.new
15
+ authorize! :new, @stock
14
16
  end
15
17
 
16
18
  def edit
@@ -18,20 +20,25 @@ class Iro::StocksController < Iro::ApplicationController
18
20
 
19
21
  def create
20
22
  @stock = Iro::Stock.new(stock_params)
23
+ authorize! :create, @stock
21
24
 
22
25
  if @stock.save
23
- redirect_to action: :index, notice: 'Stock was successfully created.'
26
+ flash_notice @stock
24
27
  else
25
- render :new
28
+ flash_alert @stock
26
29
  end
30
+ redirect_to action: :index
27
31
  end
28
32
 
29
33
  def update
34
+ @stock = Iro::Stock.find params[:id]
35
+ authorize! :update, @stock
30
36
  if @stock.update(stock_params)
31
- redirect_to @stock, notice: 'Stock was successfully updated.'
37
+ flash_notice @stock
32
38
  else
33
- render :edit
39
+ flash_alert @stock
34
40
  end
41
+ redirect_to request.referrer
35
42
  end
36
43
 
37
44
  def destroy
@@ -0,0 +1,66 @@
1
+
2
+ class Iro::StrategiesController < Iro::ApplicationController
3
+
4
+ before_action :set_lists
5
+
6
+ def new
7
+ @strategy = Iro::Strategy.new
8
+ authorize! :new, @posision
9
+ end
10
+
11
+ def create
12
+ @strategy = Iro::Strategy.new params[:strategy].permit!
13
+ authorize! :create, @strategy
14
+
15
+ if @strategy.save
16
+ flash_notice @strategy
17
+ else
18
+ flash_alert @strategy
19
+ end
20
+
21
+ redirect_to action: :index
22
+ end
23
+
24
+ def destroy
25
+ @strategy = Iro::Strategy.find params[:id]
26
+ authorize! :destroy, @strategy
27
+ @strategy.delete
28
+ flash_notice "Probably ok"
29
+ redirect_to request.referrer
30
+ end
31
+
32
+ def edit
33
+ @strategy = Iro::Strategy.find params[:id]
34
+ authorize! :edit, @strategy
35
+ end
36
+
37
+ def index
38
+ authorize! :index, Iro::Strategy
39
+ @strategies = Iro::Strategy.all
40
+ render '_table'
41
+ end
42
+
43
+ def update
44
+ @strategy = Iro::Strategy.find params[:id]
45
+ authorize! :update, @strategy
46
+
47
+ if @strategy.update params[:strategy].permit!
48
+ flash_notice @strategy
49
+ else
50
+ flash_alert @strategy
51
+ end
52
+
53
+ redirect_to action: :index
54
+ end
55
+
56
+ ##
57
+ ## private
58
+ ##
59
+ private
60
+
61
+ def set_lists
62
+ @strategies_list = Iro::Strategy.list
63
+ @tickers_list = Iro::Stock.tickers_list
64
+ end
65
+
66
+ end
@@ -1,6 +1,8 @@
1
1
 
2
- class Iro::Alert < Iro::ApplicationRecord
3
- self.table_name = 'iro_alerts'
2
+ class Iro::Alert
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+ store_in collection: 'iro_alerts'
4
6
 
5
7
  SLEEP_TIME_SECONDS = Rails.env.production? ? 60 : 15
6
8
 
@@ -13,11 +15,20 @@ class Iro::Alert < Iro::ApplicationRecord
13
15
  STATUS_ACTIVE = 'active'
14
16
  STATUS_INACTIVE = 'inactive'
15
17
  STATUSES = [ 'active', 'inactive' ]
16
-
17
-
18
18
  def self.active
19
19
  where( status: STATUS_ACTIVE )
20
20
  end
21
21
 
22
+ field :class_name
23
+ validates :class_name, presence: true
24
+
25
+ field :symbol
26
+ validates :symbol, presence: true
27
+
28
+ field :direction
29
+ validates :direction, presence: true
30
+
31
+ field :strike
32
+ validates :strike, presence: true
22
33
 
23
34
  end
@@ -1,5 +1,110 @@
1
1
 
2
- class Iro::Datapoint < Iro::ApplicationRecord
3
- self.table_name = "iro_datapoints"
4
2
 
5
- end
3
+ class Iro::Datapoint
4
+ include Mongoid::Document
5
+ include Mongoid::Timestamps
6
+ store_in collection: 'iro_datapoints'
7
+
8
+ field :date
9
+ field :value, type: Float
10
+ field :kind
11
+
12
+ def self.test_0trash
13
+ add_fields = { '$addFields': {
14
+ 'date_string': {
15
+ '$dateToString': { 'format': "%Y-%m-%d", 'date': "$created_at" }
16
+ }
17
+ } }
18
+ group = { '$group': {
19
+ '_id': "$date_string",
20
+ 'my_doc': { '$first': "$$ROOT" }
21
+ } }
22
+ group = { '$group': {
23
+ '_id': "$date",
24
+ 'my_doc': { '$first': "$$ROOT" }
25
+ } }
26
+ lookup = { '$lookup': {
27
+ 'from': 'iro_dates',
28
+ 'localField': 'date_string',
29
+ 'foreignField': 'date',
30
+ 'as': 'dates',
31
+ } }
32
+ lookup_merge = { '$replaceRoot': {
33
+ 'newRoot': { '$mergeObjects': [
34
+ { '$arrayElemAt': [ "$dates", 0 ] }, "$$ROOT"
35
+ ] }
36
+ } }
37
+ match = { '$match': {
38
+ 'kind': 'some-type',
39
+ 'created_at': {
40
+ '$gte': '2023-12-01'.to_datetime,
41
+ '$lte': '2023-12-31'.to_datetime,
42
+ }
43
+ } }
44
+
45
+ outs = Iro::Datapoint.collection.aggregate([
46
+ add_fields,
47
+ lookup, lookup_merge,
48
+ match,
49
+
50
+ { '$sort': { 'date_string': 1 } },
51
+ group,
52
+ # { '$replaceRoot': { 'newRoot': "$my_doc" } },
53
+ # { '$project': { '_id': 0, 'date_string': 1, 'value': 1 } },
54
+ ])
55
+
56
+ puts! 'result'
57
+ pp outs.to_a
58
+ # puts! outs.to_a, 'result'
59
+ end
60
+
61
+ def self.test
62
+ lookup = { '$lookup': {
63
+ 'from': 'iro_datapoints',
64
+ 'localField': 'date',
65
+ 'foreignField': 'date',
66
+ 'pipeline': [
67
+ { '$sort': { 'value': -1 } },
68
+ ],
69
+ 'as': 'datapoints',
70
+ } }
71
+ lookup_merge = { '$replaceRoot': {
72
+ 'newRoot': { '$mergeObjects': [
73
+ { '$arrayElemAt': [ "$datapoints", 0 ] }, "$$ROOT"
74
+ ] }
75
+ } }
76
+
77
+
78
+ match = { '$match': {
79
+ 'date': {
80
+ '$gte': '2023-12-25',
81
+ '$lte': '2023-12-31',
82
+ }
83
+ } }
84
+
85
+ group = { '$group': {
86
+ '_id': "$date",
87
+ 'my_doc': { '$first': "$$ROOT" }
88
+ } }
89
+
90
+ outs = Iro::Date.collection.aggregate([
91
+ match,
92
+
93
+ lookup,
94
+ lookup_merge,
95
+
96
+ group,
97
+ { '$replaceRoot': { 'newRoot': "$my_doc" } },
98
+ # { '$replaceRoot': { 'newRoot': "$my_doc" } },
99
+
100
+
101
+ { '$project': { '_id': 0, 'date': 1, 'value': 1 } },
102
+ { '$sort': { 'date': 1 } },
103
+ ])
104
+
105
+ puts! 'result'
106
+ pp outs.to_a
107
+ # puts! outs.to_a, 'result'
108
+ end
109
+
110
+ end
@@ -0,0 +1,10 @@
1
+
2
+ class Iro::Date
3
+ include Mongoid::Document
4
+ # include Mongoid::Timestamps
5
+ store_in collection: 'iro_dates'
6
+
7
+ field :date
8
+
9
+ end
10
+
@@ -1,7 +1,15 @@
1
1
 
2
- ##
3
- ## SQL
4
- ##
5
- class Iro::Option # < Iro::ApplicationRecord
6
- # self.table_name = 'iro_options'
2
+
3
+ class Iro::Option
4
+ include Mongoid::Document
5
+ include Mongoid::Timestamps
6
+ store_in collection: 'iro_options'
7
+
8
+ # field :ticker
9
+ # validates :ticker, uniqueness: true, presence: true
10
+
11
+ field :symbol
12
+ validates :symbol, uniqueness: true, presence: true
13
+
14
+
7
15
  end