-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3acc2d
commit e7cf95d
Showing
53 changed files
with
1,649 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[flake8] | ||
# E501 is the "Line too long" error. We disable it because we use Black for | ||
# code formatting. Black makes a best effort to keep lines under the max | ||
# length, but can go over in some cases. | ||
# W503 goes against PEP8 rules. It's disabled by default, but must be disabled | ||
# explicitly when using `ignore`. | ||
ignore = E501, W503 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Visual Studio Code | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
sudo: false | ||
dist: xenial | ||
|
||
language: python | ||
|
||
matrix: | ||
include: | ||
- python: "3.7" | ||
- python: "3.8" | ||
|
||
cache: | ||
pip: true | ||
|
||
install: | ||
- make venv | ||
|
||
script: | ||
- make lint | ||
- make fmtcheck | ||
- make ci | ||
|
||
after_success: make coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"recommendations": [ | ||
"ms-python.python", | ||
"bungcip.better-toml", | ||
"EditorConfig.editorconfig" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
// Show the path in the top window bar. | ||
"window.title": "${rootName}${separator}${activeEditorMedium}", | ||
"editor.renderWhitespace": "all", | ||
"files.exclude": { | ||
"**/*.pyc": { | ||
"when": "$(basename).py" | ||
}, | ||
"**/__pycache__": true | ||
}, | ||
// Formatting | ||
"editor.formatOnSave": true, | ||
"python.formatting.provider": "black", | ||
// Linting | ||
"python.linting.enabled": true, | ||
"python.linting.pylintEnabled": false, | ||
"python.linting.flake8Enabled": true, | ||
// Tests | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestEnabled": true, | ||
"python.testing.nosetestsEnabled": false, | ||
"python.pythonPath": "/Users/luis.calado/repos/personal/coinoxr/venv/bin/python3.7" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) [2020] Luis Calado | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
VENV_NAME?=venv | ||
|
||
venv: $(VENV_NAME)/bin/activate | ||
|
||
$(VENV_NAME)/bin/activate: setup.py | ||
pip install --upgrade pip virtualenv | ||
@test -d $(VENV_NAME) || python -m virtualenv --clear $(VENV_NAME) | ||
${VENV_NAME}/bin/python -m pip install -U pip tox | ||
${VENV_NAME}/bin/python -m pip install -e . | ||
@touch $(VENV_NAME)/bin/activate | ||
|
||
test: venv | ||
@${VENV_NAME}/bin/tox -p auto | ||
|
||
ci: venv | ||
@${VENV_NAME}/bin/python setup.py test -a "--cov=coinoxr" | ||
|
||
coveralls: venv | ||
@${VENV_NAME}/bin/pip install --upgrade coveralls | ||
@${VENV_NAME}/bin/coveralls | ||
|
||
fmt: venv | ||
@${VENV_NAME}/bin/tox -e fmt | ||
|
||
fmtcheck: venv | ||
@${VENV_NAME}/bin/tox -e fmt -- --check --verbose | ||
|
||
lint: venv | ||
@${VENV_NAME}/bin/tox -e lint | ||
|
||
clean: | ||
@rm -rf $(VENV_NAME) build/ dist/ | ||
|
||
.PHONY: venv test coveralls fmt fmtcheck lint clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,45 @@ | ||
# Coinoxr - Open Exchange Rates | ||
|
||
[![Build Status](https://travis-ci.org/luisfmcalado/coinoxr.svg?branch=master)](https://travis-ci.org/luisfmcalado/coinoxr) | ||
[![Coverage Status](https://coveralls.io/repos/github/luisfmcalado/coinoxr/badge.svg?branch=master)](https://coveralls.io/github/luisfmcalado/coinoxr?branch=master) | ||
|
||
Python library for Open Exchange Rates API. | ||
|
||
## Installation | ||
|
||
Install dependency | ||
```bash | ||
$ pip install coinoxr | ||
``` | ||
|
||
Install dependency from source code | ||
```bash | ||
$ python setup.py install | ||
``` | ||
|
||
### Requirements | ||
- Python 3.7+ | ||
|
||
|
||
## Usage | ||
|
||
```python | ||
import coinoxr | ||
coinoxr.app_id = "c01ed21da6424fd3b0ac68f9e63a3d29" | ||
|
||
coinoxr.Latest().get(base="EUR") | ||
``` | ||
|
||
## Development | ||
|
||
Run all the tests for every environment: | ||
|
||
```bash | ||
$ make test | ||
``` | ||
|
||
The code can be formatted with black: | ||
|
||
```bash | ||
$ make fmt | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from coinoxr.client import RequestsClient | ||
|
||
|
||
default_http_client = RequestsClient() | ||
default_url = "https://openexchangerates.org/api/" | ||
app_id = None | ||
|
||
|
||
def base_url(path): | ||
return default_url + path | ||
|
||
|
||
from coinoxr.usage import Usage # noqa | ||
from coinoxr.latest import Latest # noqa | ||
from coinoxr.historical import Historical # noqa | ||
from coinoxr.currency import Currency # noqa | ||
from coinoxr.time_series import TimeSeries # noqa | ||
from coinoxr.convert import Convert # noqa | ||
from coinoxr.ohlc import Ohlc # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import requests | ||
from coinoxr.response import Response | ||
|
||
|
||
class HttpClient: | ||
def get(self, url, params): | ||
return Response(200, None) | ||
|
||
|
||
class RequestsClient(HttpClient): | ||
def get(self, url, params): | ||
response = requests.get(url, params=params) | ||
try: | ||
return Response(response.status_code, response.json()) | ||
except ValueError: | ||
return Response(response.status_code, None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from coinoxr.requestor import Requestor | ||
|
||
|
||
class Convert: | ||
def __init__(self, requestor=None): | ||
self._requestor = requestor | ||
if requestor is None: | ||
self._requestor = Requestor() | ||
|
||
def get(self, amount, from_currency, to_currency, pretty_print=False): | ||
path = "convert/%s/%s/%s" % (amount, from_currency, to_currency) | ||
params = {"prettyprint": pretty_print} | ||
return self._requestor.get(path, params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from coinoxr.requestor import Requestor | ||
|
||
|
||
class Currency: | ||
def __init__(self, requestor=None): | ||
self._requestor = requestor | ||
if requestor is None: | ||
self._requestor = Requestor(skip_app_id=True) | ||
|
||
def get( | ||
self, pretty_print=False, show_alternative=False, show_inactive=False, | ||
): | ||
params = { | ||
"prettyprint": pretty_print, | ||
"show_alternative": show_alternative, | ||
"show_inactive": show_inactive, | ||
} | ||
return self._requestor.get("currencies.json", params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class AppIdError(Exception): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from coinoxr.requestor import Requestor | ||
|
||
|
||
class Historical: | ||
def __init__(self, requestor=None): | ||
self._requestor = requestor | ||
if requestor is None: | ||
self._requestor = Requestor() | ||
|
||
def get( | ||
self, date, base=None, pretty_print=False, symbols=None, show_alternative=False | ||
): | ||
params = {"prettyprint": pretty_print, "show_alternative": show_alternative} | ||
|
||
if base is not None: | ||
params["base"] = base | ||
|
||
if symbols is not None: | ||
params["symbols"] = symbols | ||
|
||
return self._requestor.get("historical/%s.json" % date, params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from coinoxr.requestor import Requestor | ||
|
||
|
||
class Latest: | ||
def __init__(self, requestor=None): | ||
self._requestor = requestor | ||
if requestor is None: | ||
self._requestor = Requestor() | ||
|
||
def get(self, base=None, pretty_print=False, symbols=None, show_alternative=False): | ||
params = {"prettyprint": pretty_print, "show_alternative": show_alternative} | ||
|
||
if base is not None: | ||
params["base"] = base | ||
|
||
if symbols is not None: | ||
params["symbols"] = symbols | ||
|
||
return self._requestor.get("latest.json", params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from coinoxr.requestor import Requestor | ||
|
||
|
||
class Ohlc: | ||
def __init__(self, requestor=None): | ||
self._requestor = requestor | ||
if requestor is None: | ||
self._requestor = Requestor() | ||
|
||
def get( | ||
self, start_time, period, base=None, pretty_print=False, symbols=None, | ||
): | ||
params = { | ||
"prettyprint": pretty_print, | ||
"period": period, | ||
"start_time": start_time, | ||
} | ||
|
||
if base is not None: | ||
params["base"] = base | ||
|
||
if symbols is not None: | ||
params["symbols"] = symbols | ||
|
||
return self._requestor.get("ohlc.json", params) |
Oops, something went wrong.