logo
TradFi

How to Configure Webhook Alerts for Phemex Signal Trading

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.

 
{ "id": "{{strategy.order.id}}", "symbol": "{{ticker}}", "action": "{{strategy.order.action}}", "qty": "{{strategy.order.contracts}}", "price": "{{strategy.order.price}}", "type": "Limit", "marketPosition": "{{strategy.market_position}}", "prevMarketPosition": "{{strategy.prev_market_position}}", "marketPositionSize": "{{strategy.market_position_size}}", "prevMarketPositionSize": "{{strategy.prev_market_position_size}}", "signalToken": "POdKsisSLkUxWXXIcjlx-eh_4UDuqfgYXL2KKX5wbOgazrhgKhdNhLoUb8OQK_xv0RnLdIclDFOOfqL6sfXwzkBJTN6n9v-U4qgwWK5YCtMP38IG1UJ91dsn2cw=", "timestamp": "{{timenow}}" }
 

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" }

Related Articles

Sorry we couldn't help — let us assist you directly

Choose a contact method — support responds within 2 minutes:

Submit Ticket

Log in to check your account status in real time