To connect a TradingView strategy to Phemex Signal Trading, paste the JSON template below into your TradingView alert's Message field, fill in your signalToken from Phemex, and send the alert to Phemex's webhook URL. Phemex will then mirror your buy/sell signals automatically. For detailed step guide, please refer to this article > How to Use Signal Trading Bots on Phemex? (Web)
Alert Format
Copy this JSON template into the TradingView alert Message field. Curly-brace placeholders are TradingView strategy variables and will be auto-filled at runtime.
Parameter Reference
|
Parameter
|
Type
|
Value
|
Description
|
|---|---|---|---|
|
id
|
Mandatory
|
{{strategy.order.id}} from TradingView
|
id - Order Identifier Returns the ID of the executed order, which is the string used as the first argument in the function call that generates the order: strategy.entry, strategy.exit, or strategy.order.
|
|
symbol
|
Mandatory
|
{{ticker}} from TradingView
|
TradingView Symbol Identical to the Symbol Name used by Phemex.
|
|
action
|
Mandatory
|
{{strategy.order.action}} from TradingView
|
Action - "Buy" or "Sell"? Returns the string "buy" or "sell" for executed orders. Buy - to open a long position / close a short position Sell - to open a short position / close a long position.
|
|
qty
|
Optional
|
{{strategy.order.contracts}} from TradingView
|
Order Quantity Valid when the entry condition equals TradingView, for example, placing an order for 0.001 of BTCUSDT, i.e., qty=0.001.
|
|
price
|
Mandatory
|
{{strategy.order.price}} from TradingView
|
Limit Order Price The signal strategy will use limit order type for all orders.
|
|
type
|
Optional
|
The default order type is set as "Limit" within the signal. It can be changed to "Market" if needed.
|
To place a Limit order, use "Limit"; to place a Market order, use "Market".
|
|
marketPosition
|
Optional
|
{{strategy.market_position}} from TradingView
|
marketPosition - Expected position status (at the time of order execution) Returns the current position direction of the strategy as a string: "long", "flat", or "short". Long - long position, flat - no position, short - short position.
|
|
prevMarketPosition
|
Optional
|
{{strategy.prev_market_position}} from TradingView
|
prevMarketPosition - Previous position status (before order execution) Returns the previous position direction of the strategy as a string: "long", "flat", or "short".
|
|
marketPositionSize
|
Optional
|
{{strategy.market_position_size}} from TradingView
|
marketPositionSize - Expected position size (at the time of order execution)
|
|
prevMarketPositionSize
|
Optional
|
{{strategy.prev_market_position_size}} from TradingView
|
prevMarketPositionSize - Previous position size (before order execution)
|
|
signalToken
|
Mandatory
|
Provided by Phemex at the time of signal creation
|
Signal Code: Authentication of the signal. Ensures that the incoming request is legitimate and authorized. This signal code is automatically generated when a user successfully creates a new signal on Phemex and should be copied into the TradingView alert message.
|
|
timestamp
|
Mandatory
|
{{timenow}} from TradingView
|
Order Timestamp
|
Examples
Example 1: Long Position Opening → Long Position Closing (Close All)
// Open a long position in BTCUSDT, opening price: 40,000, opening quantity: 0.001. { "id": "id_9b4b19b3d112", "symbol": "BTCUSDT", "action": "buy", "qty": 0.001, "price": 40000, "type": "Limit", "marketPosition": "long", "prevMarketPosition": "flat", "marketPositionSize": 0.001, "prevMarketPositionSize": 0, "signalToken": "kGAOBKheClXD7bVZHe-hEYHxF1rfTwlPPyko3DSWT1Q==", "timestamp": "2024-01-17T10:51:58Z" } // Close a long position in BTCUSDT, closing price: 41,000, closing quantity: 0.001. { "id": "id_9b4b19b3d113", "symbol": "BTCUSDT", "action": "sell", "qty": 0.001, "price": 41000, "type": "Limit", "marketPosition": "flat", "prevMarketPosition": "long", "marketPositionSize": 0, "prevMarketPositionSize": 0.001, "signalToken": "kGAOBKheClXD7bVZHe-hEYHxF1rfTwlPPyko3DSWT1Q==", "timestamp": "2024-01-17T11:51:58Z" }
Example 2: Long → Short (One-Step Reversal)
// Open a long position in BTCUSDT, opening price: 40,000, opening quantity: 0.001. { "id": "id_9b4b19b3d112", "symbol": "BTCUSDT", "action": "buy", "qty": 0.001, "price": 40000, "type": "Limit", "marketPosition": "long", "prevMarketPosition": "flat", "marketPositionSize": 0.001, "prevMarketPositionSize": 0, "signalToken": "kGAOBKheClXD7bVZHe-hEYHxF1rfTwlPPyko3DSWT1Q==", "timestamp": "2024-01-17T10:51:58Z" } // Open a short position in BTCUSDT, closing price: 41,000, closing quantity: 0.002. // If qty > posQty, reversal will occur: fully close the 0.001 long, then open a 0.001 short. { "id": "id_9b4b19b3d113", "symbol": "BTCUSDT", "action": "sell", "qty": 0.002, "price": 41000, "type": "Limit", "marketPosition": "short", "prevMarketPosition": "long", "marketPositionSize": 0.001, "prevMarketPositionSize": 0.001, "signalToken": "kGAOBKheClXD7bVZHe-hEYHxF1rfTwlPPyko3DSWT1Q==", "timestamp": "2024-01-17T11:51:58Z" }
Example 3: Long Opening → Partial Close → Full Close
// Open a long position in BTCUSDT, opening price: 40,000, opening quantity: 0.002. { "id": "id_9b4b19b3d112", "symbol": "BTCUSDT", "action": "buy", "qty": 0.002, "price": 40000, "type": "Limit", "marketPosition": "long", "prevMarketPosition": "flat", "marketPositionSize": 0.002, "prevMarketPositionSize": 0, "signalToken": "kGAOBKheClXD7bVZHe-hEYHxF1rfTwlPPyko3DSWT1Q==", "timestamp": "2024-01-17T10:51:58Z" } // Partially close the long position in BTCUSDT, closing price: 41,000, closing quantity: 0.001. { "id": "id_9b4b19b3d113", "symbol": "BTCUSDT", "action": "sell", "qty": 0.001, "price": 41000, "type": "Limit", "marketPosition": "long", "prevMarketPosition": "long", "marketPositionSize": 0.001, "prevMarketPositionSize": 0.002, "signalToken": "kGAOBKheClXD7bVZHe-hEYHxF1rfTwlPPyko3DSWT1Q==", "timestamp": "2024-01-17T11:51:58Z" } // Close the long position in BTCUSDT, closing price: 42,000, closing quantity: 0.001. { "id": "id_9b4b19b3d114", "symbol": "BTCUSDT", "action": "sell", "qty": 0.001, "price": 42000, "type": "Limit", "marketPosition": "flat", "prevMarketPosition": "long", "marketPositionSize": 0, "prevMarketPositionSize": 0.001, "signalToken": "kGAOBKheClXD7bVZHe-hEYHxF1rfTwlPPyko3DSWT1Q==", "timestamp": "2024-01-17T12:51:58Z" }
Example 4: Long Market Order Entry → Long Market Order Exit
// Open a long position in BTCUSDT, entry price: 40,000, position size: 0.001 { "id": "id_9b4b19b3d112", "symbol": "BTCUSDT", "action": "buy", "qty": 0.001, "price": 40000, "type": "Market", "marketPosition": "long", "prevMarketPosition": "flat", "marketPositionSize": 0.001, "prevMarketPositionSize": 0, "signalToken": "kGAOBKheClXD7bVZHe-hEYHxF1rfTwlPPyko3DSWT1Q==", "timestamp": "2024-01-17T10:51:58Z" } // Close the long position in BTCUSDT, exit price: 41,000, position size: 0.001 { "id": "id_9b4b19b3d113", "symbol": "BTCUSDT", "action": "sell", "qty": 0.001, "price": 41000, "type": "Market", "marketPosition": "flat", "prevMarketPosition": "long", "marketPositionSize": 0, "prevMarketPositionSize": 0.001, "signalToken": "kGAOBKheClXD7bVZHe-hEYHxF1rfTwlPPyko3DSWT1Q==", "timestamp": "2024-01-17T11:51:58Z" }

Submit Ticket