Skip to content

Commit

Permalink
Merge pull request #80 from Polymarket/feat/update-balance-allowance
Browse files Browse the repository at this point in the history
New endpoint: Update balance and allowance
  • Loading branch information
poly-rodr authored Jun 7, 2024
2 parents f33495e + 801dd88 commit 84a0c17
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
44 changes: 44 additions & 0 deletions examples/update_balance_allowance.py
Original file line number Diff line number Diff line change
@@ -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()
16 changes: 16 additions & 0 deletions py_clob_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
GET_NOTIFICATIONS,
DROP_NOTIFICATIONS,
GET_BALANCE_ALLOWANCE,
UPDATE_BALANCE_ALLOWANCE,
IS_ORDER_SCORING,
GET_TICK_SIZE,
ARE_ORDERS_SCORING,
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions py_clob_client/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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.16.0",
version="0.17.0",
author="Polymarket Engineering",
author_email="[email protected]",
maintainer="Polymarket Engineering",
Expand Down

0 comments on commit 84a0c17

Please sign in to comment.