Documentation Index
Fetch the complete documentation index at: https://docs.qfex.com/llms.txt
Use this file to discover all available pages before exploring further.
Order entry is performed over WebSocket.
- Endpoint:
wss://trade.qfex.com?api_key=YOUR_API_KEY
- Authenticate within 1 minute of connecting.
1) Authenticate
Send this immediately after you connect:
{ "type": "auth", "params": { "hmac": { "public_key": "qfex_pub_xxxxx", "nonce": "c0ffee...", "unix_ts": 1760545414, "signature": "5f2e..." } } }
2) Add Order
Adding a stop order follows the same pattern as adding a typical order. The direction given must be the eventual direction of the triggered order that is placed into the book.
TAKE_PROFIT and STOP_LOSS orders cannot exceed your current position, attempting to do this could cause your order to be rejected or other stop orders to be cancelled.
{
"type": "add_order",
"params": {
"symbol": "AAPL-USD",
"side": "BUY",
"order_type": "TAKE_PROFIT",
"order_time_in_force": "GTC", // Ignored
"quantity": 1,
"price": 200
}
}
Parameters
| Field | Type | Required | Description |
|---|
symbol | string | ✅ | The market symbol (e.g. AAPL-USD). |
side | enum | ✅ | Order direction. See OrderDirection. |
order_type | enum | ✅ | Type of order. See OrderType. |
order_time_in_force | enum | ✅ | Time in force policy. Required for legacy reasons, the value will not be read. |
quantity | number | ✅ | Quantity of the order. Must respect lot size but not min/max limits. |
price | number | ✅ | Price for when the order is triggered. |
⚠️ Notes:
- Tick size, lot size, and min/max order quantity are symbol-specific. See Reference Data API.
- An order may be rejected with OrderStatus codes if parameters are invalid.
Sample Code
# Python (websocket-client)
# pip install websocket-client
import json
import websocket
API_KEY = "YOUR_API_KEY"
def send(ws, obj):
ws.send(json.dumps(obj))
def on_open(ws):
# 1) Authenticate
# https://docs.qfex.com/websocket/channels/trade/authenticate#how-it-works
send(ws, {"type": "auth", "params": { "hmac": { "public_key": "qfex_pub_xxxxx", "nonce": "c0ffee...", "unix_ts": 1760545414, "signature": "5f2e..." }}})
# 2) Add stop order
send(ws, {
"type": "add_order",
"params": {
"symbol": "AAPL-USD",
"side": "BUY",
"order_type": "TAKE_PROFIT",
"order_time_in_force": "GTC",
"quantity": 1,
"price": 200
}
})
ws = websocket.WebSocketApp(
"wss://trade.qfex.com?api_key=YOUR_API_KEY",
on_open=on_open,
on_message=lambda _, m: print(m),
on_error=lambda _, e: print("Error:", e),
on_close=lambda *_: print("Closed"),
)
ws.run_forever()
Example Response
When you place an order, you will receive an order_response with status ACK:
{
"order_response": {
"order_id": "5b309929-206f-40ec-804d-cbe46e81afc1",
"symbol": "AAPL-USD",
"status": "ACK",
"quantity": 1.0,
"price": 200.0,
"take_profit": 0.0,
"stop_loss": 0.0,
"side": "BUY",
"type": "TAKE_PROFIT",
"time_in_force": "GTC",
"user_id": "0020ce8e-eaee-480e-8d7f-b9241d756ee5",
"client_order_id": "",
"quantity_remaining": 1.0
}
}