polymarket-apis 0.3.0__py3-none-any.whl → 0.3.2__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.
- polymarket_apis/__init__.py +41 -0
- polymarket_apis/clients/__init__.py +23 -0
- polymarket_apis/clients/clob_client.py +171 -79
- polymarket_apis/clients/data_client.py +181 -66
- polymarket_apis/clients/gamma_client.py +582 -100
- polymarket_apis/clients/graphql_client.py +28 -11
- polymarket_apis/clients/web3_client.py +131 -60
- polymarket_apis/clients/websockets_client.py +24 -7
- polymarket_apis/types/__init__.py +167 -0
- polymarket_apis/types/clob_types.py +28 -8
- polymarket_apis/types/common.py +15 -32
- polymarket_apis/types/data_types.py +15 -2
- polymarket_apis/types/gamma_types.py +521 -258
- polymarket_apis/types/websockets_types.py +92 -41
- polymarket_apis/utilities/config.py +1 -0
- polymarket_apis/utilities/exceptions.py +5 -0
- polymarket_apis/utilities/order_builder/builder.py +32 -16
- polymarket_apis/utilities/order_builder/helpers.py +0 -1
- polymarket_apis/utilities/signing/hmac.py +5 -1
- polymarket_apis/utilities/web3/abis/custom_contract_errors.py +1 -1
- polymarket_apis/utilities/web3/helpers.py +1 -0
- {polymarket_apis-0.3.0.dist-info → polymarket_apis-0.3.2.dist-info}/METADATA +34 -5
- polymarket_apis-0.3.2.dist-info/RECORD +41 -0
- polymarket_apis/utilities/schemas/activity-subgraph.graphql +0 -86
- polymarket_apis/utilities/schemas/open-interest.graphql +0 -30
- polymarket_apis-0.3.0.dist-info/RECORD +0 -43
- {polymarket_apis-0.3.0.dist-info → polymarket_apis-0.3.2.dist-info}/WHEEL +0 -0
|
@@ -21,6 +21,7 @@ from ..utilities.constants import ZERO_ADDRESS
|
|
|
21
21
|
|
|
22
22
|
logger = logging.getLogger(__name__)
|
|
23
23
|
|
|
24
|
+
|
|
24
25
|
class ApiCreds(BaseModel):
|
|
25
26
|
key: str = Field(alias="apiKey")
|
|
26
27
|
secret: str
|
|
@@ -122,11 +123,13 @@ class Rewards(BaseModel):
|
|
|
122
123
|
rewards_min_size: int = Field(alias="min_size")
|
|
123
124
|
rewards_max_spread: float = Field(alias="max_spread")
|
|
124
125
|
|
|
126
|
+
|
|
125
127
|
class EarnedReward(BaseModel):
|
|
126
128
|
asset_address: EthAddress
|
|
127
129
|
earnings: float
|
|
128
130
|
asset_rate: float
|
|
129
131
|
|
|
132
|
+
|
|
130
133
|
class DailyEarnedReward(BaseModel):
|
|
131
134
|
date: datetime
|
|
132
135
|
asset_address: EthAddress
|
|
@@ -134,12 +137,12 @@ class DailyEarnedReward(BaseModel):
|
|
|
134
137
|
earnings: float
|
|
135
138
|
asset_rate: float
|
|
136
139
|
|
|
137
|
-
|
|
140
|
+
|
|
141
|
+
class RewardMarket(BaseModel):
|
|
138
142
|
market_id: str
|
|
139
143
|
condition_id: Keccak256
|
|
140
144
|
question: str
|
|
141
145
|
market_slug: str
|
|
142
|
-
market_description: str
|
|
143
146
|
event_slug: str
|
|
144
147
|
image: str
|
|
145
148
|
maker_address: EthAddress
|
|
@@ -165,6 +168,7 @@ class MarketRewards(BaseModel):
|
|
|
165
168
|
rewards_min_size: int
|
|
166
169
|
market_competitiveness: float
|
|
167
170
|
|
|
171
|
+
|
|
168
172
|
class ClobMarket(BaseModel):
|
|
169
173
|
# Core market information
|
|
170
174
|
token_ids: list[Token] = Field(alias="tokens")
|
|
@@ -215,7 +219,9 @@ class ClobMarket(BaseModel):
|
|
|
215
219
|
|
|
216
220
|
@field_validator("neg_risk_market_id", "neg_risk_request_id", mode="wrap")
|
|
217
221
|
@classmethod
|
|
218
|
-
def validate_neg_risk_fields(
|
|
222
|
+
def validate_neg_risk_fields(
|
|
223
|
+
cls, value: str, handler: ValidatorFunctionWrapHandler, info: ValidationInfo
|
|
224
|
+
) -> Optional[str]:
|
|
219
225
|
try:
|
|
220
226
|
return handler(value)
|
|
221
227
|
except ValidationError as e:
|
|
@@ -227,12 +233,17 @@ class ClobMarket(BaseModel):
|
|
|
227
233
|
return value
|
|
228
234
|
if neg_risk and value == "":
|
|
229
235
|
for _ in e.errors():
|
|
230
|
-
msg = (
|
|
231
|
-
|
|
236
|
+
msg = (
|
|
237
|
+
"Poorly setup market: negative risk is True, but either neg_risk_market_id or neg_risk_request_id is missing. "
|
|
238
|
+
f" Question: {info.data.get('question')}; Market slug: {info.data.get('market_slug')} \n"
|
|
239
|
+
)
|
|
232
240
|
logger.warning(msg)
|
|
241
|
+
|
|
233
242
|
@field_validator("condition_id", "question_id", mode="wrap")
|
|
234
243
|
@classmethod
|
|
235
|
-
def validate_condition_fields(
|
|
244
|
+
def validate_condition_fields(
|
|
245
|
+
cls, value: str, handler: ValidatorFunctionWrapHandler, info: ValidationInfo
|
|
246
|
+
) -> str:
|
|
236
247
|
try:
|
|
237
248
|
return handler(value)
|
|
238
249
|
except ValueError:
|
|
@@ -241,6 +252,7 @@ class ClobMarket(BaseModel):
|
|
|
241
252
|
return value
|
|
242
253
|
raise
|
|
243
254
|
|
|
255
|
+
|
|
244
256
|
class OpenOrder(BaseModel):
|
|
245
257
|
order_id: Keccak256 = Field(alias="id")
|
|
246
258
|
status: str
|
|
@@ -258,6 +270,7 @@ class OpenOrder(BaseModel):
|
|
|
258
270
|
associate_trades: list[str]
|
|
259
271
|
created_at: datetime
|
|
260
272
|
|
|
273
|
+
|
|
261
274
|
class MakerOrder(BaseModel):
|
|
262
275
|
token_id: str = Field(alias="asset_id")
|
|
263
276
|
order_id: Keccak256
|
|
@@ -268,6 +281,7 @@ class MakerOrder(BaseModel):
|
|
|
268
281
|
outcome: str
|
|
269
282
|
fee_rate_bps: float
|
|
270
283
|
|
|
284
|
+
|
|
271
285
|
class PolygonTrade(BaseModel):
|
|
272
286
|
trade_id: str = Field(alias="id")
|
|
273
287
|
taker_order_id: Keccak256
|
|
@@ -277,7 +291,7 @@ class PolygonTrade(BaseModel):
|
|
|
277
291
|
size: float
|
|
278
292
|
fee_rate_bps: float
|
|
279
293
|
price: float
|
|
280
|
-
status: str
|
|
294
|
+
status: str # change to literals MINED, CONFIRMED
|
|
281
295
|
match_time: datetime
|
|
282
296
|
last_update: datetime
|
|
283
297
|
outcome: str
|
|
@@ -288,6 +302,7 @@ class PolygonTrade(BaseModel):
|
|
|
288
302
|
maker_orders: list[MakerOrder]
|
|
289
303
|
trader_side: Literal["TAKER", "MAKER"]
|
|
290
304
|
|
|
305
|
+
|
|
291
306
|
class TradeParams(BaseModel):
|
|
292
307
|
id: Optional[str] = None
|
|
293
308
|
maker_address: Optional[str] = None
|
|
@@ -304,13 +319,14 @@ class OpenOrderParams(BaseModel):
|
|
|
304
319
|
|
|
305
320
|
|
|
306
321
|
class DropNotificationParams(BaseModel):
|
|
307
|
-
ids: Optional[list[str]]= None
|
|
322
|
+
ids: Optional[list[str]] = None
|
|
308
323
|
|
|
309
324
|
|
|
310
325
|
class OrderSummary(BaseModel):
|
|
311
326
|
price: Optional[float] = None
|
|
312
327
|
size: Optional[float] = None
|
|
313
328
|
|
|
329
|
+
|
|
314
330
|
class PriceLevel(OrderSummary):
|
|
315
331
|
side: Literal["BUY", "SELL"]
|
|
316
332
|
|
|
@@ -375,6 +391,7 @@ class RoundConfig(BaseModel):
|
|
|
375
391
|
size: int
|
|
376
392
|
amount: int
|
|
377
393
|
|
|
394
|
+
|
|
378
395
|
class OrderArgs(BaseModel):
|
|
379
396
|
token_id: str
|
|
380
397
|
"""
|
|
@@ -456,12 +473,14 @@ class MarketOrderArgs(BaseModel):
|
|
|
456
473
|
|
|
457
474
|
order_type: OrderType = OrderType.FOK
|
|
458
475
|
|
|
476
|
+
|
|
459
477
|
class PostOrdersArgs(BaseModel):
|
|
460
478
|
order: SignedOrder
|
|
461
479
|
order_type: OrderType = OrderType.GTC
|
|
462
480
|
|
|
463
481
|
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
464
482
|
|
|
483
|
+
|
|
465
484
|
class ContractConfig(BaseModel):
|
|
466
485
|
"""Contract Configuration."""
|
|
467
486
|
|
|
@@ -489,6 +508,7 @@ class OrderPostResponse(BaseModel):
|
|
|
489
508
|
status: str = Literal["live", "matched", "delayed"]
|
|
490
509
|
success: bool
|
|
491
510
|
|
|
511
|
+
|
|
492
512
|
class OrderCancelResponse(BaseModel):
|
|
493
513
|
not_canceled: Optional[dict[Keccak256, str]]
|
|
494
514
|
canceled: Optional[list[Keccak256]]
|
polymarket_apis/types/common.py
CHANGED
|
@@ -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
|
|
|
@@ -11,41 +12,23 @@ def validate_keccak256(v: str) -> str:
|
|
|
11
12
|
raise ValueError(msg)
|
|
12
13
|
return v
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
tz_pos = v.find("-", dot_pos)
|
|
27
|
-
|
|
28
|
-
if tz_pos != -1:
|
|
29
|
-
frac = v[dot_pos+1:tz_pos]
|
|
30
|
-
if len(frac) < 6:
|
|
31
|
-
frac = frac.ljust(6, "0")
|
|
32
|
-
v = f"{v[:dot_pos+1]}{frac}{v[tz_pos:]}"
|
|
33
|
-
|
|
34
|
-
# Try parsing with and without microseconds
|
|
35
|
-
for fmt in ("%Y-%m-%d %H:%M:%S.%f%z", "%Y-%m-%d %H:%M:%S%z"):
|
|
36
|
-
try:
|
|
37
|
-
return datetime.strptime(v, fmt) # noqa: DTZ007
|
|
38
|
-
except ValueError:
|
|
39
|
-
continue
|
|
40
|
-
msg = f"Time data '{v}' does not match expected formats."
|
|
41
|
-
raise ValueError(msg)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
TimestampWithTZ = Annotated[datetime, BeforeValidator(parse_timestamp)]
|
|
15
|
+
|
|
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)]
|
|
45
27
|
EthAddress = Annotated[str, Field(pattern=r"^0x[A-Fa-f0-9]{40}$")]
|
|
46
28
|
Keccak256 = Annotated[str, AfterValidator(validate_keccak256)]
|
|
47
29
|
EmptyString = Annotated[str, Field(pattern=r"^$", description="An empty string")]
|
|
48
30
|
|
|
31
|
+
|
|
49
32
|
class TimeseriesPoint(BaseModel):
|
|
50
33
|
value: float
|
|
51
34
|
timestamp: datetime
|
|
@@ -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
|
|
|
@@ -44,7 +44,7 @@ class Position(BaseModel):
|
|
|
44
44
|
@field_validator("end_date", mode="before")
|
|
45
45
|
def handle_empty_end_date(cls, v):
|
|
46
46
|
if v == "":
|
|
47
|
-
return datetime(2099,12,31, tzinfo=UTC)
|
|
47
|
+
return datetime(2099, 12, 31, tzinfo=UTC)
|
|
48
48
|
return v
|
|
49
49
|
|
|
50
50
|
|
|
@@ -145,6 +145,7 @@ class ValueResponse(BaseModel):
|
|
|
145
145
|
# Value information
|
|
146
146
|
value: float
|
|
147
147
|
|
|
148
|
+
|
|
148
149
|
class User(BaseModel):
|
|
149
150
|
proxy_wallet: EthAddress = Field(alias="proxyWallet")
|
|
150
151
|
name: str
|
|
@@ -152,10 +153,22 @@ class User(BaseModel):
|
|
|
152
153
|
profile_image: str = Field(alias="profileImage")
|
|
153
154
|
profile_image_optimized: str = Field(alias="profileImageOptimized")
|
|
154
155
|
|
|
156
|
+
|
|
155
157
|
class UserMetric(User):
|
|
156
158
|
amount: float
|
|
157
159
|
pseudonym: str
|
|
158
160
|
|
|
161
|
+
|
|
159
162
|
class UserRank(User):
|
|
160
163
|
amount: float
|
|
161
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]]
|