diff --git a/examples/update_balance_allowance.py b/examples/update_balance_allowance.py new file mode 100644 index 0000000..ceee7b3 --- /dev/null +++ b/examples/update_balance_allowance.py @@ -0,0 +1,44 @@ +import os + +from py_clob_client.client import ClobClient +from py_clob_client.clob_types import ApiCreds, BalanceAllowanceParams, AssetType +from dotenv import load_dotenv +from py_clob_client.constants import AMOY + +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 = AMOY + client = ClobClient(host, key=key, chain_id=chain_id, creds=creds) + + # USDC + client.update_balance_allowance( + params=BalanceAllowanceParams(asset_type=AssetType.COLLATERAL) + ) + + # YES + client.update_balance_allowance( + params=BalanceAllowanceParams( + asset_type=AssetType.CONDITIONAL, + token_id="52114319501245915516055106046884209969926127482827954674443846427813813222426", + ) + ) + + # NO + client.update_balance_allowance( + params=BalanceAllowanceParams( + asset_type=AssetType.CONDITIONAL, + token_id="71321045679252212594626385532706912750332728571942532289631379312455583992563", + ) + ) + + +main() diff --git a/py_clob_client/client.py b/py_clob_client/client.py index c00d51f..8fb6a1d 100644 --- a/py_clob_client/client.py +++ b/py_clob_client/client.py @@ -26,6 +26,7 @@ GET_NOTIFICATIONS, DROP_NOTIFICATIONS, GET_BALANCE_ALLOWANCE, + UPDATE_BALANCE_ALLOWANCE, IS_ORDER_SCORING, GET_TICK_SIZE, ARE_ORDERS_SCORING, @@ -603,6 +604,21 @@ def get_balance_allowance(self, params: BalanceAllowanceParams = None): ) return get(url, headers=headers) + def update_balance_allowance(self, params: BalanceAllowanceParams = None): + """ + Updates the balance & allowance for a user + Requires Level 2 authentication + """ + self.assert_level_2_auth() + request_args = RequestArgs(method="GET", request_path=UPDATE_BALANCE_ALLOWANCE) + headers = create_level_2_headers(self.signer, self.creds, request_args) + if params.signature_type == -1: + params.signature_type = self.builder.sig_type + url = add_balance_allowance_params_to_url( + "{}{}".format(self.host, UPDATE_BALANCE_ALLOWANCE), params + ) + return get(url, headers=headers) + def is_order_scoring(self, params: OrderScoringParams): """ Check if the order is currently scoring diff --git a/py_clob_client/endpoints.py b/py_clob_client/endpoints.py index 7f563f2..b1052a5 100644 --- a/py_clob_client/endpoints.py +++ b/py_clob_client/endpoints.py @@ -24,6 +24,7 @@ GET_NOTIFICATIONS = "/notifications" DROP_NOTIFICATIONS = "/notifications" GET_BALANCE_ALLOWANCE = "/balance-allowance" +UPDATE_BALANCE_ALLOWANCE = "/balance-allowance/update" IS_ORDER_SCORING = "/order-scoring" ARE_ORDERS_SCORING = "/orders-scoring" GET_TICK_SIZE = "/tick-size" diff --git a/setup.py b/setup.py index dc96045..7fa06b2 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="py_clob_client", - version="0.16.0", + version="0.17.0", author="Polymarket Engineering", author_email="engineering@polymarket.com", maintainer="Polymarket Engineering",