Giter Site home page Giter Site logo

aiomql's Introduction

Aiomql - Bot Building Framework and Asynchronous MetaTrader5 Library

GitHub GitHub issues PyPI

Installation

pip install aiomql

Key Features

  • Asynchronous Python Library For MetaTrader5
  • Asynchronous Bot Building Framework
  • Build bots for trading in different financial markets using a bot factory
  • Use threadpool executors to run multiple strategies on multiple instruments concurrently
  • Records and keep track of trades and strategies in csv files.
  • Helper classes for Bot Building. Easy to use and extend.
  • Compatible with pandas-ta.
  • Sample Pre-Built strategies
  • Manage Trading periods using Sessions
  • Risk Management
  • Run multiple bots concurrently with different accounts from the same broker or different brokers

As an asynchronous MetaTrader5 Libray

import asyncio

from aiomql import MetaTrader


async def main():
    mt5 = MetaTrader()
    await mt5.initialize()
    await mt5.login(123456, '*******', 'Broker-Server')
    symbols = await mt5.symbols_get()
    print(symbols)
    
asyncio.run(main())

As a Bot Building FrameWork using a Sample Strategy

The following code is a sample bot that uses the FingerTrap strategy from the library.
It assumes that you have a config file in the same directory as the script.
The config file should be named aiomql.json and should contain the login details for your account.
It demonstrates the use of sessions and risk management.
Sessions allows you to specify the trading period for a strategy. You can also set an action to be performed at the end of a session.
Risk Management allows you to manage the risk of a strategy. You can set the risk per trade and the risk to reward ratio.
The trader class handles the placing of orders and risk management. It is an attribute of the strategy class.

from datetime import time
import logging

from aiomql import Bot, ForexSymbol, FingerTrap, Session, Sessions, RAM, SimpleTrader, TimeFrame

logging.basicConfig(level=logging.INFO)


def build_bot():
    bot = Bot()
    
    # create sessions for the strategies
    london = Session(name='London', start=8, end=time(hour=15, minute=30), on_end='close_all')
    new_york = Session(name='New York', start=13, end=time(hour=20, minute=30))
    tokyo = Session(name='Tokyo', start=23, end=time(hour=6, minute=30))
    
    # configure the parameters and the trader for a strategy
    params = {'trend_candles_count': 500, 'fast_period': 8, 'slow_period': 34, 'etf': TimeFrame.M5}
    gbpusd = ForexSymbol(name='GBPUSD')
    st1 = FingerTrap(symbol=gbpusd, params=params, trader=SimpleTrader(symbol=gbpusd, ram=RAM(risk=0.05, risk_to_reward=2)),
                     sessions=Sessions(london, new_york))
    
    # use the default for the other strategies
    st2 = FingerTrap(symbol=ForexSymbol(name='AUDUSD'), sessions=Sessions(tokyo, new_york))
    st3 = FingerTrap(symbol=ForexSymbol(name='USDCAD'), sessions=Sessions(new_york))
    st4 = FingerTrap(symbol=ForexSymbol(name='USDJPY'), sessions=Sessions(tokyo))
    st5 = FingerTrap(symbol=ForexSymbol(name='EURGBP'), sessions=Sessions(london))
    
    # sessions are not required
    st6 = FingerTrap(symbol=ForexSymbol(name='EURUSD'))
    
    # add strategies to the bot
    bot.add_strategies([st1, st2, st3, st4, st5, st6])
    bot.execute()

# run the bot
build_bot()

API Documentation

see API Documentation for more details

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Support

Feeling generous, like the package or want to see it become a more mature package?

Consider supporting the project by buying me a coffee.
"Buy Me A Coffee"

aiomql's People

Contributors

ichinga-samuel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

aiomql's Issues

import error

I have an error

No Config File Found
Traceback (most recent call last):
File "C:\bot\example.py", line 1, in
from lib.strategies.finger_trap import FingerTrap
File "C:\bot\lib_init_.py", line 1, in
from .strategies.finger_trap import FingerTrap
File "C:\bot\lib\strategies\finger_trap.py", line 5, in
from ..traders.simple_deal_trader import DealTrader
File "C:\bot\lib\traders\simple_deal_trader.py", line 4, in
from aiomql.utils import dict_to_string
File "C:\Users\AS\miniconda3\lib\site-packages\aiomql_init_.py", line 3, in
from .strategy import Strategy
File "C:\Users\AS\miniconda3\lib\site-packages\aiomql\strategy.py", line 10, in
from .candle import Candles, Candle
File "C:\Users\AS\miniconda3\lib\site-packages\aiomql\candle.py", line 2, in
from typing import Type, TypeVar, Generic, Self
ImportError: cannot import name 'Self' from 'typing' (C:\Users\AS\miniconda3\lib\typing.py)

and I fix it to remove Self from candle.py line 2

backtest

do you have backtest in your framwork?

error

hey my friend, I ran this code and that had error

def build_bot():
    bot = Bot()
    st = FingerTrap(symbol=ForexSymbol(name='EURUSD'))
    st1 = FingerTrap(symbol=ForexSymbol(name='GBPUSD'))
    st3 = FingerTrap(symbol=ForexSymbol(name='EURGBP'))
    st4 = FingerTrap(symbol=ForexSymbol(name='EURAUD'))
    bot.add_strategies([st1, st, st3, st4])
    bot.execute()


build_bot()

error :

No Config File Found
No Config File Found
No Config File Found
No Config File Found
EURGBP not a available for this market
EURAUD not a available for this market
EURUSD not a available for this market
GBPUSD not a available for this market
Trading EURUSD
Trading EURAUD
'NoneType' object has no attribute 'data'. Error in FingerTrap.check_trend
'NoneType' object has no attribute 'data'. Error in FingerTrap.check_trend
'NoneType' object has no attribute 'data'. Error in FingerTrap.confirm_trend
'NoneType' object has no attribute 'data'. Error in FingerTrap.confirm_trend
'NoneType' object has no attribute 'data'. Error in FingerTrap.check_trend
'NoneType' object has no attribute 'data'. Error in FingerTrap.check_trend
'NoneType' object has no attribute 'data'. Error in FingerTrap.confirm_trend
'NoneType' object has no attribute 'data'. Error in FingerTrap.confirm_trend

TradeResult

hey friend
I think that you remove TradeResult
but in file /src/aiomql/lib/traders/simple_deal_trader.py
you use it

from .trade_result import TradeResult

 
 result.profit = await self.order.calc_profit()
 await TradeResult(result=result, parameters=params).save()      #line 60

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.