refactor symbol and executor

This commit is contained in:
Ichinga Samuel
2023-10-24 13:59:28 +01:00
parent 21043dd326
commit aa39fdf033
14 changed files with 214 additions and 13 deletions
+10
View File
@@ -0,0 +1,10 @@
from aiomql import MetaTrader
import pytest
from .fixtures import *
@pytest.mark.asyncio
class BaseTest:
""""""
mt5 = MetaTrader()
+31
View File
@@ -0,0 +1,31 @@
import json
import os
from aiomql import MetaTrader as mt5, Config
import pytest
@pytest.fixture(scope="session")
def get_default_config():
data = {"win_percentage": 0.90, "record_dir": "Trade Records"}
obj = open('mt5.json', 'w')
json.dump(data, obj)
obj.close()
yield
os.remove('mt5.json')
@pytest.fixture(scope="session")
def get_config():
data = {"win_percentage": 0.8, "record_dir": "Trade_Records"}
obj = open('config.json', 'w')
json.dump(data, obj)
obj.close()
yield
os.remove('config.json')
@pytest.fixture(autouse=True, scope="session")
def init():
config = Config(filename="test_config.json")
mt5._initialize()
mt5._login(login=config.account_number, password=config.password, server=config.server)
+5
View File
@@ -0,0 +1,5 @@
{
"account_number": 160286827,
"password": "TheN@me0fTheW!nd",
"server": "ForexTimeFXTM-Demo01"
}
+13
View File
@@ -0,0 +1,13 @@
from aiomql import config
from . import get_config, get_default_config
def test_default_config_file(get_default_config):
conf = config.Config()
assert conf.win_percentage == 0.90
def test_config_file_name(get_config):
conf = config.Config(filename='config.json')
assert conf.win_percentage == 0.8
+7
View File
@@ -0,0 +1,7 @@
from aiomql import TradeAction
class TestConstants:
def test_trade_action(self):
assert TradeAction.DEAL == 1
+11
View File
@@ -0,0 +1,11 @@
from aiomql.symbol import Symbol
from . import *
class TestSymbol(BaseTest):
sym = Symbol(name="EURJPY")
async def test_init(self):
await self.sym.init()
assert self.sym.select is True
+22
View File
@@ -0,0 +1,22 @@
from . import *
from aiomql import Terminal
class TestTerminal(BaseTest):
terminal = Terminal()
async def test_version(self):
res = await self.terminal.version
assert len(res) == 3
async def test_info(self):
res = await self.terminal.info()
assert res.connected is True
async def test_error(self):
res = await self.terminal.last_error()
assert res.code == 1
async def test_symbols_get(self):
res = await self.terminal.symbols_get()
sym = next(res)
assert isinstance(sym.name, str)