metrapy
A batteries included wrapper around MetaTrader5's python utility.
[+] Wrapper Functions: Get account, tickers, orders, positions, history & deals
[+] Polling utility that uses thread to fetch data periodically
[+] Wrapper utility for placing orders, Maps for MT5 constants
What does it tries to solve?
It tries to make working with Python + MT5 easier, by adding default validation & error messages, parsing responses, and wrapping them appropriately.
Installation
pip install metrapy
Connection
from metrapy.connector import MT5
mpy = MT5({
'server': 'ServerName-Global',
'login': 1876876,
'password': 'yourpass'
})
# Default terminal path location is already provided. However, you can override that with your own.
mpy = MT5({
'path': 'your-terminal-location',
'server': 'ServerName-Global',
'login': 1876876,
'password': 'yourpass'
})
[x] Make sure you have Algorithmic trading enabled in MT5 terminal
Exposed Defaults
timezoneis UTC 0 by default, you can override it with your own.mt5core package is exposed as_mt5property. so, you do not need to import it explicitly.
mt5 = mpy._mt5
- All the mappings are exposed via
mpy.mapsproperty. mpy.connectedprovides connected status- You can pass
magic&debugparameters to the MT5() constructor, for helpful debugging.
Polling Utility
MT5 does not provide for data fetching in realtime mode. So, the options are
- Poll your data, on regular time intervals
- Make a bridge between MQL5 & Python to fetch that data (using sockets, streams or something else)
Support for 1 is available and should be useful enough in most of the cases.
from metrapy.sync import poller
poller(your_func, timeframe, adjusted_secs=0)
- your_func is piece of code to execute at any given timeframe
- supports integer (number of secs), or timeframe (1s, 1M, 2M, 5M, 15M, 30M, 1H, 4H, 1D, 1W)
def start():
print("5 minutes spent")
poller(start, "5M")
poller(start, 100, 2)
It must be noted that code will run at regular time intervals, not from when you start the code. For example, above code will run at HH:05, HH:10, HH:15, HH:20, ...
Release files for metrapy 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| metrapy-0.2.1.tar.gz | 6.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| metrapy-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.0 kB
Release files / metrapy-0.2.1.tar.gz
| Download URL | metrapy-0.2.1.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
46e04a6a00a6ed24ebd87e12e0f53b513fcec45a4aca2a965e778d3c01b1c5e3
|
|
BLAKE2b-256 checksum How to use checksums |
a84c31bcf157c9a704e9c2c8bddc14c7fd751e35fdc4255598dd4fc8c47efd2f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.6.1 CPython/3.11.4 Windows/10
|
Release files / metrapy-0.2.1-py3-none-any.whl
| Download URL | metrapy-0.2.1-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cd0ba358df1bbd821ee975c6d7ccf27a47979b6b88f883636729a9a234794021
|
|
BLAKE2b-256 checksum How to use checksums |
f915e65cfe915cd60742128ec2605f7c0a48a4bbc67d0108e1f79c9c459af12c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.6.1 CPython/3.11.4 Windows/10
|