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
polymarket_apis/__init__.py
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Polymarket APIs - Unified interface for Polymarket's various APIs.
|
|
3
|
+
|
|
4
|
+
This package provides a comprehensive interface to Polymarket's APIs including:
|
|
5
|
+
- CLOB (Central Limit Order Book) API for trading
|
|
6
|
+
- Gamma API for event and market information
|
|
7
|
+
- Data API for user information
|
|
8
|
+
- Web3 API for blockchain interactions
|
|
9
|
+
- WebSocket API for real-time data streams
|
|
10
|
+
- GraphQL API for flexible data queries
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
__version__ = "0.3.1"
|
|
14
|
+
__author__ = "Razvan Gheorghe"
|
|
15
|
+
__email__ = "razvan@gheorghe.me"
|
|
16
|
+
|
|
17
|
+
from .clients import (
|
|
18
|
+
AsyncPolymarketGraphQLClient,
|
|
19
|
+
PolymarketClobClient,
|
|
20
|
+
PolymarketDataClient,
|
|
21
|
+
PolymarketGammaClient,
|
|
22
|
+
PolymarketGraphQLClient,
|
|
23
|
+
PolymarketWeb3Client,
|
|
24
|
+
PolymarketWebsocketsClient,
|
|
25
|
+
)
|
|
26
|
+
from .types.clob_types import MarketOrderArgs, OrderArgs
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"AsyncPolymarketGraphQLClient",
|
|
30
|
+
"MarketOrderArgs",
|
|
31
|
+
"OrderArgs",
|
|
32
|
+
"PolymarketClobClient",
|
|
33
|
+
"PolymarketDataClient",
|
|
34
|
+
"PolymarketGammaClient",
|
|
35
|
+
"PolymarketGraphQLClient",
|
|
36
|
+
"PolymarketWeb3Client",
|
|
37
|
+
"PolymarketWebsocketsClient",
|
|
38
|
+
"__author__",
|
|
39
|
+
"__email__",
|
|
40
|
+
"__version__",
|
|
41
|
+
]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Client modules for Polymarket APIs.
|
|
3
|
+
|
|
4
|
+
This module contains all the client classes for interacting with different
|
|
5
|
+
Polymarket APIs including CLOB, Data, Gamma, GraphQL, Web3, and WebSocket clients.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .clob_client import PolymarketClobClient
|
|
9
|
+
from .data_client import PolymarketDataClient
|
|
10
|
+
from .gamma_client import PolymarketGammaClient
|
|
11
|
+
from .graphql_client import AsyncPolymarketGraphQLClient, PolymarketGraphQLClient
|
|
12
|
+
from .web3_client import PolymarketWeb3Client
|
|
13
|
+
from .websockets_client import PolymarketWebsocketsClient
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"AsyncPolymarketGraphQLClient",
|
|
17
|
+
"PolymarketClobClient",
|
|
18
|
+
"PolymarketDataClient",
|
|
19
|
+
"PolymarketGammaClient",
|
|
20
|
+
"PolymarketGraphQLClient",
|
|
21
|
+
"PolymarketWeb3Client",
|
|
22
|
+
"PolymarketWebsocketsClient",
|
|
23
|
+
]
|
|
@@ -27,11 +27,11 @@ from ..types.clob_types import (
|
|
|
27
27
|
PaginatedResponse,
|
|
28
28
|
PartialCreateOrderOptions,
|
|
29
29
|
PolygonTrade,
|
|
30
|
-
PolymarketRewardItem,
|
|
31
30
|
PostOrdersArgs,
|
|
32
31
|
Price,
|
|
33
32
|
PriceHistory,
|
|
34
33
|
RequestArgs,
|
|
34
|
+
RewardMarket,
|
|
35
35
|
Spread,
|
|
36
36
|
TickSize,
|
|
37
37
|
TokenBidAskDict,
|
|
@@ -88,15 +88,16 @@ from ..utilities.signing.signer import Signer
|
|
|
88
88
|
|
|
89
89
|
logger = logging.getLogger(__name__)
|
|
90
90
|
|
|
91
|
+
|
|
91
92
|
class PolymarketClobClient:
|
|
92
93
|
def __init__(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
94
|
+
self,
|
|
95
|
+
private_key: str,
|
|
96
|
+
proxy_address: EthAddress,
|
|
97
|
+
creds: Optional[ApiCreds] = None,
|
|
98
|
+
chain_id: Literal[137, 80002] = POLYGON,
|
|
99
|
+
signature_type: Literal[0, 1, 2] = 1,
|
|
100
|
+
# 0 - EOA wallet, 1 - Proxy wallet, 2 - Gnosis Safe wallet
|
|
100
101
|
):
|
|
101
102
|
self.proxy_address = proxy_address
|
|
102
103
|
self.client = httpx.Client(http2=True, timeout=30.0)
|
|
@@ -199,7 +200,9 @@ class PolymarketClobClient:
|
|
|
199
200
|
return fee_rate
|
|
200
201
|
|
|
201
202
|
def __resolve_tick_size(
|
|
202
|
-
|
|
203
|
+
self,
|
|
204
|
+
token_id: str,
|
|
205
|
+
tick_size: TickSize = None,
|
|
203
206
|
) -> TickSize:
|
|
204
207
|
min_tick_size = self.get_tick_size(token_id)
|
|
205
208
|
if tick_size is not None:
|
|
@@ -211,12 +214,19 @@ class PolymarketClobClient:
|
|
|
211
214
|
return tick_size
|
|
212
215
|
|
|
213
216
|
def __resolve_fee_rate(
|
|
214
|
-
|
|
217
|
+
self,
|
|
218
|
+
token_id: str,
|
|
219
|
+
user_fee_rate: Optional[int] = None,
|
|
215
220
|
) -> int:
|
|
216
221
|
market_fee_rate_bps = self.get_fee_rate_bps(token_id)
|
|
217
222
|
# If both fee rate on the market and the user supplied fee rate are non-zero, validate that they match
|
|
218
223
|
# else return the market fee rate
|
|
219
|
-
if
|
|
224
|
+
if (
|
|
225
|
+
market_fee_rate_bps > 0
|
|
226
|
+
and user_fee_rate is not None
|
|
227
|
+
and user_fee_rate > 0
|
|
228
|
+
and user_fee_rate != market_fee_rate_bps
|
|
229
|
+
):
|
|
220
230
|
msg = f"invalid user provided fee rate: ({user_fee_rate}), fee rate for the market must be {market_fee_rate_bps}"
|
|
221
231
|
raise InvalidFeeRateError(msg)
|
|
222
232
|
return market_fee_rate_bps
|
|
@@ -291,10 +301,14 @@ class PolymarketClobClient:
|
|
|
291
301
|
response.raise_for_status()
|
|
292
302
|
return [OrderBookSummary(**obs) for obs in response.json()]
|
|
293
303
|
|
|
294
|
-
async def get_order_books_async(
|
|
304
|
+
async def get_order_books_async(
|
|
305
|
+
self, token_ids: list[str]
|
|
306
|
+
) -> list[OrderBookSummary]:
|
|
295
307
|
"""Get the orderbook for a set of tokens asynchronously."""
|
|
296
308
|
body = [{"token_id": token_id} for token_id in token_ids]
|
|
297
|
-
response = await self.async_client.post(
|
|
309
|
+
response = await self.async_client.post(
|
|
310
|
+
self._build_url(GET_ORDER_BOOKS), json=body
|
|
311
|
+
)
|
|
298
312
|
response.raise_for_status()
|
|
299
313
|
return [OrderBookSummary(**obs) for obs in response.json()]
|
|
300
314
|
|
|
@@ -304,7 +318,7 @@ class PolymarketClobClient:
|
|
|
304
318
|
response.raise_for_status()
|
|
305
319
|
return ClobMarket(**response.json())
|
|
306
320
|
|
|
307
|
-
def get_markets(self, next_cursor="MA==")
|
|
321
|
+
def get_markets(self, next_cursor="MA==") -> PaginatedResponse[ClobMarket]:
|
|
308
322
|
"""Get paginated ClobMarkets."""
|
|
309
323
|
params = {"next_cursor": next_cursor}
|
|
310
324
|
response = self.client.get(self._build_url(GET_MARKETS), params=params)
|
|
@@ -333,10 +347,10 @@ class PolymarketClobClient:
|
|
|
333
347
|
return current_markets + next_page_markets
|
|
334
348
|
|
|
335
349
|
def get_recent_history(
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
350
|
+
self,
|
|
351
|
+
token_id: str,
|
|
352
|
+
interval: Optional[Literal["1d", "6h", "1h"]] = "1d",
|
|
353
|
+
fidelity: int = 1, # resolution in minutes
|
|
340
354
|
) -> PriceHistory:
|
|
341
355
|
"""Get the recent price history of a token (up to now) - 1h, 6h, 1d."""
|
|
342
356
|
if fidelity < 1:
|
|
@@ -353,17 +367,17 @@ class PolymarketClobClient:
|
|
|
353
367
|
return PriceHistory(**response.json(), token_id=token_id)
|
|
354
368
|
|
|
355
369
|
def get_history(
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
370
|
+
self,
|
|
371
|
+
token_id: str,
|
|
372
|
+
start_time: Optional[datetime] = None,
|
|
373
|
+
end_time: Optional[datetime] = None,
|
|
374
|
+
interval: Literal["max", "1m", "1w"] = "max",
|
|
375
|
+
fidelity: int = 2, # resolution in minutes
|
|
362
376
|
) -> PriceHistory:
|
|
363
377
|
"""Get the price history of a token between selected dates - 1m, 1w, max."""
|
|
364
|
-
min_fidelities = {"1m": 10, "1w": 5, "max": 2}
|
|
378
|
+
min_fidelities: dict[str, int] = {"1m": 10, "1w": 5, "max": 2}
|
|
365
379
|
|
|
366
|
-
if fidelity < min_fidelities[interval]:
|
|
380
|
+
if fidelity is None or fidelity < min_fidelities[interval]:
|
|
367
381
|
msg = f"invalid filters: minimum 'fidelity' for '{interval}' range is {min_fidelities[interval]}"
|
|
368
382
|
raise ValueError(msg)
|
|
369
383
|
|
|
@@ -389,7 +403,13 @@ class PolymarketClobClient:
|
|
|
389
403
|
response.raise_for_status()
|
|
390
404
|
return PriceHistory(**response.json(), token_id=token_id)
|
|
391
405
|
|
|
392
|
-
def get_orders(
|
|
406
|
+
def get_orders(
|
|
407
|
+
self,
|
|
408
|
+
order_id: Optional[str] = None,
|
|
409
|
+
condition_id: Optional[Keccak256] = None,
|
|
410
|
+
token_id: Optional[str] = None,
|
|
411
|
+
next_cursor: str = "MA==",
|
|
412
|
+
) -> list[OpenOrder]:
|
|
393
413
|
"""Gets your active orders, filtered by order_id, condition_id, token_id."""
|
|
394
414
|
params = {}
|
|
395
415
|
if order_id:
|
|
@@ -406,14 +426,18 @@ class PolymarketClobClient:
|
|
|
406
426
|
next_cursor = next_cursor if next_cursor is not None else "MA=="
|
|
407
427
|
while next_cursor != END_CURSOR:
|
|
408
428
|
params["next_cursor"] = next_cursor
|
|
409
|
-
response = self.client.get(
|
|
429
|
+
response = self.client.get(
|
|
430
|
+
self._build_url(ORDERS), headers=headers, params=params
|
|
431
|
+
)
|
|
410
432
|
response.raise_for_status()
|
|
411
433
|
next_cursor = response.json()["next_cursor"]
|
|
412
434
|
results += [OpenOrder(**order) for order in response.json()["data"]]
|
|
413
435
|
|
|
414
436
|
return results
|
|
415
437
|
|
|
416
|
-
def create_order(
|
|
438
|
+
def create_order(
|
|
439
|
+
self, order_args: OrderArgs, options: Optional[PartialCreateOrderOptions] = None
|
|
440
|
+
) -> SignedOrder:
|
|
417
441
|
"""Creates and signs an order."""
|
|
418
442
|
# add resolve_order_options, or similar
|
|
419
443
|
tick_size = self.__resolve_tick_size(
|
|
@@ -425,7 +449,6 @@ class PolymarketClobClient:
|
|
|
425
449
|
msg = f"price ({order_args.price}), min: {tick_size} - max: {1 - float(tick_size)}"
|
|
426
450
|
raise InvalidPriceError(msg)
|
|
427
451
|
|
|
428
|
-
|
|
429
452
|
neg_risk = (
|
|
430
453
|
options.neg_risk
|
|
431
454
|
if options and options.neg_risk
|
|
@@ -433,7 +456,9 @@ class PolymarketClobClient:
|
|
|
433
456
|
)
|
|
434
457
|
|
|
435
458
|
# fee rate
|
|
436
|
-
fee_rate_bps = self.__resolve_fee_rate(
|
|
459
|
+
fee_rate_bps = self.__resolve_fee_rate(
|
|
460
|
+
order_args.token_id, order_args.fee_rate_bps
|
|
461
|
+
)
|
|
437
462
|
order_args.fee_rate_bps = fee_rate_bps
|
|
438
463
|
|
|
439
464
|
return self.builder.create_order(
|
|
@@ -444,7 +469,9 @@ class PolymarketClobClient:
|
|
|
444
469
|
),
|
|
445
470
|
)
|
|
446
471
|
|
|
447
|
-
def post_order(
|
|
472
|
+
def post_order(
|
|
473
|
+
self, order: SignedOrder, order_type: OrderType = OrderType.GTC
|
|
474
|
+
) -> Optional[OrderPostResponse]:
|
|
448
475
|
"""Posts a SignedOrder."""
|
|
449
476
|
body = order_to_json(order, self.creds.key, order_type)
|
|
450
477
|
headers = create_level_2_headers(
|
|
@@ -467,14 +494,21 @@ class PolymarketClobClient:
|
|
|
467
494
|
error_json = exc.response.json()
|
|
468
495
|
print("Details:", error_json["error"])
|
|
469
496
|
|
|
470
|
-
def create_and_post_order(
|
|
497
|
+
def create_and_post_order(
|
|
498
|
+
self,
|
|
499
|
+
order_args: OrderArgs,
|
|
500
|
+
options: Optional[PartialCreateOrderOptions] = None,
|
|
501
|
+
order_type: OrderType = OrderType.GTC,
|
|
502
|
+
) -> OrderPostResponse:
|
|
471
503
|
"""Utility function to create and publish an order."""
|
|
472
504
|
order = self.create_order(order_args, options)
|
|
473
505
|
return self.post_order(order=order, order_type=order_type)
|
|
474
506
|
|
|
475
507
|
def post_orders(self, args: list[PostOrdersArgs]):
|
|
476
508
|
"""Posts multiple SignedOrders at once."""
|
|
477
|
-
body = [
|
|
509
|
+
body = [
|
|
510
|
+
order_to_json(arg.order, self.creds.key, arg.order_type) for arg in args
|
|
511
|
+
]
|
|
478
512
|
headers = create_level_2_headers(
|
|
479
513
|
self.signer,
|
|
480
514
|
self.creds,
|
|
@@ -493,8 +527,10 @@ class PolymarketClobClient:
|
|
|
493
527
|
resp = OrderPostResponse(**item)
|
|
494
528
|
order_responses.append(resp)
|
|
495
529
|
if resp.error_msg:
|
|
496
|
-
msg = (
|
|
497
|
-
|
|
530
|
+
msg = (
|
|
531
|
+
f"Error posting order in position {index} \n"
|
|
532
|
+
f"Details: {resp.error_msg}"
|
|
533
|
+
)
|
|
498
534
|
logger.warning(msg)
|
|
499
535
|
except httpx.HTTPStatusError as exc:
|
|
500
536
|
msg = f"Client Error '{exc.response.status_code} {exc.response.reason_phrase}' while posting order"
|
|
@@ -504,15 +540,22 @@ class PolymarketClobClient:
|
|
|
504
540
|
else:
|
|
505
541
|
return order_responses
|
|
506
542
|
|
|
507
|
-
def create_and_post_orders(
|
|
543
|
+
def create_and_post_orders(
|
|
544
|
+
self, args: list[OrderArgs], order_types: list[OrderType]
|
|
545
|
+
) -> list[OrderPostResponse]:
|
|
508
546
|
"""Utility function to create and publish multiple orders at once."""
|
|
509
547
|
return self.post_orders(
|
|
510
|
-
[
|
|
511
|
-
|
|
512
|
-
|
|
548
|
+
[
|
|
549
|
+
PostOrdersArgs(
|
|
550
|
+
order=self.create_order(order_args), order_type=order_type
|
|
551
|
+
)
|
|
552
|
+
for order_args, order_type in zip(args, order_types, strict=True)
|
|
553
|
+
],
|
|
513
554
|
)
|
|
514
555
|
|
|
515
|
-
def calculate_market_price(
|
|
556
|
+
def calculate_market_price(
|
|
557
|
+
self, token_id: str, side: str, amount: float, order_type: OrderType
|
|
558
|
+
) -> float:
|
|
516
559
|
"""Calculates the matching price considering an amount and the current orderbook."""
|
|
517
560
|
book = self.get_order_book(token_id)
|
|
518
561
|
if book is None:
|
|
@@ -523,19 +566,27 @@ class PolymarketClobClient:
|
|
|
523
566
|
msg = "No ask orders available"
|
|
524
567
|
raise LiquidityError(msg)
|
|
525
568
|
return self.builder.calculate_buy_market_price(
|
|
526
|
-
book.asks,
|
|
569
|
+
book.asks,
|
|
570
|
+
amount,
|
|
571
|
+
order_type,
|
|
527
572
|
)
|
|
528
573
|
if side == "SELL":
|
|
529
574
|
if book.bids is None:
|
|
530
575
|
msg = "No bid orders available"
|
|
531
576
|
raise LiquidityError(msg)
|
|
532
577
|
return self.builder.calculate_sell_market_price(
|
|
533
|
-
book.bids,
|
|
578
|
+
book.bids,
|
|
579
|
+
amount,
|
|
580
|
+
order_type,
|
|
534
581
|
)
|
|
535
582
|
msg = 'Side must be "BUY" or "SELL"'
|
|
536
583
|
raise ValueError(msg)
|
|
537
584
|
|
|
538
|
-
def create_market_order(
|
|
585
|
+
def create_market_order(
|
|
586
|
+
self,
|
|
587
|
+
order_args: MarketOrderArgs,
|
|
588
|
+
options: Optional[PartialCreateOrderOptions] = None,
|
|
589
|
+
):
|
|
539
590
|
"""Creates and signs a market order."""
|
|
540
591
|
tick_size = self.__resolve_tick_size(
|
|
541
592
|
order_args.token_id,
|
|
@@ -561,7 +612,9 @@ class PolymarketClobClient:
|
|
|
561
612
|
)
|
|
562
613
|
|
|
563
614
|
# fee rate
|
|
564
|
-
fee_rate_bps = self.__resolve_fee_rate(
|
|
615
|
+
fee_rate_bps = self.__resolve_fee_rate(
|
|
616
|
+
order_args.token_id, order_args.fee_rate_bps
|
|
617
|
+
)
|
|
565
618
|
order_args.fee_rate_bps = fee_rate_bps
|
|
566
619
|
|
|
567
620
|
return self.builder.create_market_order(
|
|
@@ -573,10 +626,10 @@ class PolymarketClobClient:
|
|
|
573
626
|
)
|
|
574
627
|
|
|
575
628
|
def create_and_post_market_order(
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
629
|
+
self,
|
|
630
|
+
order_args: MarketOrderArgs,
|
|
631
|
+
options: Optional[PartialCreateOrderOptions] = None,
|
|
632
|
+
order_type: OrderType = OrderType.FOK,
|
|
580
633
|
) -> OrderPostResponse:
|
|
581
634
|
"""Utility function to create and publish a market order."""
|
|
582
635
|
order = self.create_market_order(order_args, options)
|
|
@@ -589,7 +642,12 @@ class PolymarketClobClient:
|
|
|
589
642
|
request_args = RequestArgs(method="DELETE", request_path=CANCEL, body=body)
|
|
590
643
|
headers = create_level_2_headers(self.signer, self.creds, request_args)
|
|
591
644
|
|
|
592
|
-
response = self.client.request(
|
|
645
|
+
response = self.client.request(
|
|
646
|
+
"DELETE",
|
|
647
|
+
self._build_url(CANCEL),
|
|
648
|
+
headers=headers,
|
|
649
|
+
data=json.dumps(body).encode("utf-8"),
|
|
650
|
+
)
|
|
593
651
|
response.raise_for_status()
|
|
594
652
|
return OrderCancelResponse(**response.json())
|
|
595
653
|
|
|
@@ -598,11 +656,18 @@ class PolymarketClobClient:
|
|
|
598
656
|
body = order_ids
|
|
599
657
|
|
|
600
658
|
request_args = RequestArgs(
|
|
601
|
-
method="DELETE",
|
|
659
|
+
method="DELETE",
|
|
660
|
+
request_path=CANCEL_ORDERS,
|
|
661
|
+
body=body,
|
|
602
662
|
)
|
|
603
663
|
headers = create_level_2_headers(self.signer, self.creds, request_args)
|
|
604
664
|
|
|
605
|
-
response = self.client.request(
|
|
665
|
+
response = self.client.request(
|
|
666
|
+
"DELETE",
|
|
667
|
+
self._build_url(CANCEL_ORDERS),
|
|
668
|
+
headers=headers,
|
|
669
|
+
data=json.dumps(body).encode("utf-8"),
|
|
670
|
+
)
|
|
606
671
|
response.raise_for_status()
|
|
607
672
|
return OrderCancelResponse(**response.json())
|
|
608
673
|
|
|
@@ -620,7 +685,11 @@ class PolymarketClobClient:
|
|
|
620
685
|
request_args = RequestArgs(method="GET", request_path=IS_ORDER_SCORING)
|
|
621
686
|
headers = create_level_2_headers(self.signer, self.creds, request_args)
|
|
622
687
|
|
|
623
|
-
response = self.client.get(
|
|
688
|
+
response = self.client.get(
|
|
689
|
+
self._build_url(IS_ORDER_SCORING),
|
|
690
|
+
headers=headers,
|
|
691
|
+
params={"order_id": order_id},
|
|
692
|
+
)
|
|
624
693
|
response.raise_for_status()
|
|
625
694
|
return response.json()["scoring"]
|
|
626
695
|
|
|
@@ -628,12 +697,16 @@ class PolymarketClobClient:
|
|
|
628
697
|
"""Check if the orders are currently scoring."""
|
|
629
698
|
body = order_ids
|
|
630
699
|
request_args = RequestArgs(
|
|
631
|
-
method="POST",
|
|
700
|
+
method="POST",
|
|
701
|
+
request_path=ARE_ORDERS_SCORING,
|
|
702
|
+
body=body,
|
|
632
703
|
)
|
|
633
704
|
headers = create_level_2_headers(self.signer, self.creds, request_args)
|
|
634
705
|
headers["Content-Type"] = "application/json"
|
|
635
706
|
|
|
636
|
-
response = self.client.post(
|
|
707
|
+
response = self.client.post(
|
|
708
|
+
self._build_url(ARE_ORDERS_SCORING), headers=headers, json=body
|
|
709
|
+
)
|
|
637
710
|
response.raise_for_status()
|
|
638
711
|
return response.json()
|
|
639
712
|
|
|
@@ -646,19 +719,22 @@ class PolymarketClobClient:
|
|
|
646
719
|
request_args = RequestArgs(method="GET", request_path="/rewards/markets/")
|
|
647
720
|
headers = create_level_2_headers(self.signer, self.creds, request_args)
|
|
648
721
|
|
|
649
|
-
response = self.client.get(
|
|
722
|
+
response = self.client.get(
|
|
723
|
+
self._build_url("/rewards/markets/" + condition_id), headers=headers
|
|
724
|
+
)
|
|
650
725
|
response.raise_for_status()
|
|
651
726
|
return next(MarketRewards(**market) for market in response.json()["data"])
|
|
652
727
|
|
|
653
728
|
def get_trades(
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
729
|
+
self,
|
|
730
|
+
condition_id: Optional[Keccak256] = None,
|
|
731
|
+
token_id: Optional[str] = None,
|
|
732
|
+
trade_id: Optional[str] = None,
|
|
733
|
+
before: Optional[datetime] = None,
|
|
734
|
+
after: Optional[datetime] = None,
|
|
735
|
+
proxy_address: Optional[int] = None,
|
|
736
|
+
next_cursor="MA==",
|
|
737
|
+
) -> list[PolygonTrade]:
|
|
662
738
|
"""Fetches the trade history for a user."""
|
|
663
739
|
params = {}
|
|
664
740
|
if condition_id:
|
|
@@ -681,7 +757,9 @@ class PolymarketClobClient:
|
|
|
681
757
|
next_cursor = next_cursor if next_cursor is not None else "MA=="
|
|
682
758
|
while next_cursor != END_CURSOR:
|
|
683
759
|
params["next_cursor"] = next_cursor
|
|
684
|
-
response =
|
|
760
|
+
response = self.client.get(
|
|
761
|
+
self._build_url(TRADES), headers=headers, params=params
|
|
762
|
+
)
|
|
685
763
|
response.raise_for_status()
|
|
686
764
|
next_cursor = response.json()["next_cursor"]
|
|
687
765
|
results += [PolygonTrade(**trade) for trade in response.json()["data"]]
|
|
@@ -694,14 +772,16 @@ class PolymarketClobClient:
|
|
|
694
772
|
date = datetime.now(UTC)
|
|
695
773
|
params = {
|
|
696
774
|
"authenticationType": "magic",
|
|
697
|
-
"date": f"{date.strftime(
|
|
775
|
+
"date": f"{date.strftime('%Y-%m-%d')}",
|
|
698
776
|
}
|
|
699
777
|
|
|
700
778
|
request_args = RequestArgs(method="GET", request_path="/rewards/user/total")
|
|
701
779
|
headers = create_level_2_headers(self.signer, self.creds, request_args)
|
|
702
780
|
params["l2Headers"] = json.dumps(headers)
|
|
703
781
|
|
|
704
|
-
response = self.client.get(
|
|
782
|
+
response = self.client.get(
|
|
783
|
+
"https://polymarket.com/api/rewards/totalEarnings", params=params
|
|
784
|
+
)
|
|
705
785
|
response.raise_for_status()
|
|
706
786
|
if response.json():
|
|
707
787
|
return DailyEarnedReward(**response.json()[0])
|
|
@@ -714,14 +794,25 @@ class PolymarketClobClient:
|
|
|
714
794
|
)
|
|
715
795
|
|
|
716
796
|
def get_reward_markets(
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
797
|
+
self,
|
|
798
|
+
query: Optional[str] = None,
|
|
799
|
+
sort_by: Optional[
|
|
800
|
+
Literal[
|
|
801
|
+
"market",
|
|
802
|
+
"max_spread",
|
|
803
|
+
"min_size",
|
|
804
|
+
"rate_per_day",
|
|
805
|
+
"spread",
|
|
806
|
+
"price",
|
|
807
|
+
"earnings",
|
|
808
|
+
"earning_percentage",
|
|
809
|
+
]
|
|
810
|
+
] = "market",
|
|
811
|
+
sort_direction: Optional[Literal["ASC", "DESC"]] = None,
|
|
812
|
+
show_favorites: bool = False,
|
|
813
|
+
) -> list[RewardMarket]:
|
|
723
814
|
"""
|
|
724
|
-
|
|
815
|
+
Search through markets that offer rewards (polymarket.com/rewards items) by query, sorted by different metrics. If query is empty, returns all markets with rewards.
|
|
725
816
|
|
|
726
817
|
- market start date ("market") - TODO confirm this
|
|
727
818
|
- max spread for rewards in usdc
|
|
@@ -753,11 +844,12 @@ class PolymarketClobClient:
|
|
|
753
844
|
next_cursor = "MA=="
|
|
754
845
|
while next_cursor != END_CURSOR:
|
|
755
846
|
params["nextCursor"] = next_cursor
|
|
756
|
-
response = self.client.get(
|
|
757
|
-
|
|
847
|
+
response = self.client.get(
|
|
848
|
+
"https://polymarket.com/api/rewards/markets", params=params
|
|
849
|
+
)
|
|
758
850
|
response.raise_for_status()
|
|
759
851
|
next_cursor = response.json()["next_cursor"]
|
|
760
|
-
results += [
|
|
852
|
+
results += [RewardMarket(**reward) for reward in response.json()["data"]]
|
|
761
853
|
|
|
762
854
|
return results
|
|
763
855
|
|