> For the complete documentation index, see [llms.txt](https://vexar.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vexar.gitbook.io/docs/api-reference.md).

# API Reference

### REST API

#### Base URL

```
https://api.vexatrade.com/v1
```

#### Authentication

All API requests require authentication using API keys:

```bash
curl -H "X-API-Key: YOUR_API_KEY" \
     -H "X-API-Secret: YOUR_API_SECRET" \
     https://api.vexatrade.com/v1/account
```

#### Endpoints

**Market Data**

**GET /markets**

Retrieve all available markets.

```json
{
  "markets": [
    {
      "symbol": "BTC-PERP",
      "type": "perpetual",
      "base": "BTC",
      "quote": "USD",
      "minOrderSize": "0.001",
      "tickSize": "0.5"
    }
  ]
}
```

**GET /ticker/{symbol}**

Get real-time ticker data for a specific market.

```json
{
  "symbol": "BTC-PERP",
  "lastPrice": "45000.00",
  "bid": "44999.50",
  "ask": "45000.50",
  "volume24h": "1234.56",
  "change24h": "2.5"
}
```

**GET /orderbook/{symbol}**

Retrieve order book depth.

Query Parameters:

* `depth`: Number of levels (default: 20, max: 100)

```json
{
  "symbol": "BTC-PERP",
  "bids": [["44999.50", "1.25"], ["44999.00", "2.50"]],
  "asks": [["45000.50", "1.00"], ["45001.00", "3.00"]],
  "timestamp": 1672531200000
}
```

**Trading**

**POST /orders**

Place a new order.

```json
{
  "symbol": "BTC-PERP",
  "side": "buy",
  "type": "limit",
  "quantity": "0.5",
  "price": "44500.00",
  "timeInForce": "GTC"
}
```

Response:

```json
{
  "orderId": "12345678",
  "status": "open",
  "fillQuantity": "0",
  "remainingQuantity": "0.5"
}
```

**DELETE /orders/{orderId}**

Cancel an existing order.

**GET /orders**

Retrieve all open orders.

Query Parameters:

* `symbol`: Filter by market symbol
* `status`: Filter by status (open, filled, cancelled)

**GET /trades**

Get trade history.

Query Parameters:

* `symbol`: Filter by market
* `startTime`: Start timestamp
* `endTime`: End timestamp
* `limit`: Number of results (default: 50, max: 500)

**Account**

**GET /account**

Retrieve account information and balances.

```json
{
  "balances": [
    {
      "asset": "USD",
      "free": "10000.00",
      "locked": "500.00"
    },
    {
      "asset": "BTC",
      "free": "1.5",
      "locked": "0.5"
    }
  ],
  "marginLevel": "5.2",
  "totalEquity": "78500.00"
}
```

**GET /positions**

Get open positions (perpetual markets only).

```json
{
  "positions": [
    {
      "symbol": "BTC-PERP",
      "side": "long",
      "quantity": "2.0",
      "entryPrice": "44000.00",
      "markPrice": "45000.00",
      "unrealizedPnL": "2000.00",
      "leverage": "10x"
    }
  ]
}
```

### WebSocket API

#### Connection

```javascript
const ws = new WebSocket('wss://ws.vexatrade.com');

ws.onopen = () => {
  // Authenticate
  ws.send(JSON.stringify({
    type: 'auth',
    apiKey: 'YOUR_API_KEY',
    apiSecret: 'YOUR_API_SECRET'
  }));
};
```

#### Subscribe to Market Data

```javascript
// Subscribe to ticker updates
ws.send(JSON.stringify({
  type: 'subscribe',
  channel: 'ticker',
  symbol: 'BTC-PERP'
}));

// Subscribe to order book updates
ws.send(JSON.stringify({
  type: 'subscribe',
  channel: 'orderbook',
  symbol: 'BTC-PERP'
}));

// Subscribe to trades
ws.send(JSON.stringify({
  type: 'subscribe',
  channel: 'trades',
  symbol: 'BTC-PERP'
}));
```

#### Private Channels

```javascript
// Subscribe to order updates
ws.send(JSON.stringify({
  type: 'subscribe',
  channel: 'orders'
}));

// Subscribe to position updates
ws.send(JSON.stringify({
  type: 'subscribe',
  channel: 'positions'
}));
```

### Rate Limits

* REST API: 1200 requests per minute per API key
* WebSocket: 10 connections per API key
* Order placement: 100 orders per second

### Error Codes

| Code | Message               | Description                        |
| ---- | --------------------- | ---------------------------------- |
| 400  | Bad Request           | Invalid request parameters         |
| 401  | Unauthorized          | Invalid or missing API credentials |
| 403  | Forbidden             | Insufficient permissions           |
| 429  | Too Many Requests     | Rate limit exceeded                |
| 500  | Internal Server Error | Server-side error                  |

### SDK Libraries

#### Python

```bash
pip install vexar-sdk
```

```python
from vexar import Client

client = Client(api_key='YOUR_KEY', api_secret='YOUR_SECRET')
balances = client.get_balances()
```

#### JavaScript/Node.js

```bash
npm install @vexar/sdk
```

```javascript
const { VexarClient } = require('@vexar/sdk');

const client = new VexarClient({
  apiKey: 'YOUR_KEY',
  apiSecret: 'YOUR_SECRET'
});

const balances = await client.getBalances();
```

### Need Help?

Visit our Support Page or join our developer community on Discord.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://vexar.gitbook.io/docs/api-reference.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
