Typed, production-grade Python SDK for the Phemex crypto exchange API
Project description
phemex-py
Typed, production-grade Python SDK for the Phemex crypto exchange API.
- Sync and async clients (built on httpx)
- Fully typed request/response models (built on Pydantic)
- USD-M perpetual futures: orders, positions, market data, funding rates, and more
Installation
pip install phemex-py
Quick Start
Authentication
You need a Phemex API key and secret. Create one from your Phemex account settings.
Setting them as environment variables is a tried and true method:
PHEMEX_KIND=test
PHEMEX_KEY=
PHEMEX_SECRET=
The kind parameter controls which Phemex environment to connect to:
| Kind | URL |
|---|---|
vip |
https://vapi.phemex.com |
public |
https://api.phemex.com |
test |
https://testnet-api.phemex.com |
Sync Client
from phemex_py import PhemexClient
with PhemexClient(
kind="public",
api_key="your-api-key",
api_secret="your-api-secret",
) as client:
# Get server time
server_time = client.server_time()
# Get product info
products = client.usdm_rest.product_information()
# Get ticker
ticker = client.usdm_rest.ticker(symbol="BTCUSDT")
# Get open orders
orders = client.usdm_rest.open_orders(symbol="BTCUSDT")
# Get account positions
positions = client.usdm_rest.positions()
Async Client
import asyncio
from phemex_py import AsyncPhemexClient
async def main():
async with AsyncPhemexClient(
kind="public",
api_key="your-api-key",
api_secret="your-api-secret",
) as client:
ticker = await client.usdm_rest.ticker(symbol="BTCUSDT")
positions = await client.usdm_rest.positions()
asyncio.run(main())
Testnet
Use kind="test" for paper trading:
client = PhemexClient(
kind="test",
api_key="your-testnet-key",
api_secret="your-testnet-secret",
)
API Coverage
USD-M Perpetual REST API
| Category | Endpoints |
|---|---|
| Market Data | product_information, order_book, klines, trades, ticker, tickers |
| Orders | place_order, amend_order, cancel_order, bulk_cancel, cancel_all |
| Positions | positions, positions_with_pnl, switch_position_mode, set_leverage, assign_position_balance |
| Account | risk_units |
| History | open_orders, closed_orders, closed_positions, user_trades, order_history, lookup_order, trade_history |
| Funding | funding_fee_history, funding_rates |
Links
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file phemex_py-0.1.1.tar.gz.
File metadata
- Download URL: phemex_py-0.1.1.tar.gz
- Upload date:
- Size: 152.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dbd7128168bc07d558e994a7aa1f4a2ae66d7d182ce8844fdb5249857cf69fd9
|
|
| MD5 |
1d87deed7326f0addf2bbd3c4fcd3a70
|
|
| BLAKE2b-256 |
63bf9b02120f014984e29068659f0f063c15d2d57fd61f230347bb3425206661
|
File details
Details for the file phemex_py-0.1.1-py3-none-any.whl.
File metadata
- Download URL: phemex_py-0.1.1-py3-none-any.whl
- Upload date:
- Size: 135.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d471c88dabc33066475ef811e50765d62239a3138c324a945dda3c06bb742808
|
|
| MD5 |
b15eba517c6f1adbb4ae4994fe27190c
|
|
| BLAKE2b-256 |
51466ed37f7ac74f1fef8f263757ab1fd64ac57bd70782a8ebf917ec23a44c71
|