feat: move daemon to docker with daily schedule and deduplication
All checks were successful
Deployment / deploy-docker (push) Successful in 17s
All checks were successful
Deployment / deploy-docker (push) Successful in 17s
This commit is contained in:
@@ -4,10 +4,11 @@ from typing import List
|
||||
from ..exchanges.base import Trade
|
||||
|
||||
class DatabaseClient:
|
||||
def __init__(self, host: str = "localhost", port: int = 9000):
|
||||
def __init__(self, host: str = "localhost", port: int = 9000, user: str = None, password: str = None):
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.url = f"http://{host}:{port}/write"
|
||||
self.auth = (user, password) if user and password else None
|
||||
|
||||
def save_trades(self, trades: List[Trade]):
|
||||
if not trades:
|
||||
@@ -15,10 +16,6 @@ class DatabaseClient:
|
||||
|
||||
lines = []
|
||||
for trade in trades:
|
||||
# QuestDB Influx Line Protocol format:
|
||||
# table_name,tag1=val1,tag2=val2 field1=val1,field2=val2 timestamp
|
||||
# We use microseconds for timestamp (nanoseconds is standard for ILP)
|
||||
|
||||
# Clean symbols for ILP
|
||||
symbol = trade.symbol.replace(" ", "\\ ").replace(",", "\\,")
|
||||
exchange = trade.exchange
|
||||
@@ -31,8 +28,13 @@ class DatabaseClient:
|
||||
payload = "\n".join(lines) + "\n"
|
||||
|
||||
try:
|
||||
response = requests.post(self.url, data=payload, params={'precision': 'ns'})
|
||||
if response.status_code != 204:
|
||||
response = requests.post(
|
||||
self.url,
|
||||
data=payload,
|
||||
params={'precision': 'ns'},
|
||||
auth=self.auth
|
||||
)
|
||||
if response.status_code not in [204, 200]:
|
||||
print(f"Error saving to QuestDB: {response.text}")
|
||||
except Exception as e:
|
||||
print(f"Could not connect to QuestDB at {self.url}: {e}")
|
||||
|
||||
Reference in New Issue
Block a user