polymarket-apis 0.3.3__py3-none-any.whl → 0.3.5__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.

Potentially problematic release.


This version of polymarket-apis might be problematic. Click here for more details.

@@ -10,7 +10,7 @@ This package provides a comprehensive interface to Polymarket's APIs including:
10
10
  - GraphQL API for flexible data queries
11
11
  """
12
12
 
13
- __version__ = "0.3.3"
13
+ __version__ = "0.3.5"
14
14
  __author__ = "Razvan Gheorghe"
15
15
  __email__ = "razvan@gheorghe.me"
16
16
 
@@ -1,6 +1,6 @@
1
1
  import json
2
2
  import logging
3
- from datetime import UTC, datetime
3
+ from datetime import UTC, datetime, timedelta
4
4
  from typing import Literal, Optional
5
5
  from urllib.parse import urljoin
6
6
 
@@ -349,12 +349,21 @@ class PolymarketClobClient:
349
349
  def get_recent_history(
350
350
  self,
351
351
  token_id: str,
352
- interval: Optional[Literal["1d", "6h", "1h"]] = "1d",
352
+ interval: Literal["1h", "6h", "1d", "1w", "1m", "max"] = "1d",
353
353
  fidelity: int = 1, # resolution in minutes
354
354
  ) -> PriceHistory:
355
- """Get the recent price history of a token (up to now) - 1h, 6h, 1d."""
356
- if fidelity < 1:
357
- msg = f"invalid filters: minimum 'fidelity' for '{interval}' range is 1"
355
+ """Get the recent price history of a token (up to now) - 1h, 6h, 1d, 1w, 1m."""
356
+ min_fidelities: dict[str, int] = {
357
+ "1h": 1,
358
+ "6h": 1,
359
+ "1d": 1,
360
+ "1w": 5,
361
+ "1m": 10,
362
+ "max": 2,
363
+ }
364
+
365
+ if fidelity < min_fidelities.get(interval):
366
+ msg = f"invalid filters: minimum 'fidelity' for '{interval}' range is {min_fidelities.get(interval)}"
358
367
  raise ValueError(msg)
359
368
 
360
369
  params = {
@@ -371,38 +380,41 @@ class PolymarketClobClient:
371
380
  token_id: str,
372
381
  start_time: Optional[datetime] = None,
373
382
  end_time: Optional[datetime] = None,
374
- interval: Literal["max", "1m", "1w"] = "max",
375
383
  fidelity: int = 2, # resolution in minutes
376
384
  ) -> PriceHistory:
377
- """Get the price history of a token between selected dates - 1m, 1w, max."""
378
- min_fidelities: dict[str, int] = {"1m": 10, "1w": 5, "max": 2}
379
-
380
- if fidelity is None or fidelity < min_fidelities[interval]:
381
- msg = f"invalid filters: minimum 'fidelity' for '{interval}' range is {min_fidelities[interval]}"
382
- raise ValueError(msg)
383
-
385
+ """Get the price history of a token between a selected date range of max 15 days or from start_time to now."""
384
386
  if start_time is None and end_time is None:
385
- msg = "At least one of 'start_time' or 'end_time' must be provided."
387
+ msg = "At least 'start_time' or ('start_time' and 'end_time') must be provided"
386
388
  raise ValueError(msg)
387
389
 
388
- # Default values for timestamps if one is not provided
389
-
390
- if start_time is None:
391
- start_time = datetime(2020, 1, 1, tzinfo=UTC) # Default start time
392
- if end_time is None:
393
- end_time = datetime.now(UTC) # Default end time
390
+ if (
391
+ start_time
392
+ and end_time
393
+ and start_time + timedelta(days=15, seconds=1) < end_time
394
+ ):
395
+ msg = "'start_time' - 'end_time' range cannot exceed 15 days. Remove 'end_time' to get prices up to now or set a shorter range."
396
+ raise ValueError(msg)
394
397
 
395
398
  params = {
396
399
  "market": token_id,
397
- "startTs": int(start_time.timestamp()),
398
- "endTs": int(end_time.timestamp()),
399
- "interval": interval,
400
400
  "fidelity": fidelity,
401
401
  }
402
+ if start_time:
403
+ params["startTs"] = int(start_time.timestamp())
404
+ if end_time:
405
+ params["endTs"] = int(end_time.timestamp())
406
+
402
407
  response = self.client.get(self._build_url("/prices-history"), params=params)
403
408
  response.raise_for_status()
404
409
  return PriceHistory(**response.json(), token_id=token_id)
405
410
 
411
+ def get_all_history(self, token_id: str) -> PriceHistory:
412
+ """Get the full price history of a token."""
413
+ return self.get_history(
414
+ token_id=token_id,
415
+ start_time=datetime(2020, 1, 1, tzinfo=UTC),
416
+ )
417
+
406
418
  def get_orders(
407
419
  self,
408
420
  order_id: Optional[str] = None,
@@ -3,7 +3,7 @@ from datetime import UTC, datetime
3
3
  from typing import Annotated
4
4
 
5
5
  from dateutil import parser
6
- from pydantic import AfterValidator, BaseModel, BeforeValidator, Field
6
+ from pydantic import AfterValidator, BaseModel, BeforeValidator, ConfigDict, Field
7
7
 
8
8
 
9
9
  def validate_keccak256(v: str) -> str:
@@ -30,5 +30,7 @@ EmptyString = Annotated[str, Field(pattern=r"^$", description="An empty string")
30
30
 
31
31
 
32
32
  class TimeseriesPoint(BaseModel):
33
- value: float
34
- timestamp: datetime
33
+ model_config = ConfigDict(populate_by_name=True)
34
+
35
+ value: float = Field(alias="p")
36
+ timestamp: datetime = Field(alias="t")
@@ -28,7 +28,7 @@ def _pack_primitive(typ: str, val: Any) -> bytes:
28
28
  raw = val
29
29
 
30
30
  if typ == "string":
31
- if not isinstance(raw, (bytes, str)):
31
+ if not isinstance(raw, bytes | str):
32
32
  msg = "string value must be str or bytes"
33
33
  raise TypeError(msg)
34
34
  return raw.encode() if isinstance(raw, str) else raw
@@ -47,7 +47,7 @@ def _pack_primitive(typ: str, val: Any) -> bytes:
47
47
  b = raw.to_bytes(n, "big")
48
48
  elif isinstance(raw, str) and raw.startswith("0x"):
49
49
  b = bytes.fromhex(raw[2:])
50
- elif isinstance(raw, (bytes, bytearray)):
50
+ elif isinstance(raw, bytes | bytearray):
51
51
  b = bytes(raw)
52
52
  else:
53
53
  msg = f"unsupported value for {typ}"
@@ -63,7 +63,7 @@ def _pack_primitive(typ: str, val: Any) -> bytes:
63
63
  addr = raw[2:]
64
64
  elif isinstance(raw, str):
65
65
  addr = raw
66
- elif isinstance(raw, (bytes, bytearray)):
66
+ elif isinstance(raw, bytes | bytearray):
67
67
  return bytes(raw[-20:])
68
68
  else:
69
69
  msg = "address must be hex string or bytes"
@@ -75,7 +75,7 @@ def _pack_primitive(typ: str, val: Any) -> bytes:
75
75
  if m:
76
76
  bits = int(m.group(1)) if m.group(1) else 256
77
77
  size = bits // 8
78
- if isinstance(raw, (bytes, bytearray)):
78
+ if isinstance(raw, bytes | bytearray):
79
79
  intval = int.from_bytes(raw, "big")
80
80
  elif isinstance(raw, str) and raw.startswith("0x"):
81
81
  intval = int(raw, 16)
@@ -1,7 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: polymarket-apis
3
- Version: 0.3.3
3
+ Version: 0.3.5
4
4
  Summary: Unified Polymarket APIs with Pydantic data validation - Clob, Gamma, Data, Web3, Websockets, GraphQL clients.
5
+ Project-URL: repository, https://github.com/qualiaenjoyer/polymarket-apis
5
6
  Author-email: Razvan Gheorghe <razvan@gheorghe.me>
6
7
  Requires-Python: >=3.12
7
8
  Requires-Dist: gql[httpx]>=4.0.0
@@ -10,6 +11,7 @@ Requires-Dist: lomond>=0.3.3
10
11
  Requires-Dist: poly-eip712-structs>=0.0.1
11
12
  Requires-Dist: py-order-utils>=0.3.2
12
13
  Requires-Dist: pydantic>=2.10.5
14
+ Requires-Dist: python-dateutil>=2.9.0
13
15
  Requires-Dist: web3>=7.0
14
16
  Requires-Dist: wsaccel>=0.6.7
15
17
  Description-Content-Type: text/markdown
@@ -87,7 +89,9 @@ flowchart LR
87
89
  - check if a **Market** offers rewards by `condition_id` - **get_market_rewards()**
88
90
  - get all active markets that offer rewards sorted by different metrics and ordered, filtered by a query, show your favourites from the web app - **get_reward_markets()** (*naming would do with some work*)
89
91
  - #### Miscellaneous
90
- - get price history
92
+ - get recent price history by `token_id` in the last 1h, 6h, 1d, 1w, 1m
93
+ - get price history by `token_id` in start/end interval
94
+ - get all price history by `token_id` in 2 min increments
91
95
  - get **ClobMarket** by `condition_id`
92
96
  - get all **ClobMarkets**
93
97
 
@@ -1,6 +1,6 @@
1
- polymarket_apis/__init__.py,sha256=hhFBeFCjzptC4uFwwYbCYjh_-8URUhOUeP_elZeCbVw,1126
1
+ polymarket_apis/__init__.py,sha256=Qsw7dvWt7VBTSIGwDJ-TFkWTa1pgTAYCqz9WFnlQGwg,1126
2
2
  polymarket_apis/clients/__init__.py,sha256=ruMvFEA4HNkbWEYqbnrCuYXR4PUwkV1XWG0w63we-LA,759
3
- polymarket_apis/clients/clob_client.py,sha256=dDXkEf31tQnLHC7KsN7UIMfnLDJJFHrJ4VD_WwaTFbI,32102
3
+ polymarket_apis/clients/clob_client.py,sha256=jtPt3xOrywUSKRKDqChpKgTABlIOBQdV7tbfxsBl008,32400
4
4
  polymarket_apis/clients/data_client.py,sha256=SAPxgfWwPK_YuNBOvDxKgUIzdh-hMo2YlnTZ0rFDMXE,12000
5
5
  polymarket_apis/clients/gamma_client.py,sha256=tBR_z03c3wh1_sxFbjNx54DcrFEjFB0TmJiOYNUc_pk,27632
6
6
  polymarket_apis/clients/graphql_client.py,sha256=KgjxbXNWEXp82ZEz464in5mCn1PydnZqWq-g11xu9YU,1839
@@ -8,7 +8,7 @@ polymarket_apis/clients/web3_client.py,sha256=J3j7T39cgZVb4PrYs7FoPoasO3PBP_7SbS
8
8
  polymarket_apis/clients/websockets_client.py,sha256=gaGcsjqp1ZRyxrL6EWvZ9XaTv7koTPDzlcShj0u0B2A,7737
9
9
  polymarket_apis/types/__init__.py,sha256=cyrAPNX0ty0wkMwZqB0lNA7n3JoOJCSeTpclmamMh9k,3258
10
10
  polymarket_apis/types/clob_types.py,sha256=PmD_afx7zowX0cFJ39PQQ4jywGtwNjLfoke1H7iZZnI,11744
11
- polymarket_apis/types/common.py,sha256=RYu6Dfh0HUIogpK_kZ1AQQQEiqQD3hHACU5fMKSUoMU,1003
11
+ polymarket_apis/types/common.py,sha256=zFo10eBj4_3alOhYSilCm6Dh5ZkzhrdR9nuRSDQ_od8,1107
12
12
  polymarket_apis/types/data_types.py,sha256=F6GDhWNtIoQ8kvLvUdlRt596aUfnuc1aHg8m8UweT_M,4641
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
@@ -27,7 +27,7 @@ polymarket_apis/utilities/signing/hmac.py,sha256=1VPfO2yT8nyStk6U4AQeyTzQTt5-69P
27
27
  polymarket_apis/utilities/signing/model.py,sha256=kVduuJGth7WSCUDCVVydCgPd4yEVI85gEmMxohXsvp0,191
28
28
  polymarket_apis/utilities/signing/signer.py,sha256=7-nFALFrz0qg4F4lZRyHI41S7IWxr7t0WMLOHqHzJcg,732
29
29
  polymarket_apis/utilities/web3/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
30
- polymarket_apis/utilities/web3/helpers.py,sha256=QEpBaA_g7DRzFUZAfiKr6kg5T5_u5FaVZ0mGGNzo6mo,4698
30
+ polymarket_apis/utilities/web3/helpers.py,sha256=qzQA-n9rHbuFk57olvBa8P_T6IzrUsaQ2Vv0887EX4o,4694
31
31
  polymarket_apis/utilities/web3/abis/CTFExchange.json,sha256=zt8fZnUaOrD8Vh5njM0EEUpeITWhuu0SZrIZigWxgV8,38499
32
32
  polymarket_apis/utilities/web3/abis/ConditionalTokens.json,sha256=3TUcX7He74VMkoL1kxbDbtULZ70VY_EBe01pfByprsk,12584
33
33
  polymarket_apis/utilities/web3/abis/NegRiskAdapter.json,sha256=HABIoRF1s1NgctpRTdaaNDqzODzgdZLE-s2E6ef4nAY,18867
@@ -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.3.dist-info/METADATA,sha256=5jvX-fOSD09sCoWwBuBEPh_LFDhB4u3nzGVKfPXzRPk,12193
42
- polymarket_apis-0.3.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
43
- polymarket_apis-0.3.3.dist-info/RECORD,,
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,,