dded logging, replaced print() and bare except Exception: continue with except (ValueError, KeyError) + debug log
This commit is contained in:
@@ -1,10 +1,13 @@
|
|||||||
import requests
|
import requests
|
||||||
import csv
|
import csv
|
||||||
import io
|
import io
|
||||||
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import List
|
from typing import List
|
||||||
from .base import BaseExchange, Trade
|
from .base import BaseExchange, Trade
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class LSExchange(BaseExchange):
|
class LSExchange(BaseExchange):
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
@@ -15,23 +18,23 @@ class LSExchange(BaseExchange):
|
|||||||
if include_yesterday:
|
if include_yesterday:
|
||||||
endpoints.append("https://www.ls-x.de/_rpc/json/.lstc/instrument/list/lstctradesyesterday")
|
endpoints.append("https://www.ls-x.de/_rpc/json/.lstc/instrument/list/lstctradesyesterday")
|
||||||
endpoints.append("https://www.ls-x.de/_rpc/json/.lstc/instrument/list/lsxtradesyesterday")
|
endpoints.append("https://www.ls-x.de/_rpc/json/.lstc/instrument/list/lsxtradesyesterday")
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'Referer': 'https://www.ls-tc.de/'
|
'Referer': 'https://www.ls-tc.de/'
|
||||||
}
|
}
|
||||||
|
|
||||||
all_trades = []
|
all_trades = []
|
||||||
for url in endpoints:
|
for url in endpoints:
|
||||||
try:
|
try:
|
||||||
response = requests.get(url, headers=headers)
|
response = requests.get(url, headers=headers)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
f = io.StringIO(response.text)
|
f = io.StringIO(response.text)
|
||||||
# Header: isin;displayName;tradeTime;price;currency;size;orderId
|
# Header: isin;displayName;tradeTime;price;currency;size;orderId
|
||||||
reader = csv.DictReader(f, delimiter=';')
|
reader = csv.DictReader(f, delimiter=';')
|
||||||
|
|
||||||
for item in reader:
|
for item in reader:
|
||||||
try:
|
try:
|
||||||
price = float(item['price'].replace(',', '.'))
|
price = float(item['price'].replace(',', '.'))
|
||||||
@@ -39,11 +42,11 @@ class LSExchange(BaseExchange):
|
|||||||
isin = item['isin']
|
isin = item['isin']
|
||||||
symbol = item['displayName']
|
symbol = item['displayName']
|
||||||
time_str = item['tradeTime']
|
time_str = item['tradeTime']
|
||||||
|
|
||||||
# Format: 2026-01-23T07:30:00.992000Z
|
# Format: 2026-01-23T07:30:00.992000Z
|
||||||
ts_str = time_str.replace('Z', '+00:00')
|
ts_str = time_str.replace('Z', '+00:00')
|
||||||
timestamp = datetime.fromisoformat(ts_str)
|
timestamp = datetime.fromisoformat(ts_str)
|
||||||
|
|
||||||
all_trades.append(Trade(
|
all_trades.append(Trade(
|
||||||
exchange=self.name,
|
exchange=self.name,
|
||||||
symbol=symbol,
|
symbol=symbol,
|
||||||
@@ -52,8 +55,9 @@ class LSExchange(BaseExchange):
|
|||||||
quantity=quantity,
|
quantity=quantity,
|
||||||
timestamp=timestamp
|
timestamp=timestamp
|
||||||
))
|
))
|
||||||
except Exception:
|
except (ValueError, KeyError) as e:
|
||||||
|
logger.debug(f"Fehler beim Parsen einer LS-Zeile: {e}")
|
||||||
continue
|
continue
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error fetching LS data from {url}: {e}")
|
logger.error(f"Fehler beim Abrufen von LS-Daten von {url}: {e}")
|
||||||
return all_trades
|
return all_trades
|
||||||
|
|||||||
Reference in New Issue
Block a user