mirror of
https://github.com/ryanamay/sparkle.git
synced 2024-09-20 09:30:35 +00:00
Compare commits
No commits in common. "8dd9bcadb9d14558479018feb401116cb2941463" and "9f751e39dfecafddb79275495416b366a10737c9" have entirely different histories.
8dd9bcadb9
...
9f751e39df
5 changed files with 31 additions and 23 deletions
12
Dockerfile
12
Dockerfile
|
@ -2,10 +2,10 @@
|
||||||
# base layer
|
# base layer
|
||||||
FROM python:3.12-alpine as base
|
FROM python:3.12-alpine as base
|
||||||
|
|
||||||
ENV VIRTUAL_ENV=/sparkle/.venv \
|
ARG DEV=false
|
||||||
PATH="/sparkle/.venv/bin:$PATH"
|
|
||||||
|
|
||||||
RUN python -m venv $VIRTUAL_ENV
|
ENV VIRTUAL_ENV=/app/.venv \
|
||||||
|
PATH="/app/.venv/bin:$PATH"
|
||||||
|
|
||||||
RUN apk update && \
|
RUN apk update && \
|
||||||
apk add libpq
|
apk add libpq
|
||||||
|
@ -26,7 +26,7 @@ RUN pip install poetry==1.8.3
|
||||||
|
|
||||||
# Install the app
|
# Install the app
|
||||||
COPY pyproject.toml poetry.lock ./
|
COPY pyproject.toml poetry.lock ./
|
||||||
RUN poetry install --no-root && rm -rf $POETRY_CACHE_DIR;
|
RUN poetry install dev --no-root && rm -rf $POETRY_CACHE_DIR;
|
||||||
|
|
||||||
FROM base as runtime
|
FROM base as runtime
|
||||||
|
|
||||||
|
@ -34,5 +34,7 @@ COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
|
||||||
|
|
||||||
COPY app ./app
|
COPY app ./app
|
||||||
|
|
||||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
WORKDIR /sparkle/app
|
||||||
|
|
||||||
|
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||||
|
|
||||||
|
|
|
@ -5,18 +5,25 @@ from app.core.websocket import start_finnhub_websocket
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.get("/search")
|
@router.get("/price/{symbol}")
|
||||||
async def lookup(query: str, exchange: str | None = None):
|
async def get_stock_price(symbol: str):
|
||||||
"""
|
url = f"https://finnhub.io/api/v1/quote?symbol={symbol}&token={settings.FINNHUB_API_KEY}"
|
||||||
API to search for a stock symbol.
|
response = requests.get(url)
|
||||||
"""
|
return response.json()
|
||||||
params = {
|
|
||||||
"token": settings.FINNHUB_API_KEY,
|
|
||||||
"q": query
|
|
||||||
}
|
|
||||||
|
|
||||||
if exchange:
|
|
||||||
params["exchange"] = exchange
|
|
||||||
|
|
||||||
response = requests.get("https://finnhub.io/api/v1/search", params=params)
|
@router.get("/start-websocket")
|
||||||
return response.json()
|
async def start_websocket():
|
||||||
|
"""
|
||||||
|
Endpoint to start the Finnhub WebSocket connection.
|
||||||
|
"""
|
||||||
|
start_finnhub_websocket()
|
||||||
|
return {"message": "WebSocket connection started"}
|
||||||
|
|
||||||
|
@router.get("/stop-websocket")
|
||||||
|
async def stop_websocket():
|
||||||
|
"""
|
||||||
|
Endpoint to stop the Finnhub WebSocket connection.
|
||||||
|
"""
|
||||||
|
# Code to stop the WebSocket connection
|
||||||
|
return {"message": "WebSocket connection stopped"}
|
|
@ -1,5 +1,4 @@
|
||||||
import os
|
import os
|
||||||
import finnhub
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
@ -7,6 +6,5 @@ load_dotenv()
|
||||||
class Settings:
|
class Settings:
|
||||||
FINNHUB_API_KEY: str = os.getenv("FINNHUB_API_KEY")
|
FINNHUB_API_KEY: str = os.getenv("FINNHUB_API_KEY")
|
||||||
FINNHUB_WEBSOCKET_URL: str = "wss://ws.finnhub.io?token=" + FINNHUB_API_KEY
|
FINNHUB_WEBSOCKET_URL: str = "wss://ws.finnhub.io?token=" + FINNHUB_API_KEY
|
||||||
client: finnhub.Client = finnhub.Client(api_key=FINNHUB_API_KEY)
|
|
||||||
|
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
|
|
|
@ -4,12 +4,12 @@ from app.api.v1.routes import stock
|
||||||
from app.ws.routes import trades
|
from app.ws.routes import trades
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
app.include_router(stock.router, prefix="/api/v1")
|
||||||
|
app.include_router(trades.router, prefix="/ws")
|
||||||
|
|
||||||
@app.on_event("startup")
|
@app.on_event("startup")
|
||||||
async def startup_event():
|
async def startup_event():
|
||||||
app.include_router(stock.router, prefix="/api/v1")
|
# Code to run on app startup, e.g., connect to WebSocket
|
||||||
app.include_router(trades.router, prefix="/ws")
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@app.on_event("shutdown")
|
@app.on_event("shutdown")
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
services:
|
services:
|
||||||
sparkle:
|
sparkle:
|
||||||
container_name: sparkle
|
container_name: sparkle
|
||||||
|
image: sparkle:lastest
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
|
|
Loading…
Reference in a new issue