The process for generation of the API Key is as follows:
To create a new key, Navigate to the API Dashboard. Click Create API Key, and you will be redirected to the Create an API Key window.
Provide a name for your API key and choose the necessary permissions. Additionally, select the option to Bind the IP Address to the API Key, if needed.
Note(i): Enabling the "Bind IP address to API Key" option enhances security by ensuring that the API key is only valid for requests originating from a specific IP address. This minimizes the risk of unauthorized access, as the key cannot be used from any other IP address
You can bind the API key to multiple IP addresses by entering them as a comma-separated list.
Click on Save. A One Time Password (OTP) will be shared on your registered Email ID and Mobile number.
Enter the received OTP in the respective boxes. An API Key will be generated.
Store the API Key and Secret on the following screens properly
To authenticate API requests, clients must generate an HMAC-SHA256 signature using their API secret and send it in the request header. The API key must also be included in the request headers.
X-AUTH-APIKEY: Your API key.
X-AUTH-SIGNATURE: HMAC-SHA256 signature of the payload using your API secret.
The generated signature is a hexadecimal (hex) encoded string. This means that after computing the HMAC-SHA256 hash of the payload using the API secret, the output is converted into a lowercase hexadecimal string representation.
1. Determine the payload:
For GET and DELETE requests: Use the query parameters as the payload.
For POST and PUT requests: Use the request body as the payload.
2. Generate the HMAC-SHA256 signature by hashing the payload with the API secret.
3. Convert the computed hash to a hex string.
There are two segments in Websocket collection:
Users can subscribe to the WebSocket to receive real-time updates on market data, such as the order book, trades, and ticker information.
Websocket Endpoint:
socket.zebapi.com/api/v1/websocket/public
Live Subscribing/Unsubscribing
The following data can be sent through the WebSocket instance to subscribe or unsubscribe.
{
"request": <request-path>
}
{
"request": <request-path>,
"subscribe": false,
}
It pushes the order book snapshot, trade data, and ticker information for a trading pair.
Request path: exchange/<symbol>
{
"request": "exchange/BTC-INR"
}
// Last 24 hour Price Change percentage
{
"data": -1.78,
"requestType": "BTC-INR",
"type": "exchange-pricechange"
}
// Last 24 hour volume
{
"data": 1.5,
"requestType": "BTC-INR",
"type": "exchange-volumechange"
}
// Last 24 hour exchange high price
{
"data": 6299991,
"requestType": "BTC-INR",
"type": "exchange-high"
}
// Last 24 hour exchange low price
{
"data": 4899108.005,
"requestType": "BTC-INR",
"type": "exchange-low"
}
// Order book snapshot
{
"data": {
"asks": [
{
"amount": 6000,
"price": "5885000"
},
{
"amount": 7347,
"price": "5907694.21"
},
{
"amount": 126049,
"price": "5950000"
},
…
],
"bids": [
{
"amount": 579032,
"price": "5882166.82"
},
{
"amount": 169454,
"price": "5880000"
},
…
]
},
"requestType": "BTC-INR",
"type": "exchange-book"
}
// Executed trades
{
"data": {
"fill_flags": 1,
"fill_price": 2102991,
"is_buyer": "maker" or "taker",
"fill_qty": 4758,
"inbound_order_filled": true,
"lastModifiedDate": 1677154922164,
"trans_id": 871549,
},
"requestType": "BTC-INR",
"type": "exchange-fill"
}
// Top Buy Price
{
"data": 5885000,
"requestType": "BTC-INR",
"type": "exchange-topbuy"
}
// Top Sell Price
{
"data": 5882166.82,
"requestType": "BTC-INR",
"type": "exchange-topsell"
}
// Last traded price
{
"data": 5882166.82,
"requestType": "BTC-INR",
"type": "exchange-marketprice"
}
The buy and sell prices in Quick Trade can be retrieved by subscribing to the Quick Trade updates.
Request path: qt/<symbol>
{
"request": "qt/BTC-INR"
}
{
"data": {
"BTC-INR": {
"BuyRate": 5969972.00442825,
"LTP": 5902775.445,
"PercentChange": "0.15",
"SellRate": 5864271.73969875
}
},
"type": "qt-instant-trade-rate"
}
The ticker data for all pairs on the exchange can be retrieved by subscribing to Exchange Trending updates.
Request path: exchange/trending/<mother_currency>/<quote_currency>/data
{
"request": "exchange/trending/INR/INR/data"
}
{
"data": [
{
"CurrencyCode": "BTC",
"CurrencyHoverImage": "https://static.zebpay.com/multicoins/ic_coin_bitcoin_hover.png",
"CurrencyName": "Bitcoin",
"IsNew": false,
"MessageText": "",
"PercentDiff": -2.42,
"Rate": 5840000,
"Sender": "Zrevamp.Trade",
"Sequence": 4,
"TradeValue": 451291.13,
"Volume": 0.07727588
},
{
"CurrencyCode": "MATIC",
"CurrencyHoverImage": "https://static.zebpay.com/multicoins/ic_coin_polygon_hover.png",
"CurrencyName": "Polygon",
"IsNew": false,
"MessageText": "",
"PercentDiff": -28.75,
"Rate": 65.19725,
"Sender": "Zrevamp.Trade",
"Sequence": 5,
"TradeValue": 421320.26,
"Volume": 6462.2398
},
...
],
"requestType": "INR/INR",
"type": "exchange-trending"
}
The ticker data for all pairs in Quick Trade can be retrieved by subscribing to Quick Trade Trending updates.
Request path: qt/trending/<mother_currency>/<quote_currency>/data
{
"request": "qt/trending/INR/INR/data"
}
{
"data": [
{
"CurrencyCode": "BTC",
"CurrencyName": "Bitcoin",
"IsNew": false,
"MessageText": "",
"PercentDiff": -2.06,
"Rate": 5902484.56,
"SellRate": 5798607.26,
"Sender": "Zrevamp.Trade",
"Sequence": 10,
"TradeRateBefore24Hours": 6027030.1005408,
"TradeValue": 1080140.15,
"Volume": 0.18299754
},
{
"CurrencyCode": "ETH",
"CurrencyName": "Ether",
"IsNew": false,
"MessageText": "",
"PercentDiff": -0.86,
"Rate": 290244.25,
"SellRate": 285124.2,
"Sender": "Zrevamp.Trade",
"Sequence": 11,
"TradeRateBefore24Hours": 292788.076028,
"TradeValue": 1004865.33,
"Volume": 3.46213681
},
...
],
"requestType": "INR/INR",
"type": "qt-trending"
}
{
"request": "PING"
}
{
"response": "PONG"
}
The client disconnects the socket connection if no messages are sent or received for 1 minute.
To disconnect or close the socket connection, you can send the following request.
{
"request": "STOP"
}
User can listen to websocket for fetching the real time updates on user data like balance and order.
Websocket Endpoint:
socket.zebapi.com/api/v1/websocket/public
Live Subscribing/Unsubscribing:
The following data can be sent through the websocket instance in order to subscribe/unsubscribe.
{
"request": <request-path>,
"token": <auth_token>
}
{
"request": <request-path>,
"subscribe": false
}
It provides wallet balance information whenever there is a change in the wallet balance.
Request path: balance
{
"request": "balance"
"token": "<auth_token>"
}
{
"data": [
{
"currency": "INR",
"balance": "6280469.9",
"last_updated": "1723805866866",
"pending_trade_balance": "769.4",
"isVirtual": false,
"lending_balance": "0",
"pack_balance": "0",
"qt_locked_balance": "15420.44"
},
{
"currency": "BTC",
"balance": "2501.86179663",
"last_updated": "1723805866866",
"pending_trade_balance": "0",
"isVirtual": true,
"lending_balance": "4.60763963",
"pack_balance": "0.0113988",
"qt_locked_balance": "0"
}
],
"type": "BALANCE"
}
It provides information related to orders.
Request path: order
{
"request": "order"
"token": "<auth_token>"
}
{
"data": [
{
"id": 5781331,
"tradePair": "BTC-INR",
"status": "OPEN",
"side": "Bid",
"orderType": "LIMIT",
"avgPrice": "0",
"price": "5883917.16",
"size": "0.00013",
"volumeOpen": "0.00013",
"volumeExecuted": "0",
"fee": "0",
"tradeValue": "0",
"marketOrderAmount": "0",
"stopPrice": "0",
"tax": "0",
"tds": "0",
"createdAt": 1723642482773
},
{
"id": 5781451,
"tradePair": "ETH-INR",
"status": "OPEN",
"side": "Bid",
"orderType": "LIMIT",
"avgPrice": "0",
"price": "408121.98",
"size": "0.002",
"volumeOpen": "0.002",
"volumeExecuted": "0",
"fee": "0",
"tradeValue": "0",
"marketOrderAmount": "0",
"stopPrice": "0",
"tax": "0",
"tds": "0",
"createdAt": 1723806235036
},
{
"id": 5781450,
"tradePair": "ETH-INR",
"status": "OPEN",
"side": "Bid",
"orderType": "LIMIT",
"avgPrice": "0",
"price": "408121.98",
"size": "0.001",
"volumeOpen": "0.001",
"volumeExecuted": "0",
"fee": "0",
"tradeValue": "0",
"marketOrderAmount": "0",
"stopPrice": "0",
"tax": "0",
"tds": "0",
"createdAt": 1723806192664
}
],
"type": "ORDER"
}
{
"request": "PING"
}
{
"response": "PONG"
}
The client disconnects the socket connection if no messages are sent or received for 1 minute.
To disconnect or close the socket connection, you can send the following request.
{
"request": "STOP"
}
There are two segments in Futures websocket collection:
Market Data Streams provide real-time access to essential market information through WebSocket connections. By subscribing to specific streams, users can receive live updates on various market metrics. Following streams are available to subscribe to:
Connection Setup:
To access public market data streams, establish a WebSocket connection to the following URL using a socket client like socket.io
WS URL:
wss://futuresws.zebpay.com/socket.io
Namespace: /
Subscribing & Unsubscribing to Data Streams:
The WebSocket connection allows users to subscribe to different data streams and receive real-time updates on market events.
Subscribe to Data Streams:
Send a message with the "subscribe" action, specifying the streams you want to receive in the params list
Unsubscribe from Data Streams:
To stop receiving data from a specific stream, send an unsubscribe message specifying the stream names in the params list.
Listening to Events:
Upon successful subscription, the WebSocket server will emit events whenever there is new data for the subscribed streams.
Each event type has a unique payload structure as detailed below.
Action: send
Message Name: "subscribe"
Message Data:
{
"params":[
"btcinr@kline_1m",
"btcinr@markPrice" //streamsto subscribe to
]
}
Action: send
Message Name: "unsubscribe"
Message Data:
{
"params": [
"btcinr@kline_1m",
"btcinr@markPrice" //streams to unsubscribe from
]
}
Provides real-time updates to the order book's bids (buy orders) and asks (sell orders) for a specific symbol, showing the depth of market liquidity.
Action: receive
Message Name: "depthUpdate"
Message Data:
{
"e": "depthUpdate", // Event type
"E": 1707636353921, // Event time (in ms)
"T": 1707636353915, // Transaction time (in ms)
"s": "BTCINR", // Symbol
"U": 3960811287130, // First update ID in event
"u": 3960811297623, // Last update ID in event
"pu": 3960811281312, // Previous final update ID
"b": [ // Bids (buy orders) array
["4240107.8", "0.710"], // [Price, Quantity]
["4240116.5", "0.230"]
],
"a": [ // Asks (sell orders) array
["4240353.6", "17.892"], // [Price, Quantity]
["4240362.4", "1.206"]
]
}
Provides real-time candlestick data for a specified trading interval, including open, close, high, low, and volume information.
Action: receive
Message Name: "kline"
Message Data:
{
"e": "continuous_kline", // Event type
"E": 1730749500239, // Event time
"ps": "ETHINR", // Symbol
"ct": "PERPETUAL", // Contract type
"k": {
"t": 1730749500000, // Kline start time
"T": 1730750399999, // Kline close time
"i": "1m", // Interval (15 minutes)
"f": 1, // First update ID
"L": 1, // Last update ID
"o": "211211", // Open price
"c": "211224", // Close price
"h": "211467", // High price
"l": "211188", // Low price
"v": "778.018", // Volume
"n": 1, // Number of trades
"x": false, // Is this kline closed?
"q": null, // Quote asset volume (null here)
"V": null, // Taker buy volume (null here)
"Q": null, // Taker buy quote asset volume
"B": null // Ignore
}
}
Real-time details of aggregated trades grouped by price for a specific symbol.
Action: receive
Message Name: "aggTrade"
Message Data:
{
"e": "aggTrade", // Event type
"E": 1730749897776, // Event time
"a": 1828600727, // Aggregate trade ID
"s": "ETHINR", // Symbol
"p": "211156", // Price
"q": "0.211", // Quantity
"f": 4586488827, // First trade ID
"l": 4586488828, // Last trade ID
"T": 1730749897666, // Trade time
"m": true // Is the buyer the market maker?
}
Provides the mark price, index price, and funding rate for a specific symbol.
Action: receive
Message Name: "markPriceUpdate"
Message Data:
{
"e": "markPriceUpdate", // Event type
"E": 1707634490000, // Event time
"s": "BTCINR", // Symbol
"p": "4334823.66859808", // Market price
"P": "4335379.542328075", // Estimated settle price
"i": "4336589.925536482", // Index price
"r": "-0.0027", // Funding rate
"T": 1707638400000 // Next funding time
}
Provides rolling 24-hour price statistics, including last trade price, highest/lowest prices, and volume.
Action: receive
Message Name: "24hrTicker"
Message Data:
{
"e": "24hrTicker", // Event type
"E": 1707635719309, // Event time
"s": "BTCINR", // Symbol
"p": "87845.124", // Price change over 24 hours
"P": "2.116", // Price change percentage
"w": "4188295.5225", // Weighted average price
"c": "4239633.639", // Last price
"Q": "0.003", // Last quantity
"o": "4151788.515", // Open price
"h": "4267566", // High price
"l": "4112704.2840000005", // Low price
"v": "222797.117", // Base asset volume
"q": "10626810856.19", // Quote asset volume
"O": 1707549300000, // Open time
"C": 1707635719307, // Close time
"F": 4575372791, // First trade ID
"L": 4578191477, // Last trade ID
"n": 2818668 // Number of trades
}
Provides general details for all contracts, including last trade price, market price, and 24-hour price change percentage.
Action: receive
Message Name: "allContractDetails"
Message Data:
{
"XRPINR": {
"lastPrice": "46.2545", // Last trade price
"marketPrice": "46.2366455382", // Current market price
"priceChangePercent": "0.725", // 24-hr price change %age per
"baseAssetVolume": "487166675.8" // base asset volume in 24 hrs
},
"MATICINR": {
"lastPrice": "74.9827",
"marketPrice": "75.02073812399999",
"priceChangePercent": "0.845",
"baseAssetVolume": "236293682"
},
// Additional symbols...
}
The private socket API enables real-time access to user-specific data such as order updates, position status, and balance changes. This secure data stream requires authentication via the access_token.
Connection Setup:
To access private user order specific data streams, establish a WebSocket connection to the following URL using a socket client like socket.io
WS URL:
wss://futuresws.zebpay.com/socket.io
Namespace: /auth-stream
Authentication:
The private socket requires clients to pass an access_token and client_type during the handshake.
The token should be included as part of the auth object in the WebSocket client’s connection request.
Listening to Events:
To listen for events, establish a WebSocket connection with the required authentication token and client type fields.
Each event type has its own payload structure as defined below.
{
"url": "wss://futuresws.zebpay.com/socket.io",
"namespace": "/auth-stream",
"transport": "websocket",
"auth": {
"token": "access_token", // JWT token for authentication
"clientType": "api" // 'api' for api client type
}
}
Order-related events for actions like filled, partially filled, canceled, failed, and new orders.
Listening Event Name:
1. newOrder: New active order in the open order book.
Action: receive
Message Name: "newOrder" or “orderFilled or “orderPartiallyFilled”, “orderCancelled” or “orderFailed”
Message Data:
{
"eventTime": "1696425435000000000",
"accountId": 5,
"orderId": 3133,
"clientOrderId": "07227f7c2236b71b4b31-5-ext",
"time": "2024-05-10T13:26:00.144Z",
"updateTime": "2024-05-10T13:26:00.237Z",
"symbol": "BTCINR",
"baseAsset": "BTC",
"quoteAsset": "INR",
"contractType": "PERPETUAL",
"type": "MARKET",
"side": "BUY",
"price": 5739874,
"status": "NEW",
"avgPrice": 0,
"executedPrice": 0,
"orderAmount": 0.002,
"executedAmount": 0,
"filledAmount": 0,
"cumQty": 0,
"linkId": "07227f7c2236b71b4b31-5-ext",
"linkType": "ORDER",
"subType": "PRIMARY",
"placeType": "ORDER_FORM",
"market": "INR",
"marginAsset": "INR"
}
Position-related events for new, updated, and closed positions.
Event Types:
1. newPosition: Creates a new entry in the position book.
Action: receive
Message Name: "newPosition" or "updatePosition" or "closePosition"
Message Data:
{
"eventTime": "1696425435000000000",
"accountId": 5,
"contractPair": "BTCINR",
"contractType": "PERPETUAL",
"entryPrice": 5705246,
"leverage": 10,
"liquidationPrice": 5199116,
"marginType": "ISOLATED",
"margin": 3441.36,
"positionAmount": 0.002,
"positionId": "3aa3b75a-20fb-4f1f-a49f-333bc45559c3",
"positionSize": 34231.48,
"positionStatus": "OPEN",
"positionType": "LONG",
"realizedProfit": 0,
"quantity": 0.006,
"market": "INR",
"marginAsset": "INR",
"marginConversionRate": 1,
"marginSettlementRate": 1,
"marginInMarginAsset": 3441.36,
"realizedProfitInMarginAsset": 0
}
Real-time updates to user balances, including total, locked, and available balances.
Event Types:
balanceUpdate: Provides any update to the user’s wallet balances.
Action: receive
Message Name: "balanceUpdate"
Message Data:
{
"eventTime": "1696425435000000000", // Event timestamp in nanosecs
"accountId": 7, // account ID
"updatedWalletBalance": 1989.26, // Total balance after update
"updatedLockedBalance": 1053.18, // Balance currently locked
"updatedAvailableBalance": 936.08, // Balance available for use
"asset": "INR" // Asset in which bal is updated
}
Triggered when a new trade is executed for a specific account. Provides details of the trade.
Listening Event Name: newTrade
Action: receive
Message Name: "newTrade"
Message Data:
{
"eventTime": "1696425435000000000", // in nanosecs
"accountId": 5, // ID of the user account
"tradeId": 2616, // Unique trade identifier
"clientOrderId": "be9c210d2934b67b7a82-5-ext",
"tradeTime": "2024-05-10T13:28:36.377Z",
"symbol": "BTCINR", // Trading pair symbol
"side": "BUY",
"executedPrice": 5701423,
"executedQuantity": 0.029,
"fee": 0, // Fee for the trade
"realizedPnl": 0,
"role": "maker",
"market": "INR",
"marginAsset": "INR",
"positionId": "examplePositionId" // Position ID linked to trade
}
Events triggered to notify the user when they are over leveraged or have been liquidated.
Event Types:
1. marginCallAlert: Triggered when the utilisation ratio hits 80%
Action: receive
Message Name: "marginCallAlert"
Message Data:
{
"eventTime": "1696425435000000000", // margin call ts in nanosecs
"accountId": 7,
"contractPair": "BTCINR",
"marginRequired": 500.00, // margin reqd to prevent liquidation
"currentMargin": 200.00, // current margin level for the position
"positionType": "LONG",
"positionId": "88e19883-e7e2-4318-95ba-bb9db39117ad",
}
Action: receive
Message Name: "liquidationAlert"
Message Data:
{
"eventTime": "1696425435000000000", // liquidation ts in nanosecs
"accountId": 7,
"contractPair": "BTCINR",
"liquidationPrice": 3448000.64,
"positionType": "LONG",
"quantity": 0.003, // Qty of asset liquidated
"positionId": "88e19883-e7e2-4318-95ba-bb9db39117ad"
}