-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.py
More file actions
28 lines (22 loc) · 984 Bytes
/
Copy pathhandler.py
File metadata and controls
28 lines (22 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import logging
from typing import Dict, Any
from core import CryptoEngine
logger = logging.getLogger(__name__)
class TransactionHandler:
"""Handles execution flow for automated crypto trades."""
def __init__(self, engine: CryptoEngine):
self.engine = engine
def process_request(self, data: Dict[str, Any]) -> Dict[str, Any]:
"""Validates and executes trade requests."""
if not self._is_valid(data):
return {"status": "error", "message": "invalid payload"}
try:
result = self.engine.execute(data)
return {"status": "success", "tx_id": result}
except Exception as e:
logger.error(f"Execution failure: {e}")
return {"status": "error", "message": str(e)}
def _is_valid(self, data: Dict[str, Any]) -> bool:
"""Basic structure validation for incoming orders."""
required = ['asset', 'amount', 'side']
return all(key in data for key in required)