diff --git a/.github/.pre-commit-config.yaml b/.github/.pre-commit-config.yaml index dd62c4f3..9adff499 100644 --- a/.github/.pre-commit-config.yaml +++ b/.github/.pre-commit-config.yaml @@ -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 \ No newline at end of file + - id: trailing-whitespace + + - repo: https://github.com/PyCQA/bandit + rev: '1.7.5' + hooks: + - id: bandit + args: ["-c", "pyproject.toml"] \ No newline at end of file diff --git a/findmyorder/config.py b/findmyorder/config.py index f9041f4b..0ce9e616 100644 --- a/findmyorder/config.py +++ b/findmyorder/config.py @@ -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", +) diff --git a/findmyorder/default_settings.toml b/findmyorder/default_settings.toml index c2a7f5ee..716a9db2 100644 --- a/findmyorder/default_settings.toml +++ b/findmyorder/default_settings.toml @@ -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 ### diff --git a/findmyorder/main.py b/findmyorder/main.py index e7046317..7c8c5f2f 100644 --- a/findmyorder/main.py +++ b/findmyorder/main.py @@ -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. @@ -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 @@ -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( @@ -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): @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 8414d9d7..e3231385 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = [ @@ -43,8 +45,7 @@ exclude = [ ".github/*", "docs/*", ] -ignore = ["E401","F401","F811"] -format = "github" + fixable = ["ALL"] [tool.pylint.exceptions] @@ -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" @@ -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__"] diff --git a/tests/test_unit.py b/tests/test_unit.py index 1b4b2425..0a92ae8e 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -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""" @@ -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"