Skip to main content

This library contains a series of tools to create a trading bot for Forex trading using Metatrader.

Project description

TRADEO - A forex trading framework using MetaTrader

Logo

This library contains a series of tools to create a trading bot for Forex trading. It uses the DWX Connect (modified) to send commands and receive information of MetaTrader. This library is created based on a linux installation of MetaTrader.

Test codecov.io

Installation

Install the library

PIP

pip install tradeo

POETRY

poetry add tradeo

Or you can add manually in pyproject.toml file if you want download it from a specific branch:

tradeo = { git = "git@github.com:sorul/tradeo.git", branch = "develop" }

Configure Metatrader

It is necessary to download the mt_tb_expert.ex5 file and put it in the proper directory. This directory is usually: MetaTrader/MQL5/Experts/Advisors/mt_tb_expert.ex5.

We add the currency pairs in the timeframe we are going to use (in my case it would be 5 minutes). There is the option for the bot to open them automatically, but I do not recommend it.

Activate the expert in any symbol chart, it does not matter which chart you use. But only in one of them.

Usage

  • You can create strategies inheriting tradeo.strategies.strategy.Strategy class. An example of this it would be basic_strategy.py

  • You can customize the handler of metatrader responses inheriting tradeo.event_handlers.event_handler.EventHandler class. An example of this it would be basic_handler.py

  • An example of a main script using this library would be basic_forex.py that inheriting tradeo.executable.executable.Executable.

[!NOTE]
A real project that imports this wonderful library and you can watch for inspiration is sorul_tradingbot

Execution of your project if you import this library

It's necessary to export certain environment variables before running the bot.

# Timezone configuration
export TB_LOCAL_TIMEZONE=Europe/Madrid
export TB_BROKER_TIMEZONE=Etc/GMT-2

# Trading configuration
export TB_SYMBOLS=EURUSD,USDCAD,USDCHF
export TB_ACCOUNT_CURRENCY=EUR
export TB_TIMEFRAME=M5
export TB_LOOKBACK_DAYS=10

# Forex-Client configuration
export TB_CHECK_MESSAGES_THREAD=true
export TB_CHECK_MARKET_DATA_THREAD=false
export TB_CHECK_BAR_DATA_THREAD=false
export TB_CHECK_OPEN_ORDERS_THREAD=true
export TB_CHECK_HISTORICAL_DATA_THREAD=true
export TB_CHECK_HISTORICAL_TRADES_THREAD=false

# Metatrader configuration
export TB_WINE_HOME="${HOME}/.wine"
export TB_MT_TERMINAL_EXE="${TB_WINE_HOME}/drive_c/Program Files/MetaTrader/terminal.exe"
export TB_MT_FILES_PATH="${TB_WINE_HOME}/drive_c/Program Files/MetaTrader/MQL5/Files"

# Logging configuration
export TB_LOG_LEVEL=INFO
export TB_SYSLOG_ADDRESS=logs2.papertrailapp.com
export TB_SYSLOG_PORT=43931

# Telegram configuration
export TB_TG_LOG_LEVEL=INFO
export TB_TG_FOREX_TOKEN=0000000000:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
export TB_TG_FOREX_CHAT_ID=-999999999

The different possibilities for exporting environment variables depend on the user's preference. For example, we can place all the variables in a ".env" file and then execute the command using a Makefile and poetry:

Makefile

run_forex:
	source .env && ~/.local/bin/poetry run run_forex

Edit the crontab (crontab -e):

@reboot cd <path_to_your_project> && make start_metatrader

*/5 * * * 0-5  cd <path_to_your_project> && make run_forex

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tradeo-0.19.0.tar.gz (34.3 kB view details)

Uploaded Source

Built Distribution

tradeo-0.19.0-py3-none-any.whl (40.3 kB view details)

Uploaded Python 3

File details

Details for the file tradeo-0.19.0.tar.gz.

File metadata

  • Download URL: tradeo-0.19.0.tar.gz
  • Upload date:
  • Size: 34.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.18

File hashes

Hashes for tradeo-0.19.0.tar.gz
Algorithm Hash digest
SHA256 7b95999789c11067d32d88c88e434b19c57fb61c21980dc8271e14b1e6fd8510
MD5 c8983f074030047a5e20ba8784be4d55
BLAKE2b-256 4b79b6172cc570cf165db21b507591bd1721da7b6ee6887ebad20da0e4f962ea

See more details on using hashes here.

File details

Details for the file tradeo-0.19.0-py3-none-any.whl.

File metadata

  • Download URL: tradeo-0.19.0-py3-none-any.whl
  • Upload date:
  • Size: 40.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.18

File hashes

Hashes for tradeo-0.19.0-py3-none-any.whl
Algorithm Hash digest
SHA256 37f446c6ce7919f3764e070931098c55fde532b9ae9ffcfa3c0d989dde5ed089
MD5 40297d19e2786305170dc4b9a37145b0
BLAKE2b-256 00d7356c241a7b823736ae90434f11777de1d039f2416660c36c32f742c3d161

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page