polymarket-apis 0.3.5__py3-none-any.whl → 0.3.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -221,7 +221,7 @@ class ClobMarket(BaseModel):
221
221
  @classmethod
222
222
  def validate_neg_risk_fields(
223
223
  cls, value: str, handler: ValidatorFunctionWrapHandler, info: ValidationInfo
224
- ) -> Optional[str]:
224
+ ) -> str | None:
225
225
  try:
226
226
  return handler(value)
227
227
  except ValidationError as e:
@@ -238,6 +238,7 @@ class ClobMarket(BaseModel):
238
238
  f" Question: {info.data.get('question')}; Market slug: {info.data.get('market_slug')} \n"
239
239
  )
240
240
  logger.warning(msg)
241
+ return None
241
242
 
242
243
  @field_validator("condition_id", "question_id", mode="wrap")
243
244
  @classmethod
@@ -323,8 +324,8 @@ class DropNotificationParams(BaseModel):
323
324
 
324
325
 
325
326
  class OrderSummary(BaseModel):
326
- price: Optional[float] = None
327
- size: Optional[float] = None
327
+ price: float
328
+ size: float
328
329
 
329
330
 
330
331
  class PriceLevel(OrderSummary):
@@ -505,7 +506,7 @@ class OrderPostResponse(BaseModel):
505
506
  order_id: Union[Keccak256, Literal[""]] = Field(alias="orderID")
506
507
  taking_amount: str = Field(alias="takingAmount")
507
508
  making_amount: str = Field(alias="makingAmount")
508
- status: str = Literal["live", "matched", "delayed"]
509
+ status: Literal["live", "matched", "delayed"]
509
510
  success: bool
510
511
 
511
512
 
@@ -19,7 +19,11 @@ def parse_flexible_datetime(v: str | datetime) -> datetime:
19
19
  return datetime.fromtimestamp(0, tz=UTC)
20
20
 
21
21
  if isinstance(v, str):
22
- return parser.parse(v)
22
+ parsed = parser.parse(v)
23
+ if not isinstance(parsed, datetime):
24
+ msg = f"Failed to parse '{v}' as datetime, got {type(parsed)}"
25
+ raise TypeError(msg)
26
+ return parsed
23
27
  return v
24
28
 
25
29
 
@@ -1,11 +1,43 @@
1
1
  from datetime import UTC, datetime
2
2
  from typing import Literal, Optional
3
3
 
4
- from pydantic import BaseModel, Field, field_validator
4
+ from pydantic import BaseModel, Field, field_validator, model_validator
5
5
 
6
6
  from .common import EmptyString, EthAddress, Keccak256
7
7
 
8
8
 
9
+ class GQLPosition(BaseModel):
10
+ user: EthAddress
11
+ token_id: str
12
+ complementary_token_id: str
13
+ condition_id: Keccak256
14
+ outcome_index: int
15
+ balance: float
16
+
17
+ @model_validator(mode="before")
18
+ def _flatten(cls, values):
19
+ asset = values.get("asset")
20
+ if isinstance(asset, dict):
21
+ if "id" in asset:
22
+ values.setdefault("token_id", asset["id"])
23
+ if "complement" in asset:
24
+ values.setdefault("complementary_token_id", asset["complement"])
25
+ condition = asset.get("condition")
26
+ if isinstance(condition, dict) and "id" in condition:
27
+ values.setdefault("condition_id", condition["id"])
28
+ if "outcomeIndex" in asset:
29
+ values.setdefault("outcome_index", asset["outcomeIndex"])
30
+ values.pop("asset", None)
31
+ return values
32
+
33
+ @field_validator("balance", mode="before")
34
+ @classmethod
35
+ def _parse_balance(cls, value):
36
+ if isinstance(value, str):
37
+ value = int(value)
38
+ return value / 10**6
39
+
40
+
9
41
  class Position(BaseModel):
10
42
  # User identification
11
43
  proxy_wallet: EthAddress = Field(alias="proxyWallet")
@@ -1,3 +1,5 @@
1
+ from typing import Literal
2
+
1
3
  # Access levels
2
4
  L0 = 0
3
5
  L1 = 1
@@ -17,9 +19,8 @@ L2_AUTH_UNAVAILABLE = "API Credentials are needed to interact with this endpoint
17
19
  ADDRESS_ZERO = "0x0000000000000000000000000000000000000000"
18
20
  HASH_ZERO = "0x0000000000000000000000000000000000000000000000000000000000000000"
19
21
 
20
- AMOY = 80002
21
- POLYGON = 137
22
-
22
+ AMOY: Literal[80002] = 80002
23
+ POLYGON: Literal[137] = 137
23
24
  END_CURSOR = "LTE="
24
25
 
25
26
  BUY = "BUY"
@@ -221,10 +221,10 @@ class OrderBuilder:
221
221
  msg = "No ask orders available"
222
222
  raise LiquidityError(msg)
223
223
 
224
- sum = 0
224
+ amount = 0.0
225
225
  for p in reversed(asks):
226
- sum += float(p.size) * float(p.price)
227
- if sum >= amount_to_match:
226
+ amount += float(p.size) * float(p.price)
227
+ if amount >= amount_to_match:
228
228
  return float(p.price)
229
229
 
230
230
  if order_type == OrderType.FOK:
@@ -245,10 +245,10 @@ class OrderBuilder:
245
245
  msg = "No bid orders available"
246
246
  raise LiquidityError(msg)
247
247
 
248
- sum = 0
248
+ amount = 0.0
249
249
  for p in reversed(bids):
250
- sum += float(p.size)
251
- if sum >= amount_to_match:
250
+ amount += float(p.size)
251
+ if amount >= amount_to_match:
252
252
  return float(p.price)
253
253
 
254
254
  if order_type == OrderType.FOK:
@@ -11,7 +11,7 @@ class Signer:
11
11
  raise ValueError(msg)
12
12
 
13
13
  self.private_key = private_key
14
- self.account = Account.from_key(private_key)
14
+ self.account = Account.from_key(private_key) # type: ignore[misc]
15
15
  self.chain_id = chain_id
16
16
 
17
17
  def address(self):
@@ -22,4 +22,4 @@ class Signer:
22
22
 
23
23
  def sign(self, message_hash):
24
24
  """Signs a message hash."""
25
- return Account.unsafe_sign_hash(message_hash, self.private_key).signature.hex()
25
+ return Account.unsafe_sign_hash(message_hash, self.private_key).signature.hex() # type: ignore[misc]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: polymarket-apis
3
- Version: 0.3.5
3
+ Version: 0.3.7
4
4
  Summary: Unified Polymarket APIs with Pydantic data validation - Clob, Gamma, Data, Web3, Websockets, GraphQL clients.
5
5
  Project-URL: repository, https://github.com/qualiaenjoyer/polymarket-apis
6
6
  Author-email: Razvan Gheorghe <razvan@gheorghe.me>
@@ -155,7 +155,10 @@ flowchart LR
155
155
  - get top users on the profit/volume leaderboards (at most 100) for a recent window (1d, 7d, 30d, all)
156
156
 
157
157
  ### PolymarketWeb3Client - Blockchain related operations
158
- - #### Supporting both Email/Magic wallets (signature_type=1) and Safe/Gnosis wallets (signature_type=2)
158
+ - #### Supporting EOA(signature_type=0), Email/Magic wallets (signature_type=1) and Safe/Gnosis wallets (signature_type=2)
159
+ - #### Approvals
160
+ - set approvals for all needed usdc and conditional token spenders (needed for full trading functionality)
161
+ - Safe/Gnosis wallets need to be deployed beforehand, either via "Enable Trading" pop-up on the web UI or by calling createProxy on the SafeWalletFactory contract (wip)
159
162
  - #### Balance
160
163
  - get usdc balance by user address
161
164
  - get token balance by `token_id` and user address
@@ -1,31 +1,31 @@
1
- polymarket_apis/__init__.py,sha256=Qsw7dvWt7VBTSIGwDJ-TFkWTa1pgTAYCqz9WFnlQGwg,1126
1
+ polymarket_apis/__init__.py,sha256=OzhWc-PqnHoGyrcRwclQG2mLGSu0cz7QLuhx-jenzgk,1126
2
2
  polymarket_apis/clients/__init__.py,sha256=ruMvFEA4HNkbWEYqbnrCuYXR4PUwkV1XWG0w63we-LA,759
3
- polymarket_apis/clients/clob_client.py,sha256=jtPt3xOrywUSKRKDqChpKgTABlIOBQdV7tbfxsBl008,32400
4
- polymarket_apis/clients/data_client.py,sha256=SAPxgfWwPK_YuNBOvDxKgUIzdh-hMo2YlnTZ0rFDMXE,12000
5
- polymarket_apis/clients/gamma_client.py,sha256=tBR_z03c3wh1_sxFbjNx54DcrFEjFB0TmJiOYNUc_pk,27632
3
+ polymarket_apis/clients/clob_client.py,sha256=Eo5zXYtI_Ct0EByzjJnH6h7FLHOqheXDujBA57CtINw,32485
4
+ polymarket_apis/clients/data_client.py,sha256=0--2W6_DZtC7cRud8OYS7bH2heWzn2NwvcUVK3PyEwU,13242
5
+ polymarket_apis/clients/gamma_client.py,sha256=iDfuaClhRK2Y5v8ZA03Qbne3CnIM4JJolHo-qUrQV78,27633
6
6
  polymarket_apis/clients/graphql_client.py,sha256=KgjxbXNWEXp82ZEz464in5mCn1PydnZqWq-g11xu9YU,1839
7
- polymarket_apis/clients/web3_client.py,sha256=J3j7T39cgZVb4PrYs7FoPoasO3PBP_7SbSuQzA--m64,20162
7
+ polymarket_apis/clients/web3_client.py,sha256=Xsk1APsnMDRu9daLKZnf6LW41LdocuRV9rqjKnZjYmw,26400
8
8
  polymarket_apis/clients/websockets_client.py,sha256=gaGcsjqp1ZRyxrL6EWvZ9XaTv7koTPDzlcShj0u0B2A,7737
9
9
  polymarket_apis/types/__init__.py,sha256=cyrAPNX0ty0wkMwZqB0lNA7n3JoOJCSeTpclmamMh9k,3258
10
- polymarket_apis/types/clob_types.py,sha256=PmD_afx7zowX0cFJ39PQQ4jywGtwNjLfoke1H7iZZnI,11744
11
- polymarket_apis/types/common.py,sha256=zFo10eBj4_3alOhYSilCm6Dh5ZkzhrdR9nuRSDQ_od8,1107
12
- polymarket_apis/types/data_types.py,sha256=F6GDhWNtIoQ8kvLvUdlRt596aUfnuc1aHg8m8UweT_M,4641
10
+ polymarket_apis/types/clob_types.py,sha256=WZs370ni2B2UsLW-yIPGA2C-z8dfbywX26vADuu2YFc,11725
11
+ polymarket_apis/types/common.py,sha256=OYvn-BIbLM5YHNiZCi9ttqbqfPjRdvFhBE192EsBIdQ,1284
12
+ polymarket_apis/types/data_types.py,sha256=vBElvARw8LkH2xXwJkVErpQo0FkXJA3b44hKD5clSOI,5729
13
13
  polymarket_apis/types/gamma_types.py,sha256=MoIUI6csqEp_vij7mkFi2IlIA99c5UNzI3zODSONWzQ,30641
14
14
  polymarket_apis/types/websockets_types.py,sha256=XGTpfix2rFFQg-97ZkPagS_tHJJpSnB5mCMf_sT2MOI,11180
15
15
  polymarket_apis/utilities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  polymarket_apis/utilities/config.py,sha256=kQymQRy9fVg5jt8CcQJxsSgIZFbfjPx2q_gNnZI5b24,2449
17
- polymarket_apis/utilities/constants.py,sha256=rGX-XXu5tLy2yUurFQCQNRtSvZPPcRAUCmjlqVtTAvY,580
17
+ polymarket_apis/utilities/constants.py,sha256=TzFVtN8zNgvEa4yjLWjpvPYsAi1LLV5oPEnHlbwxSDQ,637
18
18
  polymarket_apis/utilities/endpoints.py,sha256=bxZyrJBPbVauWc-eR0RMh6KDqU-SmO_3LfQwVMNJ6vE,1235
19
19
  polymarket_apis/utilities/exceptions.py,sha256=nLVkwGNkX8mBhOi3L3lLEJ5UCPd5OBjl2f7kcct3K3A,368
20
20
  polymarket_apis/utilities/headers.py,sha256=Cc5WEnIBLYAgfwvmCXRBwA2zUYME8fDy4PbwlwlB6Oo,1510
21
21
  polymarket_apis/utilities/order_builder/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
- polymarket_apis/utilities/order_builder/builder.py,sha256=1SXgJlKlutRqMA1iBtZcw5K6CWI379d4wXZ5pdNgs0M,8454
22
+ polymarket_apis/utilities/order_builder/builder.py,sha256=dyxKhMeNjGyHXEIFBBZhWwI8TaQQcE_ErQ4sF6BcMX0,8476
23
23
  polymarket_apis/utilities/order_builder/helpers.py,sha256=2-UYDLntYOXjyN0ZDQI13jW2zwXwIODEK-smBRFTYRk,1943
24
24
  polymarket_apis/utilities/signing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
25
  polymarket_apis/utilities/signing/eip712.py,sha256=fGLurznnfY5M0VCP1Txyq_FYQRfggyHoTwz-PGIK2Eg,895
26
26
  polymarket_apis/utilities/signing/hmac.py,sha256=1VPfO2yT8nyStk6U4AQeyTzQTt5-69PTw24Gdt5YOMo,718
27
27
  polymarket_apis/utilities/signing/model.py,sha256=kVduuJGth7WSCUDCVVydCgPd4yEVI85gEmMxohXsvp0,191
28
- polymarket_apis/utilities/signing/signer.py,sha256=7-nFALFrz0qg4F4lZRyHI41S7IWxr7t0WMLOHqHzJcg,732
28
+ polymarket_apis/utilities/signing/signer.py,sha256=cxjcYRn1a0ApVcir1AvamsFcLZ0rYNlEEX4sPUz_Nrw,776
29
29
  polymarket_apis/utilities/web3/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
30
30
  polymarket_apis/utilities/web3/helpers.py,sha256=qzQA-n9rHbuFk57olvBa8P_T6IzrUsaQ2Vv0887EX4o,4694
31
31
  polymarket_apis/utilities/web3/abis/CTFExchange.json,sha256=zt8fZnUaOrD8Vh5njM0EEUpeITWhuu0SZrIZigWxgV8,38499
@@ -38,6 +38,6 @@ polymarket_apis/utilities/web3/abis/SafeProxyFactory.json,sha256=bdr2WdYCRClXLTT
38
38
  polymarket_apis/utilities/web3/abis/UChildERC20Proxy.json,sha256=ZyQC38U0uxInlmnW2VXDVD3TJfTIRmSNMkTxQsaG7oA,27396
39
39
  polymarket_apis/utilities/web3/abis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
40
40
  polymarket_apis/utilities/web3/abis/custom_contract_errors.py,sha256=GjCVn2b6iRheT7s-kc8Po9uwH9LfaHA1yRpJyjXRcxs,1172
41
- polymarket_apis-0.3.5.dist-info/METADATA,sha256=omavoehsTPIj6xjEvkp5gbU5TSZhUG827ROn9_S6xNk,12479
42
- polymarket_apis-0.3.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
43
- polymarket_apis-0.3.5.dist-info/RECORD,,
41
+ polymarket_apis-0.3.7.dist-info/METADATA,sha256=Z3jOxzSY7thon83qiZQbeZ_8sCebx2BKCVRKR-acFjA,12802
42
+ polymarket_apis-0.3.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
43
+ polymarket_apis-0.3.7.dist-info/RECORD,,