sensei_eod_utils 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +56 -0
- data/.rubocop.yml +2 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +49 -0
- data/README.md +1 -0
- data/lib/eod_facade/base.rb +23 -0
- data/lib/eod_facade/constants.rb +15 -0
- data/lib/eod_facade/eod.rb +24 -0
- data/lib/eod_facade/fundamentals.rb +20 -0
- data/lib/eod_facade/options.rb +34 -0
- data/lib/eod_models/option_type.rb +11 -0
- data/lib/eod_services/contract.rb +46 -0
- data/lib/sensei_eod_utils.rb +11 -0
- data/sensei_eod_utils.gemspec +19 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 81fcf0f2ac81739a48382d26cd6e45b07255006d6671ccbc29705efd5d7989bc
|
4
|
+
data.tar.gz: 52930df2d0979b8006e1d5d2b69419bd5d77ba3a0d18b60498361552a7c64593
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6a624e587a722bedd29a1a232d8a3c02675cc6329d77ae6fff4a6b714e8b31a4db641f3ec43982380e68014a98932701ea3921d1f93bfb5ca91071b3c80d6bc0
|
7
|
+
data.tar.gz: 0d0360220deca1c692135c908a79062052bdd8e194aec17cef9f0c5e4b7fb0de5e22223bb9e3fd62a22d4b6e8a5a04faf40bb1be55f8b6df66a576edc29000c1
|
data/.gitignore
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
# .rubocop-https?--*
|
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
ruby '2.5.5'
|
5
|
+
|
6
|
+
gem 'httparty'
|
7
|
+
# gem 'redis'
|
8
|
+
gem 'oj'
|
9
|
+
|
10
|
+
group :development do
|
11
|
+
gem 'pry'
|
12
|
+
gem 'rubocop', require: false
|
13
|
+
gem 'rubocop-rspec', require: false
|
14
|
+
end
|
15
|
+
|
16
|
+
group :test do
|
17
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ast (2.4.0)
|
5
|
+
coderay (1.1.2)
|
6
|
+
httparty (0.17.3)
|
7
|
+
mime-types (~> 3.0)
|
8
|
+
multi_xml (>= 0.5.2)
|
9
|
+
jaro_winkler (1.5.4)
|
10
|
+
method_source (0.9.2)
|
11
|
+
mime-types (3.3)
|
12
|
+
mime-types-data (~> 3.2015)
|
13
|
+
mime-types-data (3.2019.1009)
|
14
|
+
multi_xml (0.6.0)
|
15
|
+
oj (3.10.0)
|
16
|
+
parallel (1.19.1)
|
17
|
+
parser (2.6.5.0)
|
18
|
+
ast (~> 2.4.0)
|
19
|
+
pry (0.12.2)
|
20
|
+
coderay (~> 1.1.0)
|
21
|
+
method_source (~> 0.9.0)
|
22
|
+
rainbow (3.0.0)
|
23
|
+
rubocop (0.78.0)
|
24
|
+
jaro_winkler (~> 1.5.1)
|
25
|
+
parallel (~> 1.10)
|
26
|
+
parser (>= 2.6)
|
27
|
+
rainbow (>= 2.2.2, < 4.0)
|
28
|
+
ruby-progressbar (~> 1.7)
|
29
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
30
|
+
rubocop-rspec (1.37.1)
|
31
|
+
rubocop (>= 0.68.1)
|
32
|
+
ruby-progressbar (1.10.1)
|
33
|
+
unicode-display_width (1.6.0)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
httparty
|
40
|
+
oj
|
41
|
+
pry
|
42
|
+
rubocop
|
43
|
+
rubocop-rspec
|
44
|
+
|
45
|
+
RUBY VERSION
|
46
|
+
ruby 2.5.5p157
|
47
|
+
|
48
|
+
BUNDLED WITH
|
49
|
+
2.0.2
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# sensei-eod-utils
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
module EodFacade
|
6
|
+
class Base
|
7
|
+
class << self
|
8
|
+
def make_request(url_path, params = {})
|
9
|
+
HTTParty.get(full_url(url_path),
|
10
|
+
query: params.merge(
|
11
|
+
api_token: EodApi::Constants.api_key
|
12
|
+
),
|
13
|
+
format: :json)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def full_url(url_path)
|
19
|
+
"#{EodApi::Constants.base_url}#{url_path}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bigdecimal'
|
4
|
+
|
5
|
+
require_relative 'base_service'
|
6
|
+
require_relative '../redis/service'
|
7
|
+
require_relative '../trade/option/contract_service'
|
8
|
+
|
9
|
+
module EodFacade
|
10
|
+
class Eod < ::EodFacade::Base
|
11
|
+
class << self
|
12
|
+
def call(symbol, params = {})
|
13
|
+
data = make_request(url_path(symbol), params.merge(fmt: 'json'))
|
14
|
+
Oj.load(data)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def url_path(symbol)
|
20
|
+
"/eod/#{symbol}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'oj'
|
4
|
+
|
5
|
+
module EodFacade
|
6
|
+
class Fundamentals < ::EodFacade::Base
|
7
|
+
class << self
|
8
|
+
def call(symbol)
|
9
|
+
data = make_request(url_path(symbol))
|
10
|
+
Oj.load(data)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def url_path(symbol)
|
16
|
+
"/fundamentals/#{symbol}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'oj'
|
4
|
+
|
5
|
+
module EodFacade
|
6
|
+
class Options < ::EodFacade::Base
|
7
|
+
class << self
|
8
|
+
def call(symbol)
|
9
|
+
underlying = EodServices::Contract.underlying_symbol(symbol)
|
10
|
+
expiry = EodServices::Contract.contract_expiry(symbol)
|
11
|
+
|
12
|
+
unless expiry
|
13
|
+
raise ArgumentError, "Invalid expiration date for option #{symbol}"
|
14
|
+
end
|
15
|
+
|
16
|
+
data = make_request(url_path(underlying), params(expiry))
|
17
|
+
Oj.load(data)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def params(expiry)
|
23
|
+
{
|
24
|
+
from: expiry.to_s,
|
25
|
+
to: expiry.to_s
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def url_path(underlying)
|
30
|
+
"/options/#{underlying}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EodServices
|
4
|
+
class Contract
|
5
|
+
class <<self
|
6
|
+
# rubocop:disable Metrics/LineLength
|
7
|
+
CONTRACT_REGEX = /^(?<symbol>[A-Z]+)(?<expiry>[0-9]{6})(?<option_type>[CP]{1})[0-9]{8}$/.freeze
|
8
|
+
# rubocop:enable Metrics/LineLength
|
9
|
+
|
10
|
+
def contract_symbol(underlying:, expiry:, type:, strike:)
|
11
|
+
return underlying if type == OptionType::STOCK
|
12
|
+
|
13
|
+
underlying + expiration(expiry) + type + padded_strike(strike)
|
14
|
+
end
|
15
|
+
|
16
|
+
def underlying_symbol(contract_symbol)
|
17
|
+
match = contract_symbol.match(CONTRACT_REGEX)
|
18
|
+
return match[:symbol] if match
|
19
|
+
|
20
|
+
contract_symbol
|
21
|
+
end
|
22
|
+
|
23
|
+
def contract_expiry(contract_symbol)
|
24
|
+
match = contract_symbol.match(CONTRACT_REGEX)
|
25
|
+
Date.parse(match[:expiry]) if match
|
26
|
+
end
|
27
|
+
|
28
|
+
def contract_type(contract_symbol)
|
29
|
+
match = contract_symbol.match(CONTRACT_REGEX)
|
30
|
+
return match[:option_type] if match
|
31
|
+
|
32
|
+
OptionType::STOCK
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def padded_strike(strike)
|
38
|
+
(strike * 1000).to_i.to_s.rjust(8, '0')
|
39
|
+
end
|
40
|
+
|
41
|
+
def expiration(expiry)
|
42
|
+
expiry.strftime('%y%m%d')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eod_models/option_type.rb'
|
4
|
+
|
5
|
+
require 'eod_services/contract.rb'
|
6
|
+
|
7
|
+
require 'eod_facade/base.rb'
|
8
|
+
require 'eod_facade/constants.rb'
|
9
|
+
require 'eod_facade/fundamentals.rb'
|
10
|
+
require 'eod_facade/options.rb'
|
11
|
+
require 'eod_facade/eod.rb'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'sensei_eod_utils'
|
5
|
+
s.version = '0.0.0'
|
6
|
+
s.date = '2019-12-20'
|
7
|
+
s.summary = 'Sensei trader utility functions and Eod api facade'
|
8
|
+
s.authors = ['Nishant Shah']
|
9
|
+
s.files = `git ls-files -z`.split("\x0").reject do |f|
|
10
|
+
f.match(%r{^(test|spec|features)/})
|
11
|
+
end
|
12
|
+
s.require_paths = ['lib']
|
13
|
+
s.homepage = 'https://rubygems.org/gems/sensei_eod_utils'
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
s.add_dependency 'httparty', '~> 0.17'
|
17
|
+
# s.add_dependency "redis"
|
18
|
+
s.add_dependency 'oj', '~> 3.10'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensei_eod_utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nishant Shah
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.17'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: oj
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.10'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.10'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- ".gitignore"
|
48
|
+
- ".rubocop.yml"
|
49
|
+
- Gemfile
|
50
|
+
- Gemfile.lock
|
51
|
+
- README.md
|
52
|
+
- lib/eod_facade/base.rb
|
53
|
+
- lib/eod_facade/constants.rb
|
54
|
+
- lib/eod_facade/eod.rb
|
55
|
+
- lib/eod_facade/fundamentals.rb
|
56
|
+
- lib/eod_facade/options.rb
|
57
|
+
- lib/eod_models/option_type.rb
|
58
|
+
- lib/eod_services/contract.rb
|
59
|
+
- lib/sensei_eod_utils.rb
|
60
|
+
- sensei_eod_utils.gemspec
|
61
|
+
homepage: https://rubygems.org/gems/sensei_eod_utils
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubygems_version: 3.0.4
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Sensei trader utility functions and Eod api facade
|
84
|
+
test_files: []
|