Skip to content

Commit

Permalink
Merge pull request #72 from Polymarket/feat/improvements-on-balance-c…
Browse files Browse the repository at this point in the history
…hecker

adding signature to the balance allowance fetching
  • Loading branch information
poly-rodr authored Mar 15, 2024
2 parents 3669764 + e07a7ec commit 78600d9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
4 changes: 3 additions & 1 deletion py_clob_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def get_conditional_address(self):
if contract_config:
return contract_config.conditional_tokens

def get_exchange_address(self, neg_risk = False):
def get_exchange_address(self, neg_risk=False):
"""
Returns the exchange address
"""
Expand Down Expand Up @@ -520,6 +520,8 @@ def get_balance_allowance(self, params: BalanceAllowanceParams = None):
self.assert_level_2_auth()
request_args = RequestArgs(method="GET", request_path=GET_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, GET_BALANCE_ALLOWANCE), params
)
Expand Down
1 change: 1 addition & 0 deletions py_clob_client/clob_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class AssetType(enumerate):
class BalanceAllowanceParams:
asset_type: AssetType = None
token_id: str = None
signature_type: int = -1


class OrderType(enumerate):
Expand Down
2 changes: 2 additions & 0 deletions py_clob_client/http_helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def add_balance_allowance_params_to_url(
url = build_query_params(url, "asset_type", params.asset_type.__str__())
if params.token_id:
url = build_query_params(url, "token_id", params.token_id)
if params.signature_type is not None:
url = build_query_params(url, "signature_type", params.signature_type)
return url


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.13.3",
version="0.14.0",
author="Polymarket Engineering",
author_email="[email protected]",
maintainer="Polymarket Engineering",
Expand Down
12 changes: 8 additions & 4 deletions tests/http_helpers/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,21 @@ def test_drop_notifications_query_params(self):
def test_add_balance_allowance_params_to_url(self):
url = add_balance_allowance_params_to_url(
"http://tracker",
BalanceAllowanceParams(asset_type=AssetType.COLLATERAL),
BalanceAllowanceParams(asset_type=AssetType.COLLATERAL, signature_type=0),
)
self.assertIsNotNone(url)
self.assertEqual(url, "http://tracker?asset_type=COLLATERAL")
self.assertEqual(url, "http://tracker?asset_type=COLLATERAL&signature_type=0")

url = add_balance_allowance_params_to_url(
"http://tracker",
BalanceAllowanceParams(asset_type=AssetType.CONDITIONAL, token_id="222"),
BalanceAllowanceParams(
asset_type=AssetType.CONDITIONAL, token_id="222", signature_type=1
),
)
self.assertIsNotNone(url)
self.assertEqual(url, "http://tracker?asset_type=CONDITIONAL&token_id=222")
self.assertEqual(
url, "http://tracker?asset_type=CONDITIONAL&token_id=222&signature_type=1"
)

def test_add_order_scoring_params_to_url(self):
url = add_order_scoring_params_to_url(
Expand Down

0 comments on commit 78600d9

Please sign in to comment.