-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
12 changed files
with
198 additions
and
90 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
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
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,7 +1,13 @@ | ||
from starlette.applications import Starlette | ||
|
||
from exchange_radar.web.src.endpoints.http import exc_handler | ||
from exchange_radar.web.src.settings import base as settings | ||
from exchange_radar.web.src.tasks.sync_cache import sync_cache | ||
from exchange_radar.web.src.urls import routes | ||
|
||
app = Starlette(debug=settings.DEBUG, routes=routes, on_startup=(sync_cache,)) | ||
exception_handlers = { | ||
400: exc_handler, | ||
} | ||
|
||
|
||
app = Starlette(debug=settings.DEBUG, routes=routes, exception_handlers=exception_handlers, on_startup=(sync_cache,)) |
Empty file.
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,36 @@ | ||
from collections.abc import Callable | ||
from functools import wraps | ||
|
||
from starlette.exceptions import HTTPException, WebSocketException | ||
from starlette.requests import Request | ||
|
||
|
||
class RaiseValidationException: | ||
def __init__(self, request: Request, message: str): | ||
if request.scope["type"] == "http": | ||
raise HTTPException(400, detail=message) | ||
elif request.scope["type"] == "websocket": | ||
raise WebSocketException(code=1008, reason=None) | ||
raise HTTPException(400, detail="Invalid request type") | ||
|
||
|
||
def validate(serializer) -> Callable: | ||
def decorator(f: Callable): | ||
@wraps(f) | ||
async def wrapper(*args, **kwargs): | ||
data = None | ||
request: Request = args[-1] | ||
try: | ||
data = serializer(**request.path_params) | ||
except AttributeError: | ||
# object has no attribute 'path_params' | ||
pass | ||
except TypeError: | ||
RaiseValidationException(request=request, message="Mandatory fields are missing") | ||
except ValueError as error: | ||
RaiseValidationException(request=request, message=str(error)) | ||
return await f(data=data, *args, **kwargs) | ||
|
||
return wrapper | ||
|
||
return decorator |
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 dataclasses import dataclass | ||
|
||
from exchange_radar.web.src.serializers.mixins import Validations | ||
from exchange_radar.web.src.settings import base as settings | ||
|
||
|
||
@dataclass | ||
class ParamsInputSerializer(Validations): | ||
coin: str | ||
|
||
def validate_coin(self, value, **_) -> str: # noqa | ||
if value not in settings.COINS: | ||
raise ValueError(f"Invalid coin: {value}") | ||
return value | ||
|
||
|
||
@dataclass | ||
class IndexParamsInputSerializer(ParamsInputSerializer): | ||
coin: str = "BTC" |
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,5 @@ | ||
class Validations: | ||
def __post_init__(self): | ||
for name, field in self.__dataclass_fields__.items(): # noqa | ||
if method := getattr(self, f"validate_{name}", None): | ||
setattr(self, name, method(getattr(self, name), field=field)) |
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
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,47 @@ | ||
function createElement(obj) { | ||
const span = document.createElement("span"); | ||
|
||
if (obj.is_seller === false) { | ||
span.className = "order_buy"; | ||
} else { | ||
span.className = "order_sell"; | ||
} | ||
|
||
span.innerHTML = ` ${obj.message} \n`; | ||
return span | ||
} | ||
|
||
function setVolume(obj) { | ||
const volume = obj.volume.toLocaleString('en-US', { | ||
minimumFractionDigits: 4, | ||
maximumFractionDigits: 8 | ||
}); | ||
$(`#${obj.trade_symbol}_volume`).text(volume); | ||
|
||
if (obj.hasOwnProperty('price')) { | ||
const volume_in_currency = (obj.volume * obj.price).toLocaleString('en-US', { | ||
minimumFractionDigits: 2, | ||
maximumFractionDigits: 2 | ||
}); | ||
$(`#${obj.trade_symbol}_volume_in_currency`).text(`${volume_in_currency} ${obj.currency}`); | ||
} | ||
} | ||
|
||
function setVolumeTrades(obj) { | ||
const volume_trades_buys = obj.volume_trades[0].toLocaleString('en-US', { | ||
minimumFractionDigits: 4, | ||
maximumFractionDigits: 8 | ||
}); | ||
$(`#${obj.trade_symbol}_volume_trades_buy_orders`).text(volume_trades_buys); | ||
|
||
const volume_trades_sells = obj.volume_trades[1].toLocaleString('en-US', { | ||
minimumFractionDigits: 4, | ||
maximumFractionDigits: 8 | ||
}); | ||
$(`#${obj.trade_symbol}_volume_trades_sell_orders`).text(volume_trades_sells); | ||
} | ||
|
||
function setNumberTrades(obj) { | ||
$(`#${obj.trade_symbol}_number_trades_buy_orders`).text(obj.number_trades[0].toLocaleString('en-US')); | ||
$(`#${obj.trade_symbol}_number_trades_sell_orders`).text(obj.number_trades[1].toLocaleString('en-US')); | ||
} |
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
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,32 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
|
||
<head> | ||
{% include 'snippets/headers.j2' %} | ||
{% include 'snippets/switch.j2' %} | ||
</head> | ||
|
||
<body> | ||
<div class="padded-boxes"> | ||
<section> | ||
<div class="padded"> | ||
<!-- box 1 content --> | ||
<pre> | ||
{{ error_message }} | ||
|
||
|
||
|
||
|
||
|
||
<label class="switch"><span class="sun"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g fill="#ffd43b"><circle r="5" cy="12" cx="12"></circle><path d="m21 13h-1a1 1 0 0 1 0-2h1a1 1 0 0 1 0 2zm-17 0h-1a1 1 0 0 1 0-2h1a1 1 0 0 1 0 2zm13.66-5.66a1 1 0 0 1 -.66-.29 1 1 0 0 1 0-1.41l.71-.71a1 1 0 1 1 1.41 1.41l-.71.71a1 1 0 0 1 -.75.29zm-12.02 12.02a1 1 0 0 1 -.71-.29 1 1 0 0 1 0-1.41l.71-.66a1 1 0 0 1 1.41 1.41l-.71.71a1 1 0 0 1 -.7.24zm6.36-14.36a1 1 0 0 1 -1-1v-1a1 1 0 0 1 2 0v1a1 1 0 0 1 -1 1zm0 17a1 1 0 0 1 -1-1v-1a1 1 0 0 1 2 0v1a1 1 0 0 1 -1 1zm-5.66-14.66a1 1 0 0 1 -.7-.29l-.71-.71a1 1 0 0 1 1.41-1.41l.71.71a1 1 0 0 1 0 1.41 1 1 0 0 1 -.71.29zm12.02 12.02a1 1 0 0 1 -.7-.29l-.66-.71a1 1 0 0 1 1.36-1.36l.71.71a1 1 0 0 1 0 1.41 1 1 0 0 1 -.71.24z"></path></g></svg></span><span class="moon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path d="m223.5 32c-123.5 0-223.5 100.3-223.5 224s100 224 223.5 224c60.6 0 115.5-24.2 155.8-63.4 5-4.9 6.3-12.5 3.1-18.7s-10.1-9.7-17-8.5c-9.8 1.7-19.8 2.6-30.1 2.6-96.9 0-175.5-78.8-175.5-176 0-65.8 36-123.1 89.3-153.3 6.1-3.5 9.2-10.5 7.7-17.3s-7.3-11.9-14.3-12.5c-6.3-.5-12.6-.8-19-.8z"></path></svg></span><input type="checkbox" class="input"><span class="slider"></span></label> | ||
|
||
|
||
<a href="https://pauloantunes.com">Contact</a> | <a href="https://github.com/pantunes/exchange-radar">Github</a> | ||
|
||
</pre> | ||
</div> | ||
</section> | ||
</div> | ||
</body> | ||
|
||
</html> |
Oops, something went wrong.