Skip to content

Commit 7001e59

Browse files
committed
fix parts of broken part
1 parent 087ecff commit 7001e59

File tree

8 files changed

+266
-62
lines changed

8 files changed

+266
-62
lines changed

.github/workflows/test-pytest.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Test | Pytest
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: ['*']
7+
8+
jobs:
9+
pytest:
10+
runs-on: windows-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Install uv and set the python version
17+
uses: astral-sh/setup-uv@v5
18+
with:
19+
python-version: "3.11"
20+
21+
- name: Install the project
22+
run: uv sync --locked --group dev
23+
24+
- name: Run tests with coverage
25+
run: |
26+
pytest \
27+
-k . \
28+
--cov=mqpy \
29+
--cov-append \
30+
--cov-report=term-missing:skip-covered \
31+
--junitxml=pytest.xml \
32+
-x | tee pytest-coverage.txt
33+
34+
- name: Add coverage summary to GitHub summary
35+
run: |
36+
cat summary.md >> $GITHUB_STEP_SUMMARY

example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
This example demonstrates a Moving Average Crossover strategy.
44
"""
55

6-
from mqpy.src.rates import Rates
7-
from mqpy.src.tick import Tick
8-
from mqpy.src.trade import Trade
6+
from mqpy.rates import Rates
7+
from mqpy.tick import Tick
8+
from mqpy.trade import Trade
99

1010
# Initialize the trading strategy
1111
trade = Trade(
@@ -45,7 +45,7 @@
4545
is_cross_below = short_ma < long_ma and current_tick.last < short_ma
4646

4747
# Execute trading positions based on signals
48-
trade.open_position(is_cross_above, is_cross_below, "Moving Average Crossover Strategy")
48+
trade.open_position(should_buy=is_cross_above, should_sell=is_cross_below, comment="Moving Average Crossover Strategy")
4949

5050
prev_tick_time = current_tick.time_msc
5151

mqpy/trade.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def select_symbol(self) -> None:
113113
Returns:
114114
None
115115
"""
116-
Mt5.symbol_select(self.symbol, enable=True)
116+
Mt5.symbol_select(self.symbol, True)
117117

118118
def prepare_symbol(self) -> None:
119119
"""Prepare the trading symbol for opening positions.
@@ -130,7 +130,7 @@ def prepare_symbol(self) -> None:
130130

131131
if not symbol_info.visible:
132132
logger.warning(f"The {self.symbol} is not visible, needed to be switched on.")
133-
if not Mt5.symbol_select(self.symbol, enable=True):
133+
if not Mt5.symbol_select(self.symbol, True):
134134
logger.error(
135135
f"The expert advisor {self.expert_name} failed in select the symbol {self.symbol}, turning off."
136136
)
@@ -240,7 +240,7 @@ def open_sell_position(self, comment: str = "") -> None:
240240
result = Mt5.order_send(request)
241241
self.request_result(price, result)
242242

243-
def request_result(self, price: float, result: Mt5.TradeResult) -> None:
243+
def request_result(self, price: float, result: int) -> None:
244244
"""Process the result of a trading request.
245245
246246
Args:

pyproject.toml

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,27 @@
11
[build-system]
22
requires = [
3-
"setuptools",
3+
"setuptools>=61.0",
44
"wheel",
55
]
66
build-backend = "setuptools.build_meta"
77

88
[project]
99
name = "mqpy"
1010
authors = [
11-
{name = "Joao Euko"}
11+
{email = "joao@example.com", name = "Joao Euko"},
1212
]
1313
version = "v0.6.9"
1414
description = "I developed this library to simplify the process of creating an Expert Advisor in MQL5. While developing in MQL5 can be complex, the same task is more streamlined in Python."
15-
requires-python = ">=3.9"
15+
requires-python = ">=3.8"
1616
dependencies = []
1717

1818
readme = "README.md"
19-
license = "MIT"
19+
license = {text = "MIT"}
2020

21-
[tool.setuptools.packages.find]
22-
where = []
21+
[project.scripts]
22+
mqpy = "mqpy.__main__:main"
2323

24-
[tool.semantic_release]
25-
version_variable = [
26-
"mqpy/version.py:__version__",
27-
]
28-
version_toml = [
29-
"pyproject.toml:project.version",
30-
]
31-
32-
[tool.semantic_release.changelog]
33-
retain_old_entries = true
34-
35-
[dependency-groups]
24+
[project.optional-dependencies]
3625
dev = [
3726
"pre-commit>=4.0.1",
3827
"pylint>=3.3.3",
@@ -49,6 +38,20 @@ docs = [
4938
"mkdocstrings[python]>=0.29.1",
5039
]
5140

41+
[tool.setuptools]
42+
packages = ["mqpy"]
43+
44+
[tool.semantic_release]
45+
version_variable = [
46+
"mqpy/version.py:__version__",
47+
]
48+
version_toml = [
49+
"pyproject.toml:project.version",
50+
]
51+
52+
[tool.semantic_release.changelog]
53+
retain_old_entries = true
54+
5255
# pre-commit
5356
[tool.pytest.ini_options]
5457
markers = []

setup.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
1-
"""Setup script for the mqpy package.
1+
# """Setup script for the mqpy package.
22

3-
This module contains the setup configuration for the mqpy package, which provides a Python interface
4-
for creating Expert Advisors in MetaTrader 5.
5-
"""
3+
# This module contains the setup configuration for the mqpy package, which provides a Python interface
4+
# for creating Expert Advisors in MetaTrader 5.
5+
# """
66

7-
import pathlib
7+
from setuptools import setup, find_packages
88

9-
import setuptools
10-
11-
long_description = (pathlib.Path(__file__).parent / "README.md").read_text()
12-
13-
setuptools.setup(
9+
setup(
1410
name="mqpy",
15-
version="v0.6.9",
16-
description=(
17-
"A library to simplify the process of creating an Expert Advisor in MQL5. "
18-
"It makes Python development more streamlined than MQL5."
19-
),
20-
author="Joao Paulo Euko",
21-
license="MIT",
22-
keywords=["metatrader5", "algotrading", "stock market"],
11+
version="0.6.9",
12+
packages=find_packages(),
13+
install_requires=[],
14+
author="Joao Euko",
15+
author_email="",
16+
description="A library to simplify creating Expert Advisors in MQL5",
17+
long_description=open("README.md").read(),
2318
long_description_content_type="text/markdown",
24-
packages=setuptools.find_packages(),
25-
install_requires=[
26-
"metatrader5 == 5.0.4874",
27-
"setuptools == 78.1.0",
28-
],
19+
license="MIT",
2920
entry_points={
3021
"console_scripts": [
31-
"mqpy = __main__:main",
22+
"mqpy=mqpy.__main__:main",
3223
],
3324
},
25+
python_requires=">=3.8",
3426
)

tests/conftest.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import pytest
2+
3+
@pytest.fixture
4+
def test_symbols():
5+
"""Provides common test symbols that can be used across tests."""
6+
return {
7+
"forex": "EURUSD",
8+
"indices": "US500",
9+
"commodities": "XAUUSD",
10+
"crypto": "BTCUSD",
11+
"invalid": "INVALID"
12+
}
13+
14+
@pytest.fixture
15+
def configure_logging():
16+
"""Sets up logging configuration for tests."""
17+
import logging
18+
19+
root = logging.getLogger()
20+
for handler in root.handlers[:]:
21+
root.removeHandler(handler)
22+
23+
handler = logging.StreamHandler()
24+
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
25+
handler.setFormatter(formatter)
26+
root.addHandler(handler)
27+
28+
root.setLevel(logging.INFO)
29+
30+
yield
31+
32+
for handler in root.handlers[:]:
33+
root.removeHandler(handler)

tests/integration/test_mt5_connection.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,23 @@
2424

2525
success = False
2626
for attempt in range(10):
27-
if mt5.initialize(
28-
login=int(os.getenv("MT5_LOGIN")), # type: ignore[arg-type]
29-
password=os.getenv("MT5_PASSWORD"),
30-
server=os.getenv("MT5_SERVER"),
31-
path=os.getenv("MT5_PATH"),
32-
):
33-
logger.info("MT5 initialized successfully")
34-
mt5.shutdown()
35-
success = True
36-
break
37-
else:
38-
logger.info(f"Attempt {attempt+1}: Not ready yet, sleeping...")
39-
time.sleep(5)
27+
try:
28+
if mt5.initialize(
29+
login=int(os.getenv("MT5_LOGIN")), # type: ignore[arg-type]
30+
password=os.getenv("MT5_PASSWORD"),
31+
server=os.getenv("MT5_SERVER"),
32+
path=os.getenv("MT5_PATH"),
33+
):
34+
logger.info("MT5 initialized successfully")
35+
mt5.shutdown()
36+
success = True
37+
break
38+
except Exception as e:
39+
try:
40+
mt5.initialize()
41+
except Exception as e:
42+
logger.info(f"Attempt {attempt+1}: Not ready yet, sleeping...")
43+
time.sleep(5)
4044

4145
if not success:
4246
logger.info("Failed to initialize MT5 after waiting.")

0 commit comments

Comments
 (0)