Skip to content

Commit

Permalink
Merge pull request #7 from Polymarket/fix/more-endpoints
Browse files Browse the repository at this point in the history
Feat: more endpoints
  • Loading branch information
JonathanAmenechi authored Mar 7, 2022
2 parents 2472715 + 92159f6 commit bee4d57
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
9 changes: 9 additions & 0 deletions examples/get_orderbook.py
Original file line number Diff line number Diff line change
@@ -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()
31 changes: 28 additions & 3 deletions py_clob_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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
Expand Down Expand Up @@ -97,11 +97,28 @@ 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={}&tokenID={}".format(self.host, MID_POINT, self.get_conditional_address(), tokenID))
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):
"""
Expand Down Expand Up @@ -177,10 +194,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
Expand All @@ -193,6 +216,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)
Expand Down
3 changes: 3 additions & 0 deletions py_clob_client/endpoints.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
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/"
OPEN_ORDERS = "/open-orders"
POST_ORDER = "/order"
CANCEL = "/order"
CANCEL_ALL = "/cancel-all"
MID_POINT="/midpoint"
PRICE = "/price"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="py_clob_client",
version="0.0.6",
version="0.0.7",
author="Jonathan Amenechi",
author_email="[email protected]",
description="Python client for the Polymarket CLOB",
Expand Down

0 comments on commit bee4d57

Please sign in to comment.