-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: bump pydantic, sqlmodel, and fastapi
- Loading branch information
Showing
49 changed files
with
652 additions
and
450 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
.idea/ | ||
.vscode/ | ||
|
||
scratch* | ||
|
||
.old/ | ||
|
||
# Byte-compiled / optimized / DLL files | ||
|
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
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
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,63 +1,82 @@ | ||
from typing import TYPE_CHECKING | ||
from fastapi import APIRouter, HTTPException | ||
from __future__ import annotations | ||
|
||
from typing import Union | ||
|
||
from fastapi import APIRouter, HTTPException, Query | ||
from starlette.responses import Response | ||
|
||
from balanced_backend.api.v1.endpoints._utils import sleep_while_empty_cache | ||
from balanced_backend.cache.cache import cache | ||
|
||
if TYPE_CHECKING: | ||
from balanced_backend.models.coingecko import ( | ||
PairsCoinGecko, | ||
TickerCoinGecko, | ||
OrderBookCoinGecko, | ||
HistoricalCoinGecko, | ||
) | ||
from balanced_backend.models.coingecko import ( | ||
PairsCoinGecko, | ||
TickerCoinGecko, | ||
OrderBookCoinGecko, | ||
HistoricalCoinGecko, | ||
) | ||
|
||
router = APIRouter() | ||
|
||
|
||
# Per this guide | ||
# https://docs.google.com/document/d/1v27QFoQq1SKT3Priq3aqPgB70Xd_PnDzbOCiuoCyixw/edit | ||
|
||
|
||
@router.get("/pairs") | ||
async def get_coingecko_summary() -> list['PairsCoinGecko']: | ||
await sleep_while_empty_cache('coingecko_pairs') | ||
async def get_coingecko_summary() -> list[PairsCoinGecko]: | ||
await sleep_while_empty_cache("coingecko_pairs") | ||
return cache.coingecko_pairs | ||
|
||
|
||
@router.get("/tickers") | ||
async def get_coingecko_ticker() -> dict[str, 'TickerCoinGecko']: | ||
await sleep_while_empty_cache('coingecko_tickers') | ||
async def get_coingecko_ticker() -> list[TickerCoinGecko]: | ||
await sleep_while_empty_cache("coingecko_tickers") | ||
return cache.coingecko_tickers | ||
|
||
|
||
@router.get("/orderbook") | ||
async def get_coingecko_orderbook( | ||
ticker_id: str = None, | ||
) -> dict[str, 'OrderBookCoinGecko']: | ||
await sleep_while_empty_cache('coingecko_orderbook') | ||
ticker_id: str = None, | ||
) -> dict[str, OrderBookCoinGecko] | OrderBookCoinGecko: | ||
await sleep_while_empty_cache("coingecko_orderbook") | ||
if ticker_id is None: | ||
return cache.coingecko_orderbook | ||
try: | ||
return cache.coingecko_orderbook[ticker_id] | ||
except KeyError: | ||
raise HTTPException( | ||
status_code=204, | ||
detail=f"ticker_id not found - check /summary for available pairs." | ||
detail=f"ticker_id not found - check /summary for available pairs.", | ||
) | ||
|
||
|
||
|
||
@router.get("/historical_trades") | ||
async def get_coingecko_trades( | ||
response: Response, | ||
ticker_id: str = None, | ||
) -> dict[str, 'HistoricalCoinGecko']: | ||
await sleep_while_empty_cache('coingecko_historical') | ||
response: Response, | ||
ticker_id: str = Query(None), | ||
type: str = Query(None, regex="^(buy|sell)$"), | ||
) -> Union[ | ||
dict[str, dict[str, list[HistoricalCoinGecko]]], | ||
dict[str, list[HistoricalCoinGecko]], | ||
list[HistoricalCoinGecko], | ||
]: | ||
await sleep_while_empty_cache("coingecko_historical") | ||
|
||
if ticker_id is None: | ||
response.headers["x-total-count"] = str(len(cache.coingecko_historical)) | ||
return cache.coingecko_historical | ||
output = cache.coingecko_historical | ||
if type: | ||
for k, v in output.items(): | ||
output[k] = output[k][type] | ||
return output | ||
try: | ||
return cache.coingecko_historical[ticker_id] | ||
output = cache.coingecko_historical[ticker_id] | ||
if type: | ||
return output[type] | ||
return output | ||
|
||
except KeyError: | ||
raise HTTPException( | ||
status_code=204, | ||
detail=f"ticker_id not found - check /summary for available pairs." | ||
status_code=422, | ||
detail=f"ticker_id not found - check /summary for available pairs.", | ||
) |
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
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
Oops, something went wrong.