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 +4 -4
- data/lib/ish/ameritrade.rb +61 -21
- data/lib/ish/input_error.rb +3 -0
- data/lib/ish_models.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5abe58e2f0a85264e21a4e9f29628e9779df734de5853030678582216f8ef46
|
4
|
+
data.tar.gz: bb3ff694e571ae054038bfb72383c320f4e81feb46036d33f26ef369809758ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c392fd667cbfa30fd5066cb6431b92bc3c775da4a0f15fb0c2948c81f612b6695888f3d76346e9464f8ce32a01ef3017593604c6a14f12339e3f1a46f1dfdf55
|
7
|
+
data.tar.gz: 3d6d42a6b3624eb87bb165b14bd5e7c20d9ce7ce474ea2ba8f8b63bfa324aa5490b2ea210e0164d0a815a5ad978870ed03396416cf646dbfa436d72b186824bb
|
data/lib/ish/ameritrade.rb
CHANGED
@@ -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
|
-
|
9
|
+
# https://developer.tdameritrade.com/option-chains/apis/get/marketdata/chains
|
10
|
+
# FVRR_082021P200
|
10
11
|
|
11
|
-
|
12
|
-
include HTTParty
|
13
|
-
base_uri 'api.tdameritrade.com'
|
12
|
+
require 'httparty'
|
14
13
|
|
15
|
-
|
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|
|
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 =
|
25
|
-
out = self.
|
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.
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
data/lib/ish_models.rb
CHANGED
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.
|
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
|