> 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/account.md).

# Account

## Set Leverage

> Set leverage for a symbol.\
> \
> \*\*Signature:\*\* Agent · \*\*Protobuf:\*\* \`MsgSetLeverage\`\
> \
> \`\`\`protobuf\
> message MsgSetLeverage {\
> &#x20; int64  symbol\_code = 1;\
> &#x20; string leverage    = 2;\
> }\
> \`\`\`<br>

````json
{"openapi":"3.0.3","info":{"title":"AFX DEX Exchange API","version":"1.0.0"},"servers":[{"url":"https://api.afx.xyz","description":"Mainnet"},{"url":"https://api-testnet.afx.xyz","description":"Testnet"}],"paths":{"/exchange/setLeverage":{"post":{"operationId":"setLeverage","summary":"Set Leverage","tags":["Account"],"description":"Set leverage for a symbol.\n\n**Signature:** Agent · **Protobuf:** `MsgSetLeverage`\n\n```protobuf\nmessage MsgSetLeverage {\n  int64  symbol_code = 1;\n  string leverage    = 2;\n}\n```\n","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SetLeverageRequest"}}}},"responses":{"200":{"$ref":"#/components/responses/ExchangeOk"}}}}},"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"}}},"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"}}}}}},"responses":{"ExchangeOk":{"description":"Transaction submitted","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ExchangeResponse"}}}}}}}
````

## Set Margin Mode

> Set margin mode for a symbol.\
> \
> \*\*Signature:\*\* Agent · \*\*Protobuf:\*\* \`MsgSetMarginMode\`\
> \
> \`\`\`protobuf\
> message MsgSetMarginMode {\
> &#x20; int64              symbol\_code = 1;\
> &#x20; PositionMarginMode margin\_mode = 2;  // CROSS=1, ISOLATED=2\
> }\
> \`\`\`<br>

````json
{"openapi":"3.0.3","info":{"title":"AFX DEX Exchange API","version":"1.0.0"},"servers":[{"url":"https://api.afx.xyz","description":"Mainnet"},{"url":"https://api-testnet.afx.xyz","description":"Testnet"}],"paths":{"/exchange/setMarginMode":{"post":{"operationId":"setMarginMode","summary":"Set Margin Mode","tags":["Account"],"description":"Set margin mode for a symbol.\n\n**Signature:** Agent · **Protobuf:** `MsgSetMarginMode`\n\n```protobuf\nmessage MsgSetMarginMode {\n  int64              symbol_code = 1;\n  PositionMarginMode margin_mode = 2;  // CROSS=1, ISOLATED=2\n}\n```\n","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SetMarginModeRequest"}}}},"responses":{"200":{"$ref":"#/components/responses/ExchangeOk"}}}}},"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"}}},"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"}}}}}},"responses":{"ExchangeOk":{"description":"Transaction submitted","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ExchangeResponse"}}}}}}}
````

## Assign Position Margin

> Add or remove margin for an isolated position.\
> \
> \*\*Signature:\*\* Agent · \*\*Protobuf:\*\* \`MsgAssignPosMargin\`\
> \
> \`\`\`protobuf\
> message MsgAssignPosMargin {\
> &#x20; int64  symbol\_code        = 1;\
> &#x20; string assigned\_pos\_margin = 2;\
> }\
> \`\`\`<br>

````json
{"openapi":"3.0.3","info":{"title":"AFX DEX Exchange API","version":"1.0.0"},"servers":[{"url":"https://api.afx.xyz","description":"Mainnet"},{"url":"https://api-testnet.afx.xyz","description":"Testnet"}],"paths":{"/exchange/assignPosMargin":{"post":{"operationId":"assignPosMargin","summary":"Assign Position Margin","tags":["Account"],"description":"Add or remove margin for an isolated position.\n\n**Signature:** Agent · **Protobuf:** `MsgAssignPosMargin`\n\n```protobuf\nmessage MsgAssignPosMargin {\n  int64  symbol_code        = 1;\n  string assigned_pos_margin = 2;\n}\n```\n","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AssignPosMarginRequest"}}}},"responses":{"200":{"$ref":"#/components/responses/ExchangeOk"}}}}},"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"}}},"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"}}}}}},"responses":{"ExchangeOk":{"description":"Transaction submitted","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ExchangeResponse"}}}}}}}
````


---

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