> ## 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.

# Get Available Leverage Levels

You can request the leverage levels available for each symbol for your account.

<Note>
  You cannot change the leverage level if you have any open orders or a non zero
  position.
</Note>

Leverage management is performed over **WebSocket**.

* **Endpoint:** `wss://trade.qfex.com?api_key=YOUR_API_KEY`
* **Authenticate within 1 minute of connecting.**

## Example Request

```json theme={null}
{
  "type": "get_available_leverage_levels",
  "params": {
    "limit": 10, // Optional
    "offset": 0  // Optional
  }
}
```

* `limit` *(optional)* — maximum number of trades to return (default **1000**)
* `offset` *(optional)* — pagination offset (default **0**)

## Sample Code

<CodeGroup>
  ```python python theme={null}
  # Python (websocket-client)
  import json, websocket

  API_KEY = "YOUR_API_KEY"

  def send(ws, obj): ws.send(json.dumps(obj))

  def on_open(ws):
      # 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..." }}})
      # Request user trades
      send(ws, {"type": "get_available_leverage_levels", "params": {"limit": 10, "offset": 0}})

  ws = websocket.WebSocketApp(
      "wss://trade.qfex.com?api_key=YOUR_API_KEY",
      on_open=on_open,
      on_message=lambda _, m: print("Message:", m)
  )
  ws.run_forever()
  ```

  ```javascript node theme={null}
  // Node.js (ws)
  import WebSocket from "ws";
  const ws = new WebSocket("wss://trade.qfex.com?api_key=YOUR_API_KEY");
  const API_KEY = "YOUR_API_KEY";

  ws.on("open", () => {
    ws.send(JSON.stringify({ type: "auth", params: { api_key: API_KEY } }));
    ws.send(
      JSON.stringify({
        type: "get_available_leverage_levels",
        params: { limit: 10, offset: 0 },
      })
    );
  });

  ws.on("message", (msg) => console.log("Message:", msg.toString()));
  ```

  ```go go theme={null}
  // Go (gorilla/websocket)
  package main

  import (
  	"log"
  	"github.com/gorilla/websocket"
  )

  func mustWriteJSON(c *websocket.Conn, v any) {
  	if err := c.WriteJSON(v); err != nil { log.Fatal("write:", err) }
  }

  func main() {
  	c, _, err := websocket.DefaultDialer.Dial("wss://trade.qfex.com?api_key=YOUR_API_KEY", nil)
  	if err != nil { log.Fatal("dial:", err) }
  	defer c.Close()

  	// Authenticate
  	mustWriteJSON(c, map[string]any{
  		"type": "auth",
  		"params": map[string]any{"hmac": map[string]any{"public_key": "qfex_pub_xxxxx", "nonce": "c0ffee...", "unix_ts": 1760545414, "signature": "5f2e..."}}
  	})

  	// Get user leverage
  	mustWriteJSON(c, map[string]any{
  		"type": "get_available_leverage_levels",
  		"params": map[string]any{"limit": 10, "offset": 0},
  	})
  }
  ```

  ```java java theme={null}
  // Java (OkHttp WebSocket)
  import java.util.concurrent.TimeUnit;
  import okhttp3.*;

  public class GetUserTradesWs {
    public static void main(String[] args) {
      OkHttpClient client = new OkHttpClient.Builder()
          .pingInterval(20, TimeUnit.SECONDS).build();

      Request req = new Request.Builder()
          .url("wss://trade.qfex.com?api_key=YOUR_API_KEY").build();

      WebSocketListener li = new WebSocketListener() {
        @Override public void onOpen(WebSocket ws, Response r) {
          ws.send("{\"type\": \"auth\", \"params\": { \"hmac\": { \"public_key\": \"qfex_pub_xxxxx\", \"nonce\": \"c0ffee...\..\", \"unix_ts\": 1760545414, \"signature\": \"5f2e...\" }}}");
          ws.send("{\"type\":\"get_available_leverage_levels\",\"params\":{\"limit\":10,\"offset\":0}}");
        }
        @Override public void onMessage(WebSocket ws, String text) {
          System.out.println(text);
        }
      };

      client.newWebSocket(req, li);
      try { Thread.sleep(Long.MAX_VALUE); } catch (InterruptedException ignored) {}
    }
  }
  ```
</CodeGroup>

## Example Response

```json theme={null}
{
  "available_leverage_levels_response": [
    {
      "id": "04349aaf-b29c-456d-b255-7b9de6e180c4",
      "symbol": "META-USD",
      "initial_margin": 1.0,
      "maintenance_margin": 0.6666666666666666,
      "max_notional": 195000.0,
      "leverage": "1"
    },
    {
      "id": "9dc9cc77-5222-47f3-80fe-16d48fa1082e",
      "symbol": "META-USD",
      "initial_margin": 0.5,
      "maintenance_margin": 0.3333333333333333,
      "max_notional": 190000.0,
      "leverage": "2"
    }
  ]
}
```
