Skip to content

Commit

Permalink
Merge pull request #308 from mraniki/dev
Browse files Browse the repository at this point in the history
♻️ pyproject update ✅ Unit Test
  • Loading branch information
mraniki committed Oct 10, 2023
2 parents 28b1b9b + d8ebbb3 commit f763ebc
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 28 deletions.
13 changes: 9 additions & 4 deletions .github/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.291
rev: v0.0.292
hooks:
- id: ruff
#args: [--fix, --exit-non-zero-on-fix]
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: trailing-whitespace

- repo: https://github.com/PyCQA/bandit
rev: '1.7.5'
hooks:
- id: bandit
args: ["-c", "pyproject.toml"]
10 changes: 5 additions & 5 deletions findmyorder/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
# Load the default settings file
settings_files=[
os.path.join(ROOT, "default_settings.toml"),
'talky_settings.toml',
'settings.toml',
'.secrets.toml'
".op.toml",
"talky_settings.toml",
"settings.toml",
".secrets.toml" ".op.toml",
],
# Load the.env file
load_dotenv=True,
# Set the environments to True
environments=True,
# Set the default environment
default_env="default",)
default_env="default",
)
2 changes: 1 addition & 1 deletion findmyorder/default_settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ mapping = [

# Instrument to be ignored
# when generating an order
ignore_instrument = "US500 USTEC DOGE"
ignore_instrument = "US500 DOGE"

########################################
### END OF DEFAULT SETTINGS ###
Expand Down
31 changes: 18 additions & 13 deletions findmyorder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ class FindMyOrder:
def __init__(
self,
):
self.logger = logger
"""
Initializes the class instance.
async def search(
self,
my_string: str,
) -> bool:
Args:
self (ClassName): The class instance.
Returns:
None
"""

async def search(self, my_string: str) -> bool:
"""
Search an order.
Expand All @@ -61,7 +66,7 @@ async def search(
"""
if my_string:
string_check = my_string.split()[0].lower()
self.logger.debug("Searching order identifier in {}", string_check)
logger.debug("Searching order identifier in {}", string_check)
if string_check in settings.action_identifier.lower():
return True
return False
Expand Down Expand Up @@ -131,11 +136,11 @@ async def identify_order(
)

order = order_grammar.parse_string(instring=my_string, parse_all=False)
self.logger.debug("Order parsed {}", order)
logger.debug("Order parsed {}", order)
return order.asDict()

except Exception as error:
self.logger.error(error)
logger.error(error)
return error

async def get_order(
Expand All @@ -154,18 +159,18 @@ async def get_order(
"""
if not await self.search(msg):
self.logger.debug("No order identified")
logger.debug("No order identified")
return None
order = await self.identify_order(msg)
if isinstance(order, dict):
order["timestamp"] = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
if settings.instrument_mapping:
self.logger.debug("mapping")
logger.debug("mapping")
await self.replace_instrument(order)
if order["instrument"] in settings.ignore_instrument:
self.logger.debug("Ignoring instrument {}", order["instrument"])
logger.debug("Ignoring instrument {}", order["instrument"])
return
self.logger.debug("Order identified {}", order)
logger.debug("Order identified {}", order)
return order

async def replace_instrument(self, order):
Expand All @@ -184,5 +189,5 @@ async def replace_instrument(self, order):
if item["id"] == instrument:
order["instrument"] = item["alt"]
break
self.logger.debug("Instrument symbol changed", order)
logger.debug("Instrument symbol changed", order)
return order
15 changes: 10 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ pyparsing = "^3.0.9"


[tool.poetry.group.dev.dependencies]
python-semantic-release = "^8.0.7"
ruff = "*"
python-semantic-release = ">=8.0.8"
ruff = "^0.0.292"
black = "^23.3.0"
pre-commit = "^3.3.1"

[tool.ruff]
select = [
Expand All @@ -43,8 +45,7 @@ exclude = [
".github/*",
"docs/*",
]
ignore = ["E401","F401","F811"]
format = "github"

fixable = ["ALL"]

[tool.pylint.exceptions]
Expand All @@ -64,7 +65,7 @@ pytest = "^7.0"
pytest-cov = "^4.1"
pytest-asyncio = "^0.21.0"
pytest-mock = "^3.11.1"
pytest-loguru = "^0.2.0"
pytest-loguru = "^0.3.0"



Expand Down Expand Up @@ -97,6 +98,10 @@ omit = [
"*/config.py"
]

[tool.bandit]
exclude_dirs = ["tests","docs"]
skips = ["B101","B104"]

[tool.semantic_release]
upload_to_vcs_release = true
version_variables = ["findmyorder/__init__.py:__version__"]
Expand Down
31 changes: 31 additions & 0 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ def short_order():
return "Buy EURUSD"


@pytest.fixture
def order_2():
"""return order 2"""
return """
📊 FUTURES Exchanges: Binance, ByBit USDT
#AAVEUSDT
🟢LONG ENTRY :- 65.20 - 63.70
Leverage: Cross (2X)
👇TAKE PROFIT
1) 65.70
2) 66.20
3) 66.70
Stop Loss : - 62.00
"""


@pytest.fixture
def result_order():
"""return standard expected results"""
Expand Down Expand Up @@ -217,3 +239,12 @@ async def test_mapping_order(fmo, crypto_short_order, result_crypto_order):
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_identify_order2(fmo, order_2):
"""Identify Testing"""
result = await fmo.identify_order(order_2)
assert result is not None
# result = await fmo.get_order(order_2)
# assert result["action"] == "LONG"

0 comments on commit f763ebc

Please sign in to comment.