Skip to content

Commit

Permalink
Feat/ is order scoring new endpoint
Browse files Browse the repository at this point in the history
Returns a boolean value where it is indicated if an order is scoring or not.

### HTTP Request

```bash
GET {clob-endpoint}/order-scoring?order_id={...}
```

### Python client

```python
scoring = client.is_order_scoring(
    OrderScoringParams(
        orderId="0xb816482a5187a3d3db49cbaf6fe3ddf24f53e6c712b5a4bf5e01d0ec7b11dabc"
    )
)
print(scoring)
```
  • Loading branch information
poly-rodr committed Mar 20, 2023
1 parent e4a860b commit 8e421bf
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 1 deletion.
31 changes: 31 additions & 0 deletions examples/is_order_scoring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os

from py_clob_client.client import ClobClient
from py_clob_client.clob_types import ApiCreds, OrderScoringParams
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)

scoring = client.is_order_scoring(
OrderScoringParams(
orderId="0xb816482a5187a3d3db49cbaf6fe3ddf24f53e6c712b5a4bf5e01d0ec7b11dabc"
)
)
print(scoring)
print("Done!")


main()
16 changes: 16 additions & 0 deletions py_clob_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
GET_TRADE_NOTIFICATIONS,
DROP_TRADE_NOTIFICATIONS,
GET_BALANCE_ALLOWANCE,
IS_ORDER_SCORING,
)
from .clob_types import (
ApiCreds,
Expand All @@ -36,6 +37,7 @@
TradeNotificationParams,
OrderBookSummary,
BalanceAllowanceParams,
OrderScoringParams,
)
from .exceptions import PolyException
from .http_helpers.helpers import (
Expand All @@ -45,6 +47,7 @@
post,
add_trade_notifications_query_params,
add_balance_allowance_params_to_url,
add_order_scoring_params_to_url,
)
from py_order_utils.config import get_contract_config
from .constants import L0, L1, L1_AUTH_UNAVAILABLE, L2, L2_AUTH_UNAVAILABLE
Expand Down Expand Up @@ -418,3 +421,16 @@ def get_balance_allowance(self, params: BalanceAllowanceParams = None):
"{}{}".format(self.host, GET_BALANCE_ALLOWANCE), params
)
return get(url, headers=headers)

def is_order_scoring(self, params: OrderScoringParams):
"""
Check if the order is currently scoring
Requires Level 2 authentication
"""
self.assert_level_2_auth()
request_args = RequestArgs(method="GET", request_path=IS_ORDER_SCORING)
headers = create_level_2_headers(self.signer, self.creds, request_args)
url = add_order_scoring_params_to_url(
"{}{}".format(self.host, IS_ORDER_SCORING), params
)
return get(url, headers=headers)
5 changes: 5 additions & 0 deletions py_clob_client/clob_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,8 @@ class OrderType(enumerate):
# TODO: add support for FOK orders
FOK = "FOK"
GTD = "GTD"


@dataclass
class OrderScoringParams:
orderId: str
1 change: 1 addition & 0 deletions py_clob_client/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
GET_TRADE_NOTIFICATIONS = "/trade-notifications"
DROP_TRADE_NOTIFICATIONS = "/drop-trade-notifications"
GET_BALANCE_ALLOWANCE = "/balance-allowance"
IS_ORDER_SCORING = "/order-scoring"
15 changes: 15 additions & 0 deletions py_clob_client/http_helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
FilterParams,
TradeNotificationParams,
BalanceAllowanceParams,
OrderScoringParams,
)

from ..exceptions import PolyApiException
Expand Down Expand Up @@ -120,3 +121,17 @@ def add_balance_allowance_params_to_url(
if params.token_id:
url = build_query_params(url, "token_id", params.token_id)
return url


def add_order_scoring_params_to_url(
base_url: str, params: OrderScoringParams = None
) -> str:
"""
Adds query parameters to a url
"""
url = base_url
if params:
url = url + "?"
if params.orderId:
url = build_query_params(url, "order_id", params.orderId)
return url
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.3.0",
version="0.4.0",
author="Polymarket Engineering",
author_email="[email protected]",
maintainer="Polymarket Engineering",
Expand Down
10 changes: 10 additions & 0 deletions tests/http_helpers/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
TradeNotificationParams,
BalanceAllowanceParams,
AssetType,
OrderScoringParams,
)

from py_clob_client.http_helpers.helpers import (
build_query_params,
add_query_params,
add_trade_notifications_query_params,
add_balance_allowance_params_to_url,
add_order_scoring_params_to_url,
)


Expand Down Expand Up @@ -58,3 +60,11 @@ def test_add_balance_allowance_params_to_url(self):
)
self.assertIsNotNone(url)
self.assertEqual(url, "http://tracker?asset_type=CONDITIONAL&token_id=222")

def test_add_order_scoring_params_to_url(self):
url = add_order_scoring_params_to_url(
"http://tracker",
OrderScoringParams(orderId="0x0123abc"),
)
self.assertIsNotNone(url)
self.assertEqual(url, "http://tracker?order_id=0x0123abc")

0 comments on commit 8e421bf

Please sign in to comment.