Fix: Analytics Worker berechnet jetzt alle Tabellen pro Tag
Some checks failed
Deployment / deploy-docker (push) Has been cancelled
Some checks failed
Deployment / deploy-docker (push) Has been cancelled
This commit is contained in:
@@ -173,25 +173,30 @@ class DeutscheBoerseBase(BaseExchange):
|
||||
def _parse_trade_record(self, record: dict) -> Optional[Trade]:
|
||||
"""
|
||||
Parst einen einzelnen Trade-Record aus dem JSON.
|
||||
Deutsche Börse verwendet RTS1/RTS2 Format.
|
||||
|
||||
Wichtige Felder:
|
||||
- TrdDt: Trading Date (YYYY-MM-DD)
|
||||
- TrdTm: Trading Time (HH:MM:SS.ffffff)
|
||||
- ISIN: Instrument Identifier
|
||||
- FinInstrmId.Id: Alternative ISIN Feld
|
||||
- Pric.Pric.MntryVal.Amt: Preis
|
||||
- Qty.Unit: Menge
|
||||
Aktuelles JSON-Format (NDJSON):
|
||||
{
|
||||
"messageId": "posttrade",
|
||||
"sourceName": "GAT",
|
||||
"isin": "US00123Q1040",
|
||||
"lastTradeTime": "2026-01-29T14:07:00.419000000Z",
|
||||
"lastTrade": 10.145,
|
||||
"lastQty": 500.0,
|
||||
"currency": "EUR",
|
||||
...
|
||||
}
|
||||
"""
|
||||
try:
|
||||
# ISIN extrahieren
|
||||
isin = record.get('ISIN') or record.get('FinInstrmId', {}).get('Id', '')
|
||||
# ISIN extrahieren - neues Format verwendet 'isin' lowercase
|
||||
isin = record.get('isin') or record.get('ISIN') or record.get('instrumentId') or record.get('FinInstrmId', {}).get('Id', '')
|
||||
if not isin:
|
||||
return None
|
||||
|
||||
# Preis extrahieren (verschiedene mögliche Pfade)
|
||||
# Preis extrahieren - neues Format: 'lastTrade'
|
||||
price = None
|
||||
if 'Pric' in record:
|
||||
if 'lastTrade' in record:
|
||||
price = float(record['lastTrade'])
|
||||
elif 'Pric' in record:
|
||||
pric = record['Pric']
|
||||
if isinstance(pric, dict):
|
||||
if 'Pric' in pric:
|
||||
@@ -208,9 +213,11 @@ class DeutscheBoerseBase(BaseExchange):
|
||||
if price is None or price <= 0:
|
||||
return None
|
||||
|
||||
# Menge extrahieren
|
||||
# Menge extrahieren - neues Format: 'lastQty'
|
||||
quantity = None
|
||||
if 'Qty' in record:
|
||||
if 'lastQty' in record:
|
||||
quantity = float(record['lastQty'])
|
||||
elif 'Qty' in record:
|
||||
qty = record['Qty']
|
||||
if isinstance(qty, dict):
|
||||
quantity = float(qty.get('Unit', qty.get('Qty', 0)))
|
||||
@@ -220,29 +227,46 @@ class DeutscheBoerseBase(BaseExchange):
|
||||
if quantity is None or quantity <= 0:
|
||||
return None
|
||||
|
||||
# Timestamp extrahieren
|
||||
trd_dt = record.get('TrdDt', '')
|
||||
trd_tm = record.get('TrdTm', '00:00:00')
|
||||
# Timestamp extrahieren - neues Format: 'lastTradeTime'
|
||||
timestamp = None
|
||||
if 'lastTradeTime' in record:
|
||||
ts_str = record['lastTradeTime']
|
||||
# Format: "2026-01-29T14:07:00.419000000Z"
|
||||
# Python kann max 6 Dezimalstellen, also kürzen
|
||||
if '.' in ts_str:
|
||||
parts = ts_str.replace('Z', '').split('.')
|
||||
if len(parts) == 2 and len(parts[1]) > 6:
|
||||
ts_str = parts[0] + '.' + parts[1][:6] + '+00:00'
|
||||
else:
|
||||
ts_str = ts_str.replace('Z', '+00:00')
|
||||
else:
|
||||
ts_str = ts_str.replace('Z', '+00:00')
|
||||
timestamp = datetime.fromisoformat(ts_str)
|
||||
else:
|
||||
# Fallback für altes Format
|
||||
trd_dt = record.get('TrdDt', '')
|
||||
trd_tm = record.get('TrdTm', '00:00:00')
|
||||
|
||||
if not trd_dt:
|
||||
return None
|
||||
|
||||
ts_str = f"{trd_dt}T{trd_tm}"
|
||||
if '.' in ts_str:
|
||||
parts = ts_str.split('.')
|
||||
if len(parts[1]) > 6:
|
||||
ts_str = parts[0] + '.' + parts[1][:6]
|
||||
|
||||
timestamp = datetime.fromisoformat(ts_str)
|
||||
|
||||
if not trd_dt:
|
||||
if timestamp is None:
|
||||
return None
|
||||
|
||||
# Kombiniere Datum und Zeit
|
||||
ts_str = f"{trd_dt}T{trd_tm}"
|
||||
# Entferne Mikrosekunden wenn zu lang
|
||||
if '.' in ts_str:
|
||||
parts = ts_str.split('.')
|
||||
if len(parts[1]) > 6:
|
||||
ts_str = parts[0] + '.' + parts[1][:6]
|
||||
|
||||
# Parse als UTC (Deutsche Börse liefert UTC)
|
||||
timestamp = datetime.fromisoformat(ts_str)
|
||||
if timestamp.tzinfo is None:
|
||||
timestamp = timestamp.replace(tzinfo=timezone.utc)
|
||||
|
||||
return Trade(
|
||||
exchange=self.name,
|
||||
symbol=isin, # Symbol = ISIN
|
||||
symbol=isin,
|
||||
isin=isin,
|
||||
price=price,
|
||||
quantity=quantity,
|
||||
@@ -250,7 +274,7 @@ class DeutscheBoerseBase(BaseExchange):
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error parsing record: {e}")
|
||||
# Debug: Zeige ersten fehlgeschlagenen Record
|
||||
return None
|
||||
|
||||
def _get_last_trading_day(self, from_date: datetime.date) -> datetime.date:
|
||||
|
||||
Reference in New Issue
Block a user