Gr8/mt5connect.py

97 lines
3.1 KiB
Python
Raw Permalink Normal View History

2025-09-10 15:02:31 +03:00
# import MetaTrader5 as mt5
# import smtplib
# from email.mime.text import MIMEText
# from email.mime.multipart import MIMEMultipart
# import json
# import os
# # ----------------------------
# # Load settings
# # ----------------------------
# def load_config(filepath="config.json"):
# if not os.path.exists(filepath):
# raise FileNotFoundError(f"Config file not found: {filepath}")
# with open(filepath, "r") as f:
# return json.load(f)
# # ----------------------------
# # Send email notification
# # ----------------------------
# def send_email(subject, body, smtp_config):
# msg = MIMEMultipart()
# msg['From'] = smtp_config["sender_email"]
# msg['To'] = smtp_config["recipient_email"]
# msg['Subject'] = subject
# msg.attach(MIMEText(body, "plain"))
# try:
# with smtplib.SMTP(smtp_config["smtp_server"], smtp_config["smtp_port"]) as server:
# server.starttls()
# server.login(smtp_config["sender_email"], smtp_config["sender_password"])
# server.send_message(msg)
# print(f"[EMAIL] Sent to {smtp_config['recipient_email']}")
# except Exception as e:
# print(f"[EMAIL ERROR] {e}")
# # ----------------------------
# # Main function
# # ----------------------------
# def main():
# # Load MT5 config
# config = load_config("config.json")
# # Email credentials (edit this)
# smtp_config = {
# "smtp_server": "smtp.gmail.com",
# "smtp_port": 587,
# "sender_email": "ifairvaluegap@gmail.com", # replace
# "sender_password": "pyxv pjnd jftb klnz", # Gmail app password
# "recipient_email": "griffinskimutai@gmail.com" # replace
# }
# # Initialize MT5
# if mt5.initialize(
# path=config["mt5Pathway"],
# login=int(config["username"]),
# password=config["password"],
# server=config["server"]
# ):
# print("[MT5] Connection successful")
# send_email(
# subject="MT5 Connection Successful",
# body=f"MT5 successfully connected to account {config['username']} on server {config['server']}.",
# smtp_config=smtp_config
# )
# else:
# error_msg = f"[MT5] Connection failed: {mt5.last_error()}"
# print(error_msg)
# send_email(
# subject="MT5 Connection Failed",
# body=error_msg,
# smtp_config=smtp_config
# )
# mt5.shutdown()
# # ----------------------------
# # Run script
# # ----------------------------
# if __name__ == "__main__":
# main()
# import MetaTrader5 as mt5
# MT5_PATH = r"C:\Users\wkimu\AppData\Roaming\FundedNext MT5 Terminal\terminal64.exe"
# LOGIN = 31942605
# PASSWORD = "hltGA95##"
# SERVER = "FundedNext-Server3"
# if not mt5.initialize(path=MT5_PATH, login=LOGIN, password=PASSWORD, server=SERVER):
# print("Initialize failed:", mt5.last_error())
# else:
# print("Connected:", mt5.account_info())
# mt5.shutdown()
import os
mt5_path = r"C:\Users\wkimu\AppData\Roaming\FundedNext MT5 Terminal\terminal64.exe"
print("Exists:", os.path.exists(mt5_path))