Skip to content

Commit

Permalink
Merge pull request #48 from Polymarket/feat/adapt-cancel-order
Browse files Browse the repository at this point in the history
Feat/ new order cancelation endpoints
  • Loading branch information
poly-rodr authored Feb 7, 2023
2 parents e4effc4 + c6f2da6 commit 8b9bde2
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 1 deletion.
29 changes: 29 additions & 0 deletions examples/cancel_market_orders.py
Original file line number Diff line number Diff line change
@@ -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()
29 changes: 29 additions & 0 deletions examples/cancel_order.py
Original file line number Diff line number Diff line change
@@ -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()
29 changes: 29 additions & 0 deletions examples/cancel_orders.py
Original file line number Diff line number Diff line change
@@ -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()
34 changes: 34 additions & 0 deletions py_clob_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from .endpoints import (
CANCEL,
CANCEL_ORDERS,
CANCEL_MARKET_ORDERS,
CANCEL_ALL,
CREATE_API_KEY,
DELETE_API_KEY,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions py_clob_client/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
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.1.12",
version="0.1.13",
author="Polymarket Engineering",
author_email="[email protected]",
maintainer="Polymarket Engineering",
Expand Down

0 comments on commit 8b9bde2

Please sign in to comment.