Compare commits

..

No commits in common. "8dd9bcadb9d14558479018feb401116cb2941463" and "9f751e39dfecafddb79275495416b366a10737c9" have entirely different histories.

5 changed files with 31 additions and 23 deletions

View file

@ -2,10 +2,10 @@
# base layer
FROM python:3.12-alpine as base
ENV VIRTUAL_ENV=/sparkle/.venv \
PATH="/sparkle/.venv/bin:$PATH"
ARG DEV=false
RUN python -m venv $VIRTUAL_ENV
ENV VIRTUAL_ENV=/app/.venv \
PATH="/app/.venv/bin:$PATH"
RUN apk update && \
apk add libpq
@ -26,7 +26,7 @@ RUN pip install poetry==1.8.3
# Install the app
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
@ -34,5 +34,7 @@ COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
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"]

View file

@ -5,18 +5,25 @@ from app.core.websocket import start_finnhub_websocket
router = APIRouter()
@router.get("/search")
async def lookup(query: str, exchange: str | None = None):
"""
API to search for a stock symbol.
"""
params = {
"token": settings.FINNHUB_API_KEY,
"q": query
}
@router.get("/price/{symbol}")
async def get_stock_price(symbol: str):
url = f"https://finnhub.io/api/v1/quote?symbol={symbol}&token={settings.FINNHUB_API_KEY}"
response = requests.get(url)
return response.json()
if exchange:
params["exchange"] = exchange
response = requests.get("https://finnhub.io/api/v1/search", params=params)
return response.json()
@router.get("/start-websocket")
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"}

View file

@ -1,5 +1,4 @@
import os
import finnhub
from dotenv import load_dotenv
load_dotenv()
@ -7,6 +6,5 @@ load_dotenv()
class Settings:
FINNHUB_API_KEY: str = os.getenv("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()

View file

@ -4,12 +4,12 @@ from app.api.v1.routes import stock
from app.ws.routes import trades
app = FastAPI()
app.include_router(stock.router, prefix="/api/v1")
app.include_router(trades.router, prefix="/ws")
@app.on_event("startup")
async def startup_event():
app.include_router(stock.router, prefix="/api/v1")
app.include_router(trades.router, prefix="/ws")
# Code to run on app startup, e.g., connect to WebSocket
pass
@app.on_event("shutdown")

View file

@ -1,6 +1,7 @@
services:
sparkle:
container_name: sparkle
image: sparkle:lastest
build:
context: .
dockerfile: Dockerfile