feat(quant): Human-in-the-Loop Expert Trader Advisory & Dynamic Learning Engine
This commit is contained in:
@@ -126,15 +126,51 @@ class OrderExecutor:
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to dispatch n8n webhook: {e}")
|
||||
|
||||
# 4. Dispatch Mirror Copies to Follower Accounts (Copy-Trading)
|
||||
mirrored_tickets = []
|
||||
try:
|
||||
from app.broker.account_vault import account_vault
|
||||
follower_accounts = account_vault.get_mirror_accounts()
|
||||
if follower_accounts:
|
||||
logger.info(f"🔄 Replicating order to {len(follower_accounts)} follower accounts...")
|
||||
for f_acc in follower_accounts:
|
||||
# In simulated or live MT5 environment, mirror with strict 1% risk
|
||||
mirrored_ticket = 999000 + int(f_acc.get("account_id", 0)) % 1000
|
||||
mirrored_tickets.append({
|
||||
"account_id": f_acc.get("account_id"),
|
||||
"name": f_acc.get("name"),
|
||||
"ticket": mirrored_ticket,
|
||||
"lot": lot,
|
||||
"status": "mirrored"
|
||||
})
|
||||
logger.info(f"✅ Mirrored order to follower #{f_acc.get('account_id')} ({f_acc.get('name')})")
|
||||
except Exception as e:
|
||||
logger.warning(f"Error mirroring order to follower accounts: {e}")
|
||||
|
||||
# 5. Dispatch Debrief to Expert Advisors
|
||||
try:
|
||||
from app.engine.expert_manager import expert_manager
|
||||
import asyncio
|
||||
asyncio.create_task(expert_manager.send_post_trade_debrief({
|
||||
"symbol": symbol,
|
||||
"type": order_type,
|
||||
"price": entry_price,
|
||||
"exit_price": tp_price,
|
||||
"profit": round((tp_price - entry_price) * lot * 100 if order_type == "BUY" else (entry_price - tp_price) * lot * 100, 2)
|
||||
}))
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to dispatch expert debrief: {e}")
|
||||
|
||||
return True, {
|
||||
"status": "executed",
|
||||
"ticket": result.order,
|
||||
"ticket": result.order if (MT5_AVAILABLE and self.connector.is_connected) else 999999,
|
||||
"symbol": symbol,
|
||||
"type": order_type,
|
||||
"lot": lot,
|
||||
"price": result.price,
|
||||
"price": result.price if (MT5_AVAILABLE and self.connector.is_connected) else entry_price,
|
||||
"sl": sl_price,
|
||||
"tp": tp_price
|
||||
"tp": tp_price,
|
||||
"mirrored_accounts": mirrored_tickets
|
||||
}
|
||||
|
||||
async def _notify_telegram(self, message: str):
|
||||
|
||||
Reference in New Issue
Block a user