From 9ab07c4d738b3141349d7a2ec7b4bcae1efcd9b0 Mon Sep 17 00:00:00 2001 From: JonathanAmenechi <7217608+JonathanAmenechi@users.noreply.github.com> Date: Mon, 7 Mar 2022 11:35:27 -0500 Subject: [PATCH 1/2] fix: add endpoints, update get_order_book and midpoint to adhere to new standard --- examples/get_orderbook.py | 9 +++++++++ py_clob_client/client.py | 14 +++++++++++--- py_clob_client/endpoints.py | 1 + setup.py | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 examples/get_orderbook.py diff --git a/examples/get_orderbook.py b/examples/get_orderbook.py new file mode 100644 index 0000000..f2e6953 --- /dev/null +++ b/examples/get_orderbook.py @@ -0,0 +1,9 @@ +from py_clob_client.client import ClobClient + +def main(): + host = "http://localhost:8080" + client = ClobClient(host) + + print(client.get_order_book("16678291189211314787145083999015737376658799626183230671758641503291735614088")) + +main() \ No newline at end of file diff --git a/py_clob_client/client.py b/py_clob_client/client.py index cdf6dc4..f778b78 100644 --- a/py_clob_client/client.py +++ b/py_clob_client/client.py @@ -5,7 +5,7 @@ from .headers import create_level_1_headers, create_level_2_headers from .signer import Signer -from .endpoints import CANCEL, CANCEL_ALL, CREATE_API_KEY, GET_API_KEYS, GET_ORDER, MID_POINT, OPEN_ORDERS, POST_ORDER, TIME, TRADE_HISTORY +from .endpoints import CANCEL, CANCEL_ALL, CREATE_API_KEY, GET_API_KEYS, GET_ORDER, GET_ORDER_BOOK, MID_POINT, OPEN_ORDERS, POST_ORDER, TIME, TRADE_HISTORY from .clob_types import ApiCreds, LimitOrderArgs, MarketOrderArgs, RequestArgs from .exceptions import PolyException from .http_helpers.helpers import delete, get, post @@ -101,7 +101,7 @@ def get_midpoint(self, tokenID): """ Get the mid market price for the given market """ - return get("{}{}?market={}&tokenID={}".format(self.host, MID_POINT, self.get_conditional_address(), tokenID)) + return get("{}{}?market={}".format(self.host, MID_POINT, tokenID)) def create_limit_order(self, order_args: LimitOrderArgs): """ @@ -177,10 +177,16 @@ def get_open_orders(self, tokenID = None): headers = create_level_2_headers(self.signer, self.creds, request_args) if tokenID is not None: - return get("{}{}?market={}&tokenID={}".format(self.host, OPEN_ORDERS, self.get_conditional_address(), tokenID), headers=headers) + return get("{}{}?market={}".format(self.host, OPEN_ORDERS, tokenID), headers=headers) return get("{}{}".format(self.host, OPEN_ORDERS), headers=headers) + def get_order_book(self, token_id): + """ + Fetches the orderbook for the token_id + """ + return get("{}{}?market={}".format(self.host, GET_ORDER_BOOK, token_id)) + def get_order(self, order_id): """ Fetches the order corresponding to the order_id @@ -193,6 +199,8 @@ def get_order(self, order_id): return get("{}{}".format(self.host, endpoint), headers=headers) def get_trade_history(self): + """ + """ self.assert_level_2_auth() request_args = RequestArgs(method="GET", request_path=TRADE_HISTORY) headers = create_level_2_headers(self.signer, self.creds, request_args) diff --git a/py_clob_client/endpoints.py b/py_clob_client/endpoints.py index d869ba1..df93574 100644 --- a/py_clob_client/endpoints.py +++ b/py_clob_client/endpoints.py @@ -2,6 +2,7 @@ CREATE_API_KEY = "/create-api-key" GET_API_KEYS = "/get-api-keys" TRADE_HISTORY = "/trade-history" +GET_ORDER_BOOK = "/book" GET_ORDER = "/order/" OPEN_ORDERS = "/open-orders" POST_ORDER = "/order" diff --git a/setup.py b/setup.py index 9256c67..b2a9a9c 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="py_clob_client", - version="0.0.6", + version="0.0.7", author="Jonathan Amenechi", author_email="jonathanamenechi@gmail.com", description="Python client for the Polymarket CLOB", From 92159f6a79b990b842fae6534ea271dab0257f9f Mon Sep 17 00:00:00 2001 From: JonathanAmenechi <7217608+JonathanAmenechi@users.noreply.github.com> Date: Mon, 7 Mar 2022 12:35:47 -0500 Subject: [PATCH 2/2] fix: delete_api_key endpoint --- py_clob_client/client.py | 19 ++++++++++++++++++- py_clob_client/endpoints.py | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/py_clob_client/client.py b/py_clob_client/client.py index f778b78..5a6f981 100644 --- a/py_clob_client/client.py +++ b/py_clob_client/client.py @@ -5,7 +5,7 @@ from .headers import create_level_1_headers, create_level_2_headers from .signer import Signer -from .endpoints import CANCEL, CANCEL_ALL, CREATE_API_KEY, GET_API_KEYS, GET_ORDER, GET_ORDER_BOOK, MID_POINT, OPEN_ORDERS, POST_ORDER, TIME, TRADE_HISTORY +from .endpoints import CANCEL, CANCEL_ALL, CREATE_API_KEY, DELETE_API_KEY, GET_API_KEYS, GET_ORDER, GET_ORDER_BOOK, MID_POINT, OPEN_ORDERS, POST_ORDER, PRICE, TIME, TRADE_HISTORY from .clob_types import ApiCreds, LimitOrderArgs, MarketOrderArgs, RequestArgs from .exceptions import PolyException from .http_helpers.helpers import delete, get, post @@ -97,12 +97,29 @@ def get_api_keys(self): headers = create_level_2_headers(self.signer, self.creds, request_args) return get("{}{}".format(self.host, GET_API_KEYS), headers=headers) + def delete_api_key(self): + """ + Deletes an API key + Level 2 Auth required + """ + self.assert_level_2_auth() + + request_args = RequestArgs(method="DELETE", request_path=DELETE_API_KEY) + headers = create_level_2_headers(self.signer, self.creds, request_args) + return delete("{}{}".format(self.host, DELETE_API_KEY), headers=headers) + def get_midpoint(self, tokenID): """ Get the mid market price for the given market """ return get("{}{}?market={}".format(self.host, MID_POINT, tokenID)) + def get_price(self, tokenID, side): + """ + Get the mid market price for the given market + """ + return get("{}{}?price={}&side={}".format(self.host, PRICE, tokenID, side)) + def create_limit_order(self, order_args: LimitOrderArgs): """ Creates and signs a limit order diff --git a/py_clob_client/endpoints.py b/py_clob_client/endpoints.py index df93574..3e8883d 100644 --- a/py_clob_client/endpoints.py +++ b/py_clob_client/endpoints.py @@ -1,6 +1,7 @@ TIME = "/time" CREATE_API_KEY = "/create-api-key" GET_API_KEYS = "/get-api-keys" +DELETE_API_KEY = "/delete-api-key" TRADE_HISTORY = "/trade-history" GET_ORDER_BOOK = "/book" GET_ORDER = "/order/" @@ -9,3 +10,4 @@ CANCEL = "/order" CANCEL_ALL = "/cancel-all" MID_POINT="/midpoint" +PRICE = "/price" \ No newline at end of file