storage manager
This commit is contained in:
101
COBY/tests/test_timescale_integration.py
Normal file
101
COBY/tests/test_timescale_integration.py
Normal file
@ -0,0 +1,101 @@
|
||||
"""
|
||||
Test script for TimescaleDB integration.
|
||||
Tests database connection, schema creation, and basic operations.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
from ..config import Config
|
||||
from ..storage.storage_manager import StorageManager
|
||||
from ..models.core import OrderBookSnapshot, TradeEvent, PriceLevel
|
||||
|
||||
# Set up logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def test_timescale_integration():
|
||||
"""Test TimescaleDB integration with basic operations."""
|
||||
|
||||
# Initialize configuration
|
||||
config = Config()
|
||||
|
||||
# Create storage manager
|
||||
storage = StorageManager(config)
|
||||
|
||||
try:
|
||||
# Initialize storage
|
||||
logger.info("Initializing storage manager...")
|
||||
await storage.initialize()
|
||||
|
||||
# Test health check
|
||||
logger.info("Running health check...")
|
||||
health = await storage.health_check()
|
||||
logger.info(f"Health status: {health}")
|
||||
|
||||
# Test schema info
|
||||
logger.info("Getting schema information...")
|
||||
schema_info = await storage.get_system_stats()
|
||||
logger.info(f"Schema info: {schema_info}")
|
||||
|
||||
# Test order book storage
|
||||
logger.info("Testing order book storage...")
|
||||
test_orderbook = OrderBookSnapshot(
|
||||
symbol="BTCUSDT",
|
||||
exchange="binance",
|
||||
timestamp=datetime.utcnow(),
|
||||
bids=[
|
||||
PriceLevel(price=50000.0, size=1.5),
|
||||
PriceLevel(price=49999.0, size=2.0),
|
||||
],
|
||||
asks=[
|
||||
PriceLevel(price=50001.0, size=1.2),
|
||||
PriceLevel(price=50002.0, size=0.8),
|
||||
],
|
||||
sequence_id=12345
|
||||
)
|
||||
|
||||
success = await storage.store_orderbook(test_orderbook)
|
||||
logger.info(f"Order book storage result: {success}")
|
||||
|
||||
# Test trade storage
|
||||
logger.info("Testing trade storage...")
|
||||
test_trade = TradeEvent(
|
||||
symbol="BTCUSDT",
|
||||
exchange="binance",
|
||||
timestamp=datetime.utcnow(),
|
||||
price=50000.5,
|
||||
size=0.1,
|
||||
side="buy",
|
||||
trade_id="test_trade_123"
|
||||
)
|
||||
|
||||
success = await storage.store_trade(test_trade)
|
||||
logger.info(f"Trade storage result: {success}")
|
||||
|
||||
# Test data retrieval
|
||||
logger.info("Testing data retrieval...")
|
||||
latest_orderbook = await storage.get_latest_orderbook("BTCUSDT", "binance")
|
||||
logger.info(f"Latest order book: {latest_orderbook is not None}")
|
||||
|
||||
# Test system stats
|
||||
logger.info("Getting system statistics...")
|
||||
stats = await storage.get_system_stats()
|
||||
logger.info(f"System stats: {stats}")
|
||||
|
||||
logger.info("All tests completed successfully!")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Test failed: {e}")
|
||||
raise
|
||||
|
||||
finally:
|
||||
# Clean up
|
||||
await storage.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(test_timescale_integration())
|
Reference in New Issue
Block a user