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

# Models

## The Signature object

```json
{"openapi":"3.0.3","info":{"title":"AFX DEX Exchange API","version":"1.0.0"},"components":{"schemas":{"Signature":{"type":"object","required":["r","s","v"],"properties":{"r":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"s":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"v":{"type":"integer","description":"27 or 28"}}}}}}
```

## The ExchangeResponse object

```json
{"openapi":"3.0.3","info":{"title":"AFX DEX Exchange API","version":"1.0.0"},"components":{"schemas":{"ExchangeResponse":{"type":"object","properties":{"code":{"type":"integer","description":"`0` = success. See Error Codes section for non-zero values."},"message":{"type":"string"},"data":{"type":"object","nullable":true,"properties":{"txHash":{"type":"string"},"txCode":{"type":"integer"},"txMsg":{"type":"string"}}}}}}}}
```

## The PlaceOrderRequest object

```json
{"openapi":"3.0.3","info":{"title":"AFX DEX Exchange API","version":"1.0.0"},"components":{"schemas":{"PlaceOrderRequest":{"type":"object","required":["action","signature","nonce"],"properties":{"action":{"type":"object","required":["type","orders"],"properties":{"type":{"type":"string","enum":["placeOrder"]},"orders":{"type":"array","minItems":1,"items":{"type":"object","required":["symbolCode","ordPx","ordQty","ordType","ordSide","timeInForce"],"properties":{"symbolCode":{"type":"integer","format":"int64"},"ordPx":{"type":"string","description":"Limit `> 0`, Market `\"0\"`"},"ordQty":{"type":"string"},"ordType":{"type":"string","enum":["LIMIT","MARKET"],"description":"NONE and display-only values MARKET_LIQ_SELLOFF, LIMIT_LIQ_SELLOFF, ADL, and LIQUIDATION must not be sent in requests."},"ordSide":{"type":"string","enum":["BUY","SELL","BUY_CLOSE_HEDGE","SELL_CLOSE_HEDGE"]},"timeInForce":{"type":"string","enum":["GTC","IOC","FOK","POST_ONLY"]},"clOrdId":{"type":"integer","format":"int64"},"parentOrdId":{"type":"integer","format":"int64"},"reduceOnlyOption":{"type":"string","enum":["REDUCE_ONLY","TP_FROM_POSITION","SL_FROM_POSITION"]},"triggerPx":{"type":"string"},"tpslTriggerType":{"type":"string","enum":["LAST_PRICE","MARK_PRICE","INDEX_PRICE"]},"slippagePct":{"type":"string"}}}}}},"signature":{"$ref":"#/components/schemas/Signature"},"nonce":{"type":"integer","format":"int64","description":"Request nonce as a Unix timestamp in milliseconds. Recommended: current time in milliseconds. Must be unique; do not reuse the same nonce for another signed request."},"expiryAfter":{"type":"integer","format":"int64","nullable":true,"description":"Unix timestamp in milliseconds after which the request expires. null = no expiry; use 0 in the signature payload when this field is null."},"vaultAddress":{"type":"string","nullable":true}}},"Signature":{"type":"object","required":["r","s","v"],"properties":{"r":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"s":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"v":{"type":"integer","description":"27 or 28"}}}}}}
```

## The ReplaceOrderRequest object

```json
{"openapi":"3.0.3","info":{"title":"AFX DEX Exchange API","version":"1.0.0"},"components":{"schemas":{"ReplaceOrderRequest":{"type":"object","required":["action","signature","nonce"],"properties":{"action":{"type":"object","required":["type","symbolCode","ordPx","ordQty","ordType","ordSide","timeInForce"],"properties":{"type":{"type":"string","enum":["replaceOrder"]},"symbolCode":{"type":"integer","format":"int64"},"ordPx":{"type":"string","description":"Limit `> 0`, Market `\"0\"`"},"ordQty":{"type":"string"},"ordType":{"type":"string","enum":["LIMIT","MARKET"],"description":"NONE and display-only values MARKET_LIQ_SELLOFF, LIMIT_LIQ_SELLOFF, ADL, and LIQUIDATION must not be sent in requests."},"ordSide":{"type":"string","enum":["BUY","SELL","BUY_CLOSE_HEDGE","SELL_CLOSE_HEDGE"]},"timeInForce":{"type":"string","enum":["GTC","IOC","FOK","POST_ONLY"]},"clOrdId":{"type":"integer","format":"int64","description":"Client order ID. clOrdId or ordId is required."},"ordId":{"type":"integer","format":"int64","description":"System order ID. clOrdId or ordId is required."},"parentOrdId":{"type":"integer","format":"int64"},"reduceOnly":{"type":"string","enum":["REDUCE_ONLY","TP_FROM_POSITION","SL_FROM_POSITION"]},"triggerPx":{"type":"string"},"tpslTriggerType":{"type":"string","enum":["LAST_PRICE","MARK_PRICE","INDEX_PRICE"]},"slippagePct":{"type":"string"}}},"signature":{"$ref":"#/components/schemas/Signature"},"nonce":{"type":"integer","format":"int64","description":"Request nonce as a Unix timestamp in milliseconds. Recommended: current time in milliseconds. Must be unique; do not reuse the same nonce for another signed request."},"expiryAfter":{"type":"integer","format":"int64","nullable":true,"description":"Unix timestamp in milliseconds after which the request expires. null = no expiry; use 0 in the signature payload when this field is null."},"vaultAddress":{"type":"string","nullable":true}}},"Signature":{"type":"object","required":["r","s","v"],"properties":{"r":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"s":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"v":{"type":"integer","description":"27 or 28"}}}}}}
```

## The PlaceBracketOrderRequest object

```json
{"openapi":"3.0.3","info":{"title":"AFX DEX Exchange API","version":"1.0.0"},"components":{"schemas":{"PlaceBracketOrderRequest":{"type":"object","required":["action","signature","nonce"],"properties":{"action":{"type":"object","required":["type","orders"],"properties":{"type":{"type":"string","enum":["placeBracketOrder"]},"orders":{"type":"array","minItems":2,"maxItems":3,"items":{"type":"object","required":["symbolCode","ordPx","ordQty","ordType","ordSide","timeInForce"],"properties":{"symbolCode":{"type":"integer","format":"int64"},"ordPx":{"type":"string","description":"Limit `> 0`, Market `\"0\"`"},"ordQty":{"type":"string"},"ordType":{"type":"string","enum":["LIMIT","MARKET"],"description":"NONE and display-only values MARKET_LIQ_SELLOFF, LIMIT_LIQ_SELLOFF, ADL, and LIQUIDATION must not be sent in requests."},"ordSide":{"type":"string","enum":["BUY","SELL","BUY_CLOSE_HEDGE","SELL_CLOSE_HEDGE"]},"timeInForce":{"type":"string","enum":["GTC","IOC","FOK","POST_ONLY"]},"clOrdId":{"type":"integer","format":"int64"},"parentOrdId":{"type":"integer","format":"int64"},"reduceOnly":{"type":"string","enum":["REDUCE_ONLY","TP_FROM_POSITION","SL_FROM_POSITION"]},"triggerPx":{"type":"string"},"tpslTriggerType":{"type":"string","enum":["LAST_PRICE","MARK_PRICE","INDEX_PRICE"]},"slippagePct":{"type":"string"}}}}}},"signature":{"$ref":"#/components/schemas/Signature"},"nonce":{"type":"integer","format":"int64","description":"Request nonce as a Unix timestamp in milliseconds. Recommended: current time in milliseconds. Must be unique; do not reuse the same nonce for another signed request."},"expiryAfter":{"type":"integer","format":"int64","nullable":true,"description":"Unix timestamp in milliseconds after which the request expires. null = no expiry; use 0 in the signature payload when this field is null."},"vaultAddress":{"type":"string","nullable":true}}},"Signature":{"type":"object","required":["r","s","v"],"properties":{"r":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"s":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"v":{"type":"integer","description":"27 or 28"}}}}}}
```

## The CancelOrderRequest object

```json
{"openapi":"3.0.3","info":{"title":"AFX DEX Exchange API","version":"1.0.0"},"components":{"schemas":{"CancelOrderRequest":{"type":"object","required":["action","signature","nonce"],"properties":{"action":{"type":"object","required":["type","cancels"],"properties":{"type":{"type":"string","enum":["cancelOrder"]},"cancels":{"type":"array","minItems":1,"items":{"type":"object","required":["symbolCode"],"properties":{"symbolCode":{"type":"string"},"clOrdId":{"type":"string","description":"Client order ID (clOrdId or ordId required)"},"ordId":{"type":"string","description":"System order ID (clOrdId or ordId required)"}}}}}},"signature":{"$ref":"#/components/schemas/Signature"},"nonce":{"type":"integer","format":"int64","description":"Request nonce as a Unix timestamp in milliseconds. Recommended: current time in milliseconds. Must be unique; do not reuse the same nonce for another signed request."},"vaultAddress":{"type":"string","nullable":true}}},"Signature":{"type":"object","required":["r","s","v"],"properties":{"r":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"s":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"v":{"type":"integer","description":"27 or 28"}}}}}}
```

## The CancelAllRequest object

```json
{"openapi":"3.0.3","info":{"title":"AFX DEX Exchange API","version":"1.0.0"},"components":{"schemas":{"CancelAllRequest":{"type":"object","required":["action","signature","nonce"],"properties":{"action":{"type":"object","required":["type","symbolCode"],"properties":{"type":{"type":"string","enum":["cancelAll"]},"symbolCode":{"type":"integer","format":"int64"},"conditionalOrder":{"type":"boolean","default":false}}},"signature":{"$ref":"#/components/schemas/Signature"},"nonce":{"type":"integer","format":"int64","description":"Request nonce as a Unix timestamp in milliseconds. Recommended: current time in milliseconds. Must be unique; do not reuse the same nonce for another signed request."},"vaultAddress":{"type":"string","nullable":true}}},"Signature":{"type":"object","required":["r","s","v"],"properties":{"r":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"s":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"v":{"type":"integer","description":"27 or 28"}}}}}}
```

## The SetLeverageRequest object

```json
{"openapi":"3.0.3","info":{"title":"AFX DEX Exchange API","version":"1.0.0"},"components":{"schemas":{"SetLeverageRequest":{"type":"object","required":["action","signature","nonce"],"properties":{"action":{"type":"object","required":["type","symbolCode","leverage"],"properties":{"type":{"type":"string","enum":["setLeverage"]},"symbolCode":{"type":"integer","format":"int64"},"leverage":{"type":"string","description":">= 1, max 2 decimal places"}}},"signature":{"$ref":"#/components/schemas/Signature"},"nonce":{"type":"integer","format":"int64","description":"Request nonce as a Unix timestamp in milliseconds. Recommended: current time in milliseconds. Must be unique; do not reuse the same nonce for another signed request."},"vaultAddress":{"type":"string","nullable":true}}},"Signature":{"type":"object","required":["r","s","v"],"properties":{"r":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"s":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"v":{"type":"integer","description":"27 or 28"}}}}}}
```

## The SetMarginModeRequest object

```json
{"openapi":"3.0.3","info":{"title":"AFX DEX Exchange API","version":"1.0.0"},"components":{"schemas":{"SetMarginModeRequest":{"type":"object","required":["action","signature","nonce"],"properties":{"action":{"type":"object","required":["type","symbolCode","marginMode"],"properties":{"type":{"type":"string","enum":["setMarginMode"]},"symbolCode":{"type":"integer","format":"int64"},"marginMode":{"type":"string","enum":["CROSS","ISOLATED"]}}},"signature":{"$ref":"#/components/schemas/Signature"},"nonce":{"type":"integer","format":"int64","description":"Request nonce as a Unix timestamp in milliseconds. Recommended: current time in milliseconds. Must be unique; do not reuse the same nonce for another signed request."},"vaultAddress":{"type":"string","nullable":true}}},"Signature":{"type":"object","required":["r","s","v"],"properties":{"r":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"s":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"v":{"type":"integer","description":"27 or 28"}}}}}}
```

## The AssignPosMarginRequest object

```json
{"openapi":"3.0.3","info":{"title":"AFX DEX Exchange API","version":"1.0.0"},"components":{"schemas":{"AssignPosMarginRequest":{"type":"object","required":["action","signature","nonce"],"properties":{"action":{"type":"object","required":["type","symbolCode","assignedPosMargin"],"properties":{"type":{"type":"string","enum":["assignPosMargin"]},"symbolCode":{"type":"integer","format":"int64"},"assignedPosMargin":{"type":"string","description":"Amount to assign (non-zero)"}}},"signature":{"$ref":"#/components/schemas/Signature"},"nonce":{"type":"integer","format":"int64","description":"Request nonce as a Unix timestamp in milliseconds. Recommended: current time in milliseconds. Must be unique; do not reuse the same nonce for another signed request."},"vaultAddress":{"type":"string","nullable":true}}},"Signature":{"type":"object","required":["r","s","v"],"properties":{"r":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"s":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"v":{"type":"integer","description":"27 or 28"}}}}}}
```

## The ApproveAgentRequest object

```json
{"openapi":"3.0.3","info":{"title":"AFX DEX Exchange API","version":"1.0.0"},"components":{"schemas":{"ApproveAgentRequest":{"type":"object","required":["action","signature","nonce"],"properties":{"action":{"type":"object","required":["type","agentAddress","agentName","validitySeconds","dexChain"],"properties":{"type":{"type":"string","enum":["approveAgent"]},"agentAddress":{"type":"string","description":"Agent wallet address (0x hex)"},"agentName":{"type":"string","default":"app.afx.xyz","description":"Agent name. SDK default: app.afx.xyz"},"validitySeconds":{"type":"integer","format":"int64","description":"Agent authorization duration in seconds. 0 means the authorization is valid for 7 days; maximum 365 days."},"dexChain":{"type":"string","enum":["Mainnet","Testnet"]},"referralCode":{"type":"string","description":"Referral code (only effective on first approve)"}}},"signature":{"$ref":"#/components/schemas/Signature"},"nonce":{"type":"integer","format":"int64","description":"Request nonce as a Unix timestamp in milliseconds. Recommended: current time in milliseconds. Must be unique; do not reuse the same nonce for another signed request."},"expiryAfter":{"type":"integer","format":"int64","nullable":true,"description":"Unix timestamp in milliseconds after which the request expires. null = no expiry; use 0 in the signature payload when this field is null."}}},"Signature":{"type":"object","required":["r","s","v"],"properties":{"r":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"s":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"v":{"type":"integer","description":"27 or 28"}}}}}}
```

## The WithdrawRequest object

```json
{"openapi":"3.0.3","info":{"title":"AFX DEX Exchange API","version":"1.0.0"},"components":{"schemas":{"WithdrawRequest":{"type":"object","required":["action","signature","nonce"],"properties":{"action":{"type":"object","required":["type","destination","amount"],"properties":{"type":{"type":"string","enum":["withdraw"]},"destination":{"type":"string","description":"Recipient address (0x hex)"},"amount":{"type":"string","description":"Withdrawal amount. Minimum mainnet withdrawal: 2 USDC."}}},"signature":{"$ref":"#/components/schemas/Signature"},"nonce":{"type":"integer","format":"int64","description":"Request nonce as a Unix timestamp in milliseconds. Recommended: current time in milliseconds. Must be unique; do not reuse the same nonce for another signed request."},"expiryAfter":{"type":"integer","format":"int64","nullable":true,"description":"Unix timestamp in milliseconds after which the request expires. For withdrawals, use a longer window such as current time + 3,600,000 milliseconds. null = no expiry; use 0 in the signature payload when this field is null."}}},"Signature":{"type":"object","required":["r","s","v"],"properties":{"r":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"s":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"v":{"type":"integer","description":"27 or 28"}}}}}}
```

## The BindReferralRequest object

```json
{"openapi":"3.0.3","info":{"title":"AFX DEX Exchange API","version":"1.0.0"},"components":{"schemas":{"BindReferralRequest":{"type":"object","required":["action","signature","nonce"],"properties":{"action":{"type":"object","required":["type","referralCode"],"properties":{"type":{"type":"string","enum":["bindReferral"]},"referralCode":{"type":"string"}}},"signature":{"$ref":"#/components/schemas/Signature"},"nonce":{"type":"integer","format":"int64","description":"Request nonce as a Unix timestamp in milliseconds. Recommended: current time in milliseconds. Must be unique; do not reuse the same nonce for another signed request."}}},"Signature":{"type":"object","required":["r","s","v"],"properties":{"r":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"s":{"type":"string","description":"32-byte hex, zero-padded to 64 chars"},"v":{"type":"integer","description":"27 or 28"}}}}}}
```


---

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

```
GET https://docs.afx.xyz/api-reference/exchange/models.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
