wco_models 3.4.0.10 → 3.5.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/wco/main.scss +3 -7
  3. data/app/assets/stylesheets/wco/photos.scss +1 -2
  4. data/app/controllers/wco/api/newspartials_controller.rb +15 -5
  5. data/app/controllers/wco/newspartials_controller.rb +2 -2
  6. data/app/controllers/wco/newsvideos_controller.rb +14 -10
  7. data/app/controllers/wco/office_action_templates_controller.rb +0 -3
  8. data/app/controllers/wco/publishers_controller.rb +16 -6
  9. data/app/controllers/wco/reports_controller.rb +5 -6
  10. data/app/controllers/wco/sitemap_paths_controller.rb +2 -14
  11. data/app/controllers/wco/sites_controller.rb +1 -1
  12. data/app/controllers/wco/tags_controller.rb +1 -1
  13. data/app/models/iro/option.rb +4 -37
  14. data/app/models/iro/priceitem.rb +4 -62
  15. data/app/models/tda/option.rb +41 -39
  16. data/app/models/wco/newspartial.rb +33 -8
  17. data/app/models/wco/newsvideo.rb +4 -3
  18. data/app/models/wco/publisher.rb +8 -29
  19. data/app/models/wco/report.rb +2 -12
  20. data/app/models/wco/setting.rb +1 -1
  21. data/app/models/wco/site.rb +67 -1
  22. data/app/models/wco/sitemap_path.rb +13 -19
  23. data/app/models/wco/tag.rb +8 -15
  24. data/app/models/wco/utils.rb +19 -0
  25. data/app/views/wco/api/newsproducer/_studio_blue2.js +205 -317
  26. data/app/views/wco/api/newsproducer/_studio_fps.js +12 -12
  27. data/app/views/wco/api/newsproducer/studio_blue2.html.erb +25 -24
  28. data/app/views/wco/api/newsproducer/studio_fps.html.erb +8 -10
  29. data/app/views/wco/api/newsproducer/trash/_scenes.js-bk +20 -0
  30. data/app/views/wco/api/newsproducer/trash/_scenes.js.erb +15 -0
  31. data/app/views/wco/api/newsproducer/trash/_studio_blue0.js +326 -0
  32. data/app/views/wco/api/newsproducer/trash/_studio_blue1.js +733 -0
  33. data/app/views/wco/api/newsproducer/trash/studio_blue0.html.erb +27 -0
  34. data/app/views/wco/api/newsproducer/trash/studio_blue1.html.erb +108 -0
  35. data/app/views/wco/api/newsvideos/show.jbuilder +1 -1
  36. data/app/views/wco/newspartials/_form.haml +6 -0
  37. data/app/views/wco/newspartials/_show_in_newsvideo.haml +2 -2
  38. data/app/views/wco/newsvideos/_form.haml +4 -0
  39. data/app/views/wco/newsvideos/show.haml +2 -2
  40. data/app/views/wco/office_action_templates/index.haml +1 -1
  41. data/app/views/wco/office_actions/_actions.haml +1 -1
  42. data/app/views/wco/publishers/_form.haml +2 -11
  43. data/app/views/wco/publishers/_post_with.haml +1 -1
  44. data/app/views/wco/reports/_form.haml +2 -13
  45. data/app/views/wco/reports/_index.haml +11 -18
  46. data/app/views/wco/reports/show.haml +1 -6
  47. data/app/views/wco/sitemap_paths/_index.haml +0 -1
  48. data/app/views/wco/sitemap_paths/check.haml +13 -0
  49. data/app/views/wco/sites/index.haml +0 -6
  50. data/app/views/wco/sites/show.haml +1 -1
  51. data/app/views/wco/tags/_form.haml +0 -3
  52. data/config/routes.rb +12 -11
  53. data/lib/shortcuts.rb +1 -1
  54. data/lib/wco_models.rb +1 -1
  55. metadata +28 -24
  56. data/app/models/wco/publisher_d10.rb +0 -50
  57. data/app/views/wco/api/newsproducer/README_newsproducer.txt +0 -12
  58. data/app/views/wco/sitemap_paths/show.haml +0 -14
  59. /data/app/views/wco/api/newsproducer/{_scenes.js-bk → done/_scenes.js-bk} +0 -0
  60. /data/app/views/wco/api/newsproducer/{_scenes.js.erb → done/_scenes.js.erb} +0 -0
  61. /data/app/views/wco/api/newsproducer/{_studio_1.js → done/_studio_1.js} +0 -0
  62. /data/app/views/wco/api/newsproducer/{_studio_blue0.js → done/_studio_blue0.js} +0 -0
  63. /data/app/views/wco/api/newsproducer/{_studio_blue1.js → done/_studio_blue1.js} +0 -0
  64. /data/app/views/wco/api/newsproducer/{_studio_coc.js → done/_studio_coc.js} +0 -0
  65. /data/app/views/wco/api/newsproducer/{_studio_coc.js-bk → done/_studio_coc.js-bk} +0 -0
  66. /data/app/views/wco/api/newsproducer/{_studio_coc.js-cannon → done/_studio_coc.js-cannon} +0 -0
  67. /data/app/views/wco/api/newsproducer/{_studio_ra2.js → done/_studio_ra2.js} +0 -0
  68. /data/app/views/wco/api/newsproducer/{_touch_controls.js → done/_touch_controls.js} +0 -0
  69. /data/app/views/wco/api/newsproducer/{_touch_pad.css → done/_touch_pad.css} +0 -0
  70. /data/app/views/wco/api/newsproducer/{canvas.html.erb → done/canvas.html.erb} +0 -0
  71. /data/app/views/wco/api/newsproducer/{canvas_minimal.html.erb → done/canvas_minimal.html.erb} +0 -0
  72. /data/app/views/wco/api/newsproducer/{games_fps.html → done/games_fps.html} +0 -0
  73. /data/app/views/wco/api/newsproducer/{studio_1.html.erb → done/studio_1.html.erb} +0 -0
  74. /data/app/views/wco/api/newsproducer/{studio_blue0.html.erb → done/studio_blue0.html.erb} +0 -0
  75. /data/app/views/wco/api/newsproducer/{studio_blue1.html.erb → done/studio_blue1.html.erb} +0 -0
  76. /data/app/views/wco/api/newsproducer/{studio_coc.html.erb → done/studio_coc.html.erb} +0 -0
  77. /data/app/views/wco/api/newsproducer/{studio_ra2.html.erb → done/studio_ra2.html.erb} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f5abb5827947d4171ccd787261016dd83ab76eb8df606961e3fbd639771ae4b
4
- data.tar.gz: 24b8d1da5e414a442bcf05c9cb8b85d7440a431b2335584f4dc564c7370a1390
3
+ metadata.gz: 944e681b8a31afee5ce6e98f68fd1fc54bed6770a7c1568d39057d0f90a3c722
4
+ data.tar.gz: 62a8c729538678a89947c90d5ebee4e9856fe5c363a5fcc06e427e90ce6dab87
5
5
  SHA512:
6
- metadata.gz: 5230158058f314c630b0085006c91bec6211fbbbe5559ab88f3ce5021d9667acee3116085291cd8802ad51c49871be20000216d1d8545fcab59724624997a20f
7
- data.tar.gz: 5d526a2d4bdaf7ecf50d5492e4a028f76f2a376219de38991d814e2de32026e80323a3f64ab0f2203d07a846b9fd20e7bfdf0d117c8cb49471a946fa4af394c5
6
+ metadata.gz: 22ff6dd88163091cd5078c2c807776f84c07f0649a981852fd4385b5c9c4773eb76d9717b67afaf8f4a07862f00c5414b2aecf5ce1868a4381f75f8741b8a70b
7
+ data.tar.gz: 581a5a302dbb5864d4f8bf100268a2af1eddc45737915a72f303e2b52a466f289b97b7f61dc787c8fdb6bc96486fc1abcf38d154314fb9238eb31969df6687e9
@@ -117,10 +117,7 @@ textarea.monospace {
117
117
  /* D */
118
118
 
119
119
  .d-flex {
120
- align-items: baseline; /* 2026-11-12: I dont want this alignment */
121
- }
122
- .no-align {
123
- align-items: unset;
120
+ align-items: baseline;
124
121
  }
125
122
 
126
123
  .descr {
@@ -346,12 +343,11 @@ table thead.sticky {
346
343
  .w-300px {
347
344
  width: 300px;
348
345
  }
346
+
349
347
  .w-400px {
350
348
  width: 400px;
351
349
  }
350
+
352
351
  .w-500px {
353
352
  width: 500px;
354
353
  }
355
- .w-600px {
356
- width: 500px;
357
- }
@@ -10,11 +10,10 @@
10
10
 
11
11
  div.thumb {
12
12
  margin: 0 0.5em 0.5em 0;
13
- flex-shrink: 0;
14
13
  }
15
14
 
16
15
  .photos-thumbs img,
17
- .thumb {
16
+ img.thumb {
18
17
  border: 1px solid red;
19
18
  width: 100px;
20
19
  height: 100px;
@@ -53,19 +53,29 @@ class Wco::Api::NewspartialsController < Wco::ApiController
53
53
 
54
54
  def show_config
55
55
  @newspartial = Wco::Newspartial.find params[:id]
56
- config = JSON.parse @newspartial.speech_json
56
+ config = @newspartial.config
57
57
 
58
58
  # @newsvideo_events = Wco::NewsvideoEvent.where( newsvideo: @newspartial.newsvideo )
59
- @newsvideo_events = @newspartial.newsvideo_events
60
- config[:fns] = @newsvideo_events.map { |ev| ev.exec_js }
61
- config[:ftimes] = @newsvideo_events.map { |ev| ev.start_at_ms }
59
+ @newsvideo_events = @newspartial.newsvideo_events
60
+ config[:fns] = @newsvideo_events.map { |ev| ev.exec_js }
61
+ config[:ftimes] = @newsvideo_events.map { |ev| ev.start_at_ms }
62
62
  config[:fdurations] = @newsvideo_events.map { |ev| ev.duration_ms }
63
63
 
64
64
 
65
65
  config[:w_px] = @newspartial.newsvideo.w_px
66
66
  config[:h_px] = @newspartial.newsvideo.h_px
67
+ config[:fps] = @newspartial.newsvideo.fps
67
68
  config[:slug] = "#{@newspartial.newsvideo.slug}::#{@newspartial.slug}"
68
- render json: config
69
+
70
+ config[:generate_video_url] = wco.api_newsproducer_studio_blue_url({
71
+ api_key: Wco::Setting.get('WASYACO_SIMPLE_API_KEY'),
72
+ api_secret: Wco::Setting.get('WASYACO_SIMPLE_API_SECRET'),
73
+ host: Rails.application.routes.default_url_options[:host],
74
+ newspartial_id: @newspartial.id.to_s,
75
+ wco_origin: Rails.application.routes.default_url_options[:host], # request.base_url,
76
+ })
77
+ puts! config, 'ze config'
78
+ render json: JSON.generate(config, ascii_only: false, escape_html_entities: false)
69
79
  end
70
80
 
71
81
  end
@@ -46,8 +46,8 @@ class Wco::NewspartialsController < Wco::ApplicationController
46
46
  authorize! :edit, @newspartial
47
47
 
48
48
  Rails.env.production? ?
49
- Wco::NewspartialVideoJob.perform_async(params[:id]) :
50
- Wco::NewspartialVideoJob.perform_sync( params[:id])
49
+ Wco::NewspartialVideoJob.perform_async( params[:id]) :
50
+ Wco::NewspartialVideoJob.perform_sync( params[:id])
51
51
 
52
52
  flash_notice 'Scheduled.'
53
53
  redirect_to controller: 'newsvideos', id: @newspartial.newsvideo_id, action: 'show'
@@ -118,24 +118,28 @@ class Wco::NewsvideosController < Wco::ApplicationController
118
118
  @newsvideo = Wco::Newsvideo.unscoped.find params[:id]
119
119
  authorize! :edit, @newsvideo
120
120
 
121
- cmd = "cd #{PUPPETEER_ROOT} ; yarn run newsvideo_generate_all_audio #{@newsvideo.id}"
122
- puts "+++ puppeteer cmd:"
123
- puts cmd
124
- out = `#{cmd}`
125
- puts! out, 'out'
121
+ # cmd = "cd #{PUPPETEER_ROOT} ; yarn run newsvideo_generate_all_audio #{@newsvideo.id}"
122
+ # puts "+++ puppeteer cmd:"
123
+ # puts cmd
124
+ # out = `#{cmd}`
125
+ # puts! out, 'out'
126
+
127
+ @newsvideo.newspartials.each do |newspartial|
128
+ newspartial.generate_speech
129
+ print '.'
130
+ end
126
131
 
127
132
  render json: { status: :ok }
128
133
  end
129
134
 
135
+ ## via puppeteer
130
136
  def generate_all_video
131
137
  @newsvideo = Wco::Newsvideo.unscoped.find params[:id]
132
138
  authorize! :edit, @newsvideo
133
139
 
134
- cmd = "cd #{PUPPETEER_ROOT} ; yarn run newsvideo_generate_all_video #{@newsvideo.id}"
135
- puts "+++ puppeteer cmd:"
136
- puts cmd
137
- out = `#{cmd}`
138
- puts! out, 'out'
140
+ @newsvideo.newspartials.each do |np|
141
+ np.generate_video
142
+ end
139
143
 
140
144
  render json: { status: :ok }
141
145
  end
@@ -25,15 +25,12 @@ class Wco::OfficeActionTemplatesController < Wco::ApplicationController
25
25
  def perform
26
26
  @oat = OAT.find params[:id]
27
27
  authorize! :run, @oat
28
-
29
28
  @conversations = WcoEmail::Conversation.find( params[:conversation_ids] ) if params[:conversation_ids].present?
30
-
31
29
  if 'rb' == @oat.action_type
32
30
  out = eval( @oat.action_exe )
33
31
  elsif 'sh' == @oat.action_type
34
32
  out = `#{@oat.action_exe}`
35
33
  end
36
-
37
34
  flash_notice out
38
35
  redirect_to action: :index
39
36
  end
@@ -12,18 +12,28 @@ class Wco::PublishersController < Wco::ApplicationController
12
12
  redirect_to action: 'index'
13
13
  end
14
14
 
15
+ ## this is becoming obsolete - try using do_run_any
16
+ def do_run
17
+ @publisher = Wco::Publisher.find params[:id]
18
+ authorize! :do_run, @publisher
19
+
20
+ @publisher.props = OpenStruct.new( JSON.parse params[:publisher][:props] )
21
+ # @publisher.do_run binding
22
+ @publisher.do_run
23
+
24
+ flash_notice "Probably ok"
25
+
26
+ redirect_to action: 'index'
27
+ end
28
+
15
29
  def do_run_any
16
30
  @publisher = Wco::Publisher.find params[:id]
17
31
  authorize! :do_run, @publisher
18
32
 
19
33
  @publisher.props = OpenStruct.new( JSON.parse params[:props] )
20
- flag = @publisher.do_run
21
- if !flag
22
- flash_alert @publisher.errors
23
- else
24
- flash_notice "#do_run_any Probably ok"
25
- end
34
+ @publisher.do_run
26
35
 
36
+ flash_notice "Probably ok"
27
37
  redirect_to request.referrer || { action: 'index' }
28
38
  end
29
39
 
@@ -5,18 +5,16 @@ class Wco::ReportsController < Wco::ApplicationController
5
5
 
6
6
  def create
7
7
  params[:report][:tag_ids]&.delete ''
8
- img_thumb_params = params[:report][:image_thumb]
9
- params[:report].delete :image_thumb
10
8
 
11
9
  @report = Wco::Report.new params[:report].permit!
12
10
  authorize! :create, @report
13
11
 
14
12
  @report.author = current_profile
15
13
 
16
- if img_thumb_params.present?
17
- @photo = Wco::Photo.new photo: img_thumb_params
18
- @photo.save!
19
- @report.image_thumb = @photo
14
+ if params[:report][:image_thumb]&.[](:image).present?
15
+ thumb = @report.image_thumb || @report.build_image_thumb
16
+ thumb.image = params[:report][:image_thumb_attributes][:image]
17
+ thumb.save
20
18
  end
21
19
 
22
20
  if @report.save
@@ -207,6 +205,7 @@ class Wco::ReportsController < Wco::ApplicationController
207
205
  params[:report][:tag_ids]&.delete ''
208
206
  img_thumb_params = params[:report][:image_thumb]
209
207
  params[:report].delete :image_thumb
208
+ # puts! img_thumb_params, 'img_thumb_params'
210
209
 
211
210
  @report = Wco::Report.unscoped.find params[:id]
212
211
  authorize! :update, @report
@@ -7,13 +7,12 @@ class Wco::SitemapPathsController < Wco::ApplicationController
7
7
  @spath = Wco::SitemapPath.find params[:id]
8
8
  authorize! :check, @spath
9
9
  @spath.check
10
- redirect_to wco.spath_path(@spath)
11
10
  end
12
11
 
13
12
  def clear
14
13
  @spath = Wco::SitemapPath.find params[:id]
15
14
  authorize! :clear, @spath
16
- @spath.logs.destroy_all
15
+ @spath.update_attributes({ results: [] })
17
16
  redirect_to request.referrer || sites_path(@spath.site)
18
17
  end
19
18
 
@@ -30,18 +29,6 @@ class Wco::SitemapPathsController < Wco::ApplicationController
30
29
  end
31
30
  end
32
31
 
33
- def destroy
34
- @spath = Wco::SitemapPath.find params[:id]
35
- site_id = @spath.site_id
36
- authorize! :destroy, @spath
37
- if @spath.destroy
38
- flash_notice 'ok'
39
- else
40
- flash_alert 'No luck.'
41
- end
42
- redirect_to request.referrer || sites_path(site_id)
43
- end
44
-
45
32
  def edit
46
33
  @spath = Wco::SitemapPath.find params[:id]
47
34
  @site = @spath.site
@@ -58,6 +45,7 @@ class Wco::SitemapPathsController < Wco::ApplicationController
58
45
  @spath = Wco::SitemapPath.find params[:id]
59
46
  @site = @spath.site
60
47
  authorize! :show, @spath
48
+ render 'check'
61
49
  end
62
50
 
63
51
 
@@ -40,7 +40,7 @@ class Wco::SitesController < Wco::ApplicationController
40
40
 
41
41
  def index
42
42
  authorize! :index, Wco::Site
43
- @sites = Wco::Site.all.includes( :tags )
43
+ @sites = Wco::Site.all
44
44
  end
45
45
 
46
46
  def new
@@ -32,7 +32,7 @@ class Wco::TagsController < Wco::ApplicationController
32
32
 
33
33
  def index
34
34
  authorize! :index, Wco::Tag
35
- @tags = Wco::Tag.where( site: nil ).order_by( slug: :asc )
35
+ @tags = Wco::Tag.all.order_by( slug: :asc )
36
36
 
37
37
  tags = Wco::Tag.all.to_a.group_by(&:parent_id)
38
38
  build_tree = lambda do |parent_id|
@@ -8,7 +8,7 @@ class Iro::Option
8
8
  attr_accessor :recompute
9
9
 
10
10
  belongs_to :stock, class_name: 'Iro::Stock', inverse_of: :strategies
11
- field :ticker, type: :string
11
+ def ticker; stock.ticker; end
12
12
 
13
13
  CALL = 'CALL'
14
14
  PUT = 'PUT'
@@ -67,47 +67,14 @@ class Iro::Option
67
67
  return options
68
68
  end
69
69
 
70
- field :symbol, type: :string
71
- validates :symbol, uniqueness: true
72
- index({ symbol: -1 }, { unique: true, name: 'symbol' })
73
- # def symbol
74
- # return self[:symbol] if self[:symbol]
75
- # self[:symbol] = generate_symbol
76
- # end
77
-
78
70
  ## for schwab, eg:
79
71
  ## "COST 260306C01030000"
80
- def generate_symbol
72
+ def symbol
81
73
  p_c_ = put_call == 'PUT' ? 'P' : 'C'
82
74
  strike_ = format("%08d", (strike.to_f * 1000).round)
83
75
  sym = "#{stock.ticker.ljust(6)}#{expires_on.strftime("%y%m%d")}#{p_c_}#{strike_}"
84
76
  end
85
77
 
86
- def self.find_or_create_by_symbol symbol
87
- option = Iro::Option.where( symbol: symbol ).first
88
- return option if option
89
- h = Iro::Option.symbol_to_h symbol
90
- item = Iro::Option.new({
91
- stock: Iro::Stock.find_by( ticker: h[:ticker] ),
92
- ticker: h[:ticker],
93
- put_call: h[:put_call],
94
- strike: h[:strike],
95
- expires_on: h[:expires_on],
96
- symbol: symbol,
97
- })
98
- item.save
99
- return item
100
- end
101
-
102
- ## trash, I can save the symbol every time. 2026-10-04
103
- # def self.find_by_symbol symbol
104
- # option = self.where( symbol: symbol ).first
105
- # return option if option
106
- # h = Iro::Option.symbol_to_h symbol
107
- # Iro::Option.where( h ).first
108
- # end
109
-
110
-
111
78
  =begin
112
79
  symbol = "META 260424P00500000"
113
80
  =end
@@ -116,7 +83,7 @@ class Iro::Option
116
83
  date_str = symbol[6,6]
117
84
  type = symbol[12] == 'P' ? 'PUT' : 'CALL'
118
85
  strike_str = symbol[13,8]
119
- expires_on = Date.strptime(date_str, "%y%m%d").to_s
86
+ expires_on = Date.strptime(date_str, "%y%m%d")
120
87
  strike = strike_str.to_i / 1000.0
121
88
  return {
122
89
  ticker: ticker,
@@ -125,7 +92,7 @@ class Iro::Option
125
92
  expires_on: expires_on,
126
93
  }
127
94
  end
128
- def to_h
95
+ def symbol_to_h
129
96
  self.class.symbol_to_h symbol
130
97
  end
131
98
 
@@ -21,19 +21,18 @@ class Iro::Priceitem
21
21
  field :bidSize, type: Integer
22
22
  field :ask, type: Float
23
23
  field :askSize, type: Integer
24
- field :last, type: Float ## this is important?
25
- field :mark, type: Float ## no, this is important. (bid+ask)/2
24
+ field :last, type: Float ## this is important
26
25
 
27
26
  field :openPrice, type: Float
28
27
  field :lowPrice, type: Float
29
28
  field :highPrice, type: Float
30
29
  field :closePrice, type: Float
31
30
 
32
- field :quote_at, type: DateTime ## this is important?
31
+ field :quote_at, type: DateTime ## this is important, the timestamp mostly used for analysis
33
32
  field :quoteTimeInLong, type: Integer
34
- field :timestamp, type: Integer ## do not use?
33
+ field :timestamp, type: Integer ## do not use?!
35
34
  field :totalVolume, type: Integer
36
-
35
+ field :mark, type: Float
37
36
  field :exchangeName, type: String
38
37
  field :volatility, type: Float
39
38
 
@@ -44,63 +43,6 @@ class Iro::Priceitem
44
43
  field :openInterest, type: Integer
45
44
  field :strikePrice, type: Float
46
45
 
47
- def self.create_from_chains!
48
- Iro::Iro.schwab_exec_sync ## should be schwab_data_sync()
49
-
50
- stocks = Iro::Stock.active
51
- fridays = 3.times.map { |i| ( Date.current.next_occurring(:friday) + i.weeks ).to_s }
52
-
53
- stocks.each do |stock|
54
- puts "+++ Getting #{stock.ticker}..."
55
- response = Tda::Option.get_chains({
56
- ticker: stock.ticker,
57
- fromDate: fridays[0],
58
- toDate: fridays.last,
59
- strikeCount: 10,
60
- })
61
- # puts! response.keys, 'response.keys'
62
- # puts! response['symbol'], 'response symbol'
63
- # sleep 10
64
-
65
- first_val = nil
66
- ['callExpDateMap', 'putExpDateMap'].each do |which_map|
67
-
68
- response[which_map].each do |_date, strikes|
69
- if fridays.include?( _date.split(':')[0] )
70
- strikes.each do |_strike, vals|
71
- vals.each do |val|
72
- if !first_val
73
- first_val = val
74
- puts! val.keys, 'val keys'
75
- end
76
-
77
- option = Iro::Option.find_or_create_by_symbol( val['symbol'] )
78
-
79
- # opt = OpenStruct.new val
80
- pi = Iro::Priceitem.new( val.slice( 'expirationDate',
81
- 'putCall', 'symbol', 'exchangeName', 'bid', 'ask',
82
- 'last', 'mark', 'bidSize', 'askSize', 'totalVolume', 'quoteTimeInLong', 'volatility',
83
- 'delta', 'gamma', 'theta', 'openInterest', 'strikePrice' ) )
84
- pi.stock = stock
85
- pi.option = option
86
- pi.quote_at = Time.at( val['quoteTimeInLong'] / 1000 )
87
- pi.ticker = stock.ticker
88
- pi.save!
89
-
90
- # puts! pi
91
- print '.'
92
-
93
-
94
- end
95
- end
96
- end ## end fridays.include?
97
- end
98
-
99
- end ## which_map
100
- end
101
-
102
- end
103
-
104
46
  def self.my_find props={}
105
47
  lookup = { '$lookup': {
106
48
  'from': 'iro_price_items',
@@ -1,7 +1,16 @@
1
1
 
2
2
  require 'httparty'
3
3
 
4
+ =begin
5
+ class Schwab
6
+ include HTTParty
7
+ debug_output $stdout
8
+ base_uri 'https://api.schwabapi.com/marketdata/v1'
9
+ end
10
+ =end
11
+
4
12
  class Tda::Option
13
+
5
14
  include ::HTTParty
6
15
  # debug_output $stdout
7
16
  base_uri 'https://api.schwabapi.com/marketdata/v1'
@@ -9,7 +18,7 @@ class Tda::Option
9
18
 
10
19
  ##
11
20
  ## Get entire chains for a ticker
12
- ## params: { ticker, force, strikeCount, fromDate (yyyy-mm-dd), toDate }
21
+ ## params: { ticker, force }
13
22
  ##
14
23
  ## 2024-08-09 :: Continue
15
24
  ## 2024-08-21 :: Continue : )
@@ -20,10 +29,7 @@ class Tda::Option
20
29
  return JSON.parse File.read filename
21
30
 
22
31
  else
23
- query = { symbol: params[:ticker] } ## says query[:symbol], not ticker.
24
- query[:strikeCount] = params[:strikeCount] if params[:strikeCount]
25
- query[:fromDate] = params[:fromDate] if params[:fromDate]
26
- query[:toDate] = params[:toDate] if params[:toDate]
32
+ query = { symbol: params[:ticker] } ## use 'GME' as symbol here even though a symbol is eg 'GME_021023P2.5'
27
33
  # puts! query, 'query'
28
34
 
29
35
  headers = {
@@ -31,30 +37,40 @@ class Tda::Option
31
37
  Authorization: "Bearer #{Iro::Iro.schwab_data_token}",
32
38
  }
33
39
  path = "/chains"
34
- response = self.get path, { headers: headers, query: query }
35
- timestamp = DateTime.parse response.headers['date']
36
- response = response.parsed_response
37
- puts! response, '/chains got this response'
40
+ out = self.get path, {
41
+ headers: headers,
42
+ query: query }
43
+ timestamp = DateTime.parse out.headers['date']
44
+ out = out.parsed_response
45
+ # puts! out, 'outs'
38
46
 
39
47
  outs = []
40
48
  %w| put call |.each do |contractType|
41
- _out = response["#{contractType}ExpDateMap"]
42
- _out.each do |_date, vs| ## date="2023-02-10:5"
49
+ _out = out["#{contractType}ExpDateMap"]
50
+ _out.each do |date, vs| ## date="2023-02-10:5"
43
51
  vs.each do |strike, _v| ## strike="18.5"
44
52
  _v = _v[0] ## weird, keep
45
53
  # puts! _v, '_v'
46
54
 
47
- v = _v.slice( 'putCall', 'symbol', 'bid', 'ask', 'last', 'mark', 'totalVolume', 'openInterest',
48
- 'strikePrice', 'expirationDate' )
55
+ v = {
56
+ putCall: _v['putCall'],
57
+ symbol: _v['symbol'],
58
+ bid: _v['bid'],
59
+ ask: _v['ask'],
60
+ last: _v['last'],
61
+ totalVolume: _v['totalVolume'],
62
+ openInterest: _v['openInterest'],
63
+ strikePrice: _v['strikePrice'],
64
+ expirationDate: _v['expirationDate'],
65
+ }
49
66
  v.each do |k, i|
50
67
  if i == 'NaN'
51
68
  v[k] = nil
52
69
  end
53
70
  end
54
71
 
55
- v[:timestamp] = timestamp # _v['quoteTimeInLong']/1000.0
56
- v[:quote_at] = Time.at(_v['quoteTimeInLong'] / 1000.0)
57
- v[:ticker] = params[:ticker]
72
+ v[:timestamp] = timestamp
73
+ v[:ticker] = params[:ticker]
58
74
  outs.push( v )
59
75
  end
60
76
  end
@@ -67,8 +83,8 @@ class Tda::Option
67
83
  end
68
84
  end
69
85
 
70
- File.write filename, JSON.pretty_generate(response)
71
- return response
86
+ File.write filename, out.to_json
87
+ return out
72
88
  end
73
89
  end
74
90
 
@@ -80,8 +96,6 @@ class Tda::Option
80
96
  OpenStruct.new ::Tda::Option.get_quotes(params)[0]
81
97
  end
82
98
 
83
- ## ...for a single symbol.
84
- ## but use get_quotes_h instead?!
85
99
  ##
86
100
  ## params: contractType, strike, expirationDate, ticker
87
101
  ##
@@ -236,23 +250,19 @@ class Tda::Option
236
250
  end
237
251
 
238
252
  def self.close_credit_call
239
- throw 'r40 - not implemented'
240
253
  end
241
254
  def self.close_long_debit_call_spread
242
- throw 'r41 - not implemented'
243
255
  end
244
256
  def self.close_short_debit_put_spread
245
- throw 'r42 - not implemented'
246
257
  end
247
258
 
248
- ## trash? remove.
249
- # def self.get_token
250
- # opts = {
251
- # grant_type: 'authorization_code',
252
- # access_type: 'offline',
253
- # code: ::TD_AMERITRADE[:code],
254
- # }
255
- # end
259
+ def self.get_token
260
+ opts = {
261
+ grant_type: 'authorization_code',
262
+ access_type: 'offline',
263
+ code: ::TD_AMERITRADE[:code],
264
+ }
265
+ end
256
266
 
257
267
  def self.create_credit_call outer:, inner:, q:, price:
258
268
  query = {
@@ -297,21 +307,13 @@ class Tda::Option
297
307
  # puts! out, 'created credit call?'
298
308
  end
299
309
  def self.create_long_debit_call_spread
300
- throw 'r43 - not implemented'
301
310
  end
302
311
  def self.create_short_debit_put_spread
303
- throw 'r44 - not implemented'
304
312
  end
305
313
 
306
314
 
307
315
  end
308
316
 
309
-
310
-
311
-
312
-
313
-
314
-
315
317
  ##
316
318
  ## From: https://developer.tdameritrade.com/content/place-order-samples
317
319
  ## Buy Limit: Vertical Call Spread