polymarket-apis 0.2.3__py3-none-any.whl → 0.2.5__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/clients/clob_client.py +2 -2
- polymarket_apis/clients/websockets_client.py +23 -6
- polymarket_apis/types/clob_types.py +1 -1
- polymarket_apis/types/websockets_types.py +31 -14
- polymarket_apis/utilities/headers.py +1 -1
- {polymarket_apis-0.2.3.dist-info → polymarket_apis-0.2.5.dist-info}/METADATA +1 -1
- {polymarket_apis-0.2.3.dist-info → polymarket_apis-0.2.5.dist-info}/RECORD +8 -8
- {polymarket_apis-0.2.3.dist-info → polymarket_apis-0.2.5.dist-info}/WHEEL +0 -0
|
@@ -446,7 +446,7 @@ class PolymarketClobClient:
|
|
|
446
446
|
|
|
447
447
|
def post_order(self, order: SignedOrder, order_type: OrderType = OrderType.GTC) -> Optional[OrderPostResponse]:
|
|
448
448
|
"""Posts a SignedOrder."""
|
|
449
|
-
body = order_to_json(order, self.creds.
|
|
449
|
+
body = order_to_json(order, self.creds.key, order_type)
|
|
450
450
|
headers = create_level_2_headers(
|
|
451
451
|
self.signer,
|
|
452
452
|
self.creds,
|
|
@@ -474,7 +474,7 @@ class PolymarketClobClient:
|
|
|
474
474
|
|
|
475
475
|
def post_orders(self, args: list[PostOrdersArgs]):
|
|
476
476
|
"""Posts multiple SignedOrders at once."""
|
|
477
|
-
body = [order_to_json(arg.order, self.creds.
|
|
477
|
+
body = [order_to_json(arg.order, self.creds.key, arg.order_type) for arg in args]
|
|
478
478
|
headers = create_level_2_headers(
|
|
479
479
|
self.signer,
|
|
480
480
|
self.creds,
|
|
@@ -10,13 +10,15 @@ from polymarket_apis.utilities.exceptions import AuthenticationRequiredError
|
|
|
10
10
|
|
|
11
11
|
from ..types.clob_types import ApiCreds
|
|
12
12
|
from ..types.websockets_types import (
|
|
13
|
+
ActivityOrderMatchEvent,
|
|
14
|
+
ActivityTradeEvent,
|
|
13
15
|
CommentEvent,
|
|
14
16
|
CryptoPriceSubscribeEvent,
|
|
15
17
|
CryptoPriceUpdateEvent,
|
|
16
18
|
LastTradePriceEvent,
|
|
17
19
|
LiveDataLastTradePriceEvent,
|
|
18
20
|
LiveDataOrderBookSummaryEvent,
|
|
19
|
-
|
|
21
|
+
LiveDataOrderEvent,
|
|
20
22
|
LiveDataPriceChangeEvent,
|
|
21
23
|
LiveDataTickSizeChangeEvent,
|
|
22
24
|
LiveDataTradeEvent,
|
|
@@ -79,9 +81,9 @@ def _process_live_data_event(event):
|
|
|
79
81
|
message = event.json
|
|
80
82
|
match message["type"]:
|
|
81
83
|
case "trades":
|
|
82
|
-
print(
|
|
84
|
+
print(ActivityTradeEvent(**message), "\n")
|
|
83
85
|
case "orders_matched":
|
|
84
|
-
print(
|
|
86
|
+
print(ActivityOrderMatchEvent(**message), "\n")
|
|
85
87
|
case "comment_created" | "comment_removed":
|
|
86
88
|
print(CommentEvent(**message), "\n")
|
|
87
89
|
case "reaction_created" | "reaction_removed":
|
|
@@ -104,6 +106,10 @@ def _process_live_data_event(event):
|
|
|
104
106
|
print(LiveDataTickSizeChangeEvent(**message), "\n")
|
|
105
107
|
case "market_created" | "market_resolved":
|
|
106
108
|
print(MarketStatusChangeEvent(**message), "\n")
|
|
109
|
+
case "order":
|
|
110
|
+
print(LiveDataOrderEvent(**message), "\n")
|
|
111
|
+
case "trade":
|
|
112
|
+
print(LiveDataTradeEvent(**message), "\n")
|
|
107
113
|
case _:
|
|
108
114
|
print(message)
|
|
109
115
|
except JSONDecodeError:
|
|
@@ -128,6 +134,7 @@ class PolymarketWebsocketsClient:
|
|
|
128
134
|
|
|
129
135
|
"""
|
|
130
136
|
websocket = WebSocket(self.url_market)
|
|
137
|
+
|
|
131
138
|
for event in persist(websocket): # persist automatically reconnects
|
|
132
139
|
if event.name == "ready":
|
|
133
140
|
websocket.send_json(
|
|
@@ -146,6 +153,7 @@ class PolymarketWebsocketsClient:
|
|
|
146
153
|
|
|
147
154
|
"""
|
|
148
155
|
websocket = WebSocket(self.url_user)
|
|
156
|
+
|
|
149
157
|
for event in persist(websocket):
|
|
150
158
|
if event.name == "ready":
|
|
151
159
|
websocket.send_json(
|
|
@@ -156,7 +164,6 @@ class PolymarketWebsocketsClient:
|
|
|
156
164
|
|
|
157
165
|
def live_data_socket(self, subscriptions: list[dict[str, Any]], process_event: Callable = _process_live_data_event, creds: Optional[ApiCreds] = None):
|
|
158
166
|
# info on how to subscribe found at https://github.com/Polymarket/real-time-data-client?tab=readme-ov-file#subscribe
|
|
159
|
-
# website seems to still use user_socket so clob_user might be wip
|
|
160
167
|
"""
|
|
161
168
|
Connect to the live data websocket and subscribe to specified events.
|
|
162
169
|
|
|
@@ -175,12 +182,22 @@ class PolymarketWebsocketsClient:
|
|
|
175
182
|
|
|
176
183
|
for event in persist(websocket):
|
|
177
184
|
if event.name == "ready":
|
|
185
|
+
if needs_auth:
|
|
186
|
+
subscriptions_with_creds = []
|
|
187
|
+
for sub in subscriptions:
|
|
188
|
+
if sub.get("topic") == "clob_user":
|
|
189
|
+
sub_copy = sub.copy()
|
|
190
|
+
sub_copy["clob_auth"] = creds.model_dump()
|
|
191
|
+
subscriptions_with_creds.append(sub_copy)
|
|
192
|
+
else:
|
|
193
|
+
subscriptions_with_creds.append(sub)
|
|
194
|
+
subscriptions = subscriptions_with_creds
|
|
195
|
+
|
|
178
196
|
payload = {
|
|
179
197
|
"action": "subscribe",
|
|
180
198
|
"subscriptions": subscriptions,
|
|
181
199
|
}
|
|
182
|
-
|
|
183
|
-
payload["auth"] = creds.model_dump(by_alias=True)
|
|
200
|
+
|
|
184
201
|
websocket.send_json(**payload)
|
|
185
202
|
|
|
186
203
|
elif event.name == "text":
|
|
@@ -16,6 +16,7 @@ class PriceChange(BaseModel):
|
|
|
16
16
|
side: Literal["BUY", "SELL"] = Field(validation_alias=AliasChoices("si", "side"))
|
|
17
17
|
token_id: str = Field(validation_alias=AliasChoices("a", "asset_id"))
|
|
18
18
|
hash: str = Field(validation_alias=AliasChoices("h", "hash"))
|
|
19
|
+
|
|
19
20
|
class PriceChanges(BaseModel):
|
|
20
21
|
condition_id: Keccak256 = Field(validation_alias=AliasChoices("m", "market"))
|
|
21
22
|
price_changes: list[PriceChange] = Field(validation_alias=AliasChoices("pc", "price_changes"))
|
|
@@ -58,8 +59,8 @@ class OrderEvent(BaseModel):
|
|
|
58
59
|
order_id: Keccak256 = Field(alias="id")
|
|
59
60
|
associated_trades: Optional[list[str]] = None # list of trade ids which
|
|
60
61
|
maker_address: EthAddress
|
|
61
|
-
order_owner: str # api key of order owner
|
|
62
|
-
event_owner: str = Field(alias="owner") # api key of event owner
|
|
62
|
+
order_owner: str = Field(alias="owner") # api key of order owner
|
|
63
|
+
event_owner: Optional[str] = Field(None, alias="owner") # api key of event owner
|
|
63
64
|
|
|
64
65
|
price: float
|
|
65
66
|
side: Literal["BUY", "SELL"]
|
|
@@ -70,10 +71,10 @@ class OrderEvent(BaseModel):
|
|
|
70
71
|
|
|
71
72
|
created_at: datetime
|
|
72
73
|
expiration: Optional[datetime] = None
|
|
73
|
-
timestamp: datetime # time of event
|
|
74
|
+
timestamp: Optional[datetime] = None # time of event
|
|
74
75
|
|
|
75
|
-
event_type: Literal["order"]
|
|
76
|
-
type: Literal["PLACEMENT", "UPDATE"
|
|
76
|
+
event_type: Optional[Literal["order"]] = None
|
|
77
|
+
type: Literal["PLACEMENT", "UPDATE", "CANCELLATION"]
|
|
77
78
|
|
|
78
79
|
status: Literal["LIVE", "CANCELED", "MATCHED"]
|
|
79
80
|
|
|
@@ -89,7 +90,7 @@ class TradeEvent(BaseModel):
|
|
|
89
90
|
taker_order_id: Keccak256
|
|
90
91
|
maker_orders: list[MakerOrder]
|
|
91
92
|
trade_id: str = Field(alias="id")
|
|
92
|
-
trade_owner: str # api key of trade owner
|
|
93
|
+
trade_owner: Optional[str] = Field(None, alias="owner") # api key of trade owner
|
|
93
94
|
event_owner: str = Field(alias="owner") # api key of event owner
|
|
94
95
|
|
|
95
96
|
price: float
|
|
@@ -99,17 +100,17 @@ class TradeEvent(BaseModel):
|
|
|
99
100
|
|
|
100
101
|
last_update: datetime # time of last update to trade
|
|
101
102
|
matchtime: Optional[datetime] = None # time trade was matched
|
|
102
|
-
timestamp: datetime # time of event
|
|
103
|
+
timestamp: Optional[datetime] = None # time of event
|
|
103
104
|
|
|
104
|
-
event_type: Literal["trade"]
|
|
105
|
-
type: Literal["TRADE"]
|
|
105
|
+
event_type: Optional[Literal["trade"]] = None
|
|
106
|
+
type: Optional[Literal["TRADE"]] = None
|
|
106
107
|
|
|
107
108
|
status: Literal["MATCHED", "MINED", "CONFIRMED", "RETRYING", "FAILED"]
|
|
108
109
|
|
|
109
110
|
# wss://ws-live-data.polymarket.com types
|
|
110
111
|
|
|
111
112
|
# Payload models
|
|
112
|
-
class
|
|
113
|
+
class ActivityTrade(BaseModel):
|
|
113
114
|
token_id: str = Field(alias="asset") # ERC1155 token ID of conditional token being traded
|
|
114
115
|
condition_id: str = Field(alias="conditionId") # Id of market which is also the CTF condition ID
|
|
115
116
|
event_slug: str = Field(alias="eventSlug") # Slug of the event
|
|
@@ -198,14 +199,14 @@ class LiveDataClobMarket(BaseModel):
|
|
|
198
199
|
neg_risk: bool
|
|
199
200
|
|
|
200
201
|
# Event models
|
|
201
|
-
class
|
|
202
|
-
payload:
|
|
202
|
+
class ActivityTradeEvent(BaseModel):
|
|
203
|
+
payload: ActivityTrade
|
|
203
204
|
timestamp: datetime
|
|
204
205
|
type: Literal["trades"]
|
|
205
206
|
topic: Literal["activity"]
|
|
206
207
|
|
|
207
|
-
class
|
|
208
|
-
payload:
|
|
208
|
+
class ActivityOrderMatchEvent(BaseModel):
|
|
209
|
+
payload: ActivityTrade
|
|
209
210
|
timestamp: datetime
|
|
210
211
|
type: Literal["orders_matched"]
|
|
211
212
|
topic: Literal["activity"]
|
|
@@ -282,7 +283,23 @@ class MarketStatusChangeEvent(BaseModel):
|
|
|
282
283
|
type: Literal["market_created", "market_resolved"]
|
|
283
284
|
topic: Literal["clob_market"]
|
|
284
285
|
|
|
286
|
+
class LiveDataOrderEvent(BaseModel):
|
|
287
|
+
connection_id: str
|
|
288
|
+
payload: OrderEvent
|
|
289
|
+
timestamp: datetime
|
|
290
|
+
type: Literal["order"]
|
|
291
|
+
topic: Literal["clob_user"]
|
|
292
|
+
|
|
293
|
+
class LiveDataTradeEvent(BaseModel):
|
|
294
|
+
connection_id: str
|
|
295
|
+
payload: TradeEvent
|
|
296
|
+
timestamp: datetime
|
|
297
|
+
type: Literal["trade"]
|
|
298
|
+
topic: Literal["clob_user"]
|
|
299
|
+
|
|
285
300
|
class ErrorEvent(BaseModel):
|
|
286
301
|
message: str
|
|
287
302
|
connection_id: str = Field(alias="connectionId")
|
|
288
303
|
request_id: str = Field(alias="requestId")
|
|
304
|
+
|
|
305
|
+
|
|
@@ -49,6 +49,6 @@ def create_level_2_headers(signer: Signer, creds: ApiCreds, request_args: Reques
|
|
|
49
49
|
POLY_ADDRESS: signer.address(),
|
|
50
50
|
POLY_SIGNATURE: hmac_sig,
|
|
51
51
|
POLY_TIMESTAMP: timestamp,
|
|
52
|
-
POLY_API_KEY: creds.
|
|
52
|
+
POLY_API_KEY: creds.key,
|
|
53
53
|
POLY_PASSPHRASE: creds.passphrase,
|
|
54
54
|
}
|
|
@@ -1,23 +1,23 @@
|
|
|
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=
|
|
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
6
|
polymarket_apis/clients/graphql_client.py,sha256=Jgrz107EVpHRSAXvY45hRUKuPndl9-41_EaqIYbb5mo,6907
|
|
7
7
|
polymarket_apis/clients/web3_client.py,sha256=0SX25LMP59FWzfsoshxt-_XNPcPXnmvwmCaHu3K4K2E,11222
|
|
8
|
-
polymarket_apis/clients/websockets_client.py,sha256=
|
|
8
|
+
polymarket_apis/clients/websockets_client.py,sha256=wueJ54ZgJgeiJmKi5EEIB8_YwkdD3y2Dr4t9WjFMXuU,7581
|
|
9
9
|
polymarket_apis/types/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
-
polymarket_apis/types/clob_types.py,sha256=
|
|
10
|
+
polymarket_apis/types/clob_types.py,sha256=O7_6x5gtLjjkcVhcUMv7aIyFhdk2LRfRObPibRwdC44,11699
|
|
11
11
|
polymarket_apis/types/common.py,sha256=eTY2kjOArzrZRVSmEJvxEyxGJeMx045R073EMZMzCKM,1629
|
|
12
12
|
polymarket_apis/types/data_types.py,sha256=K-bE5g1owFozvznmQZ0MicxGccqVSuEibuVzXFAoa4E,4408
|
|
13
13
|
polymarket_apis/types/gamma_types.py,sha256=CfjuQbkNaM-PcZoezSZvMk4ru7a4AzXh64Clbf13MHc,12518
|
|
14
|
-
polymarket_apis/types/websockets_types.py,sha256=
|
|
14
|
+
polymarket_apis/types/websockets_types.py,sha256=96xQl6xQ4ReL-b4a-UYNittPvXJBXuzX1RBxlJHJg-s,11993
|
|
15
15
|
polymarket_apis/utilities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
16
|
polymarket_apis/utilities/config.py,sha256=IfIBJa6rSi-e-9_HjeI8j4cD3MXtzRjoLzgcgn5tHbc,2448
|
|
17
17
|
polymarket_apis/utilities/constants.py,sha256=OdxaAsyYzAK1RXty5VtvidMgan8YW-JfHS3Rdxp6n_U,580
|
|
18
18
|
polymarket_apis/utilities/endpoints.py,sha256=bxZyrJBPbVauWc-eR0RMh6KDqU-SmO_3LfQwVMNJ6vE,1235
|
|
19
19
|
polymarket_apis/utilities/exceptions.py,sha256=58vuiLuZxX6d05qa29jgEOC4ZYBv368JaO8DAFMD0Dc,363
|
|
20
|
-
polymarket_apis/utilities/headers.py,sha256=
|
|
20
|
+
polymarket_apis/utilities/headers.py,sha256=Cc5WEnIBLYAgfwvmCXRBwA2zUYME8fDy4PbwlwlB6Oo,1510
|
|
21
21
|
polymarket_apis/utilities/order_builder/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
22
22
|
polymarket_apis/utilities/order_builder/builder.py,sha256=-eQ092J6Wkproy2SY6USFGWAniS5ZMBg85Ij_cnqqPs,8332
|
|
23
23
|
polymarket_apis/utilities/order_builder/helpers.py,sha256=QN39noGcWrGAy89dJc8DvEGJwiX0fMVc62R-pkclAu4,1714
|
|
@@ -36,6 +36,6 @@ polymarket_apis/utilities/web3/abis/ProxyWalletFactory.json,sha256=5KjBHUWdkc_kd
|
|
|
36
36
|
polymarket_apis/utilities/web3/abis/UChildERC20Proxy.json,sha256=ZyQC38U0uxInlmnW2VXDVD3TJfTIRmSNMkTxQsaG7oA,27396
|
|
37
37
|
polymarket_apis/utilities/web3/abis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
38
38
|
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.
|
|
39
|
+
polymarket_apis-0.2.5.dist-info/METADATA,sha256=B3ij72Emt46fd9e8pfCxn7rtxG2lulL5T9Xz33Et8Uo,558
|
|
40
|
+
polymarket_apis-0.2.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
41
|
+
polymarket_apis-0.2.5.dist-info/RECORD,,
|
|
File without changes
|