From 0c1a69eab0c406fb2369e8fdbaa8a22e8091c0b3 Mon Sep 17 00:00:00 2001 From: justinpolygon <123573436+justinpolygon@users.noreply.github.com> Date: Wed, 22 Feb 2023 22:20:35 -0800 Subject: [PATCH] Fix malformed query filter params --- polygon/rest/base.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/polygon/rest/base.py b/polygon/rest/base.py index 3507ed02..3885db18 100644 --- a/polygon/rest/base.py +++ b/polygon/rest/base.py @@ -141,14 +141,12 @@ def _get_params( elif isinstance(val, datetime): val = int(val.timestamp() * self.time_mult(datetime_res)) if val is not None: - if ( - argname.endswith("_lt") - or argname.endswith("_lte") - or argname.endswith("_gt") - or argname.endswith("_gte") - or argname.endswith("_any_of") - ): - argname = ".".join(argname.split("_", 1)) + for ext in ["lt", "lte", "gt", "gte", "any_of"]: + if argname.endswith(f"_{ext}"): + # lop off ext, then rebuild argname with ext, + # using ., and not _ (removesuffix would work) + # but that is python 3.9+ + argname = argname[: -len(f"_{ext}")] + f".{ext}" if argname.endswith("any_of"): val = ",".join(val) params[argname] = val