Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frame work not working #11

Open
5oclockshadow opened this issue Dec 2, 2024 · 0 comments
Open

Frame work not working #11

5oclockshadow opened this issue Dec 2, 2024 · 0 comments

Comments

@5oclockshadow
Copy link

Hey man me again, Ill try to be quick. im having issues connecting and using strategy... i did somedigging but im not that knowledgeable to figure out whats wrong and how to fix. ive tried the aiomql.json file in same folder as main and that doesnt work... below i force login into the account with same credentials as mt5 lib directly twice. please help. mt5 login fin your framework doesnt with the same cred pulled from env...

`from aiomql import *
import MetaTrader5 as mt5
import asyncio
import pandas as pd
import os
from dotenv import load_dotenv

authorized = mt5.login(login=os.getenv('login'), password=os.getenv('password'), server=os.getenv('server'))

load_dotenv() # This will load environment variables from the .env file
password = os.getenv('password')
login = os.getenv('login')
server = os.getenv('server')

instances

bot = Bot()
acc = Account()
config = Config()

mt5.initialize()
mt5.login(login=login, password=password, server=server)
print(mt5.terminal_info())
print(mt5.version())
acc.login = os.getenv('login')
acc.password = os.getenv('password')
acc.server = os.getenv('server')

async def main():
acc = Account() # Initialize the Account instance
# populate acc by env file
acc.login = os.getenv('login')
acc.password = os.getenv('password')
acc.server = os.getenv('server')
# await acc.connected()
# print("Connected to account:", acc.connected)
# await acc.refresh()

# Perform login before entering the context
try:
    print("--- MetaTrader5 Section ---")  # Label for MetaTrader5
    # Connect to MetaTrader 5
    if not mt5.initialize():
        print("initialize() failed")
        mt5.shutdown()
        return
    # Request connection status and parameters
    print(mt5.terminal_info())
    print(mt5.version())
    # Connect to the trade account
    authorized = mt5.login(login=login, password=password, server=server)
    print("authorized=", authorized)
    if authorized:
        account_info = mt5.account_info()
        if account_info is not None:
            print(account_info)
            account_info_dict = account_info._asdict()
            df = pd.DataFrame(list(account_info_dict.items()), columns=['property', 'value'])
            print(df)
    else:
        print("Failed to connect to trade account.")
        mt5.shutdown()
        return

    print("--- aiomql Section ---")  # Label for aiomql
    # Use the account context
    acc = Account()
    acc.login = os.getenv('login') 
    acc.password = password=os.getenv('password')
    acc.server = server=os.getenv('server')
    
    
    async with acc:
        acc.mt5.login_sync(login=os.getenv('login'), password=os.getenv('password'), server=os.getenv('server'))
        print("Connected to account:", acc.connected)
        # Perform operations here
        await acc.refresh()
        print("Account refreshed!")

except Exception as e:
    print(f"An exception occurred: {e}")
finally:
    mt5.shutdown()
    print("MetaTrader 5 shutdown")

Run the async function

asyncio.run(main())`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant