pmxt 1.0.1__py3-none-any.whl → 1.0.4__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.
pmxt/client.py CHANGED
@@ -198,6 +198,12 @@ class Exchange(ABC):
198
198
  # Configure the API client with the actual base URL
199
199
  config = Configuration(host=base_url)
200
200
  self._api_client = ApiClient(configuration=config)
201
+
202
+ # Add access token from lock file
203
+ server_info = self._server_manager.get_server_info()
204
+ if server_info and 'accessToken' in server_info:
205
+ self._api_client.default_headers['x-pmxt-access-token'] = server_info['accessToken']
206
+
201
207
  self._api = DefaultApi(api_client=self._api_client)
202
208
 
203
209
  def _handle_response(self, response: Dict[str, Any]) -> Any:
pmxt/server_manager.py CHANGED
@@ -69,15 +69,62 @@ class ServerManager:
69
69
  Raises:
70
70
  Exception: If server fails to start or become healthy
71
71
  """
72
- # Step 1: Check if server is already running
72
+ # Step 1: Check if force restart is requested (DEV MODE)
73
+ if os.getenv('PMXT_ALWAYS_RESTART') == '1':
74
+ self._kill_old_server()
75
+
76
+ # Step 2: Check if server is already running and matches version
73
77
  if self.is_server_alive():
74
- return
78
+ if self._is_version_mismatch():
79
+ # print("PMXT: Version mismatch detected. Restarting server...")
80
+ self._kill_old_server()
81
+ else:
82
+ return
75
83
 
76
- # Step 2: Start server via launcher
84
+ # Step 3: Start server via launcher
77
85
  self._start_server_via_launcher()
78
86
 
79
- # Step 3: Wait for health check
87
+ # Step 4: Wait for health check
80
88
  self._wait_for_health()
89
+
90
+ def _is_version_mismatch(self) -> bool:
91
+ """Check if running server version matches expected version."""
92
+ server_info = self.get_server_info()
93
+ if not server_info or 'version' not in server_info:
94
+ return True # Old server without version
95
+
96
+ # Get expected version
97
+ try:
98
+ # 1. Check production path (bundled)
99
+ pkg_path = Path(__file__).parent / '_server' / 'package.json'
100
+
101
+ # 2. Check dev path (monorepo)
102
+ if not pkg_path.exists():
103
+ # Traverse up to find core/package.json
104
+ pkg_path = Path(__file__).parent.parent.parent.parent / 'core' / 'package.json'
105
+
106
+ if pkg_path.exists():
107
+ data = json.loads(pkg_path.read_text())
108
+ expected_version = data.get('version')
109
+ if expected_version and not server_info['version'].startswith(expected_version):
110
+ return True
111
+ except:
112
+ pass
113
+
114
+ return False
115
+
116
+ def _kill_old_server(self) -> None:
117
+ """Kill the currently running server."""
118
+ server_info = self.get_server_info()
119
+ if server_info and 'pid' in server_info:
120
+ import signal
121
+ try:
122
+ os.kill(server_info['pid'], signal.SIGTERM)
123
+ # Brief wait for cleanup
124
+ time.sleep(0.5)
125
+ except:
126
+ pass
127
+ self._remove_stale_lock()
81
128
 
82
129
  def is_server_alive(self) -> bool:
83
130
  """
@@ -144,18 +191,29 @@ class ServerManager:
144
191
  """
145
192
  Start the server using the pmxt-ensure-server launcher.
146
193
  """
147
- # 1. Check for local development paths first
194
+ # 1. Check for bundled server (PRODUCTION - installed via pip)
195
+ bundled_launcher = Path(__file__).parent / '_server' / 'bin' / 'pmxt-ensure-server'
196
+
197
+ # 2. Check for monorepo structure (DEVELOPMENT)
148
198
  current_file = Path(__file__).resolve()
149
- # Look for ../../bin/pmxt-ensure-server (monorepo structure)
150
- local_launcher = current_file.parent.parent.parent / 'bin' / 'pmxt-ensure-server'
199
+ local_launcher = current_file.parent.parent.parent.parent / 'core' / 'bin' / 'pmxt-ensure-server'
151
200
 
152
- launcher = str(local_launcher) if local_launcher.exists() else shutil.which('pmxt-ensure-server')
201
+ # 3. Check PATH (GLOBAL INSTALL)
202
+ path_launcher = shutil.which('pmxt-ensure-server')
153
203
 
154
- if not launcher:
204
+ # Priority order: bundled > local dev > PATH
205
+ if bundled_launcher.exists():
206
+ launcher = str(bundled_launcher)
207
+ elif local_launcher.exists():
208
+ launcher = str(local_launcher)
209
+ elif path_launcher:
210
+ launcher = path_launcher
211
+ else:
155
212
  raise Exception(
156
213
  "pmxt-ensure-server not found.\n"
157
- "Local search failed and not in PATH.\n"
158
- "Please install the server: npm install -g pmxtjs"
214
+ "This should have been bundled with the package.\n"
215
+ "Please reinstall: pip install --force-reinstall pmxt\n"
216
+ "Or install the server manually: npm install -g pmxt-core"
159
217
  )
160
218
 
161
219
  # Call the launcher
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pmxt
3
- Version: 1.0.1
3
+ Version: 1.0.4
4
4
  Summary: Unified prediction market data API - The ccxt for prediction markets
5
5
  Author: PMXT Contributors
6
6
  License: MIT
@@ -1,11 +1,14 @@
1
- pmxt/__init__.py,sha256=I84TjHQFVD84qYfgQzAipnaxF54NBoeOzlOS7eL_xps,1150
2
- pmxt/client.py,sha256=pXAPl_IPhnza2xwlObSlLia9aWpBHA97Nsxq9aP3yvU,23485
1
+ pmxt/__init__.py,sha256=Ndcnaw9g7pzjDlzyp--yAC7kWkAoZIOdm6qKu0JgNPY,1150
2
+ pmxt/client.py,sha256=zetDOeeVfbPB8FAYmAJ0TKBm8ayecMXKunC3T-Rr9qM,23764
3
3
  pmxt/models.py,sha256=Mu0hLVjQU3PM5m68poK61VQcJtPQ8ZdLdLU7pq1lqjQ,6004
4
- pmxt/server_manager.py,sha256=XmvNhBia3ex7XyIcxy2pIdoCHu_Y4R7tKSEWrw2jaKc,8320
5
- pmxt_internal/__init__.py,sha256=C-gVAVkcuSGwGO_RizwP6CcUywnL6GEln8n5fWdPGkg,5973
6
- pmxt_internal/api_client.py,sha256=Or2AVtohO9R9hWORQWYvSNeI09cjANbSDG-VtnHhyHY,27889
4
+ pmxt/server_manager.py,sha256=wmHcGBM3oMNLSajCZ0xnANNSmqBYt9vWxQzeYmfo0-Y,10635
5
+ pmxt/_server/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ pmxt/_server/bin/pmxt-ensure-server,sha256=kXIond0UbxS52FAVQD7kHmSBaL_s6cbIyapLRr4KZJw,4544
7
+ pmxt/_server/server/bundled.js,sha256=xz4CbngIw6bEk9-WJx01Ot36WnksbRs2Q48VqMnXDzQ,3395261
8
+ pmxt_internal/__init__.py,sha256=7zNRfRaiNCcIEPMdprPwqzukZr8KuGTuh6shFyuLpcc,5973
9
+ pmxt_internal/api_client.py,sha256=qyxGwvCTSfLqocSG0TeVhPPxR1SwJ5TPfLOKb1f6cf8,27889
7
10
  pmxt_internal/api_response.py,sha256=eMxw1mpmJcoGZ3gs9z6jM4oYoZ10Gjk333s9sKxGv7s,652
8
- pmxt_internal/configuration.py,sha256=tm1iEGbjjtgFaNzwQILH6xZLUyy8TwllHcn9QZDElHM,18320
11
+ pmxt_internal/configuration.py,sha256=pu1_jLL1TW9moJrv7nD5-lFWfdKm7JxgazKS1bNjfnU,18320
9
12
  pmxt_internal/exceptions.py,sha256=txF8A7vlan57JS69kFPs-IZF-Qhp7IZobBTJVa4fOaM,6644
10
13
  pmxt_internal/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
14
  pmxt_internal/rest.py,sha256=FMj4yaV6XLr842u_ScWHSzQsTFdk0jaUeuWLJoRbogQ,9760
@@ -50,7 +53,7 @@ pmxt_internal/models/search_markets_request.py,sha256=BARoy2GXgV7RQNIGck6UaOyQqf
50
53
  pmxt_internal/models/search_markets_request_args_inner.py,sha256=PkusFd_OxhUsItsBpluPJA11zg0sXXjbOK-lPmemvLs,5561
51
54
  pmxt_internal/models/trade.py,sha256=U6Fc18rbwILs9FmX8CSDYYL8dF6763l8QzeMQNRxQdo,3328
52
55
  pmxt_internal/models/unified_market.py,sha256=mNyUrGKWxvI2f2KCa2uhGwq22cBdDia2hD5AtzFw8fE,4487
53
- pmxt-1.0.1.dist-info/METADATA,sha256=POG07mOia5wAMbM4z41CIFipNWp3XOZneA2N9mcHTuA,6300
54
- pmxt-1.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
55
- pmxt-1.0.1.dist-info/top_level.txt,sha256=J_jrcouJ-x-5lpcXMxeW0GOSi1HsBVR5_PdSfvigVrw,19
56
- pmxt-1.0.1.dist-info/RECORD,,
56
+ pmxt-1.0.4.dist-info/METADATA,sha256=6AMypjzaOIHmwVKQ2L8hKBz2shiE5lqVqmisxL88OB4,6300
57
+ pmxt-1.0.4.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
58
+ pmxt-1.0.4.dist-info/top_level.txt,sha256=J_jrcouJ-x-5lpcXMxeW0GOSi1HsBVR5_PdSfvigVrw,19
59
+ pmxt-1.0.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
pmxt_internal/__init__.py CHANGED
@@ -14,7 +14,7 @@
14
14
  """ # noqa: E501
15
15
 
16
16
 
17
- __version__ = "1.0.1"
17
+ __version__ = "1.0.4"
18
18
 
19
19
  # Define package exports
20
20
  __all__ = [
@@ -91,7 +91,7 @@ class ApiClient:
91
91
  self.default_headers[header_name] = header_value
92
92
  self.cookie = cookie
93
93
  # Set default User-Agent.
94
- self.user_agent = 'OpenAPI-Generator/1.0.1/python'
94
+ self.user_agent = 'OpenAPI-Generator/1.0.4/python'
95
95
  self.client_side_validation = configuration.client_side_validation
96
96
 
97
97
  def __enter__(self):
@@ -506,7 +506,7 @@ class Configuration:
506
506
  "OS: {env}\n"\
507
507
  "Python Version: {pyversion}\n"\
508
508
  "Version of the API: 0.4.4\n"\
509
- "SDK Package Version: 1.0.1".\
509
+ "SDK Package Version: 1.0.4".\
510
510
  format(env=sys.platform, pyversion=sys.version)
511
511
 
512
512
  def get_host_settings(self) -> List[HostSetting]: