{
  "openapi": "3.0.3",
  "info": {
    "title": "Forexizer Connect API",
    "version": "1.0.0",
    "description": "Read-only MetaTrader 4 and 5 trade data. Your users give an investor (read-only) password; you get their trades, deposits, open positions, balance and equity. Guides: https://connect.forexizer.com/docs",
    "contact": {
      "email": "connect@forexizer.com",
      "url": "https://connect.forexizer.com"
    }
  },
  "servers": [
    {
      "url": "https://connect.forexizer.com/v1"
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "tags": [
    {
      "name": "Accounts"
    },
    {
      "name": "Data"
    },
    {
      "name": "Webhooks"
    }
  ],
  "paths": {
    "/accounts": {
      "get": {
        "tags": [
          "Accounts"
        ],
        "summary": "List accounts",
        "operationId": "listAccounts",
        "responses": {
          "200": {
            "description": "Your accounts",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Account"
                      }
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Missing or wrong API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Accounts"
        ],
        "summary": "Connect an account",
        "operationId": "connectAccount",
        "description": "Starts its first sync at once. Sending a login and server you already have, with a new password, updates that account when its login failed; otherwise 409 already_connected with its account_id.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "platform": {
                    "type": "string",
                    "enum": [
                      "mt4",
                      "mt5"
                    ]
                  },
                  "login": {
                    "type": "string",
                    "description": "The numeric account number, as a string.",
                    "example": "12345678"
                  },
                  "server": {
                    "type": "string",
                    "example": "Broker-Live"
                  },
                  "password": {
                    "type": "string",
                    "description": "The investor (read-only) password. A trading password is refused and deleted."
                  },
                  "reference": {
                    "type": "string",
                    "description": "Your own id for it, up to 200 characters."
                  },
                  "sync": {
                    "type": "string",
                    "enum": [
                      "scheduled",
                      "on_demand"
                    ]
                  }
                },
                "required": [
                  "platform",
                  "login",
                  "server",
                  "password"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Connected, status connecting",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Account"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or wrong API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Plan's account limit reached",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "already_connected",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/accounts/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "The account's id."
        }
      ],
      "get": {
        "tags": [
          "Accounts"
        ],
        "summary": "Get an account",
        "operationId": "getAccount",
        "responses": {
          "200": {
            "description": "The account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Account"
                }
              }
            }
          },
          "404": {
            "description": "No such account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Accounts"
        ],
        "summary": "Delete an account",
        "operationId": "deleteAccount",
        "description": "Deletes its password at once and all its data.",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "404": {
            "description": "No such account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/accounts/{id}/sync": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "The account's id."
        }
      ],
      "post": {
        "tags": [
          "Accounts"
        ],
        "summary": "Sync now",
        "operationId": "syncAccount",
        "responses": {
          "202": {
            "description": "Queued",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "queued": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "No such account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited (see Retry-After)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/accounts/{id}/trades": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "The account's id."
        }
      ],
      "get": {
        "tags": [
          "Data"
        ],
        "summary": "Closed trades, newest first",
        "operationId": "listTrades",
        "parameters": [
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Only from this time (trades: close time)."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of trades",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Trade"
                      }
                    },
                    "next_cursor": {
                      "type": "string",
                      "description": "Opaque. Pass as cursor for the next page; null on the last. Marks where this page stopped, so rows added meanwhile never repeat or shift a page.",
                      "nullable": true
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/accounts/{id}/operations": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "The account's id."
        }
      ],
      "get": {
        "tags": [
          "Data"
        ],
        "summary": "Deposits and withdrawals, newest first",
        "operationId": "listOperations",
        "parameters": [
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Only from this time (trades: close time)."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of operations",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Operation"
                      }
                    },
                    "next_cursor": {
                      "type": "string",
                      "description": "Opaque. Pass as cursor for the next page; null on the last. Marks where this page stopped, so rows added meanwhile never repeat or shift a page.",
                      "nullable": true
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/accounts/{id}/positions": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "The account's id."
        }
      ],
      "get": {
        "tags": [
          "Data"
        ],
        "summary": "Open positions, as of the last sync",
        "operationId": "listPositions",
        "responses": {
          "200": {
            "description": "Open positions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Position"
                      }
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/accounts/{id}/days": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "The account's id."
        }
      ],
      "get": {
        "tags": [
          "Data"
        ],
        "summary": "Daily balance and equity, newest first",
        "operationId": "listDays",
        "parameters": [
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "Only from this date."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of days",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Day"
                      }
                    },
                    "next_cursor": {
                      "type": "string",
                      "description": "Opaque. Pass as cursor for the next page; null on the last. Marks where this page stopped, so rows added meanwhile never repeat or shift a page.",
                      "nullable": true
                    }
                  },
                  "required": [
                    "data",
                    "next_cursor"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/webhooks/test": {
      "post": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Send a test event to your endpoint",
        "operationId": "testWebhook",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "trade.closed",
                      "operation.created",
                      "sync.completed",
                      "sync.failed",
                      "account.connected",
                      "account.login_failed"
                    ]
                  }
                },
                "required": [
                  "type"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "What your endpoint answered",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string"
                    },
                    "status": {
                      "type": "integer",
                      "nullable": true
                    },
                    "ok": {
                      "type": "boolean"
                    },
                    "ms": {
                      "type": "integer"
                    },
                    "error": {
                      "type": "string",
                      "nullable": true
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "fxc_live_\u2026 (Live) or fxc_test_\u2026 (Sandbox), from your dashboard."
      }
    },
    "schemas": {
      "Account": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "acc_9f2k"
          },
          "platform": {
            "type": "string",
            "enum": [
              "mt4",
              "mt5"
            ]
          },
          "login": {
            "type": "string",
            "example": "12345678"
          },
          "server": {
            "type": "string",
            "example": "Broker-Live"
          },
          "reference": {
            "type": "string",
            "description": "Your own id for the account, as you sent it.",
            "nullable": true
          },
          "sync": {
            "type": "string",
            "enum": [
              "scheduled",
              "on_demand"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "connecting",
              "connected",
              "login_failed",
              "unavailable"
            ]
          },
          "error": {
            "type": "string",
            "description": "Why, when status is login_failed or unavailable.",
            "nullable": true
          },
          "currency": {
            "type": "string",
            "example": "USD",
            "nullable": true
          },
          "balance": {
            "type": "number",
            "nullable": true
          },
          "equity": {
            "type": "number",
            "nullable": true
          },
          "holder_name": {
            "type": "string",
            "description": "The account holder's name, as the broker records it.",
            "nullable": true
          },
          "broker": {
            "type": "string",
            "example": "Broker Ltd",
            "nullable": true
          },
          "leverage": {
            "type": "integer",
            "example": 500,
            "nullable": true
          },
          "account_type": {
            "type": "string",
            "enum": [
              "demo",
              "contest",
              "real"
            ],
            "nullable": true
          },
          "last_synced_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "sandbox": {
            "type": "boolean",
            "description": "Present, and true, on Sandbox accounts only."
          }
        },
        "required": [
          "id",
          "platform",
          "login",
          "server",
          "sync",
          "status"
        ]
      },
      "Trade": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "ticket": {
            "type": "string",
            "description": "The broker's position id."
          },
          "symbol": {
            "type": "string"
          },
          "side": {
            "type": "string",
            "enum": [
              "buy",
              "sell"
            ]
          },
          "volume": {
            "type": "number"
          },
          "open_time": {
            "type": "string",
            "format": "date-time"
          },
          "open_price": {
            "type": "number"
          },
          "close_time": {
            "type": "string",
            "format": "date-time"
          },
          "close_price": {
            "type": "number"
          },
          "commission": {
            "type": "number"
          },
          "swap": {
            "type": "number"
          },
          "profit": {
            "type": "number",
            "description": "Gross. Net is profit + commission + swap."
          }
        },
        "required": [
          "id",
          "ticket",
          "symbol",
          "side",
          "volume",
          "profit"
        ]
      },
      "Operation": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "ticket": {
            "type": "string",
            "description": "The broker's deal ticket."
          },
          "type": {
            "type": "string",
            "enum": [
              "deposit",
              "withdrawal"
            ]
          },
          "amount": {
            "type": "number"
          },
          "time": {
            "type": "string",
            "format": "date-time"
          },
          "comment": {
            "type": "string",
            "nullable": true
          }
        },
        "required": [
          "id",
          "ticket",
          "type",
          "amount",
          "time"
        ]
      },
      "Position": {
        "type": "object",
        "properties": {
          "ticket": {
            "type": "string"
          },
          "symbol": {
            "type": "string"
          },
          "side": {
            "type": "string",
            "enum": [
              "buy",
              "sell"
            ]
          },
          "volume": {
            "type": "number"
          },
          "open_time": {
            "type": "string",
            "format": "date-time"
          },
          "open_price": {
            "type": "number"
          },
          "current_price": {
            "type": "number"
          },
          "stop_loss": {
            "type": "number",
            "nullable": true
          },
          "take_profit": {
            "type": "number",
            "nullable": true
          },
          "profit": {
            "type": "number",
            "description": "Floating, before commission."
          },
          "swap": {
            "type": "number"
          },
          "comment": {
            "type": "string",
            "nullable": true
          },
          "as_of": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "ticket",
          "symbol",
          "side",
          "volume"
        ]
      },
      "Day": {
        "type": "object",
        "properties": {
          "date": {
            "type": "string",
            "format": "date"
          },
          "balance_open": {
            "type": "number"
          },
          "balance_close": {
            "type": "number"
          },
          "equity_open": {
            "type": "number"
          },
          "equity_close": {
            "type": "number"
          },
          "equity_low": {
            "type": "number"
          },
          "equity_high": {
            "type": "number"
          },
          "as_of": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "date"
        ]
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "example": "account_limit_reached"
              },
              "message": {
                "type": "string"
              },
              "account_id": {
                "type": "string",
                "description": "On already_connected: the account that has this login."
              }
            },
            "required": [
              "code",
              "message"
            ]
          }
        }
      }
    }
  }
}