diff --git a/findmyorder/default_settings.toml b/findmyorder/default_settings.toml index bcdfbd1f..cf4743bd 100644 --- a/findmyorder/default_settings.toml +++ b/findmyorder/default_settings.toml @@ -33,7 +33,7 @@ mapping = [ { id = "BTC", alt = "WBTC" }, { id = "ETH", alt = "WETH" }, ] - +ignore_instrument = "US500 USTEC DOGE" [testing] diff --git a/findmyorder/main.py b/findmyorder/main.py index 1231637e..7ace469b 100644 --- a/findmyorder/main.py +++ b/findmyorder/main.py @@ -97,16 +97,19 @@ async def get_order( msg: str, ): """get an order.""" - if await self.search(msg): - order = await self.identify_order(msg) - if isinstance(order, dict): - order["timestamp"] = datetime.utcnow().strftime( - "%Y-%m-%dT%H:%M:%SZ") - print(settings.instrument_mapping) - if settings.instrument_mapping: - await self.replace_instrument(order) - return order - return None + if not await self.search(msg): + return None + order = await self.identify_order(msg) + if isinstance(order, dict): + order["timestamp"] = datetime.utcnow().strftime( + "%Y-%m-%dT%H:%M:%SZ") + print(settings.instrument_mapping) + if settings.instrument_mapping: + await self.replace_instrument(order) + if order["instrument"] in settings.ignore_instrument: + """ ignoring instrument""" + return + return order async def replace_instrument(self, order): """ replace instrument by an alternative instrument """ diff --git a/tests/test_unit.py b/tests/test_unit.py index ee43411d..216aff2f 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -4,12 +4,9 @@ from datetime import datetime import pytest -from unittest.mock import patch from findmyorder import FindMyOrder, settings - - @pytest.fixture(scope="session", autouse=True) def set_test_settings(): settings.configure(FORCE_ENV_FOR_DYNACONF="testing") @@ -45,6 +42,10 @@ def result_order(): "timestamp": datetime.now() } +@pytest.fixture +def ignore_order(): + """return valid order""" + return "buy US500" @pytest.fixture def crypto_order(): @@ -94,9 +95,17 @@ def invalid_order(): async def test_settings(): """Search Testing""" assert settings.VALUE == "On Testing" - assert settings.findmyorder_enabled == True + assert settings.findmyorder_enabled is True +@pytest.mark.asyncio +async def test_info(fmo): + """Search Testing""" + result = await fmo.get_info() + print(result) + assert result is not None + assert str(result).startswith("FindMyOrder") + @pytest.mark.asyncio async def test_search_valid_order(fmo, crypto_order): """Search Testing""" @@ -173,6 +182,14 @@ async def test_short_valid_get_order(fmo, short_order, result_order): assert int(result["quantity"]) == 1 assert type(result["timestamp"] is datetime) + +@pytest.mark.asyncio +async def test_ignore_eorder(fmo, ignore_order): + """ignore order Testing""" + result = await fmo.get_order(ignore_order) + assert result is None + + @pytest.mark.asyncio async def test_mapping_order( fmo, @@ -181,10 +198,11 @@ async def test_mapping_order( """replace instrument Testing""" result = await fmo.get_order(crypto_short_order) print(result) - assert settings.instrument_mapping == True + assert settings.instrument_mapping is True assert result["instrument"] == result_crypto_order["instrument"] assert type(result["timestamp"] is datetime) + @pytest.mark.asyncio async def test_contains_no_emoji(fmo, order): """check emoji""" @@ -214,4 +232,3 @@ def func_that_raises(): # Check that the function returned None assert result is None -