polymarket-apis 0.3.1__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 +1 -1
- polymarket_apis/clients/clob_client.py +4 -4
- polymarket_apis/clients/data_client.py +105 -15
- polymarket_apis/clients/gamma_client.py +514 -50
- polymarket_apis/types/__init__.py +9 -37
- polymarket_apis/types/common.py +13 -32
- polymarket_apis/types/data_types.py +11 -1
- polymarket_apis/types/gamma_types.py +509 -265
- polymarket_apis/types/websockets_types.py +1 -29
- {polymarket_apis-0.3.1.dist-info → polymarket_apis-0.3.2.dist-info}/METADATA +29 -3
- {polymarket_apis-0.3.1.dist-info → polymarket_apis-0.3.2.dist-info}/RECORD +12 -12
- {polymarket_apis-0.3.1.dist-info → polymarket_apis-0.3.2.dist-info}/WHEEL +0 -0
polymarket_apis/__init__.py
CHANGED
|
@@ -499,7 +499,7 @@ class PolymarketClobClient:
|
|
|
499
499
|
order_args: OrderArgs,
|
|
500
500
|
options: Optional[PartialCreateOrderOptions] = None,
|
|
501
501
|
order_type: OrderType = OrderType.GTC,
|
|
502
|
-
) -> OrderPostResponse:
|
|
502
|
+
) -> OrderPostResponse | None:
|
|
503
503
|
"""Utility function to create and publish an order."""
|
|
504
504
|
order = self.create_order(order_args, options)
|
|
505
505
|
return self.post_order(order=order, order_type=order_type)
|
|
@@ -630,7 +630,7 @@ class PolymarketClobClient:
|
|
|
630
630
|
order_args: MarketOrderArgs,
|
|
631
631
|
options: Optional[PartialCreateOrderOptions] = None,
|
|
632
632
|
order_type: OrderType = OrderType.FOK,
|
|
633
|
-
) -> OrderPostResponse:
|
|
633
|
+
) -> OrderPostResponse | None:
|
|
634
634
|
"""Utility function to create and publish a market order."""
|
|
635
635
|
order = self.create_market_order(order_args, options)
|
|
636
636
|
return self.post_order(order=order, order_type=order_type)
|
|
@@ -646,7 +646,7 @@ class PolymarketClobClient:
|
|
|
646
646
|
"DELETE",
|
|
647
647
|
self._build_url(CANCEL),
|
|
648
648
|
headers=headers,
|
|
649
|
-
|
|
649
|
+
content=json.dumps(body).encode("utf-8"),
|
|
650
650
|
)
|
|
651
651
|
response.raise_for_status()
|
|
652
652
|
return OrderCancelResponse(**response.json())
|
|
@@ -736,7 +736,7 @@ class PolymarketClobClient:
|
|
|
736
736
|
next_cursor="MA==",
|
|
737
737
|
) -> list[PolygonTrade]:
|
|
738
738
|
"""Fetches the trade history for a user."""
|
|
739
|
-
params = {}
|
|
739
|
+
params: dict[str, str | int] = {}
|
|
740
740
|
if condition_id:
|
|
741
741
|
params["market"] = condition_id
|
|
742
742
|
if token_id:
|
|
@@ -7,7 +7,9 @@ import httpx
|
|
|
7
7
|
from ..types.common import EthAddress, TimeseriesPoint
|
|
8
8
|
from ..types.data_types import (
|
|
9
9
|
Activity,
|
|
10
|
+
EventLiveVolume,
|
|
10
11
|
HolderResponse,
|
|
12
|
+
MarketValue,
|
|
11
13
|
Position,
|
|
12
14
|
Trade,
|
|
13
15
|
UserMetric,
|
|
@@ -24,13 +26,23 @@ class PolymarketDataClient:
|
|
|
24
26
|
def _build_url(self, endpoint: str) -> str:
|
|
25
27
|
return urljoin(self.base_url, endpoint)
|
|
26
28
|
|
|
29
|
+
def get_ok(self) -> str:
|
|
30
|
+
response = self.client.get(self.base_url)
|
|
31
|
+
response.raise_for_status()
|
|
32
|
+
return response.json()["data"]
|
|
33
|
+
|
|
27
34
|
def get_positions(
|
|
28
35
|
self,
|
|
29
|
-
user:
|
|
30
|
-
condition_id: Optional[
|
|
36
|
+
user: EthAddress,
|
|
37
|
+
condition_id: Optional[
|
|
38
|
+
Union[str, list[str]]
|
|
39
|
+
] = None, # mutually exclusive with event_id
|
|
40
|
+
event_id: Optional[
|
|
41
|
+
Union[int, list[int]]
|
|
42
|
+
] = None, # mutually exclusive with condition_id
|
|
31
43
|
size_threshold: float = 1.0,
|
|
32
|
-
redeemable:
|
|
33
|
-
mergeable:
|
|
44
|
+
redeemable: bool = False,
|
|
45
|
+
mergeable: bool = False,
|
|
34
46
|
title: Optional[str] = None,
|
|
35
47
|
limit: int = 100,
|
|
36
48
|
offset: int = 0,
|
|
@@ -43,10 +55,11 @@ class PolymarketDataClient:
|
|
|
43
55
|
"TITLE",
|
|
44
56
|
"RESOLVING",
|
|
45
57
|
"PRICE",
|
|
58
|
+
"AVGPRICE",
|
|
46
59
|
] = "TOKENS",
|
|
47
60
|
sort_direction: Literal["ASC", "DESC"] = "DESC",
|
|
48
61
|
) -> list[Position]:
|
|
49
|
-
params = {
|
|
62
|
+
params: dict[str, str | list[str] | int | float] = {
|
|
50
63
|
"user": user,
|
|
51
64
|
"sizeThreshold": size_threshold,
|
|
52
65
|
"limit": min(limit, 500),
|
|
@@ -56,6 +69,10 @@ class PolymarketDataClient:
|
|
|
56
69
|
params["market"] = condition_id
|
|
57
70
|
if isinstance(condition_id, list):
|
|
58
71
|
params["market"] = ",".join(condition_id)
|
|
72
|
+
if isinstance(event_id, str):
|
|
73
|
+
params["eventId"] = event_id
|
|
74
|
+
if isinstance(event_id, list):
|
|
75
|
+
params["eventId"] = [str(i) for i in event_id]
|
|
59
76
|
if redeemable is not None:
|
|
60
77
|
params["redeemable"] = redeemable
|
|
61
78
|
if mergeable is not None:
|
|
@@ -77,12 +94,15 @@ class PolymarketDataClient:
|
|
|
77
94
|
offset: int = 0,
|
|
78
95
|
taker_only: bool = True,
|
|
79
96
|
filter_type: Optional[Literal["CASH", "TOKENS"]] = None,
|
|
80
|
-
filter_amount: Optional[
|
|
81
|
-
|
|
97
|
+
filter_amount: Optional[
|
|
98
|
+
float
|
|
99
|
+
] = None, # must be provided together with filter_type
|
|
100
|
+
condition_id: Optional[str | list[str]] = None,
|
|
101
|
+
event_id: Optional[int | list[int]] = None,
|
|
82
102
|
user: Optional[str] = None,
|
|
83
103
|
side: Optional[Literal["BUY", "SELL"]] = None,
|
|
84
104
|
) -> list[Trade]:
|
|
85
|
-
params: dict[str, int | bool | str |
|
|
105
|
+
params: dict[str, int | bool | float | str | list[str]] = {
|
|
86
106
|
"limit": min(limit, 500),
|
|
87
107
|
"offset": offset,
|
|
88
108
|
"takerOnly": taker_only,
|
|
@@ -91,8 +111,14 @@ class PolymarketDataClient:
|
|
|
91
111
|
params["filterType"] = filter_type
|
|
92
112
|
if filter_amount:
|
|
93
113
|
params["filterAmount"] = filter_amount
|
|
94
|
-
if condition_id:
|
|
114
|
+
if isinstance(condition_id, str):
|
|
95
115
|
params["market"] = condition_id
|
|
116
|
+
if isinstance(condition_id, list):
|
|
117
|
+
params["market"] = ",".join(condition_id)
|
|
118
|
+
if isinstance(event_id, str):
|
|
119
|
+
params["eventId"] = event_id
|
|
120
|
+
if isinstance(event_id, list):
|
|
121
|
+
params["eventId"] = [str(i) for i in event_id]
|
|
96
122
|
if user:
|
|
97
123
|
params["user"] = user
|
|
98
124
|
if side:
|
|
@@ -104,10 +130,11 @@ class PolymarketDataClient:
|
|
|
104
130
|
|
|
105
131
|
def get_activity(
|
|
106
132
|
self,
|
|
107
|
-
user:
|
|
133
|
+
user: EthAddress,
|
|
108
134
|
limit: int = 100,
|
|
109
135
|
offset: int = 0,
|
|
110
136
|
condition_id: Optional[Union[str, list[str]]] = None,
|
|
137
|
+
event_id: Optional[Union[int, list[int]]] = None,
|
|
111
138
|
type: Optional[
|
|
112
139
|
Union[
|
|
113
140
|
Literal["TRADE", "SPLIT", "MERGE", "REDEEM", "REWARD", "CONVERSION"],
|
|
@@ -122,11 +149,19 @@ class PolymarketDataClient:
|
|
|
122
149
|
sort_by: Literal["TIMESTAMP", "TOKENS", "CASH"] = "TIMESTAMP",
|
|
123
150
|
sort_direction: Literal["ASC", "DESC"] = "DESC",
|
|
124
151
|
) -> list[Activity]:
|
|
125
|
-
params
|
|
152
|
+
params: dict[str, str | list[str] | int] = {
|
|
153
|
+
"user": user,
|
|
154
|
+
"limit": min(limit, 500),
|
|
155
|
+
"offset": offset,
|
|
156
|
+
}
|
|
126
157
|
if isinstance(condition_id, str):
|
|
127
158
|
params["market"] = condition_id
|
|
128
159
|
if isinstance(condition_id, list):
|
|
129
160
|
params["market"] = ",".join(condition_id)
|
|
161
|
+
if isinstance(event_id, str):
|
|
162
|
+
params["eventId"] = event_id
|
|
163
|
+
if isinstance(event_id, list):
|
|
164
|
+
params["eventId"] = [str(i) for i in event_id]
|
|
130
165
|
if isinstance(type, str):
|
|
131
166
|
params["type"] = type
|
|
132
167
|
if isinstance(type, list):
|
|
@@ -149,17 +184,18 @@ class PolymarketDataClient:
|
|
|
149
184
|
def get_holders(
|
|
150
185
|
self,
|
|
151
186
|
condition_id: str,
|
|
152
|
-
limit: int =
|
|
187
|
+
limit: int = 500,
|
|
188
|
+
min_balance: int = 1,
|
|
153
189
|
) -> list[HolderResponse]:
|
|
154
|
-
"""Takes in a condition_id and returns
|
|
155
|
-
params = {"market": condition_id, "limit": limit}
|
|
190
|
+
"""Takes in a condition_id and returns top holders for each corresponding token_id."""
|
|
191
|
+
params = {"market": condition_id, "limit": limit, "min_balance": min_balance}
|
|
156
192
|
response = self.client.get(self._build_url("/holders"), params=params)
|
|
157
193
|
response.raise_for_status()
|
|
158
194
|
return [HolderResponse(**holder_data) for holder_data in response.json()]
|
|
159
195
|
|
|
160
196
|
def get_value(
|
|
161
197
|
self,
|
|
162
|
-
user:
|
|
198
|
+
user: EthAddress,
|
|
163
199
|
condition_ids: Optional[Union[str, list[str]]] = None,
|
|
164
200
|
) -> ValueResponse:
|
|
165
201
|
"""
|
|
@@ -180,6 +216,60 @@ class PolymarketDataClient:
|
|
|
180
216
|
response.raise_for_status()
|
|
181
217
|
return ValueResponse(**response.json()[0])
|
|
182
218
|
|
|
219
|
+
def get_closed_positions(
|
|
220
|
+
self,
|
|
221
|
+
user: EthAddress,
|
|
222
|
+
condition_ids: Optional[Union[str, list[str]]] = None,
|
|
223
|
+
) -> list[Position]:
|
|
224
|
+
"""Get all closed positions."""
|
|
225
|
+
params = {"user": user}
|
|
226
|
+
if isinstance(condition_ids, str):
|
|
227
|
+
params["market"] = condition_ids
|
|
228
|
+
if isinstance(condition_ids, list):
|
|
229
|
+
params["market"] = ",".join(condition_ids)
|
|
230
|
+
|
|
231
|
+
response = self.client.get(self._build_url("/closed-positions"), params=params)
|
|
232
|
+
response.raise_for_status()
|
|
233
|
+
return [Position(**pos) for pos in response.json()]
|
|
234
|
+
|
|
235
|
+
def get_total_markets_traded(
|
|
236
|
+
self,
|
|
237
|
+
user: EthAddress,
|
|
238
|
+
) -> int:
|
|
239
|
+
"""Get the total number of markets a user has traded in."""
|
|
240
|
+
params = {"user": user}
|
|
241
|
+
|
|
242
|
+
response = self.client.get(self._build_url("/traded"), params=params)
|
|
243
|
+
response.raise_for_status()
|
|
244
|
+
return response.json()["traded"]
|
|
245
|
+
|
|
246
|
+
def get_open_interest(
|
|
247
|
+
self,
|
|
248
|
+
condition_ids: Optional[Union[str, list[str]]] = None,
|
|
249
|
+
) -> list[MarketValue]:
|
|
250
|
+
"""Get open interest."""
|
|
251
|
+
params = {}
|
|
252
|
+
|
|
253
|
+
if isinstance(condition_ids, str):
|
|
254
|
+
params["market"] = condition_ids
|
|
255
|
+
if isinstance(condition_ids, list):
|
|
256
|
+
params["market"] = ",".join(condition_ids)
|
|
257
|
+
|
|
258
|
+
response = self.client.get(self._build_url("/oi"), params=params)
|
|
259
|
+
response.raise_for_status()
|
|
260
|
+
return [MarketValue(**oi) for oi in response.json()]
|
|
261
|
+
|
|
262
|
+
def get_live_volume(
|
|
263
|
+
self,
|
|
264
|
+
event_id: int,
|
|
265
|
+
) -> EventLiveVolume:
|
|
266
|
+
"""Get live volume for a given event."""
|
|
267
|
+
params = {"id": str(event_id)}
|
|
268
|
+
|
|
269
|
+
response = self.client.get(self._build_url("/live-volume"), params=params)
|
|
270
|
+
response.raise_for_status()
|
|
271
|
+
return EventLiveVolume(**response.json()[0])
|
|
272
|
+
|
|
183
273
|
# website endpoints
|
|
184
274
|
|
|
185
275
|
def get_pnl(
|