From 906fddc9060df13ab0391565fa828031ceea638f Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Mon, 11 Dec 2023 19:20:25 +0800 Subject: [PATCH 01/35] Update index.html.md --- source/index.html.md | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/source/index.html.md b/source/index.html.md index 49d0a1b..64819b4 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -70,6 +70,10 @@ To apply for a partnership, please contact: **broker@mexc.com** # Change Log +## **2023-12-11** + +- Query Sub-account List endpoint add response params:uid + ## **2023-11-10** - Add user internal transfer endpoint and query internal transfer history endpoint. @@ -1283,12 +1287,14 @@ Get details of the sub-account list { "subAccount":"mexc666", "isFreeze":false, - "createTime":1544433328000 + "createTime":1544433328000, + "uid": "49910511" }, { "subAccount":"mexc888", "isFreeze":false, - "createTime":1544433328000 + "createTime":1544433328000, + "uid": "91921059" } ] } @@ -1311,6 +1317,16 @@ Parameters: | timestamp | LONG | YES | | | recvWindow | LONG | NO | | +Response: + +| Name | Description | +| -------- | ----------------- | +| subAccount | subAccount name | +| isFreeze | isFreeze | +| createTime | createTime | +| uid | subaccount uid | + + From d87069e8d2cbc52de4eff06d54a895ee49e2d68d Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Mon, 8 Jan 2024 14:26:46 +0800 Subject: [PATCH 02/35] Update index.html.md --- source/index.html.md | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/source/index.html.md b/source/index.html.md index 64819b4..f6158c6 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -70,6 +70,11 @@ To apply for a partnership, please contact: **broker@mexc.com** # Change Log +## **2024-01-01** + +- Kline support interval: week +- Deposit and withdraw history endpoint update the query timestamp range + ## **2023-12-11** - Query Sub-account List endpoint add response params:uid @@ -2612,13 +2617,15 @@ Parameters: | :------ | :-------- | :-------- | :---------- | |coin|string|NO|coin | |status|string|NO|status| -|startTime|string|NO|default: 30 days ago from current time| +|startTime|string|NO|default: 7 days ago from current time| |endTime|string|NO|default:current time| |limit|string|NO|default:1000,max:1000| |timestamp|string|YES|timestamp| |signature|string|YES|signature| -Ensure that the default timestamp of 'startTime' and 'endTime' does not exceed 30 days. +1. default return the records of the last 7 days. +2. Ensure that the default timestamp of 'startTime' and 'endTime' does not exceed 7 days. +3. can query 90 days data at most. Response: @@ -2679,13 +2686,16 @@ Parameters: |coin|string|NO|coin | |status|string|NO|withdraw status| |limit|string|NO|default:1000, max:1000| -|startTime|string|NO|default: 30 days ago from current time| +|startTime|string|NO|default: 7 days ago from current time| |endTime|string|NO|default:current time| |timestamp|string|YES|timestamp| |signature|string|YES|signature| -1. Supported multiple network coins' withdraw history may not return the 'network' field. -2. Ensure that the default timestamp of 'startTime' and 'endTime' does not exceed 30 days. +1. default return the records of the last 7 days. +2. Ensure that the default timestamp of 'startTime' and 'endTime' does not exceed 7 days. +3. can query 90 days data at most. +4. Supported multiple network coins's withdraw history may not return the 'network' field. + Response: @@ -5004,6 +5014,7 @@ If startTime and endTime are not sent, the data from T-7 to T is returned. - 60m 60 minute - 4h 4 hour - 1d 1 day +- 1w 1 week - 1M 1 month ### changed type From 80c9eec49bd155a6d2b1cafd7cb78190f6e811dd Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Wed, 10 Jan 2024 15:22:15 +0800 Subject: [PATCH 03/35] Update build.yml --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a9282d8..ba682bd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: - ruby-version: [2.6, 2.7, 3.0] + ruby-version: [3.1] steps: - uses: actions/checkout@v2 From b957959adddbdbee97938d108fd0ecfaca086030 Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Wed, 17 Jan 2024 11:18:37 +0800 Subject: [PATCH 04/35] Update index.html.md --- source/index.html.md | 58 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/source/index.html.md b/source/index.html.md index f6158c6..b159ee9 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -70,6 +70,10 @@ To apply for a partnership, please contact: **broker@mexc.com** # Change Log +## **2024-01-12** + +- Add query sub-account asset endpoint + ## **2024-01-01** - Kline support interval: week @@ -1547,6 +1551,60 @@ get /api/v3/capital/sub-account/universalTransfer |timestamp|number|timestamp| |totalCount|number|total transfer| +## Query Sub-account Asset + +> request + +``` +get /api/v3/sub-account/asset?subAccount=account1&accountType=SPOT×tamp={{timestamp}}&signature={{signature}} +``` +> response + +```json +{ + "balances": [ + { + "asset": "MX", + "free": "3", + "locked": "0" + }, + { + "asset": "BTC", + "free": "0.0003", + "locked": "0" + } + ] +} +``` + +- **GET** ```/api/v3/sub-account/asset``` + +**Permission:** SPOT_TRANSFER_READ + +**Weight(IP):** 1 + +**request** + +| Name | Type| Mandatory | Description | +| :------ | :-------- | :-------- | :---------- | +| subAccount | string | Yes | subAccount name,only support query for single subaccount| +| accountType|string|Yes|account type:"SPOT","FUTURES",only support SPOT currently| +| timestamp|string|Yes|timestamp| +| signature|string|Yes|signature| + + +**response** + +| Name |Type | Description| +| :------------ | :-------- | :--------| +|balances|string|balance| +|asset|string|asset| +|free|string|free| +|locked|string|locked| + + + + ## Query Internal Transfer history From 5f853508554791f271e1f5dde91578aede2b410a Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Mon, 8 Apr 2024 17:07:35 +0800 Subject: [PATCH 08/35] Update index.html.md --- source/index.html.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/source/index.html.md b/source/index.html.md index 878df32..b4a4553 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -70,6 +70,10 @@ To apply for a partnership, please contact: **broker@mexc.com** # Change Log +## **2024-04-04** + +- Update response params of Get Withdraw History endpoint + ## **2024-01-12** - Add query sub-account asset endpoint @@ -2716,7 +2720,11 @@ get /api/v3/capital/withdraw/history?coin=USDT×tamp={{timestamp}}&signature "confirmNo": null, "applyTime": 1665300874000, "remark": "", - "memo": "MX10086" + "memo": "MX10086", + "transHash": "0x0ced593b8b5adc9f600334d0d7335456a7ed772ea5547beda7ffc4f33a065c", + "updateTime": 1712134082000, + "coinId": "128f589271cb495b03e71e6323eb7be", + "vcoinId": "af42c6414b9a46c8869ce30fd51660f" } ] ``` @@ -2764,6 +2772,11 @@ Response: |confirmNo| confirmNo| |txId|txId| |remark|remark| +|memo|memo| +|transHash|transaction Hash| +|coinId|asset id| +|vcoinId|currency id| + ## Generate deposit address (supporting network) From 009193a61f884eb7016eeca03c49d01e49b4b249 Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Mon, 8 Apr 2024 17:12:04 +0800 Subject: [PATCH 09/35] Update index.html.md --- source/index.html.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/index.html.md b/source/index.html.md index b4a4553..fd08759 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -70,7 +70,7 @@ To apply for a partnership, please contact: **broker@mexc.com** # Change Log -## **2024-04-04** +## **2024-04-08** - Update response params of Get Withdraw History endpoint From 2e59c41089a78177465ca5b2cbacaeaddecf347c Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Mon, 27 May 2024 19:52:12 +0800 Subject: [PATCH 10/35] Update index.html.md --- source/index.html.md | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/source/index.html.md b/source/index.html.md index fd08759..dbf39cf 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -70,6 +70,9 @@ To apply for a partnership, please contact: **broker@mexc.com** # Change Log +## **2024-05-15** +- Add query commission endpoint + ## **2024-04-08** - Update response params of Get Withdraw History endpoint @@ -2467,6 +2470,53 @@ get api/v3/mxDeduct/enable | :------------ | :-------- | :--------| |mxDeductEnable|boolean|true:enable,false:disable| +## Query Symbol Commission + +> request + +``` +get api/v3/tradeFee?symbol=MXUSDT×tamp={{timestamp}}&signature={{signature}} +``` +> return + +```json +{ + "data":{ + "makerCommission":0.003000000000000000, + "takerCommission":0.003000000000000000 + }, + "code":0, + "msg":"success", + "timestamp":1669109672717 +} +``` +**HTTP请求** + +- **GET** ```api/v3/tradeFee``` + +**Permission:** SPOT_ACCOUNT_READ + +**Weight(IP):** 20 + +**request** + +| Name | Type| Mandatory | Description | +| :------ | :-------- | :-------- | :---------- | +|symbol|string|yes|symbol| +|recvWindow|long|no|recvWindow| +|timestamp|long|yes|timestamp| +|signature|string|yes|signature| + + +**return** + +| Name | Type | Description| +| :------------ | :-------- | :--------| +|makerCommission|long|User Maker Commission| +|takerCommission|long|User Taker Commission| + + + # Wallet Endpoints ## Query the currency information From f3c5e4d41fc298162b2ea67e8b297310d1d00616 Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Sun, 9 Jun 2024 12:58:17 +0800 Subject: [PATCH 11/35] Update index.html.md --- source/index.html.md | 77 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 12 deletions(-) diff --git a/source/index.html.md b/source/index.html.md index dbf39cf..62c80c6 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -70,6 +70,10 @@ To apply for a partnership, please contact: **broker@mexc.com** # Change Log +## **2024-06-09** +- Query The Currency Information endpoint add params:netWork,network will offline soon. +- Add new withdraw endpoint,previous withdraw endpoint will offline soon. + ## **2024-05-15** - Add query commission endpoint @@ -2549,7 +2553,8 @@ Get /api/v3/capital/config/getall "sameAddress": false, "contract": "TN3W4H6rK2ce4vX9YnFQHwKENnHjoxbm9", "withdrawTips": "Both a MEMO and an Address are required.", - "depositTips": "Both a MEMO and an Address are required." + "depositTips": "Both a MEMO and an Address are required.", + "netWork": "EOS" }, { "coin": "BTC", @@ -2566,7 +2571,8 @@ Get /api/v3/capital/config/getall "sameAddress": false, "contract": "0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c", "withdrawTips": null, - "depositTips": null + "depositTips": null, + "network": "BTC" } ] }, @@ -2592,7 +2598,6 @@ Response: | Name | Description | | :------------ | :-------- | |depositEnable|depositEnable| -|network|withdraw network| |withdrawEnable|withdrawEnable| |withdrawFee|withdrawFee| |withdrawMax|Max withdraw amount| @@ -2600,26 +2605,26 @@ Response: |contract|coin contract| |withdrawTips|withdrawTips| |depositTips|depositTips| +|network|withdraw network(previous params,offline soon)| +|netWork|withdraw network(new params,for new withdraw endpoint)| -## Withdraw +## Withdraw(new) > Request ``` -post /api/v3/capital/withdraw/apply?coin=EOS&address=zzqqqqqqqqqq&amount=10&network=EOS&memo=MX10086×tamp={{timestamp}}&signature={{signature}} +post /api/v3/capital/withdraw?coin=EOS&address=zzqqqqqqqqqq&amount=10&network=EOS&memo=MX10086×tamp={{timestamp}}&signature={{signature}} ``` > Response ```json -[ - { +{ "id":"7213fea8e94b4a5593d507237e5a555b" - } -] +} ``` -- **POST** ```/api/v3/capital/withdraw/apply``` +- **POST** ```/api/v3/capital/withdraw``` **Permission:** SPOT_WITHDRAW_WRITE @@ -2631,7 +2636,8 @@ Parameters: | :------ | :-------- |:----------|:---------------------------------------------------------------| |coin|string| YES | coin | |withdrawOrderId|string| NO | withdrawOrderId | -|network|string| NO | withdraw network | +|netWork|string| NO | withdraw network | +|contractAddress|string| NO | coin contract address | |address|string| YES | withdraw address | |memo|string| NO | memo(If memo is required in the address, it must be passed in) | |amount|string| YES | withdraw amount | @@ -2639,7 +2645,7 @@ Parameters: |timestamp|string| YES | timestamp | |signature|string| YES | signature | -Can get `network` via endpoints `Get /api/v3/capital/config/getall`'s response params `networkList`. +Can get `netWork` via endpoints `Get /api/v3/capital/config/getall`'s response params `networkList`. Response: @@ -3485,6 +3491,53 @@ If startTime and endTime are not provided, will default to returning data from t |status |status| |timestamp |timestamp| +## Withdraw(previous,offline soon) + +> Request + +``` +post /api/v3/capital/withdraw/apply?coin=EOS&address=zzqqqqqqqqqq&amount=10&network=EOS&memo=MX10086×tamp={{timestamp}}&signature={{signature}} +``` +> Response + +```json +[ + { + "id":"7213fea8e94b4a5593d507237e5a555b" + } +] +``` + + +- **POST** ```/api/v3/capital/withdraw/apply``` + +**Permission:** SPOT_WITHDRAW_WRITE + +**Weight(IP):** 1 + +Parameters: + +| Name | Type| Mandatory | Description | +| :------ | :-------- |:----------|:---------------------------------------------------------------| +|coin|string| YES | coin | +|withdrawOrderId|string| NO | withdrawOrderId | +|network|string| NO | withdraw network | +|address|string| YES | withdraw address | +|memo|string| NO | memo(If memo is required in the address, it must be passed in) | +|amount|string| YES | withdraw amount | +|remark|string| NO | remark | +|timestamp|string| YES | timestamp | +|signature|string| YES | signature | + +Can get `network` via endpoints `Get /api/v3/capital/config/getall`'s response params `networkList`. + +Response: + +| Name | Description | +| :------------ | :-------- | +|id|withdraw ID| + + # ETF ## Get ETF info From 6b4f0ac0d7bb30e328d65c455dcfe16338d6c2bc Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Tue, 9 Jul 2024 17:01:18 +0800 Subject: [PATCH 12/35] Update index.html.md --- source/index.html.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/index.html.md b/source/index.html.md index 62c80c6..8289da5 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -2363,7 +2363,7 @@ Parameters: | orderId | string | NO | order Id | | startTime | long | NO | | | endTime | long | NO | | -| limit | int | NO | Default 500; max 1000; | +| limit | int | NO | Default 100; max 100; | | recvWindow | long | NO | | | timestamp | long | YES | | From e2bebeed3653c47214ca6ecf798c94a76be5503b Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Mon, 22 Jul 2024 23:34:04 +0800 Subject: [PATCH 13/35] Update index.html.md --- source/index.html.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/index.html.md b/source/index.html.md index 8289da5..badab54 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -1836,7 +1836,7 @@ Additional mandatory parameters based on `type`: Other info: -MARKET: When type is market, if it is a buy order, `quoteOrderQty` is a required. If it is a sell order, `quantity` is a required. +MARKET: When type is market, `quoteOrderQty` or `quantity` required to choose anyone. - `MARKET` orders using the `quantity` field specifies the amount of the `base asset` the user wants to sell at the market price - For example, sending a `MARKET` order on BTCUSDT will specify how much BTC the user is selling. @@ -4883,7 +4883,7 @@ get /api/v3/rebate/affiliate/commission/detail?timestamp={{timestamp}}&signature If startTime and endTime are not sent, the data from T-7 to T is returned. If type is not sent, the data of all types is returned,maximum 30 days data can be queried at one time. - +If startTime and endTime are not sent, the data from T-7 to T is returned. ## Get Affiliate Referral Data(affiliate only) From ffa4dd25dea416780dc7c81c379508066bf20b46 Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Fri, 16 Aug 2024 14:55:02 +0800 Subject: [PATCH 14/35] Update index.html.md --- source/index.html.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/source/index.html.md b/source/index.html.md index badab54..79b6bb7 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -70,6 +70,9 @@ To apply for a partnership, please contact: **broker@mexc.com** # Change Log +## **2024-08-16** +- Exchange Information endpoint update params:status and tradeSideType. + ## **2024-06-09** - Query The Currency Information endpoint add params:netWork,network will offline soon. - Add new withdraw endpoint,previous withdraw endpoint will offline soon. @@ -526,8 +529,8 @@ The account is used as the basic unit of speed limit for the endpoints that need - According to the two modes of IP and UID (account) limit, each are independent. - Endpoints are marked according to IP or UID limit and their corresponding weight value. -- Each endpoint with IP limits has an independent 20000 per minute limit. -- Each endpoint with UID limits has an independent 240000 per minute limit. +- Each endpoint with IP limits has an independent 500 every 10 second limit. +- Each endpoint with UID limits has an independent 500 every 10 second limit. ### Limits Error @@ -754,7 +757,8 @@ NONE "filters": [], "maxQuoteAmount": "5000000", "makerCommission": "0.002", - "takerCommission": "0.002" + "takerCommission": "0.002", + "tradeSideType":"1" } ``` @@ -784,7 +788,7 @@ There are 3 possible options: | rateLimits | Array | rate Limits | | exchangeFilters | Array | exchange Filters | | symbol | String | symbol | -| status | String | status | +| status | String | status:1 - online, 2 - Pause, 3 - offline | | baseAsset | String | base Asset | | baseAssetPrecision | Int | base Asset Precision | | quoteAsset | String | quote Asset | @@ -804,6 +808,8 @@ There are 3 possible options: | baseSizePrecision|string| min order quantity | | quoteAmountPrecisionMarket |string| min order amount in market order | | maxQuoteAmountMarket | String | max quote Amount in market order | +| tradeSideType | String | tradeSide Type:1 - All, 2 - buy order only, 3 - Sell order only, 4 - Close | + From 8c7352ed04ebe289fc31262c5f44a650adc12fd5 Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Wed, 9 Oct 2024 18:07:05 +0800 Subject: [PATCH 15/35] Update index.html.md --- source/index.html.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/index.html.md b/source/index.html.md index 79b6bb7..aee42bf 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -3380,7 +3380,7 @@ Response: |totalRecords|int|totalRecords| |totalPage|int|totalPage| - + ## Query Internal Transfer history From 1f976ca82c777abafbc803c9d185127bca79d1a1 Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Thu, 17 Oct 2024 18:34:41 +0800 Subject: [PATCH 16/35] Update index.html.md --- source/index.html.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/source/index.html.md b/source/index.html.md index aee42bf..101caf6 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -70,6 +70,9 @@ To apply for a partnership, please contact: **broker@mexc.com** # Change Log +## **2024-10-17** +- Add Query Kyc status endpoint + ## **2024-08-16** - Exchange Information endpoint update params:status and tradeSideType. @@ -1713,6 +1716,42 @@ post /api/v3/sub-account/margin # Spot Account/Trade +## Query KYC status + +> request + +``` +GET /api/v3/kyc/status?timestamp={{timestamp}}&signature={{signature}} +``` + +> response + +```json +{ +"status": "1" +} +``` + +**GET** ```/api/v3/kyc/status ``` + +**Permission:** SPOT_ACCOUNT_READ + +**Weight(IP):** 1 + +**Request** + +| Name | Type | Mandatory | Description | +| :---------- | :-------- | :-------- | :-------------------- | +|timestamp |string |Yes | timestamp | +|signature |string |Yes |signature | + +**Response** + +| Name | Type | Description | +| :------------ | :-------- |:-------------------------| +| status | string | 1:Unverified 2:Primary kyc 3:Advanced kyc 4:Institutional kyc | + + ## User API default symbol > Request From eab48cb94073b3ae4108e24cc96d8481a891454b Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Mon, 23 Dec 2024 04:19:38 +0800 Subject: [PATCH 17/35] Update index.html.md --- source/index.html.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/index.html.md b/source/index.html.md index 101caf6..20129a9 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -1892,7 +1892,7 @@ MARKET: When type is market, `quoteOrderQty` or `quantity` required to choose a ## Batch Orders -Supports 20 orders with a same symbol in a batch,rate limit:2 times/s. +Supports 30 orders with a same symbol in a batch,rate limit:2 times/s. > Request @@ -1950,7 +1950,7 @@ Parameters: | Name | type | Mandatory | Description | | :--------------- | :------ | :------- |:-------------------------------------------| -| batchOrders | LIST | YES | list of batchOrders,supports max 20 orders | +| batchOrders | LIST | YES | list of batchOrders,supports max 30 orders | | symbol | STRING | YES | symbol | | side | ENUM | YES | order side | | type | ENUM | YES | order type | @@ -3583,7 +3583,7 @@ Response: |id|withdraw ID| -# ETF + # Websocket Market Streams From 13ba5e260f5911aa926cd44d928d940c07c6bf3d Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Mon, 23 Dec 2024 04:20:52 +0800 Subject: [PATCH 18/35] Update index.html.md --- source/index.html.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/index.html.md b/source/index.html.md index 20129a9..69a96ae 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -58,7 +58,7 @@ This includes copy trade platforms, trading bots, quantitative strategy platform This includes wallet platforms, market data platforms, aggregation trading platforms, stockbrokers, as well as stock and securities trading platforms, etc., all of which have their own independent users. MEXC can provide order matching systems, account management systems, settlement systems, as well as main and sub-account systems, etc. Independent brokers can share the trading fluidity and depth over the MEXC platform and receive profit shares from fees. -To apply for a partnership, please contact: **broker@mexc.com** +To apply for a partnership, please contact: **institution@mexc.com** ## Contact us From 6ff193e35183f081a42fb758cc64b324a4f14f5d Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Thu, 9 Jan 2025 02:14:38 +0800 Subject: [PATCH 19/35] Update layout.erb --- source/layouts/layout.erb | 1 - 1 file changed, 1 deletion(-) diff --git a/source/layouts/layout.erb b/source/layouts/layout.erb index c49b29d..8e286d6 100644 --- a/source/layouts/layout.erb +++ b/source/layouts/layout.erb @@ -149,7 +149,6 @@ under the License. $(function(){ const menuObj = [ ['spot_v3', 'SpotV3', 'spot_v3_en', '现货V3' ,'spot_v3_cn'], - ['spot_v2', 'SpotV2', 'spot_v2_en', '现货V2' ,'spot_v2_cn'], ['contract_v1', 'Futures', 'contract_v1_en', '合约' ,'contract_v1_cn'], ['broker','Broker','broker_en','经纪商','broker_cn'] ]; From 2c9e769ffb5977c1e4919646d5c0fdd19ec1d567 Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Mon, 24 Feb 2025 18:44:47 +0800 Subject: [PATCH 20/35] Update index.html.md --- source/index.html.md | 1114 +++++++++++++++++++++++------------------- 1 file changed, 600 insertions(+), 514 deletions(-) diff --git a/source/index.html.md b/source/index.html.md index 69a96ae..42b4323 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -3633,185 +3633,283 @@ Response: # Websocket Market Streams -- The base endpoint is: **wss://wbs.mexc.com/ws**. +- The base endpoint is: **ws://[wbs-api.mexc.com/ws](http://wbs-api.mexc.com/ws)** +- Each connection to **wbs.mexc.com** is valid for no more than 24 hours. Please handle disconnections and reconnections properly. +- All trading pair names in the symbol must be in **uppercase**. For example: `spot@public.deals.v3.api.pb@` + Example: `spot@public.deals.v3.api.pb@BTCUSDT` +- If there is no valid subscription on the websocket, the server will actively disconnect after **30 seconds**. If the subscription is successful but there is no data flow, the server will disconnect after **one minute**. The client can send a ping to keep the connection alive. +- One ws connection supports a maximum of 30 subscriptions. +- Please process the data according to the parameters returned in the documentation. Parameters not returned in the documentation will be optimized soon, so please do not use them. + +## Live Subscription/Unsubscription to Data Streams + +- The following data can be sent via websocket to subscribe or unsubscribe from data streams. Examples are provided below. +- The `id` in the response is an unsigned integer and serves as the unique identifier for communication. +- If the `msg` in the response matches the corresponding request field, it indicates that the request was sent successfully. + +## Protocol Buffers Integration + +The current websocket push uses the protobuf format. The specific integration process is as follows: + +1.**PB File Definition** + The PB definition files can be obtained via the provided link. + +2.**Generate Deserialization Code** + Use the tool available at https://github.com/protocolbuffers/protobuf to compile the .proto files and generate deserialization code. + + > **Java** + + ```shell + protoc --java_out=custom_path/java-out -I=custom_path/proto-v3-api custom_path/proto-v3-api/*.proto + ``` + + > **Python** + + ```shell + protoc --python_out=custom_path/python-out -I=custom_path/proto-v3-api custom_path/proto-v3-api/* + ``` + + > **Others** + + Multiple languages are supported, including C++, C#, Go, Ruby, PHP, JS, etc. For details, see https://github.com/protocolbuffers/protobuf. + +3.**Data Deserialization** + Use the code generated in the previous step to deserialize the data. + + > **Java** + Include the protobuf-java dependency: + + ```xml + + com.google.protobuf + protobuf-java + {protobuf.version} + + ``` + + + + ```java + //Parsing example: + + // Assemble the object + PushDataV3ApiWrapper pushDataV3ApiWrapper = PushDataV3ApiWrapper.newBuilder() + .setChannel("spot@public.increase.depth.v3.api.pb") + .setSymbol("BTCUSDT") + .setSendTime(System.currentTimeMillis()) + .build(); + + // Serialize to a byte array + byte[] serializedData = pushDataV3ApiWrapper.toByteArray(); + + // Deserialize into a PushDataV3ApiWrapper object + PushDataV3ApiWrapper resultV3 = PushDataV3ApiWrapper.parseFrom(serializedData); + ``` + + > **Python** + + ```python + #Parsing example: + + import PushDataV3ApiWrapper_pb2 + + # Assemble the object + pushData = PushDataV3ApiWrapper_pb2.PushDataV3ApiWrapper() + pushData.channel = 'spot@public.increase.depth.v3.api.pb' + pushData.symbol = 'BTCUSDT' + + # Serialize to a string + serializedData = pushData.SerializeToString() + + # Deserialize into a PushDataV3ApiWrapper object + result = PushDataV3ApiWrapper_pb2.PushDataV3ApiWrapper() + result.ParseFromString(serializedData) + print(result) + ``` -- A single connection to **wbs.mexc.com** is only valid for 24 hours; expect to be disconnected at the 24 hour mark. +--- -- All symbols are **Uppercase**
eg:`spot@public.deals.v3.api@`
->`spot@public.deals.v3.api@BTCUSDT`. +### Subscribe to a Data Stream -- If there is no valid websocket subscription, the server will disconnect in **30 seconds**. If the subscription is successful but there is no streams, the server will disconnect in **1 minute**. The client can send `PING` to maintain the connection. +> **Subscription Channel Response** -- Every websocket connection maximun support 30 subscriptions at one time. +```json +{ + "id": 0, + "code": 0, + "msg": "spot@public.deals.v3.api.pb@BTCUSDT" +} +``` -## Live Subscribing/Unsubscribing to streams +- **Request** -- The following data can be sent through the websocket instance in order to subscribe/unsubscribe from streams. Examples can be seen below. -- The id used in the JSON payloads is an unsigned INT used as an identifier to uniquely identify the messages going back and forth. +{ + "method": "SUBSCRIPTION", + "params": ["spot@public.deals.v3.api.pb@BTCUSDT"] +} -- In the response, if the `msg` received is same as request params, this means the request sent was a success. -### Subscribe to a stream +--- -> **Subscribe Response** +### Unsubscribe from a Data Stream -``` - { - "id":0, - "code":0, - "msg":"spot@public.deals.v3.api@BTCUSDT" - } +> **Unsubscription Response** + +```json +{ + "id": 0, + "code": 0, + "msg": "spot@public.increase.depth.v3.api.pb@BTCUSDT" +} ``` - **Request** { - "method":"SUBSCRIPTION", - "params":["spot@public.deals.v3.api@BTCUSDT"] + "method": "UNSUBSCRIPTION", + "params": ["spot@public.deals.v3.api.pb@BTCUSDT"] } -### Unsubscribe to a stream -> **Unsubscribe Response** +--- -``` - { - "id":0, - "code":0, - "msg":"spot@public.increase.depth.v3.api@BTCUSDT,spot@public.deals.v3.api@BTCUSDT" - } -``` +### PING/PONG Mechanism -- **Request** +> **PING/PONG Response** +```json { - "method":"UNSUBSCRIPTION", - "params":["spot@public.deals.v3.api@BTCUSDT","spot@public.increase.depth.v3.api@BTCUSDT"] + "id": 0, + "code": 0, + "msg": "PONG" } +``` -### PING/PONG +- **Request** -> **PING/PONG Response** -``` - { - "id":0, - "code":0, - "msg":"PONG" - } -``` +{"method": "PING"} -- **Request** -{"method":"PING"} +--- ## Trade Streams ->**request:** +> **Request:** -``` +```json { "method": "SUBSCRIPTION", "params": [ - "spot@public.deals.v3.api@BTCUSDT" + "spot@public.aggre.deals.v3.api.pb@100ms@BTCUSDT" ] } ``` -> **response:** -``` +> **Response:** + +```json { - "c":"spot@public.deals.v3.api@BTCUSDT", - "d":{ - "deals":[{ - "S":2, //tradeType - "p":"20233.84", //price - "t":1661927587825, //dealTime - "v":"0.001028"}], //quantity - "e":"spot@public.deals.v3.api"}, //eventType - "s":"BTCUSDT", //symbol - "t":1661927587836 //eventTime -} + "channel": "spot@public.aggre.deals.v3.api.pb@100ms@BTCUSDT", + "publicdeals": { + "dealsList": [ + { + "price": "93220.00", // Trade price + "quantity": "0.04438243", // Trade quantity + "tradetype": 2, // Trade type (1: Buy, 2: Sell) + "time": 1736409765051 // Trade time + } + ], + "eventtype": "spot@public.aggre.deals.v3.api.pb@100ms" // Event type + }, + "symbol": "BTCUSDT", // Trading pair + "sendtime": 1736409765052 // Event time +} ``` -**Request:** `spot@public.deals.v3.api@` +**Request Parameter:** `spot@public.aggre.deals.v3.api.pb@(100ms|10ms)@` -The Trade Streams push raw trade information; each trade has a unique buyer and seller. +The Trade Streams push raw trade information; each trade has a unique buyer and seller -**Response:** +**Response Parameters:** -| Name | Type | Description | -| :-------- | :----- | :--- | -| deals | array | dealsInfo | -| > S | int | tradeType 1:buy 2:sell | -| > p | string | price | -| > t | long | dealTime | -| > v | string | quantity | -| e | string | eventType | -| s | string | symbol | -| t | long | eventTime | +| Parameter | Data Type | Description | +| --------- | --------- | ---------------------------- | +| dealsList | array | Trade information | +| price | string | Trade price | +| quantity | string | Trade quantity | +| tradetype | int | Trade type (1: Buy, 2: Sell) | +| time | long | Trade time | +| eventtype | string | Event type | +| symbol | string | Trading pair | +| sendtime | long | Event time | -## Kline Streams +--- ->**request:** +## K-line Streams -``` +> **Request:** + +```json { "method": "SUBSCRIPTION", "params": [ - "spot@public.kline.v3.api@BTCUSDT@Min15" + "spot@public.kline.v3.api.pb@BTCUSDT@Min15" ] } ``` -> **response:** +> **Response:** -``` +```json { - "c":"spot@public.kline.v3.api@BTCUSDT@Min15", - "d":{ - "k":{ - "T":1661931900, - "a":29043.48804658, - "c":20279.43, - "h":20284.93, - "i":"Min15", - "l":20277.52, - "o":20284.93, - "t":1661931000, - "v":1.43211}, - "e":"spot@public.kline.v3.api"}, - "s":"BTCUSDT", - "t":1661931016878 + "channel": "spot@public.kline.v3.api.pb@BTCUSDT@Min15", + "publicspotkline": { + "interval": "Min15", // K-line interval + "windowstart": 1736410500, // Start time of the K-line + "openingprice": "92925", // Opening trade price during this K-line + "closingprice": "93158.47", // Closing trade price during this K-line + "highestprice": "93158.47", // Highest trade price during this K-line + "lowestprice": "92800", // Lowest trade price during this K-line + "volume": "36.83803224", // Trade volume during this K-line + "amount": "3424811.05", // Trade amount during this K-line + "windowend": 1736411400 // End time of the K-line + }, + "symbol": "BTCUSDT", + "symbolid": "2fb942154ef44a4ab2ef98c8afb6a4a7", + "createtime": 1736410707571 } - ``` The Kline/Candlestick Stream push updates to the current klines/candlestick every second. -**Request:** `spot@public.kline.v3.api@@` +**Request Parameter:** `spot@public.kline.v3.api.pb@@` -**Response:** +**Response Parameters:** -| Name | Type | Description | -| :-------- | :----- | :--- | -| k | object| klineInfo | -| > T | long | endTime | -| > a | bigDecimal | volume | -| > c | bigDecimal | closingPrice | -| > h | bigDecimal | highestPrice | -| > i | interval | interval | -| > l | bigDecimal | lowestPrice | -| > o | bigDecimal | openingPrice | -| > t | long | stratTime | -| > v | bigDecimal | quantity | -| s | string | symbol | -| t | long | eventTime | - -**Kline chart intervals:** - -Min -> minutes; Hour -> hours; Day -> days; Week -> weeks, M -> months +| Parameter | Data Type | Description | +| --------------- | ---------- | -------------------------------------- | +| publicspotkline | object | K-line information | +| interval | string | K-line interval | +| windowstart | long | Start time of the K-line | +| openingprice | bigDecimal | Opening trade price during this K-line | +| closingprice | bigDecimal | Closing trade price during this K-line | +| highestprice | bigDecimal | Highest trade price during this K-line | +| lowestprice | bigDecimal | Lowest trade price during this K-line | +| volume | bigDecimal | Trade volume during this K-line | +| amount | bigDecimal | Trade amount during this K-line | +| windowend | long | End time of the K-line | +| symbol | string | Trading pair | +| symbolid | string | Trading pair ID | +| createtime | long | Event time | + +**K-line Interval Parameters:** + +- Min: Minutes; Hour: Hours; Day: Days; Week: Weeks; M: Month + +Available intervals: - Min1 - Min5 @@ -3824,326 +3922,352 @@ Min -> minutes; Hour -> hours; Day -> days; Week -> weeks, M -> months - Week1 - Month1 +--- + ## Diff.Depth Stream -> **request:** +> **Request:** -``` +```json { "method": "SUBSCRIPTION", "params": [ - "spot@public.increase.depth.v3.api@BTCUSDT" + "spot@public.aggre.depth.v3.api.pb@100ms@BTCUSDT" ] } ``` -> **response:** - -``` +> **Response:** +```json { - "c":"spot@public.increase.depth.v3.api@BTCUSDT", - "d":{ - "asks":[{ - "p":"20290.89", - "v":"0.000000"}], - "e":"spot@public.increase.depth.v3.api", - "r":"3407459756"}, - "s":"BTCUSDT", - "t":1661932660144 + "channel": "spot@public.aggre.depth.v3.api.pb@100ms@BTCUSDT", + "publicincreasedepths": { + "asksList": [], // asks: Sell orders + "bidsList": [ // bids: Buy orders + { + "price": "92877.58", // Price level of change + "quantity": "0.00000000" // Quantity + } + ], + "eventtype": "spot@public.aggre.depth.v3.api.pb@100ms", // Event type + "version": "36913293511" // Version number + }, + "symbol": "BTCUSDT", // Trading pair + "sendtime": 1736411507002 // Event time } ``` -If the quantity is 0, it means that the order of the price has been cancel or traded,remove the price level. +If the order quantity (`quantity`) for a price level is 0, it indicates that the order at that price has been canceled or executed, and that price level should be removed. -**Request:** `spot@public.increase.depth.v3.api@` +**Request Parameter:** `spot@public.aggre.depth.v3.api.pb@(100ms|10ms)@` -**Response:** +**Response Parameters:** -| Name | Type | Description | -| :-------- | :----- | :--- | -| p | string | price | -| v | string | quantity | -| e | string | eventType | -| r | string | version | -| s | string | symbol | -| t | long | eventTime | +| Parameter | Data Type | Description | +| --------- | --------- | --------------------- | +| price | string | Price level of change | +| quantity | string | Quantity | +| eventtype | string | Event type | +| version | string | Version number | +| symbol | string | Trading pair | +| sendtime | long | Event time | -## Partial Book Depth Streams -Top bids and asks, Valid are 5, 10, or 20. +--- ->**request:** +## Diff.Depth Stream(Batch Aggregation) -``` +> **Request:** + +```json { "method": "SUBSCRIPTION", "params": [ - "spot@public.limit.depth.v3.api@BTCUSDT@5" - - ] + "spot@public.increase.depth.batch.v3.api.pb@BTCUSDT" + ] } ``` -> **response:** - -``` +> **Response:** +```json { - "c":"spot@public.limit.depth.v3.api@BTCUSDT@5", - "d":{ - "asks":[{ - "p":"20290.89", - "v":"0.650000"}], - "e":"spot@public.limit.depth.v3.api", - "r":"3407459756"}, - "s":"BTCUSDT", - "t":1661932660144 + "channel" : "spot@public.increase.depth.batch.v3.api.pb@BTCUSDT", + "symbol" : "BTCUSDT", + "sendTime" : "1739502064578", + "publicIncreaseDepthsBatch" : { + "items" : [ { + "asks" : [ ], + "bids" : [ { + "price" : "96578.48", + "quantity" : "0.00000000" + } ], + "eventType" : "", + "version" : "39003145507" + }, { + "asks" : [ ], + "bids" : [ { + "price" : "96578.90", + "quantity" : "0.00000000" + } ], + "eventType" : "", + "version" : "39003145508" + }, { + "asks" : [ ], + "bids" : [ { + "price" : "96579.31", + "quantity" : "0.00000000" + } ], + "eventType" : "", + "version" : "39003145509" + }, { + "asks" : [ ], + "bids" : [ { + "price" : "96579.84", + "quantity" : "0.00000000" + } ], + "eventType" : "", + "version" : "39003145510" + }, { + "asks" : [ ], + "bids" : [ { + "price" : "96576.69", + "quantity" : "4.88725694" + } ], + "eventType" : "", + "version" : "39003145511" + } ], + "eventType" : "spot@public.increase.depth.batch.v3.api.pb" + } } ``` +In the batch aggregation version, if the number of entries exceeds 5 or the time interval exceeds 5ms, the data is pushed once. If the order quantity for a price level is 0, it indicates that the order at that price has been canceled or executed, and that price level should be removed. -**Request:** `spot@public.limit.depth.v3.api@@` +**Request Parameter:** `spot@public.increase.depth.batch.v3.api.pb@` -**Response:** +**Response Parameters:** -| Name | Type | Description | -| :-------- | :----- | :--- | -| p | string | price | -| v | string | quantity | -| e | string | eventType | -| r | string | version | -| s | string | symbol | -| t | long | eventTime | +| Parameter | Data Type | Description | +| --------- | --------- | --------------------- | +| price | string | Price level of change | +| quantity | string | Quantity | +| eventtype | string | Event type | +| version | string | Version number | +| symbol | string | Trading pair | +| sendtime | long | Event time | -## Individual Symbol Book Ticker Streams -Pushes any update to the best bid or ask's price or quantity in real-time for a specified symbol. +--- -> **request:** +## Partial Book Depth Streams -``` +This stream pushes limited level depth information. The “levels” indicate the number of order levels for buy and sell orders, which can be 5, 10, or 20 levels. + +> **Request:** + +```json { -    "method": "SUBSCRIPTION", -    "params": [ -                "spot@public.bookTicker.v3.api@BTCUSDT" -      ] + "method": "SUBSCRIPTION", + "params": [ + "spot@public.limit.depth.v3.api.pb@BTCUSDT@5" + ] } ``` -> **response:** - -``` +> **Response:** +```json { - "c":"spot@public.bookTicker.v3.api@", - "d":{ -    - "A":"40.66000000" -    "B":"31.21000000",   -    "a":"25.36520000", - "b":"25.35190000",},   - "s":"BTCUSDT", - "t":1661932660144 + "channel": "spot@public.limit.depth.v3.api.pb@BTCUSDT@5", + "publiclimitdepths": { + "asksList": [ // asks: Sell orders + { + "price": "93180.18", // Price level of change + "quantity": "0.21976424" // Quantity + } + ], + "bidsList": [ // bids: Buy orders + { + "price": "93179.98", + "quantity": "2.82651000" + } + ], + "eventtype": "spot@public.limit.depth.v3.api.pb", // Event type + "version": "36913565463" // Version number + }, + "symbol": "BTCUSDT", // Trading pair + "sendtime": 1736411838730 // Event time } ``` +**Request Parameter:** `spot@public.limit.depth.v3.api.pb@@` -**Request:** `spot@public.bookTicker.v3.api@` +**Response Parameters:** -**Response:** +| Parameter | Data Type | Description | +| --------- | --------- | --------------------- | +| price | string | Price level of change | +| quantity | string | Quantity | +| eventtype | string | Event type | +| version | string | Version number | +| symbol | string | Trading pair | +| sendtime | long | Event time | -| Name | Type | Description | -| :-------- | :----- | :--- | -| A | string | best ask qty | -| B | string | best bid qty | -| a | string | best ask price | -| b | string | best bid price | -| s | string | symbol | -| t | long | eventTime | +--- -## MiniTicker +## Individual Symbol Book Ticker Streams ->**request:** +Pushes any update to the best bid or ask's price or quantity in real-time for a specified symbol. -``` +> **Request:** + +```json { "method": "SUBSCRIPTION", "params": [ - "spot@public.miniTicker.v3.api@BTCUSDT@UTC+8" + "spot@public.aggre.bookTicker.v3.api.pb@100ms@BTCUSDT" ] } ``` -> **response:** -``` +> **Response:** + +```json { - "d": - {"s":"BTCUSDT", - "p":"36474.74", - "r":"0.0354", - "tr":"0.0354", - "h":"36549.72", - "l":"35101.68", - "v":"375173478.65", - "q":"10557.72895", - "lastRT":"-1", - "MT":"0", - "NV":"--", - "t":"1699502456050"}, - "c":"spot@public.miniTicker.v3.api@BTCUSDT@UTC+8", - "t":1699502456051, - "s":"BTCUSDT" -} -``` - -**Request:** `spot@public.miniTicker.v3.api@@` + "channel": "spot@public.aggre.bookTicker.v3.api.pb@100ms@BTCUSDT", + "publicbookticker": { + "bidprice": "93387.28", // Best bid price + "bidquantity": "3.73485", // Best bid quantity + "askprice": "93387.29", // Best ask price + "askquantity": "7.669875" // Best ask quantity + }, + "symbol": "BTCUSDT", // Trading pair + "sendtime": 1736412092433 // Event time +} +``` +**Request Parameter:** `spot@public.aggre.bookTicker.v3.api.pb@(100ms|10ms)@` -**Response:** +**Response Parameters:** -| Name | Type | Description | -| :-------- | :----- | :--- | -| c | string | channel name| -| d | data| data| -| >s | string |symbol| -| >p | string |deal price| -| >r | string |price Change Percent in utc8| -| >tr | string |price Change Percent in time zone| -| >h | string |24h high price | -| >l | string |24h low price | -| >v | string |24h volume| -| >q | string |24h quote Volume| -| >lastRT | string |etf Last Rebase Time| -| >MT | string |etf Merge Times| -| >NV | string |etf Net Value| +| Parameter | Data Type | Description | +| ----------- | --------- | ----------------- | +| bidprice | string | Best bid price | +| bidquantity | string | Best bid quantity | +| askprice | string | Best ask price | +| askquantity | string | Best ask quantity | +| symbol | string | Trading pair | +| sendtime | long | Event time | +--- -## MiniTickers +## Individual Symbol Book Ticker Streams(Batch Aggregation) ->**request:** +This batch aggregation version pushes the best order information for a specified trading pair. -``` +> **Request:** + +```json { "method": "SUBSCRIPTION", "params": [ - "spot@public.miniTickers.v3.api@UTC+8" + "spot@public.bookTicker.batch.v3.api.pb@BTCUSDT" ] } ``` -> **response:** -``` +> **Response:** + +```json { - "d": - [{"s":"SENSOUSDT", - "p":"0.07642", - "r":"-0.0383", - "tr":"-0.0383", - "h":"0.08032", - "l":"0.07463", - "v":"25052.6533", - "q":"323777.17", - "lastRT":"-1", - "MT":"0", - "NV":"--"}, - {"s":"BTCUSDT", - "p":"36474.74", - "r":"0.0354", - "tr":"0.0354", - "h":"36549.72", - "l":"35101.68", - "v":"375173478.65", - "q":"10557.72895", - "lastRT":"-1", - "MT":"0", - "NV":"--"}, - "c":"spot@public.miniTickers.v3.api@UTC+8", - "t":1699502456051, -} -``` - -**Request:** `spot@public.miniTickers.v3.api@` + "channel" : "spot@public.bookTicker.batch.v3.api.pb@BTCUSDT", + "symbol" : "BTCUSDT", + "sendTime" : "1739503249114", + "publicBookTickerBatch" : { + "items" : [ { + "bidPrice" : "96567.37", + "bidQuantity" : "3.362925", + "askPrice" : "96567.38", + "askQuantity" : "1.545255" + } ] + } +} +``` +**Request Parameter:** `spot@public.bookTicker.batch.v3.api.pb@` -**Response:** +**Response Parameters:** + +| Parameter | Data Type | Description | +| ----------- | --------- | ----------------- | +| bidprice | string | Best bid price | +| bidquantity | string | Best bid quantity | +| askprice | string | Best ask price | +| askquantity | string | Best ask quantity | +| symbol | string | Trading pair | +| sendtime | long | Event time | + +--- -| Name | Type | Description | -| :-------- | :----- | :--- | -| c | string | channel name| -| d | data| data| -| >s | string |symbol| -| >p | string |deal price| -| >r | string |24h price Change Percent in utc8| -| >tr | string |24h price Change Percent in time zone| -| >h | string |24h high price | -| >l | string |24h low price | -| >v | string |24h volume| -| >q | string |24h quote Volume| -| >lastRT | string |etf Last Rebase Time| -| >MT | string |etf Merge Times| -| >NV | string |etf Net Value| - - - -**How is incremental depth information maintained:** - -1. Though **spot@public.increase.depth.v3.api@** to get full amount of depth information, save the current version. -2. Subscribe to ws depth information, if the received data version more than the current version after update, the later received update cover the previous one at the same price. -3. Through **https://api.mexc.com/api/v3/depth?symbol=MXBTC&limit=1000** get the latest 1000 depth snapshots. +## How to Properly Maintain a Local Copy of the Order Book + +1. Subscribe to `spot@public.aggre.depth.v3.api.pb@(100ms|10ms)@` to get full amount of depth information, save the current version. +2. Subscribe to ws depth information, if the received data version more than the current version after update, the later received update cover the previous one at the same price. +3. Through **https://api.mexc.com/api/v3/depth?symbol=MXBTC&limit=1000** to get the latest 1000 depth snapshots. 4. Discard version data from the snapshot obtained by Version (less than step 3 )for the same price in the current cached depth information 5. Update the contents of the deep snapshots to the local cache and keep updating from the event received by the WS 6. The version of each new event should be exactly equal to version+1 of the previous event, otherwise packet loss may occur. In case of packet loss or discontinuous version of the event retrieved, please re-initialize from Step 3. 7. The amount of hanging orders in each event represents the **absolute value** of the current hanging orders of the price, rather than the relative change. 8. If the amount of a hanging order corresponding to a certain price is 0, it means that the hanging order at that price has been cancelled, the price should be removed. +Note: Because the depth snapshot has a limitation on the number of price levels, any price levels not included in the initial snapshot and without quantity changes will not appear in the incremental depth updates. Therefore, even after applying all incremental updates, these price levels may not be visible in your local order book, and there may be some discrepancies between your local order book and the real order book. However, for most use cases, a depth limit of 5000 levels is sufficient to understand the market and trading activity effectively. + +--- + # Websocket User Data Streams - The base API endpoint is: **https://api.mexc.com** - - A User Data Stream `listenKey` is valid for 60 minutes after creation. - -- Doing a `PUT` on a `listenKey` will extend its validity for 60 minutes. - +- Doing a `PUT` on a `listenKey` will extend its validity for 60 minutes. - Doing a `DELETE` on a `listenKey` will close the stream and invalidate the `listenKey`. - -- websocket baseurl: **wss://wbs.mexc.com/ws** - -- User Data Streams are accessed at **/ws?listenKey=listenKey**
eg:**wss://wbs.mexc.com/ws?listenKey=pqia91ma19a5s61cv6a81va65sd099v8a65a1a5s61cv6a81va65sdf19v8a65a1** - +- websocket baseurl: **ws://wbs-api.mexc.com/ws** +- User Data Streams are accessed at **/ws?listenKey=listenKey** + For example: **ws://wbs-api.mexc.com/ws?listenKey=pqia91ma19a5s61cv6a81va65sd099v8a65a1a5s61cv6a81va65sdf19v8a65a1** - A single connection is only valid for 24 hours; expect to be disconnected at the 24 hour mark. - - Each UID can apply for a maximum of 60 listen keys (excluding invalid listen keys). +- Each listen key maximum support 5 websocket connection (which means each uid can applies for a maximum of 60 listen keys and 300 ws links). -- Each listen key maximum support 5 websocket connection (which means each uid can applies for a maximum of 60 listen keys and 300 ws links). +## Listen Key -## Listen Key - -### Create a ListenKey +### Generate Listen Key > **Response** -``` +```json { "listenKey": "pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1" } ``` -**Permission:** SPOT_ACCOUNT_R +**Required Permissions:** Account Read / SPOT_ACCOUNT_R -**HTTP** +**HTTP Request** -- **POST** ` /api/v3/userDataStream` +- **POST** `/api/v3/userDataStream` -Start a new user data stream. The stream will close after 60 minutes unless a keepalive is sent. +Starts a new data stream. The stream will close 60 minutes after creation unless a keepalive is sent. -**request:** +**Parameters:** NONE -### Query all ListenKey +--- + +### Get Valid Listen Keys > **Response** -``` +```json { "listenKey": [ "c285bc363cfeac6646576b801a2ed1f9523310fcda9e927e509aaaaaaaaaaaaaa", @@ -4153,275 +4277,237 @@ NONE } ``` -**Permission:** SPOT_ACCOUNT_R +**Required Permissions:** Account Read / SPOT_ACCOUNT_R -**HTTP** +**HTTP Request** -- **GET** ` /api/v3/userDataStream` +- **GET** `/api/v3/userDataStream` -get all valid listenKey +Retrieves all currently valid listen keys. -**request:** +**Parameters:** NONE +--- -### Keep-alive a ListenKey +### Extend Listen Key Validity > **Response** -``` +```json { "listenKey": "pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1" } ``` -**HTTP** -- **PUT** ` /api/v3/userDataStream` +**HTTP Request** + +- **PUT** `/api/v3/userDataStream` -Keepalive a user data stream to prevent a time out. User data streams will close after 60 minutes. It's recommended to send a ping about every 30 minutes. +Extends the validity to 60 minutes from the time of this call. It is recommended to send a request every 30 minutes. -**Request:** +**Request Parameters:** -| Name | Type | Mandatory | Description | -| :-------- | :------- | :------- | :--- | -| listenKey | STRING | YES | | +| Parameter | Data Type | Required | Description | +| --------- | --------- | -------- | ----------- | +| listenKey | string | Yes | | - ### Close a ListenKey +--- - > **Response** +### Close Listen Key - ``` - { - "listenKey": "pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1" - } - ``` +> **Response** + +```json +{ + "listenKey": "pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1" +} +``` - **HTTP** +**HTTP Request** - - **DELETE** ` /api/v3/userDataStream` +- **DELETE** `/api/v3/userDataStream` - Close out a user data stream. +Closes the user data stream. +**Request Parameters:** -## Spot Account Upadte +| Parameter | Data Type | Required | Description | +| --------- | --------- | -------- | ----------- | +| listenKey | string | Yes | | -The server will push an update of the account assets when the account balance changes. +--- ->**request:** +## Spot Account Update -``` +After a successful subscription, whenever the account balance or available balance changes, the server will push updates of the account assets. + +> **Request:** + +```json { "method": "SUBSCRIPTION", "params": [ - "spot@private.account.v3.api" + "spot@private.account.v3.api.pb" ] } ``` -> **response:** +> **Response:** -``` +```json { - "c": "spot@private.account.v3.api", - "d": { - "a": "USDT", - "c": 1678185928428, - "f": "302.185113007893322435", - "fd": "-4.990689704", - "l": "4.990689704", - "ld": "4.990689704", - "o": "ENTRUST_PLACE" - }, - "t": 1678185928435 + channel: "spot@private.account.v3.api.pb", + createTime: 1736417034305, + sendTime: 1736417034307, + privateAccount { + vcoinName: "USDT", + coinId: "128f589271cb4951b03e71e6323eb7be", + balanceAmount: "21.94210356004384", + balanceAmountChange: "10", + frozenAmount: "0", + frozenAmountChange: "0", + type: "CONTRACT_TRANSFER", + time: 1736416910000 + } } ``` -**Request:** `spot@private.account.v3.api` +**Request Parameter:** `spot@private.account.v3.api.pb` -**Response:** - -| Name | Type | Description | -| :-------- | :----- | :--- | -| d | json | account updates | -| > a | string | asset | -| > c | long | change time | -| > f | string | free balance | -| > fd | string | free changed amount | -| > l | string | frozen amount | -| > ld | string | frozen changed amount| -| > o | string | changed type| -| t | long | eventTime | +**Response Parameters:** +| Parameter | Data Type | Description | +| ------------------- | --------- | ----------------------------------------------------------- | +| privateAccount | json | Account information | +| vcoinName | string | Asset name | +| balanceAmount | string | Available balance | +| balanceAmountChange | string | Change in available balance | +| frozenAmount | string | Frozen balance | +| frozenAmountChange | string | Change in frozen balance | +| type | string | Change type (see details) | +| time | long | Settlement time | +--- -## Spot Account Deals +## Spot Account Deals ->**request:** +> **Request:** -``` +```json { "method": "SUBSCRIPTION", "params": [ - "spot@private.deals.v3.api" + "spot@private.deals.v3.api.pb" ] } ``` -> **response:** +> **Response:** -``` +```json { - "c": "spot@private.deals.v3.api", - "d": { - "p": "1.804", - "v": "0.31", - "a": "0.55924", - "S": 1, - "T": 1678901086198, - "t": "5bbb6ad8b4474570b155610e30d960cd", - "c": "", - "i": "2dd9655f9fa2438fa1709510d7c1afd9", - "m": 0, - "st": 0, - "n": "0.000248206380027431", - "N": "MX" - }, - "s": "MXUSDT", - "t": 1661938980285 + channel: "spot@private.deals.v3.api.pb", + symbol: "MXUSDT", + sendTime: 1736417034332, + privateDeals { + price: "3.6962", + quantity: "1", + amount: "3.6962", + tradeType: 2, + tradeId: "505979017439002624X1", + orderId: "C02__505979017439002624115", + feeAmount: "0.0003998377369698171", + feeCurrency: "MX", + time: 1736417034280 + } } ``` -**Request:** `spot@private.deals.v3.api` +**Request Parameter:** `spot@private.deals.v3.api.pb` -**Response:** +**Response Parameters:** -| Name | Type | Description | -| :-------- | :----- | :--- | -| d | json | dealsInfo | -| > S | int | tradetype 1:buy 2:sell | -| > T | long | tradeTime | -| > c | string | clientOrderId | -| > i | string | orderId | -| > m | int | isMaker | -| > p | string | price | -| > st | byte | isSelfTrade | -| > t | string | tradeId | -| > v | string | quantity | -| > a | string | deals amount | -| > n | string | commission fee| -| > N | string | commissionAsset)| -| s | string | symbol | -| t | long |eventTime | - -## Spot Account Orders - ->**request:** - -``` -{ - "method": "SUBSCRIPTION", - "params": [ - "spot@private.orders.v3.api" - ] -} -``` +| Parameter | Data Type | Description | +| ------------- | --------- | ---------------------------- | +| symbol | string | Trading pair | +| sendTime | long | Event time | +| privateDeals | json | Account trade information | +| price | string | Trade price | +| quantity | string | Trade quantity | +| amount | string | Trade amount | +| tradeType | int | Trade type (1: Buy, 2: Sell) | +| tradeId | string | Trade ID | +| orderId | string | Order ID | +| clientOrderId | string | User-defined order ID | +| feeAmount | string | Fee amount | +| feeCurrency | string | Fee currency | +| time | long | Trade time | -**Request:** `spot@private.orders.v3.api` +--- -### 1. Limit/Market Orders +## Spot Account Orders -> **response:** +> **Request:** -``` +```json { - "c": "spot@private.orders.v3.api", - "d": { - "A":8.0, - "O":1661938138000, - "S":1, - "V":10, - "a":8, - "c":"", - "i":"e03a5c7441e44ed899466a7140b71391", - "m":0, - "o":1, - "p":0.8, - "s":1, - "v":10, - "ap":0, - "cv":0, - "ca":0 - }, - "s": "MXUSDT", - "t": 1661938138193 + "method": "SUBSCRIPTION", + "params": [ + "spot@private.orders.v3.api.pb" + ] } ``` -**Response:** +**Request Parameter:** `spot@private.orders.v3.api.pb` -| Name | Type | Description | -| :-------- | :----- | :--- | -| d | json | orderInfo | -| > A | bigDecimal | remainAmount | -| > O | long | createTime| -| > S | int | tradetype 1:buy 2:sell | -| > V | bigDecimal | remainQuantity | -| > a | bigDecimal | amount | -| > c | string | clientOrderId | -| > i | string | orderId | -| > m | int | isMaker | -| > o | int | LIMIT_ORDER(1),POST_ONLY(2),IMMEDIATE_OR_CANCEL(3),
FILL_OR_KILL(4),MARKET_ORDER(5);STOP_LIMIT(100) | -| > p | bigDecimal | PRICE | -| > s | int | status 1:New order 2:Filled 3:Partially filled 4:Order canceled 5:Order filled partially, and then the rest of the order is canceled | -| > v | bigDecimal | quantity | -| > ap | bigDecimal | avgPrice | -| > cv | bigDecimal | cumulativeQuantity | -| > ca | bigDecimal | cumulativeAmount | -| t | long | eventTime | -| s | string | symbol | - -### 2. Stop Limit Order - -> **response:** +> **Response:** -``` +```json { - "c": "spot@private.orders.v3.api", - "d": { - "N":"USDT", - "O":1661938853715, - "P":0.9, - "S":1, - "T":1, - "i":"f6d82e5f41d745f59fe9d3cafffd80b5", - "o":100, - "p":1.01, - "s":"NEW", - "v":6 - }, - "s": "MXUSDT", - "t": 1661938853727 + channel: "spot@private.orders.v3.api.pb", + symbol: "MXUSDT", + sendTime: 1736417034281, + privateOrders { + id: "C02__505979017439002624115", + price: "3.5121", + quantity: "1", + amount: "0", + avgPrice: "3.6962", + orderType: 5, + tradeType: 2, + remainAmount: "0", + remainQuantity: "0", + lastDealQuantity: "1", + cumulativeQuantity: "1", + cumulativeAmount: "3.6962", + status: 2, + createTime: 1736417034259 + } } ``` -**Response:** - -| Name | Type | Description | -| :-------- | :----- | :--- | -| d | json | orderInfo | -| > N | string | commissionAsset | -| > O | long | createTime | -| > P | bigDecimal | triggerPrice | -| > S | int | tradetype 1:buy 2:sell | -| > T | int | 0: GE(price is higher than triggerPrice) 1: LE(price is lower than triggerPrice) | -| > i | string | orderId | -| > o | int | orderType LIMIT_ORDER(1),POST_ONLY(2),IMMEDIATE_OR_CANCEL(3),
FILL_OR_KILL(4),MARKET_ORDER(5);STOP_LIMIT(100) | -| > p | bigDecimal | price | -| > s | string | state NEW,CANCELED,EXECUTED,FAILED | -| > v | bigDecimal | quantity | -| s | string | symbol | -| t | long | eventTime | +**Response Parameters:** + +| Parameter | Data Type | Description | +| ------------------ | ---------- | ------------------------------------------------------------ | +| symbol | string | Trading pair | +| sendTime | long | Event time | +| privateOrders | json | Account order information | +| id | string | Order ID | +| price | bigDecimal | Order price | +| quantity | bigDecimal | Order quantity | +| amount | bigDecimal | Total order amount | +| avgPrice | bigDecimal | Average trade price | +| orderType | int | Order type: LIMIT_ORDER (1), POST_ONLY (2), IMMEDIATE_OR_CANCEL (3), FILL_OR_KILL (4), MARKET_ORDER (5); Stop loss/take profit (100) | +| tradeType | int | Trade type (1: Buy, 2: Sell) | +| remainAmount | bigDecimal | Remaining amount | +| remainQuantity | bigDecimal | Remaining quantity | +| cumulativeQuantity | bigDecimal | Cumulative trade quantity | +| cumulativeAmount | bigDecimal | Cumulative trade amount | +| status | int | Order status: 1: Not traded, 2: Fully traded, 3: Partially traded, 4: Canceled, 5: Partially canceled | +| createTime | long | Order creation time | # Rebate Endpoints From 003b25b71853c709fcfb5d4f6ca04729dbbe230d Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Mon, 24 Feb 2025 18:51:18 +0800 Subject: [PATCH 21/35] Update index.html.md --- source/index.html.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/index.html.md b/source/index.html.md index 42b4323..241413d 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -3655,7 +3655,7 @@ The current websocket push uses the protobuf format. The specific integration pr The PB definition files can be obtained via the provided link. 2.**Generate Deserialization Code** - Use the tool available at https://github.com/protocolbuffers/protobuf to compile the .proto files and generate deserialization code. + Use the tool available at [https://github.com/protocolbuffers/protobuf](https://github.com/protocolbuffers/protobuf) to compile the .proto files and generate deserialization code. > **Java** @@ -3671,7 +3671,9 @@ The current websocket push uses the protobuf format. The specific integration pr > **Others** - Multiple languages are supported, including C++, C#, Go, Ruby, PHP, JS, etc. For details, see https://github.com/protocolbuffers/protobuf. + ``` + Multiple languages are supported, including C++, C#, Go, Ruby, PHP, JS, etc. For details, see [https://github.com/protocolbuffers/protobuf](https://github.com/protocolbuffers/protobuf). + ``` 3.**Data Deserialization** Use the code generated in the previous step to deserialize the data. From cd17e9b6f6da85940634b2d521b72e6bfe2e2c8f Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Mon, 24 Feb 2025 18:52:52 +0800 Subject: [PATCH 22/35] Update index.html.md --- source/index.html.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/index.html.md b/source/index.html.md index 241413d..e8ca80d 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -3633,7 +3633,7 @@ Response: # Websocket Market Streams -- The base endpoint is: **ws://[wbs-api.mexc.com/ws](http://wbs-api.mexc.com/ws)** +- The base endpoint is: **[ws://wbs-api.mexc.com/ws](http://wbs-api.mexc.com/ws)** - Each connection to **wbs.mexc.com** is valid for no more than 24 hours. Please handle disconnections and reconnections properly. - All trading pair names in the symbol must be in **uppercase**. For example: `spot@public.deals.v3.api.pb@` Example: `spot@public.deals.v3.api.pb@BTCUSDT` From 32d517c21cee8091b13b1e18954934ffd970b619 Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Mon, 24 Feb 2025 18:55:26 +0800 Subject: [PATCH 23/35] Update index.html.md --- source/index.html.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/index.html.md b/source/index.html.md index e8ca80d..a74fb8e 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -70,6 +70,9 @@ To apply for a partnership, please contact: **institution@mexc.com** # Change Log +## **2025-02-24** +- Update Protocol Buffers websocket channels + ## **2024-10-17** - Add Query Kyc status endpoint From 5ec083ad264def7d006fabf2afa454071670b2c2 Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Tue, 25 Feb 2025 00:43:01 +0800 Subject: [PATCH 24/35] Update index.html.md --- source/index.html.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/index.html.md b/source/index.html.md index a74fb8e..a12916f 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -3663,13 +3663,13 @@ The current websocket push uses the protobuf format. The specific integration pr > **Java** ```shell - protoc --java_out=custom_path/java-out -I=custom_path/proto-v3-api custom_path/proto-v3-api/*.proto + protoc *.proto --java_out=python custom_path ``` > **Python** ```shell - protoc --python_out=custom_path/python-out -I=custom_path/proto-v3-api custom_path/proto-v3-api/* + protoc *.proto --python_out=python custom_path ``` > **Others** From 0bb7a5c2334975cd82fb9d2d16ebda5fb3fe69b6 Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Tue, 25 Feb 2025 15:42:30 +0800 Subject: [PATCH 25/35] Update index.html.md --- source/index.html.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/index.html.md b/source/index.html.md index a12916f..28f86be 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -3655,7 +3655,7 @@ Response: The current websocket push uses the protobuf format. The specific integration process is as follows: 1.**PB File Definition** - The PB definition files can be obtained via the provided link. + The PB definition files can be obtained via the provided link:[https://github.com/mexcdevelop/websocket-proto](https://github.com/mexcdevelop/websocket-proto) 2.**Generate Deserialization Code** Use the tool available at [https://github.com/protocolbuffers/protobuf](https://github.com/protocolbuffers/protobuf) to compile the .proto files and generate deserialization code. From 0a319947990f384b0855eb8da9b71df70b25821f Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Tue, 25 Feb 2025 16:04:51 +0800 Subject: [PATCH 26/35] Update index.html.md --- source/index.html.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/index.html.md b/source/index.html.md index 28f86be..43a26f4 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -3699,7 +3699,7 @@ The current websocket push uses the protobuf format. The specific integration pr // Assemble the object PushDataV3ApiWrapper pushDataV3ApiWrapper = PushDataV3ApiWrapper.newBuilder() - .setChannel("spot@public.increase.depth.v3.api.pb") + .setChannel("spot@public.aggre.depth.v3.api.pb") .setSymbol("BTCUSDT") .setSendTime(System.currentTimeMillis()) .build(); @@ -3720,7 +3720,7 @@ The current websocket push uses the protobuf format. The specific integration pr # Assemble the object pushData = PushDataV3ApiWrapper_pb2.PushDataV3ApiWrapper() - pushData.channel = 'spot@public.increase.depth.v3.api.pb' + pushData.channel = 'spot@public.aggre.depth.v3.api.pb' pushData.symbol = 'BTCUSDT' # Serialize to a string From 0a7d95667df782aa51c260b210ab8d7054e8ac22 Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Mon, 3 Mar 2025 16:19:49 +0800 Subject: [PATCH 27/35] Update index.html.md --- source/index.html.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/index.html.md b/source/index.html.md index 43a26f4..9fbbf5b 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -3699,7 +3699,7 @@ The current websocket push uses the protobuf format. The specific integration pr // Assemble the object PushDataV3ApiWrapper pushDataV3ApiWrapper = PushDataV3ApiWrapper.newBuilder() - .setChannel("spot@public.aggre.depth.v3.api.pb") + .setChannel("spot@public.aggre.depth.v3.api.pb@10ms") .setSymbol("BTCUSDT") .setSendTime(System.currentTimeMillis()) .build(); @@ -3720,7 +3720,7 @@ The current websocket push uses the protobuf format. The specific integration pr # Assemble the object pushData = PushDataV3ApiWrapper_pb2.PushDataV3ApiWrapper() - pushData.channel = 'spot@public.aggre.depth.v3.api.pb' + pushData.channel = 'spot@public.aggre.depth.v3.api.pb@10ms' pushData.symbol = 'BTCUSDT' # Serialize to a string From 157973956dcf97249f83cfc023ffa7dc51cabccb Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Mon, 3 Mar 2025 17:12:43 +0800 Subject: [PATCH 28/35] Update index.html.md --- source/index.html.md | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/source/index.html.md b/source/index.html.md index 9fbbf5b..7b2ac2b 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -3637,7 +3637,7 @@ Response: # Websocket Market Streams - The base endpoint is: **[ws://wbs-api.mexc.com/ws](http://wbs-api.mexc.com/ws)** -- Each connection to **wbs.mexc.com** is valid for no more than 24 hours. Please handle disconnections and reconnections properly. +- Each connection to **[ws://wbs-api.mexc.com/ws](http://wbs-api.mexc.com/ws)** is valid for no more than 24 hours. Please handle disconnections and reconnections properly. - All trading pair names in the symbol must be in **uppercase**. For example: `spot@public.deals.v3.api.pb@` Example: `spot@public.deals.v3.api.pb@BTCUSDT` - If there is no valid subscription on the websocket, the server will actively disconnect after **30 seconds**. If the subscription is successful but there is no data flow, the server will disconnect after **one minute**. The client can send a ping to keep the connection alive. @@ -4216,16 +4216,18 @@ This batch aggregation version pushes the best order information for a specified ## How to Properly Maintain a Local Copy of the Order Book -1. Subscribe to `spot@public.aggre.depth.v3.api.pb@(100ms|10ms)@` to get full amount of depth information, save the current version. -2. Subscribe to ws depth information, if the received data version more than the current version after update, the later received update cover the previous one at the same price. -3. Through **https://api.mexc.com/api/v3/depth?symbol=MXBTC&limit=1000** to get the latest 1000 depth snapshots. -4. Discard version data from the snapshot obtained by Version (less than step 3 )for the same price in the current cached depth information -5. Update the contents of the deep snapshots to the local cache and keep updating from the event received by the WS -6. The version of each new event should be exactly equal to version+1 of the previous event, otherwise packet loss may occur. In case of packet loss or discontinuous version of the event retrieved, please re-initialize from Step 3. -7. The amount of hanging orders in each event represents the **absolute value** of the current hanging orders of the price, rather than the relative change. -8. If the amount of a hanging order corresponding to a certain price is 0, it means that the hanging order at that price has been cancelled, the price should be removed. - -Note: Because the depth snapshot has a limitation on the number of price levels, any price levels not included in the initial snapshot and without quantity changes will not appear in the incremental depth updates. Therefore, even after applying all incremental updates, these price levels may not be visible in your local order book, and there may be some discrepancies between your local order book and the real order book. However, for most use cases, a depth limit of 5000 levels is sufficient to understand the market and trading activity effectively. +1. Connect to the WebSocket and subscribe to `spot@public.aggre.depth.v3.api.pb@(100ms|10ms)@MXBTC` to obtain incremental aggregated depth information. +2. Access the REST API `https://api.mexc.com/api/v3/depth?symbol=MXBTC&limit=1000` to obtain a depth snapshot with 1000 levels. +3. The `fromVersion` of each new push message should be exactly equal to the `toVersion + 1` of the previous message. Otherwise, packet loss has occurred, and reinitialization from step 2 is required. +4. The order quantity in each push message represents the absolute value of the current order quantity at that price level, not a relative change. +5. If the `toVersion` in the push message is smaller than the `version` in the snapshot, the message is outdated and should be ignored. +6. If the `fromVersion` in the push message is greater than the `version` in the snapshot, data is missing between the push message and the snapshot, requiring reinitialization from step 2. +7. Now that the `version` in the snapshot falls within the `[fromVersion, toVersion]` range of the push message, the push message can be integrated with the snapshot data 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 a new entry with the quantity from the push message. + - If a price level in the push message has a quantity of 0, remove that price level from the snapshot. + +**Note:** Since the depth snapshot has a limitation on the number of price levels, price levels outside the initial snapshot that have not changed in quantity will not appear in incremental push messages. Therefore, the local order book may differ slightly from the real order book. However, for most use cases, the 5000-depth limit is sufficient to effectively understand the market and trading activity. --- From 27bb1e2e93c1f3b6263c315b5393b3da745f7f55 Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Mon, 3 Mar 2025 17:29:30 +0800 Subject: [PATCH 29/35] Update build.yml --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ba682bd..c109a8b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,7 @@ jobs: with: ruby-version: ${{ matrix.ruby-version }} - - uses: actions/cache@v2 + - uses: actions/cache@v3 with: path: vendor/bundle key: gems-${{ runner.os }}-${{ matrix.ruby-version }}-${{ hashFiles('**/Gemfile.lock') }} From 935873d3a2dbd3242232cd8e0cf6fd75b7100e0c Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Mon, 3 Mar 2025 22:30:48 +0800 Subject: [PATCH 30/35] update --- .github/workflows/deploy.yml | 2 +- .github/workflows/dev_deploy.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 307f309..6163691 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -20,7 +20,7 @@ jobs: with: ruby-version: ${{ env.ruby-version }} - - uses: actions/cache@v2 + - uses: actions/cache@v3 with: path: vendor/bundle key: gems-${{ runner.os }}-${{ env.ruby-version }}-${{ hashFiles('**/Gemfile.lock') }} diff --git a/.github/workflows/dev_deploy.yml b/.github/workflows/dev_deploy.yml index 198640a..8b08d0a 100644 --- a/.github/workflows/dev_deploy.yml +++ b/.github/workflows/dev_deploy.yml @@ -35,7 +35,7 @@ jobs: with: ruby-version: ${{ env.ruby-version }} - - uses: actions/cache@v2 + - uses: actions/cache@v3 with: path: vendor/bundle key: gems-${{ runner.os }}-${{ env.ruby-version }}-${{ hashFiles('**/Gemfile.lock') }} From 2070cbe75ce63a89dda0830538b51e1d5b7936d7 Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Thu, 10 Apr 2025 07:49:44 +0800 Subject: [PATCH 31/35] Update index.html.md --- source/index.html.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/index.html.md b/source/index.html.md index 7b2ac2b..b080899 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -1895,7 +1895,7 @@ MARKET: When type is market, `quoteOrderQty` or `quantity` required to choose a ## Batch Orders -Supports 30 orders with a same symbol in a batch,rate limit:2 times/s. +Supports 20 orders with a same symbol in a batch,rate limit:2 times/s. > Request @@ -1953,7 +1953,7 @@ Parameters: | Name | type | Mandatory | Description | | :--------------- | :------ | :------- |:-------------------------------------------| -| batchOrders | LIST | YES | list of batchOrders,supports max 30 orders | +| batchOrders | LIST | YES | list of batchOrders,supports max 20 orders | | symbol | STRING | YES | symbol | | side | ENUM | YES | order side | | type | ENUM | YES | order type | @@ -2121,7 +2121,7 @@ Response: "orderListId": -1, "clientOrderId": "myOrder1", "price": "0.1", - "origQty": "1.0", + "Qty": "1.0", "executedQty": "0.0", "cummulativeQuoteQty": "0.0", "status": "NEW", @@ -2164,7 +2164,7 @@ Response: | orderId | order id | | clientOrderId | client order id | | price | Price | -| origOty | Original order quantity | +| Qty | Original order quantity | | executedQty | Executed order quantity | | cummulativeQuoteQty | Cummulative quote quantity | | status | order status | From 833df7b2fcb02a615264b1f3f1657d8018739dce Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Thu, 12 Jun 2025 02:08:08 +0800 Subject: [PATCH 32/35] Update index.html.md --- source/index.html.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/index.html.md b/source/index.html.md index b080899..9ae73de 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -2791,7 +2791,7 @@ Response: |amount|deposit amount| |coin|coin | |network|deposit network| -|status|deposit status,1:SMALL,2:TIME_DELAY,3:LARGE_DELAY,
4:PENDING,5:SUCCESS,6:AUDITING,7:REJECTED| +|status|deposit status,1:SMALL,2:TIME_DELAY,3:LARGE_DELAY,
4:PENDING,5:SUCCESS,6:AUDITING,7:REJECTED
8:REFUND,9:PRE_SUCCESS,10:INVALID,
11:RESTRICTED,12:COMPLETED| |address|deposit adress| |addressTag|addressTag| |txId|txId| @@ -3536,7 +3536,7 @@ If startTime and endTime are not provided, will default to returning data from t |amount |amount| |fromAccountType |fromAccountType| |toAccountType |toAccountType| -|status |status| +|status |status:"SUCCESS","FAILED","WAIT"| |timestamp |timestamp| ## Withdraw(previous,offline soon) From 00207be81adf841cd823b0a09d8a3b3301e7d61c Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Fri, 25 Jul 2025 12:41:01 +0800 Subject: [PATCH 33/35] Update index.html.md --- source/index.html.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/source/index.html.md b/source/index.html.md index 9ae73de..8a847e7 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -2148,7 +2148,7 @@ Parameters: | Name | Type | Mandatory | Description | | ----------------- | ------ | --------- | ----------- | -| symbol | String | YES | | +| symbol | String | No | | | origClientOrderId | String | NO | | | orderId | String | NO | | | recvWindow | long | NO | | @@ -3956,7 +3956,8 @@ Available intervals: } ], "eventtype": "spot@public.aggre.depth.v3.api.pb@100ms", // Event type - "version": "36913293511" // Version number + "fromVersion" : "10589632359", // from Version number + "toVersion" : "10589632359" // to Version number }, "symbol": "BTCUSDT", // Trading pair "sendtime": 1736411507002 // Event time @@ -3974,13 +3975,14 @@ If the order quantity (`quantity`) for a price level is 0, it indicates that the | price | string | Price level of change | | quantity | string | Quantity | | eventtype | string | Event type | -| version | string | Version number | +| fromversion | string | From Version number | +| toversion | string | To Version number | | symbol | string | Trading pair | | sendtime | long | Event time | --- -## Diff.Depth Stream(Batch Aggregation) + ## Partial Book Depth Streams From b251b73f2a705c428f8236100b3e1a40190ee13d Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Fri, 8 Aug 2025 06:37:39 +0800 Subject: [PATCH 34/35] Update index.html.md --- source/index.html.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/index.html.md b/source/index.html.md index 8a847e7..6b1eb35 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -3639,7 +3639,7 @@ Response: - The base endpoint is: **[ws://wbs-api.mexc.com/ws](http://wbs-api.mexc.com/ws)** - Each connection to **[ws://wbs-api.mexc.com/ws](http://wbs-api.mexc.com/ws)** is valid for no more than 24 hours. Please handle disconnections and reconnections properly. - All trading pair names in the symbol must be in **uppercase**. For example: `spot@public.deals.v3.api.pb@` - Example: `spot@public.deals.v3.api.pb@BTCUSDT` + Example: `spot@public.aggre.deals.v3.api.pb@100ms@BTCUSDT` - If there is no valid subscription on the websocket, the server will actively disconnect after **30 seconds**. If the subscription is successful but there is no data flow, the server will disconnect after **one minute**. The client can send a ping to keep the connection alive. - One ws connection supports a maximum of 30 subscriptions. - Please process the data according to the parameters returned in the documentation. Parameters not returned in the documentation will be optimized soon, so please do not use them. @@ -3742,7 +3742,7 @@ The current websocket push uses the protobuf format. The specific integration pr { "id": 0, "code": 0, - "msg": "spot@public.deals.v3.api.pb@BTCUSDT" + "msg": "spot@public.aggre.deals.v3.api.pb@100ms@BTCUSDT" } ``` @@ -3751,7 +3751,7 @@ The current websocket push uses the protobuf format. The specific integration pr { "method": "SUBSCRIPTION", - "params": ["spot@public.deals.v3.api.pb@BTCUSDT"] + "params": ["spot@public.aggre.deals.v3.api.pb@100ms@BTCUSDT"] } @@ -3774,7 +3774,7 @@ The current websocket push uses the protobuf format. The specific integration pr { "method": "UNSUBSCRIPTION", - "params": ["spot@public.deals.v3.api.pb@BTCUSDT"] + "params": ["spot@public.aggre.deals.v3.api.pb@100ms@BTCUSDT"] } From b46acb84065a5f4170cbf81f500c96d24f5cfb99 Mon Sep 17 00:00:00 2001 From: "ross.H" Date: Fri, 8 Aug 2025 06:41:46 +0800 Subject: [PATCH 35/35] Update index.html.md --- source/index.html.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/index.html.md b/source/index.html.md index 6b1eb35..29d7aab 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -3638,7 +3638,7 @@ Response: - The base endpoint is: **[ws://wbs-api.mexc.com/ws](http://wbs-api.mexc.com/ws)** - Each connection to **[ws://wbs-api.mexc.com/ws](http://wbs-api.mexc.com/ws)** is valid for no more than 24 hours. Please handle disconnections and reconnections properly. -- All trading pair names in the symbol must be in **uppercase**. For example: `spot@public.deals.v3.api.pb@` +- All trading pair names in the symbol must be in **uppercase**. For example: `spot@public.aggre.deals.v3.api.pb@(100ms|10ms)@` Example: `spot@public.aggre.deals.v3.api.pb@100ms@BTCUSDT` - If there is no valid subscription on the websocket, the server will actively disconnect after **30 seconds**. If the subscription is successful but there is no data flow, the server will disconnect after **one minute**. The client can send a ping to keep the connection alive. - One ws connection supports a maximum of 30 subscriptions.