{
  "openapi": "3.1.1",
  "info": {
    "title": "Harmonic Patterns API",
    "version": "1.1.0",
    "contact": {
      "email": "api@harmonic-patterns.com"
    }
  },
  "servers": [
    {
      "url": "https://api.harmonic-patterns.com/v1"
    }
  ],
  "paths": {
    "/patterns": {
      "get": {
        "operationId": "listPatterns",
        "summary": "list Patterns",
        "description": "Required scope: patterns:read.",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "in": "query",
            "name": "from",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "style": "form",
            "explode": false
          },
          {
            "in": "query",
            "name": "to",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "style": "form",
            "explode": false
          },
          {
            "in": "query",
            "name": "symbols",
            "schema": {
              "type": "array",
              "items": {
                "type": "string",
                "pattern": "^[A-Z0-9][A-Z0-9._-]{0,23}$"
              },
              "maxItems": 10
            },
            "style": "form",
            "explode": false
          },
          {
            "in": "query",
            "name": "pattern_types",
            "schema": {
              "type": "array",
              "items": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_-]{0,31}$"
              },
              "maxItems": 5
            },
            "style": "form",
            "explode": false
          },
          {
            "in": "query",
            "name": "timeframes",
            "schema": {
              "type": "array",
              "items": {
                "type": "string",
                "pattern": "^([MHDW][1-9][0-9]{0,2}|MN1)$"
              },
              "maxItems": 5
            },
            "style": "form",
            "explode": false
          },
          {
            "in": "query",
            "name": "direction",
            "schema": {
              "type": "string",
              "enum": [
                "bullish",
                "bearish"
              ]
            },
            "style": "form",
            "explode": false
          },
          {
            "in": "query",
            "name": "status",
            "schema": {
              "type": "string",
              "enum": [
                "detected",
                "active",
                "invalidated",
                "completed"
              ]
            },
            "style": "form",
            "explode": false
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            },
            "style": "form",
            "explode": false
          },
          {
            "in": "query",
            "name": "cursor",
            "schema": {
              "type": "string",
              "maxLength": 2048
            },
            "style": "form",
            "explode": false
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "data",
                    "next_cursor",
                    "has_more",
                    "meta"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Pattern"
                      }
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Metadata"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request or cursor",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing bearer credential",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Insufficient permission",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Resource unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "405": {
            "description": "Method unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Client limit reached",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "minimum": 0
                },
                "description": "Delay in seconds"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable or global saturation",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/patterns/{id}": {
      "get": {
        "operationId": "getPattern",
        "summary": "get Pattern",
        "description": "Required scope: patterns:read.",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{32}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "data",
                    "next_cursor",
                    "has_more",
                    "meta"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Pattern"
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Metadata"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request or cursor",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing bearer credential",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Insufficient permission",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Resource unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "405": {
            "description": "Method unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Client limit reached",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "minimum": 0
                },
                "description": "Delay in seconds"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable or global saturation",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/catalog": {
      "get": {
        "operationId": "getCatalog",
        "summary": "get Catalog",
        "description": "Required scope: catalog:read.",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "data",
                    "next_cursor",
                    "has_more",
                    "meta"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Catalog"
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Metadata"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request or cursor",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing bearer credential",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Insufficient permission",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Resource unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "405": {
            "description": "Method unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Client limit reached",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "minimum": 0
                },
                "description": "Delay in seconds"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable or global saturation",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/usage": {
      "get": {
        "operationId": "getUsage",
        "summary": "get Usage",
        "description": "Required scope: usage:read.",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "data",
                    "next_cursor",
                    "has_more",
                    "meta"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Usage"
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Metadata"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request or cursor",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing bearer credential",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Insufficient permission",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Resource unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "405": {
            "description": "Method unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Client limit reached",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "minimum": 0
                },
                "description": "Delay in seconds"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable or global saturation",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/ea/signals": {
      "get": {
        "operationId": "getEASignals",
        "summary": "Read active EA filters",
        "description": "Returns matching detections from active saved filters, ordered by stable profile ID for overlapping matches. A token with only disabled filters receives an empty array. Filters start at activation or modification.",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "profile_risk",
            "in": "query",
            "description": "1 supports volume and fixed stops. 2 also supports the profile spread limit. A terminal receives only profiles whose settings it can enforce.",
            "schema": {"type": "string", "enum": ["1","2"]}
          },
          {
            "name": "profile_lots",
            "in": "query",
            "description": "Set to 1 when the terminal supports profile-specific volumes. Older terminals receive only signals assigned to profiles using the terminal default.",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          },
          {
            "name": "Prefer",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "wait=14"
              ]
            },
            "description": "Wait up to 14 seconds for a new committed signal when returning a valid EA cursor."
          },
          {
            "name": "X-HP-EA-Cursor",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9]{80}$"
            },
            "description": "Opaque short-lived cursor returned to the same bearer. Withhold from logs."
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "data",
                    "next_cursor",
                    "has_more",
                    "meta"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/EAFeed"
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Metadata"
                    }
                  }
                }
              }
            },
            "headers": {
              "X-HP-EA-Cursor": {
                "schema": {
                  "type": "string"
                },
                "description": "Optional cursor for the next authenticated wait."
              }
            }
          },
          "400": {
            "description": "Invalid request or cursor",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing bearer credential",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Insufficient permission",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Resource unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "405": {
            "description": "Method unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Client limit reached",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "minimum": 0
                },
                "description": "Delay in seconds"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable or global saturation",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "EA token has no bound profile.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/ea/trades": {
      "post": {
        "operationId": "reportEADeal",
        "summary": "Report a deal, an execution decision, or the latest position balance",
        "description": "Requires the EA token and the receipt issued for that signal. Replaying the identical deal is idempotent. Net is reported in the account currency and includes profit, commission, swap and fees.",
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [{"$ref":"#/components/schemas/EADeal"},{"$ref":"#/components/schemas/EADecision"},{"$ref":"#/components/schemas/EAPositionMark"}]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "data",
                    "next_cursor",
                    "has_more",
                    "meta"
                  ],
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "accepted": {
                          "const": true
                        }
                      },
                      "required": [
                        "accepted"
                      ]
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Metadata"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request or cursor",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing bearer credential",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "Insufficient permission",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "Resource unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "405": {
            "description": "Method unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Client limit reached",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "minimum": 0
                },
                "description": "Delay in seconds"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Dependency unavailable or global saturation",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "EA token has no bound profile.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Pattern": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "pattern_type",
          "symbol",
          "timeframe",
          "direction",
          "status",
          "detected_at",
          "updated_at",
          "snapshot_at",
          "signal"
        ],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[0-9a-f]{32}$"
          },
          "pattern_type": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_-]{0,31}$"
          },
          "symbol": {
            "type": "string",
            "pattern": "^[A-Z0-9][A-Z0-9._-]{0,23}$"
          },
          "timeframe": {
            "type": "string",
            "pattern": "^([MHDW][1-9][0-9]{0,2}|MN1)$"
          },
          "direction": {
            "type": "string",
            "enum": [
              "bullish",
              "bearish"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "detected",
              "active",
              "invalidated",
              "completed"
            ]
          },
          "detected_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "snapshot_at": {
            "type": "string",
            "format": "date-time"
          },
          "signal": {
            "$ref": "#/components/schemas/Signal"
          }
        }
      },
      "Catalog": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "symbols",
          "pattern_types",
          "timeframes",
          "directions",
          "statuses"
        ],
        "properties": {
          "symbols": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^[A-Z0-9][A-Z0-9._-]{0,23}$"
            }
          },
          "pattern_types": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_-]{0,31}$"
            }
          },
          "timeframes": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^([MHDW][1-9][0-9]{0,2}|MN1)$"
            }
          },
          "directions": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "bullish",
                "bearish"
              ]
            }
          },
          "statuses": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "detected",
                "active",
                "invalidated",
                "completed"
              ]
            }
          }
        }
      },
      "Usage": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "token_id",
          "client_id",
          "admitted",
          "rejected",
          "successes",
          "errors",
          "records",
          "bytes",
          "client_admitted",
          "daily_quota",
          "remaining",
          "requests_per_minute",
          "burst",
          "concurrency",
          "last_used",
          "resets_at"
        ],
        "properties": {
          "token_id": {
            "type": "string",
            "pattern": "^[0-9a-f]{32}$"
          },
          "client_id": {
            "type": "string",
            "pattern": "^[0-9a-f]{32}$"
          },
          "admitted": {
            "type": "integer",
            "minimum": 0
          },
          "rejected": {
            "type": "integer",
            "minimum": 0
          },
          "successes": {
            "type": "integer",
            "minimum": 0
          },
          "errors": {
            "type": "integer",
            "minimum": 0
          },
          "records": {
            "type": "integer",
            "minimum": 0
          },
          "bytes": {
            "type": "integer",
            "minimum": 0
          },
          "client_admitted": {
            "type": "integer",
            "minimum": 0
          },
          "daily_quota": {
            "type": "integer",
            "minimum": 0
          },
          "remaining": {
            "type": "integer",
            "minimum": 0
          },
          "requests_per_minute": {
            "type": "integer",
            "minimum": 0
          },
          "burst": {
            "type": "integer",
            "minimum": 0
          },
          "concurrency": {
            "type": "integer",
            "minimum": 0
          },
          "last_used": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "resets_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Metadata": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "request_id",
          "server_time",
          "available_from"
        ],
        "properties": {
          "request_id": {
            "type": "string",
            "pattern": "^[0-9a-f]{32}$"
          },
          "server_time": {
            "type": "string",
            "format": "date-time"
          },
          "available_from": {
            "type": "string",
            "format": "date-time"
          },
          "from": {
            "type": "string",
            "format": "date-time"
          },
          "to": {
            "type": "string",
            "format": "date-time"
          },
          "data_as_of": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Problem": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "type",
          "title",
          "status",
          "code",
          "request_id"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer",
            "minimum": 0
          },
          "code": {
            "type": "string"
          },
          "request_id": {
            "type": "string",
            "pattern": "^[0-9a-f]{32}$"
          },
          "resets_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Signal": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "name": {
            "type": "string"
          },
          "form_time": {
            "type": "string",
            "format": "date-time"
          },
          "reference_price": {
            "type": "string",
            "pattern": "^-?[0-9]{1,18}(\\.[0-9]{1,18})?$"
          },
          "reference_side": {
            "type": "string",
            "enum": [
              "bid",
              "ask"
            ]
          },
          "entry_price": {
            "type": "string",
            "pattern": "^-?[0-9]{1,18}(\\.[0-9]{1,18})?$"
          },
          "entry_source": {
            "type": "string",
            "enum": [
              "bid",
              "ask"
            ]
          },
          "target1": {
            "type": "string",
            "pattern": "^-?[0-9]{1,18}(\\.[0-9]{1,18})?$"
          },
          "target2": {
            "type": "string",
            "pattern": "^-?[0-9]{1,18}(\\.[0-9]{1,18})?$"
          },
          "digits": {
            "type": "integer",
            "minimum": 0
          },
          "point": {
            "type": "string",
            "pattern": "^-?[0-9]{1,18}(\\.[0-9]{1,18})?$"
          },
          "bid": {
            "anyOf": [
              {
                "type": "string",
                "pattern": "^-?[0-9]{1,18}(\\.[0-9]{1,18})?$"
              },
              {
                "type": "null"
              }
            ]
          },
          "ask": {
            "anyOf": [
              {
                "type": "string",
                "pattern": "^-?[0-9]{1,18}(\\.[0-9]{1,18})?$"
              },
              {
                "type": "null"
              }
            ]
          },
          "quote_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ]
          },
          "resolved_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ]
          },
          "recorded_points": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "age_bars": {
            "type": "integer",
            "minimum": 0
          },
          "stale": {
            "type": "boolean"
          },
          "horizon": {
            "type": "integer",
            "minimum": 0
          },
          "bars_left": {
            "type": "integer",
            "minimum": 0
          },
          "revision_count": {
            "type": "integer",
            "minimum": 0
          },
          "post_expiry_max_points": {
            "type": "number"
          },
          "hit": {
            "type": "string",
            "enum": [
              "profit"
            ]
          },
          "pnl_state": {
            "type": "string",
            "enum": [
              "profit",
              "loss",
              "neutro"
            ]
          },
          "outcome": {
            "type": "string",
            "enum": [
              "profit",
              "aberto",
              "expirado"
            ]
          },
          "variation_points": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "variation_pct": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "mae_points": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "mfe_points": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "objective_window": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "max_points": {
                "type": "number"
              },
              "state": {
                "type": "string",
                "enum": [
                  "complete",
                  "forming",
                  "unobserved"
                ]
              },
              "bars": {
                "type": "integer",
                "minimum": 0
              }
            },
            "required": [
              "max_points",
              "state",
              "bars"
            ]
          },
          "ratios": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "ab_xa": {
                "type": "string",
                "pattern": "^-?[0-9]{1,18}(\\.[0-9]{1,18})?$"
              },
              "bc_ab": {
                "type": "string",
                "pattern": "^-?[0-9]{1,18}(\\.[0-9]{1,18})?$"
              },
              "cd_bc": {
                "type": "string",
                "pattern": "^-?[0-9]{1,18}(\\.[0-9]{1,18})?$"
              },
              "d_xa": {
                "type": "string",
                "pattern": "^-?[0-9]{1,18}(\\.[0-9]{1,18})?$"
              }
            },
            "required": []
          },
          "points": {
            "type": "array",
            "maxItems": 8,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "role": {
                  "type": "string",
                  "enum": [
                    "O",
                    "X",
                    "A",
                    "B",
                    "C",
                    "D"
                  ]
                },
                "price": {
                  "type": "string",
                  "pattern": "^-?[0-9]{1,18}(\\.[0-9]{1,18})?$"
                },
                "time": {
                  "type": "string",
                  "format": "date-time"
                }
              },
              "required": [
                "role",
                "price",
                "time"
              ]
            }
          },
          "chart_ratios": {
            "type": "array",
            "maxItems": 5,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "from",
                "to",
                "formula",
                "value"
              ],
              "properties": {
                "from": {
                  "enum": [
                    "O",
                    "X",
                    "A",
                    "B",
                    "C",
                    "D"
                  ]
                },
                "to": {
                  "enum": [
                    "O",
                    "X",
                    "A",
                    "B",
                    "C",
                    "D"
                  ]
                },
                "formula": {
                  "enum": [
                    "AB/XA",
                    "BC/AB",
                    "CD/BC",
                    "CD/XC",
                    "AD/XA",
                    "XA/OX",
                    "CD/AB"
                  ]
                },
                "value": {
                  "type": "number",
                  "minimum": 0
                }
              }
            }
          },
          "validity": {
            "enum": [
              "unknown",
              "active",
              "expired"
            ]
          },
          "default_objective": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "points",
              "state",
              "reached_after_expiry"
            ],
            "properties": {
              "points": {
                "const": 10
              },
              "state": {
                "enum": [
                  "forming",
                  "unobserved",
                  "missed",
                  "reached"
                ]
              },
              "reached_after_expiry": {
                "type": "boolean"
              }
            }
          }
        },
        "required": [
          "name",
          "form_time",
          "digits",
          "bid",
          "ask",
          "quote_at",
          "resolved_at",
          "recorded_points",
          "age_bars",
          "stale",
          "horizon",
          "bars_left",
          "revision_count",
          "outcome",
          "variation_points",
          "variation_pct",
          "mae_points",
          "mfe_points",
          "objective_window",
          "ratios",
          "points",
          "chart_ratios",
          "validity",
          "default_objective"
        ]
      },
      "EAFeed": {
        "type": "object",
        "required": [
          "server",
          "signals"
        ],
        "properties": {
          "server": {
            "type": "integer",
            "description": "UTC Unix seconds at request start"
          },
          "signals": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object",
              "required": [
                "id",
                "symbol",
                "direction",
                "active",
                "detected",
                "profile",
                "timeframe",
                "target"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{32}$"
                },
                "symbol": {
                  "type": "string"
                },
                "direction": {
                  "enum": [
                    "bullish",
                    "bearish"
                  ]
                },
                "active": {
                  "type": "boolean"
                },
                "detected": {
                  "type": "integer"
                },
                "profile": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{32}$"
                },
                "timeframe": {
                  "type": "string"
                },
                "target": {
                  "type": "number",
                  "description": "Absolute take-profit price from the browser signal entry and the saved point objective. Zero means unavailable."
                },
                "receipt": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{64}$",
                  "description": "Keep private. Permits reporting trades for this delivered, active buy or sell signal."
                },
                "spread_points": {"type":"integer","minimum":1,"maximum":2147483647,"description":"Maximum bid/ask spread in broker points for this profile."},
                "stop_points": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 2147483647,
                  "description": "Stop distance from the executed entry in broker symbol points. Takes precedence over the terminal percentage stop."
                },
                "lots": {
                  "type": "number",
                  "exclusiveMinimum": 0,
                  "description": "Volume in lots for the assigned profile. When absent use the terminal default."
                }
              }
            }
          }
        }
      },
      "EADecision": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "account",
          "profile",
          "signal",
          "receipt",
          "kind",
          "at",
          "reason"
        ],
        "properties": {
          "account": {
            "type": "string",
            "pattern": "^[a-f0-9]{32}$"
          },
          "profile": {
            "type": "string",
            "pattern": "^[a-f0-9]{32}$"
          },
          "signal": {
            "type": "string",
            "pattern": "^[a-f0-9]{32}$"
          },
          "receipt": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "kind": {
            "const": "decision"
          },
          "at": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "enum": [
              "symbol_unavailable",
              "trade_mode",
              "market_or_tp_disabled",
              "sl_disabled",
              "position_on_symbol",
              "maximum_positions",
              "invalid_volume",
              "stale_quote",
              "spread_limit",
              "target_or_stop_distance",
              "filling_mode",
              "broker_rejected"
            ]
          },
          "spread": {
            "type": "number",
            "minimum": 0
          },
          "limit": {
            "type": "integer",
            "minimum": 1
          },
          "broker_code": {
            "type": "integer",
            "minimum": 0
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "reason": {
                  "const": "spread_limit"
                }
              }
            },
            "then": {
              "required": [
                "spread",
                "limit"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "reason": {
                  "const": "broker_rejected"
                }
              }
            },
            "then": {
              "required": [
                "broker_code"
              ]
            }
          }
        ]
      },
      "EAPositionMark": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "account",
          "profile",
          "signal",
          "receipt",
          "kind",
          "at",
          "volume",
          "position",
          "currency",
          "net"
        ],
        "properties": {
          "account": {
            "type": "string",
            "pattern": "^[a-f0-9]{32}$"
          },
          "profile": {
            "type": "string",
            "pattern": "^[a-f0-9]{32}$"
          },
          "signal": {
            "type": "string",
            "pattern": "^[a-f0-9]{32}$"
          },
          "receipt": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "kind": {
            "const": "position"
          },
          "at": {
            "type": "integer",
            "minimum": 1
          },
          "volume": {
            "type": "number",
            "minimum": 0
          },
          "position": {
            "type": "string",
            "pattern": "^[1-9][0-9]{0,19}$"
          },
          "currency": {
            "type": "string",
            "pattern": "^[A-Z][A-Z0-9]{1,11}$"
          },
          "net": {
            "type": "string",
            "pattern": "^-?(0|[1-9][0-9]{0,14})(\\.[0-9]{1,8})?$"
          }
        }
      },
      "EADeal": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "profile": {
            "type": "string",
            "pattern": "^[a-f0-9]{32}$"
          },
          "signal": {
            "type": "string",
            "pattern": "^[a-f0-9]{32}$"
          },
          "receipt": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "account": {
            "type": "string",
            "pattern": "^[a-f0-9]{32}$"
          },
          "position": {
            "type": "string",
            "pattern": "^[1-9][0-9]{0,19}$"
          },
          "deal": {
            "type": "string",
            "pattern": "^[1-9][0-9]{0,19}$"
          },
          "currency": {
            "type": "string",
            "pattern": "^[A-Z][A-Z0-9]{1,11}$"
          },
          "net": {
            "type": "string",
            "pattern": "^-?(0|[1-9][0-9]{0,14})(\\.[0-9]{1,8})?$"
          },
          "entry": {
            "type": "boolean"
          }
        },
        "required": [
          "profile",
          "signal",
          "receipt",
          "account",
          "position",
          "deal",
          "currency",
          "net",
          "entry"
        ]
      }
    }
  }
}
