polymarket-apis 0.2.2__py3-none-any.whl → 0.2.3__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.

@@ -1,44 +1,66 @@
1
1
  from datetime import datetime
2
- from typing import Literal
2
+ from typing import Literal, Optional
3
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
4
+ from pydantic import AliasChoices, BaseModel, Field, field_validator
8
5
 
6
+ from ..types.clob_types import MakerOrder, OrderBookSummary, TickSize
7
+ from ..types.common import EthAddress, Keccak256, TimeseriesPoint
9
8
 
10
9
  # wss://ws-subscriptions-clob.polymarket.com/ws/market types
11
- class OrderBookSummaryEvent(OrderBookSummary):
12
- event_type: Literal["book"]
13
10
 
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"]
11
+ class PriceChange(BaseModel):
12
+ best_ask: float = Field(validation_alias=AliasChoices("ba", "best_ask"))
13
+ best_bid: float = Field(validation_alias=AliasChoices("bb", "best_bid"))
14
+ price: float = Field(validation_alias=AliasChoices("p", "price"))
15
+ size: float = Field(validation_alias=AliasChoices("s", "size"))
16
+ side: Literal["BUY", "SELL"] = Field(validation_alias=AliasChoices("si", "side"))
17
+ token_id: str = Field(validation_alias=AliasChoices("a", "asset_id"))
18
+ hash: str = Field(validation_alias=AliasChoices("h", "hash"))
19
+ class PriceChanges(BaseModel):
20
+ condition_id: Keccak256 = Field(validation_alias=AliasChoices("m", "market"))
21
+ price_changes: list[PriceChange] = Field(validation_alias=AliasChoices("pc", "price_changes"))
22
+ timestamp: datetime = Field(validation_alias=AliasChoices("t", "timestamp"))
21
23
 
22
- class TickSizeChangeEvent(BaseModel):
24
+ class TickSizeChange(BaseModel):
23
25
  token_id: str = Field(alias="asset_id")
24
26
  condition_id: Keccak256 = Field(alias="market")
25
27
  old_tick_size: TickSize
26
28
  new_tick_size: TickSize
29
+
30
+ class LastTradePrice(BaseModel):
31
+ price: float
32
+ size: float
27
33
  side: Literal["BUY", "SELL"]
28
- timestamp: datetime # time of event
34
+ token_id: str = Field(alias="asset_id")
35
+ condition_id: Keccak256 = Field(alias="market")
36
+ fee_rate_bps: float
37
+
38
+ class OrderBookSummaryEvent(OrderBookSummary):
39
+ event_type: Literal["book"]
40
+
41
+ class PriceChangeEvent(PriceChanges):
42
+ event_type: Literal["price_change"]
43
+
44
+ class TickSizeChangeEvent(TickSizeChange):
45
+ side: Literal["BUY", "SELL"]
46
+ timestamp: datetime
29
47
  event_type: Literal["tick_size_change"]
30
48
 
49
+ class LastTradePriceEvent(LastTradePrice):
50
+ timestamp: datetime
51
+ event_type: Literal["last_trade_price"]
52
+
31
53
  # wss://ws-subscriptions-clob.polymarket.com/ws/user types
54
+
32
55
  class OrderEvent(BaseModel):
33
56
  token_id: str = Field(alias="asset_id")
34
57
  condition_id: Keccak256 = Field(alias="market")
35
58
  order_id: Keccak256 = Field(alias="id")
36
- associated_trades: list[str] | None = None # list of trade ids which
59
+ associated_trades: Optional[list[str]] = None # list of trade ids which
37
60
  maker_address: EthAddress
38
61
  order_owner: str # api key of order owner
39
62
  event_owner: str = Field(alias="owner") # api key of event owner
40
63
 
41
-
42
64
  price: float
43
65
  side: Literal["BUY", "SELL"]
44
66
  size_matched: float
@@ -47,7 +69,7 @@ class OrderEvent(BaseModel):
47
69
  order_type: Literal["GTC", "FOK", "GTD"]
48
70
 
49
71
  created_at: datetime
50
- expiration: datetime | None = None
72
+ expiration: Optional[datetime] = None
51
73
  timestamp: datetime # time of event
52
74
 
53
75
  event_type: Literal["order"]
@@ -76,7 +98,7 @@ class TradeEvent(BaseModel):
76
98
  outcome: str
77
99
 
78
100
  last_update: datetime # time of last update to trade
79
- matchtime: datetime | None = None # time trade was matched
101
+ matchtime: Optional[datetime] = None # time trade was matched
80
102
  timestamp: datetime # time of event
81
103
 
82
104
  event_type: Literal["trade"]
@@ -85,6 +107,8 @@ class TradeEvent(BaseModel):
85
107
  status: Literal["MATCHED", "MINED", "CONFIRMED", "RETRYING", "FAILED"]
86
108
 
87
109
  # wss://ws-live-data.polymarket.com types
110
+
111
+ # Payload models
88
112
  class LiveDataTrade(BaseModel):
89
113
  token_id: str = Field(alias="asset") # ERC1155 token ID of conditional token being traded
90
114
  condition_id: str = Field(alias="conditionId") # Id of market which is also the CTF condition ID
@@ -104,25 +128,24 @@ class LiveDataTrade(BaseModel):
104
128
  bio: str # Bio of the user of the trade
105
129
  pseudonym: str # Pseudonym of the user
106
130
  profile_image: str = Field(alias="profileImage") # URL to the user profile image
107
- profile_image_optimized: str | None = Field(None, alias="profileImageOptimized")
108
-
131
+ profile_image_optimized: Optional[str] = Field(None, alias="profileImageOptimized")
109
132
 
110
133
  class Comment(BaseModel):
111
134
  id: str # Unique identifier of comment
112
135
  body: str # Content of the comment
113
136
  parent_entity_type: str = Field(alias="parentEntityType") # Type of the parent entity (Event or Series)
114
137
  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
138
+ parent_comment_id: Optional[str] = Field(None, alias="parentCommentID") # ID of the parent comment
116
139
  user_address: str = Field(alias="userAddress") # Address of the user
117
- reply_address: str | None = Field(None, alias="replyAddress") # Address of the reply user
140
+ reply_address: Optional[str] = Field(None, alias="replyAddress") # Address of the reply user
118
141
  created_at: datetime = Field(alias="createdAt") # Creation timestamp
119
- updated_at: datetime | None = Field(None, alias="updatedAt") # Last update timestamp
142
+ updated_at: Optional[datetime] = Field(None, alias="updatedAt") # Last update timestamp
120
143
 
121
144
  class Reaction(BaseModel):
122
145
  id: str # Unique identifier of reaction
123
146
  comment_id: int = Field(alias="commentID") # ID of the comment
124
147
  reaction_type: str = Field(alias="reactionType") # Type of the reaction
125
- icon: str | None = None # Icon representing the reaction
148
+ icon: Optional[str] = None # Icon representing the reaction
126
149
  user_address: str = Field(alias="userAddress") # Address of the user
127
150
  created_at: datetime = Field(alias="createdAt") # Creation timestamp
128
151
 
@@ -138,7 +161,7 @@ class Request(BaseModel):
138
161
  price: float # Price from in/out sizes
139
162
  size_in: float = Field(alias="sizeIn") # Input size of the request
140
163
  size_out: float = Field(alias="sizeOut") # Output size of the request
141
- expiry: datetime | None = None
164
+ expiry: Optional[datetime] = None
142
165
 
143
166
  class Quote(BaseModel):
144
167
  quote_id: str = Field(alias="quoteId") # Unique identifier for the quote
@@ -152,8 +175,29 @@ class Quote(BaseModel):
152
175
  side: Literal["BUY", "SELL"] # Indicates buy or sell side
153
176
  size_in: float = Field(alias="sizeIn") # Input size of the quote
154
177
  size_out: float = Field(alias="sizeOut") # Output size of the quote
155
- expiry: datetime | None = None
178
+ expiry: Optional[datetime] = None
179
+
180
+ class CryptoPriceSubscribe(BaseModel):
181
+ data: list[TimeseriesPoint]
182
+ symbol: str
183
+
184
+ class CryptoPriceUpdate(TimeseriesPoint):
185
+ symbol: str
186
+ full_accuracy_value: str
187
+
188
+ class AggOrderBookSummary(OrderBookSummary):
189
+ min_order_size: float
190
+ tick_size: TickSize
191
+ neg_risk: bool
156
192
 
193
+ class LiveDataClobMarket(BaseModel):
194
+ token_ids: list[str] = Field(alias="asset_ids")
195
+ condition_id: Keccak256 = Field(alias="market")
196
+ min_order_size: float
197
+ tick_size: TickSize
198
+ neg_risk: bool
199
+
200
+ # Event models
157
201
  class LiveDataTradeEvent(BaseModel):
158
202
  payload: LiveDataTrade
159
203
  timestamp: datetime
@@ -189,3 +233,56 @@ class QuoteEvent(BaseModel):
189
233
  timestamp: datetime
190
234
  type: Literal["quote_created", "quote_edited", "quote_canceled", "quote_expired"]
191
235
  topic: Literal["rfq"]
236
+
237
+ class CryptoPriceUpdateEvent(BaseModel):
238
+ payload: CryptoPriceUpdate
239
+ timestamp: datetime
240
+ connection_id: str
241
+ type: Literal["update"]
242
+ topic: Literal["crypto_prices", "crypto_prices_chainlink"]
243
+
244
+ class CryptoPriceSubscribeEvent(BaseModel):
245
+ payload: CryptoPriceSubscribe
246
+ timestamp: datetime
247
+ type: Literal["subscribe"]
248
+ topic: Literal["crypto_prices", "crypto_prices_chainlink"]
249
+
250
+ class LiveDataOrderBookSummaryEvent(BaseModel):
251
+ payload: list[AggOrderBookSummary] | AggOrderBookSummary
252
+ timestamp: datetime
253
+ connection_id: str
254
+ type: Literal["agg_orderbook"]
255
+ topic: Literal["clob_market"]
256
+
257
+ class LiveDataPriceChangeEvent(BaseModel):
258
+ payload: PriceChanges
259
+ timestamp: datetime
260
+ connection_id: str
261
+ type: Literal["price_change"]
262
+ topic: Literal["clob_market"]
263
+
264
+ class LiveDataLastTradePriceEvent(BaseModel):
265
+ payload: LastTradePrice
266
+ timestamp: datetime
267
+ connection_id: str
268
+ type: Literal["last_trade_price"]
269
+ topic: Literal["clob_market"]
270
+
271
+ class LiveDataTickSizeChangeEvent(BaseModel):
272
+ payload: TickSizeChange
273
+ timestamp: datetime
274
+ connection_id: str
275
+ type: Literal["tick_size_change"]
276
+ topic: Literal["clob_market"]
277
+
278
+ class MarketStatusChangeEvent(BaseModel):
279
+ payload: LiveDataClobMarket
280
+ timestamp: datetime
281
+ connection_id: str
282
+ type: Literal["market_created", "market_resolved"]
283
+ topic: Literal["clob_market"]
284
+
285
+ class ErrorEvent(BaseModel):
286
+ message: str
287
+ connection_id: str = Field(alias="connectionId")
288
+ request_id: str = Field(alias="requestId")
@@ -34,3 +34,15 @@ def get_contract_config(chain_id: int, neg_risk: bool = False) -> ContractConfig
34
34
  raise ValueError(msg)
35
35
 
36
36
  return config
37
+
38
+
39
+ GRAPHQL_ENDPOINTS = {
40
+ "activity_subgraph": "https://api.goldsky.com/api/public/project_cl6mb8i9h0003e201j6li0diw/subgraphs/activity-subgraph/0.0.4/gn",
41
+ "fpmm_subgraph": "https://api.goldsky.com/api/public/project_cl6mb8i9h0003e201j6li0diw/subgraphs/fpmm-subgraph/0.0.1/gn",
42
+ "open_interest_subgraph": "https://api.goldsky.com/api/public/project_cl6mb8i9h0003e201j6li0diw/subgraphs/oi-subgraph/0.0.6/gn",
43
+ "orderbook_subgraph": "https://api.goldsky.com/api/public/project_cl6mb8i9h0003e201j6li0diw/subgraphs/orderbook-subgraph/0.0.1/gn",
44
+ "pnl_subgraph": "https://api.goldsky.com/api/public/project_cl6mb8i9h0003e201j6li0diw/subgraphs/pnl-subgraph/0.0.14/gn",
45
+ "positions_subgraph": "https://api.goldsky.com/api/public/project_cl6mb8i9h0003e201j6li0diw/subgraphs/positions-subgraph/0.0.7/gn",
46
+ "sports_oracle_subgraph": "https://api.goldsky.com/api/public/project_cl6mb8i9h0003e201j6li0diw/subgraphs/sports-oracle-subgraph/0.0.1/gn",
47
+ "wallet_subgraph": "https://api.goldsky.com/api/public/project_cl6mb8i9h0003e201j6li0diw/subgraphs/wallet-subgraph/0.0.4/gn",
48
+ }
@@ -29,6 +29,7 @@ IS_ORDER_SCORING = "/order-scoring"
29
29
  ARE_ORDERS_SCORING = "/orders-scoring"
30
30
  GET_TICK_SIZE = "/tick-size"
31
31
  GET_NEG_RISK = "/neg-risk"
32
+ GET_FEE_RATE = "/fee-rate"
32
33
  GET_SAMPLING_SIMPLIFIED_MARKETS = "/sampling-simplified-markets"
33
34
  GET_SAMPLING_MARKETS = "/sampling-markets"
34
35
  GET_SIMPLIFIED_MARKETS = "/simplified-markets"
@@ -4,8 +4,14 @@ class InvalidPriceError(Exception):
4
4
  class InvalidTickSizeError(Exception):
5
5
  pass
6
6
 
7
+ class InvalidFeeRateError(Exception):
8
+ pass
9
+
7
10
  class LiquidityError(Exception):
8
11
  pass
9
12
 
10
13
  class MissingOrderbookError(Exception):
11
14
  pass
15
+
16
+ class AuthenticationRequiredError(ValueError):
17
+ """Raised when authentication credentials are required but not provided."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: polymarket-apis
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Unified Polymarket APIs - clob, gamma, data, web3, websockets
5
5
  Author-email: Razvan Gheorghe <razvan@gheorghe.me>
6
6
  Requires-Python: >=3.12
@@ -1,21 +1,22 @@
1
1
  polymarket_apis/__init__.py,sha256=8a6dT19YqnOcLEmprl8vavi97JpaRrcDWBTllGsrmbE,61
2
2
  polymarket_apis/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- polymarket_apis/clients/clob_client.py,sha256=2Mgh-WRPJ3CqlcuBMrXAgKQRzWr-dNthynZf2Q0jsiY,29549
3
+ polymarket_apis/clients/clob_client.py,sha256=BIRkjL_B-cFcDdsUMV-RKwQU4gxPgoWlNpDxE6QbqZc,31033
4
4
  polymarket_apis/clients/data_client.py,sha256=sAJqesjKT8cRNr-j4OsXj-xYHEOzt0WWCvXcvejX7uI,8641
5
- polymarket_apis/clients/gamma_client.py,sha256=y-qBzU21qKXpluO3-mWPY_h9N6KSbiq4cpvR-X8Awqo,11972
6
- polymarket_apis/clients/web3_client.py,sha256=lIE-xXYmlk0sO0OFy2OQ9ylJPIL39gMnSg2bAjD6HmQ,11215
7
- polymarket_apis/clients/websockets_client.py,sha256=Spdp_8L_RzNJEZ867Vk9BMTW3J-lMAwyx3P0R98x_j4,4646
5
+ polymarket_apis/clients/gamma_client.py,sha256=yGi7l0vceBgrwMlqLFZYyQ_Lj13hNaDwaBtLSDoTAnM,12190
6
+ polymarket_apis/clients/graphql_client.py,sha256=Jgrz107EVpHRSAXvY45hRUKuPndl9-41_EaqIYbb5mo,6907
7
+ polymarket_apis/clients/web3_client.py,sha256=0SX25LMP59FWzfsoshxt-_XNPcPXnmvwmCaHu3K4K2E,11222
8
+ polymarket_apis/clients/websockets_client.py,sha256=2FWGP16oH-uqd-eIMuXfo8TMPhSVGf06LwDsJaQ1Yf8,7001
8
9
  polymarket_apis/types/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
10
  polymarket_apis/types/clob_types.py,sha256=TlbSH6P3BpDz1xX9hhcHjH6Y5HogZVnhjL-wTE9hF2Q,11703
10
- polymarket_apis/types/common.py,sha256=eqgTPYQaRe_kl4XpixLgQlVlP0iB1jd3ThiJs_xwHx0,1568
11
+ polymarket_apis/types/common.py,sha256=eTY2kjOArzrZRVSmEJvxEyxGJeMx045R073EMZMzCKM,1629
11
12
  polymarket_apis/types/data_types.py,sha256=K-bE5g1owFozvznmQZ0MicxGccqVSuEibuVzXFAoa4E,4408
12
- polymarket_apis/types/gamma_types.py,sha256=zREASm8jrQokxNC-VYvghYtorhdHebvxww803iRadSU,10377
13
- polymarket_apis/types/websockets_types.py,sha256=o55PkBksDgy4yxAWEM_qB3JifxuP70ev5IyQuj9Krfk,8278
13
+ polymarket_apis/types/gamma_types.py,sha256=CfjuQbkNaM-PcZoezSZvMk4ru7a4AzXh64Clbf13MHc,12518
14
+ polymarket_apis/types/websockets_types.py,sha256=Aylgj5ik-ywmwG1XUK3EfdtHxuRnR3-Nt3HnKuTTq_s,11492
14
15
  polymarket_apis/utilities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
- polymarket_apis/utilities/config.py,sha256=t1cN9nLy949nL-kO8-m3ODS9g-rcYVduxJ2J1LNUqdc,1358
16
+ polymarket_apis/utilities/config.py,sha256=IfIBJa6rSi-e-9_HjeI8j4cD3MXtzRjoLzgcgn5tHbc,2448
16
17
  polymarket_apis/utilities/constants.py,sha256=OdxaAsyYzAK1RXty5VtvidMgan8YW-JfHS3Rdxp6n_U,580
17
- polymarket_apis/utilities/endpoints.py,sha256=OX6KBeS7XHC8t50s0QpBw8KMg7IS279Jq6xIk8I05Kc,1208
18
- polymarket_apis/utilities/exceptions.py,sha256=agbe5OZD9kRoQVTGJvBK3mbnZgLTXI4FJNESM0zsKqM,187
18
+ polymarket_apis/utilities/endpoints.py,sha256=bxZyrJBPbVauWc-eR0RMh6KDqU-SmO_3LfQwVMNJ6vE,1235
19
+ polymarket_apis/utilities/exceptions.py,sha256=58vuiLuZxX6d05qa29jgEOC4ZYBv368JaO8DAFMD0Dc,363
19
20
  polymarket_apis/utilities/headers.py,sha256=dl3ONZU56nsrGkAishwYtALT-Qn8P3Ts_z58-XgPARg,1514
20
21
  polymarket_apis/utilities/order_builder/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
22
  polymarket_apis/utilities/order_builder/builder.py,sha256=-eQ092J6Wkproy2SY6USFGWAniS5ZMBg85Ij_cnqqPs,8332
@@ -35,6 +36,6 @@ polymarket_apis/utilities/web3/abis/ProxyWalletFactory.json,sha256=5KjBHUWdkc_kd
35
36
  polymarket_apis/utilities/web3/abis/UChildERC20Proxy.json,sha256=ZyQC38U0uxInlmnW2VXDVD3TJfTIRmSNMkTxQsaG7oA,27396
36
37
  polymarket_apis/utilities/web3/abis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
37
38
  polymarket_apis/utilities/web3/abis/custom_contract_errors.py,sha256=ZCeJPK5tobPAR9vaNxw_pQZwKyZc_R0GdggfWaeXvOs,1176
38
- polymarket_apis-0.2.2.dist-info/METADATA,sha256=Ghid2hQzHlSGgv4BzxuQHy6GgkBLUDgvx6XVytm6UQM,558
39
- polymarket_apis-0.2.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
40
- polymarket_apis-0.2.2.dist-info/RECORD,,
39
+ polymarket_apis-0.2.3.dist-info/METADATA,sha256=DHct659fgfOT_mWi-jzeiSTtizi-DhlGtoeo008WyGc,558
40
+ polymarket_apis-0.2.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
41
+ polymarket_apis-0.2.3.dist-info/RECORD,,