Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🥚ignore_instrument setting #237

Merged
merged 4 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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

Check warning on line 101 in findmyorder/main.py

View check run for this annotation

Codecov / codecov/patch

findmyorder/main.py#L101

Added line #L101 was not covered by tests
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 @@
"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 @@
async def test_settings():
"""Search Testing"""
assert settings.VALUE == "On Testing"
assert settings.findmyorder_enabled == True
assert settings.findmyorder_enabled is True
Dismissed Show dismissed Hide dismissed


@pytest.mark.asyncio
async def test_info(fmo):
"""Search Testing"""
result = await fmo.get_info()
print(result)
assert result is not None
Dismissed Show dismissed Hide dismissed
assert str(result).startswith("FindMyOrder")
Dismissed Show dismissed Hide dismissed

@pytest.mark.asyncio
async def test_search_valid_order(fmo, crypto_order):
"""Search Testing"""
Expand Down Expand Up @@ -173,6 +182,14 @@
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
Dismissed Show dismissed Hide dismissed


@pytest.mark.asyncio
async def test_mapping_order(
fmo,
Expand All @@ -181,10 +198,11 @@
"""replace instrument Testing"""
result = await fmo.get_order(crypto_short_order)
print(result)
assert settings.instrument_mapping == True
assert settings.instrument_mapping is True
Dismissed Show dismissed Hide dismissed
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 @@

# Check that the function returned None
assert result is None