MEXC API Bypass
Client for interacting with MEXC Futures API with automatic signature generation for authentication. Requires a ‘WEB’ format access token that can be obtained from a browser session after authorization on the MEXC platform.
Disclaimer
This project is for educational purposes only. The author is not responsible for any financial losses or other consequences resulting from the use of this code. Cryptocurrency trading involves high risks. Before using, make sure you fully understand the API mechanics and trading risks. All actions are performed at your own risk.
Prerequisites
To work with this project, you need:
Installation
git clone https://github.com/hostnes/MexcApiBypass.git
cd MexcApiBypass
python3 -m venv venv
source venv/bin/activate # Linux/macOS
# venv\Scripts\activate # Windows
pip install -r requirements.txt
Obtaining the ‘WEB’ Token
To use the client, you need a ‘WEB’ format access token extracted from the MEXC browser session. Instructions:
- Log in to the MEXC website in your browser.
- Open the developer console (
F12 or through the browser menu).
- In the “Application” tab (Chrome) or “Storage” tab (Firefox), find the “Cookies” section.
- Select the MEXC domain from the list.
- Find the entry named “u_id” and copy its value.
- Use the obtained value (starts with “WEB”) as the
api_key parameter when initializing the client.
Quick Start
from mexc_client import MexcClient
client = MexcClient(api_key='WEB...')
contract = client.get_contract_detail("BTC_USDT")
result = client.place_order(symbol="BTC_USDT", side=1, vol=170, price=2.5, leverage=20)
positions = client.get_open_positions()
API Methods
get_contract_detail(symbol)
GET /api/v1/contract/detail
Get contract details.
Parameters:
symbol (str) — trading pair
Example request:
{
"symbol": "BTC_USDT"
}
Example response:
{
"success": true,
"contract_size": 0.0001,
"max_leverage": 500,
"max_volume": 400000,
"min_volume": 1,
"vol_scale": 0,
"vol_unit": 1,
"data": {
"symbol": "BTC_USDT",
"displayName": "BTC_USDT永续",
"baseCoin": "BTC",
"quoteCoin": "USDT",
"contractSize": 0.0001,
"minLeverage": 1,
"maxLeverage": 500,
"minVol": 1,
"maxVol": 400000,
"takerFeeRate": 0.0004,
"makerFeeRate": 0.0001
}
}
get_open_positions()
GET /api/v1/private/position/open_positions
Get list of all open positions.
Parameters: none
Example request:
{}
Example response:
{
"success": true,
"data": [
{
"positionId": 1109973831,
"symbol": "BTC_USDT",
"positionType": 1,
"openType": 1,
"state": 1,
"holdVol": 5,
"frozenVol": 0,
"closeVol": 0,
"holdAvgPrice": 109777.5,
"holdAvgPriceFullyScale": "109777.5",
"openAvgPrice": 109777.5,
"openAvgPriceFullyScale": "109777.5",
"closeAvgPrice": 0,
"liquidatePrice": 55020.5,
"oim": 27.444375,
"im": 27.444375,
"holdFee": 0,
"realised": 0,
"leverage": 2,
"marginRatio": 0.0027,
"createTime": 1761887133854,
"updateTime": 1761887133854
}
]
}
place_order(symbol, side, vol, price, open_type=1, order_type="1", leverage=20, price_protect="0")
POST /api/v1/private/order/create
Place a limit order.
Parameters:
symbol (str) — trading pair
side (int) — order direction
vol (float) — volume
price (float) — price
open_type (int) — margin type, default 1
order_type (str) — order type, default "1"
leverage (int) — leverage, default 20
price_protect (str) — price protection, default "0"
Example request:
{
"symbol": "BTC_USDT",
"side": 1,
"vol": 170,
"price": 2.5,
"open_type": 1,
"order_type": "1",
"leverage": 20,
"price_protect": "0"
}
Example response:
{
"success": true,
"code": 0,
"data": {
"orderId": "739113577038255616",
"ts": 1761888808839
}
}
open_market_position(symbol, side, open_type, volume, leverage, stop_loss_price=None, take_profit_price=None)
POST /api/v1/private/order/submit
Open a market position with optional stop-loss and take-profit.
Parameters:
symbol (str) — trading pair
side (int) — position direction
open_type (int) — margin type
volume (str) — position volume in contracts
leverage (int) — leverage
stop_loss_price (str, optional) — stop-loss price
take_profit_price (str, optional) — take-profit price
Example request:
{
"symbol": "ARB_USDT",
"side": 1,
"open_type": 2,
"volume": "10",
"leverage": 5,
"stop_loss_price": "25000",
"take_profit_price": "35000"
}
Example response:
{
"success": true,
"data": {
"orderId": "739113577038255616",
"ts": 1761888808839
}
}
Examples
from mexc_client import MexcClient
client = MexcClient(api_key='WEB...')
# Get contract information
contract = client.get_contract_detail("BTC_USDT")
if contract["success"]:
print(f"Max leverage: {contract['max_leverage']}")
print(f"Min volume: {contract['min_volume']}")
# Place a limit order
result = client.place_order(
symbol="BTC_USDT",
side=1,
vol=170,
price=2.5,
leverage=20
)
if result["success"]:
print(f"Order ID: {result['data']['orderId']}")
# Get all positions
positions = client.get_open_positions()
if positions["success"]:
for pos in positions["data"]:
print(f"{pos['symbol']}: {pos['holdVol']} @ {pos['holdAvgPrice']}")
Project Support
If this project has been useful to you, we would appreciate a star on GitHub. This helps the project grow and become more visible. We also welcome any ideas, feedback, and suggestions for improving functionality through Issues or Pull Requests.
All presented methods are examples of basic functionality. You can extend the code and add your own methods to work with other MEXC Futures API endpoints. Full API documentation is available at: https://www.mexc.com/api-docs/futures/integration-guide
评论