Skip to content

Commit

Permalink
Add app
Browse files Browse the repository at this point in the history
  • Loading branch information
Tcintra committed Dec 12, 2023
1 parent b4d122a commit 472036c
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@

[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
[![CI](https://github.com/xenophonlabs/crvUSDrisk/actions/workflows/CI.yml/badge.svg)](https://github.com/xenophonlabs/crvUSDrisk/actions/workflows/CI.yml/badge.svg)
[![CI](https://github.com/xenophonlabs/oneinch-quotes/actions/workflows/CI.yml/badge.svg)](https://github.com/xenophonlabs/oneinch-quotes/actions/workflows/CI.yml/badge.svg)

*This repo is being used as part of the [crvUSD Risk Modeling effort](https://github.com/xenophonlabs/crvUSDrisk).*

TODO:

- Complete README

- Change CI badge URL

- Add demo notebook with plots!


Expand Down
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
astroid==3.0.1
asttokens==2.4.1
black==23.11.0
blinker==1.7.0
certifi==2023.11.17
charset-normalizer==3.3.2
click==8.1.7
decorator==5.1.1
dill==0.3.7
executing==2.0.1
Flask==3.0.0
Flask-SQLAlchemy==3.1.1
greenlet==3.0.2
idna==3.6
ipython==8.18.1
isort==5.13.1
itsdangerous==2.1.2
jedi==0.19.1
Jinja2==3.1.2
MarkupSafe==2.1.3
matplotlib-inline==0.1.6
mccabe==0.7.0
mypy==1.7.1
Expand All @@ -29,6 +35,7 @@ ptyprocess==0.7.0
pure-eval==0.2.2
Pygments==2.17.2
pylint==3.0.3
pylint-plugin-utils==0.8.2
python-dateutil==2.8.2
python-dotenv==1.0.0
pytz==2023.3.post1
Expand All @@ -45,3 +52,4 @@ typing_extensions==4.9.0
tzdata==2023.3
urllib3==2.1.0
wcwidth==0.2.12
Werkzeug==3.0.1
Empty file added src/app/__init__.py
Empty file.
64 changes: 64 additions & 0 deletions src/app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""
Provides an API for accessing quotes.
"""
from flask import Flask, jsonify, request
from flask.wrappers import Response
from flask_sqlalchemy import SQLAlchemy
from ..db.datahandler import DataHandler
from ..configs import URI

db = SQLAlchemy()

app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = URI
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

db.init_app(app)


@app.route("/quotes", methods=["GET"])
def get_quotes() -> Response:
"""
Get 1Inch quotes.
Parameters
----------
pair : tuple | None
The pair to get quotes for. If not provided,
all pairs are returned.
start : int | None
The start timestamp to get quotes for. If not provided,
all quotes until `end` are returned.
end : int | None
The end timestamp to get quotes for. If not provided,
all quotes from `start` are returned.
cols : list | None
The columns to return. If not provided, all columns are returned.
process : bool
Whether to process the quotes. If processed, the returned quotes
will be grouped by `hour` and a `price_impact` column will be added.
Refer to :func:`src.db.datahandler.DataHandler.process_quotes`.
Returns
-------
flask.wrappers.Response
The quotes.
"""
pair = request.args.get("pair", type=tuple)
start = request.args.get("start", type=int)
end = request.args.get("end", type=int)
cols = request.args.get("cols", type=list)
process = request.args.get("process", True, type=bool)
with DataHandler() as datahandler:
try:
return jsonify(
datahandler.get_quotes(
pair, start, end, cols=cols, process=process
).to_dict(orient="records")
)
except Exception as e: # pylint: disable=broad-except
return jsonify({"error": str(e)})


if __name__ == "__main__":
app.run(debug=True)

0 comments on commit 472036c

Please sign in to comment.