API reference ยท Margin
PUT
/v1/accounts/{account_id}/margin/{market}Set leverage and margin mode.
Read and trade
The leverage and margin mode new positions on the market use. Changing the leverage of an open position changes its margin.
Path parameters#
-
The account number.
-
A market id.
Request body#
-
isolated: the position has its own margin. cross: positions share the account's balance.
One of
isolatedcross -
A whole number from 1 to the market's max_leverage.
Responses#
200OK
-
A market id: the asset and USD.
-
The margin mode.
One of
isolatedcross -
The leverage.
400The request is malformed.
{
"error": {
"type": "invalid_request",
"code": "invalid_request",
"message": "The request is not valid.",
"request_id": "req_0f9c2a7d8e1b4c6a9f3e5d7b1a2c4e6f",
"retryable": false,
"doc_url": "https://docs.phoenixperpsfunding.com/reference/errors#invalid_request"
}
}401The request has no Authorization header.
{
"error": {
"type": "authentication",
"code": "missing_api_key",
"message": "No API key: send it as Authorization: Bearer <key>.",
"request_id": "req_0f9c2a7d8e1b4c6a9f3e5d7b1a2c4e6f",
"retryable": false,
"doc_url": "https://docs.phoenixperpsfunding.com/reference/errors#missing_api_key"
}
}403The key only works from the addresses you listed.
{
"error": {
"type": "permission",
"code": "ip_not_allowed",
"message": "This address is not on the key's allowlist.",
"request_id": "req_0f9c2a7d8e1b4c6a9f3e5d7b1a2c4e6f",
"retryable": false,
"doc_url": "https://docs.phoenixperpsfunding.com/reference/errors#ip_not_allowed"
}
}404The account does not exist in this environment, or the key does not reach it.
{
"error": {
"type": "not_found",
"code": "account_not_found",
"message": "No account with that id is reachable with this key.",
"request_id": "req_0f9c2a7d8e1b4c6a9f3e5d7b1a2c4e6f",
"retryable": false,
"doc_url": "https://docs.phoenixperpsfunding.com/reference/errors#account_not_found"
}
}409The account exists but is not open on the trading engine yet.
{
"error": {
"type": "conflict",
"code": "account_not_ready",
"message": "This account is still being opened.",
"request_id": "req_0f9c2a7d8e1b4c6a9f3e5d7b1a2c4e6f",
"retryable": true,
"doc_url": "https://docs.phoenixperpsfunding.com/reference/errors#account_not_ready"
}
}422The account passed, failed, or was closed (details.reason).
{
"error": {
"type": "rule_rejection",
"code": "account_not_tradable",
"message": "This account cannot trade.",
"request_id": "req_0f9c2a7d8e1b4c6a9f3e5d7b1a2c4e6f",
"retryable": false,
"doc_url": "https://docs.phoenixperpsfunding.com/reference/errors#account_not_tradable"
}
}429A request budget is used up (details.scope says which).
{
"error": {
"type": "rate_limit",
"code": "rate_limited",
"message": "Too many requests: slow down.",
"request_id": "req_0f9c2a7d8e1b4c6a9f3e5d7b1a2c4e6f",
"retryable": true,
"doc_url": "https://docs.phoenixperpsfunding.com/reference/errors#rate_limited"
}
}500An error we did not expect.
{
"error": {
"type": "server",
"code": "internal_error",
"message": "Something went wrong on our side.",
"request_id": "req_0f9c2a7d8e1b4c6a9f3e5d7b1a2c4e6f",
"retryable": true,
"doc_url": "https://docs.phoenixperpsfunding.com/reference/errors#internal_error"
}
}503The trading engine did not give a complete answer in time; nothing partial is returned.
{
"error": {
"type": "engine",
"code": "state_unavailable",
"message": "The account's figures cannot be read right now.",
"request_id": "req_0f9c2a7d8e1b4c6a9f3e5d7b1a2c4e6f",
"retryable": true,
"doc_url": "https://docs.phoenixperpsfunding.com/reference/errors#state_unavailable"
}
}Errors#
Codes this endpoint can return. Match on the code, never on the message.
- 401
missing_api_key - 401
invalid_api_key - 401
expired_api_key - 401
revoked_api_key - 401
invalid_token - 401
expired_token - 401
revoked_token - 401
wrong_resource - 401
wrong_environment - 403
ip_not_allowed - 403
api_disabled - 429
rate_limited - 404
account_not_found - 409
account_not_ready - 422
account_not_tradable - 403
insufficient_permission - 400
invalid_request - 400
unknown_field - 400
idempotency_key_required - 400
invalid_idempotency_key - 422
idempotency_key_reused - 409
operation_in_progress - 503
state_unavailable - 503
stale_quote - 503
engine_unavailable - 503
engine_busy - 422
key_market_not_allowed - 404
market_not_found - 409
margin_mode_locked - 400
invalid_leverage - 422
insufficient_margin - 422
liquidation_risk - 422
position_liquidating