Files
aiomql/README.md
T

101 lines
4.1 KiB
Markdown
Raw Normal View History

2024-01-18 02:26:27 +01:00
# Aiomql - Bot Building Framework and Asynchronous MetaTrader5 Library
2023-10-11 09:49:06 +01:00
![GitHub](https://img.shields.io/github/license/ichinga-samuel/aiomql?style=plastic)
![GitHub issues](https://img.shields.io/github/issues/ichinga-samuel/aiomql?style=plastic)
![PyPI](https://img.shields.io/pypi/v/aiomql)
2024-01-18 02:26:27 +01:00
### Installation
2023-10-11 09:49:06 +01:00
```bash
pip install aiomql
```
2024-01-18 02:26:27 +01:00
### Key Features
- Asynchronous Python Library For MetaTrader5
- Asynchronous Bot Building Framework
2023-10-11 09:49:06 +01:00
- Build bots for trading in different financial markets using a bot factory
- Use threadpool executors to run multiple strategies on multiple instruments concurrently
2024-01-18 02:26:27 +01:00
- 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.
2023-10-11 09:49:06 +01:00
- Sample Pre-Built strategies
2024-05-05 00:08:57 +01:00
- Visualization of charts using matplotlib and mplfinance
2024-01-18 02:26:27 +01:00
- Manage Trading periods using Sessions
- Risk Management
- Run multiple bots concurrently with different accounts from the same broker or different brokers
2023-10-11 09:49:06 +01:00
2024-01-18 02:26:27 +01:00
### As an asynchronous MetaTrader5 Libray
2023-10-11 09:49:06 +01:00
```python
import asyncio
2024-01-18 02:26:27 +01:00
from aiomql import MetaTrader
2023-10-11 09:49:06 +01:00
async def main():
2023-10-17 05:21:43 +01:00
mt5 = MetaTrader()
await mt5.initialize()
await mt5.login(123456, '*******', 'Broker-Server')
symbols = await mt5.symbols_get()
print(symbols)
2023-10-11 09:49:06 +01:00
asyncio.run(main())
```
2024-01-18 02:26:27 +01:00
### 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.***
2023-10-11 09:49:06 +01:00
```python
2023-10-17 05:21:43 +01:00
from datetime import time
import logging
2023-10-11 09:49:06 +01:00
2024-01-18 02:26:27 +01:00
from aiomql import Bot, ForexSymbol, FingerTrap, Session, Sessions, RAM, SimpleTrader, TimeFrame
2023-10-11 09:49:06 +01:00
2023-10-17 05:21:43 +01:00
logging.basicConfig(level=logging.INFO)
2023-10-11 09:49:06 +01:00
2023-10-17 05:21:43 +01:00
def build_bot():
bot = Bot()
2024-01-18 02:26:27 +01:00
# 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))
2023-10-17 05:21:43 +01:00
2024-01-18 02:26:27 +01:00
# configure the parameters and the trader for a strategy
2024-02-12 21:09:28 +01:00
params = {'trend_candles_count': 500, 'fast_period': 8, 'slow_period': 34, 'etf': TimeFrame.M5}
2024-01-18 02:26:27 +01:00
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))
2023-10-17 05:21:43 +01:00
2024-01-18 02:26:27 +01:00
# 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'))
2023-10-17 05:21:43 +01:00
# add strategies to the bot
2024-01-18 02:26:27 +01:00
bot.add_strategies([st1, st2, st3, st4, st5, st6])
2023-10-17 05:21:43 +01:00
bot.execute()
2024-01-18 02:26:27 +01:00
# run the bot
2023-10-17 05:21:43 +01:00
build_bot()
2023-10-11 09:49:06 +01:00
```
## API Documentation
2023-10-17 05:21:43 +01:00
see [API Documentation](https://github.com/Ichinga-Samuel/aiomql/tree/master/docs) for more details
2024-01-18 02:26:27 +01:00
## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
## Support
2024-02-12 21:09:28 +01:00
Feeling generous, like the package or want to see it become a more mature package?
2024-01-18 02:26:27 +01:00
Consider supporting the project by buying me a coffee.\
2024-02-12 21:09:28 +01:00
[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/ichingasamuel)