ish_models 0.0.33.127 → 0.0.33.128

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: d025168334524e77a95ebd65c77aca9f238357650a60e1ac34d96a98fab70393
4
- data.tar.gz: 880e8151b3f6c11dc6dd43e1b39a1b856ddf18a0f69b8029830a6b224007dd5f
3
+ metadata.gz: a5abe58e2f0a85264e21a4e9f29628e9779df734de5853030678582216f8ef46
4
+ data.tar.gz: bb3ff694e571ae054038bfb72383c320f4e81feb46036d33f26ef369809758ed
5
5
  SHA512:
6
- metadata.gz: 9b5c590ad879d8841b94f9f6c293a24b6ded2a00f085b10704bc55c855954ef89ef324c010e117feaefcfa9da8d9691b0ecafe1220d665406bb748c82cda4ccc
7
- data.tar.gz: fe93fcd905f544f3d584055b6e07ea826e42d451be19e446433ff8db05ff504340a3348087c72a0a2412f60f80c2da662f3efd0a771ad97bcc9f06689bc09142
6
+ metadata.gz: c392fd667cbfa30fd5066cb6431b92bc3c775da4a0f15fb0c2948c81f612b6695888f3d76346e9464f8ce32a01ef3017593604c6a14f12339e3f1a46f1dfdf55
7
+ data.tar.gz: 3d6d42a6b3624eb87bb165b14bd5e7c20d9ce7ce474ea2ba8f8b63bfa324aa5490b2ea210e0164d0a815a5ad978870ed03396416cf646dbfa436d72b186824bb
@@ -6,38 +6,78 @@
6
6
 
7
7
  # cron job or service? Well, I've historically done service. Cron is easier tho. The wiring should be for both.
8
8
 
9
- module Ish::Ameritrade; end
9
+ # https://developer.tdameritrade.com/option-chains/apis/get/marketdata/chains
10
+ # FVRR_082021P200
10
11
 
11
- class Ish::Ameritrade::Api
12
- include HTTParty
13
- base_uri 'api.tdameritrade.com'
12
+ require 'httparty'
14
13
 
15
- def self.get_option_chain opts
14
+ module Ish::Ameritrade
15
+
16
+ CONFIG = {
17
+ underlying_downprice_tolerance: 0.14,
18
+ }
19
+
20
+ # def self.main_fvrr_1
21
+ # query_hash = {
22
+ # apikey: ::TD_AME[:apiKey],
23
+ # symbol: 'FVRR',
24
+ # contractType: 'PUT',
25
+ # strike: 200,
26
+ # fromDate: '2021-08-20',
27
+ # toDate: '2021-08-20',
28
+ # }
29
+ # response = ::Ish::Ameritrade::Api.get_option_chain(query_hash)
30
+ # puts! response, 'ze repsonse'
31
+ # end
32
+
33
+ ## AKA stop loss
34
+ def self.main_fvrr_2
35
+ # response = ::Ish::Ameritrade::Api.get_quote({ symbol: 'FVRR_082021P200' })
36
+
37
+ # @TODO: pass the info on the position in here.
38
+ strike_price = 200
39
+
40
+ # What is my risk tolerance here? 14% down movement of the underlying
41
+ response = ::Ish::Ameritrade::Api.get_quote({ symbol: 'FVRR' })
42
+ last_price = response[:lastPrice]
43
+ tolerable_price = ( strike_price * (1-CONFIG[:underlying_downprice_tolerance]) )
44
+
45
+ if last_price < tolerable_price
46
+ puts! 'LIMIT TRIGGERED, LETS EXIT' # @TODO: send an email
47
+ end
48
+ end
49
+
50
+ end
16
51
 
52
+ class Ish::Ameritrade::Api
53
+ include ::HTTParty
54
+ base_uri 'https://api.tdameritrade.com'
55
+
56
+ def self.get_quote opts
17
57
  # validate input
18
- %i| apiKey symbol contrtactType strike fromDate toDate |.each do |s|
58
+ %i| symbol |.each do |s|
19
59
  if !opts[s]
20
- raise "invalid input, missing #{s}"
60
+ raise Ish::InputError.new("invalid input, missing #{s}")
21
61
  end
22
62
  end
23
63
 
24
- path = '/v1/marketdata/chains'
25
- out = self.class.get path, opts
64
+ path = "/v1/marketdata/#{opts[:symbol]}/quotes"
65
+ out = self.get path, { query: { apikey: ::TD_AME[:apiKey] } }
66
+ out = out.parsed_response[out.parsed_response.keys[0]].symbolize_keys
26
67
  out
27
68
  end
28
69
 
29
- def self.main_fvrr_1
30
- query_hash = {
31
- apiKey: '',
32
- symbol: 'FVRR',
33
- contractType: 'PUT',
34
- stike: 200,
35
- fromDate: '2021-08-20',
36
- toDate: '2021-08-20',
37
- }
38
- response = Ameritrade::Api.get_option_chain(query_hash)
39
-
40
- puts! response, 'ze repsonse'
70
+ def self.get_option_chain opts
71
+ # validate input
72
+ %i| apikey symbol contractType strike fromDate toDate |.each do |s|
73
+ if !opts[s]
74
+ raise Ish::InputError.new("invalid input, missing #{s}")
75
+ end
76
+ end
77
+
78
+ path = '/v1/marketdata/chains'
79
+ out = self.get path, { query: opts }
80
+ out
41
81
  end
42
82
 
43
83
  end
@@ -0,0 +1,3 @@
1
+
2
+ class Ish::InputError < RuntimeError
3
+ end
data/lib/ish_models.rb CHANGED
@@ -37,6 +37,7 @@ require 'ish/ameritrade'
37
37
  require 'ish/covered_call'
38
38
  require 'ish/crawler.rb'
39
39
  require 'ish/gallery_name.rb'
40
+ require 'ish/input_error.rb'
40
41
  require 'ish/iron_condor.rb'
41
42
  require 'ish/iron_condor_watcher.rb'
42
43
  require 'ish/payment.rb'
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.127
4
+ version: 0.0.33.128
5
5
  platform: ruby
6
6
  authors:
7
7
  - piousbox
@@ -125,6 +125,7 @@ files:
125
125
  - lib/ish/covered_call_watcher.rb
126
126
  - lib/ish/crawler.rb
127
127
  - lib/ish/gallery_name.rb
128
+ - lib/ish/input_error.rb
128
129
  - lib/ish/invoice.rb
129
130
  - lib/ish/iron_condor.rb
130
131
  - lib/ish/iron_condor_watcher.rb