iron_warbler 2.0.7.27 → 2.0.7.29

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: 817fe321c59fe077810b34daaf097462c339ccbf7a2944845f1f460f3bff72cc
4
- data.tar.gz: 10a0379b148bd595b730d63ab5b63cf624c4c3039c5586309981f840ad0869bd
3
+ metadata.gz: 60a17bd2d6ccedafac952f5463331f53ff1e1817e8eab7a00285b43deb265396
4
+ data.tar.gz: e85425f94157c1d040c2606247ca42b5c7d928431d05978c92d94ea1b8f1b365
5
5
  SHA512:
6
- metadata.gz: 015ce7410f643ea640082ccfc7f231009d527b287a24206eb5b3340a1571b477c95f2da9a9eaed8e7b2f0a1d0162a59f553029a57746a324be560083cbf92f5a
7
- data.tar.gz: cabc439b34662c94886d6893138a51c4be2ace1b8a97fdc7a8fa0859bbea4178fca944043c50365a5b04093269688a95d1d8ce3e1e3c8d52293dac12d3f345c0
6
+ metadata.gz: 5f035df03d218468790ed2af125164f2173dcdbcd47598cd3f846aea14cfc6b032b2c16f72d03f7ca53d5eebfa37bf398359bfd032230e2c74e44296214a6f1e
7
+ data.tar.gz: 9e71f4855db33c8f7b02fd021980eb1e8b8eff59d6d7f24c96c8d3de380aeafb286a127650ef56dea0192f60f874b8b4f71b2feb57028706a2a681661d4fb822
@@ -0,0 +1,9 @@
1
+
2
+ .iro-alerts--index {
3
+ .field {
4
+ label {
5
+ min-width: auto;
6
+ }
7
+ }
8
+ }
9
+
@@ -45,8 +45,8 @@ class Iro::AlertsController < Iro::ApplicationController
45
45
  super
46
46
 
47
47
  # @profiles_list = Wco::Profile.list
48
- @stocks_list = Iro::Stock.list
49
- puts! @stocks_list, '@stocks_list'
48
+ @stocks_list = Iro::Stock.list
49
+ @symbols_list = [[nil,nil]] + Iro::Stock.active.map { |s| [ s.ticker, s.ticker ] }
50
50
  end
51
51
 
52
52
 
@@ -1,8 +1,41 @@
1
1
 
2
+ class Schwab
3
+ include HTTParty
4
+ debug_output $stdout
5
+ end
6
+
2
7
  class Iro::ApiController < ActionController::Base
3
8
  layout false
4
9
 
5
- before_action :decode_jwt
10
+ before_action :decode_jwt, except: [ :oauth2_redirect ]
11
+
12
+ def oauth2_redirect
13
+ out = Schwab.post( "https://api.schwabapi.com/v1/oauth/token", {
14
+ headers: {
15
+ "Content-Type": "application/x-www-form-urlencoded",
16
+ },
17
+ basic_auth: { username: SCHWAB_DATA[:key], password: SCHWAB_DATA[:secret] },
18
+ body: {
19
+ grant_type: 'authorization_code',
20
+ code: params[:code].sub('%40', '@'),
21
+ redirect_uri: SCHWAB_DATA[:redirect_url],
22
+ },
23
+ })
24
+ out = out.parsed_response
25
+
26
+ attrs = {
27
+ schwab_access_token: out['access_token'],
28
+ schwab_refresh_token: out['refresh_token'],
29
+ schwab_id_token: out['id_token'],
30
+ }
31
+ # puts! attrs, 'attrs'
32
+
33
+ profile = Wco::Profile.find_by email: 'piousbox@gmail.com'
34
+ profile.update(attrs)
35
+ profile.save!
36
+
37
+ render json: { status: :ok }
38
+ end
6
39
 
7
40
  ##
8
41
  ## private
@@ -54,11 +54,12 @@ class Iro::StocksController < Iro::ApplicationController
54
54
  def show
55
55
  authorize! :show, @stock
56
56
 
57
- @priceitems = Iro::PriceItem.where({
57
+ @priceitems = ::Iro::Priceitem.where({
58
58
  ticker: @stock.ticker,
59
59
  })
60
60
 
61
61
  respond_to do |format|
62
+ format.html
62
63
  format.json do
63
64
  render layout: false
64
65
  end
@@ -4,7 +4,8 @@ require 'httparty'
4
4
  class Tda::Option
5
5
 
6
6
  include ::HTTParty
7
- base_uri 'https://api.tdameritrade.com'
7
+ # base_uri 'https://api.tdameritrade.com'
8
+ base_uri 'https://api.schwabapi.com/marketdata/v1'
8
9
 
9
10
 
10
11
  ##
@@ -83,7 +84,7 @@ class Tda::Option
83
84
  end
84
85
  end
85
86
  if params[:expirationDate]
86
- opts[:fromDate] = opts[:toDate] = params[:expirationDate]
87
+ opts[:fromDate] = opts[:toDate] = params[:expirationDate].to_s[0...10]
87
88
  else
88
89
  raise Iro::InputError.new("Invalid input, missing 'date'.")
89
90
  end
@@ -97,11 +98,17 @@ class Tda::Option
97
98
  opts[:strike] = params[:strike]
98
99
  end
99
100
 
100
- query = { apikey: ::TD_AMERITRADE[:apiKey] }.merge opts
101
+ query = { }.merge opts
101
102
  # puts! query, 'input opts'
102
103
 
103
- path = "/v1/marketdata/chains"
104
- out = self.get path, { query: query }
104
+ headers = {
105
+ accept: 'application/json',
106
+ Authorization: "Bearer #{::SCHWAB_DATA[:access_token]}",
107
+ }
108
+
109
+
110
+ path = "/chains"
111
+ out = self.get path, { headers: headers, query: query }
105
112
  timestamp = DateTime.parse out.headers['date']
106
113
  ## out = HTTParty.get "https://api.tdameritrade.com#{path}", { query: query }
107
114
  out = out.parsed_response.deep_symbolize_keys
@@ -3,7 +3,7 @@ require 'httparty'
3
3
 
4
4
  class Tda::Stock
5
5
  include ::HTTParty
6
- base_uri 'https://api.tdameritrade.com'
6
+ base_uri 'https://api.schwabapi.com/marketdata/v1'
7
7
 
8
8
  ## alias
9
9
  def self.get_quote which
@@ -13,9 +13,17 @@ class Tda::Stock
13
13
  ## tickers = "GME"
14
14
  ## tickers = "NVDA,GME"
15
15
  def self.get_quotes tickers
16
- path = "/v1/marketdata/quotes"
17
- inns = self.get path, { query: { apikey: ::TD_AMERITRADE[:apiKey], symbol: tickers } }
16
+ profile = Wco::Profile.find_by email: 'piousbox@gmail.com'
17
+
18
+ path = "/quotes"
19
+ headers = {
20
+ accept: 'application/json',
21
+ Authorization: "Bearer #{profile.schwab_access_token}",
22
+ }
23
+ inns = self.get path, { headers: headers, query: { symbols: tickers } }
18
24
  inns = inns.parsed_response
25
+ puts! inns, 'parsed response'
26
+
19
27
  if [ NilClass, String ].include?( inns.class )
20
28
  return []
21
29
  end
@@ -23,7 +31,8 @@ class Tda::Stock
23
31
  inns[k] = v.deep_symbolize_keys
24
32
  end
25
33
  outs = []
26
- inns.each do |symbol, obj|
34
+ inns.each do |symbol, _obj|
35
+ obj = _obj[:quote]
27
36
  outs.push ::Iro::Priceitem.create!({
28
37
  putCall: 'STOCK',
29
38
  symbol: symbol,
@@ -37,8 +46,7 @@ class Tda::Stock
37
46
  closePrice: obj[:closePrice],
38
47
  highPrice: obj[:highPrice],
39
48
  lowPrice: obj[:lowPrice],
40
- quoteTimeInLong: obj[:quoteTimeInLong],
41
- timestamp: Time.at( obj[:quoteTimeInLong]/1000 ),
49
+ timestamp: Time.at( obj[:quoteTime]/1000 ),
42
50
  totalVolume: obj[:totalVolume],
43
51
  mark: obj[:mark],
44
52
  exchangeName: obj[:exchangeName],
@@ -7,6 +7,8 @@
7
7
  .W
8
8
  .d-flex.flex-wrap
9
9
  %ul
10
+ %li
11
+ = link_to "Schwab Login", "https://api.schwabapi.com/v1/oauth/authorize?client_id=#{SCHWAB_DATA[:key]}&redirect_uri=#{SCHWAB_DATA[:redirect_url]}"
10
12
  %li
11
13
  = link_to "Stocks (#{Iro::Stock.all.length})", stocks_path
12
14
  = link_to '[sync]', sync_stocks_path
@@ -24,7 +24,7 @@
24
24
  -# = f.text_field :kind
25
25
  .field
26
26
  = f.label :symbol
27
- = f.select :symbol, options_for_select( @stocks_list, selected: alert.symbol )
27
+ = f.select :symbol, options_for_select( @symbols_list, selected: alert.symbol )
28
28
  .field
29
29
  = f.label :direction
30
30
  = f.select :direction, options_for_select([ :ABOVE, :BELOW ], selected: alert.direction)
@@ -1,9 +1,9 @@
1
1
 
2
- .iro-alerts--index.maxwidth
2
+ .iro-alerts--index.padded
3
3
  %h5 Iro Alerts
4
4
 
5
- %ul
5
+ .a
6
6
  - @alerts.each do |alert|
7
- %li
7
+ .a
8
8
  = render 'iro/alerts/form', alert: alert
9
- %li= render 'iro/alerts/form', alert: Iro::Alert.new
9
+ .a= render 'iro/alerts/form', alert: Iro::Alert.new
@@ -18,9 +18,9 @@
18
18
  %label Stock
19
19
  = f.select :stock_id, options_for_select( @stocks_list, selected: position.stock_id )
20
20
 
21
- .field
22
- %label long or short?
23
- = f.select :long_or_short, options_for_select([nil, Iro::Strategy::LONG, Iro::Strategy::SHORT], selected: long_or_short )
21
+ -# .field
22
+ -# %label long or short?
23
+ -# = f.select :long_or_short, options_for_select([nil, Iro::Strategy::LONG, Iro::Strategy::SHORT], selected: long_or_short )
24
24
 
25
25
  %label Strategy
26
26
  = f.select :strategy_id, options_for_select( @strategies_list, selected: position.strategy_id )
@@ -1,5 +1,5 @@
1
1
 
2
- .stocks--index.maxwidth
2
+ .stocks-index.maxwidth
3
3
  .maxwidth
4
4
  %h5 Stocks
5
5
 
@@ -0,0 +1,5 @@
1
+
2
+ .stocks-show.maxwidth
3
+ %h4= @stock
4
+
5
+ %h5 Max Pain
data/config/routes.rb CHANGED
@@ -9,14 +9,14 @@ Iro::Engine.routes.draw do
9
9
 
10
10
  resources :option_watches
11
11
 
12
- match 'positions/:id/close', to: 'positions#close', as: :close_position, via: [ :get, :post ]
13
- get 'positions/duplicate/:id', to: 'positions#new', as: :duplicate_position
14
- post 'positions/propose', to: 'positions#propose', as: :propose_position
15
- get 'positions/:id/prepare', to: 'positions#prepare', as: :prepare_to_roll_position, defaults: { template: 'gameui' }
16
- match 'positions/:id/prepare2', to: 'positions#prepare2', as: :prepare2_position, defaults: { template: 'gameui' }, via: [ :get, :post ]
17
- match 'positions/:id/prepare3', to: 'positions#prepare3', as: :prepare3_position, defaults: { template: 'gameui' }, via: [ :get, :post ]
18
- post 'positions/:id/roll', to: 'positions#do_roll', as: :roll_position
19
- get 'positions/:id/sync', to: 'positions#sync', as: :sync_position
12
+ match 'positions/:id/close', to: 'positions#close', as: :close_position, via: [ :get, :post ]
13
+ get 'positions/duplicate/:id', to: 'positions#new', as: :duplicate_position
14
+ post 'positions/propose', to: 'positions#propose', as: :propose_position
15
+ get 'positions/:id/prepare', to: 'positions#prepare', as: :prepare_to_roll_position, defaults: { template: 'gameui' }
16
+ match 'positions/:id/prepare2', to: 'positions#prepare2', as: :prepare2_position, defaults: { template: 'gameui' }, via: [ :get, :post ]
17
+ match 'positions/:id/prepare3', to: 'positions#prepare3', as: :prepare3_position, defaults: { template: 'gameui' }, via: [ :get, :post ]
18
+ post 'positions/:id/roll', to: 'positions#do_roll', as: :roll_position
19
+ get 'positions/:id/sync', to: 'positions#sync', as: :sync_position
20
20
  resources :positions
21
21
  resources :profiles
22
22
 
@@ -29,6 +29,7 @@ Iro::Engine.routes.draw do
29
29
 
30
30
  resources :strategies
31
31
 
32
+ get 'api/oauth2-redirect.html', to: 'api#oauth2_redirect'
32
33
  namespace :api do
33
34
  get 'stocks', to: 'stocks#index'
34
35
  get 'stocks/:ticker', to: 'stocks#show'
@@ -62,7 +62,8 @@ namespace :iro do
62
62
  # Wco::Exceptionist.notify(e, 'Error in iro:watch_stocks')
63
63
  end
64
64
 
65
- sleep 15*60 # 15 min
65
+ print '.'
66
+ sleep 15 # *60 # 15 min
66
67
  end
67
68
  end
68
69
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron_warbler
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.7.27
4
+ version: 2.0.7.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Pudeyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-07 00:00:00.000000000 Z
11
+ date: 2024-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: business_time
@@ -218,6 +218,7 @@ files:
218
218
  - app/assets/javascript/iron_warbler/application.js
219
219
  - app/assets/javascript/iron_warbler/gameui.js
220
220
  - app/assets/stylesheets/iron_warbler/Card.scss
221
+ - app/assets/stylesheets/iron_warbler/alerts.scss
221
222
  - app/assets/stylesheets/iron_warbler/application.css
222
223
  - app/assets/stylesheets/iron_warbler/positions.scss
223
224
  - app/assets/stylesheets/iron_warbler/positions_gameui.scss
@@ -304,6 +305,7 @@ files:
304
305
  - app/views/iro/stocks/_grid_is_short.haml
305
306
  - app/views/iro/stocks/edit.haml
306
307
  - app/views/iro/stocks/index.haml
308
+ - app/views/iro/stocks/show.haml
307
309
  - app/views/iro/strategies/_form.haml
308
310
  - app/views/iro/strategies/_header.haml
309
311
  - app/views/iro/strategies/_show.haml