From 83edd53faa66c4dcc3b5772503b544c85808ce43 Mon Sep 17 00:00:00 2001 From: RecRanger <168371178+RecRanger@users.noreply.github.com> Date: Thu, 26 Mar 2026 15:41:11 -0600 Subject: [PATCH] Add specific type hints for all `side: str` --- py_clob_client/client.py | 4 ++-- py_clob_client/clob_types.py | 6 +++--- py_clob_client/order_builder/builder.py | 6 ++++-- py_clob_client/rfq/rfq_types.py | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/py_clob_client/client.py b/py_clob_client/client.py index e6be3c56..616921f4 100644 --- a/py_clob_client/client.py +++ b/py_clob_client/client.py @@ -1,7 +1,7 @@ import logging import json import time -from typing import Optional +from typing import Literal, Optional from py_builder_signing_sdk.config import BuilderConfig @@ -1060,7 +1060,7 @@ def get_builder_trades(self, params: TradeParams = None, next_cursor="MA=="): return results def calculate_market_price( - self, token_id: str, side: str, amount: float, order_type: OrderType + self, token_id: str, side: Literal["BUY", "SELL"], amount: float, order_type: OrderType ) -> float: """ Calculates the matching price considering an amount and the current orderbook diff --git a/py_clob_client/clob_types.py b/py_clob_client/clob_types.py index 8811a72a..b1c2e352 100644 --- a/py_clob_client/clob_types.py +++ b/py_clob_client/clob_types.py @@ -39,7 +39,7 @@ class RequestArgs: @dataclass class BookParams: token_id: str - side: str = "" + side: Literal["BUY", "SELL", ""] = "" @dataclass @@ -59,7 +59,7 @@ class OrderArgs: Size in terms of the ConditionalToken """ - side: str + side: Literal["BUY", "SELL"] """ Side of the order """ @@ -98,7 +98,7 @@ class MarketOrderArgs: SELL orders: Shares to sell """ - side: str + side: Literal["BUY", "SELL"] """ Side of the order """ diff --git a/py_clob_client/order_builder/builder.py b/py_clob_client/order_builder/builder.py index 64fb7c96..9e429fc1 100644 --- a/py_clob_client/order_builder/builder.py +++ b/py_clob_client/order_builder/builder.py @@ -1,3 +1,5 @@ +from typing import Literal + from py_order_utils.builders import OrderBuilder as UtilsOrderBuilder from py_order_utils.signer import Signer as UtilsSigner from py_order_utils.model import ( @@ -49,7 +51,7 @@ def __init__(self, signer: Signer, sig_type=None, funder=None): self.funder = funder if funder is not None else self.signer.address() def get_order_amounts( - self, side: str, size: float, price: float, round_config: RoundConfig + self, side: Literal["BUY", "SELL"], size: float, price: float, round_config: RoundConfig ): raw_price = round_normal(price, round_config.price) @@ -83,7 +85,7 @@ def get_order_amounts( raise ValueError(f"order_args.side must be '{BUY}' or '{SELL}'") def get_market_order_amounts( - self, side: str, amount: float, price: float, round_config: RoundConfig + self, side: Literal["BUY", "SELL"], amount: float, price: float, round_config: RoundConfig ): raw_price = round_normal(price, round_config.price) diff --git a/py_clob_client/rfq/rfq_types.py b/py_clob_client/rfq/rfq_types.py index 01d23ab8..471f4e5d 100644 --- a/py_clob_client/rfq/rfq_types.py +++ b/py_clob_client/rfq/rfq_types.py @@ -29,7 +29,7 @@ class RfqUserRequest: price: float """Price per token (0 < price < 1).""" - side: str + side: Literal["BUY", "SELL"] """Order side: "BUY" or "SELL".""" size: float @@ -54,7 +54,7 @@ class RfqUserQuote: price: float """Price per token (0 < price < 1).""" - side: str + side: Literal["BUY", "SELL"] """Quoter's side: "BUY" or "SELL".""" size: float