polymarket-apis 0.2.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 +2 -0
- polymarket_apis/clients/__init__.py +0 -0
- polymarket_apis/clients/clob_client.py +730 -0
- polymarket_apis/clients/data_client.py +234 -0
- polymarket_apis/clients/gamma_client.py +311 -0
- polymarket_apis/clients/web3_client.py +261 -0
- polymarket_apis/clients/websockets_client.py +131 -0
- polymarket_apis/types/__init__.py +0 -0
- polymarket_apis/types/clob_types.py +494 -0
- polymarket_apis/types/common.py +49 -0
- polymarket_apis/types/data_types.py +161 -0
- polymarket_apis/types/gamma_types.py +313 -0
- polymarket_apis/types/websockets_types.py +191 -0
- polymarket_apis/utilities/__init__.py +0 -0
- polymarket_apis/utilities/config.py +36 -0
- polymarket_apis/utilities/constants.py +26 -0
- polymarket_apis/utilities/endpoints.py +37 -0
- polymarket_apis/utilities/exceptions.py +11 -0
- polymarket_apis/utilities/headers.py +54 -0
- polymarket_apis/utilities/order_builder/__init__.py +0 -0
- polymarket_apis/utilities/order_builder/builder.py +240 -0
- polymarket_apis/utilities/order_builder/helpers.py +61 -0
- polymarket_apis/utilities/signing/__init__.py +0 -0
- polymarket_apis/utilities/signing/eip712.py +28 -0
- polymarket_apis/utilities/signing/hmac.py +20 -0
- polymarket_apis/utilities/signing/model.py +8 -0
- polymarket_apis/utilities/signing/signer.py +25 -0
- polymarket_apis/utilities/web3/__init__.py +0 -0
- polymarket_apis/utilities/web3/abis/CTFExchange.json +1851 -0
- polymarket_apis/utilities/web3/abis/ConditionalTokens.json +705 -0
- polymarket_apis/utilities/web3/abis/NegRiskAdapter.json +999 -0
- polymarket_apis/utilities/web3/abis/NegRiskCtfExchange.json +1856 -0
- polymarket_apis/utilities/web3/abis/ProxyWalletFactory.json +319 -0
- polymarket_apis/utilities/web3/abis/UChildERC20Proxy.json +1438 -0
- polymarket_apis/utilities/web3/abis/__init__.py +0 -0
- polymarket_apis/utilities/web3/abis/custom_contract_errors.py +31 -0
- polymarket_apis/utilities/web3/helpers.py +8 -0
- polymarket_apis-0.2.2.dist-info/METADATA +18 -0
- polymarket_apis-0.2.2.dist-info/RECORD +40 -0
- polymarket_apis-0.2.2.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
|
|
5
|
+
from pydantic import (
|
|
6
|
+
BaseModel,
|
|
7
|
+
Field,
|
|
8
|
+
Json,
|
|
9
|
+
ValidationInfo,
|
|
10
|
+
ValidatorFunctionWrapHandler,
|
|
11
|
+
field_validator,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
from .common import EthAddress, Keccak256, TimestampWithTZ
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Event(BaseModel):
|
|
18
|
+
# Basic identification
|
|
19
|
+
id: str
|
|
20
|
+
slug: str
|
|
21
|
+
ticker: str | None = None
|
|
22
|
+
|
|
23
|
+
# Core event information
|
|
24
|
+
title: str
|
|
25
|
+
description: str | None = None
|
|
26
|
+
resolution_source: str | None = Field(None, alias="resolutionSource")
|
|
27
|
+
category: str | None = None
|
|
28
|
+
|
|
29
|
+
# Visual representation
|
|
30
|
+
image: str | None = None
|
|
31
|
+
icon: str | None = None
|
|
32
|
+
|
|
33
|
+
# Temporal information
|
|
34
|
+
start_date: datetime | None = Field(None, alias="startDate")
|
|
35
|
+
end_date: datetime | None = Field(None, alias="endDate")
|
|
36
|
+
creation_date: datetime | None = Field(None, alias="creationDate")
|
|
37
|
+
created_at: datetime = Field(alias="createdAt")
|
|
38
|
+
updated_at: datetime | None = Field(None, alias="updatedAt")
|
|
39
|
+
published_at: TimestampWithTZ | None = None
|
|
40
|
+
closed_time: datetime | None = Field(None, alias="closedTime")
|
|
41
|
+
|
|
42
|
+
# Status flags
|
|
43
|
+
active: bool
|
|
44
|
+
closed: bool
|
|
45
|
+
archived: bool | None = None
|
|
46
|
+
new: bool | None = None
|
|
47
|
+
featured: bool | None = None
|
|
48
|
+
restricted: bool | None = None
|
|
49
|
+
cyom: bool
|
|
50
|
+
automatically_active: bool | None = Field(None, alias="automaticallyActive")
|
|
51
|
+
|
|
52
|
+
# Financial metrics
|
|
53
|
+
liquidity: float | None = None
|
|
54
|
+
volume: float | None = None
|
|
55
|
+
open_interest: int | None = Field(None, alias="openInterest")
|
|
56
|
+
competitive: float | None = None
|
|
57
|
+
volume_24hr: float | None = Field(None, alias="volume24hr")
|
|
58
|
+
liquidity_amm: float | None = Field(None, alias="liquidityAmm")
|
|
59
|
+
liquidity_clob: float | None = Field(None, alias="liquidityClob")
|
|
60
|
+
|
|
61
|
+
# Related data
|
|
62
|
+
markets: list[GammaMarket] | None = None
|
|
63
|
+
series: list[Series] | None = None
|
|
64
|
+
tags: list[Tag] | None = None
|
|
65
|
+
|
|
66
|
+
# User interaction
|
|
67
|
+
comment_count: int | None = Field(None, alias="commentCount")
|
|
68
|
+
|
|
69
|
+
# Display and functionality settings
|
|
70
|
+
sort_by: str | None = Field(None, alias="sortBy")
|
|
71
|
+
show_all_outcomes: bool = Field(alias="showAllOutcomes")
|
|
72
|
+
show_market_images: bool = Field(alias="showMarketImages")
|
|
73
|
+
gmp_chart_mode: str | None = Field(None, alias="gmpChartMode")
|
|
74
|
+
|
|
75
|
+
# Negative risk settings
|
|
76
|
+
enable_neg_risk: bool = Field(alias="enableNegRisk")
|
|
77
|
+
neg_risk: bool | None = Field(None, alias="negRisk")
|
|
78
|
+
neg_risk_market_id: str | None = Field(None, alias="negRiskMarketID")
|
|
79
|
+
neg_risk_augmented: bool | None = Field(None, alias="negRiskAugmented")
|
|
80
|
+
|
|
81
|
+
# Order book settings
|
|
82
|
+
enable_order_book: bool | None = Field(None, alias="enableOrderBook")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class GammaMarket(BaseModel):
|
|
86
|
+
# Basic identification
|
|
87
|
+
id: str
|
|
88
|
+
slug: str
|
|
89
|
+
condition_id: Keccak256 = Field(alias="conditionId")
|
|
90
|
+
question_id: Keccak256 | None = Field(None, alias="questionID")
|
|
91
|
+
|
|
92
|
+
# Core market information
|
|
93
|
+
question: str
|
|
94
|
+
description: str
|
|
95
|
+
resolution_source: str | None = Field(None, alias="resolutionSource")
|
|
96
|
+
outcome: list | None = None
|
|
97
|
+
outcome_prices: Json[list[float]] | list[float] | None = Field(None, alias="outcomePrices")
|
|
98
|
+
|
|
99
|
+
# Visual representation
|
|
100
|
+
image: str | None = None
|
|
101
|
+
icon: str | None = None
|
|
102
|
+
|
|
103
|
+
# Temporal information
|
|
104
|
+
start_date: datetime | None = Field(None, alias="startDate")
|
|
105
|
+
end_date: datetime | None = Field(None, alias="endDate")
|
|
106
|
+
created_at: datetime = Field(alias="createdAt")
|
|
107
|
+
updated_at: datetime | None = Field(None, alias="updatedAt")
|
|
108
|
+
start_date_iso: datetime | None = Field(None, alias="startDateIso")
|
|
109
|
+
end_date_iso: datetime | None = Field(None, alias="endDateIso")
|
|
110
|
+
deployed_timestamp: datetime | None = Field(None, alias="deployedTimestamp")
|
|
111
|
+
accepting_orders_timestamp: datetime | None = Field(
|
|
112
|
+
None, alias="acceptingOrdersTimestamp",
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
# Status flags
|
|
116
|
+
active: bool
|
|
117
|
+
closed: bool
|
|
118
|
+
archived: bool
|
|
119
|
+
new: bool | None = None
|
|
120
|
+
featured: bool | None = None
|
|
121
|
+
restricted: bool
|
|
122
|
+
ready: bool
|
|
123
|
+
deployed: bool | None = None
|
|
124
|
+
funded: bool
|
|
125
|
+
cyom: bool
|
|
126
|
+
approved: bool
|
|
127
|
+
|
|
128
|
+
# Financial metrics
|
|
129
|
+
liquidity: float | None = None
|
|
130
|
+
volume: float | None = None
|
|
131
|
+
volume_num: float | None = Field(None, alias="volumeNum")
|
|
132
|
+
liquidity_num: float | None = Field(None, alias="liquidityNum")
|
|
133
|
+
volume_24hr: float | None = Field(None, alias="volume24hr")
|
|
134
|
+
volume_24hr_clob: float | None = Field(None, alias="volume24hrClob")
|
|
135
|
+
volume_clob: float | None = Field(None, alias="volumeClob")
|
|
136
|
+
liquidity_clob: float | None = Field(None, alias="liquidityClob")
|
|
137
|
+
competitive: float | None = None
|
|
138
|
+
spread: float
|
|
139
|
+
|
|
140
|
+
# Order book settings
|
|
141
|
+
enable_order_book: bool | None = Field(None, alias="enableOrderBook")
|
|
142
|
+
order_price_min_tick_size: float | None = Field(
|
|
143
|
+
None, alias="orderPriceMinTickSize",
|
|
144
|
+
)
|
|
145
|
+
order_min_size: float | None = Field(None, alias="orderMinSize")
|
|
146
|
+
accepting_orders: bool | None = Field(None, alias="acceptingOrders")
|
|
147
|
+
|
|
148
|
+
# Related data
|
|
149
|
+
events: list[Event] | None = None
|
|
150
|
+
clob_rewards: list[ClobReward] | None = Field(None, alias="clobRewards")
|
|
151
|
+
|
|
152
|
+
# User interaction
|
|
153
|
+
comment_count: int | None = Field(None, alias="commentCount")
|
|
154
|
+
|
|
155
|
+
# Market maker information
|
|
156
|
+
market_maker_address: str = Field(alias="marketMakerAddress")
|
|
157
|
+
|
|
158
|
+
# Additional settings
|
|
159
|
+
group_item_title: str | None = Field(None, alias="groupItemTitle")
|
|
160
|
+
group_item_threshold: int | None = Field(None, alias="groupItemThreshold")
|
|
161
|
+
token_ids: Json[list[str]] | list[str] | None = Field(None, alias="clobTokenIds")
|
|
162
|
+
uma_bond: int | None = Field(None, alias="umaBond")
|
|
163
|
+
uma_reward: float | None = Field(None, alias="umaReward")
|
|
164
|
+
neg_risk: bool | None = Field(None, alias="negRisk")
|
|
165
|
+
pager_duty_notification_enabled: bool = Field(alias="pagerDutyNotificationEnabled")
|
|
166
|
+
review_status: str | None = Field(None, alias="reviewStatus")
|
|
167
|
+
rewards_min_size: int = Field(alias="rewardsMinSize")
|
|
168
|
+
rewards_max_spread: float = Field(alias="rewardsMaxSpread")
|
|
169
|
+
|
|
170
|
+
# Resolution information
|
|
171
|
+
submitted_by: str | None = None
|
|
172
|
+
resolved_by: EthAddress | None = Field(None, alias="resolvedBy")
|
|
173
|
+
has_reviewed_dates: bool | None = Field(None, alias="hasReviewedDates")
|
|
174
|
+
|
|
175
|
+
@field_validator("condition_id", mode="wrap")
|
|
176
|
+
@classmethod
|
|
177
|
+
def validate_condition_id(
|
|
178
|
+
cls, value: str, handler: ValidatorFunctionWrapHandler, info: ValidationInfo,
|
|
179
|
+
) -> str:
|
|
180
|
+
try:
|
|
181
|
+
# First attempt standard Keccak256 validation
|
|
182
|
+
return handler(value)
|
|
183
|
+
except ValueError:
|
|
184
|
+
active = info.data.get("active", False)
|
|
185
|
+
|
|
186
|
+
# Only allow empty string when inactive
|
|
187
|
+
if not active and value == "":
|
|
188
|
+
return value
|
|
189
|
+
|
|
190
|
+
# Re-raise original error for other cases
|
|
191
|
+
raise
|
|
192
|
+
|
|
193
|
+
class ClobReward(BaseModel):
|
|
194
|
+
# Basic identification
|
|
195
|
+
id: str
|
|
196
|
+
condition_id: Keccak256 = Field(alias="conditionId")
|
|
197
|
+
|
|
198
|
+
# Reward information
|
|
199
|
+
asset_address: str = Field(alias="assetAddress")
|
|
200
|
+
rewards_amount: float = Field(alias="rewardsAmount")
|
|
201
|
+
rewards_daily_rate: float | None = Field(None, alias="rewardsDailyRate")
|
|
202
|
+
|
|
203
|
+
# Temporal information
|
|
204
|
+
start_date: datetime = Field(alias="startDate")
|
|
205
|
+
end_date: datetime = Field(alias="endDate")
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
class Tag(BaseModel):
|
|
209
|
+
# Basic identification
|
|
210
|
+
id: str
|
|
211
|
+
label: str
|
|
212
|
+
slug: str
|
|
213
|
+
|
|
214
|
+
# Display settings
|
|
215
|
+
force_show: bool | None = Field(None, alias="forceShow")
|
|
216
|
+
force_hide: bool | None = Field(None, alias="forceHide")
|
|
217
|
+
|
|
218
|
+
# Temporal information
|
|
219
|
+
published_at: TimestampWithTZ | datetime | None = Field(None, alias="publishedAt")
|
|
220
|
+
created_at: datetime | None = Field(None, alias="createdAt")
|
|
221
|
+
updated_at: datetime | None = Field(None, alias="updatedAt")
|
|
222
|
+
|
|
223
|
+
# User information
|
|
224
|
+
created_by: int | None = Field(None, alias="createdBy")
|
|
225
|
+
updated_by: int | None = Field(None, alias="updatedBy")
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
class Series(BaseModel):
|
|
229
|
+
# Basic identification
|
|
230
|
+
id: str
|
|
231
|
+
slug: str
|
|
232
|
+
ticker: str
|
|
233
|
+
title: str
|
|
234
|
+
|
|
235
|
+
# Series characteristics
|
|
236
|
+
series_type: str | None = Field(None, alias="seriesType")
|
|
237
|
+
recurrence: str | None = None
|
|
238
|
+
layout: str | None = None
|
|
239
|
+
|
|
240
|
+
# Visual representation
|
|
241
|
+
icon: str | None = None
|
|
242
|
+
image: str | None = None
|
|
243
|
+
|
|
244
|
+
# Temporal information
|
|
245
|
+
start_date: datetime | None = Field(None, alias="startDate")
|
|
246
|
+
created_at: datetime = Field(alias="createdAt")
|
|
247
|
+
updated_at: datetime | None = Field(None, alias="updatedAt")
|
|
248
|
+
published_at: TimestampWithTZ | datetime | None = Field(None, alias="publishedAt")
|
|
249
|
+
|
|
250
|
+
# Status flags
|
|
251
|
+
active: bool | None = None
|
|
252
|
+
archived: bool | None = None
|
|
253
|
+
closed: bool | None = None
|
|
254
|
+
featured: bool | None = None
|
|
255
|
+
new: bool | None = None
|
|
256
|
+
restricted: bool | None = None
|
|
257
|
+
|
|
258
|
+
# Financial metrics
|
|
259
|
+
liquidity: float | None = None
|
|
260
|
+
volume: float | None = None
|
|
261
|
+
volume_24hr: float | None = Field(None, alias="volume24hr")
|
|
262
|
+
competitive: str | None = None
|
|
263
|
+
|
|
264
|
+
# User interaction
|
|
265
|
+
comment_count: int = Field(alias="commentCount")
|
|
266
|
+
comments_enabled: bool | None = Field(None, alias="commentsEnabled")
|
|
267
|
+
|
|
268
|
+
# User information
|
|
269
|
+
created_by: str | None = Field(None, alias="createdBy")
|
|
270
|
+
updated_by: str | None = Field(None, alias="updatedBy")
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
class QueryEvent(BaseModel):
|
|
274
|
+
# Basic identification
|
|
275
|
+
id: str
|
|
276
|
+
slug: str
|
|
277
|
+
title: str
|
|
278
|
+
|
|
279
|
+
# Visual representation
|
|
280
|
+
image: str | None = None
|
|
281
|
+
|
|
282
|
+
# Status flags
|
|
283
|
+
active: bool
|
|
284
|
+
closed: bool
|
|
285
|
+
archived: bool
|
|
286
|
+
neg_risk: bool | None = Field(None, alias="negRisk")
|
|
287
|
+
|
|
288
|
+
# Temporal information
|
|
289
|
+
start_date: datetime | None = Field(None, alias="startDate")
|
|
290
|
+
end_date: datetime | None = Field(None, alias="endDate")
|
|
291
|
+
ended: bool
|
|
292
|
+
|
|
293
|
+
# Related data
|
|
294
|
+
markets: list[QueryMarket] | None = None
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
class QueryMarket(BaseModel):
|
|
298
|
+
# Basic identification
|
|
299
|
+
slug: str
|
|
300
|
+
question: str
|
|
301
|
+
group_item_title: str | None = Field(None, alias="groupItemTitle")
|
|
302
|
+
|
|
303
|
+
# Market data
|
|
304
|
+
outcomes: list | None = None
|
|
305
|
+
outcome_prices: Json[list[float]] | list[float] | None = Field(None, alias="outcomePrices")
|
|
306
|
+
last_trade_price: float | None = Field(None, alias="lastTradePrice")
|
|
307
|
+
best_ask: float | None = Field(None, alias="bestAsk")
|
|
308
|
+
best_bid: float | None = Field(None, alias="bestBid")
|
|
309
|
+
spread: float
|
|
310
|
+
|
|
311
|
+
# Status flags
|
|
312
|
+
closed: bool
|
|
313
|
+
archived: bool
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from typing import Literal
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel, Field, field_validator
|
|
5
|
+
|
|
6
|
+
from ..types.clob_types import MakerOrder, OrderBookSummary, PriceLevel, TickSize
|
|
7
|
+
from ..types.common import EthAddress, Keccak256
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
# wss://ws-subscriptions-clob.polymarket.com/ws/market types
|
|
11
|
+
class OrderBookSummaryEvent(OrderBookSummary):
|
|
12
|
+
event_type: Literal["book"]
|
|
13
|
+
|
|
14
|
+
class PriceChangeEvent(BaseModel):
|
|
15
|
+
token_id: str = Field(alias="asset_id")
|
|
16
|
+
changes: list[PriceLevel]
|
|
17
|
+
hash: str
|
|
18
|
+
market: str
|
|
19
|
+
timestamp: datetime # time of event
|
|
20
|
+
event_type: Literal["price_change"]
|
|
21
|
+
|
|
22
|
+
class TickSizeChangeEvent(BaseModel):
|
|
23
|
+
token_id: str = Field(alias="asset_id")
|
|
24
|
+
condition_id: Keccak256 = Field(alias="market")
|
|
25
|
+
old_tick_size: TickSize
|
|
26
|
+
new_tick_size: TickSize
|
|
27
|
+
side: Literal["BUY", "SELL"]
|
|
28
|
+
timestamp: datetime # time of event
|
|
29
|
+
event_type: Literal["tick_size_change"]
|
|
30
|
+
|
|
31
|
+
# wss://ws-subscriptions-clob.polymarket.com/ws/user types
|
|
32
|
+
class OrderEvent(BaseModel):
|
|
33
|
+
token_id: str = Field(alias="asset_id")
|
|
34
|
+
condition_id: Keccak256 = Field(alias="market")
|
|
35
|
+
order_id: Keccak256 = Field(alias="id")
|
|
36
|
+
associated_trades: list[str] | None = None # list of trade ids which
|
|
37
|
+
maker_address: EthAddress
|
|
38
|
+
order_owner: str # api key of order owner
|
|
39
|
+
event_owner: str = Field(alias="owner") # api key of event owner
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
price: float
|
|
43
|
+
side: Literal["BUY", "SELL"]
|
|
44
|
+
size_matched: float
|
|
45
|
+
original_size: float
|
|
46
|
+
outcome: str
|
|
47
|
+
order_type: Literal["GTC", "FOK", "GTD"]
|
|
48
|
+
|
|
49
|
+
created_at: datetime
|
|
50
|
+
expiration: datetime | None = None
|
|
51
|
+
timestamp: datetime # time of event
|
|
52
|
+
|
|
53
|
+
event_type: Literal["order"]
|
|
54
|
+
type: Literal["PLACEMENT", "UPDATE" , "CANCELLATION"]
|
|
55
|
+
|
|
56
|
+
status: Literal["LIVE", "CANCELED", "MATCHED"]
|
|
57
|
+
|
|
58
|
+
@field_validator("expiration", mode="before")
|
|
59
|
+
def validate_expiration(cls, v):
|
|
60
|
+
if v == "0":
|
|
61
|
+
return None
|
|
62
|
+
return v
|
|
63
|
+
|
|
64
|
+
class TradeEvent(BaseModel):
|
|
65
|
+
token_id: str = Field(alias="asset_id")
|
|
66
|
+
condition_id: Keccak256 = Field(alias="market")
|
|
67
|
+
taker_order_id: Keccak256
|
|
68
|
+
maker_orders: list[MakerOrder]
|
|
69
|
+
trade_id: str = Field(alias="id")
|
|
70
|
+
trade_owner: str # api key of trade owner
|
|
71
|
+
event_owner: str = Field(alias="owner") # api key of event owner
|
|
72
|
+
|
|
73
|
+
price: float
|
|
74
|
+
size: float
|
|
75
|
+
side: Literal["BUY", "SELL"]
|
|
76
|
+
outcome: str
|
|
77
|
+
|
|
78
|
+
last_update: datetime # time of last update to trade
|
|
79
|
+
matchtime: datetime | None = None # time trade was matched
|
|
80
|
+
timestamp: datetime # time of event
|
|
81
|
+
|
|
82
|
+
event_type: Literal["trade"]
|
|
83
|
+
type: Literal["TRADE"]
|
|
84
|
+
|
|
85
|
+
status: Literal["MATCHED", "MINED", "CONFIRMED", "RETRYING", "FAILED"]
|
|
86
|
+
|
|
87
|
+
# wss://ws-live-data.polymarket.com types
|
|
88
|
+
class LiveDataTrade(BaseModel):
|
|
89
|
+
token_id: str = Field(alias="asset") # ERC1155 token ID of conditional token being traded
|
|
90
|
+
condition_id: str = Field(alias="conditionId") # Id of market which is also the CTF condition ID
|
|
91
|
+
event_slug: str = Field(alias="eventSlug") # Slug of the event
|
|
92
|
+
outcome: str # Human readable outcome of the market
|
|
93
|
+
outcome_index: int = Field(alias="outcomeIndex") # Index of the outcome
|
|
94
|
+
price: float # Price of the trade
|
|
95
|
+
side: Literal["BUY", "SELL"] # Side of the trade
|
|
96
|
+
size: float # Size of the trade
|
|
97
|
+
slug: str # Slug of the market
|
|
98
|
+
timestamp: datetime # Timestamp of the trade
|
|
99
|
+
title: str # Title of the event
|
|
100
|
+
transaction_hash: str = Field(alias="transactionHash") # Hash of the transaction
|
|
101
|
+
proxy_wallet: str = Field(alias="proxyWallet") # Address of the user proxy wallet
|
|
102
|
+
icon: str # URL to the market icon image
|
|
103
|
+
name: str # Name of the user of the trade
|
|
104
|
+
bio: str # Bio of the user of the trade
|
|
105
|
+
pseudonym: str # Pseudonym of the user
|
|
106
|
+
profile_image: str = Field(alias="profileImage") # URL to the user profile image
|
|
107
|
+
profile_image_optimized: str | None = Field(None, alias="profileImageOptimized")
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
class Comment(BaseModel):
|
|
111
|
+
id: str # Unique identifier of comment
|
|
112
|
+
body: str # Content of the comment
|
|
113
|
+
parent_entity_type: str = Field(alias="parentEntityType") # Type of the parent entity (Event or Series)
|
|
114
|
+
parent_entity_id: int = Field(alias="parentEntityID") # ID of the parent entity
|
|
115
|
+
parent_comment_id: str | None = Field(None, alias="parentCommentID") # ID of the parent comment
|
|
116
|
+
user_address: str = Field(alias="userAddress") # Address of the user
|
|
117
|
+
reply_address: str | None = Field(None, alias="replyAddress") # Address of the reply user
|
|
118
|
+
created_at: datetime = Field(alias="createdAt") # Creation timestamp
|
|
119
|
+
updated_at: datetime | None = Field(None, alias="updatedAt") # Last update timestamp
|
|
120
|
+
|
|
121
|
+
class Reaction(BaseModel):
|
|
122
|
+
id: str # Unique identifier of reaction
|
|
123
|
+
comment_id: int = Field(alias="commentID") # ID of the comment
|
|
124
|
+
reaction_type: str = Field(alias="reactionType") # Type of the reaction
|
|
125
|
+
icon: str | None = None # Icon representing the reaction
|
|
126
|
+
user_address: str = Field(alias="userAddress") # Address of the user
|
|
127
|
+
created_at: datetime = Field(alias="createdAt") # Creation timestamp
|
|
128
|
+
|
|
129
|
+
class Request(BaseModel):
|
|
130
|
+
request_id: str = Field(alias="requestId") # Unique identifier for the request
|
|
131
|
+
proxy_address: str = Field(alias="proxyAddress") # Proxy address
|
|
132
|
+
user_address: str = Field(alias="userAddress") # User address
|
|
133
|
+
condition_id: Keccak256 = Field(alias="market") # Id of market which is also the CTF condition ID
|
|
134
|
+
token_id: str = Field(alias="token") # ERC1155 token ID of conditional token being traded
|
|
135
|
+
complement_token_id: str = Field(alias="complement") # Complement ERC1155 token ID of conditional token being traded
|
|
136
|
+
state: Literal["STATE_REQUEST_EXPIRED", "STATE_USER_CANCELED", "STATE_REQUEST_CANCELED", "STATE_MAKER_CANCELED", "STATE_ACCEPTING_QUOTES", "STATE_REQUEST_QUOTED", "STATE_QUOTE_IMPROVED"] # Current state of the request
|
|
137
|
+
side: Literal["BUY", "SELL"] # Indicates buy or sell side
|
|
138
|
+
price: float # Price from in/out sizes
|
|
139
|
+
size_in: float = Field(alias="sizeIn") # Input size of the request
|
|
140
|
+
size_out: float = Field(alias="sizeOut") # Output size of the request
|
|
141
|
+
expiry: datetime | None = None
|
|
142
|
+
|
|
143
|
+
class Quote(BaseModel):
|
|
144
|
+
quote_id: str = Field(alias="quoteId") # Unique identifier for the quote
|
|
145
|
+
request_id: str = Field(alias="requestId") # Associated request identifier
|
|
146
|
+
proxy_address: str = Field(alias="proxyAddress") # Proxy address
|
|
147
|
+
user_address: str = Field(alias="userAddress") # User address
|
|
148
|
+
condition_id: Keccak256 = Field(alias="condition") # Id of market which is also the CTF condition ID
|
|
149
|
+
token_id: str = Field(alias="token") # ERC1155 token ID of conditional token being traded
|
|
150
|
+
complement_token_id: str = Field(alias="complement") # Complement ERC1155 token ID of conditional token being traded
|
|
151
|
+
state: Literal["STATE_REQUEST_EXPIRED", "STATE_USER_CANCELED", "STATE_REQUEST_CANCELED", "STATE_MAKER_CANCELED", "STATE_ACCEPTING_QUOTES", "STATE_REQUEST_QUOTED", "STATE_QUOTE_IMPROVED"] # Current state of the quote
|
|
152
|
+
side: Literal["BUY", "SELL"] # Indicates buy or sell side
|
|
153
|
+
size_in: float = Field(alias="sizeIn") # Input size of the quote
|
|
154
|
+
size_out: float = Field(alias="sizeOut") # Output size of the quote
|
|
155
|
+
expiry: datetime | None = None
|
|
156
|
+
|
|
157
|
+
class LiveDataTradeEvent(BaseModel):
|
|
158
|
+
payload: LiveDataTrade
|
|
159
|
+
timestamp: datetime
|
|
160
|
+
type: Literal["trades"]
|
|
161
|
+
topic: Literal["activity"]
|
|
162
|
+
|
|
163
|
+
class LiveDataOrderMatchEvent(BaseModel):
|
|
164
|
+
payload: LiveDataTrade
|
|
165
|
+
timestamp: datetime
|
|
166
|
+
type: Literal["orders_matched"]
|
|
167
|
+
topic: Literal["activity"]
|
|
168
|
+
|
|
169
|
+
class CommentEvent(BaseModel):
|
|
170
|
+
payload: Comment
|
|
171
|
+
timestamp: datetime
|
|
172
|
+
type: Literal["comment_created", "comment_removed"]
|
|
173
|
+
topic: Literal["comments"]
|
|
174
|
+
|
|
175
|
+
class ReactionEvent(BaseModel):
|
|
176
|
+
payload: Reaction
|
|
177
|
+
timestamp: datetime
|
|
178
|
+
type: Literal["reaction_created", "reaction_removed"]
|
|
179
|
+
topic: Literal["comments"]
|
|
180
|
+
|
|
181
|
+
class RequestEvent(BaseModel):
|
|
182
|
+
payload: Request
|
|
183
|
+
timestamp: datetime
|
|
184
|
+
type: Literal["request_created", "request_edited", "request_canceled", "request_expired"]
|
|
185
|
+
topic: Literal["rfq"]
|
|
186
|
+
|
|
187
|
+
class QuoteEvent(BaseModel):
|
|
188
|
+
payload: Quote
|
|
189
|
+
timestamp: datetime
|
|
190
|
+
type: Literal["quote_created", "quote_edited", "quote_canceled", "quote_expired"]
|
|
191
|
+
topic: Literal["rfq"]
|
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from ..types.clob_types import ContractConfig
|
|
2
|
+
|
|
3
|
+
CONFIG = {
|
|
4
|
+
137: ContractConfig(
|
|
5
|
+
exchange="0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E",
|
|
6
|
+
collateral="0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
|
|
7
|
+
conditional_tokens="0x4D97DCd97eC945f40cF65F87097ACe5EA0476045",
|
|
8
|
+
),
|
|
9
|
+
80002: ContractConfig(
|
|
10
|
+
exchange="0xdFE02Eb6733538f8Ea35D585af8DE5958AD99E40",
|
|
11
|
+
collateral="0x9c4e1703476e875070ee25b56a58b008cfb8fa78",
|
|
12
|
+
conditional_tokens="0x69308FB512518e39F9b16112fA8d994F4e2Bf8bB",
|
|
13
|
+
),
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
NEG_RISK_CONFIG = {
|
|
17
|
+
137: ContractConfig(
|
|
18
|
+
exchange="0xC5d563A36AE78145C45a50134d48A1215220f80a",
|
|
19
|
+
collateral="0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
|
|
20
|
+
conditional_tokens="0x4D97DCd97eC945f40cF65F87097ACe5EA0476045",
|
|
21
|
+
),
|
|
22
|
+
80002: ContractConfig(
|
|
23
|
+
exchange="0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296",
|
|
24
|
+
collateral="0x9c4e1703476e875070ee25b56a58b008cfb8fa78",
|
|
25
|
+
conditional_tokens="0x69308FB512518e39F9b16112fA8d994F4e2Bf8bB",
|
|
26
|
+
),
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
def get_contract_config(chain_id: int, neg_risk: bool = False) -> ContractConfig:
|
|
30
|
+
"""Get the contract configuration for the chain."""
|
|
31
|
+
config = NEG_RISK_CONFIG.get(chain_id) if neg_risk else CONFIG.get(chain_id)
|
|
32
|
+
if config is None:
|
|
33
|
+
msg = f"Invalid chain_id: ${chain_id}"
|
|
34
|
+
raise ValueError(msg)
|
|
35
|
+
|
|
36
|
+
return config
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Access levels
|
|
2
|
+
L0 = 0
|
|
3
|
+
L1 = 1
|
|
4
|
+
L2 = 2
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
CREDENTIAL_CREATION_WARNING = """🚨🚨🚨
|
|
8
|
+
Your credentials CANNOT be recovered after they've been created.
|
|
9
|
+
Be sure to store them safely!
|
|
10
|
+
🚨🚨🚨"""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
L1_AUTH_UNAVAILABLE = "A private key is needed to interact with this endpoint!"
|
|
14
|
+
|
|
15
|
+
L2_AUTH_UNAVAILABLE = "API Credentials are needed to interact with this endpoint!"
|
|
16
|
+
|
|
17
|
+
ZERO_ADDRESS = "0x0000000000000000000000000000000000000000"
|
|
18
|
+
HASH_ZERO = "0x0000000000000000000000000000000000000000000000000000000000000000"
|
|
19
|
+
|
|
20
|
+
AMOY = 80002
|
|
21
|
+
POLYGON = 137
|
|
22
|
+
|
|
23
|
+
END_CURSOR = "LTE="
|
|
24
|
+
|
|
25
|
+
BUY = "BUY"
|
|
26
|
+
SELL = "SELL"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
TIME = "/time"
|
|
2
|
+
CREATE_API_KEY = "/auth/api-key"
|
|
3
|
+
GET_API_KEYS = "/auth/api-keys"
|
|
4
|
+
DELETE_API_KEY = "/auth/api-key"
|
|
5
|
+
DERIVE_API_KEY = "/auth/derive-api-key"
|
|
6
|
+
TRADES = "/data/trades"
|
|
7
|
+
GET_ORDER_BOOK = "/book"
|
|
8
|
+
GET_ORDER_BOOKS = "/books"
|
|
9
|
+
ORDERS = "/data/orders"
|
|
10
|
+
POST_ORDER = "/order"
|
|
11
|
+
POST_ORDERS = "/orders"
|
|
12
|
+
CANCEL = "/order"
|
|
13
|
+
CANCEL_ORDERS = "/orders"
|
|
14
|
+
CANCEL_ALL = "/cancel-all"
|
|
15
|
+
CANCEL_MARKET_ORDERS = "/cancel-market-orders"
|
|
16
|
+
MID_POINT = "/midpoint"
|
|
17
|
+
MID_POINTS = "/midpoints"
|
|
18
|
+
PRICE = "/price"
|
|
19
|
+
GET_PRICES = "/prices"
|
|
20
|
+
GET_SPREAD = "/spread"
|
|
21
|
+
GET_SPREADS = "/spreads"
|
|
22
|
+
GET_LAST_TRADE_PRICE = "/last-trade-price"
|
|
23
|
+
GET_LAST_TRADES_PRICES = "/last-trades-prices"
|
|
24
|
+
GET_NOTIFICATIONS = "/notifications"
|
|
25
|
+
DROP_NOTIFICATIONS = "/notifications"
|
|
26
|
+
GET_BALANCE_ALLOWANCE = "/balance-allowance"
|
|
27
|
+
UPDATE_BALANCE_ALLOWANCE = "/balance-allowance/update"
|
|
28
|
+
IS_ORDER_SCORING = "/order-scoring"
|
|
29
|
+
ARE_ORDERS_SCORING = "/orders-scoring"
|
|
30
|
+
GET_TICK_SIZE = "/tick-size"
|
|
31
|
+
GET_NEG_RISK = "/neg-risk"
|
|
32
|
+
GET_SAMPLING_SIMPLIFIED_MARKETS = "/sampling-simplified-markets"
|
|
33
|
+
GET_SAMPLING_MARKETS = "/sampling-markets"
|
|
34
|
+
GET_SIMPLIFIED_MARKETS = "/simplified-markets"
|
|
35
|
+
GET_MARKETS = "/markets"
|
|
36
|
+
GET_MARKET = "/markets/"
|
|
37
|
+
GET_MARKET_TRADES_EVENTS = "/live-activity/events/"
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from datetime import UTC, datetime
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
from ..types.clob_types import ApiCreds, RequestArgs
|
|
5
|
+
from .signing.eip712 import sign_clob_auth_message
|
|
6
|
+
from .signing.hmac import build_hmac_signature
|
|
7
|
+
from .signing.signer import Signer
|
|
8
|
+
|
|
9
|
+
POLY_ADDRESS = "POLY_ADDRESS"
|
|
10
|
+
POLY_SIGNATURE = "POLY_SIGNATURE"
|
|
11
|
+
POLY_TIMESTAMP = "POLY_TIMESTAMP"
|
|
12
|
+
POLY_NONCE = "POLY_NONCE"
|
|
13
|
+
POLY_API_KEY = "POLY_API_KEY"
|
|
14
|
+
POLY_PASSPHRASE = "POLY_PASSPHRASE"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def create_level_1_headers(signer: Signer, nonce: Optional[int] = None):
|
|
18
|
+
"""Creates Level 1 Poly headers for a request."""
|
|
19
|
+
timestamp = int(datetime.now(tz=UTC).timestamp())
|
|
20
|
+
|
|
21
|
+
n = 0
|
|
22
|
+
if nonce is not None:
|
|
23
|
+
n = nonce
|
|
24
|
+
|
|
25
|
+
signature = sign_clob_auth_message(signer, timestamp, n)
|
|
26
|
+
headers = {
|
|
27
|
+
POLY_ADDRESS: signer.address(),
|
|
28
|
+
POLY_SIGNATURE: signature,
|
|
29
|
+
POLY_TIMESTAMP: str(timestamp),
|
|
30
|
+
POLY_NONCE: str(n),
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return headers
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def create_level_2_headers(signer: Signer, creds: ApiCreds, request_args: RequestArgs):
|
|
37
|
+
"""Creates Level 2 Poly headers for a request."""
|
|
38
|
+
timestamp = str(int(datetime.now(tz=UTC).timestamp()))
|
|
39
|
+
|
|
40
|
+
hmac_sig = build_hmac_signature(
|
|
41
|
+
creds.secret,
|
|
42
|
+
timestamp,
|
|
43
|
+
request_args.method,
|
|
44
|
+
request_args.request_path,
|
|
45
|
+
request_args.body,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
POLY_ADDRESS: signer.address(),
|
|
50
|
+
POLY_SIGNATURE: hmac_sig,
|
|
51
|
+
POLY_TIMESTAMP: timestamp,
|
|
52
|
+
POLY_API_KEY: creds.api_key,
|
|
53
|
+
POLY_PASSPHRASE: creds.passphrase,
|
|
54
|
+
}
|
|
File without changes
|