From c6f2da6ddef01325fdf3a0985fab56937b266cca Mon Sep 17 00:00:00 2001 From: Rodrigo <95635797+poly-rodr@users.noreply.github.com> Date: Mon, 6 Feb 2023 17:03:35 -0300 Subject: [PATCH] Feat/ new order cancelation endpoints --- examples/cancel_market_orders.py | 29 +++++++++++++++++++++++++++ examples/cancel_order.py | 29 +++++++++++++++++++++++++++ examples/cancel_orders.py | 29 +++++++++++++++++++++++++++ py_clob_client/client.py | 34 ++++++++++++++++++++++++++++++++ py_clob_client/endpoints.py | 2 ++ setup.py | 2 +- 6 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 examples/cancel_market_orders.py create mode 100644 examples/cancel_order.py create mode 100644 examples/cancel_orders.py diff --git a/examples/cancel_market_orders.py b/examples/cancel_market_orders.py new file mode 100644 index 0000000..a32d2f6 --- /dev/null +++ b/examples/cancel_market_orders.py @@ -0,0 +1,29 @@ +import os + +from py_clob_client.client import ClobClient +from py_clob_client.clob_types import ApiCreds +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) + + resp = client.cancel_market_orders(market="0xaaa", asset_id="100") + print(resp) + print("Done!") + + +main() diff --git a/examples/cancel_order.py b/examples/cancel_order.py new file mode 100644 index 0000000..3fb0b90 --- /dev/null +++ b/examples/cancel_order.py @@ -0,0 +1,29 @@ +import os + +from py_clob_client.client import ClobClient +from py_clob_client.clob_types import ApiCreds +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) + + resp = client.cancel(order_id="0xaaaa") + print(resp) + print("Done!") + + +main() diff --git a/examples/cancel_orders.py b/examples/cancel_orders.py new file mode 100644 index 0000000..8a84b22 --- /dev/null +++ b/examples/cancel_orders.py @@ -0,0 +1,29 @@ +import os + +from py_clob_client.client import ClobClient +from py_clob_client.clob_types import ApiCreds +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) + + resp = client.cancel_orders(["0xaaaa"]) + print(resp) + print("Done!") + + +main() diff --git a/py_clob_client/client.py b/py_clob_client/client.py index 18bd3e5..eec49dd 100644 --- a/py_clob_client/client.py +++ b/py_clob_client/client.py @@ -8,6 +8,8 @@ from .endpoints import ( CANCEL, + CANCEL_ORDERS, + CANCEL_MARKET_ORDERS, CANCEL_ALL, CREATE_API_KEY, DELETE_API_KEY, @@ -256,6 +258,22 @@ def cancel(self, order_id): headers = create_level_2_headers(self.signer, self.creds, request_args) return delete("{}{}".format(self.host, CANCEL), headers=headers, data=body) + def cancel_orders(self, order_ids): + """ + Cancels orders + Level 2 Auth required + """ + self.assert_level_2_auth() + body = order_ids + + request_args = RequestArgs( + method="DELETE", request_path=CANCEL_ORDERS, body=body + ) + headers = create_level_2_headers(self.signer, self.creds, request_args) + return delete( + "{}{}".format(self.host, CANCEL_ORDERS), headers=headers, data=body + ) + def cancel_all(self): """ Cancels all available orders for the user @@ -266,6 +284,22 @@ def cancel_all(self): headers = create_level_2_headers(self.signer, self.creds, request_args) return delete("{}{}".format(self.host, CANCEL_ALL), headers=headers) + def cancel_market_orders(self, market: str = None, asset_id: str = None): + """ + Cancels orders + Level 2 Auth required + """ + self.assert_level_2_auth() + body = {"market": market, "asset_id": asset_id} + + request_args = RequestArgs( + method="DELETE", request_path=CANCEL_MARKET_ORDERS, body=body + ) + headers = create_level_2_headers(self.signer, self.creds, request_args) + return delete( + "{}{}".format(self.host, CANCEL_MARKET_ORDERS), headers=headers, data=body + ) + def get_orders(self, params: FilterParams = None): """ Gets orders for the API key diff --git a/py_clob_client/endpoints.py b/py_clob_client/endpoints.py index 4265fcb..0000ef9 100644 --- a/py_clob_client/endpoints.py +++ b/py_clob_client/endpoints.py @@ -9,7 +9,9 @@ ORDERS = "/orders" POST_ORDER = "/order" CANCEL = "/order" +CANCEL_ORDERS = "/orders" CANCEL_ALL = "/cancel-all" +CANCEL_MARKET_ORDERS = "/cancel-market-orders" MID_POINT = "/midpoint" PRICE = "/price" GET_LAST_TRADE_PRICE = "/last-trade-price" diff --git a/setup.py b/setup.py index 0909545..017b7c2 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="py_clob_client", - version="0.1.12", + version="0.1.13", author="Polymarket Engineering", author_email="engineering@polymarket.com", maintainer="Polymarket Engineering",