MEXC is a global cryptocurrency exchange that exposes streaming market and account data over secure WebSocket connections.
The WebSocket Spot API follows the specifications published in the Market Streams and User Data Streams documentation. Market channels are delivered as Protocol Buffers frames while private streams use JSON. The TsgcWSAPI_MEXC component manages the connection lifecycle, authentication and listen key maintenance so that applications can focus on processing the pushed data.
In addition to streaming over WebSockets, the toolkit also exposes the complete Spot HTTP API. The TsgcHTTP_API_MEXC_Spot component (unit sgcHTTP_API_MEXC) wraps every official REST endpoint so applications can query market data or trade with signed requests.
The base WebSocket endpoint is wss://wbs-api.mexc.com/ws. When MEXCUserDataStreams.UserStream is enabled and a valid API key is provided, the component automatically requests a listen key and appends it to the connection URL.
Drop a TsgcWebSocketClient and a TsgcWSAPI_MEXC component on the form (or create them in code), assign the client instance to the API component and activate the client to start the session.
TsgcWebSocketClient *WSClient = new TsgcWebSocketClient();
TsgcWSAPI_MEXC *MEXC = new TsgcWSAPI_MEXC();
MEXC->Client = WSClient;
MEXC->MEXCAPI->ApiKey = "YOUR_KEY";
MEXC->MEXCAPI->ApiSecret = "YOUR_SECRET";
MEXC->MEXCUserDataStreams->UserStream = true;
if (WSClient->Connect()) {
MEXC->SubscribeTrade("BTCUSDT");
}
The following sample demonstrates how to decode a trade frame:
The component exposes helpers for each public Spot channel. Invoke the Subscribe* method to start streaming data and the corresponding UnSubscribe* to stop it.
| Method | Parameters | Description |
| SubscribeTrade | Symbol, Interval (ms) | Aggregated trade executions delivered as Protobuf publicdeals. |
| SubscribeKline | Symbol, Interval | Candlestick updates for configurable intervals (1 minute to 1 month). |
| SubscribeDiffDepth | Symbol, Interval (ms) | Order book incremental depth deltas for local book maintenance. |
| SubscribeBookDepth | Symbol, Levels | Periodic snapshots of the limit order book with the requested depth (default 5). |
| SubscribeBookTicker | Symbol, Interval (ms) | Best bid/ask updates for a single trading pair. |
| SubscribeBookTickerBatch | UTC flag | Aggregated book ticker updates for multiple symbols. |
| SubscribeMiniTickers | UTC flag | Rolling 24h mini ticker statistics for all active instruments. |
| SubscribeMiniTicker | Symbol, UTC flag | Mini ticker for a single symbol. |
Private topics require a valid API key. The component subscribes using the active listen key and renews it periodically.
| Method | Description |
| SubscribeAccountUpdate | Account balance and position changes. |
| SubscribeAccountDeals | Execution reports for filled orders. |
| SubscribeAccountOrders | Order life-cycle updates (new, cancelled, rejected, etc.). |
Use the corresponding UnSubscribe* methods to terminate a stream. The component automatically sends PING commands and validates the returned PONG to monitor connectivity.
Publicly available REST methods.
| Method | Description |
| Ping | Connectivity check that calls /api/v3/ping and returns True when the exchange replies with an empty object. |
| GetServerTime | Retrieves the current exchange timestamp from /api/v3/time. |
| GetExchangeInformation | Returns trading rules and symbol metadata from /api/v3/exchangeInfo. |
| GetOrderBook | Downloads order book snapshots from /api/v3/depth; set the optional limit parameter to control the number of levels (default 100). |
| GetTrades | Retrieves recent public trades from /api/v3/trades with an optional limit (default 100). |
| GetHistoricalTrades | Provides historical trade data with optional limit and fromId filters. |
| GetAggregateTrades | Returns compressed/aggregated trades via /api/v3/aggTrades supporting optional limit, fromId, startTime and endTime filters. |
| GetKlines | Downloads candlesticks from /api/v3/klines supporting time range and limit filters. |
| GetAveragePrice | Returns the current weighted average price from /api/v3/avgPrice. |
| Get24hrTicker | Retrieves 24 hour ticker statistics for one or all symbols via /api/v3/ticker/24hr. |
| GetPriceTicker | Fetches the latest price using /api/v3/ticker/price; pass an empty symbol to retrieve prices for every trading pair. |
| GetBookTicker | Obtains best bid/ask quotes from /api/v3/ticker/bookTicker with support for single-symbol or full-exchange requests. |
Private endpoints require valid API keys and a signed query string. The component automatically appends the timestamp, recvWindow and HMAC signature.
| Method | Description |
| GetAccountInformation | Returns balances and permissions from /api/v3/account. |
| GetOpenOrders | Lists current open orders (optionally filtered by symbol). |
| GetAllOrders | Retrieves historical orders with optional time and limit filters. |
| GetOrder | Queries the status of a specific order by supplying either orderId or origClientOrderId. |
| GetMyTrades | Lists private trade executions with optional limit, fromId, startTime and endTime filters. |
| NewOrder | Places a live order on /api/v3/order (market, limit, stop, etc.) with optional timeInForce, quantity, quoteOrderQty, price, newClientOrderId, stopPrice, icebergQty and extra parameters. |
| TestNewOrder | Sends a validation-only request to /api/v3/order/test accepting the same parameter set as NewOrder. |
| CancelOrder | Cancels a specific order on /api/v3/order using orderId or origClientOrderId. |
| CancelAllOrders | Bulk cancels all open orders for a symbol via /api/v3/openOrders. |
| GetSubAccounts | Lists managed sub-accounts (/api/v3/sub-account/list). |
| GetSubAccountAssets | Returns balances for a specific sub-account. |
| TransferSubAccount | Transfers assets between sub-accounts through /api/v3/sub-account/transfer; provide the amount and optionally the transfer type. |
| GetDepositAddress | Requests deposit addresses with an optional network filter. |
| GetDepositHistory | Fetches deposit records with optional coin, status, startTime and endTime filters. |
| GetWithdrawHistory | Returns withdrawal history filtered by coin, status and optional time range. |
| Withdraw | Submits a withdrawal request via /api/v3/capital/withdraw/apply including the mandatory coin, address and amount plus optional network, addressTag, withdrawOrderId and extra parameters. |
| BatchOrders | Submit batch orders for multiple symbols in a single request. |
| GetTradeFee | Get the trade fee rate for a specific symbol. |
| GetDepositHistory | Fetches deposit records with optional coin, status, startTime and endTime filters. |
| CancelWithdraw | Cancel a pending withdrawal request by withdrawal ID. |
| CreateInternalTransfer | Transfer assets between accounts internally. |
| GetTransferHistory | Get the history of internal transfers between accounts. |