mirror of
https://github.com/quachtinh113/main-fx.git
synced 2026-08-24 08:08:30 +00:00
push code update
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
"""CrewAI trading package."""
|
||||
|
||||
from .crew import TradingCrew
|
||||
|
||||
__all__ = ["TradingCrew"]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,23 @@
|
||||
market_data_agent:
|
||||
role: >
|
||||
Market Data Operator
|
||||
goal: >
|
||||
Đảm bảo dữ liệu thị trường sẵn sàng và nhất quán trước khi phân tích tín hiệu.
|
||||
backstory: >
|
||||
Bạn phụ trách pipeline dữ liệu cho hệ thống giao dịch định lượng.
|
||||
|
||||
signal_agent:
|
||||
role: >
|
||||
Quant Signal Analyst
|
||||
goal: >
|
||||
Chạy chiến lược smart money + ADX/ATR + RSI MTF để tạo tín hiệu giao dịch.
|
||||
backstory: >
|
||||
Bạn chuyên đánh giá tín hiệu đa khung thời gian và lọc điều kiện thị trường.
|
||||
|
||||
reporting_agent:
|
||||
role: >
|
||||
Trading Reporter
|
||||
goal: >
|
||||
Tổng hợp kết quả backtest/live thành báo cáo ngắn gọn, dễ hành động.
|
||||
backstory: >
|
||||
Bạn chuyển kết quả kỹ thuật thành insight rõ ràng cho vận hành.
|
||||
@@ -0,0 +1,23 @@
|
||||
prepare_data_task:
|
||||
description: >
|
||||
Kiểm tra dữ liệu đã có cho symbol {symbol} ở các timeframe M15/H1/H4,
|
||||
xác nhận file parquet tồn tại và có thể dùng cho pipeline tín hiệu.
|
||||
expected_output: >
|
||||
Danh sách file hợp lệ kèm trạng thái sẵn sàng dữ liệu.
|
||||
agent: market_data_agent
|
||||
|
||||
run_signal_task:
|
||||
description: >
|
||||
Chạy chiến lược SmartMoneyADXATRRSIStrategy bằng dữ liệu đã chuẩn bị
|
||||
để sinh tín hiệu giao dịch mới nhất cho {symbol}.
|
||||
expected_output: >
|
||||
Bảng kết quả có strategy_signal, entry_mode, confidence cho nến mới nhất.
|
||||
agent: signal_agent
|
||||
|
||||
report_task:
|
||||
description: >
|
||||
Tóm tắt tín hiệu cuối cùng thành báo cáo vận hành: BUY/SELL/HOLD,
|
||||
độ tin cậy và ngữ cảnh thị trường.
|
||||
expected_output: >
|
||||
Báo cáo ngắn gọn dạng văn bản cho người vận hành.
|
||||
agent: reporting_agent
|
||||
@@ -0,0 +1,68 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from crewai import Agent, Crew, Process, Task
|
||||
from crewai.project import CrewBase, agent, crew, task
|
||||
|
||||
from .tools.trading_tools import render_signal_report, run_latest_signal
|
||||
|
||||
|
||||
@CrewBase
|
||||
class TradingCrew:
|
||||
"""CrewAI pipeline cho hệ thống tín hiệu trading."""
|
||||
|
||||
agents_config = "config/agents.yaml"
|
||||
tasks_config = "config/tasks.yaml"
|
||||
|
||||
@agent
|
||||
def market_data_agent(self) -> Agent:
|
||||
return Agent(
|
||||
config=self.agents_config["market_data_agent"],
|
||||
verbose=True,
|
||||
)
|
||||
|
||||
@agent
|
||||
def signal_agent(self) -> Agent:
|
||||
return Agent(
|
||||
config=self.agents_config["signal_agent"],
|
||||
verbose=True,
|
||||
)
|
||||
|
||||
@agent
|
||||
def reporting_agent(self) -> Agent:
|
||||
return Agent(
|
||||
config=self.agents_config["reporting_agent"],
|
||||
verbose=True,
|
||||
)
|
||||
|
||||
@task
|
||||
def prepare_data_task(self) -> Task:
|
||||
return Task(
|
||||
config=self.tasks_config["prepare_data_task"],
|
||||
)
|
||||
|
||||
@task
|
||||
def run_signal_task(self) -> Task:
|
||||
latest = run_latest_signal(symbol="EURUSDm")
|
||||
report = render_signal_report(latest)
|
||||
return Task(
|
||||
config=self.tasks_config["run_signal_task"],
|
||||
description=f"{self.tasks_config['run_signal_task']['description']}\n\n{report}",
|
||||
)
|
||||
|
||||
@task
|
||||
def report_task(self) -> Task:
|
||||
latest = run_latest_signal(symbol="EURUSDm")
|
||||
report = render_signal_report(latest)
|
||||
return Task(
|
||||
config=self.tasks_config["report_task"],
|
||||
description=f"{self.tasks_config['report_task']['description']}\n\n{report}",
|
||||
)
|
||||
|
||||
@crew
|
||||
def crew(self) -> Crew:
|
||||
return Crew(
|
||||
agents=self.agents,
|
||||
tasks=self.tasks,
|
||||
process=Process.sequential,
|
||||
verbose=True,
|
||||
)
|
||||
@@ -0,0 +1,13 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from .crew import TradingCrew
|
||||
|
||||
|
||||
def run(symbol: str = "EURUSDm"):
|
||||
crew = TradingCrew().crew()
|
||||
return crew.kickoff(inputs={"symbol": symbol})
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
result = run("EURUSDm")
|
||||
print(result)
|
||||
BIN
Binary file not shown.
@@ -0,0 +1,53 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
import pandas as pd
|
||||
|
||||
from src.strategies.smart_money_adx_atr_rsi_strategy import SmartMoneyADXATRRSIStrategy
|
||||
|
||||
|
||||
def load_processed(symbol: str, timeframe: str, suffix: str = "clean") -> pd.DataFrame:
|
||||
path = Path(f"data/processed/{symbol}/{timeframe}/{symbol}_{timeframe}_{suffix}.parquet")
|
||||
if not path.exists():
|
||||
raise FileNotFoundError(f"Missing file: {path}")
|
||||
|
||||
df = pd.read_parquet(path)
|
||||
if "timestamp" in df.columns:
|
||||
df["timestamp"] = pd.to_datetime(df["timestamp"], utc=True)
|
||||
df = df.set_index("timestamp")
|
||||
return df.sort_index()
|
||||
|
||||
|
||||
def run_latest_signal(symbol: str = "EURUSDm") -> pd.DataFrame:
|
||||
df_m15 = load_processed(symbol, "M15")
|
||||
df_h1 = load_processed(symbol, "H1")
|
||||
df_h4 = load_processed(symbol, "H4")
|
||||
|
||||
strategy = SmartMoneyADXATRRSIStrategy(
|
||||
require_rsi_for_range=False,
|
||||
require_rsi_for_trend=True,
|
||||
)
|
||||
result = strategy.run(df_m15, df_h1, df_h4)
|
||||
return result.tail(1).copy()
|
||||
|
||||
|
||||
def render_signal_report(latest: pd.DataFrame) -> str:
|
||||
row = latest.iloc[0]
|
||||
signal = int(row.get("strategy_signal", 0))
|
||||
|
||||
side = "HOLD"
|
||||
if signal == 1:
|
||||
side = "BUY"
|
||||
elif signal == -1:
|
||||
side = "SELL"
|
||||
|
||||
confidence = float(row.get("confidence", 0.0))
|
||||
regime = row.get("regime", "unknown")
|
||||
entry_mode = row.get("entry_mode", "none")
|
||||
|
||||
return (
|
||||
f"Signal: {side}\n"
|
||||
f"Regime: {regime}\n"
|
||||
f"Entry mode: {entry_mode}\n"
|
||||
f"Confidence: {confidence:.2f}"
|
||||
)
|
||||
Reference in New Issue
Block a user