polymarket-apis 0.3.0__py3-none-any.whl → 0.3.1__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 +169 -77
- polymarket_apis/clients/data_client.py +86 -61
- polymarket_apis/clients/gamma_client.py +92 -74
- 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 +195 -0
- polymarket_apis/types/clob_types.py +28 -8
- polymarket_apis/types/common.py +5 -3
- polymarket_apis/types/data_types.py +4 -1
- polymarket_apis/types/gamma_types.py +27 -8
- polymarket_apis/types/websockets_types.py +106 -27
- 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.1.dist-info}/METADATA +6 -3
- polymarket_apis-0.3.1.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.1.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
|
@@ -11,6 +11,7 @@ def validate_keccak256(v: str) -> str:
|
|
|
11
11
|
raise ValueError(msg)
|
|
12
12
|
return v
|
|
13
13
|
|
|
14
|
+
|
|
14
15
|
def parse_timestamp(v: str) -> datetime:
|
|
15
16
|
if isinstance(v, datetime):
|
|
16
17
|
return v
|
|
@@ -26,15 +27,15 @@ def parse_timestamp(v: str) -> datetime:
|
|
|
26
27
|
tz_pos = v.find("-", dot_pos)
|
|
27
28
|
|
|
28
29
|
if tz_pos != -1:
|
|
29
|
-
frac = v[dot_pos+1:tz_pos]
|
|
30
|
+
frac = v[dot_pos + 1 : tz_pos]
|
|
30
31
|
if len(frac) < 6:
|
|
31
32
|
frac = frac.ljust(6, "0")
|
|
32
|
-
v = f"{v[:dot_pos+1]}{frac}{v[tz_pos:]}"
|
|
33
|
+
v = f"{v[: dot_pos + 1]}{frac}{v[tz_pos:]}"
|
|
33
34
|
|
|
34
35
|
# Try parsing with and without microseconds
|
|
35
36
|
for fmt in ("%Y-%m-%d %H:%M:%S.%f%z", "%Y-%m-%d %H:%M:%S%z"):
|
|
36
37
|
try:
|
|
37
|
-
return datetime.strptime(v, fmt)
|
|
38
|
+
return datetime.strptime(v, fmt) # noqa: DTZ007
|
|
38
39
|
except ValueError:
|
|
39
40
|
continue
|
|
40
41
|
msg = f"Time data '{v}' does not match expected formats."
|
|
@@ -46,6 +47,7 @@ EthAddress = Annotated[str, Field(pattern=r"^0x[A-Fa-f0-9]{40}$")]
|
|
|
46
47
|
Keccak256 = Annotated[str, AfterValidator(validate_keccak256)]
|
|
47
48
|
EmptyString = Annotated[str, Field(pattern=r"^$", description="An empty string")]
|
|
48
49
|
|
|
50
|
+
|
|
49
51
|
class TimeseriesPoint(BaseModel):
|
|
50
52
|
value: float
|
|
51
53
|
timestamp: datetime
|
|
@@ -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,12 @@ 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
|
|
@@ -95,7 +95,9 @@ class GammaMarket(BaseModel):
|
|
|
95
95
|
description: str
|
|
96
96
|
resolution_source: Optional[str] = Field(None, alias="resolutionSource")
|
|
97
97
|
outcome: Optional[list] = None
|
|
98
|
-
outcome_prices: Optional[Json[list[float]] | list[float]] = Field(
|
|
98
|
+
outcome_prices: Optional[Json[list[float]] | list[float]] = Field(
|
|
99
|
+
None, alias="outcomePrices"
|
|
100
|
+
)
|
|
99
101
|
|
|
100
102
|
# Media URLs
|
|
101
103
|
image: Optional[str] = None
|
|
@@ -109,7 +111,9 @@ class GammaMarket(BaseModel):
|
|
|
109
111
|
start_date_iso: Optional[datetime] = Field(None, alias="startDateIso")
|
|
110
112
|
end_date_iso: Optional[datetime] = Field(None, alias="endDateIso")
|
|
111
113
|
deployed_timestamp: Optional[datetime] = Field(None, alias="deployedTimestamp")
|
|
112
|
-
accepting_orders_timestamp: Optional[datetime] = Field(
|
|
114
|
+
accepting_orders_timestamp: Optional[datetime] = Field(
|
|
115
|
+
None, alias="acceptingOrdersTimestamp"
|
|
116
|
+
)
|
|
113
117
|
|
|
114
118
|
# Status flags
|
|
115
119
|
active: bool
|
|
@@ -139,7 +143,8 @@ class GammaMarket(BaseModel):
|
|
|
139
143
|
# Order book settings
|
|
140
144
|
enable_order_book: Optional[bool] = Field(None, alias="enableOrderBook")
|
|
141
145
|
order_price_min_tick_size: Optional[float] = Field(
|
|
142
|
-
None,
|
|
146
|
+
None,
|
|
147
|
+
alias="orderPriceMinTickSize",
|
|
143
148
|
)
|
|
144
149
|
order_min_size: Optional[float] = Field(None, alias="orderMinSize")
|
|
145
150
|
accepting_orders: Optional[bool] = Field(None, alias="acceptingOrders")
|
|
@@ -174,7 +179,10 @@ class GammaMarket(BaseModel):
|
|
|
174
179
|
@field_validator("condition_id", mode="wrap")
|
|
175
180
|
@classmethod
|
|
176
181
|
def validate_condition_id(
|
|
177
|
-
|
|
182
|
+
cls,
|
|
183
|
+
value: str,
|
|
184
|
+
handler: ValidatorFunctionWrapHandler,
|
|
185
|
+
info: ValidationInfo,
|
|
178
186
|
) -> str:
|
|
179
187
|
try:
|
|
180
188
|
# First attempt standard Keccak256 validation
|
|
@@ -189,6 +197,7 @@ class GammaMarket(BaseModel):
|
|
|
189
197
|
# Re-raise original error for other cases
|
|
190
198
|
raise
|
|
191
199
|
|
|
200
|
+
|
|
192
201
|
class ClobReward(BaseModel):
|
|
193
202
|
# Identifiers
|
|
194
203
|
id: str
|
|
@@ -215,7 +224,9 @@ class Tag(BaseModel):
|
|
|
215
224
|
force_hide: Optional[bool] = Field(None, alias="forceHide")
|
|
216
225
|
|
|
217
226
|
# Datetime
|
|
218
|
-
published_at: Optional[TimestampWithTZ | datetime] = Field(
|
|
227
|
+
published_at: Optional[TimestampWithTZ | datetime] = Field(
|
|
228
|
+
None, alias="publishedAt"
|
|
229
|
+
)
|
|
219
230
|
created_at: Optional[datetime] = Field(None, alias="createdAt")
|
|
220
231
|
updated_at: Optional[datetime] = Field(None, alias="updatedAt")
|
|
221
232
|
|
|
@@ -232,7 +243,7 @@ class Series(BaseModel):
|
|
|
232
243
|
title: str
|
|
233
244
|
|
|
234
245
|
# Series characteristics
|
|
235
|
-
series_type: Optional[str] = Field(None,
|
|
246
|
+
series_type: Optional[str] = Field(None, alias="seriesType")
|
|
236
247
|
recurrence: Optional[str] = None
|
|
237
248
|
layout: Optional[str] = None
|
|
238
249
|
|
|
@@ -244,7 +255,9 @@ class Series(BaseModel):
|
|
|
244
255
|
start_date: Optional[datetime] = Field(None, alias="startDate")
|
|
245
256
|
created_at: datetime = Field(alias="createdAt")
|
|
246
257
|
updated_at: Optional[datetime] = Field(None, alias="updatedAt")
|
|
247
|
-
published_at: Optional[TimestampWithTZ | datetime] = Field(
|
|
258
|
+
published_at: Optional[TimestampWithTZ | datetime] = Field(
|
|
259
|
+
None, alias="publishedAt"
|
|
260
|
+
)
|
|
248
261
|
|
|
249
262
|
# Status flags
|
|
250
263
|
active: Optional[bool] = None
|
|
@@ -268,6 +281,7 @@ class Series(BaseModel):
|
|
|
268
281
|
created_by: Optional[str] = Field(None, alias="createdBy")
|
|
269
282
|
updated_by: Optional[str] = Field(None, alias="updatedBy")
|
|
270
283
|
|
|
284
|
+
|
|
271
285
|
class QueryEvent(BaseModel):
|
|
272
286
|
# Identifiers and description
|
|
273
287
|
id: str
|
|
@@ -327,14 +341,17 @@ class QueryEvent(BaseModel):
|
|
|
327
341
|
show_all_outcomes: bool = Field(alias="showAllOutcomes")
|
|
328
342
|
show_market_images: bool = Field(alias="showMarketImages")
|
|
329
343
|
|
|
344
|
+
|
|
330
345
|
class Pagination(BaseModel):
|
|
331
346
|
has_more: bool = Field(alias="hasMore")
|
|
332
347
|
total_results: int = Field(alias="totalResults")
|
|
333
348
|
|
|
349
|
+
|
|
334
350
|
class EventList(BaseModel):
|
|
335
351
|
events: Optional[list[QueryEvent]] = None
|
|
336
352
|
pagination: Pagination
|
|
337
353
|
|
|
354
|
+
|
|
338
355
|
class QueryMarket(BaseModel):
|
|
339
356
|
# Identifiers
|
|
340
357
|
slug: str
|
|
@@ -343,7 +360,9 @@ class QueryMarket(BaseModel):
|
|
|
343
360
|
|
|
344
361
|
# Market data
|
|
345
362
|
outcomes: Optional[list] = None
|
|
346
|
-
outcome_prices: Optional[Json[list[float]] | list[float]] = Field(
|
|
363
|
+
outcome_prices: Optional[Json[list[float]] | list[float]] = Field(
|
|
364
|
+
None, alias="outcomePrices"
|
|
365
|
+
)
|
|
347
366
|
last_trade_price: Optional[float] = Field(None, alias="lastTradePrice")
|
|
348
367
|
best_ask: Optional[float] = Field(None, alias="bestAsk")
|
|
349
368
|
best_bid: Optional[float] = Field(None, alias="bestBid")
|