Skip to main content

MT5 trading gateway for VeighNa Evo

Introduction

This gateway is developed based on MT5 ZeroMQ connection and supports all MT5 trading.

Please notice: only supports netting position mode.

Install

Users can easily install vnpy_mt5 by pip according to the following command.

pip install vnpy_mt5

Also, users can install vnpy_mt5 using the source code. Clone the repository and install as follows:

git clone https://github.com/veighna-global/vnpy_mt5.git && cd vnpy_mt5

python setup.py install

A Simple Example

Save this as run.py.

from vnpy_evo.event import EventEngine
from vnpy_evo.trader.engine import MainEngine
from vnpy_evo.trader.ui import MainWindow, create_qapp

from vnpy_mt5 import Mt5Gateway


def main():
    """主入口函数"""
    qapp = create_qapp()

    event_engine = EventEngine()
    main_engine = MainEngine(event_engine)
    main_engine.add_gateway(Mt5Gateway)

    main_window = MainWindow(main_engine, event_engine)
    main_window.showMaximized()

    qapp.exec()


if __name__ == "__main__":
    main()

MT5 Configuration

  1. Ensure that the MT5 client is installed and logged in with either a demo or a real account (note that the account provided by the broker must be in Netting mode, Hedging mode will not work).

  2. Download the vnpy_mt5 source code from GitHub, enter the vnpy_mt5.vnpy_mt5 directory, and find the Experts, Include, and Libraries folders included there.

  3. From the start menu, launch MetaEditor. In the left side "Navigator", find the MQL5 folder, right-click it and choose "Open Folder". Copy the three folders you previously unzipped into this directory.

  4. Return to MetaEditor, right-click the MQL5 directory again, and click the "Refresh" button from the pop-up menu. Then click the + button next to the Experts directory, find the vnpy_server.mq5 file, double-click to open it, and click the green play button in the top red circle to execute the compilation. The bottom "Errors" information bar will display several compilation messages (ensure there are 0 errors).

  5. MT5 will pop up a dialog for vnpy_server 1.00. In the dialog, first check the "Allow DLL imports" option under the "Dependencies" tab, then switch to the "General" tab, check the "Allow Algorithmic Trading" option, and click the "OK" button. A text prompt for vnpy_server (with very small font) will then appear at the top right corner of the chart, with a small figure icon on the right, which should have a green circle (indicating it is running).

  6. Next, click the "Tools" -> "Options" button on the top menu bar of MT5, open the MT5 Options dialog, switch to the "Expert Advisors" tab, and check all the options below. Finally, remember to click the "OK" button to save the settings. This completes all the configuration work on MT5.

Notes

  1. MT5 prohibits marketable limit orders. For example, when placing a buy order, the order price must be lower than ask_price_1, otherwise, the order will be rejected.
  2. Use market orders for transactions you wish to execute immediately.
  3. For stop orders that you wish to trigger immediately upon conditions being met, MT5 offers server-side stop order execution (supported by Mt5Gateway). Thus, stop orders placed in the CTA strategy will be issued as server-side stop orders.
  4. Be careful not to load these app modules including RpcService, RpcGateway, WebService at startup, which require the use of ZeroMQ, as this will cause ZeroMQ to report errors.

Release files for vnpy-mt5 2024.3.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vnpy-mt5 2024.3.12
File Size Uploaded
vnpy_mt5-2024.3.12.tar.gz 11.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for vnpy-mt5 2024.3.12
File Interpreter ABI Platform
vnpy_mt5-2024.3.12-py3-none-any.whl Python 3 none any Details

Total release size: 21.1 kB

Release files / vnpy_mt5-2024.3.12.tar.gz

Download URL vnpy_mt5-2024.3.12.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d6443184412df5afebddcca5c6fc49fb02fa323a93bc97e43537f5a14889c72d
BLAKE2b-256 checksum
How to use checksums
6d52d1ede6e3ca3f9244eee48ce0505193623d0641ab8763a9fb0112adb64274
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.9

Release files / vnpy_mt5-2024.3.12-py3-none-any.whl

Download URL vnpy_mt5-2024.3.12-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
426322e27b922cd1d2933f7e47ebdb1aa22dda7b475a6942021897c81393e395
BLAKE2b-256 checksum
How to use checksums
12575b99a1ff62cd92cc645935af8c6c84f03853b74f47087a6edb5ab1819ca1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.9

Release history Release notifications | RSS feed

This release

2024.3.12 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page