{
  "openapi": "3.1.0",
  "info": {
    "title": "MAMX API | Exuratech",
    "description": "MAMX manages individual MT5 accounts, investor allocations, historical trade settlement at master close, and performance fees.",
    "version": "0.2.0"
  },
  "paths": {
    "/api/v1/mamx/webhooks": {
      "post": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Register the broker webhook",
        "description": "A generated signing secret is returned once.",
        "operationId": "register_api_v1_mamx_webhooks_post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Register"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EndpointInfo"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        },
        "security": [
          {
            "MAMXAdmin": []
          }
        ]
      },
      "patch": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Update the webhook URL or rotate the signing secret",
        "operationId": "update_api_v1_mamx_webhooks_patch",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Update"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EndpointInfo"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        },
        "security": [
          {
            "MAMXAdmin": []
          }
        ]
      }
    },
    "/health": {
      "get": {
        "tags": [
          "Health"
        ],
        "summary": "Get API health",
        "description": "A fresh agent report includes an MT5 server-time read. Null means unknown, not disconnected.",
        "operationId": "health_health_get",
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          }
        }
      }
    },
    "/api/v1/mamx/preview-close": {
      "post": {
        "tags": [
          "Preview"
        ],
        "summary": "Preview a close allocation",
        "operationId": "preview_api_v1_mamx_preview_close_post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ClosePreview"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        },
        "security": [
          {
            "MAMXAdmin": []
          }
        ]
      }
    },
    "/api/v1/mamx/operations/{operation_id}": {
      "get": {
        "tags": [
          "Operations"
        ],
        "summary": "Get operation status and results",
        "description": "Track account creation, fee collection, and withdrawals.\nPENDING awaits processing; RUNNING is in progress; DONE is complete;\nREVIEW requires reconciliation; RECOVERABLE has authorized recovery.\nPasswords and worker tokens are not included.",
        "operationId": "operation_api_v1_mamx_operations__operation_id__get",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "operation_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Operation Id"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/mamx/operations/{operation_id}/credentials": {
      "get": {
        "tags": [
          "Operations"
        ],
        "summary": "Get account credentials",
        "description": "Retrieve role, login, password, and investor_password for completed account creation.\nRequires an administrative key. Responses are not cached.\nRepeated requests return the same credentials without changing them.",
        "operationId": "credentials_api_v1_mamx_operations__operation_id__credentials_get",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "operation_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Operation Id"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/mamx/accounts/create": {
      "post": {
        "tags": [
          "Accounts"
        ],
        "summary": "Create an MT5 account",
        "description": "Create an independent account without subscribing it to a master.\nSet can_be_leader=true for a master or can_be_follower=true for an investor.\nInvestor trading is disabled; the MT5 group must use Hedging.\nReturns 201 with mt5_login and credentials when complete, 202 with\noperation_id and status_url while pending, or 409 when review is required.\nReuse the same request_key and payload to retrieve the result without\ncreating another account.",
        "operationId": "create_account_api_v1_mamx_accounts_create_post",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "wait_timeout_sec",
            "in": "query",
            "required": false,
            "schema": {
              "type": "number",
              "maximum": 60.0,
              "minimum": 0.0,
              "default": 60,
              "title": "Wait Timeout Sec"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AccountCreate"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountCreatedResponse"
                }
              }
            }
          },
          "202": {
            "description": "Account creation pending; reuse the same request_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountCreationPending"
                }
              }
            }
          },
          "409": {
            "description": "Account creation requires review",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountCreationPending"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/mamx/accounts/add": {
      "post": {
        "tags": [
          "Accounts"
        ],
        "summary": "Register an existing MT5 account in MAMX",
        "description": "The agent verifies the MT5 login and group; it never creates or changes the MT5 user.\nUse a trading-enabled leader or a trading-disabled investor in a hedging group.\nRegistration does not promote the account or subscribe the investor.",
        "operationId": "add_account_api_v1_mamx_accounts_add_post",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "wait_timeout_sec",
            "in": "query",
            "required": false,
            "schema": {
              "type": "number",
              "maximum": 60.0,
              "minimum": 0.0,
              "default": 60,
              "title": "Wait Timeout Sec"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AccountImport"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountUpdatedResponse"
                }
              }
            }
          },
          "202": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountCreationPending"
                }
              }
            },
            "description": "Accepted"
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountCreationPending"
                }
              }
            },
            "description": "Conflict"
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/mamx/accounts": {
      "get": {
        "tags": [
          "Accounts"
        ],
        "summary": "List accounts",
        "operationId": "accounts_api_v1_mamx_accounts_get",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "server",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Server"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "maximum": 100,
              "minimum": 1,
              "default": 50,
              "title": "Limit"
            }
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0,
              "title": "Offset"
            }
          },
          {
            "name": "include_deleted",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean",
              "default": false,
              "title": "Include Deleted"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/mamx/accounts/{account_login}": {
      "get": {
        "tags": [
          "Accounts"
        ],
        "summary": "Get an account by MT5 login",
        "operationId": "account_api_v1_mamx_accounts__account_login__get",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "account_login",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Account Login"
            }
          },
          {
            "name": "server",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Server"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Accounts"
        ],
        "summary": "Delete an account from MAMX",
        "description": "End participation immediately and crystallize outstanding PF only. No MT5 user,\nfunds, trading rights or history are changed by deletion itself. For a master,\nall its allocations end; investor accounts and the payment account are retained.\nAn unsettled close or balance transfer returns 409; retry after completion.\nThe same DELETE returns the same record. Fees listed in final_fee_ids are\ncollected asynchronously: DELETED does not mean the payment has cleared.",
        "operationId": "delete_account_api_v1_mamx_accounts__account_login__delete",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "account_login",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Account Login"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Accounts"
        ],
        "summary": "Update an account",
        "description": "Update the name or role while preserving the login, credentials, balance, and group.\nRole changes require no master, subscription, or payment links and no open\npositions or pending orders. Currency, group, and account mode cannot be changed.\nReturns 200 when confirmed, 202 while pending, or 409 when review is required.\nReuse Idempotency-Key with the same payload to retry the request.",
        "operationId": "update_account_api_v1_mamx_accounts__account_login__patch",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "account_login",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Account Login"
            }
          },
          {
            "name": "wait_timeout_sec",
            "in": "query",
            "required": false,
            "schema": {
              "type": "number",
              "maximum": 60.0,
              "minimum": 0.0,
              "default": 60,
              "title": "Wait Timeout Sec"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 8,
                  "maxLength": 100
                },
                {
                  "type": "null"
                }
              ],
              "title": "Idempotency-Key"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AccountUpdate"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountUpdatedResponse"
                }
              }
            }
          },
          "202": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountCreationPending"
                }
              }
            },
            "description": "Accepted"
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountCreationPending"
                }
              }
            },
            "description": "Conflict"
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/mamx/accounts/{account_login}/deposit": {
      "post": {
        "tags": [
          "Accounts"
        ],
        "summary": "Deposit funds into a trading account",
        "description": "Credit the specified master or investor trading account's own MT5 balance.\nPayment accounts are excluded. This is not MT5 credit, a bank payment or trading profit.\nUse exactly one funding channel per deposit. Reuse the same idempotency_key and amount\non timeout. Track /operations/{id} until DONE. REVIEW requires reconciliation, not\na new key. The agent processes accepted deposits automatically.",
        "operationId": "account_deposit_api_v1_mamx_accounts__account_login__deposit_post",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "account_login",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Account Login"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AccountDeposit"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/mamx/accounts/{account_login}/withdraw": {
      "post": {
        "tags": [
          "Accounts"
        ],
        "summary": "Withdraw investor funds after collecting performance fees",
        "description": "Execute an MT5 balance withdrawal after any due performance fee is paid.\nAvailable funds exclude credit and the performance fee. Captured settlements\nmust finish first; pending imports return 409 without creating a withdrawal.\nHTTP 202 means pending execution. Track /operations/{id} until DONE;\nREJECTED means insufficient funds with no new fee or withdrawal executed,\nand REVIEW requires reconciliation before retrying execution.\nReuse the same idempotency_key and amount, including after a timeout.\nRequires INVESTOR_WITHDRAWAL_ENABLED and PERFORMANCE_FEE_EXECUTION_ENABLED\non the agent. Unsubscribing is not required and no bank transfer is made.",
        "operationId": "withdraw_investor_api_v1_mamx_accounts__account_login__withdraw_post",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "account_login",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Account Login"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InvestorWithdrawal"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/mamx/leaders": {
      "post": {
        "tags": [
          "Leaders"
        ],
        "summary": "Register a master and link its payment account",
        "description": "Register an existing account with can_be_leader=true as a master.\nWith payment_account_login, verify and link that existing trading-disabled account.\nWithout it, create a payment account in the master group. An invalid supplied\nlogin never falls back to creating an account.\nDoes not create another trading account or subscribe investors.\nTrack /operations/{id} until DONE; evidence.result.master_id is the master ID.\nCredentials are available only for a newly created payment account.",
        "operationId": "create_leader_api_v1_mamx_leaders_post",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LeaderCreate"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Leaders"
        ],
        "summary": "List masters",
        "operationId": "leaders_api_v1_mamx_leaders_get",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "server",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Server"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "maximum": 100,
              "minimum": 1,
              "default": 50,
              "title": "Limit"
            }
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0,
              "title": "Offset"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/mamx/leaders/{leader_id}": {
      "get": {
        "tags": [
          "Leaders"
        ],
        "summary": "Get a master profile",
        "operationId": "leader_api_v1_mamx_leaders__leader_id__get",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "leader_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Leader Id"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Leaders"
        ],
        "summary": "Edit a master strategy and fee terms",
        "description": "Use the internal master ID. Editing fee terms crystallizes accrued PF under\nthe old terms before applying the new rate/period. A name-only edit does not\ncrystallize fees. Send the same Idempotency-Key on retries. Unsettled fees,\nclose imports or balance transfers return 409 on a change of fee terms.",
        "operationId": "edit_leader_api_v1_mamx_leaders__leader_id__patch",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "leader_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Leader Id"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 8,
                  "maxLength": 100
                },
                {
                  "type": "null"
                }
              ],
              "title": "Idempotency-Key"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LeaderEdit"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/mamx/allocations": {
      "post": {
        "tags": [
          "Allocations"
        ],
        "summary": "Subscribe an investor",
        "description": "Subscribe an existing investor account to a master.\nBoth accounts must use the same server and currency.\nThe investor inherits the master performance fee and participates in future\nclose captures. Account creation does not create a subscription.\nSend idempotency_key for retry safety; an old key never reactivates a cancelled allocation.\nUse a new key only for a new subscription intent.",
        "operationId": "allocate_api_v1_mamx_allocations_post",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AllocationCreate"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Allocations"
        ],
        "summary": "List allocations",
        "operationId": "allocations_api_v1_mamx_allocations_get",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "server",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Server"
            }
          },
          {
            "name": "leader_login",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Leader Login"
            }
          },
          {
            "name": "follower_login",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Follower Login"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "maximum": 100,
              "minimum": 1,
              "default": 50,
              "title": "Limit"
            }
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0,
              "title": "Offset"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/mamx/allocations/{allocation_id}": {
      "get": {
        "tags": [
          "Allocations"
        ],
        "summary": "Get an allocation",
        "operationId": "allocation_api_v1_mamx_allocations__allocation_id__get",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "allocation_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Allocation Id"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Allocations"
        ],
        "summary": "Update allocation settings",
        "operationId": "update_allocation_api_v1_mamx_allocations__allocation_id__patch",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "allocation_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Allocation Id"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AllocationSettings"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/mamx/allocations/{allocation_id}/unsubscribe": {
      "post": {
        "tags": [
          "Allocations"
        ],
        "summary": "Unsubscribe an investor",
        "description": "Exclude the investor from future close captures.\nExisting settlements remain payable. Final performance fees are calculated\nwhen settlement processing allows it and collected asynchronously by the agent.\nThis response does not confirm fee payment or withdraw investor funds.\nCheck /allocations/{allocation_id}/fees for fee status.\nAccounts and historical records are preserved.",
        "operationId": "unsubscribe_api_v1_mamx_allocations__allocation_id__unsubscribe_post",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "allocation_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Allocation Id"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/mamx/leaders/{master_login}/payment-account/balance": {
      "get": {
        "tags": [
          "Payment Accounts"
        ],
        "summary": "Get a payment account balance",
        "description": "Return the latest agent snapshot, not a direct MT5 query.\nfresh is true for 15 seconds; metrics=null means no snapshot is available.\nRequest /balance/refresh to update it.",
        "operationId": "payment_balance_api_v1_mamx_leaders__master_login__payment_account_balance_get",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "master_login",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Master Login"
            }
          },
          {
            "name": "server",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Server"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentBalanceView"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/mamx/leaders/{master_login}/payment-account/balance/refresh": {
      "post": {
        "tags": [
          "Payment Accounts"
        ],
        "summary": "Refresh a payment account balance",
        "operationId": "refresh_payment_api_v1_mamx_leaders__master_login__payment_account_balance_refresh_post",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "master_login",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Master Login"
            }
          },
          {
            "name": "server",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Server"
            }
          }
        ],
        "responses": {
          "202": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/mamx/leaders/{master_login}/payment-account/withdraw": {
      "post": {
        "tags": [
          "Payment Accounts"
        ],
        "summary": "Withdraw from a payment account",
        "description": "Execute a balance withdrawal from the master's MT5 payment account.\nThe agent automatically executes the debit; no separate approval is required.\nHTTP 202 means execution is pending, not that funds have already been debited.\nTrack /operations/{id} until DONE and reuse the same idempotency_key on retries.\nThis does not withdraw investor funds or crystallize investor performance fees.\nRequires PAYMENT_WITHDRAWAL_ENABLED on the agent.",
        "operationId": "withdraw_payment_api_v1_mamx_leaders__master_login__payment_account_withdraw_post",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "master_login",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Master Login"
            }
          },
          {
            "name": "server",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Server"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PaymentWithdrawal"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/mamx/allocations/{allocation_id}/fees": {
      "get": {
        "tags": [
          "Performance Fees"
        ],
        "summary": "List allocation fees",
        "operationId": "fees_api_v1_mamx_allocations__allocation_id__fees_get",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "allocation_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Allocation Id"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/FeeSummary"
                  },
                  "title": "Response Fees Api V1 Mamx Allocations  Allocation Id  Fees Get"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/mamx/leaders/{leader_id}/performance-fees/credit-batches": {
      "get": {
        "tags": [
          "Performance Fees"
        ],
        "summary": "List master credit batches",
        "description": "leader_id is the internal master profile ID, not the MT5 login.",
        "operationId": "batches_api_v1_mamx_leaders__leader_id__performance_fees_credit_batches_get",
        "security": [
          {
            "MAMXAdmin": []
          }
        ],
        "parameters": [
          {
            "name": "leader_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Leader Id"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/CreditBatchView"
                  },
                  "title": "Response Batches Api V1 Mamx Leaders  Leader Id  Performance Fees Credit Batches Get"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "AccountCreate": {
        "properties": {
          "request_key": {
            "type": "string",
            "maxLength": 100,
            "minLength": 8,
            "title": "Request Key",
            "description": "Unique account creation key. Reuse the same key and payload to retry; a new key requests another account."
          },
          "server": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 120,
                "minLength": 1
              },
              {
                "type": "null"
              }
            ],
            "title": "Server",
            "description": "Defaults to the API server configuration. If supplied, it must match."
          },
          "platform_group": {
            "type": "string",
            "maxLength": 128,
            "minLength": 1,
            "title": "Platform Group",
            "description": "Exact existing MT5 Hedging group name, without wildcards. The payment account uses the master group."
          },
          "name": {
            "type": "string",
            "maxLength": 100,
            "minLength": 1,
            "title": "Name"
          },
          "username": {
            "type": "string",
            "maxLength": 100,
            "title": "Username",
            "default": ""
          },
          "leverage": {
            "type": "integer",
            "maximum": 10000.0,
            "minimum": 1.0,
            "title": "Leverage",
            "default": 100
          },
          "currency": {
            "type": "string",
            "pattern": "^[A-Z]{3}$",
            "title": "Currency",
            "default": "USD"
          },
          "currency_digits": {
            "type": "integer",
            "maximum": 8.0,
            "minimum": 0.0,
            "title": "Currency Digits",
            "default": 2
          },
          "can_be_leader": {
            "type": "boolean",
            "title": "Can Be Leader",
            "default": false
          },
          "can_be_follower": {
            "type": "boolean",
            "title": "Can Be Follower",
            "default": true
          },
          "account_mode": {
            "type": "string",
            "enum": [
              "HEDGING"
            ],
            "const": "HEDGING",
            "title": "Account Mode",
            "default": "HEDGING"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "request_key",
          "platform_group",
          "name"
        ],
        "title": "AccountCreate",
        "examples": [
          {
            "name": "Example Investor",
            "platform_group": "demo\\MAMX",
            "request_key": "account-test-001"
          }
        ]
      },
      "AccountCreatedResponse": {
        "properties": {
          "id": {
            "type": "string",
            "title": "Id"
          },
          "mt5_login": {
            "type": "string",
            "title": "Mt5 Login"
          },
          "name": {
            "type": "string",
            "title": "Name"
          },
          "currency": {
            "type": "string",
            "title": "Currency"
          },
          "platform_group": {
            "type": "string",
            "title": "Platform Group"
          },
          "leverage": {
            "type": "integer",
            "title": "Leverage"
          },
          "account_mode": {
            "type": "string",
            "enum": [
              "HEDGING"
            ],
            "const": "HEDGING",
            "title": "Account Mode"
          },
          "can_be_leader": {
            "type": "boolean",
            "title": "Can Be Leader"
          },
          "can_be_follower": {
            "type": "boolean",
            "title": "Can Be Follower"
          },
          "status": {
            "type": "string",
            "enum": [
              "ACTIVE"
            ],
            "const": "ACTIVE",
            "title": "Status"
          },
          "trading_disabled": {
            "type": "boolean",
            "title": "Trading Disabled"
          },
          "created_at": {
            "type": "string",
            "title": "Created At"
          },
          "password": {
            "type": "string",
            "title": "Password"
          },
          "investor_password": {
            "type": "string",
            "title": "Investor Password"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "id",
          "mt5_login",
          "name",
          "currency",
          "platform_group",
          "leverage",
          "account_mode",
          "can_be_leader",
          "can_be_follower",
          "status",
          "trading_disabled",
          "created_at",
          "password",
          "investor_password"
        ],
        "title": "AccountCreatedResponse"
      },
      "AccountCreationPending": {
        "properties": {
          "id": {
            "type": "string",
            "title": "Id"
          },
          "operation_id": {
            "type": "string",
            "title": "Operation Id"
          },
          "status": {
            "type": "string",
            "title": "Status"
          },
          "mt5_login": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Mt5 Login"
          },
          "status_url": {
            "type": "string",
            "title": "Status Url"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "id",
          "operation_id",
          "status",
          "status_url"
        ],
        "title": "AccountCreationPending"
      },
      "AccountDeposit": {
        "properties": {
          "idempotency_key": {
            "type": "string",
            "maxLength": 100,
            "minLength": 8,
            "pattern": ".*\\S.*",
            "title": "Idempotency Key"
          },
          "amount": {
            "anyOf": [
              {
                "type": "number",
                "exclusiveMinimum": 0.0
              },
              {
                "type": "string"
              }
            ],
            "title": "Amount",
            "description": "Positive MT5 balance deposit in the master or investor trading account currency, not credit or trading profit.",
            "default": "0"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "idempotency_key"
        ],
        "title": "AccountDeposit"
      },
      "AccountImport": {
        "properties": {
          "server": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Server"
          },
          "request_key": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 100,
                "minLength": 8
              },
              {
                "type": "null"
              }
            ],
            "title": "Request Key",
            "description": "Defaults to a stable import key for this MT5 login."
          },
          "mt5_login": {
            "type": "string",
            "pattern": "^[1-9][0-9]{0,19}$",
            "title": "Mt5 Login"
          },
          "can_be_leader": {
            "type": "boolean",
            "title": "Can Be Leader",
            "default": false
          },
          "can_be_follower": {
            "type": "boolean",
            "title": "Can Be Follower",
            "default": true
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "mt5_login"
        ],
        "title": "AccountImport"
      },
      "AccountUpdate": {
        "properties": {
          "name": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 100,
                "minLength": 1
              },
              {
                "type": "null"
              }
            ],
            "title": "Name"
          },
          "can_be_leader": {
            "anyOf": [
              {
                "type": "boolean"
              },
              {
                "type": "null"
              }
            ],
            "title": "Can Be Leader"
          },
          "can_be_follower": {
            "anyOf": [
              {
                "type": "boolean"
              },
              {
                "type": "null"
              }
            ],
            "title": "Can Be Follower"
          },
          "currency": {
            "anyOf": [
              {
                "type": "string",
                "pattern": "^[A-Z]{3}$"
              },
              {
                "type": "null"
              }
            ],
            "title": "Currency"
          },
          "account_mode": {
            "anyOf": [
              {
                "type": "string",
                "enum": [
                  "HEDGING"
                ],
                "const": "HEDGING"
              },
              {
                "type": "null"
              }
            ],
            "title": "Account Mode"
          },
          "status": {
            "anyOf": [
              {
                "type": "string",
                "enum": [
                  "ACTIVE"
                ],
                "const": "ACTIVE"
              },
              {
                "type": "null"
              }
            ],
            "title": "Status"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "title": "AccountUpdate",
        "examples": [
          {
            "can_be_follower": false,
            "can_be_leader": true
          }
        ]
      },
      "AccountUpdatedResponse": {
        "properties": {
          "id": {
            "type": "string",
            "title": "Id"
          },
          "operation_id": {
            "type": "string",
            "title": "Operation Id"
          },
          "mt5_login": {
            "type": "string",
            "title": "Mt5 Login"
          },
          "name": {
            "type": "string",
            "title": "Name"
          },
          "currency": {
            "type": "string",
            "title": "Currency"
          },
          "currency_digits": {
            "type": "integer",
            "title": "Currency Digits"
          },
          "platform_group": {
            "type": "string",
            "title": "Platform Group"
          },
          "account_mode": {
            "type": "string",
            "enum": [
              "HEDGING"
            ],
            "const": "HEDGING",
            "title": "Account Mode"
          },
          "can_be_leader": {
            "type": "boolean",
            "title": "Can Be Leader"
          },
          "can_be_follower": {
            "type": "boolean",
            "title": "Can Be Follower"
          },
          "status": {
            "type": "string",
            "enum": [
              "ACTIVE"
            ],
            "const": "ACTIVE",
            "title": "Status"
          },
          "trading_disabled": {
            "type": "boolean",
            "title": "Trading Disabled"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "id",
          "operation_id",
          "mt5_login",
          "name",
          "currency",
          "currency_digits",
          "platform_group",
          "account_mode",
          "can_be_leader",
          "can_be_follower",
          "status",
          "trading_disabled"
        ],
        "title": "AccountUpdatedResponse"
      },
      "AllocationCreate": {
        "properties": {
          "allocation_mode": {
            "type": "string",
            "enum": [
              "BALANCE",
              "EQUITY",
              "EQUITY_ROUND_DOWN",
              "SCALED",
              "FIXED"
            ],
            "title": "Allocation Mode",
            "description": "Allocation method at close. BALANCE/EQUITY divide investor balance/equity by the observed master base, excluding unsettled close results and attributable entry costs. EQUITY_ROUND_DOWN applies volume limits; SCALED uses a multiplier; FIXED prorates fixed lots across partial closes.",
            "default": "BALANCE"
          },
          "mode_parameter": {
            "anyOf": [
              {
                "type": "number",
                "exclusiveMinimum": 0.0
              },
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Mode Parameter",
            "description": "Multiplier for proportional modes (null means 1). Required for SCALED and FIXED. For FIXED, the value is the full-position lot size, not the size of each partial close."
          },
          "idempotency_key": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 100,
                "minLength": 8,
                "pattern": "^[A-Za-z0-9_.:-]+$"
              },
              {
                "type": "null"
              }
            ],
            "title": "Idempotency Key",
            "description": "Use a unique key per subscription intent. Replays return the current allocation without reactivating it."
          },
          "server": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 120,
                "minLength": 1
              },
              {
                "type": "null"
              }
            ],
            "title": "Server",
            "description": "Defaults to the API server configuration. If supplied, it must match."
          },
          "leader_login": {
            "type": "string",
            "pattern": "^[1-9][0-9]{0,19}$",
            "title": "Leader Login"
          },
          "follower_login": {
            "type": "string",
            "pattern": "^[1-9][0-9]{0,19}$",
            "title": "Follower Login"
          },
          "status": {
            "type": "string",
            "enum": [
              "ACTIVE"
            ],
            "const": "ACTIVE",
            "title": "Status",
            "default": "ACTIVE"
          },
          "performance_fee_rate": {
            "anyOf": [
              {
                "type": "number",
                "maximum": 1.0,
                "minimum": 0.0
              },
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Performance Fee Rate"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "leader_login",
          "follower_login"
        ],
        "title": "AllocationCreate",
        "examples": [
          {
            "follower_login": "100002",
            "leader_login": "100001"
          }
        ]
      },
      "AllocationSettings": {
        "properties": {
          "allocation_mode": {
            "type": "string",
            "enum": [
              "BALANCE",
              "EQUITY",
              "EQUITY_ROUND_DOWN",
              "SCALED",
              "FIXED"
            ],
            "title": "Allocation Mode",
            "description": "Allocation method at close. BALANCE/EQUITY divide investor balance/equity by the observed master base, excluding unsettled close results and attributable entry costs. EQUITY_ROUND_DOWN applies volume limits; SCALED uses a multiplier; FIXED prorates fixed lots across partial closes.",
            "default": "BALANCE"
          },
          "mode_parameter": {
            "anyOf": [
              {
                "type": "number",
                "exclusiveMinimum": 0.0
              },
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Mode Parameter",
            "description": "Multiplier for proportional modes (null means 1). Required for SCALED and FIXED. For FIXED, the value is the full-position lot size, not the size of each partial close."
          }
        },
        "additionalProperties": false,
        "type": "object",
        "title": "AllocationSettings"
      },
      "CloseDeal": {
        "properties": {
          "server": {
            "type": "string",
            "maxLength": 120,
            "minLength": 1,
            "title": "Server"
          },
          "master_login": {
            "type": "string",
            "pattern": "^[1-9][0-9]{0,19}$",
            "title": "Master Login"
          },
          "deal_id": {
            "type": "integer",
            "exclusiveMaximum": 1.8446744073709552e+19,
            "exclusiveMinimum": 0.0,
            "title": "Deal Id"
          },
          "position_id": {
            "type": "integer",
            "exclusiveMaximum": 1.8446744073709552e+19,
            "exclusiveMinimum": 0.0,
            "title": "Position Id"
          },
          "entry": {
            "type": "string",
            "enum": [
              "OUT",
              "OUT_BY"
            ],
            "title": "Entry"
          },
          "symbol": {
            "type": "string",
            "maxLength": 64,
            "minLength": 1,
            "title": "Symbol"
          },
          "currency": {
            "type": "string",
            "pattern": "^[A-Z]{3}$",
            "title": "Currency"
          },
          "currency_digits": {
            "type": "integer",
            "maximum": 8.0,
            "minimum": 0.0,
            "title": "Currency Digits",
            "default": 2
          },
          "volume": {
            "anyOf": [
              {
                "type": "number",
                "exclusiveMinimum": 0.0
              },
              {
                "type": "string"
              }
            ],
            "title": "Volume"
          },
          "position_open_volume": {
            "anyOf": [
              {
                "type": "number",
                "exclusiveMinimum": 0.0
              },
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Position Open Volume"
          },
          "profit": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "string"
              }
            ],
            "title": "Profit"
          },
          "commission": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "string"
              }
            ],
            "title": "Commission",
            "default": "0"
          },
          "swap": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "string"
              }
            ],
            "title": "Swap",
            "default": "0"
          },
          "fee": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "string"
              }
            ],
            "title": "Fee",
            "default": "0"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "server",
          "master_login",
          "deal_id",
          "position_id",
          "entry",
          "symbol",
          "currency",
          "volume",
          "profit"
        ],
        "title": "CloseDeal"
      },
      "ClosePreview": {
        "properties": {
          "deal": {
            "$ref": "#/components/schemas/CloseDeal"
          },
          "master_balance": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "string"
              }
            ],
            "title": "Master Balance"
          },
          "master_equity": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Master Equity"
          },
          "investors": {
            "items": {
              "$ref": "#/components/schemas/InvestorSnapshot"
            },
            "type": "array",
            "maxItems": 10000,
            "title": "Investors"
          },
          "opening_costs": {
            "$ref": "#/components/schemas/OpeningCosts"
          },
          "later_closes": {
            "items": {
              "$ref": "#/components/schemas/PendingCloseResult"
            },
            "type": "array",
            "maxItems": 1000,
            "title": "Later Closes"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "deal",
          "master_balance",
          "investors"
        ],
        "title": "ClosePreview"
      },
      "CreditBatchPayload": {
        "properties": {
          "master_id": {
            "type": "string",
            "title": "Master Id"
          },
          "master_login": {
            "type": "string",
            "title": "Master Login"
          },
          "payment_account_login": {
            "type": "string",
            "title": "Payment Account Login"
          },
          "currency": {
            "type": "string",
            "title": "Currency"
          },
          "currency_digits": {
            "type": "integer",
            "title": "Currency Digits"
          },
          "amount": {
            "type": "string",
            "title": "Amount"
          },
          "period_start": {
            "type": "string",
            "title": "Period Start"
          },
          "period_end": {
            "type": "string",
            "title": "Period End"
          },
          "members": {
            "items": {
              "$ref": "#/components/schemas/CreditMember"
            },
            "type": "array",
            "title": "Members"
          }
        },
        "type": "object",
        "required": [
          "master_id",
          "master_login",
          "payment_account_login",
          "currency",
          "currency_digits",
          "amount",
          "period_start",
          "period_end",
          "members"
        ],
        "title": "CreditBatchPayload"
      },
      "CreditBatchView": {
        "properties": {
          "id": {
            "type": "string",
            "title": "Id"
          },
          "server": {
            "type": "string",
            "title": "Server"
          },
          "kind": {
            "type": "string",
            "enum": [
              "FEE_CREDIT"
            ],
            "const": "FEE_CREDIT",
            "title": "Kind"
          },
          "status": {
            "type": "string",
            "title": "Status"
          },
          "step": {
            "type": "string",
            "title": "Step"
          },
          "payload": {
            "$ref": "#/components/schemas/CreditBatchPayload"
          },
          "evidence": {
            "type": "object",
            "title": "Evidence"
          },
          "error": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Error"
          },
          "created_at": {
            "type": "string",
            "title": "Created At"
          }
        },
        "type": "object",
        "required": [
          "id",
          "server",
          "kind",
          "status",
          "step",
          "payload",
          "evidence",
          "error",
          "created_at"
        ],
        "title": "CreditBatchView"
      },
      "CreditMember": {
        "properties": {
          "fee_id": {
            "type": "string",
            "title": "Fee Id"
          },
          "investor_login": {
            "type": "string",
            "title": "Investor Login"
          },
          "amount": {
            "type": "string",
            "title": "Amount"
          },
          "debit_operation_id": {
            "type": "string",
            "title": "Debit Operation Id"
          },
          "debit_ticket": {
            "type": "integer",
            "title": "Debit Ticket"
          }
        },
        "type": "object",
        "required": [
          "fee_id",
          "investor_login",
          "amount",
          "debit_operation_id",
          "debit_ticket"
        ],
        "title": "CreditMember"
      },
      "EndpointInfo": {
        "properties": {
          "id": {
            "type": "integer",
            "title": "Id",
            "default": 1
          },
          "name": {
            "type": "string",
            "title": "Name"
          },
          "url": {
            "type": "string",
            "title": "Url"
          },
          "status": {
            "type": "string",
            "title": "Status",
            "default": "ACTIVE"
          },
          "signature_algorithm": {
            "type": "string",
            "title": "Signature Algorithm",
            "default": "HMAC-SHA256"
          },
          "created_at": {
            "type": "string",
            "title": "Created At"
          },
          "signing_secret": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Signing Secret"
          }
        },
        "type": "object",
        "required": [
          "name",
          "url",
          "created_at"
        ],
        "title": "EndpointInfo"
      },
      "FeeSummary": {
        "properties": {
          "id": {
            "type": "string",
            "title": "Id"
          },
          "amount": {
            "type": "string",
            "title": "Amount"
          },
          "status": {
            "type": "string",
            "enum": [
              "PENDING",
              "DEBITED",
              "PAID"
            ],
            "title": "Status"
          },
          "high_watermark": {
            "type": "string",
            "title": "High Watermark"
          }
        },
        "type": "object",
        "required": [
          "id",
          "amount",
          "status",
          "high_watermark"
        ],
        "title": "FeeSummary"
      },
      "HTTPValidationError": {
        "properties": {
          "detail": {
            "items": {
              "$ref": "#/components/schemas/ValidationError"
            },
            "type": "array",
            "title": "Detail"
          }
        },
        "type": "object",
        "title": "HTTPValidationError"
      },
      "InvestorSnapshot": {
        "properties": {
          "allocation_mode": {
            "type": "string",
            "enum": [
              "BALANCE",
              "EQUITY",
              "EQUITY_ROUND_DOWN",
              "SCALED",
              "FIXED"
            ],
            "title": "Allocation Mode",
            "description": "Allocation method at close. BALANCE/EQUITY divide investor balance/equity by the observed master base, excluding unsettled close results and attributable entry costs. EQUITY_ROUND_DOWN applies volume limits; SCALED uses a multiplier; FIXED prorates fixed lots across partial closes.",
            "default": "BALANCE"
          },
          "mode_parameter": {
            "anyOf": [
              {
                "type": "number",
                "exclusiveMinimum": 0.0
              },
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Mode Parameter",
            "description": "Multiplier for proportional modes (null means 1). Required for SCALED and FIXED. For FIXED, the value is the full-position lot size, not the size of each partial close."
          },
          "login": {
            "type": "string",
            "pattern": "^[1-9][0-9]{0,19}$",
            "title": "Login"
          },
          "balance": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "string"
              }
            ],
            "title": "Balance"
          },
          "equity": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Equity"
          },
          "volume_min": {
            "anyOf": [
              {
                "type": "number",
                "exclusiveMinimum": 0.0
              },
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Volume Min"
          },
          "volume_max": {
            "anyOf": [
              {
                "type": "number",
                "exclusiveMinimum": 0.0
              },
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Volume Max"
          },
          "volume_step": {
            "anyOf": [
              {
                "type": "number",
                "exclusiveMinimum": 0.0
              },
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Volume Step"
          },
          "currency": {
            "type": "string",
            "pattern": "^[A-Z]{3}$",
            "title": "Currency"
          },
          "active": {
            "type": "boolean",
            "title": "Active",
            "default": true
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "login",
          "balance",
          "currency"
        ],
        "title": "InvestorSnapshot"
      },
      "InvestorWithdrawal": {
        "properties": {
          "idempotency_key": {
            "type": "string",
            "maxLength": 100,
            "minLength": 8,
            "pattern": ".*\\S.*",
            "title": "Idempotency Key",
            "description": "Reuse the same key and amount on retries to prevent duplicate withdrawals."
          },
          "amount": {
            "anyOf": [
              {
                "type": "number",
                "exclusiveMinimum": 0.0
              },
              {
                "type": "string"
              }
            ],
            "title": "Amount",
            "description": "Withdrawal amount in account currency, excluding the separately collected performance fee.",
            "default": "0"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "idempotency_key"
        ],
        "title": "InvestorWithdrawal",
        "examples": [
          {
            "amount": "25.00",
            "idempotency_key": "investor-withdrawal-001"
          }
        ]
      },
      "LeaderCreate": {
        "properties": {
          "request_key": {
            "type": "string",
            "maxLength": 100,
            "minLength": 8,
            "title": "Request Key"
          },
          "server": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 120,
                "minLength": 1
              },
              {
                "type": "null"
              }
            ],
            "title": "Server",
            "description": "Defaults to the API server configuration. If supplied, it must match."
          },
          "account_login": {
            "type": "string",
            "pattern": "^[1-9][0-9]{0,19}$",
            "title": "Account Login"
          },
          "strategy_name": {
            "type": "string",
            "maxLength": 100,
            "minLength": 1,
            "title": "Strategy Name"
          },
          "payment_account_login": {
            "anyOf": [
              {
                "type": "string",
                "pattern": "^[1-9][0-9]{0,19}$"
              },
              {
                "type": "null"
              }
            ],
            "title": "Payment Account Login",
            "description": "Existing MT5 payment login. Omit to create one in the master group."
          },
          "performance_fee_rate": {
            "anyOf": [
              {
                "type": "number",
                "maximum": 1.0,
                "minimum": 0.0
              },
              {
                "type": "string"
              }
            ],
            "title": "Performance Fee Rate",
            "default": "0.2"
          },
          "performance_fee_period": {
            "type": "string",
            "enum": [
              "OFF",
              "MINUTELY",
              "HOURLY",
              "DAILY",
              "WEEKLY",
              "SEMIMONTHLY",
              "MONTHLY"
            ],
            "title": "Performance Fee Period",
            "default": "MONTHLY"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "request_key",
          "account_login",
          "strategy_name"
        ],
        "title": "LeaderCreate",
        "examples": [
          {
            "account_login": "100001",
            "request_key": "leader-test-001",
            "strategy_name": "Example Strategy"
          }
        ]
      },
      "LeaderEdit": {
        "properties": {
          "strategy_name": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 100,
                "minLength": 1,
                "pattern": ".*\\S.*"
              },
              {
                "type": "null"
              }
            ],
            "title": "Strategy Name"
          },
          "performance_fee_rate": {
            "anyOf": [
              {
                "type": "number",
                "maximum": 1.0,
                "minimum": 0.0
              },
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Performance Fee Rate"
          },
          "performance_fee_period": {
            "anyOf": [
              {
                "type": "string",
                "enum": [
                  "OFF",
                  "MINUTELY",
                  "HOURLY",
                  "DAILY",
                  "WEEKLY",
                  "SEMIMONTHLY",
                  "MONTHLY"
                ]
              },
              {
                "type": "null"
              }
            ],
            "title": "Performance Fee Period"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "title": "LeaderEdit"
      },
      "OpeningCosts": {
        "properties": {
          "commission": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "string"
              }
            ],
            "title": "Commission",
            "default": "0"
          },
          "swap": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "string"
              }
            ],
            "title": "Swap",
            "default": "0"
          },
          "fee": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "string"
              }
            ],
            "title": "Fee",
            "default": "0"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "title": "OpeningCosts"
      },
      "PaymentBalanceView": {
        "properties": {
          "master_login": {
            "type": "string",
            "title": "Master Login"
          },
          "payment_account_login": {
            "type": "string",
            "title": "Payment Account Login"
          },
          "currency": {
            "type": "string",
            "title": "Currency"
          },
          "fresh": {
            "type": "boolean",
            "title": "Fresh"
          },
          "observed_at": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Observed At"
          },
          "metrics": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/PaymentMetrics"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "type": "object",
        "required": [
          "master_login",
          "payment_account_login",
          "currency",
          "fresh",
          "observed_at",
          "metrics"
        ],
        "title": "PaymentBalanceView"
      },
      "PaymentMetrics": {
        "properties": {
          "login": {
            "type": "string",
            "title": "Login"
          },
          "currency": {
            "type": "string",
            "title": "Currency"
          },
          "balance": {
            "type": "string",
            "title": "Balance"
          },
          "equity": {
            "type": "string",
            "title": "Equity"
          },
          "margin": {
            "type": "string",
            "title": "Margin"
          },
          "free_margin": {
            "type": "string",
            "title": "Free Margin"
          },
          "credit": {
            "type": "string",
            "title": "Credit"
          },
          "withdrawable": {
            "type": "string",
            "title": "Withdrawable"
          },
          "verified": {
            "type": "boolean",
            "title": "Verified"
          },
          "observed_at": {
            "type": "string",
            "title": "Observed At"
          }
        },
        "type": "object",
        "required": [
          "login",
          "currency",
          "balance",
          "equity",
          "margin",
          "free_margin",
          "credit",
          "withdrawable",
          "verified",
          "observed_at"
        ],
        "title": "PaymentMetrics"
      },
      "PaymentWithdrawal": {
        "properties": {
          "idempotency_key": {
            "type": "string",
            "maxLength": 100,
            "minLength": 8,
            "title": "Idempotency Key",
            "description": "Unique withdrawal key. Reuse it when retrying; a new key creates another request."
          },
          "amount": {
            "anyOf": [
              {
                "type": "number",
                "exclusiveMinimum": 0.0
              },
              {
                "type": "string"
              }
            ],
            "title": "Amount",
            "description": "Positive amount in the payment account currency. The agent checks available funds before debiting it.",
            "default": "0"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "idempotency_key"
        ],
        "title": "PaymentWithdrawal",
        "examples": [
          {
            "amount": "25.00",
            "idempotency_key": "payment-withdrawal-001"
          }
        ]
      },
      "PendingCloseResult": {
        "properties": {
          "deal": {
            "$ref": "#/components/schemas/CloseDeal"
          },
          "opening_costs": {
            "$ref": "#/components/schemas/OpeningCosts"
          },
          "closed_at": {
            "type": "string",
            "format": "date-time",
            "title": "Closed At"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "deal",
          "opening_costs",
          "closed_at"
        ],
        "title": "PendingCloseResult"
      },
      "Register": {
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 120,
            "title": "Name",
            "default": "primary"
          },
          "url": {
            "type": "string",
            "maxLength": 2048,
            "title": "Url"
          },
          "signing_secret": {
            "anyOf": [
              {
                "type": "string",
                "format": "password",
                "writeOnly": true
              },
              {
                "type": "null"
              }
            ],
            "title": "Signing Secret"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "url"
        ],
        "title": "Register"
      },
      "Update": {
        "properties": {
          "url": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 2048
              },
              {
                "type": "null"
              }
            ],
            "title": "Url"
          },
          "signing_secret": {
            "anyOf": [
              {
                "type": "string",
                "format": "password",
                "writeOnly": true
              },
              {
                "type": "null"
              }
            ],
            "title": "Signing Secret"
          },
          "rotate_secret": {
            "type": "boolean",
            "title": "Rotate Secret",
            "default": false
          }
        },
        "additionalProperties": false,
        "type": "object",
        "title": "Update"
      },
      "ValidationError": {
        "properties": {
          "loc": {
            "items": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "integer"
                }
              ]
            },
            "type": "array",
            "title": "Location"
          },
          "msg": {
            "type": "string",
            "title": "Message"
          },
          "type": {
            "type": "string",
            "title": "Error Type"
          }
        },
        "type": "object",
        "required": [
          "loc",
          "msg",
          "type"
        ],
        "title": "ValidationError"
      }
    },
    "securitySchemes": {
      "MAMXAdmin": {
        "type": "http",
        "description": "Administrative API key. Enter the key without the Bearer prefix.",
        "scheme": "bearer"
      }
    }
  },
  "tags": [
    {
      "name": "Health",
      "description": "API service status."
    },
    {
      "name": "Accounts",
      "description": "Create, retrieve, and update trading accounts."
    },
    {
      "name": "Leaders",
      "description": "Manage master profiles and their payment accounts."
    },
    {
      "name": "Allocations",
      "description": "Manage investor subscriptions and allocation settings."
    },
    {
      "name": "Operations",
      "description": "Track requests and retrieve account credentials."
    },
    {
      "name": "Webhooks",
      "description": "Register the CRM receiver and rotate its signing secret."
    },
    {
      "name": "Performance Fees",
      "description": "Manage fee crystallization and credit batches."
    },
    {
      "name": "Payment Accounts",
      "description": "Retrieve balances and request withdrawals."
    },
    {
      "name": "Preview",
      "description": "Preview close allocations without changing account data."
    }
  ]
}
