fixing dashboard
All checks were successful
Deployment / deploy-docker (push) Successful in 16s

This commit is contained in:
Melchior Reimers
2026-01-25 16:51:35 +01:00
parent b9062c5dac
commit bbc5ec76d1

View File

@@ -10,13 +10,19 @@ class DatabaseClient:
self.url = f"http://{host}:{port}/write"
self.auth = (user, password) if user and password else None
def save_trades(self, trades: List[Trade]):
def save_trades(self, trades: List[Trade], batch_size: int = 50000):
if not trades:
return
total_trades = len(trades)
print(f"Saving {total_trades} trades to QuestDB in batches of {batch_size}...")
for i in range(0, total_trades, batch_size):
batch = trades[i:i + batch_size]
lines = []
for trade in trades:
for trade in batch:
# Clean symbols for ILP
try:
symbol = trade.symbol.replace(" ", "\\ ").replace(",", "\\,")
exchange = trade.exchange
@@ -24,6 +30,12 @@ class DatabaseClient:
f"price={trade.price},quantity={trade.quantity} " \
f"{int(trade.timestamp.timestamp() * 1e9)}"
lines.append(line)
except Exception as e:
print(f"Error formating trade {trade}: {e}")
continue
if not lines:
continue
payload = "\n".join(lines) + "\n"
@@ -35,11 +47,13 @@ class DatabaseClient:
auth=self.auth
)
if response.status_code not in [204, 200]:
print(f"Error saving to QuestDB: {response.text}")
print(f"Error saving batch {i//batch_size + 1} to QuestDB: {response.text}")
else:
print(f"Saved batch {i//batch_size + 1} ({len(batch)} trades)")
except Exception as e:
print(f"Could not connect to QuestDB at {self.url}: {e}")
# Fallback: print to console or save to file
self._fallback_save(trades)
self._fallback_save(batch)
def _fallback_save(self, trades: List[Trade]):
# Just log to a file for now if QuestDB is not available