0% found this document useful (0 votes)
4 views1 page

MT5 Connection Script

Uploaded by

dkrajkumar90
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

MT5 Connection Script

Uploaded by

dkrajkumar90
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import MetaTrader5 as mt5

# Step 1: Initialize connection


if not mt5.initialize():
print("❌ MT5 Initialization failed!")
quit()
else:
print("✅ Connected to MT5")

# Step 2: Show login & account info


account_info = mt5.account_info()
if account_info:
print(f"🧾 Logged in as: {account_info.login}, Balance: {account_info.balance}")
else:
print("⚠️ Unable to fetch account info")

# Step 3: Get all visible symbols from Market Watch


symbols = mt5.symbols_get()
print(f"\n📊 Live prices for {len(symbols)} symbols:\n")

for sym in symbols[:20]: # Limit to 20 symbols for clean output


tick = mt5.symbol_info_tick(sym.name)
if tick:
print(f"{sym.name}: Bid = {tick.bid}, Ask = {tick.ask}")
else:
print(f"{sym.name}: ❌ No tick data")

# Step 4: Shutdown MT5 connection


mt5.shutdown()

You might also like