aboutsummaryrefslogtreecommitdiff
path: root/server/api/market.py
diff options
context:
space:
mode:
Diffstat (limited to 'server/api/market.py')
-rw-r--r--server/api/market.py33
1 files changed, 22 insertions, 11 deletions
diff --git a/server/api/market.py b/server/api/market.py
index 1d17857..7aaaa29 100644
--- a/server/api/market.py
+++ b/server/api/market.py
@@ -7,28 +7,34 @@ from db import SessionLocal
router = APIRouter()
-# Only allow these markets
SUPPORTED_MARKETS: Dict[str, str] = {
"ISONE": "ISONE",
"MISO": "MISO",
"NYISO": "NYISO",
}
+
def check_market_supported(market: str):
market = market.upper()
if market not in SUPPORTED_MARKETS:
- raise HTTPException(status_code=400, detail=f"Unsupported market '{market}'. Supported: {list(SUPPORTED_MARKETS.keys())}")
+ raise HTTPException(
+ status_code=400,
+ detail=f"Unsupported market '{market}'. Supported: {list(SUPPORTED_MARKETS.keys())}",
+ )
return market
+
@router.get("/day-ahead", response_model=List[MarketData])
def get_day_ahead_data(market: str = Query("ISONE")):
db: Session = SessionLocal()
market = check_market_supported(market)
- records = db.query(MarketDataDB)\
- .filter(MarketDataDB.market == market, MarketDataDB.type == "DAYAHEAD")\
- .order_by(MarketDataDB.timestamp)\
+ records = (
+ db.query(MarketDataDB)
+ .filter(MarketDataDB.market == market, MarketDataDB.type == "DAYAHEAD")
+ .order_by(MarketDataDB.timestamp)
.all()
+ )
db.close()
return [
@@ -38,23 +44,27 @@ def get_day_ahead_data(market: str = Query("ISONE")):
energy=r.energy,
congestion=r.congestion,
loss=r.loss,
- ) for r in records
+ )
+ for r in records
]
+
@router.get("/real-time", response_model=List[MarketData])
def get_real_time_data(market: str = Query("ISONE")):
db: Session = SessionLocal()
market = check_market_supported(market)
start_time = datetime.utcnow() - timedelta(days=1)
- records = db.query(MarketDataDB)\
+ records = (
+ db.query(MarketDataDB)
.filter(
MarketDataDB.market == market,
MarketDataDB.type == "REALTIME",
- MarketDataDB.timestamp >= start_time
- )\
- .order_by(MarketDataDB.timestamp)\
+ MarketDataDB.timestamp >= start_time,
+ )
+ .order_by(MarketDataDB.timestamp)
.all()
+ )
db.close()
return [
@@ -64,5 +74,6 @@ def get_real_time_data(market: str = Query("ISONE")):
energy=r.energy,
congestion=r.congestion,
loss=r.loss,
- ) for r in records
+ )
+ for r in records
]