Initial commit: Mad Turtle v2.0 ML EA for XAUUSD H1 with Python inference server and MQL5 EA
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
"""
|
||||
Fetch real XAUUSD H1 data from Yahoo Finance (GC=F gold futures).
|
||||
Saves to CSV for training pipeline.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
import pandas as pd
|
||||
import yfinance as yf
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
DATA_DIR = ROOT / "data"
|
||||
DATA_DIR.mkdir(exist_ok=True)
|
||||
OUT_CSV = DATA_DIR / "xauusd_h1.csv"
|
||||
|
||||
|
||||
def fetch_xauusd(period: str = "2y", interval: str = "1h") -> pd.DataFrame:
|
||||
ticker = yf.Ticker("GC=F")
|
||||
df = ticker.history(period=period, interval=interval, auto_adjust=True)
|
||||
if df.empty:
|
||||
raise RuntimeError("No data returned from Yahoo Finance for GC=F")
|
||||
df.index = df.index.tz_convert("UTC").tz_localize(None)
|
||||
df.index.name = "datetime"
|
||||
df.reset_index(inplace=True)
|
||||
df.rename(columns={
|
||||
"Open": "open", "High": "high", "Low": "low",
|
||||
"Close": "close", "Volume": "volume"
|
||||
}, inplace=True)
|
||||
df = df[["datetime", "open", "high", "low", "close", "volume"]].copy()
|
||||
df.dropna(subset=["open", "high", "low", "close"], inplace=True)
|
||||
df["volume"] = df["volume"].fillna(0)
|
||||
return df
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--period", default="2y", help="yfinance period (1y, 2y, max)")
|
||||
parser.add_argument("--interval", default="1h", help="yfinance interval (1h, 4h, 1d)")
|
||||
parser.add_argument("--out", default=str(OUT_CSV))
|
||||
args = parser.parse_args()
|
||||
|
||||
print(f"Fetching XAUUSD (GC=F) {args.interval} for {args.period}...")
|
||||
df = fetch_xauusd(args.period, args.interval)
|
||||
df.to_csv(args.out, index=False)
|
||||
print(f"Saved {len(df)} rows -> {args.out}")
|
||||
print(df.tail(3).to_string(index=False))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user