Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/api-doc-config.generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -1011,4 +1011,4 @@
"python": "import pmxt\nimport os\n\nexchange = pmxt.Polymarket(\n private_key=os.getenv('POLYMARKET_PRIVATE_KEY')\n)\n\n# 1. Check balance\nbalances = exchange.fetch_balance()\nif balances:\n balance = balances[0]\n print(f'Available: ${balance.available}')\n\n# 2. Search for a market\nmarkets = exchange.fetch_markets(query='Trump')\nmarket = markets[0]\noutcome = market.yes\n\nprint(f'{market.title}')\nprint(f'Price: {outcome.price * 100:.1f}%')\n\n# 3. Place a limit order\norder = exchange.create_order(\n market_id=market.market_id,\n outcome_id=outcome.outcome_id,\n side='buy',\n type='limit',\n amount=10,\n price=0.50\n)\n\nprint(f'Order placed: {order.id}')\n\n# 4. Check order status\nupdated_order = exchange.fetch_order(order.id)\nprint(f'Status: {updated_order.status}')\nprint(f'Filled: {updated_order.filled}/{updated_order.amount}')\n\n# 5. Cancel if needed\nif updated_order.status == 'open':\n exchange.cancel_order(order.id)\n print('Order cancelled')\n\n# 6. Check positions\npositions = exchange.fetch_positions()\nfor pos in positions:\n pnl_sign = '+' if pos.unrealized_pnl > 0 else ''\n print(f'{pos.outcome_label}: {pnl_sign}${pos.unrealized_pnl:.2f}')",
"typescript": "import pmxt from 'pmxtjs';\n\nconst exchange = new pmxt.Polymarket({\n privateKey: process.env.POLYMARKET_PRIVATE_KEY\n});\n\n// 1. Check balance\nconst [balance] = await exchange.fetchBalance();\nconsole.log(`Available: $${balance.available}`);\n\n// 2. Search for a market\nconst markets = await exchange.fetchMarkets({ query: 'Trump' });\nconst market = markets[0];\nconst outcome = market.yes;\n\nconsole.log(market.title);\nconsole.log(`Price: ${(outcome.price * 100).toFixed(1)}%`);\n\n// 3. Place a limit order\nconst order = await exchange.createOrder({\n marketId: market.marketId,\n outcomeId: outcome.outcomeId,\n side: 'buy',\n type: 'limit',\n amount: 10,\n price: 0.50\n});\n\nconsole.log(`Order placed: ${order.id}`);\n\n// 4. Check order status\nconst updatedOrder = await exchange.fetchOrder(order.id);\nconsole.log(`Status: ${updatedOrder.status}`);\nconsole.log(`Filled: ${updatedOrder.filled}/${updatedOrder.amount}`);\n\n// 5. Cancel if needed\nif (updatedOrder.status === 'open') {\n await exchange.cancelOrder(order.id);\n console.log('Order cancelled');\n}\n\n// 6. Check positions\nconst positions = await exchange.fetchPositions();\npositions.forEach(pos => {\n console.log(`${pos.outcomeLabel}: ${pos.unrealizedPnL > 0 ? '+' : ''}$${pos.unrealizedPnL.toFixed(2)}`);\n});"
}
}
}
29 changes: 11 additions & 18 deletions sdks/python/pmxt/server_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _extract_port_from_url(self, url: str) -> int:
from urllib.parse import urlparse
parsed = urlparse(url)
return parsed.port or self.DEFAULT_PORT
except:
except (ValueError, AttributeError):
return self.DEFAULT_PORT

def ensure_server_running(self) -> None:
Expand Down Expand Up @@ -153,7 +153,7 @@ def normalize_version(v: str) -> str:
# This allows 1.0.0 and 1.0.0-b4 to coexist in dev
if expected_base != server_base:
return True
except Exception:
except (OSError, json.JSONDecodeError, AttributeError, KeyError, TypeError, ValueError):
pass

return False
Expand Down Expand Up @@ -294,7 +294,7 @@ def _kill_orphan_sidecars(self) -> None:

if result.stdout.strip():
time.sleep(0.5)
except Exception:
except (OSError, subprocess.TimeoutExpired, ValueError):
pass

def _kill_old_server(self) -> None:
Expand All @@ -312,7 +312,7 @@ def _kill_old_server(self) -> None:
import signal
os.kill(pid, signal.SIGTERM)
time.sleep(0.5)
except Exception:
except (OSError, subprocess.TimeoutExpired):
pass

# Verify the process is actually dead; escalate to SIGKILL if not
Expand All @@ -324,7 +324,7 @@ def _kill_old_server(self) -> None:
try:
os.kill(pid, signal.SIGKILL)
time.sleep(0.2)
except Exception:
except OSError:
pass
except (OSError, ProcessLookupError):
pass # Process is dead — good
Expand Down Expand Up @@ -362,11 +362,7 @@ def is_server_alive(self) -> bool:
return False

# Quick health check to verify server is responsive
try:
return self._check_health(port, timeout=1)
except:
# Process exists but not responding
return False
return self._check_health(port, timeout=1)

except (json.JSONDecodeError, OSError):
return False
Expand Down Expand Up @@ -398,7 +394,7 @@ def _remove_stale_lock(self) -> None:
"""Remove stale lock file."""
try:
self.lock_path.unlink()
except:
except OSError:
pass

def _start_server_via_launcher(self) -> None:
Expand Down Expand Up @@ -468,12 +464,9 @@ def _wait_for_health(self) -> None:
start_time = time.time()

while time.time() - start_time < self.HEALTH_CHECK_TIMEOUT:
try:
port = self.get_running_port()
if self._check_health(port):
return
except:
pass
port = self.get_running_port()
if self._check_health(port):
return

time.sleep(self.HEALTH_CHECK_INTERVAL)

Expand Down Expand Up @@ -517,7 +510,7 @@ def get_server_info(self) -> Optional[Dict[str, Any]]:

try:
return json.loads(self.lock_path.read_text())
except:
except (OSError, json.JSONDecodeError):
return None

def get_running_port(self) -> int:
Expand Down
Loading