# userEvents

## Subscribe to userEvents

> Subscription to user events for a specific user.

```json
{"openapi":"3.1.1","info":{"title":"Hyperliquid Subscription - userEvents","version":"1.0.0"},"tags":[{"name":"userEvents"}],"servers":[{"url":"wss://api.hyperliquid.xyz/ws","description":"Mainnet WebSocket"},{"url":"wss://api.hyperliquid-testnet.xyz/ws","description":"Testnet WebSocket"}],"paths":{"/":{"post":{"tags":["userEvents"],"summary":"Subscribe to userEvents","description":"Subscription to user events for a specific user.","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"type":{"description":"Type of subscription.","enum":["userEvents"]},"user":{"type":"string","pattern":"^0[xX][0-9a-fA-F]+$","minLength":42,"maxLength":42,"description":"User address."}},"required":["type","user"],"description":"Subscription to user events for a specific user."}}},"required":true},"responses":{"200":{"description":"Event of one of possible user events.","content":{"application/json":{"schema":{"anyOf":[{"type":"object","properties":{"fills":{"type":"array","items":{"type":"object","properties":{"coin":{"type":"string","description":"Asset symbol."},"px":{"type":"string","pattern":"^[0-9]+(\\.[0-9]+)?$","description":"Price."},"sz":{"type":"string","pattern":"^[0-9]+(\\.[0-9]+)?$","description":"Size."},"side":{"enum":["B","A"],"description":"Order side (\"B\" = Bid/Buy, \"A\" = Ask/Sell)."},"time":{"type":"integer","minimum":0,"description":"Timestamp when the trade occurred (in ms since epoch)."},"startPosition":{"type":"string","pattern":"^-?[0-9]+(\\.[0-9]+)?$","description":"Start position size."},"dir":{"type":"string","description":"Direction indicator for frontend display."},"closedPnl":{"type":"string","pattern":"^-?[0-9]+(\\.[0-9]+)?$","description":"Realized PnL."},"hash":{"type":"string","pattern":"^0[xX][0-9a-fA-F]+$","minLength":66,"maxLength":66,"description":"L1 transaction hash."},"oid":{"type":"integer","minimum":0,"description":"Order ID."},"crossed":{"type":"boolean","description":"Indicates if the fill was a taker order."},"fee":{"type":"string","pattern":"^-?[0-9]+(\\.[0-9]+)?$","description":"Fee charged or rebate received (negative indicates rebate)."},"tid":{"type":"integer","minimum":0,"description":"Unique transaction identifier for a partial fill of an order."},"cloid":{"type":"string","pattern":"^0[xX][0-9a-fA-F]+$","minLength":34,"maxLength":34,"description":"Client Order ID."},"liquidation":{"type":"object","properties":{"liquidatedUser":{"type":"string","pattern":"^0[xX][0-9a-fA-F]+$","minLength":42,"maxLength":42,"description":"Address of the liquidated user."},"markPx":{"type":"string","pattern":"^[0-9]+(\\.[0-9]+)?$","description":"Mark price at the time of liquidation."},"method":{"enum":["market","backstop"],"description":"Liquidation method."}},"required":["liquidatedUser","markPx","method"],"description":"Liquidation details."},"feeToken":{"type":"string","description":"Token in which the fee is denominated (e.g., \"USDC\")."},"twapId":{"anyOf":[{"type":"integer","minimum":0,"nullable":true}],"description":"ID of the TWAP."}},"required":["coin","px","sz","side","time","startPosition","dir","closedPnl","hash","oid","crossed","fee","tid","feeToken","twapId"],"description":"Order fill record."},"description":"Array of user trade fills."}},"required":["fills"],"description":"Event of array of user trade fills."},{"type":"object","properties":{"funding":{"type":"object","properties":{"coin":{"type":"string","description":"Asset symbol."},"usdc":{"type":"string","pattern":"^-?[0-9]+(\\.[0-9]+)?$","description":"Amount transferred in USDC."},"szi":{"type":"string","pattern":"^-?[0-9]+(\\.[0-9]+)?$","description":"Signed position size."},"fundingRate":{"type":"string","pattern":"^-?[0-9]+(\\.[0-9]+)?$","description":"Applied funding rate."},"nSamples":{"anyOf":[{"type":"integer","minimum":0,"nullable":true}],"description":"Number of samples."}},"required":["coin","usdc","szi","fundingRate","nSamples"],"description":"Funding update details."}},"required":["funding"],"description":"Event of user funding update."},{"type":"object","properties":{"liquidation":{"type":"object","properties":{"lid":{"type":"integer","minimum":0,"description":"Unique liquidation ID."},"liquidator":{"type":"string","pattern":"^0[xX][0-9a-fA-F]+$","minLength":42,"maxLength":42,"description":"Address of the liquidator."},"liquidated_user":{"type":"string","pattern":"^0[xX][0-9a-fA-F]+$","minLength":42,"maxLength":42,"description":"Address of the liquidated user."},"liquidated_ntl_pos":{"type":"string","pattern":"^[0-9]+(\\.[0-9]+)?$","description":"Notional position size that was liquidated."},"liquidated_account_value":{"type":"string","pattern":"^[0-9]+(\\.[0-9]+)?$","description":"Account value at time of liquidation."}},"required":["lid","liquidator","liquidated_user","liquidated_ntl_pos","liquidated_account_value"],"description":"Liquidation details."}},"required":["liquidation"],"description":"Event of user liquidation."},{"type":"object","properties":{"nonUserCancel":{"type":"array","items":{"type":"object","properties":{"coin":{"type":"string","description":"Asset symbol (e.g., BTC)."},"oid":{"type":"integer","minimum":0,"description":"Order ID."}},"required":["coin","oid"],"description":"Cancelled order not initiated by the user."},"description":"Array of non-user initiated order cancellations."}},"required":["nonUserCancel"],"description":"Event of array of non-user initiated order cancellations."},{"type":"object","properties":{"twapHistory":{"type":"array","items":{"type":"object","properties":{"time":{"type":"integer","minimum":0,"description":"Creation time of the history record (in seconds since epoch)."},"state":{"type":"object","properties":{"coin":{"type":"string","description":"Asset symbol."},"executedNtl":{"type":"string","pattern":"^[0-9]+(\\.[0-9]+)?$","description":"Executed notional value."},"executedSz":{"type":"string","pattern":"^[0-9]+(\\.[0-9]+)?$","description":"Executed size."},"minutes":{"type":"integer","minimum":0,"description":"Duration in minutes."},"randomize":{"type":"boolean","description":"Indicates if the TWAP randomizes execution."},"reduceOnly":{"type":"boolean","description":"Indicates if the order is reduce-only."},"side":{"enum":["B","A"],"description":"Order side (\"B\" = Bid/Buy, \"A\" = Ask/Sell)."},"sz":{"type":"string","pattern":"^[0-9]+(\\.[0-9]+)?$","description":"Order size."},"timestamp":{"type":"integer","minimum":0,"description":"Start time of the TWAP order (in ms since epoch)."},"user":{"type":"string","pattern":"^0[xX][0-9a-fA-F]+$","minLength":42,"maxLength":42,"description":"User address."}},"required":["coin","executedNtl","executedSz","minutes","randomize","reduceOnly","side","sz","timestamp","user"],"description":"State of the TWAP order."},"status":{"oneOf":[{"type":"object","properties":{"status":{"enum":["finished","activated","terminated"],"description":"Status of the TWAP order."}},"required":["status"]},{"type":"object","properties":{"status":{"description":"Status of the TWAP order.","enum":["error"]},"description":{"type":"string","description":"Error message."}},"required":["status","description"]}],"description":"Current status of the TWAP order.\n- `\"finished\"`: Fully executed.\n- `\"activated\"`: Active and executing.\n- `\"terminated\"`: Terminated.\n- `\"error\"`: An error occurred."},"twapId":{"type":"integer","minimum":0,"description":"ID of the TWAP."}},"required":["time","state","status"],"description":"TWAP history record."},"description":"Array of user's TWAP history."}},"required":["twapHistory"],"description":"Event of a TWAP history entry."},{"type":"object","properties":{"twapSliceFills":{"type":"array","items":{"type":"object","properties":{"fill":{"type":"object","properties":{"coin":{"type":"string","description":"Asset symbol."},"px":{"type":"string","pattern":"^[0-9]+(\\.[0-9]+)?$","description":"Price."},"sz":{"type":"string","pattern":"^[0-9]+(\\.[0-9]+)?$","description":"Size."},"side":{"enum":["B","A"],"description":"Order side (\"B\" = Bid/Buy, \"A\" = Ask/Sell)."},"time":{"type":"integer","minimum":0,"description":"Timestamp when the trade occurred (in ms since epoch)."},"startPosition":{"type":"string","pattern":"^-?[0-9]+(\\.[0-9]+)?$","description":"Start position size."},"dir":{"type":"string","description":"Direction indicator for frontend display."},"closedPnl":{"type":"string","pattern":"^-?[0-9]+(\\.[0-9]+)?$","description":"Realized PnL."},"hash":{"type":"string","pattern":"^0[xX][0-9a-fA-F]+$","minLength":66,"maxLength":66,"description":"L1 transaction hash."},"oid":{"type":"integer","minimum":0,"description":"Order ID."},"crossed":{"type":"boolean","description":"Indicates if the fill was a taker order."},"fee":{"type":"string","pattern":"^-?[0-9]+(\\.[0-9]+)?$","description":"Fee charged or rebate received (negative indicates rebate)."},"tid":{"type":"integer","minimum":0,"description":"Unique transaction identifier for a partial fill of an order."},"feeToken":{"type":"string","description":"Token in which the fee is denominated (e.g., \"USDC\")."},"twapId":{"anyOf":[{"type":"integer","minimum":0,"nullable":true}],"description":"ID of the TWAP."}},"required":["coin","px","sz","side","time","startPosition","dir","closedPnl","hash","oid","crossed","fee","tid","feeToken","twapId"],"description":"TWAP fill record."},"twapId":{"type":"integer","minimum":0,"description":"ID of the TWAP."}},"required":["fill","twapId"],"description":"User twap slice fill."},"description":"Array of user's twap slice fills."}},"required":["twapSliceFills"],"description":"Event of TWAP slice fills."}],"description":"Event of one of possible user events."}}}}}}}}}
```
