Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Polymarket/py-clob-client
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.17.3
Choose a base ref
...
head repository: Polymarket/py-clob-client
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 14 commits
  • 10 files changed
  • 3 contributors

Commits on Jul 19, 2024

  1. Neg Risk Flag Resolution (#87)

    * neg risk flag resolution
    
    * neg risk cache
    
    * spacing
    
    * semver
    
    * update CreateOrderOptions in tests
    mshrieve authored Jul 19, 2024
    Copy the full SHA
    e142aa1 View commit details

Commits on Jul 29, 2024

  1. Copy the full SHA
    c0bdc1f View commit details
  2. Merge pull request #90 from Polymarket/fix/sig-fixes

    Fix: prepend_zx to struct hashes and sigs if they are missing
    JonathanAmenechi authored Jul 29, 2024
    Copy the full SHA
    e712c58 View commit details

Commits on Sep 24, 2024

  1. Copy the full SHA
    03f24d0 View commit details
  2. tests

    poly-rodr committed Sep 24, 2024
    Copy the full SHA
    1a155ef View commit details
  3. test

    poly-rodr committed Sep 24, 2024
    Copy the full SHA
    ec990bb View commit details
  4. test

    poly-rodr committed Sep 24, 2024
    Copy the full SHA
    53763f3 View commit details
  5. test

    poly-rodr committed Sep 24, 2024
    Copy the full SHA
    84efcc8 View commit details
  6. test

    poly-rodr committed Sep 24, 2024
    Copy the full SHA
    1ab7251 View commit details
  7. version

    poly-rodr committed Sep 24, 2024
    Copy the full SHA
    3a85a35 View commit details
  8. test

    poly-rodr committed Sep 24, 2024
    Copy the full SHA
    3989a19 View commit details
  9. Merge pull request #96 from Polymarket/feat/orderbook-ts

    Adding `timestamp` to orderbook summaries
    poly-rodr authored Sep 24, 2024
    Copy the full SHA
    9d35d1c View commit details

Commits on Dec 17, 2024

  1. Copy the full SHA
    4a331f5 View commit details
  2. Merge pull request #105 from Polymarket/chore/github-workflows-warnings

    chore/github-workflows-warnings
    poly-rodr authored Dec 17, 2024
    Copy the full SHA
    8ced202 View commit details
10 changes: 7 additions & 3 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
@@ -2,16 +2,20 @@ name: Test

on:
push:
branches: [ main ]
branches: [main]
pull_request:

jobs:
build-lint-test:
name: Test
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: Checkout Code
uses: actions/checkout@v4.1.7
with:
persist-credentials: false

- uses: actions/setup-python@v5
with:
python-version: 3.9.10

35 changes: 31 additions & 4 deletions py_clob_client/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from typing import Optional

from .order_builder.builder import OrderBuilder
from .headers.headers import create_level_1_headers, create_level_2_headers
@@ -29,6 +30,7 @@
UPDATE_BALANCE_ALLOWANCE,
IS_ORDER_SCORING,
GET_TICK_SIZE,
GET_NEG_RISK,
ARE_ORDERS_SCORING,
GET_SIMPLIFIED_MARKETS,
GET_MARKETS,
@@ -115,7 +117,11 @@ def __init__(
self.builder = OrderBuilder(
self.signer, sig_type=signature_type, funder=funder
)

# local cache
self.__tick_sizes = {}
self.__neg_risk = {}

self.logger = logging.getLogger(self.__class__.__name__)

def get_address(self):
@@ -290,6 +296,15 @@ def get_tick_size(self, token_id: str) -> TickSize:

return self.__tick_sizes[token_id]

def get_neg_risk(self, token_id: str) -> bool:
if token_id in self.__neg_risk:
return self.__neg_risk[token_id]

result = get("{}{}?token_id={}".format(self.host, GET_NEG_RISK, token_id))
self.__neg_risk[token_id] = result["neg_risk"]

return result["neg_risk"]

def __resolve_tick_size(
self, token_id: str, tick_size: TickSize = None
) -> TickSize:
@@ -307,7 +322,7 @@ def __resolve_tick_size(
return tick_size

def create_order(
self, order_args: OrderArgs, options: PartialCreateOrderOptions = None
self, order_args: OrderArgs, options: Optional[PartialCreateOrderOptions] = None
):
"""
Creates and signs an order
@@ -320,7 +335,6 @@ def create_order(
order_args.token_id,
options.tick_size if options else None,
)
neg_risk = options.neg_risk if options else False

if not price_valid(order_args.price, tick_size):
raise Exception(
@@ -332,6 +346,12 @@ def create_order(
+ str(1 - float(tick_size))
)

neg_risk = (
options.neg_risk
if options and options.neg_risk
else self.get_neg_risk(order_args.token_id)
)

return self.builder.create_order(
order_args,
CreateOrderOptions(
@@ -341,7 +361,9 @@ def create_order(
)

def create_market_order(
self, order_args: MarketOrderArgs, options: PartialCreateOrderOptions = None
self,
order_args: MarketOrderArgs,
options: Optional[PartialCreateOrderOptions] = None,
):
"""
Creates and signs an order
@@ -354,7 +376,6 @@ def create_market_order(
order_args.token_id,
options.tick_size if options else None,
)
neg_risk = options.neg_risk if options else False

if order_args.price is None or order_args.price <= 0:
order_args.price = self.calculate_market_price(
@@ -371,6 +392,12 @@ def create_market_order(
+ str(1 - float(tick_size))
)

neg_risk = (
options.neg_risk
if options and options.neg_risk
else self.get_neg_risk(order_args.token_id)
)

return self.builder.create_market_order(
order_args,
CreateOrderOptions(
6 changes: 3 additions & 3 deletions py_clob_client/clob_types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from dataclasses import dataclass
from typing import Any
from dataclasses import dataclass, asdict
from json import dumps
@@ -143,6 +142,7 @@ def json(self):
class OrderBookSummary:
market: str = None
asset_id: str = None
timestamp: str = None
bids: list[OrderSummary] = None
asks: list[OrderSummary] = None
hash: str = None
@@ -190,13 +190,13 @@ class OrdersScoringParams:
@dataclass
class CreateOrderOptions:
tick_size: TickSize
neg_risk: bool = False
neg_risk: bool


@dataclass
class PartialCreateOrderOptions:
tick_size: Optional[TickSize] = None
neg_risk: bool = False
neg_risk: Optional[bool] = None


@dataclass
1 change: 1 addition & 0 deletions py_clob_client/endpoints.py
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@
IS_ORDER_SCORING = "/order-scoring"
ARE_ORDERS_SCORING = "/orders-scoring"
GET_TICK_SIZE = "/tick-size"
GET_NEG_RISK = "/neg-risk"
GET_SAMPLING_SIMPLIFIED_MARKETS = "/sampling-simplified-markets"
GET_SAMPLING_MARKETS = "/sampling-markets"
GET_SIMPLIFIED_MARKETS = "/simplified-markets"
8 changes: 4 additions & 4 deletions py_clob_client/signing/eip712.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from poly_eip712_structs import make_domain
from eth_utils import keccak
from py_order_utils.utils import prepend_zx

from .model import ClobAuth
from ..signer import Signer
@@ -21,8 +22,7 @@ def sign_clob_auth_message(signer: Signer, timestamp: int, nonce: int) -> str:
message=MSG_TO_SIGN,
)
chain_id = signer.get_chain_id()
auth_struct_hash = (
"0x"
+ keccak(clob_auth_msg.signable_bytes(get_clob_auth_domain(chain_id))).hex()
auth_struct_hash = prepend_zx(
keccak(clob_auth_msg.signable_bytes(get_clob_auth_domain(chain_id))).hex()
)
return "0x" + signer.sign(auth_struct_hash)
return prepend_zx(signer.sign(auth_struct_hash))
1 change: 1 addition & 0 deletions py_clob_client/utilities.py
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ def parse_raw_orderbook_summary(raw_obs: any) -> OrderBookSummary:
orderbookSummary = OrderBookSummary(
market=raw_obs["market"],
asset_id=raw_obs["asset_id"],
timestamp=raw_obs["timestamp"],
bids=bids,
asks=asks,
hash=raw_obs["hash"],
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ black==24.4.2
eth-account===0.13.0
eth-utils===4.1.1
poly_eip712_structs==0.0.1
py_order_utils==0.3.1
py_order_utils==0.3.2
pytest==8.2.2
python-dotenv==0.19.2
requests==2.32.3
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@

setuptools.setup(
name="py_clob_client",
version="0.17.3",
version="0.18.0",
author="Polymarket Engineering",
author_email="engineering@polymarket.com",
maintainer="Polymarket Engineering",
@@ -18,7 +18,7 @@
"eth-account>=0.13.0",
"eth-utils>=4.1.1",
"poly_eip712_structs>=0.0.1",
"py-order-utils>=0.3.1",
"py-order-utils>=0.3.2",
"python-dotenv",
"requests",
],
Loading