Skip to content

Commit bb2bcc8

Browse files
committed
init
0 parents  commit bb2bcc8

File tree

18 files changed

+421
-0
lines changed

18 files changed

+421
-0
lines changed

.gitignore

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/#use-with-ide
110+
.pdm.toml
111+
112+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113+
__pypackages__/
114+
115+
# Celery stuff
116+
celerybeat-schedule
117+
celerybeat.pid
118+
119+
# SageMath parsed files
120+
*.sage.py
121+
122+
# Environments
123+
.env
124+
.venv
125+
env/
126+
venv/
127+
ENV/
128+
env.bak/
129+
venv.bak/
130+
131+
# Spyder project settings
132+
.spyderproject
133+
.spyproject
134+
135+
# Rope project settings
136+
.ropeproject
137+
138+
# mkdocs documentation
139+
/site
140+
141+
# mypy
142+
.mypy_cache/
143+
.dmypy.json
144+
dmypy.json
145+
146+
# Pyre type checker
147+
.pyre/
148+
149+
# pytype static type analyzer
150+
.pytype/
151+
152+
# Cython debug symbols
153+
cython_debug/
154+
155+
# PyCharm
156+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158+
# and can be added to the global gitignore or merged into this file. For a more nuclear
159+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160+
#.idea/

.npmignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Distribution / packaging
2+
.Python
3+
env/
4+
build/
5+
develop-eggs/
6+
dist/
7+
downloads/
8+
eggs/
9+
.eggs/
10+
lib/
11+
lib64/
12+
parts/
13+
sdist/
14+
var/
15+
*.egg-info/
16+
.installed.cfg
17+
*.egg
18+
19+
# Serverless directories
20+
.serverless

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
install:
2+
python install -r requirements.txt
3+
setup:
4+
python setup.py install
5+
lint:
6+
pylint * --ignore build dist
7+
lint-fix:
8+
autopep8 --in-place --aggressive --aggressive *.py

cnbc/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from __future__ import absolute_import, division, print_function
2+
3+
from cnbc.client import Client

cnbc/api_response.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from __future__ import absolute_import, division, print_function
2+
3+
4+
class ApiResponseBase(object):
5+
def __init__(self, code, headers):
6+
self.code = code
7+
self.headers = headers
8+
9+
10+
class ApiResponse(ApiResponseBase):
11+
def __init__(self, code, headers, body, interface):
12+
# super(ApiResponse, self).__init__(code, headers)
13+
ApiResponseBase.__init__(self, code, headers)
14+
self.data = interface.apply(body.get('data'))

cnbc/client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from __future__ import absolute_import, division, print_function
2+
3+
from cnbc.resources import Quote
4+
from cnbc.util import toJSON
5+
6+
class Client():
7+
def queryQuote(self, symbol):
8+
return Quote.retrieve(symbol)
9+
10+
def apply(self, symbol, requestFn, saveFn):
11+
return saveFn(symbol, requestFn(symbol))
12+
13+
def save(self, symbol, data):
14+
toJSON(self._build_filename(symbol), data)
15+
return data
16+
17+
def _build_filename(self, symbol):
18+
return '{}.json'.format(symbol)

cnbc/interfaces/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from __future__ import absolute_import, division, print_function
2+
3+
from cnbc.interfaces.options_chain import OptionsChain

cnbc/interfaces/object_base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import json
2+
3+
class ObjectBase(object):
4+
def __str__(self):
5+
return json.dumps(self, default=lambda o: o.__dict__,
6+
sort_keys=True)
7+
8+
def __repr__(self):
9+
return self.__str__()

cnbc/interfaces/option.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from __future__ import absolute_import, division, print_function
2+
3+
from cnbc.interfaces.object_base import ObjectBase
4+
5+
class Option(ObjectBase):
6+
def __init__(self, payload = {}):
7+
super()
8+
self.option = payload.get('option')
9+
self.iv = payload.get('iv')
10+
self.open_interest = payload.get('open_interest')
11+
self.volume = payload.get('volume')
12+
self.delta = payload.get('delta')
13+
self.gamma = payload.get('gamma')
14+
self.theta = payload.get('theta')
15+
self.rho = payload.get('rho')
16+
self.vega = payload.get('vega')
17+
self.theo = payload.get('theo')
18+
self.change = payload.get('change')
19+
self.open = payload.get('open')
20+
self.high = payload.get('high')
21+
self.low = payload.get('low')
22+
self.prev_day_close = payload.get('prev_day_close')
23+
24+
@classmethod
25+
def apply(cls, payload):
26+
return cls(payload)
27+
28+
29+
30+

cnbc/interfaces/options_chain.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
from __future__ import absolute_import, division, print_function
3+
4+
from cnbc.interfaces.option import Option
5+
6+
from cnbc.interfaces.object_base import ObjectBase
7+
8+
9+
class OptionsChain(ObjectBase):
10+
def __init__(self, payload={}):
11+
super()
12+
self.symbol = payload.get('symbol')
13+
self.current_price = payload.get('current_price')
14+
self.price_change = payload.get('price_change')
15+
self.price_change_percent = payload.get('price_change_percent')
16+
self.open = payload.get('open')
17+
self.high = payload.get('high')
18+
self.low = payload.get('low')
19+
self.close = payload.get('close')
20+
self.prev_day_close = payload.get('prev_day_close')
21+
self.volume = payload.get('volume')
22+
self.options = payload.get('options')
23+
self.options = list(
24+
map(lambda option: Option.apply(option), self.options))
25+
26+
@classmethod
27+
def apply(cls, payload):
28+
return cls(payload)
29+
30+
# def __dict__(self):
31+
# return {
32+
# 'symbol': self.symbol,
33+
# 'current_price': self.current_price,
34+
# 'price_change': self.price_change,
35+
# 'price_change_percent': self.price_change_percent,
36+
# 'open': self.open,
37+
# 'high': self.high,
38+
# 'low': self.low,
39+
# 'close': self.close,
40+
# 'prev_day_close': self.prev_day_close,
41+
# 'volume': self.volume,
42+
# 'options': list(map(lambda option: option.__str__, self.options))
43+
# }

0 commit comments

Comments
 (0)