Skip to main content

WebSocket API

WebSocket is a new HTML5 protocol that enables full-duplex communication between client and server, allowing data to flow quickly in both directions. A simple handshake establishes the connection; after that, the server can proactively push messages to the client based on business rules. Benefits:

  1. Very small header overhead during data transfer (about 2 bytes).
  2. Both client and server can actively send data to each other.
  3. No repeated TCP connection setup/teardown—saves bandwidth and server resources.

Native ws endpoint

  • wss://contract.mexc.com/edge

Command details for data exchange

Send ping

{
"method": "ping"
}

Server response

{
"channel": "pong",
"data": 1587453241453
}

Subscribe/unsubscribe command list (except personal/private commands, all others do not require WS auth).

If no ping is received from the client within 1 minute, the connection will be closed. Send a ping every 10–20 seconds.

Subscription filtering

Disable default pushes

{
"subscribe": false,
"method": "login",
"param": {
"apiKey": "mxU1TzSmRDW1o5AsE",
"signature": "8c957a757ea31672eca05cb652d26bab7f46a41364adb714dda5475264aff120",
"reqTime": "1611038237237"
}
}

Only assets

{
"method": "personal.filter",
"param": {
"filters": [
{
"filter": "asset"
}
]
}
}

Only ADL level

{
"method": "personal.filter",
"param": {
"filters": [
{
"filter": "adl.level"
}
]
}
}

All fills only

{
"method": "personal.filter",
"param": {
"filters": [
{
"filter": "order.deal",
"rules": []
}
]
}
}

Or

{
"method": "personal.filter",
"param": {
"filters": [
{
"filter": "order.deal"
}
]
}
}

Fills for a single contract only

{
"method": "personal.filter",
"param": {
"filters": [
{
"filter": "order.deal",
"rules": ["BTC_USDT"]
}
]
}
}

Mixed usage

{
"method": "personal.filter",
"param": {
"filters": [
{
"filter": "order",
"rules": ["BTC_USDT"]
},
{
"filter": "order.deal",
"rules": ["EOS_USDT", "ETH_USDT", "BTC_USDT"]
},
{
"filter": "position",
"rules": ["EOS_USDT", "BTC_USDT"]
},
{
"filter": "asset"
}
]
}
}

After login, all personal data will be pushed by default: order (orders), order.deal (fills), position (positions), plan.order (plan orders), stop.order (TP/SL orders), stop.planorder (TP/SL plan orders), risk.limit (risk limits), adl.level (ADL level), asset (assets).

  1. To cancel default pushes, add "subscribe": false to the login params (default is true).
  2. After login, send the personal.filter event to filter what you need. To restore all pushes, send {"method":"personal.filter"} or {"method":"personal.filter","param":{"filters":[]}}.
  3. Valid filter keys (fixed values; errors if incorrect): order, order.deal, position, plan.order, stop.order, stop.planorder, risk.limit, adl.level, asset.

asset and adl.level do not support per-symbol filtering; others can filter by a single contract.

Subsequent filter events overwrite previous ones.

Public channels

Tickers

Subscribe

{
"method": "sub.tickers",
"param": {}
}

If you need plaintext responses (same for other subs):

{
"method": "sub.tickers",
"param": {},
"gzip": false
}

Unsubscribe

{
"method": "unsub.tickers",
"param": {}
}

Sample data

{
"channel": "push.tickers",
"data": [
{
"fairPrice": 183.01,
"lastPrice": 183,
"riseFallRate": -0.0708,
"symbol": "BSV_USDT",
"volume24": 200,
"maxBidPrice": 7073.42,
"minAskPrice": 6661.37
},
{
"fairPrice": 220.22,
"lastPrice": 220.4,
"riseFallRate": -0.0686,
"symbol": "BCH_USDT",
"volume24": 200,
"maxBidPrice": 7073.42,
"minAskPrice": 6661.37
}
]
}

Get latest price, best bid/ask, and 24h volume for all perpetual contracts. No login required. Pushes every 1s.

Response fields:

FieldTypeDescription
symbolstringContract
timestamplongTrade time
lastPricedecimalLast price
volume24decimal24h volume (in contracts)
amount24decimal24h turnover (in currency)
riseFallRatedecimalChange rate
fairPricedecimalFair price
indexPricedecimalIndex price
maxBidPricedecimalMax buy price
minAskPricedecimalMin sell price
lower24Pricedecimal24h low
high24Pricedecimal24h high

Get a single ticker

Subscribe

{
"method": "sub.ticker",
"param": {
"symbol": "BTC_USDT"
}
}

Unsubscribe

{
"method": "unsub.ticker",
"param": {
"symbol": "BTC_USDT"
}
}

Sample data

{
"channel": "push.ticker",
"data": {
"ask1": 6866.5,
"bid1": 6865,
"contractId": 1,
"fairPrice": 6867.4,
"fundingRate": 0.0008,
"high24Price": 7223.5,
"indexPrice": 6861.6,
"lastPrice": 6865.5,
"lower24Price": 6756,
"maxBidPrice": 7073.42,
"minAskPrice": 6661.37,
"riseFallRate": -0.0424,
"riseFallValue": -304.5,
"symbol": "BTC_USDT",
"timestamp": 1587442022003,
"holdVol": 2284742,
"volume24": 164586129
},
"symbol": "BTC_USDT"
}

Get latest price, best bid/ask, and 24h volume for a given contract. No login required. Pushes every 1s when trades occur.

Response fields:

FieldTypeDescription
symbolstringContract
timestamplongTrade time
lastPricedecimalLast price
bid1decimalBest bid
ask1decimalBest ask
holdVoldecimalOpen interest
fundingRatedecimalFunding rate
riseFallRatedecimalChange rate
riseFallValuedecimalChange amount
volume24decimal24h volume (contracts)
amount24decimal24h turnover (currency)
fairPricedecimalFair price
indexPricedecimalIndex price
maxBidPricedecimalMax buy price
minAskPricedecimalMin sell price
lower24Pricedecimal24h low
high24Pricedecimal24h high

Deal

Subscribe

{
"method": "sub.deal",
"param": {
"symbol": "BTC_USDT"
}
}

Unsubscribe

{
"method": "unsub.deal",
"param": {
"symbol": "BTC_USDT"
}
}

Sample data

{
"symbol": "BTC_USDT",
"data": [
{
"p": 115309.8,
"v": 55,
"T": 2,
"O": 3,
"M": 1,
"t": 1755487578276
},
{
"p": 115309.8,
"v": 11,
"T": 1,
"O": 3,
"M": 1,
"t": 1755487578275
}
],
"channel": "push.deal",
"ts": 1755487578276
}

Receive recent trades. No login required. Pushed whenever trades occur. Trade stream enables aggregation by default; to disable, set compress=false in the subscription.

Response fields:

FieldTypeDescription
pdecimalPrice
vdecimalQuantity
TintTrade side: 1 buy, 2 sell
OintOpen/close flag: 1 new position, 2 reduce position, 3 position unchanged. If O=1, v is the added position size
MintSelf-trade: 1 yes, 2 no
tlongTrade time

Order book depth

Subscribe

{
"method": "sub.depth",
"param": {
"symbol": "BTC_USDT"
}
}

Unsubscribe

{
"method": "unsub.depth",
"param": {
"symbol": "BTC_USDT"
}
}

Sample data

{
"channel": "push.depth",
"data": {
"asks": [[6859.5, 3251, 1]],
"bids": [],
"version": 96801927
},
"symbol": "BTC_USDT",
"ts": 1587442022003
}

Receive depth data for a specific contract; after subscribing, updates are pushed every 200 ms.

Response fields:

FieldTypeDescription
asksList<Numeric[]>Ask depth
bidsList<Numeric[]>Bid depth
versionlongVersion

Note: [411.8, 10, 1] → 411.8 is price,10 is the order numbers of the contract ,1 is the order quantity

Depth — specify minimum notional step

Subscribe

{ "method": "sub.depth.step", "param": { "symbol": "BTC_USDT", "step": "10" } }

Note: 10 means notional bucket size of 10; e.g., levels like 100010, 100020, 100030.

Unsubscribe

{
"method": "unsub.depth.step",
"param": { "symbol": "BTC_USDT", "step": "10" }
}

Sample data

{
"channel": "push.depth.step",
"data": {
"askMarketLevelPrice": 111089.4,
"asks": [
[111090, 398676, 26],
[111100, 410175, 8]
],
"bidMarketLevelPrice": 111085.5,
"bids": [
[111080, 461204, 35],
[111070, 386809, 3]
],
"ct": 1760950364388,
"version": 27883254360
},
"symbol": "BTC_USDT"
}

Receive depth data for contracts with a specified minimum notional step; after subscribing, updates are pushed every 200 ms.

Response fields:

FieldTypeDescription
asksList<Numeric[]>Ask depth
bidsList<Numeric[]>Bid depth
askMarketLevelPricedecimalHighest willing ask
bidMarketLevelPricedecimalHighest willing bid
versionlongVersion

Note: [111090,398676,26] → 111090 is price,398676 is the order numbers of the contract ,26 is the order quantity

K-line data

Subscribe

{
"method": "sub.kline",
"param": {
"symbol": "BTC_USDT",
"interval": "Min60"
},
"gzip": false
}

Unsubscribe

{
"method": "unsub.kline",
"param": {
"symbol": "BTC_USDT"
}
}

Sample data

{
"channel": "push.kline",
"data": {
"a": 233.740269343644737245,
"c": 6885,
"h": 6910.5,
"interval": "Min60",
"l": 6885,
"o": 6894.5,
"q": 1611754,
"symbol": "BTC_USDT",
"t": 1587448800
},
"symbol": "BTC_USDT"
}

Receive K-line updates as they occur.

interval options: Min1, Min5, Min15, Min30, Min60, Hour4, Hour8, Day1, Week1, Month1

Response fields:

FieldTypeDescription
symbolstringContract
intervalstringInterval: Min1, Min5, Min15, Min30, Min60, Hour4, Hour8, Day1, Week1, Month1
adecimalTotal traded amount
qdecimalTotal traded volume
odecimalOpen
cdecimalClose
hdecimalHigh
ldecimalLow
vdecimalTotal volume
rodecimalReal open
rcdecimalReal close
rhdecimalReal high
rldecimalReal low
tlongTrade time in seconds (window start)

Funding rate

Subscribe

{
"method": "sub.funding.rate",
"param": {
"symbol": "BTC_USDT"
},
"gzip": false
}

Unsubscribe

{
"method": "unsub.funding.rate",
"param": {
"symbol": "BTC_USDT"
}
}

Sample data

{
"channel": "push.funding.rate",
"data": {
"rate": 0.001,
"symbol": "BTC_USDT"
},
"symbol": "BTC_USDT",
"ts": 1587442022003
}

Get funding rate updates.

Response fields:

FieldTypeDescription
symbolstringContract
fundingRatedecimalFunding rate
nextSettleTimelongNext settlement

Index price

Subscribe

For both linear and inverse contracts, use the same symbol (e.g., for inverse BTC_USD, use BTC_USDT when subscribing to index price).

{
"method": "sub.index.price",
"param": {
"symbol": "BTC_USDT"
},
"gzip": false
}

Unsubscribe

{
"method": "unsub.index.price",
"param": {
"symbol": "BTC_USDT"
}
}

Sample data

{
"channel": "push.index.price",
"data": {
"price": 0.001,
"symbol": "BTC_USDT"
},
"symbol": "BTC_USDT",
"ts": 1587442022003
}

Get the contract’s index price; updates are pushed whenever there are changes.

Response fields:

FieldTypeDescription
symbolstringContract
pricedecimalPrice

Fair price

Subscribe

{
"method": "sub.fair.price",
"param": {
"symbol": "BTC_USDT"
},
"gzip": false
}

Unsubscribe

{
"method": "unsub.fair.price",
"param": {
"symbol": "BTC_USDT"
}
}

Sample data

{
"channel": "push.fair.price",
"data": {
"price": 0.001,
"symbol": "BTC_USDT"
},
"symbol": "BTC_USDT",
"ts": 1587442022003
}

Get the contract’s fair price; updates are pushed whenever there are changes.

Response fields:

FieldTypeDescription
symbolstringContract
pricedecimalPrice

Contract data

Subscribe

{ "method": "sub.contract" }

Unsubscribe

{ "method": "unsub.contract" }

Sample data

{
"channel": "push.contract",
"data": {
"amountScale": 4,
"askLimitPriceRate": 0.2,
"baseCoin": "CLO",
"baseCoinName": "CLO",
"bidLimitPriceRate": 0.2,
"conceptPlate": [],
"conceptPlateId": [],
"contractSize": 10,
"depthStepList": ["0.0001", "0.001", "0.01", "0.1"],
"displayName": "CLO_USDT永续",
"displayNameEn": "CLO_USDT PERPETUAL",
"feeRateMode": "NORMAL",
"futureType": 1,
"indexOrigin": ["MEXC_FUTURE", "MEXC", "KUCOIN"],
"initialMarginRate": 0.02,
"isHidden": false,
"isHot": false,
"isNew": false,
"liquidationFeeRate": 0.0002,
"limitMaxVol": 9000,
"maintenanceMarginRate": 0.01,
"makerFeeRate": 0,
"maxLeverage": 50,
"maxNumOrders": [200, 50],
"maxVol": 9000,
"minLeverage": 1,
"minVol": 1,
"openingCountdownOption": 1,
"openingTime": 1760440200000,
"positionOpenType": 3,
"priceCoefficientVariation": 0.4,
"priceScale": 4,
"priceUnit": 0.0001,
"quoteCoin": "USDT",
"quoteCoinName": "USDT",
"riskBaseVol": 9000,
"riskIncrImr": 0.005,
"riskIncrMmr": 0.005,
"riskIncrVol": 9000,
"riskLevelLimit": 1,
"riskLimitMode": "INCREASE",
"riskLimitType": "BY_VOLUME",
"riskLongShortSwitch": 0,
"settleCoin": "USDT",
"state": 0,
"symbol": "CLO_USDT",
"takerFeeRate": 0.0002,
"triggerProtect": 0.1,
"volScale": 0,
"volUnit": 1
},
"symbol": "CLO_USDT",
"ts": 1760942212002
}

Get contract data; updates are pushed whenever there are changes.

Response fields:

FieldTypeDescription
symbolstringContract, e.g., BTC_USDT
displayNamestringDisplay name, e.g., BTC_USDT 永续
displayNameEnstringDisplay English name, e.g., BTC_USDT PERPETUAL
positionOpenTypeintOpen mode: 1 both cross & isolated; 2 cross; 3 isolated
baseCoinstringBase currency (e.g., BTC)
quoteCoinstringQuote currency (e.g., USDT)
baseCoinNamestringBase currency name
quoteCoinNamestringQuote currency name
futureTypeint1 PERPETUAL, 2 DAILY
settleCoinstringSettlement currency
contractSizedecimalContract size
minLeverageintMin leverage
maxLeverageintMax leverage
priceScaleintPrice decimals
volScaleintVolume decimals
amountScaleintAmount decimals
priceUnitdecimalMin price tick
volUnitdecimalMin volume step
minVoldecimalMin order size (contracts)
maxVoldecimalMax order size (contracts)
limitMaxVoldecimalMax size for limit orders
bidLimitPriceRatedecimalOrder price limit—seller
askLimitPriceRatedecimalOrder price limit—buyer
takerFeeRatedecimalTaker fee
makerFeeRatedecimalMaker fee
maintenanceMarginRatedecimalMaintenance margin rate
initialMarginRatedecimalInitial margin rate
riskBaseVoldecimalBase contracts for risk limit
riskIncrVoldecimalIncremental contracts
riskIncrMmrdecimalMMR increment
riskIncrImrdecimalIMR increment
riskLevelLimitdecimalNumber of risk tiers
priceCoefficientVariationdecimalFair vs index price deviation coefficient
stateint0 enabled, 1 deliver, 2 delivered, 3 delist, 4 paused
isNewbooleanNew contract tag
isHotbooleanHot contract tag
isHiddenbooleanHidden contract
triggerProtectdecimalPrice protection threshold
riskLongShortSwitchintSeparate long/short risk limits (0 off, 1 on)
riskBaseVolLongdecimalLong base contracts
riskIncrVolLongdecimalLong incremental contracts
riskBaseVolShortdecimalShort base contracts
riskIncrVolShortdecimalShort incremental contracts
openingCountdownOptionintOpening countdown option 1 - Display opening time and countdown 2 - Display opening time only 3 - Hide both opening time and countdown
openingTimelongOpening timestamp
liquidationFeeRatedecimalLiquidation fee rate
tieredDealAmountdecimalTiered turnover amount
tieredEffectiveDayintEffective days
tieredExcludeZeroFeebooleanExclude zero-fee turnover? (false no, true yes)
tieredAppointContractbooleanSpecify contracts? (false no, true yes)
tieredExcludeContractIdbooleanInclude/exclude contracts (false exclude, true include)

Event contracts

Subscribe

{ "method": "sub.event.contract" }

Unsubscribe

{ "method": "unsub.event.contract" }

Get event contract data; updates are pushed whenever there are changes.

Response fields:

FieldTypeDescription
contractIdstringContract ID
symbolstringContract, e.g., BTC_USDT
baseCoinstringBase currency, e.g., BTC
quoteCoinstringQuote currency, e.g., USDT
baseCoinNamestringBase currency name
quoteCoinNamestringQuote currency name
settleCoinstringSettlement currency
baseCoinIconUrlstringBase currency
baseCoinNamestringBase currency icon config
investMinAmountdecimalMinimum investment
investMaxAmountdecimalMaximum investment
amountScaleintQuantity precision
payRateScaleintPayout rate precision
indexPriceScaleintIndex price precision
availableScaleintAvailability precision

Private channels

Signature method:

Concatenate api_key and req_time, then HMAC-SHA256 with sec_key. api_key and sec_key are your ACCESS KEY and SECRET KEY.

Signature string

"mx0aBYs33eIilxBW5C1657186536762"

Login authentication

Example

{
"method": "login",
"param": {
"token": "token", // web & app must provide token to complete auth
"apiKey": "apiKey", // for openapi; construct per openapi docs
"reqTime": "reqTime", // for openapi; construct per openapi docs
"signature": "signature" // for openapi; construct per openapi docs
}
}

Response:

Example

{ "channel": "rs.login", "data": "success", "ts": "1587442022003" }

Success: none. Failure: return error info, channel = rs.error.

On success: channel = rs.login.

Order

Sample

{
"channel": "push.personal.order",
"data": {
"orderId": 123456789,
"symbol": "BTC_USDT",
"positionId": 987654321,
"price": 45000.50,
"vol": 10,
"leverage": 20,
"side": 1,
"category": 1,
"orderType": 1,
"dealAvgPrice": 45000.00,
"dealVol": 5,
"orderMargin": 2250.00,
"usedMargin": 1125.00,
"takerFee": 0.1125,
"makerFee": 0.09,
"profit": 0,
"feeCurrency": "USDT",
"openType": 1,
"state": 2,
"errorCode": 0,
"externalOid": "ext_001",
"createTime": 1760942212000,
"updateTime": 1760942212000,
"remainVol": 5,
"positionMode": 1,
"reduceOnly": false,
"bboTypeNum": 0,
"makerFeeRate": 0.0002,
"takerFeeRate": 0.0004
},
"ts": 1760942212000
}

channel = push.personal.order

Response fields:

FieldTypeDescription
orderIdlongOrder ID
symbolstringContract
positionIdlongPosition ID
pricedecimalOrder price
voldecimalOrder quantity
leveragelongLeverage
sideint1 open long, 2 close short, 3 open short, 4 close long
categoryint1 limit, 2 forced liquidation custody, 3 custody close, 4 ADL
orderTypeint1 limit, 2 Post Only, 3 IOC, 4 FOK, 5 market, 6 market-to-limit
dealAvgPricedecimalAverage fill price
dealVoldecimalFilled quantity
orderMargindecimalOrder margin
usedMargindecimalUsed margin
takerFeedecimalTaker fee
makerFeedecimalMaker fee
profitdecimalClose PnL
feeCurrencystringFee currency
openTypeint1 isolated, 2 cross
stateint1 pending, 2 open, 3 filled, 4 canceled, 5 invalid
errorCodeintENUM:errorCode
externalOidstringExternal order ID
createTimelongCreate time
updateTimelongUpdate time
remainVoldecimalRemaining quantity
positionModeintPosition mode
reduceOnlybooleanReduce-only
bboTypeNumintBBO limit order subtype
makerFeeRatedecimalMaker fee rate
takerFeeRatedecimalTaker fee rate

Assets

Sample

{
"channel": "push.personal.asset",
"data": {
"currency": "USDT",
"positionMargin": 5000.0000,
"frozenBalance": 1000.0000,
"availableBalance": 9000.0000,
"bonus": 100.0000
},
"ts": 1760942212000
}

channel = push.personal.asset

Response fields:

FieldTypeDescription
currencystringCurrency
positionMargindecimalPosition margin
frozenBalancedecimalFrozen balance
availableBalancedecimalCurrently available balance
bonusdecimalTrial bonus

Position

Sample

{
"channel": "push.personal.position",
"data": {
"positionId": 123456789,
"symbol": "BTC_USDT",
"holdVol": 10,
"positionType": 1,
"openType": 1,
"state": 1,
"frozenVol": 0,
"closeVol": 0,
"holdAvgPrice": 45000.50,
"holdAvgPriceFullyScale": "45000.500000000000000000",
"closeAvgPrice": 0,
"openAvgPrice": 45000.50,
"openAvgPriceFullyScale": "45000.500000000000000000",
"liquidatePrice": 40000.00,
"oim": 2250.025,
"adlLevel": 1,
"im": 2250.025,
"holdFee": 0,
"realised": 0,
"leverage": 20,
"autoAddIm": false,
"pnl": 100.50,
"marginRatio": 0.2,
"newOpenAvgPrice": 45000.50,
"newCloseAvgPrice": 0,
"closeProfitLoss": 0,
"fee": 0,
"deductFeeList": [
{
"currency": "USDT",
"deductFee": 0.1125,
"convertSettleFee": 0.1125
}
],
"makerFeeRate": 0.0002,
"takerFeeRate": 0.0004,
"createTime": 1760942212000,
"updateTime": 1760942212000,
"version": 1
},
"ts": 1760942212000
}

channel = push.personal.position

Response fields:

FieldTypeDescription
positionIdlongPosition ID
symbolstringContract
holdVoldecimalPosition size
positionTypeint1 long, 2 short
openTypeint1 isolated, 2 cross
stateint1 holding, 2 system custody, 3 closed
frozenVoldecimalFrozen quantity
closeVoldecimalClosed quantity
holdAvgPricedecimalPosition average price
holdAvgPriceFullyScalestringFull-precision position avg price
closeAvgPricedecimalClose average price
openAvgPricedecimalOpen average price
openAvgPriceFullyScalestringFull-precision open avg price
liquidatePricedecimalLiquidation price (isolated)
oimdecimalOriginal initial margin
adlLevelintADL level
imdecimalInitial margin (adjustable in isolated to tune liq price)
holdFeedecimalFunding fee (positive received, negative paid)
realiseddecimalRealized PnL
leverageintLeverage
autoAddImbooleanAuto-add margin
pnldecimalUnrealized PnL
marginRatiodecimalMargin ratio
newOpenAvgPricedecimalOpen average price
newCloseAvgPricedecimalClose average price
closeProfitLossdecimalClose PnL
feedecimalFee
deductFeeListarrayDeduction info
makerFeeRatedecimalMaker fee rate
takerFeeRatedecimalTaker fee rate
createTimelongCreate time
updateTimelongUpdate time
versionlongVersion

Deduction info

Sample

{
"channel": "push.personal.plan.order",
"data": {
"currency": "USDT",
"deductFee": 0.1125,
"convertSettleFee": 0.1125
},
"ts": 1760942212000
}

channel = push.personal.position

Response fields:

FieldTypeDescription
currencystringDeduction currency
deductFeedecimalFee in deduction currency
convertSettleFeedecimalFee converted to settlement currency

Plan orders

Sample

{
"channel": "push.personal.plan.order",
"data": {
"id": 987654321,
"symbol": "BTC_USDT",
"leverage": 20,
"side": 1,
"triggerPrice": 46000.00,
"price": 45990.00,
"vol": 5,
"openType": 1,
"triggerType": 1,
"state": 1,
"executeCycle": 24,
"trend": 1,
"errorCode": 0,
"orderId": 0,
"orderType": 1,
"marketOrderLevel": 0,
"positionMode": 1,
"lossTrend": 1,
"profitTrend": 1,
"stopLossPrice": 44000.00,
"takeProfitPrice": 47000.00,
"reduceOnly": false,
"createTime": 1760942212000,
"updateTime": 1760942212000
},
"ts": 1760942212000
}

channel = push.personal.plan.order

Response fields:

FieldTypeDescription
idlongOrder ID
symbolstringContract
leverageintLeverage
sideint1 open long, 2 close short, 3 open short, 4 close long
triggerPricedecimalTrigger price
pricedecimalExecution price
voldecimalQuantity
openTypeint1 isolated, 2 cross
triggerTypeint1 ≥, 2 ≤
stateint1 untriggered, 2 canceled, 3 executed, 4 expired, 5 execution failed
executeCycleintExecution cycle (hours)
trendintReference price: 1 last, 2 fair, 3 index
errorCodeintENUM:errorCode
orderIdlongOrder ID after execution
orderTypeint1 limit, 2 Post Only, 3 IOC, 4 FOK, 5 market
marketOrderLevelintCustom level for market orders
positionModeint0 historical none, 2 one-way, 1 hedge
lossTrendintSL reference: 1 last, 2 fair, 3 index
profitTrendintTP reference: 1 last, 2 fair, 3 index
stopLossPricedecimalSL price
takeProfitPricedecimalTP price
reduceOnlybooleanReduce-only
createTimelongCreate time
updateTimelongUpdate time

Risk limit

Sample

{
"channel": "push.personal.risk.limit",
"data": {
"symbol": "BTC_USDT",
"positionType": 1,
"riskSource": 1,
"level": 2,
"maxVol": 500,
"maxLeverage": 50,
"mmr": 0.02,
"imr": 0.04,
"leverage": 20,
"openType": 1,
"limitBySys": true,
"maxVolView": 1000
},
"ts": 1760942212000
}

channel = push.personal.risk.limit

Response fields:

FieldTypeDescription
symbolstringContract
positionTypeint1 long, 2 short
riskSourceint0 other, 1 liquidation service
levelintCurrent risk tier
maxVoldecimalMax position size
maxLeverageintMax leverage
mmrdecimalMaintenance margin rate
imrdecimalInitial margin rate
leverageintCurrent leverage
openTypeintMargin mode, default isolated
limitBySysbooleanLimited by system
maxVolViewdecimalFront-end slider helper (independent of lev)

TP/SL plan orders

Sample

{
"channel": "push.personal.stop.planorder",
"data": {
"id": 987654321,
"orderId": 123456789,
"symbol": "BTC_USDT",
"positionId": 456789123,
"lossTrend": 1,
"profitTrend": 2,
"stopLossPrice": 42000.00,
"takeProfitPrice": 48000.00,
"state": 1,
"triggerSide": 1,
"positionType": 1,
"vol": 10,
"takeProfitVol": 10,
"stopLossVol": 10,
"realityVol": 10,
"placeOrderId": 987654321,
"version": 1,
"isFinished": 0,
"profitLossVolType": "SAME",
"volType": 1,
"takeProfitReverse": 2,
"stopLossReverse": 2,
"closeTryTimes": 0,
"reverseTryTimes": 0,
"reverseErrorCode": 0,
"stopLossType": 1,
"stopLossOrderPrice": 41990.00,
"createTime": 1760942212000,
"updateTime": 1760942212000
},
"ts": 1760942212000
}

channel = push.personal.stop.planorder

Response fields:

FieldTypeDescription
idlongPrimary ID
orderIdlongOrder ID
symbolstringContract
positionIdlongPosition ID
lossTrendintSL reference type
profitTrendintTP reference type
stopLossPricedecimalSL price
takeProfitPricedecimalTP price
stateintState
triggerSideintTrigger direction: 1 TP, 2 SL
positionTypeintPosition type
voldecimalQuantity
takeProfitVoldecimalTP quantity
stopLossVoldecimalSL quantity
realityVoldecimalActual placed quantity
placeOrderIdlongActual placed order ID
versionintVersion
isFinishedintCompleted
profitLossVolTypestringTP/SL qty type (SAME / SEPARATE)
volTypeint1 staged TP/SL, 2 position TP/SL
takeProfitReverseintTP reverse: 1 yes, 2 no
stopLossReverseintSL reverse: 1 yes, 2 no
closeTryTimesintClose retry count
reverseTryTimesintReverse retry count
reverseErrorCodeintReverse open error code (0 default)
stopLossTypeint0 market SL, 1 limit SL
stopLossOrderPricedecimalLimit SL price
createTimelongCreate time
updateTimelongUpdate time

Trailing orders

Sample

{
"channel": "push.personal.track.order",
"data": {
"id": 987654321,
"symbol": "BTC_USDT",
"leverage": 20,
"side": 1,
"vol": 50,
"openType": 1,
"trend": 1,
"activePrice": 45000.00,
"markPrice": 44950.00,
"backType": 1,
"backValue": 0.5,
"triggerPrice": 44750.00,
"triggerType": 2,
"orderId": 123456789,
"errorCode": 0,
"state": 1,
"positionMode": 2,
"reduceOnly": false,
"createTime": 1760942212000,
"updateTime": 1760942212000
},
"ts": 1760942212000
}

channel = push.personal.track.order

Response fields:

FieldTypeDescription
idlongPrimary ID
symbolstringContract
leverageintLeverage
sideint1 open long, 2 close short, 3 open short, 4 close long
voldecimalQuantity
openTypeint1 isolated, 2 cross
trendintReference price (1 last, 2 fair, 3 index)
activePricedecimalActivation price
markPricedecimalReference price after activation (highest/lowest)
backTypeintCallback type (1 percentage, 2 absolute)
backValuedecimalCallback value
triggerPricedecimalTrigger price (updates with reference)
triggerTypeintTrigger condition
orderIdlongOrder ID after triggering
errorCodeintENUM:errorCode
stateint0 not active, 1 active, 2 success, 3 failed, 4 canceled
positionModeintPosition mode
reduceOnlybooleanReduce-only
createTimelongCreate time
updateTimelongUpdate time

TP/SL prices

Sample

{
"channel": "push.personal.stop.order",
"data": {
"symbol": "BTC_USDT",
"orderId": 123456789,
"lossTrend": 1,
"profitTrend": 2,
"stopLossPrice": 42000.00,
"takeProfitPrice": 48000.00
},
"ts": 1760942212000
}

channel = push.personal.stop.order

Response fields:

FieldTypeDescription
symbolstringContract
orderIdlongOrder ID
lossTrendintSL reference type
profitTrendintTP reference type
stopLossPricedecimalSL price
takeProfitPricedecimalTP price

Fill details

Sample

{
"channel": "push.personal.order.deal",
"data": {
"id": 987654321,
"symbol": "BTC_USDT",
"side": 1,
"vol": 10,
"price": 45000.50,
"feeCurrency": "USDT",
"fee": 0.225,
"timestamp": 1760942212000,
"profit": 0,
"isTaker": true,
"category": 1,
"orderId": 123456789,
"isSelf": false,
"externalOid": "ext_001",
"positionMode": 1,
"reduceOnly": false,
"opponentUid": 987654321
},
"ts": 1760942212000
}

channel = push.personal.order.deal

Response fields:

FieldTypeDescription
idlongFill ID
symbolstringContract
sideint1 open long, 2 close short, 3 open short, 4 close long
voldecimalQuantity
pricedecimalPrice
feeCurrencystringFee currency
feedecimalOne-side fee (positive = paid by user, negative = received by user)
timestamplongFill time
profitdecimalPnL
isTakerbooleanTaker?
categoryintOrder category
orderIdlongOrder ID
isSelfbooleanSelf-trade?
externalOidstringExternal order ID
positionModeintPosition mode
reduceOnlybooleanReduce-only
opponentUidlongCounterparty UID

Chase order failure

Sample

{
"channel": "push.personal.order.chase",
"data": {
"ec": 1001,
"s": "BTC_USDT"
},
"ts": 1760942212000
}

channel = push.personal.order.chase

Response fields:

FieldTypeDescription
ecintError code
sstringContract

Liquidation risk change

Sample

{
"channel": "push.personal.liquidate.risk",
"data": {
"symbol": "BTC_USDT",
"positionId": 123456789,
"liquidatePrice": 35000.0,
"marginRatio": 0.1,
"adlLevel": 3
},
"ts": 1760942212000
}

channel = push.personal.liquidate.risk

Response fields:

FieldTypeDescription
symbolstringContract
positionIdlongPosition ID
liquidatePricedecimalLiq price
marginRatiodecimalMargin ratio
adlLevelintADL level

Leverage mode change

Sample

{
"channel": "push.personal.leverage.mode",
"data": {
"lm": 1
},
"ts": 1760942212000
}

channel = push.personal.leverage.mode

Response fields:

FieldTypeDescription
lmintLeverage mode

Position mode change

Sample

{
"channel": "push.personal.position.mode",
"data": {
"positionMode": 2
},
"ts": 1760942212000
}

channel = push.personal.position.mode

Response fields:

FieldTypeDescription
positionModeintPosition mode (1 hedge, 2 one-way)

Close-all failure

channel = push.personal.position.closeall.fail

Response: No body; channel message only.

Reverse position

Sample

{
"channel": "push.personal.reverse.position",
"data": {
"contractId": 1,
"positionId": 123456789,
"state": 2,
"errorCode": 0
},
"ts": 1760942212000
}

channel = push.personal.reverse.position

Response fields:

FieldTypeDescription
contractIdintContract ID
positionIdlongPosition ID
stateintState
errorCodeintENUM:errorCode

Trial bonus notification

Sample

{
"channel": "push.personal.bonus",
"data": {
"c": "USDT",
"b": 100.0000,
"be": 1763539200000,
"g": true,
"ret": 1763539200000,
"rea": 100.0000
},
"ts": 1760942212000
}

channel = push.personal.bonus

Response fields:

FieldTypeDescription
cstringCurrency
bdecimalTrial bonus amount
belongTrial bonus expiry time
gbooleanWhether trial bonus granted
retlongMost recent expiry time
readecimalMost recent expiring amount

User notifications — liquidation warning/notice

Sample

{
"channel": "push.personal.generic.notify",
"data": {
"type": 1,
"param": {
"notifyType": 2,
"openType": 1,
"dn": "BTC_USDT永续",
"dne": "BTC_USDT PERPETUAL",
"multiAssets": false,
"marginRate": 0.085
}
},
"ts": 1760942212000
}

channel = push.personal.generic.notify

Response fields:

FieldTypeDescription
typeintNotification type (1 liquidation)
paramobjectNotification parameters

Notification params (for liquidation types)

FieldTypeDescription
notifyTypeint1 liquidation, 2 liquidation warning
openTypeint1 isolated, 2 cross
dnstringDisplay name
dnestringDisplay name (EN)
multiAssetsbooleanMulti-asset mode enabled?
marginRatedecimalMargin ratio

Event contract positions

Sample

{
"channel": "push.personal.event.contract.position",
"data": {
"positionId": 123456789,
"symbol": "BTC_USDT",
"side": "1",
"payRate": 0.15,
"amount": 1000.0000,
"openPrice": 45000.50,
"closePrice": 46250.75,
"rewardAmount": 25.5000,
"rewardAmountUsdt": 25.5000,
"state": "3",
"closeResult": "PROFIT",
"createTime": 1760942212000,
"closeTime": 1760945812000,
"pnlAmount": 125.25
},
"ts": 1760945812000
}

channel = push.personal.event.contract.position

Response fields:

FieldTypeDescription
positionIdlongPosition ID
symbolstringContract
sidestringSide
payRatedecimalBonus pay rate
amountdecimalOrder amount
openPricedecimalOpen price
closePricedecimalClose price
rewardAmountdecimalReward amount
rewardAmountUsdtdecimalReward amount in USDT
statestringState
closeResultstringClose result
createTimelongCreate time
closeTimelongClose time
pnlAmountdecimalTotal PnL

Incremental Order Book Maintenance Mechanism

  1. Obtain the full depth snapshot Request via REST API:
    GET https://contract.mexc.com/api/v1/contract/depth/{symbol}
    Example: BTC_USDT
    Retrieve the complete depth snapshot and record the returned version as the initial version.

  2. Subscribe to WebSocket incremental depth updates Subscribe to depth update events. For the same price level, if multiple updates are received, the update with the higher version should overwrite the one with the lower version.

  3. Retrieve Depth Commit snapshots
    Periodically or during initialization, obtain the most recent N depth commit snapshots (e.g., the latest 1000 records) via:
    GET https://contract.mexc.com/api/v1/contract/depth_commits/{symbol}/{limit}
    Example: BTC_USDT/1000

  4. Remove outdated local cache data
    If the version of a price level in the local cache is lower than the corresponding version in the Commit snapshot, the cached data should be discarded.

  5. Merge Commit snapshots into the local order book
    Apply the Commit snapshot data to the local order book, then continue processing WebSocket events sequentially from the latest point.

  6. Ensure version continuity
    Each WebSocket incremental event must satisfy:
    new_event.version == previous_event.version + 1
    If the version is not continuous (e.g., a gap is detected), it indicates a potential packet loss. The client must return to Step 3 to reload Commit snapshots and resynchronize.

  7. When the snapshot’s version falls within the [fromVersion, toVersion] range of the push message, the push message can be integrated with the snapshot as follows:

    • If the price level in the push message already exists in the snapshot, update the quantity based on the push message.
    • If the price level in the push message does not exist in the snapshot, insert the new price level with the quantity provided.
    • If any price level in the push message has a quantity of 0, remove that price level from the snapshot.
  8. Quantity represents an absolute value
    The quantity in each event represents the absolute order size at the given price level, not a delta.

  9. Handling price levels with a quantity of 0
    When a price level has a quantity of 0, it indicates that the level has been fully executed or canceled and should be removed from the local order book.

ENUM definitions

errorCode

  • 0 NORMAL
  • 1 PARAM_INVALID
  • 2 INSUFFICIENT_BALANCE
  • 3 POSITION_NOT_EXISTS
  • 4 POSITION_NOT_ENOUGH
  • 5 POSITION_LIQ
  • 6 ORDER_LIQ
  • 7 RISK_LEVEL_LIMIT
  • 8 SYS_CANCEL
  • 9 POSITION_MODE_NOT_MATCH
  • 10 REDUCE_ONLY_LIQ
  • 11 CONTRACT_NOT_ENABLE
  • 12 DELIVERY_CANCEL
  • 13 POSITION_LIQ_CANCEL
  • 14 ADL_CANCEL
  • 15 BLACK_USER_CANCEL
  • 16 SETTLE_FUNDING_CANCEL
  • 17 POSITION_IM_CHANGE_CANCEL
  • 18 IOC_CANCEL
  • 19 FOK_CANCEL
  • 20 POST_ONLY_CANCEL
  • 21 MARKET_CANCEL
  • 22 OID_DUPLICATE
  • 23 CID_DUPLICATE
  • 999 OTHER