Skip to content

Commit

Permalink
Merge pull request #237 from mraniki/dev
Browse files Browse the repository at this point in the history
🥚ignore_instrument  setting
  • Loading branch information
mraniki committed Jul 11, 2023
2 parents 73cec85 + b8deab5 commit 4416ef1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
2 changes: 1 addition & 1 deletion findmyorder/default_settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mapping = [
{ id = "BTC", alt = "WBTC" },
{ id = "ETH", alt = "WETH" },
]

ignore_instrument = "US500 USTEC DOGE"


[testing]
Expand Down
23 changes: 13 additions & 10 deletions findmyorder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down
29 changes: 23 additions & 6 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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,
Expand All @@ -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"""
Expand Down Expand Up @@ -214,4 +232,3 @@ def func_that_raises():

# Check that the function returned None
assert result is None

0 comments on commit 4416ef1

Please sign in to comment.