polymarket-apis 0.3.0__py3-none-any.whl → 0.3.9__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 +42 -0
- polymarket_apis/clients/__init__.py +23 -0
- polymarket_apis/clients/clob_client.py +224 -117
- polymarket_apis/clients/data_client.py +220 -67
- polymarket_apis/clients/gamma_client.py +589 -101
- polymarket_apis/clients/graphql_client.py +28 -11
- polymarket_apis/clients/web3_client.py +538 -131
- polymarket_apis/clients/websockets_client.py +24 -7
- polymarket_apis/types/__init__.py +167 -0
- polymarket_apis/types/clob_types.py +35 -14
- polymarket_apis/types/common.py +105 -35
- polymarket_apis/types/data_types.py +48 -3
- polymarket_apis/types/gamma_types.py +529 -257
- polymarket_apis/types/web3_types.py +45 -0
- polymarket_apis/types/websockets_types.py +92 -41
- polymarket_apis/utilities/config.py +1 -0
- polymarket_apis/utilities/constants.py +5 -4
- polymarket_apis/utilities/exceptions.py +9 -0
- polymarket_apis/utilities/order_builder/builder.py +38 -22
- polymarket_apis/utilities/order_builder/helpers.py +0 -1
- polymarket_apis/utilities/signing/hmac.py +5 -1
- polymarket_apis/utilities/signing/signer.py +2 -2
- polymarket_apis/utilities/web3/abis/Safe.json +1138 -0
- polymarket_apis/utilities/web3/abis/SafeProxyFactory.json +224 -0
- polymarket_apis/utilities/web3/abis/custom_contract_errors.py +1 -1
- polymarket_apis/utilities/web3/helpers.py +235 -0
- {polymarket_apis-0.3.0.dist-info → polymarket_apis-0.3.9.dist-info}/METADATA +48 -8
- polymarket_apis-0.3.9.dist-info/RECORD +44 -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.9.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"inputs": [
|
|
4
|
+
{
|
|
5
|
+
"internalType": "address",
|
|
6
|
+
"name": "_masterCopy",
|
|
7
|
+
"type": "address"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"internalType": "address",
|
|
11
|
+
"name": "_fallbackHandler",
|
|
12
|
+
"type": "address"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"stateMutability": "nonpayable",
|
|
16
|
+
"type": "constructor"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"anonymous": false,
|
|
20
|
+
"inputs": [
|
|
21
|
+
{
|
|
22
|
+
"indexed": false,
|
|
23
|
+
"internalType": "contract GnosisSafe",
|
|
24
|
+
"name": "proxy",
|
|
25
|
+
"type": "address"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"indexed": false,
|
|
29
|
+
"internalType": "address",
|
|
30
|
+
"name": "owner",
|
|
31
|
+
"type": "address"
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"name": "ProxyCreation",
|
|
35
|
+
"type": "event"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"inputs": [ ],
|
|
39
|
+
"name": "CREATE_PROXY_TYPEHASH",
|
|
40
|
+
"outputs": [
|
|
41
|
+
{
|
|
42
|
+
"internalType": "bytes32",
|
|
43
|
+
"name": "",
|
|
44
|
+
"type": "bytes32"
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
"stateMutability": "view",
|
|
48
|
+
"type": "function"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"inputs": [ ],
|
|
52
|
+
"name": "DOMAIN_TYPEHASH",
|
|
53
|
+
"outputs": [
|
|
54
|
+
{
|
|
55
|
+
"internalType": "bytes32",
|
|
56
|
+
"name": "",
|
|
57
|
+
"type": "bytes32"
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
"stateMutability": "view",
|
|
61
|
+
"type": "function"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"inputs": [ ],
|
|
65
|
+
"name": "NAME",
|
|
66
|
+
"outputs": [
|
|
67
|
+
{
|
|
68
|
+
"internalType": "string",
|
|
69
|
+
"name": "",
|
|
70
|
+
"type": "string"
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
"stateMutability": "view",
|
|
74
|
+
"type": "function"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"inputs": [
|
|
78
|
+
{
|
|
79
|
+
"internalType": "address",
|
|
80
|
+
"name": "user",
|
|
81
|
+
"type": "address"
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
"name": "computeProxyAddress",
|
|
85
|
+
"outputs": [
|
|
86
|
+
{
|
|
87
|
+
"internalType": "address",
|
|
88
|
+
"name": "",
|
|
89
|
+
"type": "address"
|
|
90
|
+
}
|
|
91
|
+
],
|
|
92
|
+
"stateMutability": "view",
|
|
93
|
+
"type": "function"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"inputs": [
|
|
97
|
+
{
|
|
98
|
+
"internalType": "address",
|
|
99
|
+
"name": "paymentToken",
|
|
100
|
+
"type": "address"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"internalType": "uint256",
|
|
104
|
+
"name": "payment",
|
|
105
|
+
"type": "uint256"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"internalType": "address payable",
|
|
109
|
+
"name": "paymentReceiver",
|
|
110
|
+
"type": "address"
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"components": [
|
|
114
|
+
{
|
|
115
|
+
"internalType": "uint8",
|
|
116
|
+
"name": "v",
|
|
117
|
+
"type": "uint8"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"internalType": "bytes32",
|
|
121
|
+
"name": "r",
|
|
122
|
+
"type": "bytes32"
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"internalType": "bytes32",
|
|
126
|
+
"name": "s",
|
|
127
|
+
"type": "bytes32"
|
|
128
|
+
}
|
|
129
|
+
],
|
|
130
|
+
"internalType": "struct SafeProxyFactory.Sig",
|
|
131
|
+
"name": "createSig",
|
|
132
|
+
"type": "tuple"
|
|
133
|
+
}
|
|
134
|
+
],
|
|
135
|
+
"name": "createProxy",
|
|
136
|
+
"outputs": [ ],
|
|
137
|
+
"stateMutability": "nonpayable",
|
|
138
|
+
"type": "function"
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"inputs": [ ],
|
|
142
|
+
"name": "domainSeparator",
|
|
143
|
+
"outputs": [
|
|
144
|
+
{
|
|
145
|
+
"internalType": "bytes32",
|
|
146
|
+
"name": "",
|
|
147
|
+
"type": "bytes32"
|
|
148
|
+
}
|
|
149
|
+
],
|
|
150
|
+
"stateMutability": "view",
|
|
151
|
+
"type": "function"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"inputs": [ ],
|
|
155
|
+
"name": "fallbackHandler",
|
|
156
|
+
"outputs": [
|
|
157
|
+
{
|
|
158
|
+
"internalType": "address",
|
|
159
|
+
"name": "",
|
|
160
|
+
"type": "address"
|
|
161
|
+
}
|
|
162
|
+
],
|
|
163
|
+
"stateMutability": "view",
|
|
164
|
+
"type": "function"
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
"inputs": [ ],
|
|
168
|
+
"name": "getContractBytecode",
|
|
169
|
+
"outputs": [
|
|
170
|
+
{
|
|
171
|
+
"internalType": "bytes",
|
|
172
|
+
"name": "",
|
|
173
|
+
"type": "bytes"
|
|
174
|
+
}
|
|
175
|
+
],
|
|
176
|
+
"stateMutability": "view",
|
|
177
|
+
"type": "function"
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
"inputs": [
|
|
181
|
+
{
|
|
182
|
+
"internalType": "address",
|
|
183
|
+
"name": "user",
|
|
184
|
+
"type": "address"
|
|
185
|
+
}
|
|
186
|
+
],
|
|
187
|
+
"name": "getSalt",
|
|
188
|
+
"outputs": [
|
|
189
|
+
{
|
|
190
|
+
"internalType": "bytes32",
|
|
191
|
+
"name": "",
|
|
192
|
+
"type": "bytes32"
|
|
193
|
+
}
|
|
194
|
+
],
|
|
195
|
+
"stateMutability": "pure",
|
|
196
|
+
"type": "function"
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
"inputs": [ ],
|
|
200
|
+
"name": "masterCopy",
|
|
201
|
+
"outputs": [
|
|
202
|
+
{
|
|
203
|
+
"internalType": "address",
|
|
204
|
+
"name": "",
|
|
205
|
+
"type": "address"
|
|
206
|
+
}
|
|
207
|
+
],
|
|
208
|
+
"stateMutability": "view",
|
|
209
|
+
"type": "function"
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
"inputs": [ ],
|
|
213
|
+
"name": "proxyCreationCode",
|
|
214
|
+
"outputs": [
|
|
215
|
+
{
|
|
216
|
+
"internalType": "bytes",
|
|
217
|
+
"name": "",
|
|
218
|
+
"type": "bytes"
|
|
219
|
+
}
|
|
220
|
+
],
|
|
221
|
+
"stateMutability": "pure",
|
|
222
|
+
"type": "function"
|
|
223
|
+
}
|
|
224
|
+
]
|
|
@@ -1,8 +1,243 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from collections.abc import Iterable
|
|
3
|
+
from typing import Any, Literal
|
|
4
|
+
|
|
5
|
+
from eth_account import Account
|
|
6
|
+
from eth_account.messages import encode_defunct
|
|
7
|
+
from web3.constants import ADDRESS_ZERO
|
|
8
|
+
from web3.contract import Contract
|
|
9
|
+
|
|
10
|
+
|
|
1
11
|
def get_market_index(question_id: str) -> int:
|
|
2
12
|
"""Extract the market index from a question ID (last 2 hex characters)."""
|
|
3
13
|
return int(question_id[-2:], 16)
|
|
4
14
|
|
|
15
|
+
|
|
5
16
|
def get_index_set(question_ids: list[str]) -> int:
|
|
6
17
|
"""Calculate bitwise index set from question IDs."""
|
|
7
18
|
indices = [get_market_index(question_id) for question_id in question_ids]
|
|
8
19
|
return sum(1 << index for index in set(indices))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _pack_primitive(typ: str, val: Any) -> bytes:
|
|
23
|
+
if isinstance(val, str) and val.startswith("0x"):
|
|
24
|
+
raw = bytes.fromhex(val[2:])
|
|
25
|
+
elif isinstance(val, bytes):
|
|
26
|
+
raw = val
|
|
27
|
+
else:
|
|
28
|
+
raw = val
|
|
29
|
+
|
|
30
|
+
if typ == "string":
|
|
31
|
+
if not isinstance(raw, bytes | str):
|
|
32
|
+
msg = "string value must be str or bytes"
|
|
33
|
+
raise TypeError(msg)
|
|
34
|
+
return raw.encode() if isinstance(raw, str) else raw
|
|
35
|
+
if typ == "bytes":
|
|
36
|
+
if isinstance(raw, int):
|
|
37
|
+
msg = "bytes value must be hex/bytes/str"
|
|
38
|
+
raise TypeError(msg)
|
|
39
|
+
if isinstance(raw, str):
|
|
40
|
+
return raw.encode()
|
|
41
|
+
return raw
|
|
42
|
+
|
|
43
|
+
m = re.match(r"^bytes(\d+)$", typ)
|
|
44
|
+
if m:
|
|
45
|
+
n = int(m.group(1))
|
|
46
|
+
if isinstance(raw, int):
|
|
47
|
+
b = raw.to_bytes(n, "big")
|
|
48
|
+
elif isinstance(raw, str) and raw.startswith("0x"):
|
|
49
|
+
b = bytes.fromhex(raw[2:])
|
|
50
|
+
elif isinstance(raw, bytes | bytearray):
|
|
51
|
+
b = bytes(raw)
|
|
52
|
+
else:
|
|
53
|
+
msg = f"unsupported value for {typ}"
|
|
54
|
+
raise TypeError(msg)
|
|
55
|
+
if len(b) != n:
|
|
56
|
+
if len(b) > n:
|
|
57
|
+
return b[:n]
|
|
58
|
+
return b.ljust(n, b"\x00")
|
|
59
|
+
return b
|
|
60
|
+
|
|
61
|
+
if typ == "address":
|
|
62
|
+
if isinstance(raw, str) and raw.startswith("0x"):
|
|
63
|
+
addr = raw[2:]
|
|
64
|
+
elif isinstance(raw, str):
|
|
65
|
+
addr = raw
|
|
66
|
+
elif isinstance(raw, bytes | bytearray):
|
|
67
|
+
return bytes(raw[-20:])
|
|
68
|
+
else:
|
|
69
|
+
msg = "address must be hex string or bytes"
|
|
70
|
+
raise TypeError(msg)
|
|
71
|
+
addr = addr.rjust(40, "0")[-40:]
|
|
72
|
+
return bytes.fromhex(addr)
|
|
73
|
+
|
|
74
|
+
m = re.match(r"^u?int(\d*)$", typ)
|
|
75
|
+
if m:
|
|
76
|
+
bits = int(m.group(1)) if m.group(1) else 256
|
|
77
|
+
size = bits // 8
|
|
78
|
+
if isinstance(raw, bytes | bytearray):
|
|
79
|
+
intval = int.from_bytes(raw, "big")
|
|
80
|
+
elif isinstance(raw, str) and raw.startswith("0x"):
|
|
81
|
+
intval = int(raw, 16)
|
|
82
|
+
elif isinstance(raw, int):
|
|
83
|
+
intval = raw
|
|
84
|
+
else:
|
|
85
|
+
msg = f"unsupported value for {typ}"
|
|
86
|
+
raise TypeError(msg)
|
|
87
|
+
if intval < 0:
|
|
88
|
+
intval &= (1 << bits) - 1
|
|
89
|
+
return intval.to_bytes(size, "big")
|
|
90
|
+
|
|
91
|
+
msg = f"unsupported type {typ}"
|
|
92
|
+
raise ValueError(msg)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def abi_encode_packed(*params: dict) -> bytes:
|
|
96
|
+
"""
|
|
97
|
+
Takes in sequence of {'type': str, 'value': any}.
|
|
98
|
+
|
|
99
|
+
returns: concatenated packed bytes (no 0x prefix).
|
|
100
|
+
"""
|
|
101
|
+
parts: list[bytes] = []
|
|
102
|
+
for p in params:
|
|
103
|
+
typ = p["type"]
|
|
104
|
+
val = p["value"]
|
|
105
|
+
if typ.endswith("[]"):
|
|
106
|
+
inner = typ[:-2]
|
|
107
|
+
if not isinstance(val, Iterable):
|
|
108
|
+
msg = f"expected array value for {typ}"
|
|
109
|
+
raise TypeError(msg)
|
|
110
|
+
for elem in val:
|
|
111
|
+
parts.append(abi_encode_packed({"type": inner, "value": elem}))
|
|
112
|
+
continue
|
|
113
|
+
parts.append(_pack_primitive(typ, val))
|
|
114
|
+
return b"".join(parts)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def split_signature(signature_hex: str) -> dict[str, Any]:
|
|
118
|
+
"""
|
|
119
|
+
Split a signature into r, s, v components compatible with Safe factory.
|
|
120
|
+
|
|
121
|
+
Args:
|
|
122
|
+
signature_hex: Signature as hex string
|
|
123
|
+
|
|
124
|
+
Returns:
|
|
125
|
+
dict: Dictionary with r, s, v components properly formatted for the contract
|
|
126
|
+
|
|
127
|
+
"""
|
|
128
|
+
# Remove 0x prefix if present
|
|
129
|
+
signature_hex = signature_hex.removeprefix("0x")
|
|
130
|
+
|
|
131
|
+
# Convert to bytes
|
|
132
|
+
signature_bytes = bytes.fromhex(signature_hex)
|
|
133
|
+
|
|
134
|
+
if len(signature_bytes) != 65:
|
|
135
|
+
msg = "Invalid signature length"
|
|
136
|
+
raise ValueError(msg)
|
|
137
|
+
|
|
138
|
+
# Extract r, s, v
|
|
139
|
+
r = signature_bytes[:32]
|
|
140
|
+
s = signature_bytes[32:64]
|
|
141
|
+
v = signature_bytes[64]
|
|
142
|
+
|
|
143
|
+
if v < 27:
|
|
144
|
+
if v in {0, 1}:
|
|
145
|
+
v += 27
|
|
146
|
+
else:
|
|
147
|
+
msg = "Invalid signature v value"
|
|
148
|
+
raise ValueError(msg)
|
|
149
|
+
|
|
150
|
+
# Return properly formatted components for the contract:
|
|
151
|
+
# - r and s as bytes32 (keep as bytes, web3.py will handle conversion)
|
|
152
|
+
# - v as uint8 (integer)
|
|
153
|
+
return {
|
|
154
|
+
"r": r, # bytes32
|
|
155
|
+
"s": s, # bytes32
|
|
156
|
+
"v": v, # uint8
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def create_safe_create_signature(
|
|
161
|
+
account: Account, chain_id: Literal[137, 80002]
|
|
162
|
+
) -> str:
|
|
163
|
+
"""
|
|
164
|
+
Create EIP-712 signature for Safe creation.
|
|
165
|
+
|
|
166
|
+
Returns:
|
|
167
|
+
str: The signature as hex string
|
|
168
|
+
|
|
169
|
+
"""
|
|
170
|
+
# EIP-712 domain
|
|
171
|
+
domain = {
|
|
172
|
+
"name": "Polymarket Contract Proxy Factory",
|
|
173
|
+
"chainId": chain_id,
|
|
174
|
+
"verifyingContract": "0xaacFeEa03eb1561C4e67d661e40682Bd20E3541b",
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
# EIP-712 types
|
|
178
|
+
types = {
|
|
179
|
+
"CreateProxy": [
|
|
180
|
+
{"name": "paymentToken", "type": "address"},
|
|
181
|
+
{"name": "payment", "type": "uint256"},
|
|
182
|
+
{"name": "paymentReceiver", "type": "address"},
|
|
183
|
+
]
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
# Values to sign
|
|
187
|
+
values = {
|
|
188
|
+
"paymentToken": ADDRESS_ZERO,
|
|
189
|
+
"payment": 0,
|
|
190
|
+
"paymentReceiver": ADDRESS_ZERO,
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
# Create the signature using eth_account
|
|
194
|
+
signature = account.sign_typed_data(domain, types, values)
|
|
195
|
+
|
|
196
|
+
return signature.signature.hex()
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def sign_safe_transaction(
|
|
200
|
+
account: Account, safe: Contract, safe_txn: dict, nonce: int
|
|
201
|
+
) -> bytes:
|
|
202
|
+
safe_tx_gas = 0
|
|
203
|
+
base_gas = 0
|
|
204
|
+
gas_price = 0
|
|
205
|
+
gas_token = ADDRESS_ZERO
|
|
206
|
+
refund_receiver = ADDRESS_ZERO
|
|
207
|
+
|
|
208
|
+
tx_hash_bytes = safe.functions.getTransactionHash(
|
|
209
|
+
safe_txn["to"],
|
|
210
|
+
safe_txn["value"],
|
|
211
|
+
safe_txn["data"],
|
|
212
|
+
safe_txn.get("operation", 0),
|
|
213
|
+
safe_tx_gas,
|
|
214
|
+
base_gas,
|
|
215
|
+
gas_price,
|
|
216
|
+
gas_token,
|
|
217
|
+
refund_receiver,
|
|
218
|
+
nonce,
|
|
219
|
+
).call()
|
|
220
|
+
|
|
221
|
+
tx_hash_hex = tx_hash_bytes.hex()
|
|
222
|
+
message = encode_defunct(hexstr=tx_hash_hex)
|
|
223
|
+
signed = account.sign_message(message)
|
|
224
|
+
r = signed.r
|
|
225
|
+
s = signed.s
|
|
226
|
+
v = signed.v
|
|
227
|
+
|
|
228
|
+
match v:
|
|
229
|
+
case 0 | 1:
|
|
230
|
+
v += 31
|
|
231
|
+
case 27 | 28:
|
|
232
|
+
v += 4
|
|
233
|
+
case _:
|
|
234
|
+
msg = "Invalid signature V value"
|
|
235
|
+
raise ValueError(msg)
|
|
236
|
+
|
|
237
|
+
packed_sig = abi_encode_packed(
|
|
238
|
+
{"type": "uint256", "value": r},
|
|
239
|
+
{"type": "uint256", "value": s},
|
|
240
|
+
{"type": "uint8", "value": v},
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
return packed_sig
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: polymarket-apis
|
|
3
|
-
Version: 0.3.
|
|
4
|
-
Summary: Unified Polymarket APIs -
|
|
3
|
+
Version: 0.3.9
|
|
4
|
+
Summary: Unified Polymarket APIs with Pydantic data validation - Clob, Gamma, Data, Web3, Websockets, GraphQL clients.
|
|
5
|
+
Project-URL: repository, https://github.com/qualiaenjoyer/polymarket-apis
|
|
5
6
|
Author-email: Razvan Gheorghe <razvan@gheorghe.me>
|
|
6
7
|
Requires-Python: >=3.12
|
|
7
8
|
Requires-Dist: gql[httpx]>=4.0.0
|
|
@@ -10,13 +11,14 @@ Requires-Dist: lomond>=0.3.3
|
|
|
10
11
|
Requires-Dist: poly-eip712-structs>=0.0.1
|
|
11
12
|
Requires-Dist: py-order-utils>=0.3.2
|
|
12
13
|
Requires-Dist: pydantic>=2.10.5
|
|
14
|
+
Requires-Dist: python-dateutil>=2.9.0
|
|
13
15
|
Requires-Dist: web3>=7.0
|
|
14
16
|
Requires-Dist: wsaccel>=0.6.7
|
|
15
17
|
Description-Content-Type: text/markdown
|
|
16
18
|
|
|
17
|
-
# polymarket-apis [](https://pypi.org/project/polymarket-apis/)
|
|
19
|
+
# polymarket-apis [](https://pypi.org/project/polymarket-apis/) [](https://deepwiki.com/qualiaenjoyer/polymarket-apis)
|
|
18
20
|
|
|
19
|
-
Polymarket
|
|
21
|
+
Unified Polymarket APIs with Pydantic data validation - Clob, Gamma, Data, Web3, Websockets, GraphQL clients.
|
|
20
22
|
|
|
21
23
|
## Polymarket Mental Models
|
|
22
24
|
|
|
@@ -47,6 +49,9 @@ flowchart LR
|
|
|
47
49
|
- **Outcome** — represents a binary option related to a market. (most commonly `Yes`/`No`, but can be e.g. `Paris Saint-Germain`/`Inter Milan` in the case of a match where draws are not possible)
|
|
48
50
|
- Identified by a **`token id`** (e.g. `15353185604353847122370324954202969073036867278400776447048296624042585335546` for the `Yes` outcome in the 1 rate cut in 2025 market)
|
|
49
51
|
|
|
52
|
+
- The different APIs represent Events/Markets differently (e.g. Event, QueryEvent / ClobMarket, GammaMarket, RewardsMarket) but they all use to the same underlying identifiers.
|
|
53
|
+
|
|
54
|
+
|
|
50
55
|
### Tokens
|
|
51
56
|
- **Tokens** are the blockchain implementation of **Outcomes** - tradable digital assets on the Polygon blockchain that users buy, hold and sell on Polygon.
|
|
52
57
|
- This helps ensure the logic of binary outcome prediction markets through smart contracts (e.g. collateralization, token prices going to $1.00 or $0.00 after resolution, splits/merges).
|
|
@@ -84,22 +89,45 @@ flowchart LR
|
|
|
84
89
|
- check if a **Market** offers rewards by `condition_id` - **get_market_rewards()**
|
|
85
90
|
- get all active markets that offer rewards sorted by different metrics and ordered, filtered by a query, show your favourites from the web app - **get_reward_markets()** (*naming would do with some work*)
|
|
86
91
|
- #### Miscellaneous
|
|
87
|
-
- get price history
|
|
92
|
+
- get recent price history by `token_id` in the last 1h, 6h, 1d, 1w, 1m
|
|
93
|
+
- get price history by `token_id` in start/end interval
|
|
94
|
+
- get all price history by `token_id` in 2 min increments
|
|
88
95
|
- get **ClobMarket** by `condition_id`
|
|
89
96
|
- get all **ClobMarkets**
|
|
90
97
|
|
|
91
98
|
### PolymarketGammaClient - Market/Event related operations
|
|
92
99
|
- #### Market
|
|
93
100
|
- get **GammaMarket** by `market_id`
|
|
101
|
+
- get **GammaMarket** by `slug`
|
|
94
102
|
- get **GammaMarkets** with pagination (offset and limit), filter by `slug`s, `market_id`s, `token_id`s, `condition_id`s, `tag_id` or filtered by active, closed, archived, liquidity window, volume window, start date window, end date window and ordered
|
|
103
|
+
- get **Tags** for a **Market** by `market_id`
|
|
95
104
|
- #### Event
|
|
96
105
|
- get **Event** by `event_id`
|
|
106
|
+
- get **Event** by `slug`
|
|
97
107
|
- get **Events** with pagination, filter by `slug`s, `event_id`s, `tag_id` or filtered by active, closed, archived, liquidity window, volume window, start date window, end date window and ordered
|
|
98
108
|
- get all **Events** given some filtration
|
|
99
|
-
- search **Events**, filter by text query, active/resolved, sort by volume/volume_24hr/liquidity/start_date/end_date/competitive
|
|
100
|
-
- #### Miscellaneous
|
|
109
|
+
- search **Events**, **Tags**, **Profiles**, filter by text query, tags, active/resolved, recurrence, sort by volume/volume_24hr/liquidity/start_date/end_date/competitive
|
|
101
110
|
- grok event summary by **Event** `slug`
|
|
102
111
|
- grok election market explanation by candidate name and election title
|
|
112
|
+
- get **Tags** for an **Event** by `event_id`
|
|
113
|
+
- #### Tag
|
|
114
|
+
- get **Tags** with pagination, order by any **Tag** field
|
|
115
|
+
- get all **Tags**
|
|
116
|
+
- get **Tag** by `tag_id`
|
|
117
|
+
- get **Tag** relations by `tag_id` or `slug`
|
|
118
|
+
- get **Tags** related to a **Tag** by `tag_id` or `slug`
|
|
119
|
+
- #### Sport
|
|
120
|
+
- get **Teams** with pagination, filter by `league`, `name`, `abbreviation`
|
|
121
|
+
- get all **Teams** given some filtration
|
|
122
|
+
- get **Sports** with pagination, filter by `name`
|
|
123
|
+
- get **Sports** metadata
|
|
124
|
+
- #### Series
|
|
125
|
+
- get **Series** with pagination, filter by `slug`, closed status, order by any **Series** field
|
|
126
|
+
- get all **Series** given some filtration
|
|
127
|
+
- #### Comments
|
|
128
|
+
- get comments by `parent_entity_type` and `parent_entity_id` with pagination, order by any **Comment** field
|
|
129
|
+
- get comments by `comment_id` - gets all comments in a thread.
|
|
130
|
+
- get comments by user base address (not proxy address) with pagination, order by any **Comment** field
|
|
103
131
|
|
|
104
132
|
### PolymarketDataClient - Portfolio related operations
|
|
105
133
|
- #### Positions
|
|
@@ -115,16 +143,28 @@ flowchart LR
|
|
|
115
143
|
- `condition_ids` is ***None*** → total value of positions
|
|
116
144
|
- `condition_ids` is ***str*** → value of positions on a market
|
|
117
145
|
- `condition_ids` is ***list[str]*** → sum of values of positions on multiple markets
|
|
146
|
+
- #### Closed positions
|
|
147
|
+
- get closed positions, filter by condition_ids
|
|
118
148
|
- #### Miscellaneous
|
|
149
|
+
- get total number of markets traded by user address
|
|
150
|
+
- get open interest for a list of condition_ids
|
|
151
|
+
- get live volume for an event by `event_id`
|
|
119
152
|
- get pnl timeseries by user address for a period (1d, 1w, 1m, all) with frequency (1h, 3h, 12h, 1d)
|
|
120
153
|
- get overall pnl/volume by user address for a recent window (1d, 7d, 30d, all)
|
|
121
154
|
- get user rank on the profit/volume leaderboards by user address for a recent window (1d, 7d, 30d, all)
|
|
122
155
|
- get top users on the profit/volume leaderboards (at most 100) for a recent window (1d, 7d, 30d, all)
|
|
123
156
|
|
|
124
157
|
### PolymarketWeb3Client - Blockchain related operations
|
|
158
|
+
- #### Supporting EOA(signature_type=0), Email/Magic wallets (signature_type=1) and Safe/Gnosis wallets (signature_type=2)
|
|
159
|
+
- #### Approvals
|
|
160
|
+
- set approvals for all needed usdc and conditional token spenders (needed for full trading functionality)
|
|
161
|
+
- Safe/Gnosis wallet holders need to run deploy_safe before setting approvals
|
|
125
162
|
- #### Balance
|
|
126
163
|
- get usdc balance by user address
|
|
127
164
|
- get token balance by `token_id` and user address
|
|
165
|
+
- #### Transfers
|
|
166
|
+
- transfer usdc to another address - needs recipient address, amount
|
|
167
|
+
- transfer token to another address - needs `token_id`, recipient address, amount
|
|
128
168
|
- #### Token/USDC conversions
|
|
129
169
|
- split USDC into complementary tokens - needs `condition_id`, amount, neg_risk bool
|
|
130
170
|
- merge complementary tokens into USDC - needs `condition_id`, amount, neg_risk bool
|
|
@@ -158,4 +198,4 @@ flowchart LR
|
|
|
158
198
|
- positions_subgraph
|
|
159
199
|
- sports_oracle_subgraph
|
|
160
200
|
- wallet_subgraph
|
|
161
|
-
- ****query()**** takes in a GraphQL query string and returns the raw json
|
|
201
|
+
- ****query()**** takes in a GraphQL query string and returns the raw json
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
polymarket_apis/__init__.py,sha256=JP-BDDPzMmwaeBsGNucp-V2kOis-cQPjz92BEkyoIIg,1126
|
|
2
|
+
polymarket_apis/clients/__init__.py,sha256=ruMvFEA4HNkbWEYqbnrCuYXR4PUwkV1XWG0w63we-LA,759
|
|
3
|
+
polymarket_apis/clients/clob_client.py,sha256=Eo5zXYtI_Ct0EByzjJnH6h7FLHOqheXDujBA57CtINw,32485
|
|
4
|
+
polymarket_apis/clients/data_client.py,sha256=0--2W6_DZtC7cRud8OYS7bH2heWzn2NwvcUVK3PyEwU,13242
|
|
5
|
+
polymarket_apis/clients/gamma_client.py,sha256=iDfuaClhRK2Y5v8ZA03Qbne3CnIM4JJolHo-qUrQV78,27633
|
|
6
|
+
polymarket_apis/clients/graphql_client.py,sha256=KgjxbXNWEXp82ZEz464in5mCn1PydnZqWq-g11xu9YU,1839
|
|
7
|
+
polymarket_apis/clients/web3_client.py,sha256=SI-CBMDnWvqXD0elXC-Ffuo2leoQlKitq4c0INuNPgw,25305
|
|
8
|
+
polymarket_apis/clients/websockets_client.py,sha256=gaGcsjqp1ZRyxrL6EWvZ9XaTv7koTPDzlcShj0u0B2A,7737
|
|
9
|
+
polymarket_apis/types/__init__.py,sha256=cyrAPNX0ty0wkMwZqB0lNA7n3JoOJCSeTpclmamMh9k,3258
|
|
10
|
+
polymarket_apis/types/clob_types.py,sha256=WZs370ni2B2UsLW-yIPGA2C-z8dfbywX26vADuu2YFc,11725
|
|
11
|
+
polymarket_apis/types/common.py,sha256=iT7HWmmaR2TwWkGPNoX4CN_Xn3D1D3Z1IYJUDunBkQ4,3797
|
|
12
|
+
polymarket_apis/types/data_types.py,sha256=vBElvARw8LkH2xXwJkVErpQo0FkXJA3b44hKD5clSOI,5729
|
|
13
|
+
polymarket_apis/types/gamma_types.py,sha256=MoIUI6csqEp_vij7mkFi2IlIA99c5UNzI3zODSONWzQ,30641
|
|
14
|
+
polymarket_apis/types/web3_types.py,sha256=kABIRvn_7BvRZIWWF5nC_7SJ-30jfQcGlaC4XnPsN00,1527
|
|
15
|
+
polymarket_apis/types/websockets_types.py,sha256=XGTpfix2rFFQg-97ZkPagS_tHJJpSnB5mCMf_sT2MOI,11180
|
|
16
|
+
polymarket_apis/utilities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
|
+
polymarket_apis/utilities/config.py,sha256=kQymQRy9fVg5jt8CcQJxsSgIZFbfjPx2q_gNnZI5b24,2449
|
|
18
|
+
polymarket_apis/utilities/constants.py,sha256=TzFVtN8zNgvEa4yjLWjpvPYsAi1LLV5oPEnHlbwxSDQ,637
|
|
19
|
+
polymarket_apis/utilities/endpoints.py,sha256=bxZyrJBPbVauWc-eR0RMh6KDqU-SmO_3LfQwVMNJ6vE,1235
|
|
20
|
+
polymarket_apis/utilities/exceptions.py,sha256=lpZPF2-rw64qrnhCQWIspAv-rgm7aKvP8UUoVHcrPUA,495
|
|
21
|
+
polymarket_apis/utilities/headers.py,sha256=Cc5WEnIBLYAgfwvmCXRBwA2zUYME8fDy4PbwlwlB6Oo,1510
|
|
22
|
+
polymarket_apis/utilities/order_builder/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
23
|
+
polymarket_apis/utilities/order_builder/builder.py,sha256=dyxKhMeNjGyHXEIFBBZhWwI8TaQQcE_ErQ4sF6BcMX0,8476
|
|
24
|
+
polymarket_apis/utilities/order_builder/helpers.py,sha256=2-UYDLntYOXjyN0ZDQI13jW2zwXwIODEK-smBRFTYRk,1943
|
|
25
|
+
polymarket_apis/utilities/signing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
26
|
+
polymarket_apis/utilities/signing/eip712.py,sha256=fGLurznnfY5M0VCP1Txyq_FYQRfggyHoTwz-PGIK2Eg,895
|
|
27
|
+
polymarket_apis/utilities/signing/hmac.py,sha256=1VPfO2yT8nyStk6U4AQeyTzQTt5-69PTw24Gdt5YOMo,718
|
|
28
|
+
polymarket_apis/utilities/signing/model.py,sha256=kVduuJGth7WSCUDCVVydCgPd4yEVI85gEmMxohXsvp0,191
|
|
29
|
+
polymarket_apis/utilities/signing/signer.py,sha256=cxjcYRn1a0ApVcir1AvamsFcLZ0rYNlEEX4sPUz_Nrw,776
|
|
30
|
+
polymarket_apis/utilities/web3/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
31
|
+
polymarket_apis/utilities/web3/helpers.py,sha256=aczuvPXqnFGcKKfT5GhpnJL2U6UBEcpjbzhQUfw0MDk,6765
|
|
32
|
+
polymarket_apis/utilities/web3/abis/CTFExchange.json,sha256=zt8fZnUaOrD8Vh5njM0EEUpeITWhuu0SZrIZigWxgV8,38499
|
|
33
|
+
polymarket_apis/utilities/web3/abis/ConditionalTokens.json,sha256=3TUcX7He74VMkoL1kxbDbtULZ70VY_EBe01pfByprsk,12584
|
|
34
|
+
polymarket_apis/utilities/web3/abis/NegRiskAdapter.json,sha256=HABIoRF1s1NgctpRTdaaNDqzODzgdZLE-s2E6ef4nAY,18867
|
|
35
|
+
polymarket_apis/utilities/web3/abis/NegRiskCtfExchange.json,sha256=QOgLKekWnPVcMGXExcLjEIOHLS89tPUoZFkVm-yRnbY,38612
|
|
36
|
+
polymarket_apis/utilities/web3/abis/ProxyWalletFactory.json,sha256=5KjBHUWdkc_kdlWPNax84o1vStpFuLgZKTMn3jc4zvU,5553
|
|
37
|
+
polymarket_apis/utilities/web3/abis/Safe.json,sha256=iXxTY7XM1hBOifAjHO9FK8e2FaQfCHrW7jK7WPvJiEM,24361
|
|
38
|
+
polymarket_apis/utilities/web3/abis/SafeProxyFactory.json,sha256=bdr2WdYCRClXLTT0jarNs4C-Rz9bxozuwZgmcew-uAY,4211
|
|
39
|
+
polymarket_apis/utilities/web3/abis/UChildERC20Proxy.json,sha256=ZyQC38U0uxInlmnW2VXDVD3TJfTIRmSNMkTxQsaG7oA,27396
|
|
40
|
+
polymarket_apis/utilities/web3/abis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
41
|
+
polymarket_apis/utilities/web3/abis/custom_contract_errors.py,sha256=GjCVn2b6iRheT7s-kc8Po9uwH9LfaHA1yRpJyjXRcxs,1172
|
|
42
|
+
polymarket_apis-0.3.9.dist-info/METADATA,sha256=20N_34_PxZUfVG5o2Uz3TGLhH4cK2eocQUCXTRsPIxs,12992
|
|
43
|
+
polymarket_apis-0.3.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
44
|
+
polymarket_apis-0.3.9.dist-info/RECORD,,
|