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
}

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"
}

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
}

Pushes once whenever the index price 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
}

Response fields:

FieldTypeDescription
symbolstringContract
pricedecimalPrice

Contract metadata

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
}

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
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" }

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

{ "channel": "rs.login", "data": "success", "ts": "1587442022003" }
{
"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:

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

On success: channel = rs.login.

Order

Sample

{
"channel": "push.personal.order",
"data": {
"category": 1,
"createTime": 1610005069976,
"dealAvgPrice": 0.731,
"dealVol": 1,
"errorCode": 0,
"externalOid": "_m_95bc2b72d3784bce8f9efecbdef9fe35",
"feeCurrency": "USDT",
"leverage": 0,
"makerFee": 0,
"openType": 1,
"orderId": "102067003631907840",
"orderMargin": 0,
"orderType": 5,
"positionId": 1397818,
"price": 0.707,
"profit": -0.0005,
"remainVol": 0,
"side": 4,
"state": 3,
"symbol": "CRV_USDT",
"takerFee": 0.00004386,
"updateTime": 1610005069983,
"usedMargin": 0,
"version": 2,
"vol": 1
},
"ts": 1610005069989
}

Request: 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
errorCodeint
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": {
"availableBalance": 0.7514236,
"bonus": 0,
"currency": "USDT",
"frozenBalance": 0,
"positionMargin": 0
},
"ts": 1610005070083
}

Request: channel = push.personal.asset

Response fields:

FieldTypeDescription
currencystringCurrency
positionMargindecimalPosition margin
frozenBalancedecimalFrozen balance
availableBalancedecimalCurrently available balance
bonusdecimalTrial bonus

Position

Sample

{
"channel": "push.personal.position",
"data": {
"autoAddIm": false,
"closeAvgPrice": 0.731,
"closeVol": 1,
"frozenVol": 0,
"holdAvgPrice": 0.736,
"holdFee": 0,
"holdVol": 0,
"im": 0,
"leverage": 15,
"liquidatePrice": 0,
"oim": 0,
"openAvgPrice": 0.736,
"openType": 1,
"positionId": 1397818,
"positionType": 1,
"realised": -0.0005,
"state": 3,
"symbol": "CRV_USDT"
},
"ts": 1610005070157
}

Request: 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

Request: none

Response fields:

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

Plan orders

Request: 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
errorCodeint0 if normal
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

Request: 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

Request: 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

Request: 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
errorCodeintError code if trigger failed
stateint0 not active, 1 active, 2 success, 3 failed, 4 canceled
positionModeintPosition mode
reduceOnlybooleanReduce-only
createTimelongCreate time
updateTimelongUpdate time

TP/SL prices

Request: channel = push.personal.stop.order

Response fields:

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

Fill details

Request: 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

Request: channel = push.personal.order.chase

Response fields:

FieldTypeDescription
ecintError code
sstringContract

Liquidation risk change

Request: channel = push.personal.liquidate.risk

Response fields:

FieldTypeDescription
symbolstringContract
positionIdlongPosition ID
liquidatePricedecimalLiq price
marginRatiodecimalMargin ratio
adlLevelintADL level

Leverage mode change

Request: channel = push.personal.leverage.mode

Response fields:

FieldTypeDescription
lmintLeverage mode

Position mode change

Request: channel = push.personal.position.mode

Response fields:

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

Close-all failure

Request: channel = push.personal.position.closeall.fail

Response: No body; channel message only.

Reverse position

Request: channel = push.personal.reverse.position

Response fields:

FieldTypeDescription
contractIdintContract ID
positionIdlongPosition ID
stateintState
errorCodeintError code

Trial bonus notification

Request: 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

Request: 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

Request: 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

How to maintain depth

Example: subscribe to trades

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

Subscription success

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

Subscription failure

{
"channel": "rs.error",
"data": "Contract does not exist!",
"ts": "1587442022003"
}

Position mode

Sample

{
"channel": "push.personal.position.mode",
"data": {
"positionMode": 1
},
"ts": 1610005070157
}

Request: channel = push.personal.position.mode

Response fields:

FieldTypeDescription
positionModeintPosition mode, 1 hedge, 2 one-way

How to maintain incremental depth:

  1. Fetch full depth via https://contract.mexc.com/api/v1/contract/depth/BTC_USDT and store the current version.
  2. Subscribe to WS depth updates. Upon receiving an update with version > current version, for the same price level, the later update overwrites the earlier one.
  3. Fetch the latest 1000 depth snapshots via https://contract.mexc.com/api/v1/contract/depth_commits/BTC_USDT/1000.
  4. In your cached depth, discard entries at the same price where version < the snapshot’s versions.
  5. Apply the snapshot to your local cache, then continue processing WS events from there.
  6. Each new event’s version must equal the previous event’s version + 1. If versions are not continuous or packets were lost, re-initialize from step 3.
  7. The quantity in each event is the absolute order size at that price, not a delta.
  8. A quantity of zero at a price means that level should be removed.

On successful subscription events:

channel will be rs. + the subscribed method, and data will be "success".