pmxt 1.0.0__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.
Files changed (56) hide show
  1. pmxt/__init__.py +58 -0
  2. pmxt/client.py +713 -0
  3. pmxt/models.py +296 -0
  4. pmxt/server_manager.py +242 -0
  5. pmxt-1.0.0.dist-info/METADATA +250 -0
  6. pmxt-1.0.0.dist-info/RECORD +56 -0
  7. pmxt-1.0.0.dist-info/WHEEL +5 -0
  8. pmxt-1.0.0.dist-info/top_level.txt +2 -0
  9. pmxt_internal/__init__.py +124 -0
  10. pmxt_internal/api/__init__.py +5 -0
  11. pmxt_internal/api/default_api.py +3722 -0
  12. pmxt_internal/api_client.py +804 -0
  13. pmxt_internal/api_response.py +21 -0
  14. pmxt_internal/configuration.py +578 -0
  15. pmxt_internal/exceptions.py +219 -0
  16. pmxt_internal/models/__init__.py +54 -0
  17. pmxt_internal/models/balance.py +93 -0
  18. pmxt_internal/models/base_request.py +91 -0
  19. pmxt_internal/models/base_response.py +93 -0
  20. pmxt_internal/models/cancel_order_request.py +94 -0
  21. pmxt_internal/models/create_order200_response.py +99 -0
  22. pmxt_internal/models/create_order_params.py +111 -0
  23. pmxt_internal/models/create_order_request.py +102 -0
  24. pmxt_internal/models/error_detail.py +87 -0
  25. pmxt_internal/models/error_response.py +93 -0
  26. pmxt_internal/models/exchange_credentials.py +93 -0
  27. pmxt_internal/models/fetch_balance200_response.py +103 -0
  28. pmxt_internal/models/fetch_markets200_response.py +103 -0
  29. pmxt_internal/models/fetch_markets_request.py +102 -0
  30. pmxt_internal/models/fetch_ohlcv200_response.py +103 -0
  31. pmxt_internal/models/fetch_ohlcv_request.py +102 -0
  32. pmxt_internal/models/fetch_ohlcv_request_args_inner.py +140 -0
  33. pmxt_internal/models/fetch_open_orders200_response.py +103 -0
  34. pmxt_internal/models/fetch_open_orders_request.py +94 -0
  35. pmxt_internal/models/fetch_order_book200_response.py +99 -0
  36. pmxt_internal/models/fetch_order_book_request.py +94 -0
  37. pmxt_internal/models/fetch_positions200_response.py +103 -0
  38. pmxt_internal/models/fetch_positions_request.py +94 -0
  39. pmxt_internal/models/fetch_trades200_response.py +103 -0
  40. pmxt_internal/models/fetch_trades_request.py +102 -0
  41. pmxt_internal/models/get_markets_by_slug_request.py +94 -0
  42. pmxt_internal/models/health_check200_response.py +89 -0
  43. pmxt_internal/models/history_filter_params.py +101 -0
  44. pmxt_internal/models/market_filter_params.py +113 -0
  45. pmxt_internal/models/market_outcome.py +95 -0
  46. pmxt_internal/models/order.py +139 -0
  47. pmxt_internal/models/order_book.py +106 -0
  48. pmxt_internal/models/order_level.py +89 -0
  49. pmxt_internal/models/position.py +101 -0
  50. pmxt_internal/models/price_candle.py +97 -0
  51. pmxt_internal/models/search_markets_request.py +102 -0
  52. pmxt_internal/models/search_markets_request_args_inner.py +140 -0
  53. pmxt_internal/models/trade.py +105 -0
  54. pmxt_internal/models/unified_market.py +120 -0
  55. pmxt_internal/py.typed +0 -0
  56. pmxt_internal/rest.py +263 -0
@@ -0,0 +1,105 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ PMXT Sidecar API
5
+
6
+ A unified local sidecar API for prediction markets (Polymarket, Kalshi). This API acts as a JSON-RPC-style gateway. Each endpoint corresponds to a specific method on the generic exchange implementation.
7
+
8
+ The version of the OpenAPI document: 0.4.4
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+
15
+ from __future__ import annotations
16
+ import pprint
17
+ import re # noqa: F401
18
+ import json
19
+
20
+ from pydantic import BaseModel, ConfigDict, StrictFloat, StrictInt, StrictStr, field_validator
21
+ from typing import Any, ClassVar, Dict, List, Optional, Union
22
+ from typing import Optional, Set
23
+ from typing_extensions import Self
24
+
25
+ class Trade(BaseModel):
26
+ """
27
+ Trade
28
+ """ # noqa: E501
29
+ id: Optional[StrictStr] = None
30
+ price: Optional[Union[StrictFloat, StrictInt]] = None
31
+ amount: Optional[Union[StrictFloat, StrictInt]] = None
32
+ side: Optional[StrictStr] = None
33
+ timestamp: Optional[StrictInt] = None
34
+ __properties: ClassVar[List[str]] = ["id", "price", "amount", "side", "timestamp"]
35
+
36
+ @field_validator('side')
37
+ def side_validate_enum(cls, value):
38
+ """Validates the enum"""
39
+ if value is None:
40
+ return value
41
+
42
+ if value not in set(['buy', 'sell', 'unknown']):
43
+ raise ValueError("must be one of enum values ('buy', 'sell', 'unknown')")
44
+ return value
45
+
46
+ model_config = ConfigDict(
47
+ populate_by_name=True,
48
+ validate_assignment=True,
49
+ protected_namespaces=(),
50
+ )
51
+
52
+
53
+ def to_str(self) -> str:
54
+ """Returns the string representation of the model using alias"""
55
+ return pprint.pformat(self.model_dump(by_alias=True))
56
+
57
+ def to_json(self) -> str:
58
+ """Returns the JSON representation of the model using alias"""
59
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
60
+ return json.dumps(self.to_dict())
61
+
62
+ @classmethod
63
+ def from_json(cls, json_str: str) -> Optional[Self]:
64
+ """Create an instance of Trade from a JSON string"""
65
+ return cls.from_dict(json.loads(json_str))
66
+
67
+ def to_dict(self) -> Dict[str, Any]:
68
+ """Return the dictionary representation of the model using alias.
69
+
70
+ This has the following differences from calling pydantic's
71
+ `self.model_dump(by_alias=True)`:
72
+
73
+ * `None` is only added to the output dict for nullable fields that
74
+ were set at model initialization. Other fields with value `None`
75
+ are ignored.
76
+ """
77
+ excluded_fields: Set[str] = set([
78
+ ])
79
+
80
+ _dict = self.model_dump(
81
+ by_alias=True,
82
+ exclude=excluded_fields,
83
+ exclude_none=True,
84
+ )
85
+ return _dict
86
+
87
+ @classmethod
88
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
89
+ """Create an instance of Trade from a dict"""
90
+ if obj is None:
91
+ return None
92
+
93
+ if not isinstance(obj, dict):
94
+ return cls.model_validate(obj)
95
+
96
+ _obj = cls.model_validate({
97
+ "id": obj.get("id"),
98
+ "price": obj.get("price"),
99
+ "amount": obj.get("amount"),
100
+ "side": obj.get("side"),
101
+ "timestamp": obj.get("timestamp")
102
+ })
103
+ return _obj
104
+
105
+
@@ -0,0 +1,120 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ PMXT Sidecar API
5
+
6
+ A unified local sidecar API for prediction markets (Polymarket, Kalshi). This API acts as a JSON-RPC-style gateway. Each endpoint corresponds to a specific method on the generic exchange implementation.
7
+
8
+ The version of the OpenAPI document: 0.4.4
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+
15
+ from __future__ import annotations
16
+ import pprint
17
+ import re # noqa: F401
18
+ import json
19
+
20
+ from datetime import datetime
21
+ from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr
22
+ from typing import Any, ClassVar, Dict, List, Optional, Union
23
+ from pmxt_internal.models.market_outcome import MarketOutcome
24
+ from typing import Optional, Set
25
+ from typing_extensions import Self
26
+
27
+ class UnifiedMarket(BaseModel):
28
+ """
29
+ UnifiedMarket
30
+ """ # noqa: E501
31
+ id: Optional[StrictStr] = None
32
+ title: Optional[StrictStr] = None
33
+ description: Optional[StrictStr] = None
34
+ outcomes: Optional[List[MarketOutcome]] = None
35
+ resolution_date: Optional[datetime] = Field(default=None, alias="resolutionDate")
36
+ volume24h: Optional[Union[StrictFloat, StrictInt]] = None
37
+ volume: Optional[Union[StrictFloat, StrictInt]] = None
38
+ liquidity: Optional[Union[StrictFloat, StrictInt]] = None
39
+ open_interest: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="openInterest")
40
+ url: Optional[StrictStr] = None
41
+ image: Optional[StrictStr] = None
42
+ category: Optional[StrictStr] = None
43
+ tags: Optional[List[StrictStr]] = None
44
+ __properties: ClassVar[List[str]] = ["id", "title", "description", "outcomes", "resolutionDate", "volume24h", "volume", "liquidity", "openInterest", "url", "image", "category", "tags"]
45
+
46
+ model_config = ConfigDict(
47
+ populate_by_name=True,
48
+ validate_assignment=True,
49
+ protected_namespaces=(),
50
+ )
51
+
52
+
53
+ def to_str(self) -> str:
54
+ """Returns the string representation of the model using alias"""
55
+ return pprint.pformat(self.model_dump(by_alias=True))
56
+
57
+ def to_json(self) -> str:
58
+ """Returns the JSON representation of the model using alias"""
59
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
60
+ return json.dumps(self.to_dict())
61
+
62
+ @classmethod
63
+ def from_json(cls, json_str: str) -> Optional[Self]:
64
+ """Create an instance of UnifiedMarket from a JSON string"""
65
+ return cls.from_dict(json.loads(json_str))
66
+
67
+ def to_dict(self) -> Dict[str, Any]:
68
+ """Return the dictionary representation of the model using alias.
69
+
70
+ This has the following differences from calling pydantic's
71
+ `self.model_dump(by_alias=True)`:
72
+
73
+ * `None` is only added to the output dict for nullable fields that
74
+ were set at model initialization. Other fields with value `None`
75
+ are ignored.
76
+ """
77
+ excluded_fields: Set[str] = set([
78
+ ])
79
+
80
+ _dict = self.model_dump(
81
+ by_alias=True,
82
+ exclude=excluded_fields,
83
+ exclude_none=True,
84
+ )
85
+ # override the default output from pydantic by calling `to_dict()` of each item in outcomes (list)
86
+ _items = []
87
+ if self.outcomes:
88
+ for _item_outcomes in self.outcomes:
89
+ if _item_outcomes:
90
+ _items.append(_item_outcomes.to_dict())
91
+ _dict['outcomes'] = _items
92
+ return _dict
93
+
94
+ @classmethod
95
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
96
+ """Create an instance of UnifiedMarket from a dict"""
97
+ if obj is None:
98
+ return None
99
+
100
+ if not isinstance(obj, dict):
101
+ return cls.model_validate(obj)
102
+
103
+ _obj = cls.model_validate({
104
+ "id": obj.get("id"),
105
+ "title": obj.get("title"),
106
+ "description": obj.get("description"),
107
+ "outcomes": [MarketOutcome.from_dict(_item) for _item in obj["outcomes"]] if obj.get("outcomes") is not None else None,
108
+ "resolutionDate": obj.get("resolutionDate"),
109
+ "volume24h": obj.get("volume24h"),
110
+ "volume": obj.get("volume"),
111
+ "liquidity": obj.get("liquidity"),
112
+ "openInterest": obj.get("openInterest"),
113
+ "url": obj.get("url"),
114
+ "image": obj.get("image"),
115
+ "category": obj.get("category"),
116
+ "tags": obj.get("tags")
117
+ })
118
+ return _obj
119
+
120
+
pmxt_internal/py.typed ADDED
File without changes
pmxt_internal/rest.py ADDED
@@ -0,0 +1,263 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ PMXT Sidecar API
5
+
6
+ A unified local sidecar API for prediction markets (Polymarket, Kalshi). This API acts as a JSON-RPC-style gateway. Each endpoint corresponds to a specific method on the generic exchange implementation.
7
+
8
+ The version of the OpenAPI document: 0.4.4
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+
15
+ import io
16
+ import json
17
+ import re
18
+ import ssl
19
+
20
+ import urllib3
21
+
22
+ from pmxt_internal.exceptions import ApiException, ApiValueError
23
+
24
+ SUPPORTED_SOCKS_PROXIES = {"socks5", "socks5h", "socks4", "socks4a"}
25
+ RESTResponseType = urllib3.HTTPResponse
26
+
27
+
28
+ def is_socks_proxy_url(url):
29
+ if url is None:
30
+ return False
31
+ split_section = url.split("://")
32
+ if len(split_section) < 2:
33
+ return False
34
+ else:
35
+ return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES
36
+
37
+
38
+ class RESTResponse(io.IOBase):
39
+
40
+ def __init__(self, resp) -> None:
41
+ self.response = resp
42
+ self.status = resp.status
43
+ self.reason = resp.reason
44
+ self.data = None
45
+
46
+ def read(self):
47
+ if self.data is None:
48
+ self.data = self.response.data
49
+ return self.data
50
+
51
+ @property
52
+ def headers(self):
53
+ """Returns a dictionary of response headers."""
54
+ return self.response.headers
55
+
56
+ def getheaders(self):
57
+ """Returns a dictionary of the response headers; use ``headers`` instead."""
58
+ return self.response.headers
59
+
60
+ def getheader(self, name, default=None):
61
+ """Returns a given response header; use ``headers.get()`` instead."""
62
+ return self.response.headers.get(name, default)
63
+
64
+
65
+ class RESTClientObject:
66
+
67
+ def __init__(self, configuration) -> None:
68
+ # urllib3.PoolManager will pass all kw parameters to connectionpool
69
+ # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # noqa: E501
70
+ # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 # noqa: E501
71
+ # Custom SSL certificates and client certificates: http://urllib3.readthedocs.io/en/latest/advanced-usage.html # noqa: E501
72
+
73
+ # cert_reqs
74
+ if configuration.verify_ssl:
75
+ cert_reqs = ssl.CERT_REQUIRED
76
+ else:
77
+ cert_reqs = ssl.CERT_NONE
78
+
79
+ pool_args = {
80
+ "cert_reqs": cert_reqs,
81
+ "ca_certs": configuration.ssl_ca_cert,
82
+ "cert_file": configuration.cert_file,
83
+ "key_file": configuration.key_file,
84
+ "ca_cert_data": configuration.ca_cert_data,
85
+ }
86
+ if configuration.assert_hostname is not None:
87
+ pool_args['assert_hostname'] = (
88
+ configuration.assert_hostname
89
+ )
90
+
91
+ if configuration.retries is not None:
92
+ pool_args['retries'] = configuration.retries
93
+
94
+ if configuration.tls_server_name:
95
+ pool_args['server_hostname'] = configuration.tls_server_name
96
+
97
+
98
+ if configuration.socket_options is not None:
99
+ pool_args['socket_options'] = configuration.socket_options
100
+
101
+ if configuration.connection_pool_maxsize is not None:
102
+ pool_args['maxsize'] = configuration.connection_pool_maxsize
103
+
104
+ # https pool manager
105
+ self.pool_manager: urllib3.PoolManager
106
+
107
+ if configuration.proxy:
108
+ if is_socks_proxy_url(configuration.proxy):
109
+ from urllib3.contrib.socks import SOCKSProxyManager
110
+ pool_args["proxy_url"] = configuration.proxy
111
+ pool_args["headers"] = configuration.proxy_headers
112
+ self.pool_manager = SOCKSProxyManager(**pool_args)
113
+ else:
114
+ pool_args["proxy_url"] = configuration.proxy
115
+ pool_args["proxy_headers"] = configuration.proxy_headers
116
+ self.pool_manager = urllib3.ProxyManager(**pool_args)
117
+ else:
118
+ self.pool_manager = urllib3.PoolManager(**pool_args)
119
+
120
+ def request(
121
+ self,
122
+ method,
123
+ url,
124
+ headers=None,
125
+ body=None,
126
+ post_params=None,
127
+ _request_timeout=None
128
+ ):
129
+ """Perform requests.
130
+
131
+ :param method: http request method
132
+ :param url: http request url
133
+ :param headers: http request headers
134
+ :param body: request json body, for `application/json`
135
+ :param post_params: request post parameters,
136
+ `application/x-www-form-urlencoded`
137
+ and `multipart/form-data`
138
+ :param _request_timeout: timeout setting for this request. If one
139
+ number provided, it will be total request
140
+ timeout. It can also be a pair (tuple) of
141
+ (connection, read) timeouts.
142
+ """
143
+ method = method.upper()
144
+ assert method in [
145
+ 'GET',
146
+ 'HEAD',
147
+ 'DELETE',
148
+ 'POST',
149
+ 'PUT',
150
+ 'PATCH',
151
+ 'OPTIONS'
152
+ ]
153
+
154
+ if post_params and body:
155
+ raise ApiValueError(
156
+ "body parameter cannot be used with post_params parameter."
157
+ )
158
+
159
+ post_params = post_params or {}
160
+ headers = headers or {}
161
+
162
+ timeout = None
163
+ if _request_timeout:
164
+ if isinstance(_request_timeout, (int, float)):
165
+ timeout = urllib3.Timeout(total=_request_timeout)
166
+ elif (
167
+ isinstance(_request_timeout, tuple)
168
+ and len(_request_timeout) == 2
169
+ ):
170
+ timeout = urllib3.Timeout(
171
+ connect=_request_timeout[0],
172
+ read=_request_timeout[1]
173
+ )
174
+
175
+ try:
176
+ # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
177
+ if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
178
+
179
+ # no content type provided or payload is json
180
+ content_type = headers.get('Content-Type')
181
+ if (
182
+ not content_type
183
+ or re.search('json', content_type, re.IGNORECASE)
184
+ ):
185
+ request_body = None
186
+ if body is not None:
187
+ request_body = json.dumps(body)
188
+ r = self.pool_manager.request(
189
+ method,
190
+ url,
191
+ body=request_body,
192
+ timeout=timeout,
193
+ headers=headers,
194
+ preload_content=False
195
+ )
196
+ elif content_type == 'application/x-www-form-urlencoded':
197
+ r = self.pool_manager.request(
198
+ method,
199
+ url,
200
+ fields=post_params,
201
+ encode_multipart=False,
202
+ timeout=timeout,
203
+ headers=headers,
204
+ preload_content=False
205
+ )
206
+ elif content_type == 'multipart/form-data':
207
+ # must del headers['Content-Type'], or the correct
208
+ # Content-Type which generated by urllib3 will be
209
+ # overwritten.
210
+ del headers['Content-Type']
211
+ # Ensures that dict objects are serialized
212
+ post_params = [(a, json.dumps(b)) if isinstance(b, dict) else (a,b) for a, b in post_params]
213
+ r = self.pool_manager.request(
214
+ method,
215
+ url,
216
+ fields=post_params,
217
+ encode_multipart=True,
218
+ timeout=timeout,
219
+ headers=headers,
220
+ preload_content=False
221
+ )
222
+ # Pass a `string` parameter directly in the body to support
223
+ # other content types than JSON when `body` argument is
224
+ # provided in serialized form.
225
+ elif isinstance(body, str) or isinstance(body, bytes):
226
+ r = self.pool_manager.request(
227
+ method,
228
+ url,
229
+ body=body,
230
+ timeout=timeout,
231
+ headers=headers,
232
+ preload_content=False
233
+ )
234
+ elif headers['Content-Type'].startswith('text/') and isinstance(body, bool):
235
+ request_body = "true" if body else "false"
236
+ r = self.pool_manager.request(
237
+ method,
238
+ url,
239
+ body=request_body,
240
+ preload_content=False,
241
+ timeout=timeout,
242
+ headers=headers)
243
+ else:
244
+ # Cannot generate the request from given parameters
245
+ msg = """Cannot prepare a request message for provided
246
+ arguments. Please check that your arguments match
247
+ declared content type."""
248
+ raise ApiException(status=0, reason=msg)
249
+ # For `GET`, `HEAD`
250
+ else:
251
+ r = self.pool_manager.request(
252
+ method,
253
+ url,
254
+ fields={},
255
+ timeout=timeout,
256
+ headers=headers,
257
+ preload_content=False
258
+ )
259
+ except urllib3.exceptions.SSLError as e:
260
+ msg = "\n".join([type(e).__name__, str(e)])
261
+ raise ApiException(status=0, reason=msg)
262
+
263
+ return RESTResponse(r)