ish_models 0.0.33.148 → 0.0.33.152

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: 84cc3820b6d71d08c41b6f903b82547dc048150f15a9beb76daf0dd0e17d91dc
4
- data.tar.gz: db8ea548690613d03cde7eb754c48ed86684184af3f7ef882b5329a822907d92
3
+ metadata.gz: eda424943e1eef920292be882d4c3d0f4de268fb556d4e85b0f099c793a577e2
4
+ data.tar.gz: 5c74167f789c8ac201c90a01c3f4c4a16bfd2ea965b2191990ab6c57daae7717
5
5
  SHA512:
6
- metadata.gz: d15d489470b5af11cd24a764578b23631819863b62800d99cd1ea4a5dc949df19af41af4948f4310ebf1738c9a3d18970d3b4925b69025b8885de48a7521aa68
7
- data.tar.gz: 1b7fc6f63626ae2b9ebc7e97adc48b1267d4dbcf7b328dae1bdd1aec53e163864bd2bd0a429effc6e5790ccfa0942c31ceebd35861617abaad47723682ef3be7
6
+ metadata.gz: 8f98bc72d8dc91b8061b28bfeec8954d283c3e811c6dc7a6e7cb2e574818417232f154c9d5271cf28a25e76f500dc637454c77c9bcb9fe43e86bb8f6a3f789fd
7
+ data.tar.gz: 5a6858c1ca87bf1c3d3dc293a01263682f5dede179c1bb07380eb70c7f1a0a4451106419263b1f9c421895a49d2307a7224ad9bed0773629e05c22e24152adab
@@ -38,6 +38,7 @@ class Ish::UserProfile
38
38
  has_many :photos
39
39
  has_many :reports, inverse_of: :user_profile
40
40
  has_many :stocks, :class_name => '::Warbler::StockWatch'
41
+ has_many :option_watches, class_name: '::Warbler::OptionWatch'
41
42
  has_many :videos, inverse_of: :user_profile
42
43
  has_many :newsitems, inverse_of: :user_profile
43
44
 
data/lib/ish_models.rb CHANGED
@@ -61,18 +61,14 @@ require 'tag'
61
61
  require 'venue'
62
62
  require 'video'
63
63
 
64
+ require 'warbler/option_watch'
64
65
  require 'warbler/stock_watch'
65
66
  require 'warbler/ameritrade'
66
67
 
67
68
  ## warbler
68
- # require 'warbler/alphavantage_stockwatcher'
69
- # require 'warbler/ameritrade'
70
69
  # require 'warbler/covered_call'
71
70
  # require 'warbler/iron_condor'
72
- # require 'warbler/iron_condor_watcher'
73
71
  # require 'warbler/stock_action'
74
- # require 'warbler/stock_option'
75
- # require 'warbler/yahoo_stockwatcher'
76
72
 
77
73
 
78
74
 
data/lib/video.rb CHANGED
@@ -12,6 +12,14 @@ class Video
12
12
  # default_scope ->{ where({ :is_public => true, :is_trash => false }).order_by({ :created_at => :desc }) }
13
13
 
14
14
  field :is_trash, :type => Boolean, :default => false
15
+ def is_trash
16
+ if deleted_at
17
+ true
18
+ else
19
+ self[:is_trash]
20
+ end
21
+ end
22
+
15
23
  field :is_public, :type => Boolean, :default => false
16
24
  field :is_feature, :type => Boolean, :default => false
17
25
 
@@ -39,6 +39,8 @@ end
39
39
  class ::Warbler::Ameritrade::Api
40
40
  include ::HTTParty
41
41
  base_uri 'https://api.tdameritrade.com'
42
+ PUT = 'PUT'
43
+ CALL = 'CALL'
42
44
 
43
45
  def self.get_quote opts
44
46
  # validate input
@@ -54,17 +56,35 @@ class ::Warbler::Ameritrade::Api
54
56
  out
55
57
  end
56
58
 
57
- def self.get_option_chain opts
59
+ def self.get_option _opts
60
+ opts = {}
61
+
58
62
  # validate input
59
- %i| apikey symbol contractType strike fromDate toDate |.each do |s|
60
- if !opts[s]
61
- raise Ish::InputError.new("invalid input, missing #{s}")
63
+ validOpts = %i| contractType strike |
64
+ validOpts.each do |s|
65
+ if _opts[s]
66
+ opts[s] = _opts[s]
67
+ else
68
+ raise Ish::InputError.new("Invalid input, missing '#{s}'.")
62
69
  end
63
70
  end
71
+ if _opts[:date]
72
+ opts[:fromDate] = opts[:toDate] = _opts[:date]
73
+ else
74
+ raise Ish::InputError.new("Invalid input, missing 'date'.")
75
+ end
76
+ if _opts[:ticker]
77
+ opts[:symbol] = _opts[:ticker].upcase
78
+ else
79
+ raise Ish::InputError.new("Invalid input, missing 'ticker'.")
80
+ end
64
81
 
65
- path = '/v1/marketdata/chains'
66
- out = self.get path, { query: opts }
67
- out
82
+ query = { apikey: ::TD_AME[:apiKey], strikeCount: 1 }.merge opts
83
+ path = "/v1/marketdata/chains"
84
+ out = self.get path, { query: query }
85
+ out = out.parsed_response.deep_symbolize_keys
86
+ tmp_sym = "#{opts[:contractType].to_s.downcase}ExpDateMap".to_sym
87
+ out[tmp_sym].first[1].first[1][0]
68
88
  end
69
89
 
70
90
  end
@@ -0,0 +1,41 @@
1
+
2
+ class Warbler::OptionWatch
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+ store_in collection: 'ish_option_watches'
6
+
7
+ SLEEP_TIME_SECONDS = 60
8
+
9
+ field :ticker # like NVDA
10
+ validates :ticker, presence: true
11
+ # field :symbol # like NVDA_021822C230
12
+
13
+ ## Strike isn't the same as price!
14
+ field :strike, :type => Float
15
+ validates :strike, presence: true
16
+
17
+ ## What is the price of the option at some strike?
18
+ field :price, type: Float
19
+ validates :price, presence: true
20
+
21
+ field :contractType
22
+ validates :contractType, presence: true
23
+
24
+ field :date
25
+ validates :date, presence: true
26
+
27
+ NOTIFICATION_TYPES = [ :NONE, :EMAIL, :SMS ]
28
+ ACTIONS = NOTIFICATION_TYPES
29
+ NOTIFICATION_NONE = :NONE
30
+ NOTIFICATION_EMAIL = :EMAIL
31
+ NOTIFICATION_SMS = :SMS
32
+ field :notification_type, :type => Symbol, :as => :action
33
+
34
+ DIRECTIONS = [ :ABOVE, :BELOW ]
35
+ DIRECTION_ABOVE = :ABOVE
36
+ DIRECTION_BELOW = :BELOW
37
+ field :direction, :type => Symbol
38
+
39
+ belongs_to :profile, :class_name => 'Ish::UserProfile'
40
+
41
+ end
@@ -4,13 +4,15 @@ class Warbler::StockWatch
4
4
  include Mongoid::Timestamps
5
5
  store_in collection: 'ish_stock_watches'
6
6
 
7
+ SLEEP_TIME_SECONDS = 60
8
+
7
9
  field :ticker
8
10
 
9
11
  NOTIFICATION_TYPES = [ :NONE, :EMAIL, :SMS ]
12
+ ACTIONS = NOTIFICATION_TYPES
10
13
  NOTIFICATION_NONE = :NONE
11
14
  NOTIFICATION_EMAIL = :EMAIL
12
15
  NOTIFICATION_SMS = :SMS
13
- ACTIONS = NOTIFICATION_TYPES
14
16
  field :notification_type, :type => Symbol, :as => :action
15
17
 
16
18
  field :price, :type => Float
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ish_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.33.148
4
+ version: 0.0.33.152
5
5
  platform: ruby
6
6
  authors:
7
7
  - piousbox
@@ -162,6 +162,7 @@ files:
162
162
  - lib/warbler/covered_call_watcher.rb
163
163
  - lib/warbler/iron_condor.rb
164
164
  - lib/warbler/iron_condor_watcher.rb
165
+ - lib/warbler/option_watch.rb
165
166
  - lib/warbler/stock_action.rb
166
167
  - lib/warbler/stock_option.rb
167
168
  - lib/warbler/stock_watch.rb