polymarket-apis 0.2.4__py3-none-any.whl → 0.2.6__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/types/gamma_types.py +1 -1
- {polymarket_apis-0.2.4.dist-info → polymarket_apis-0.2.6.dist-info}/METADATA +1 -1
- {polymarket_apis-0.2.4.dist-info → polymarket_apis-0.2.6.dist-info}/RECORD +4 -5
- polymarket_apis/clients/graphql_client.py +0 -182
- {polymarket_apis-0.2.4.dist-info → polymarket_apis-0.2.6.dist-info}/WHEEL +0 -0
|
@@ -332,7 +332,7 @@ class Pagination(BaseModel):
|
|
|
332
332
|
total_results: int = Field(alias="totalResults")
|
|
333
333
|
|
|
334
334
|
class EventList(BaseModel):
|
|
335
|
-
events: list[QueryEvent]
|
|
335
|
+
events: Optional[list[QueryEvent]] = None
|
|
336
336
|
pagination: Pagination
|
|
337
337
|
|
|
338
338
|
class QueryMarket(BaseModel):
|
|
@@ -3,14 +3,13 @@ polymarket_apis/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG
|
|
|
3
3
|
polymarket_apis/clients/clob_client.py,sha256=pE-q-4hAUyKIUHN5tbBxX4o4uzMGiMcTNQ2dIJLQkDY,31025
|
|
4
4
|
polymarket_apis/clients/data_client.py,sha256=sAJqesjKT8cRNr-j4OsXj-xYHEOzt0WWCvXcvejX7uI,8641
|
|
5
5
|
polymarket_apis/clients/gamma_client.py,sha256=yGi7l0vceBgrwMlqLFZYyQ_Lj13hNaDwaBtLSDoTAnM,12190
|
|
6
|
-
polymarket_apis/clients/graphql_client.py,sha256=Jgrz107EVpHRSAXvY45hRUKuPndl9-41_EaqIYbb5mo,6907
|
|
7
6
|
polymarket_apis/clients/web3_client.py,sha256=0SX25LMP59FWzfsoshxt-_XNPcPXnmvwmCaHu3K4K2E,11222
|
|
8
7
|
polymarket_apis/clients/websockets_client.py,sha256=wueJ54ZgJgeiJmKi5EEIB8_YwkdD3y2Dr4t9WjFMXuU,7581
|
|
9
8
|
polymarket_apis/types/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
9
|
polymarket_apis/types/clob_types.py,sha256=O7_6x5gtLjjkcVhcUMv7aIyFhdk2LRfRObPibRwdC44,11699
|
|
11
10
|
polymarket_apis/types/common.py,sha256=eTY2kjOArzrZRVSmEJvxEyxGJeMx045R073EMZMzCKM,1629
|
|
12
11
|
polymarket_apis/types/data_types.py,sha256=K-bE5g1owFozvznmQZ0MicxGccqVSuEibuVzXFAoa4E,4408
|
|
13
|
-
polymarket_apis/types/gamma_types.py,sha256=
|
|
12
|
+
polymarket_apis/types/gamma_types.py,sha256=xSafNRgkYXqIq3Vd5J3k018ue79rEiulczwUHuP8Uxo,12535
|
|
14
13
|
polymarket_apis/types/websockets_types.py,sha256=96xQl6xQ4ReL-b4a-UYNittPvXJBXuzX1RBxlJHJg-s,11993
|
|
15
14
|
polymarket_apis/utilities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
15
|
polymarket_apis/utilities/config.py,sha256=IfIBJa6rSi-e-9_HjeI8j4cD3MXtzRjoLzgcgn5tHbc,2448
|
|
@@ -36,6 +35,6 @@ polymarket_apis/utilities/web3/abis/ProxyWalletFactory.json,sha256=5KjBHUWdkc_kd
|
|
|
36
35
|
polymarket_apis/utilities/web3/abis/UChildERC20Proxy.json,sha256=ZyQC38U0uxInlmnW2VXDVD3TJfTIRmSNMkTxQsaG7oA,27396
|
|
37
36
|
polymarket_apis/utilities/web3/abis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
38
37
|
polymarket_apis/utilities/web3/abis/custom_contract_errors.py,sha256=ZCeJPK5tobPAR9vaNxw_pQZwKyZc_R0GdggfWaeXvOs,1176
|
|
39
|
-
polymarket_apis-0.2.
|
|
40
|
-
polymarket_apis-0.2.
|
|
41
|
-
polymarket_apis-0.2.
|
|
38
|
+
polymarket_apis-0.2.6.dist-info/METADATA,sha256=u_9ZmKKZb_JMmjlwhVtIGENX66ir_PtdbK8xXf0XkOM,558
|
|
39
|
+
polymarket_apis-0.2.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
40
|
+
polymarket_apis-0.2.6.dist-info/RECORD,,
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
from typing import Literal, Optional
|
|
2
|
-
|
|
3
|
-
from gql import Client, gql
|
|
4
|
-
from gql.transport.httpx import HTTPXAsyncTransport
|
|
5
|
-
from graphql import GraphQLInputObjectType, GraphQLObjectType
|
|
6
|
-
|
|
7
|
-
from ..utilities.config import GRAPHQL_ENDPOINTS
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class PolymarketGraphQLClient:
|
|
11
|
-
def __init__(self,
|
|
12
|
-
endpoint_name: Literal[
|
|
13
|
-
"activity_subgraph",
|
|
14
|
-
"fpmm_subgraph",
|
|
15
|
-
"open_interest_subgraph",
|
|
16
|
-
"orderbook_subgraph",
|
|
17
|
-
"pnl_subgraph",
|
|
18
|
-
"positions_subgraph",
|
|
19
|
-
"sports_oracle_subgraph",
|
|
20
|
-
"wallet_subgraph",
|
|
21
|
-
]):
|
|
22
|
-
if endpoint_name not in GRAPHQL_ENDPOINTS:
|
|
23
|
-
msg = f"Invalid endpoint name: {endpoint_name}. Must be one of {list(GRAPHQL_ENDPOINTS.keys())}"
|
|
24
|
-
raise ValueError(msg)
|
|
25
|
-
endpoint_url = GRAPHQL_ENDPOINTS[endpoint_name]
|
|
26
|
-
self.transport = HTTPXAsyncTransport(url=endpoint_url)
|
|
27
|
-
self.client = Client(transport=self.transport, fetch_schema_from_transport=True)
|
|
28
|
-
self.schema = None
|
|
29
|
-
self.object_types = []
|
|
30
|
-
self.query_fields = []
|
|
31
|
-
self.subscription_fields = []
|
|
32
|
-
self.filter_input_types = []
|
|
33
|
-
|
|
34
|
-
async def _init_schema(self):
|
|
35
|
-
async with self.client as session:
|
|
36
|
-
self.schema = session.schema
|
|
37
|
-
|
|
38
|
-
async def _get_query_fields(self):
|
|
39
|
-
if self.query_fields:
|
|
40
|
-
return self.query_fields
|
|
41
|
-
if not self.schema:
|
|
42
|
-
await self._init_schema()
|
|
43
|
-
self.query_fields = [field for field in self.schema.type_map["Query"].fields if not field.startswith("_")]
|
|
44
|
-
|
|
45
|
-
return self.query_fields
|
|
46
|
-
|
|
47
|
-
async def _get_subscription_fields(self):
|
|
48
|
-
if self.subscription_fields:
|
|
49
|
-
return self.subscription_fields
|
|
50
|
-
if not self.schema:
|
|
51
|
-
await self._init_schema()
|
|
52
|
-
if "Subscription" in self.schema.type_map:
|
|
53
|
-
self.subscription_fields = [field for field in self.schema.type_map["Subscription"].fields if not field.startswith("_")]
|
|
54
|
-
else:
|
|
55
|
-
self.subscription_fields = []
|
|
56
|
-
return self.subscription_fields
|
|
57
|
-
|
|
58
|
-
async def _get_object_types(self):
|
|
59
|
-
if self.object_types:
|
|
60
|
-
return self.object_types
|
|
61
|
-
if not self.schema:
|
|
62
|
-
await self._init_schema()
|
|
63
|
-
for object_name, object in self.schema.type_map.items():
|
|
64
|
-
if type(object) is GraphQLObjectType and not object_name.startswith("_"):
|
|
65
|
-
self.object_types.append(object_name)
|
|
66
|
-
return self.object_types
|
|
67
|
-
|
|
68
|
-
async def _get_filter_input_types(self):
|
|
69
|
-
if self.filter_input_types:
|
|
70
|
-
return self.filter_input_types
|
|
71
|
-
if not self.schema:
|
|
72
|
-
await self._init_schema()
|
|
73
|
-
for object_name, object in self.schema.type_map.items():
|
|
74
|
-
if isinstance(object, GraphQLInputObjectType) and not object_name.startswith("_"):
|
|
75
|
-
self.filter_input_types.append(object_name)
|
|
76
|
-
return self.filter_input_types
|
|
77
|
-
|
|
78
|
-
async def list_queries(self):
|
|
79
|
-
if self.query_fields:
|
|
80
|
-
return self.query_fields
|
|
81
|
-
return await self._get_query_fields()
|
|
82
|
-
|
|
83
|
-
async def list_subscriptions(self):
|
|
84
|
-
if self.subscription_fields:
|
|
85
|
-
return self.subscription_fields
|
|
86
|
-
return await self._get_subscription_fields()
|
|
87
|
-
|
|
88
|
-
async def list_object_types(self):
|
|
89
|
-
if self.object_types:
|
|
90
|
-
return self.object_types
|
|
91
|
-
return await self._get_object_types()
|
|
92
|
-
|
|
93
|
-
async def list_filter_input_types(self):
|
|
94
|
-
if self.filter_input_types:
|
|
95
|
-
return self.filter_input_types
|
|
96
|
-
return await self._get_filter_input_types()
|
|
97
|
-
|
|
98
|
-
async def get_fields(self, object_name: str):
|
|
99
|
-
if self.schema is None:
|
|
100
|
-
await self._init_schema()
|
|
101
|
-
if object_name not in self.schema.type_map:
|
|
102
|
-
msg = "Invalid object name"
|
|
103
|
-
raise ValueError(msg)
|
|
104
|
-
return list(self.schema.type_map[object_name].fields.keys())
|
|
105
|
-
|
|
106
|
-
async def query(
|
|
107
|
-
self,
|
|
108
|
-
endpoint: str,
|
|
109
|
-
fields: list[str],
|
|
110
|
-
filters: Optional[dict] = None,
|
|
111
|
-
relationships: Optional[dict] = None,
|
|
112
|
-
):
|
|
113
|
-
if not self.schema:
|
|
114
|
-
await self._init_schema()
|
|
115
|
-
if not self.query_fields:
|
|
116
|
-
await self._get_query_fields()
|
|
117
|
-
if not self.object_types:
|
|
118
|
-
await self._get_object_types()
|
|
119
|
-
|
|
120
|
-
if endpoint not in self.query_fields:
|
|
121
|
-
msg = f"Invalid endpoint: {endpoint}"
|
|
122
|
-
raise ValueError(msg)
|
|
123
|
-
|
|
124
|
-
endpoint_field = self.schema.type_map["Query"].fields[endpoint]
|
|
125
|
-
required_args = [
|
|
126
|
-
arg_name for arg_name, arg in endpoint_field.args.items()
|
|
127
|
-
if arg.type.to_kwargs().get("required", False)
|
|
128
|
-
]
|
|
129
|
-
missing_args = [arg for arg in required_args if not (filters and arg in filters)]
|
|
130
|
-
if missing_args:
|
|
131
|
-
msg = f"Missing required argument(s) for '{endpoint}': {', '.join(missing_args)}"
|
|
132
|
-
raise ValueError(msg)
|
|
133
|
-
|
|
134
|
-
def build_selection(fields, relationships):
|
|
135
|
-
selections = []
|
|
136
|
-
for field in fields:
|
|
137
|
-
if relationships and field in relationships:
|
|
138
|
-
subfields = relationships[field]
|
|
139
|
-
selections.append(f"{field} {{ {' '.join(subfields)} }}")
|
|
140
|
-
else:
|
|
141
|
-
selections.append(field)
|
|
142
|
-
return " ".join(selections)
|
|
143
|
-
|
|
144
|
-
def build_args(filters):
|
|
145
|
-
"""Build GraphQL arguments, handling both simple and complex where clauses."""
|
|
146
|
-
if not filters:
|
|
147
|
-
return ""
|
|
148
|
-
|
|
149
|
-
arg_strs = []
|
|
150
|
-
for k, v in filters.items():
|
|
151
|
-
if k == "where" and isinstance(v, dict):
|
|
152
|
-
# Handle complex where clause
|
|
153
|
-
where_conditions = []
|
|
154
|
-
for where_key, where_value in v.items():
|
|
155
|
-
if isinstance(where_value, str):
|
|
156
|
-
where_conditions.append(f"{where_key}: {where_value}")
|
|
157
|
-
else:
|
|
158
|
-
where_conditions.append(f"{where_key}: {where_value}")
|
|
159
|
-
where_str = "{" + ", ".join(where_conditions) + "}"
|
|
160
|
-
arg_strs.append(f"{k}: {where_str}")
|
|
161
|
-
# Handle simple key-value filters
|
|
162
|
-
elif isinstance(v, str):
|
|
163
|
-
arg_strs.append(f'{k}: "{v}"')
|
|
164
|
-
else:
|
|
165
|
-
arg_strs.append(f"{k}: {v}")
|
|
166
|
-
|
|
167
|
-
return "(" + ", ".join(arg_strs) + ")"
|
|
168
|
-
|
|
169
|
-
selection_set = build_selection(fields, relationships)
|
|
170
|
-
args = build_args(filters)
|
|
171
|
-
|
|
172
|
-
query_str = f"""
|
|
173
|
-
query {{
|
|
174
|
-
{endpoint}{args} {{
|
|
175
|
-
{selection_set}
|
|
176
|
-
}}
|
|
177
|
-
}}
|
|
178
|
-
"""
|
|
179
|
-
print(query_str)
|
|
180
|
-
async with self.client as session:
|
|
181
|
-
result = await session.execute(gql(query_str))
|
|
182
|
-
return result
|
|
File without changes
|