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

@@ -1,7 +1,8 @@
1
1
  import re
2
- from datetime import datetime
2
+ from datetime import UTC, datetime
3
3
  from typing import Annotated
4
4
 
5
+ from dateutil import parser
5
6
  from pydantic import AfterValidator, BaseModel, BeforeValidator, Field
6
7
 
7
8
 
@@ -12,37 +13,17 @@ def validate_keccak256(v: str) -> str:
12
13
  return v
13
14
 
14
15
 
15
- def parse_timestamp(v: str) -> datetime:
16
- if isinstance(v, datetime):
17
- return v
18
- # Normalize '+00' to '+0000' for timezone
19
- if v.endswith("+00"):
20
- v = v[:-3] + "+0000"
21
-
22
- # Pad fractional seconds to 6 digits if present
23
- if "." in v:
24
- dot_pos = v.find(".")
25
- tz_pos = v.find("+", dot_pos) # Find timezone start after '.'
26
- if tz_pos == -1:
27
- tz_pos = v.find("-", dot_pos)
28
-
29
- if tz_pos != -1:
30
- frac = v[dot_pos + 1 : tz_pos]
31
- if len(frac) < 6:
32
- frac = frac.ljust(6, "0")
33
- v = f"{v[: dot_pos + 1]}{frac}{v[tz_pos:]}"
34
-
35
- # Try parsing with and without microseconds
36
- for fmt in ("%Y-%m-%d %H:%M:%S.%f%z", "%Y-%m-%d %H:%M:%S%z"):
37
- try:
38
- return datetime.strptime(v, fmt) # noqa: DTZ007
39
- except ValueError:
40
- continue
41
- msg = f"Time data '{v}' does not match expected formats."
42
- raise ValueError(msg)
43
-
44
-
45
- TimestampWithTZ = Annotated[datetime, BeforeValidator(parse_timestamp)]
16
+ def parse_flexible_datetime(v: str | datetime) -> datetime:
17
+ """Parse datetime from multiple formats using dateutil."""
18
+ if v in {"NOW*()", "NOW()"}:
19
+ return datetime.fromtimestamp(0, tz=UTC)
20
+
21
+ if isinstance(v, str):
22
+ return parser.parse(v)
23
+ return v
24
+
25
+
26
+ FlexibleDatetime = Annotated[datetime, BeforeValidator(parse_flexible_datetime)]
46
27
  EthAddress = Annotated[str, Field(pattern=r"^0x[A-Fa-f0-9]{40}$")]
47
28
  Keccak256 = Annotated[str, AfterValidator(validate_keccak256)]
48
29
  EmptyString = Annotated[str, Field(pattern=r"^$", description="An empty string")]
@@ -1,5 +1,5 @@
1
1
  from datetime import UTC, datetime
2
- from typing import Literal
2
+ from typing import Literal, Optional
3
3
 
4
4
  from pydantic import BaseModel, Field, field_validator
5
5
 
@@ -162,3 +162,13 @@ class UserMetric(User):
162
162
  class UserRank(User):
163
163
  amount: float
164
164
  rank: int
165
+
166
+
167
+ class MarketValue(BaseModel):
168
+ condition_id: Keccak256 = Field(alias="market")
169
+ value: float
170
+
171
+
172
+ class EventLiveVolume(BaseModel):
173
+ total: Optional[float]
174
+ markets: Optional[list[MarketValue]]