Migrate exchange app to centralized aitbc package utilities
- Migrate 2 files from logging to aitbc.get_logger - health_monitor.py, real_exchange_integration.py - Remove logging.basicConfig() from both files - Migrate 3 files with hardcoded paths to use DATA_DIR constant - simple_exchange_api.py, scripts/seed_market.py, database.py
This commit is contained in:
@@ -7,10 +7,11 @@ import os
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker, Session
|
||||
from sqlalchemy.pool import StaticPool
|
||||
from aitbc.constants import DATA_DIR
|
||||
from models import Base
|
||||
|
||||
# Database configuration
|
||||
DATABASE_URL = os.getenv("EXCHANGE_DATABASE_URL", "sqlite:////var/lib/aitbc/data/exchange/exchange.db")
|
||||
DATABASE_URL = os.getenv("EXCHANGE_DATABASE_URL", f"sqlite:///{DATA_DIR}/data/exchange/exchange.db")
|
||||
|
||||
# Create engine
|
||||
if DATABASE_URL.startswith("sqlite"):
|
||||
|
||||
@@ -10,13 +10,11 @@ from datetime import datetime, timedelta
|
||||
from typing import Dict, List, Optional, Any
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
import logging
|
||||
|
||||
from aitbc import get_logger
|
||||
from real_exchange_integration import exchange_manager, ExchangeStatus, ExchangeHealth
|
||||
|
||||
# Setup logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
logger = get_logger(__name__)
|
||||
|
||||
class FailoverStrategy(str, Enum):
|
||||
"""Failover strategies"""
|
||||
|
||||
@@ -12,11 +12,10 @@ from datetime import datetime, timedelta
|
||||
from typing import Dict, List, Optional, Any, Tuple
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
import logging
|
||||
|
||||
# Setup logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
from aitbc import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
class ExchangeStatus(str, Enum):
|
||||
"""Exchange connection status"""
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
|
||||
import sqlite3
|
||||
from datetime import datetime
|
||||
from aitbc.constants import DATA_DIR
|
||||
|
||||
def seed_initial_price():
|
||||
"""Create initial trades to establish market price"""
|
||||
|
||||
import os
|
||||
db_path = os.getenv("EXCHANGE_DATABASE_URL", "sqlite:////var/lib/aitbc/data/exchange/exchange.db").replace("sqlite:///", "")
|
||||
db_path = os.getenv("EXCHANGE_DATABASE_URL", f"sqlite:///{DATA_DIR}/data/exchange/exchange.db").replace("sqlite://///", "")
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
|
||||
|
||||
@@ -9,12 +9,13 @@ from datetime import datetime
|
||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
import urllib.parse
|
||||
import random
|
||||
from aitbc.constants import DATA_DIR
|
||||
|
||||
# Database setup
|
||||
def get_db_path():
|
||||
"""Get database path and ensure directory exists"""
|
||||
import os
|
||||
db_path = os.getenv("EXCHANGE_DATABASE_URL", "sqlite:////var/lib/aitbc/data/exchange/exchange.db").replace("sqlite:///", "")
|
||||
db_path = os.getenv("EXCHANGE_DATABASE_URL", f"sqlite:///{DATA_DIR}/data/exchange/exchange.db").replace("sqlite://///", "")
|
||||
|
||||
# Create directory if it doesn't exist
|
||||
db_dir = os.path.dirname(db_path)
|
||||
|
||||
Reference in New Issue
Block a user