API MEXC Futures

MEXC perpetual and delivery contracts expose a dedicated streaming API documented in the official Futures WebSocket specification. The TsgcWSAPI_MEXC_Futures component encapsulates the connection, login handshake and topic management required to consume real-time derivatives data.

 

MEXC also maintains a REST interface for derivatives trading. The TsgcHTTP_API_MEXC_Futures component contained in sgcHTTP_API_MEXC complements the WebSocket feeds with HTTP helpers that map one-to-one to the official endpoints.

 

Component configuration

The Futures WebSocket endpoint is wss://contract.mexc.com/edge. Messages are encoded as JSON objects and the exchange requires periodic ping/pong frames which are handled automatically by the component.

 

To receive private notifications (order and account data) you must authenticate. Set MEXCAPI.ApiKey and MEXCAPI.ApiSecret before activating the WebSocket client. When credentials are present the component signs a login request (HMAC SHA256) as soon as the socket connects.

 

var
  WSClient: TsgcWebSocketClient;
  Futures: TsgcWSAPI_MEXC_Futures;
begin
  WSClient := TsgcWebSocketClient.Create(nil);
  Futures := TsgcWSAPI_MEXC_Futures.Create(nil);
  Futures.Client := WSClient;
  Futures.MEXCAPI.ApiKey := 'YOUR_KEY';
  Futures.MEXCAPI.ApiSecret := 'YOUR_SECRET';
  if WSClient.Connect then
    Futures.SubscribeDepth('BTC_USDT', True);
end;

 

Properties

 

Events

 

The following handler records subscription confirmations and prints incoming depth snapshots:

 

procedure TMainForm.MEXCSubscribed(Sender: TObject; const aChannel, aRaw: string);
begin
  Memo1.Lines.Add('Subscribed to ' + aChannel);
end;
procedure TMainForm.MEXCMessage(Sender: TObject; const aChannel, aRaw: string);
begin
  if SameText(aChannel, 'push.depth') then
    Memo1.Lines.Add(aRaw);
end;

 

WebSocket Subscription methods

Each helper wraps a sub/unsub request as described by the official API. Use the matching UnSubscribe* method to cancel the stream.

 

Method Parameters Description
SubscribeDeal Symbol Trades executed on the contract (channel: deal).
SubscribeTickers Global ticker statistics for all contracts.
SubscribeTicker Symbol Ticker summary for a single instrument.
SubscribeDepth Symbol, Compress Incremental order book updates 
SubscribeDepthFull Symbol, Level Full depth snapshots with configurable number of levels (default 20).
SubscribeKline Symbol, Interval Candlestick data for supported timeframes (Min1, Min5, Min15, Min30, Min60, Hour4, Hour12, Day1, Week1, Month1).
SubscribeFundingRate Symbol Latest funding rate announcements.
SubscribeIndexPrice Symbol Underlying index price stream.
SubscribeFairPrice Symbol Mark (fair) price updates pushed by the exchange.

 

When the server acknowledges a request the OnMEXCSubscribed event fires with the channel name (for example rs.sub.depth.BTC_USDT). Errors are forwarded through OnMEXCError including the server message for troubleshooting.

Private channels

Private channels require a valid API key. The component authenticates automatically when credentials are provided.

Method Description
SubscribePersonalOrder Personal order updates.
SubscribePersonalOrderDeal Personal order deal (fill) updates.
SubscribePersonalPosition Personal position updates.
SubscribePersonalPlanOrder Personal plan (trigger) order updates.
SubscribePersonalStopOrder Personal stop order updates.
SubscribePersonalStopPlanOrder Personal stop plan order updates.
SubscribePersonalRiskLimit Personal risk limit updates.
SubscribePersonalADLLevel Personal ADL (auto-deleveraging) level updates.
SubscribePersonalAsset Personal asset updates.

 

 

 

Public REST endpoints

Publicly available REST methods.

 

Method Description
GetPing Checks API reachability via /api/v1/ping.
GetServerTime Returns the server timestamp from /api/v1/time.
GetContracts Provides the list of available contracts (/api/v1/contract/detail).
GetDepth Downloads order book depth from /api/v1/contract/depth; use the optional limit parameter (default 50) to select the number of levels.
GetDeals Retrieves recent trades using /api/v1/contract/deals with an optional limit (default 100).
GetKlines Returns candlestick data through /api/v1/contract/kline with optional startTime, endTime and limit filters (default 200).
GetIndexPrice Fetches the underlying index price for the requested symbol (/api/v1/contract/indexPrice).
GetFairPrice Returns the fair (mark) price for a contract from /api/v1/contract/fairPrice.
GetFundingRate Reports the latest funding rate for a symbol using /api/v1/contract/fundingRate.
GetAllTickers Get all futures contract tickers with real-time price summaries.
GetFundingRateHistory Get historical funding rate records for a contract.
GetFairPriceKline Get fair (mark) price kline/candlestick data for a contract.
GetIndexPriceKline Get index price kline/candlestick data for a contract.

 

Private REST endpoints

Private derivatives endpoints require API credentials. The component signs each request with the timestamp and recvWindow automatically.

 

Method Description
GetAccountAssets Returns margin balances from /api/v1/private/account/assets.
GetPositionList Lists current positions via /api/v1/private/position/list, optionally filtered by symbol.
SetPositionLeverage Updates leverage for a symbol and, if supplied, the margin mode.
PlaceOrder Places a futures order on /api/v1/private/order providing symbol, side, positionSide, type and quantity plus optional price, clientOrderId and extra parameters.
CancelOrder Cancels a specific order using /api/v1/private/order/cancel by orderId or clientOrderId.
CancelAllOrders Cancels all open orders for a symbol via /api/v1/private/order/cancel-all.
GetOpenOrders Lists current open orders through /api/v1/private/order/list/open with an optional symbol filter.
GetOrderHistory Retrieves order history (/api/v1/private/order/list/history) with optional symbol, time range and limit parameters.
GetFundingHistory Returns past funding payments from /api/v1/private/account/funding with optional startTime, endTime and limit filters.
GetOpenPositions Get all currently open positions.
ChangeMargin Change the margin amount for a position.
GetPositionMode Get the current position mode (one-way or hedge mode).
ChangePositionMode Change the position mode between one-way and hedge mode.
PlaceBatchOrder Place multiple futures orders in a single batch request.
GetOrderDetail Get detailed information for a specific order.
GetOrderDealDetails Get fill/deal details for a specific order.
PlaceTriggerOrder Place a trigger (plan) order that executes when conditions are met.
CancelTriggerOrder Cancel a specific trigger order.
CancelAllTriggerOrders Cancel all open trigger orders.
GetTriggerOrders Get the list of trigger (plan) orders.
GetStopOrders Get the list of stop orders.
CancelStopOrder Cancel a specific stop order.
CancelAllStopOrders Cancel all open stop orders.