diff --git a/examples/is_order_scoring.py b/examples/is_order_scoring.py new file mode 100644 index 0000000..1017d42 --- /dev/null +++ b/examples/is_order_scoring.py @@ -0,0 +1,31 @@ +import os + +from py_clob_client.client import ClobClient +from py_clob_client.clob_types import ApiCreds, OrderScoringParams +from dotenv import load_dotenv +from py_clob_client.constants import MUMBAI + +load_dotenv() + + +def main(): + host = "http://localhost:8080" + key = os.getenv("PK") + creds = ApiCreds( + api_key=os.getenv("CLOB_API_KEY"), + api_secret=os.getenv("CLOB_SECRET"), + api_passphrase=os.getenv("CLOB_PASS_PHRASE"), + ) + chain_id = MUMBAI + client = ClobClient(host, key=key, chain_id=chain_id, creds=creds) + + scoring = client.is_order_scoring( + OrderScoringParams( + orderId="0xb816482a5187a3d3db49cbaf6fe3ddf24f53e6c712b5a4bf5e01d0ec7b11dabc" + ) + ) + print(scoring) + print("Done!") + + +main() diff --git a/py_clob_client/client.py b/py_clob_client/client.py index 5388517..c1ca740 100644 --- a/py_clob_client/client.py +++ b/py_clob_client/client.py @@ -27,6 +27,7 @@ GET_TRADE_NOTIFICATIONS, DROP_TRADE_NOTIFICATIONS, GET_BALANCE_ALLOWANCE, + IS_ORDER_SCORING, ) from .clob_types import ( ApiCreds, @@ -36,6 +37,7 @@ TradeNotificationParams, OrderBookSummary, BalanceAllowanceParams, + OrderScoringParams, ) from .exceptions import PolyException from .http_helpers.helpers import ( @@ -45,6 +47,7 @@ post, add_trade_notifications_query_params, add_balance_allowance_params_to_url, + add_order_scoring_params_to_url, ) from py_order_utils.config import get_contract_config from .constants import L0, L1, L1_AUTH_UNAVAILABLE, L2, L2_AUTH_UNAVAILABLE @@ -418,3 +421,16 @@ def get_balance_allowance(self, params: BalanceAllowanceParams = None): "{}{}".format(self.host, GET_BALANCE_ALLOWANCE), params ) return get(url, headers=headers) + + def is_order_scoring(self, params: OrderScoringParams): + """ + Check if the order is currently scoring + Requires Level 2 authentication + """ + self.assert_level_2_auth() + request_args = RequestArgs(method="GET", request_path=IS_ORDER_SCORING) + headers = create_level_2_headers(self.signer, self.creds, request_args) + url = add_order_scoring_params_to_url( + "{}{}".format(self.host, IS_ORDER_SCORING), params + ) + return get(url, headers=headers) diff --git a/py_clob_client/clob_types.py b/py_clob_client/clob_types.py index a154335..5eba231 100644 --- a/py_clob_client/clob_types.py +++ b/py_clob_client/clob_types.py @@ -127,3 +127,8 @@ class OrderType(enumerate): # TODO: add support for FOK orders FOK = "FOK" GTD = "GTD" + + +@dataclass +class OrderScoringParams: + orderId: str diff --git a/py_clob_client/endpoints.py b/py_clob_client/endpoints.py index 5fb6d04..c67b953 100644 --- a/py_clob_client/endpoints.py +++ b/py_clob_client/endpoints.py @@ -18,3 +18,4 @@ GET_TRADE_NOTIFICATIONS = "/trade-notifications" DROP_TRADE_NOTIFICATIONS = "/drop-trade-notifications" GET_BALANCE_ALLOWANCE = "/balance-allowance" +IS_ORDER_SCORING = "/order-scoring" diff --git a/py_clob_client/http_helpers/helpers.py b/py_clob_client/http_helpers/helpers.py index 55909ec..35ff025 100644 --- a/py_clob_client/http_helpers/helpers.py +++ b/py_clob_client/http_helpers/helpers.py @@ -4,6 +4,7 @@ FilterParams, TradeNotificationParams, BalanceAllowanceParams, + OrderScoringParams, ) from ..exceptions import PolyApiException @@ -120,3 +121,17 @@ def add_balance_allowance_params_to_url( if params.token_id: url = build_query_params(url, "token_id", params.token_id) return url + + +def add_order_scoring_params_to_url( + base_url: str, params: OrderScoringParams = None +) -> str: + """ + Adds query parameters to a url + """ + url = base_url + if params: + url = url + "?" + if params.orderId: + url = build_query_params(url, "order_id", params.orderId) + return url diff --git a/setup.py b/setup.py index a5e4f16..3fed833 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="py_clob_client", - version="0.3.0", + version="0.4.0", author="Polymarket Engineering", author_email="engineering@polymarket.com", maintainer="Polymarket Engineering", diff --git a/tests/http_helpers/test_helpers.py b/tests/http_helpers/test_helpers.py index 1b6a8b5..885b121 100644 --- a/tests/http_helpers/test_helpers.py +++ b/tests/http_helpers/test_helpers.py @@ -4,6 +4,7 @@ TradeNotificationParams, BalanceAllowanceParams, AssetType, + OrderScoringParams, ) from py_clob_client.http_helpers.helpers import ( @@ -11,6 +12,7 @@ add_query_params, add_trade_notifications_query_params, add_balance_allowance_params_to_url, + add_order_scoring_params_to_url, ) @@ -58,3 +60,11 @@ def test_add_balance_allowance_params_to_url(self): ) self.assertIsNotNone(url) self.assertEqual(url, "http://tracker?asset_type=CONDITIONAL&token_id=222") + + def test_add_order_scoring_params_to_url(self): + url = add_order_scoring_params_to_url( + "http://tracker", + OrderScoringParams(orderId="0x0123abc"), + ) + self.assertIsNotNone(url) + self.assertEqual(url, "http://tracker?order_id=0x0123abc")