### Querying Order Book - Sample Request - HTTP Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md Provides a concrete example of a GET request URL to query the order book for the BTCUSDT trading pair using the /md/v2/orderbook endpoint. ```HTTP GET /md/v2/orderbook?symbol=BTCUSDT ``` -------------------------------- ### Sample Wallet-Order Messages (JavaScript) Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md Examples of actual Wallet-Order messages, showing both 'snapshot' and 'incremental' types with detailed order and wallet information. ```javascript < {"orders":{"closed":[{"action":"New","avgPriceEp":0,"baseCurrency":"BTC","baseQtyEv":10000,"bizError":0,"clOrdID":"123456","createTimeNs":1587463924959744646,"cumBaseQtyEv":10000,"cumFeeEv":0,"cumQuoteQtyEv":66900000,"curBaseWalletQtyEv":899990000,"curQuoteWalletQtyEv":66900000,"cxlRejReason":0,"feeCurrency":"BTC","leavesBaseQtyEv":0,"leavesQuoteQtyEv":0,"ordStatus":"Filled","ordType":"Limit","orderID":"35217ade-3c6b-48c7-a280-8a1edb88013e","pegOffsetValueEp":0,"priceEp":68000000,"qtyType":"ByBase","quoteCurrency":"USDT","quoteQtyEv":66900000,"side":"Sell","stopPxEp":0,"symbol":"sBTCUSDT","timeInForce":"GoodTillCancel","transactTimeNs":1587463924964876798,"triggerTimeNs":0,"userID":200076}],"fills":[{"avgPriceEp":0,"baseCurrency":"BTC","baseQtyEv":10000,"clOrdID":"123456","execBaseQtyEv":10000,"execFeeEv":0,"execID":"8135ebe3-f767-577b-b70d-1a839d5178e0","execPriceEp":669000000000,"execQuoteQtyEv":66900000,"feeCurrency":"BTC","lastLiquidityInd":"RemovedLiquidity","ordType":"Limit","orderID":"35217ade-3c6b-48c7-a280-8a1edb88013e","priceEp":68000000,"qtyType":"ByBase","quoteCurrency":"USDT","quoteQtyEv":66900000,"side":"Sell","symbol":"sBTCUSDT","transactTimeNs":1587463924964876798,"userID":200076}],"open":[{"action":"New","avgPriceEp":0,"baseCurrency":"BTC","baseQtyEv":100000000,"bizError":0,"clOrdID":"31f793f4-163d-aa3f-5994-0e1164719ba2","createTimeNs":1587547657438535949,"cumBaseQtyEv":0,"cumFeeEv":0,"cumQuoteQtyEv":0,"curBaseWalletQtyEv":630000005401500000,"curQuoteWalletQtyEv":351802500000,"cxlRejReason":0,"feeCurrency":"BTC","leavesBaseQtyEv":100000000,"leavesQuoteQtyEv":0,"ordStatus":"New","ordType":"Limit","orderID":"b98b25c5-6aa4-4158-b9e5-477e37bd46d8","pegOffsetValueEp":0,"priceEp":666500000000,"qtyType":"ByBase","quoteCurrency":"USDT","quoteQtyEv":0,"side":"Sell","stopPxEp":0,"symbol":"sBTCUSDT","timeInForce":"GoodTillCancel","transactTimeNs":1587547657442752950,"triggerTimeNs":0,"userID":200076}]}},"sequence":349,"timestamp":1587549121318737606,"type":"snapshot","wallets":[{"balanceEv":0,"currency":"LTC","lastUpdateTimeNs":1587481897840503662,"lockedTradingBalanceEv":0,"lockedWithdrawEv":0,"userID":200076},{"balanceEv":351802500000,"currency":"USDT","lastUpdateTimeNs":1587543489127498121,"lockedTradingBalanceEv":0,"lockedWithdrawEv":0,"userID":200076},{"balanceEv":630000005401500000,"currency":"BTC","lastUpdateTimeNs":1587547210089640382,"lockedTradingBalanceEv":100000000,"lockedWithdrawEv":0,"userID":200076},{"balanceEv":0,"currency":"ETH","lastUpdateTimeNs":1587481897840503662,"lockedTradingBalanceEv":0,"lockedWithdrawEv":0,"userID":200076},{"balanceEv":0,"currency":"XRP","lastUpdateTimeNs":1587481897840503662,"lockedTradingBalanceEv":0,"lockedWithdrawEv":0,"userID":200076},{"balanceEv":0,"currency":"LINK","lastUpdateTimeNs":1587481897840503662,"lockedTradingBalanceEv":0,"lockedWithdrawEv":0,"userID":200076},{"balanceEv":0,"currency":"XTZ","lastUpdateTimeNs":1587481897840503662,"lockedTradingBalanceEv":0,"lockedWithdrawEv":0,"userID":200076}]} < {"orders":{"closed":[],"fills":[],"open":[{"action":"New","avgPriceEp":0,"baseCurrency":"BTC","baseQtyEv":100000000,"bizError":0,"clOrdID":"0c1099e5-b900-5351-cf60-edb15ea2539c","createTimeNs":1587549529513521745,"cumBaseQtyEv":0,"cumFeeEv":0,"cumQuoteQtyEv":0,"curBaseWalletQtyEv":630000005401500000,"curQuoteWalletQtyEv":351802500000,"cxlRejReason":0,"feeCurrency":"BTC","leavesBaseQtyEv":100000000,"leavesQuoteQtyEv":0,"ordStatus":"New","ordType":"Limit","orderID":"494a6cbb-32b3-4d6a-b9b7-196ea2506fb5","pegOffsetValueEp":0,"priceEp":666500000000,"qtyType":"ByBase","quoteCurrency":"USDT","quoteQtyEv":0,"side":"Sell","stopPxEp":0,"symbol":"sBTCUSDT","timeInForce":"GoodTillCancel","transactTimeNs":1587549529518394235,"triggerTimeNs":0,"userID":200076}]}},"sequence":350,"timestamp":1587549529519959388,"type":"incremental","wallets":[{"balanceEv":630000005401500000,"currency":"BTC","lastUpdateTimeNs":1587547210089640382,"lockedTradingBalanceEv":200000000,"lockedWithdrawEv":0,"userID":200076},{"balanceEv":351802500000,"currency":"USDT","lastUpdateTimeNs":1587543489127498121,"lockedTradingBalanceEv":0,"lockedWithdrawEv":0,"userID":200076}]} ``` -------------------------------- ### Spot Wallet Query GET Response Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md Example JSON response received after successfully querying a spot wallet for a specific currency. Contains balance details, including locked amounts. ```json { "code": 0, "msg": "", "data": [ { "currency": "BTC", "balanceEv": 0, "lockedTradingBalanceEv": 0, "lockedWithdrawEv": 0, "lastUpdateTimeNs": 0 } ] } ``` -------------------------------- ### Query Spot PNLs via HTTP GET Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md Describes the HTTP GET request path for retrieving spot PNL data. Optional query parameters 'start' and 'end' can be used to specify a time range in milliseconds. ```HTTP GET /api-data/spots/pnls ``` -------------------------------- ### Risk Limit Configuration Example - Phemex API - JSON Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md Example JSON structure illustrating the new risk limit configuration based on `leverageMargin`. Shows how `notionalValueRv`, `maxLeverage`, and maintenance margin rates are associated with an `index_id`. ```json { "index_id": 1, "items": [ { "notionalValueRv": 50000, "maxLeverage": 20, "maintenanceMarginRateRr": "0.01", "maintenanceAmountRv": "0" }, { "notionalValueRv": 100000, "maxLeverage": 10, "maintenanceMarginRateRr": "0.06", "maintenanceAmountRv": "0" }, { "notionalValueRv": 200000, "maxLeverage": 5, "maintenanceMarginRateRr": "0.16", "maintenanceAmountRv": "0" }, { "notionalValueRv": 300000, "maxLeverage": 2, "maintenanceMarginRateRr": "0.46", "maintenanceAmountRv": "0" }, { "notionalValueRv": 500000, "maxLeverage": 1, "maintenanceMarginRateRr": "0.5", "maintenanceAmountRv": "0" } ] } ``` -------------------------------- ### Sample Kline Subscribe Request (JSON) Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md Example JSON request to subscribe to 1-day kline data for BTCUSDT, using a specific `id`. ```JSON { "id": 1234, "method": "kline_p.subscribe", "params": [ "BTCUSDT", 86400 ] } ``` -------------------------------- ### Sample Kline Subscribe Response (JSON) Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md Example JSON response received after successfully subscribing to kline data, correlating with the sample request `id`. ```JSON { "error": null, "id": 1234, "result": { "status": "success" } } ``` -------------------------------- ### WebSocket User Authentication Sample - JavaScript Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md Example WebSocket messages demonstrating a `user.auth` request with sample API credentials and the successful response indicating the session is authenticated. ```javascript > { "method": "user.auth", "params": [ "API", "806066b0-f02b-4d3e-b444-76ec718e1023", "8c939f7a6e6716ab7c4240384e07c81840dacd371cdcf5051bb6b7084897470e", 1570091232 ], "id": 1234 } < { "error": null, "id": 1234, "result": { "status": "success" } } ``` -------------------------------- ### Example POST Request Body - Phemex API Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Transfer-API-en.md This JSON object represents the request body used in Signature Example 3 for an HTTP POST request to the /spot/orders endpoint. It contains parameters for placing a limit order. ```json {"symbol":"sBTCUSDT","clOrdID":"ece0187f-7e02-44b5-a778-404125f124fa","side":"Buy","qtyType":"ByBase","quoteQtyEv":"0","baseQtyEv":"100000","priceEp":"700000000","stopPxEp":"0","execInst":"","ordType":"Limit","timeInForce":"","text":""} ``` -------------------------------- ### Sample Subscribe Account Margin (RAS) Response Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md An example of the JSON response received after successfully subscribing to RAS updates, corresponding to the sample request. ```JSON { "error": null, "id": 1234, "result": { "stauts": "success" } } ``` -------------------------------- ### Sample Subscribe Trade Phemex API JSON Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md Provides a concrete example of a Trade subscription request and its corresponding successful response using the Phemex API WebSocket, demonstrating the required format and typical values. ```JSON > { "id": 1234, "method": "trade_p.subscribe", "params": [ "BTCUSDT" ] } < { "error": null, "id": 1234, "result": { "status": "success" } } ``` -------------------------------- ### Query Spot Trades History via HTTP GET Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md Describes the HTTP GET request path for retrieving historical spot trades. Requires a 'symbol' parameter and supports optional 'start', 'end', 'offset', and 'limit' parameters for filtering and pagination. ```HTTP GET /api-data/spots/trades?symbol= ``` -------------------------------- ### Querying Trade Data on Phemex API (Sample) Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md Provides a concrete example of querying trade data for the BTCUSDT symbol, showing the request URL and a sample response with actual values for recent trades. ```HTTP GET /md/v2/trade?symbol=BTCUSDT ``` ```JSON { "error": null, "id": 0, "result": { "sequence": 77766796, "symbol": "BTCUSDT", "trades_p": [ [ 1666860389799499000, "Buy", "20702.1", "0.949" ], [ 1666860377636154600, "Sell", "20675.5", "0.785" ], ... ... ... ], "type": "snapshot" } } ``` -------------------------------- ### Sample Trade Messages Phemex API JSON Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md Illustrates examples of incremental and snapshot Trade messages received from the Phemex API WebSocket, showing the structure and typical data for trade executions. ```JSON < { "sequence": 77702250, "symbol": "BTCUSDT", "trades_p": [ [ 1666856076819029800, "Sell", "20700.3", "0.649" ] ], "type": "incremental" } < { "sequence": 77663551, "symbol": "BTCUSDT", "trades_p": [ [ 1666856062351916300, "Sell", "20703.6", "0.669" ], [ 1666854025545354000, "Buy", "20699", "0.001" ] ], "type": "snapshot" } ``` -------------------------------- ### Sample Subscribe OrderBook Phemex API JSON Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md Provides a concrete example of an OrderBook subscription request and its corresponding successful response using the Phemex API WebSocket, demonstrating the required format and typical values. ```JSON > { "id": 1234, "method": "orderbook_p.subscribe", "params": [ "BTCUSDT" ] } < { "error": null, "id": 1234, "result": { "status": "success" } } ``` -------------------------------- ### Sample Query Order Book HTTP Request Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md This is a sample HTTP GET request demonstrating how to query the order book for the BTCUSD trading pair. ```HTTP GET /md/orderbook?symbol=BTCUSD ``` -------------------------------- ### Spot Order Placement PUT Response Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md Example JSON response received after successfully placing a spot order via the PUT endpoint. Contains order details, status, and execution information. ```javascript { "code": 0, "msg": "", "data": { "orderID": "d1d09454-cabc-4a23-89a7-59d43363f16d", "clOrdID": "309bcd5c-9f6e-4a68-b775-4494542eb5cb", "priceEp": 0, "action": "New", "trigger": "UNSPECIFIED", "pegPriceType": "UNSPECIFIED", "stopDirection": "UNSPECIFIED", "bizError": 0, "symbol": "sBTCUSDT", "side": "Buy", "baseQtyEv": 0, "ordType": "Limit", "timeInForce": "GoodTillCancel", "ordStatus": "Created", "cumFeeEv": 0, "cumBaseQtyEv": 0, "cumQuoteQtyEv": 0, "leavesBaseQtyEv": 0, "leavesQuoteQtyEv": 0, "avgPriceEp": 0, "cumBaseAmountEv": 0, "cumQuoteAmountEv": 0, "quoteQtyEv": 0, "qtyType": "ByBase", "stopPxEp": 0, "pegOffsetValueEp": 0 } } ``` -------------------------------- ### Querying 24hr Ticker Data on Phemex API (Sample) Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md Provides a concrete example of querying 24-hour ticker data for the BTCUSDT symbol, showing the request URL and a sample response with actual values for various metrics. ```HTTP GET /md/v2/ticker/24hr?symbol=BTCUSDT ``` ```JSON { "error": null, "id": 0, "result": { "closeRp": "20731", "fundingRateRr": "0.0001", "highRp": "20818.8", "indexPriceRp": "20737.09857143", "lowRp": "20425.2", "markPriceRp": "20737.788944", "openInterestRv": "0", "openRp": "20709", "predFundingRateRr": "0.0001", "symbol": "BTCUSDT", "timestamp": 1667222412794076700, "turnoverRv": "139029311.7517", "volumeRq": "6747.727" } } ``` -------------------------------- ### Query All Open Spot Orders by Symbol via GET Request Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md Retrieves a list of all open spot trading orders for a specified symbol using a GET request. ```HTTP GET /spot/orders?symbol= ``` -------------------------------- ### WebSocket Subscribe OrderBook Sample (Partial) - JavaScript Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md Example WebSocket messages showing a `orderbook.subscribe` request for partial updates for the 'sBTCUSDT' symbol and the successful response. ```javascript > { "id": 1234, "method": "orderbook.subscribe", "params": [ "sBTCUSDT" ] } < { "error": null, "id": 1234, "result": { "status": "success" } } ``` -------------------------------- ### Example Response for Querying Open Orders Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md This JSON object provides an example of the successful response returned by the API when querying open orders. It contains a list of order objects within the 'rows' array, detailing various order attributes like ID, symbol, side, price, quantity, and status. ```JSON { "code": 0, "msg": "", "data": { "rows": [ { "bizError": 0, "orderID": "9cb95282-7840-42d6-9768-ab8901385a67", "clOrdID": "7eaa9987-928c-652e-cc6a-82fc35641706", "symbol": "BTCUSD", "side": "Buy", "actionTimeNs": 1580533011677666800, "transactTimeNs": 1580533011677666800, "orderType": null, "priceEp": 84000000, "price": 8400, "orderQty": 1, "displayQty": 1, "timeInForce": null, "reduceOnly": false, "stopPxEp": 0, "closedPnlEv": 0, "closedPnl": 0, "closedSize": 0, "cumQty": 0, "cumValueEv": 0, "cumValue": 0, "leavesQty": 0, "leavesValueEv": 0, "leavesValue": 0, "stopPx": 0, "stopDirection": "Falling", "ordStatus": "Untriggered" }, { "bizError": 0, "orderID": "93397a06-e76d-4e3b-babc-dff2696786aa", "clOrdID": "71c2ab5d-eb6f-0d5c-a7c4-50fd5d40cc50", "symbol": "BTCUSD", "side": "Sell", "actionTimeNs": 1580532983785506600, "transactTimeNs": 1580532983786370300, "orderType": null, "priceEp": 99040000, "price": 9904, "orderQty": 1, "displayQty": 1, "timeInForce": null, "reduceOnly": false, "stopPxEp": 0, "closedPnlEv": 0, "closedPnl": 0, "closedSize": 0, "cumQty": 0, "cumValueEv": 0, "cumValue": 0, "leavesQty": 1, "leavesValueEv": 10096, "leavesValue": 0.00010096, "stopPx": 0, "stopDirection": "UNSPECIFIED", "ordStatus": "New" }, { "bizError": 0, "orderID": "2585817b-85df-4dea-8507-5db1920b9954", "clOrdID": "4b19fd1e-a1a7-2986-d02a-0288ad5137d4", "symbol": "BTCUSD", "side": "Buy", "actionTimeNs": 1580532966629408500, "transactTimeNs": 1580532966633276200, "orderType": null, "priceEp": 80040000, "price": 8004, "orderQty": 1, "displayQty": 1, "timeInForce": null, "reduceOnly": false, "stopPxEp": 0, "closedPnlEv": 0, "closedPnl": 0, "closedSize": 0, "cumQty": 0, "cumValueEv": 0, "cumValue": 0, "leavesQty": 1, "leavesValueEv": 12493, "leavesValue": 0.00012493, "stopPx": 0, "stopDirection": "UNSPECIFIED", "ordStatus": "New" } ] } } ``` -------------------------------- ### WebSocket Subscribe Full OrderBook Sample (Full) - JavaScript Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md Example WebSocket messages showing a `orderbook.subscribe` request for full updates for the 'sBTCUSDT' symbol and the successful response. ```javascript > { "id": 1234, "method": "orderbook.subscribe", "params": [ "sBTCUSDT", true ] } < { "error": null, "id": 1234, "result": { "status": "success" } } ``` -------------------------------- ### Query Product Information - Phemex API Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md Details the HTTP GET request to fetch general product information from the Phemex API. This endpoint does not require any query parameters. ```http GET /public/products ``` -------------------------------- ### Sample Tick Price Events (JSON) Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md Provides examples of actual tick price event messages received from the API for the .BTCUSDT symbol, showing the structure and data format of the real-time price updates. ```JSON {"tick_p":{"last":"20639.38692364","symbol":".BTCUSDT","timestamp":1666863393552000000}} {"tick_p":{"last":"20639.15408363","symbol":".BTCUSDT","timestamp":1666863394538132741}} ``` -------------------------------- ### Query Spot Wallet by Currency via GET Request Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md Retrieves the balance details for a specific currency in the spot wallet using a GET request. ```HTTP GET /spot/wallets?currency= ``` -------------------------------- ### WebSocket Heartbeat Sample - JavaScript Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md Example WebSocket messages showing a `server.ping` request with a specific ID and the corresponding `pong` response received from the server. ```javascript > { "id": 1234, "method": "server.ping", "params": [] } < { "error": null, "id": 1234, "result": "pong" } ``` -------------------------------- ### Sample Kline Snapshot Message (JSON) Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md Example of a kline snapshot message received via the WebSocket, containing historical kline data points for a symbol. ```JSON { "kline_p": [ [ 1666856340, 60, "20689.5", "20686.2", "20695.4", "20686.2", "20691.6", "2.742", "56731.5609" ], [ 1666856280, 60, "20700.1", "20712.7", "20712.7", "20689.1", "20689.5", "4.407", "91208.3065" ] ], "sequence": 77711279, "symbol": "BTCUSDT", "type": "snapshot" } ``` -------------------------------- ### Query Spot Orders By IDs via HTTP GET Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md Describes the HTTP GET request path for retrieving spot order details using either 'orderID' or 'clOrdID'. Requires a 'symbol' parameter. If both IDs are provided, the API prioritizes 'orderID'. ```HTTP GET /api-data/spots/trades/by-order-id?symbol=&oderId=&clOrdID= ``` -------------------------------- ### Sample AOP v1 Subscribe Response (JSON) Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md A practical example of the JSON response received after sending the sample subscription request, indicating that the subscription was successfully initiated. ```JSON { "error": null, "id": 1234, "result": { "status": "success" } } ``` -------------------------------- ### Sample OrderBook Messages Phemex API JSON Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md Illustrates examples of incremental OrderBook messages received from the Phemex API WebSocket, showing the structure and typical data for updates to the order book. ```JSON < {"depth":30,"orderbook_p":{"asks":[["20702.9","0.718"],["20703.9","0.524"],["20704.9","0"],["20720.8","0"]],"bids":[["20703.1","0"],["20701.3","0"],["20701.2","0"],["20700.5","1.622"],["20473.7","1.074"],["20441.3","0.904"]]},"sequence":77668172,"symbol":"BTCUSDT","timestamp":1666854171201355264,"type":"incremental"} < {"depth":30,"orderbook_p":{"asks":[],"bids":[["20700.5","0"],["20340.5","0.06"]]},"sequence":77668209,"symbol":"BTCUSDT","timestamp":1666854173705089711,"type":"incremental"} ``` -------------------------------- ### Placing Phemex Order Request Body JSON Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md JSON request body example for placing a new order on Phemex using the POST /g-orders endpoint. It includes various parameters for order type, quantity, price, stop loss, take profit, etc. ```JSON { "clOrdID": "137e1928-5d25-fecd-dbd1-705ded659a4f", "closeOnTrigger": true, "displayQtyRq": "0.01", "ordType": "Limit", "orderQtyRq": "0.01", "pegOffsetValueRp": "1271.9", "pegPriceType": "LastPeg", "posSide": "Long", "priceRp": "1271.9", "reduceOnly": true, "side": "Buy", "slTrigger": "ByMarkPrice", "stopLossRp": "1271.9", "stopPxRp": "1271.9", "symbol": "BTCUSDT", "takeProfitRp": "1271.9", "text": "string", "timeInForce": "GoodTillCancel", "tpTrigger": "ByMarkPrice", "triggerType": "ByMarkPrice" } ``` -------------------------------- ### Phemex API Sample Snapshot Trade Message (JavaScript/JSON) Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md Provides an example of a snapshot trade message received from the Phemex DataGW. Snapshot messages are sent upon initial connection for client recovery and contain a list of recent trades. ```javascript < { "sequence": 1167852, "symbol": "sBTCUSDT", "trades": [ [ 1573716998128563500, "Buy", 867350000000, 560000 ], [ 1573716995033683000, "Buy", 867350000000, 520000 ], [ 1573716991485286000, "Buy", 867350000000, 510000 ], [ 1573716988636291300, "Buy", 867350000000, 120000 ] ], "type": "snapshot" } ``` -------------------------------- ### Sample Kline Incremental Message (JSON) Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md Example of a kline incremental message received via the WebSocket, containing the latest kline data point update. ```JSON { "kline_p": [ [ 1666856520, 60, "20685", "20684.8", "20684.8", "20675.2", "20675.2", "3.547", "73353.8417" ] ], "priceScale": 0, "sequence": 77715046, "symbol": "BTCUSDT", "type": "incremental" } ``` -------------------------------- ### Phemex API Rate Limit Response Headers (Text) Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md Example HTTP headers returned by Phemex API endpoints for contract trading, indicating the current rate limit status and capacity for the 'SPOTORDER' group. ```text X-RateLimit-Remaining-SPOTORDER, # Remaining request permits in this minute X-RateLimit-Capacity-SPOTORDER, # Request ratelimit capacity X-RateLimit-Retry-After-SPOTORDER, # Reset timeout in seconds for current ratelimited user ``` -------------------------------- ### Phemex API Sample Incremental Trade Message (JavaScript/JSON) Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md Provides an example of an incremental trade message received from the Phemex DataGW. Incremental messages contain new trades published at regular intervals. ```javascript < { "sequence": 1188273, "symbol": "sBTCUSDT", "trades": [ [ 1573717116484024300, "Buy", 86730000000, 210000 ] ], "type": "incremental" } ``` -------------------------------- ### 24 Hours Ticker Sample Message (JavaScript) Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md Example of a 24-hour ticker data message received from the server, showing typical values. ```javascript { "market24h": { "close": 87425000, "fundingRate": 10000, "high": 92080000, "indexPrice": 87450676, "low": 87130000, "markPrice": 87453092, "open": 90710000, "openInterest": 7821141, "predFundingRate": 7609, "symbol": "BTCUSD", "timestamp": 1583646442444219017, "turnover": 1399362834123, "volume": 125287131 }, "timestamp": 1576490244024818000 } ``` -------------------------------- ### Query Product Information (HTTP) Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md Retrieves detailed information about available trading products on Phemex. This endpoint is accessed via a GET request to the specified path. Product information for hedged mode can be found under the 'perpProductsV2' node in the response. ```HTTP GET /public/products ``` -------------------------------- ### Subscribe 24 Hours Ticker Sample Interaction (JavaScript) Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md Example showing a request to subscribe to the 24-hour ticker and the corresponding successful response. ```javascript > { "method": "market24h.subscribe", "params": [], "id": 1234 } < { "error": null, "id": 1234, "result": { "status": "success" } } ``` -------------------------------- ### Spot Order Placement POST Request Body Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md Example JSON request body used when placing a spot order via the POST endpoint. Specifies order details like symbol, side, quantity, and price. ```json { "symbol": "sBTCUSDT", "clOrdID": "", "side": "Buy/Sell", "qtyType": "ByBase/ByQuote", "quoteQtyEv": 0, "baseQtyEv": 0, "priceEp": 0, "stopPxEp": 0, "trigger": "UNSPECIFIED", "ordType": "Limit", "timeInForce": "GoodTillCancel" } ``` -------------------------------- ### Sample Subscribe Account Margin (RAS) Request Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md An example of the JSON request payload used to subscribe to Account Margin (RAS) updates, showing a specific request ID. ```JSON { "id": 1234, "method": "ras_p.subscribe", "params": {} } ``` -------------------------------- ### Sample Order Book API Response (JSON) Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md This snippet provides a concrete example of the JSON response received when querying the order book, showing sample data for asks and bids, along with other response fields. ```json { "error": null, "id": 0, "result": { "book": { "asks": [ [ 87705000, 1000000 ], [ 87710000, 200000 ] ], "bids": [ [ 87700000, 2000000 ], [ 87695000, 200000 ] ] }, "depth": 30, "sequence": 455476965, "timestamp": 1583555482434235628, "symbol": "BTCUSD", "type": "snapshot" } } ``` -------------------------------- ### Query Futures Orders By Ids JSON Response Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md Provides an example of the JSON array returned by the Query Orders By Ids endpoint. It shows the structure and fields for a specific order retrieved using its ID. ```JSON [ { "orderId": "743fc923-cb01-4261-88d1-b35dba2cdac0", "clOrdId": "cfffa744-712d-867a-e397-9888eec3f6d1", "symbol": "BTCUSDT", "side": "Buy", "ordType": "Market", "actionTimeNs": 1667562110213260743, "priceRp": "21206.7", "orderQtyRq": "0.001", "displayQtyRq": "0.001", "timeInForce": "ImmediateOrCancel", "reduceOnly": false, "takeProfitRp": "0", "stopLossRp": "0", "closedPnlRv": "0", "closedSizeRq": "0", "cumQtyRq": "0.001", "cumValueRv": "20.5795", "leavesQtyRq": "0", "leavesValueRv": "0", "stopDirection": "UNSPECIFIED", "ordStatus": "Filled", "transactTimeNs": 1667562110221077395, "bizError": 0 } ] ``` -------------------------------- ### Query Spot Sub To Main Transfer - Phemex API - HTTP Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Transfer-API-en.md Describes the GET endpoint to query spot asset transfers from sub-accounts to the main account. Details query parameters like currency, time range, offset, and limit. ```HTTP GET /assets/spots/sub-accounts/transfer?currency=BTC ``` ```JSON [ { "amountEv": 0, "createAt": 0, "currency": "string", "fromUserId": 0, "id": 0, "requestKey": "string", "status": 0, "toUserId": 0 } ] ``` -------------------------------- ### Query Chain Settings HTTP Request Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md Defines the HTTP GET request endpoint and required parameter for querying available chain settings for a given currency, which is needed to determine the `chainName` for deposit address queries. ```HTTP GET /exchange/public/cfg/chain-settings?currency= ``` -------------------------------- ### WebSocket API User Authentication Sample Request JSON Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md Provides a sample JSON message demonstrating how a client sends an authentication request over the WebSocket connection using example API credentials. ```JSON > { "method": "user.auth", "params": [ "API", "806066b0-f02b-4d3e-b444-76ec718e1023", "8c939f7a6e6716ab7c4240384e07c81840dacd371cdcf5051bb6b7084897470e", 1570091232 ], "id": 1234 } ``` -------------------------------- ### Query Trading Fees History JSON Response Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md Example JSON response body returned by the Query Trading Fees History endpoint. Contains details about trading fees including maker/taker values and rates, and creation time. ```JSON [ { "id": 295, "userId": 939565, "symbol": "ETHUSDT", "currency": "USDT", "takerValueRv": "97.1104", "takerFeeRateRr": "0.0006", "makerValueRv": "97.164", "makerFeeRateRr": "0", "exchangeFeeRv": "0.06798264", "createTime": 1669766400000 } ] ``` -------------------------------- ### Query History Trades - Phemex API - GET Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md Describes the GET request to retrieve historical trade data for a given market symbol. Supports filtering by `since`, `start`, and `end` parameters. Has a rate limit of 5 per second. ```http GET /exchange/public/nomics/trades?market=&since= ``` ```json { "code": 0, "data": [ { "id": "string", "amount_quote": "string", "price": "string", "side": "string", "timestamp": "string", "type": "string" } ], "msg": "string" } ``` ```json { "code": 0, "msg": "OK", "data": [ { "id": "1183-3-2", "timestamp": "2019-11-24T08:32:17.046Z", "price": "7211.00000000", "amount_quote": "1", "side": "sell", "type": "limit" }, { "id": "1184-2-1", "timestamp": "2019-11-24T08:32:17.047Z", "price": "7211.00000000", "amount_quote": "1", "side": "buy", "type": "limit" } ] } ``` -------------------------------- ### Phemex API Generic Response JSON Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md Example JSON structure for a generic Phemex API response, showing common fields like code, data, and msg. The data field contains details about an order. ```JSON { "code": 0, "data": { "pegOffsetValueRp": "1271.9", "pegPriceType": "LastPeg", "priceRq": "98970000", "reduceOnly": true, "side": "Sell", "stopDirection": "Rising", "stopPxRp": "1271.9", "symbol": "BTCUSDT", "timeInForce": "GoodTillCancel", "transactTimeNs": 0, "trigger": "ByMarkPrice" }, "msg": "string" } ``` -------------------------------- ### Query Futures Orders History HTTP Request Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md This snippet shows the HTTP GET request endpoint used to retrieve historical futures orders for a specified symbol. Optional parameters like start, end, offset, and limit can be used for pagination and time filtering. ```HTTP GET /api-data/futures/orders?symbol= ``` -------------------------------- ### Query Spot Closed Orders Sample JSON Response Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md A sample JSON response illustrating the data returned by the deprecated endpoint for querying closed spot orders. It shows example values for the order fields. ```json { "code": 0, "msg": "OK", "data": { "total": 2, "rows": [ { "orderID": "b2b7018d-f02f-4c59-b4cf-051b9c2d2e83", "stopPxEp": 0, "avgPriceEp": 970056000000, "qtyType": "ByQuote", "leavesBaseQtyEv": 0, "leavesQuoteQtyEv": 0, "baseQtyEv": "0", "feeCurrency": "1", "stopDirection": "UNSPECIFIED", "symbol": "sBTCUSDT", "side": "Buy", "quoteQtyEv": 1000000000, "priceEp": 970056000000, "ordType": "Limit", "timeInForce": "GoodTillCancel", "ordStatus": "Filled", "execStatus": "MakerFill", "createTimeNs": 1589449348601287000, "cumFeeEv": 0, "cumBaseValueEv": 103000, "cumQuoteValueEv": 999157680 } ] } } ``` -------------------------------- ### Generating Google 2FA Code Java Example Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md This Java snippet demonstrates how to use the `com.warrenstrange:googleauth` library to generate a Time-based One-Time Password (TOTP) from a secret key and verify it. This code can be used to obtain the `otpCode` required for withdrawal requests. ```Java api 'com.warrenstrange:googleauth:1.1.2' import com.warrenstrange.googleauth.GoogleAuthenticator; @Test public void testAuth() { String secret = "XXXXXXXXXXXXXXXX"; GoogleAuthenticator gAuth = new GoogleAuthenticator(); int code = gAuth.getTotpPassword(secret); boolean ans = gAuth.authorize(secret, code); Assert.assertTrue(ans); } ``` -------------------------------- ### Query Account Positions - Phemex API Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md This snippet provides the HTTP GET request and the expected JSON response for querying account balance and position details. The request requires specifying the currency and optionally the symbol. ```HTTP GET /g-accounts/accountPositions?currency=&symbol= ``` ```JSON { "code": 0, "data": { "account": { "accountBalanceRv": "1271.9", "accountId": 123450001, "bonusBalanceRv": "1271.9", "currency": "BTC", "totalUsedBalanceRv": "1271.9", "userID": 12345 }, "positions": [ { "accountID": 123450001, "assignedPosBalanceRv": "1271.9", "avgEntryPrice": "1271.9", "avgEntryPriceRp": "1271.9", "bankruptCommRv": "1271.9", "bankruptPriceRp": "1271.9", "buyValueToCostRr": "0.1", "crossMargin": true, "cumClosedPnlRv": "1271.9", "cumFundingFeeRv": "1271.9", "cumTransactFeeRv": "1271.9", "curTermRealisedPnlRv": "1271.9", "currency": "BTC", "deleveragePercentileRr": "0.1", "estimatedOrdLossRv": "1271.9", "execSeq": 0, "initMarginReqRr": "0.1", "lastFundingTimeNs": 450000000, "lastTermEndTimeNs": 450000000, "leverageRr": "0", "liquidationPriceRp": "1271.9", "maintMarginReqRr": "0.1", "makerFeeRateRr": "0.1", "markPriceRp": "1271.9", "posCostRv": "1271.9", "posMode": "Hedged", "posSide": "Long", "positionMarginRv": "1271.9", "positionStatus": "Normal", "riskLimitRv": "0.1", "sellValueToCostRr": "0.1", "side": "Sell", "size": "0", "symbol": "BTC", "takerFeeRateRr": "0.1", "term": 0, "transactTimeNs": 450000000, "usedBalanceRv": "1271.9", "userID": 12345, "valueRv": "1271.9" } ] }, "msg": "string" } ``` -------------------------------- ### Query Closed Orders - Phemex API - HTTP Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md This is the HTTP GET request endpoint for querying closed orders on the Phemex API. It requires specifying the currency, start time, end time, offset, and limit, with optional filters for symbol, order status, order type, and whether to include a count. ```http GET /exchange/order/v2/orderList?symbol=¤cy=&ordStatus=&ordType=&start=&end=&offset=&limit=&withCount= ``` -------------------------------- ### Querying User Children and Wallets - Response JSON Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md Example JSON response containing a list of child users, their details, wallet balances (scaled and unscaled), and margin account information. The 'total' field indicates the total number of child users. ```JSON { "code": 0, "msg": "OK", "data": { "total": 87, "rows": [ { "userId": 612, "email": "x**@**.com", "nickName": "nickName", "passwordState": 1, "clientCnt": 0, "totp": 1, "logon": 0, "parentId": 0, "parentEmail": null, "status": 1, "wallet": { "totalBalance": "989.25471319", "totalBalanceEv": 98925471319, "availBalance": "989.05471319", "availBalanceEv": 98905471319, "freezeBalance": "0.20000000", "freezeBalanceEv": 20000000, "currency": "BTC", "currencyCode": 1 }, "userMarginVo": [ { "currency": "BTC", "accountBalance": "3.90032508", "totalUsedBalance": "0.00015666", "accountBalanceEv": 390032508, "totalUsedBalanceEv": 15666, "bonusBalanceEv": 0, "bonusBalance": "0" }, { "currency": "USD", "accountBalance": "38050.35000000", "totalUsedBalance": "0.00000000", "accountBalanceEv": 380503500, "totalUsedBalanceEv": 0, "bonusBalanceEv": 0, "bonusBalance": "0" } ] }, ... ] } } ``` -------------------------------- ### Query Trades History JSON Response Source: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md Example JSON response body returned by the Query Trades History endpoint. Contains details about individual trades including execution price, quantity, fees, and timestamps. ```JSON [ { "action": "New", "clOrdID": "", "closedPnlRv": "0", "closedSizeRq": "0", "currency": "USDT", "execFeeRv": "0.00166", "execID": "5c3d96e1-8874-53b6-b6e5-9dcc4d28b4ab", "execPriceRp": "16600", "execQtyRq": "0.001", "execStatus": "MakerFill", "execValueRv": "16.6", "feeRateRr": "0.0001", "orderID": "fcdfeafa-ed68-45d4-b2bd-7bc27f2b2b0b", "orderQtyRq": "0.001", "ordType": "LimitIfTouched", "priceRp": "16600", "side": "Sell", "symbol": "BTCUSDT", "tradeType": "Trade", "transactTimeNs": 1669407633926215067 } ] ```