The finance developer workbenchSearch the reference Development · 0.1.4 · unpublished

trade / wire operation

Reconcile an execution journal to the ledger

totalfinance.trade.reconcile

Join the journal's order states (from the journal store by `journalId`, or inline events) to the ledger's fills under the execution source in both directions, compare delivered fill quantities per order within an explicit tolerance, list the unresolved orders, and — with an external snapshot — compose reconcilePortfolio verbatim. With planHash, exclude other plans’ journaled orders and fills from both joins; unattributed source fills remain discrepancies. External snapshots are judged over the whole portfolio. reconciled is true only when everything agrees and no order is unresolved. No effect; requires trade:paper. Opt-in (tradePack).

Pack / profilestrade / full
Default discoveryOpt-in
Required capabilitiestrade:paper
Effects / authorizationnone / none
Cost / cancellationsmall / Do not assume inline interruption
Handle-eligible inputsledger
Idempotencynot-applicable
Input schema
{
  "type": "object",
  "properties": {
    "journalId": {
      "type": "string",
      "minLength": 1
    },
    "journal": {
      "type": "array",
      "items": {
        "allOf": [
          {
            "type": "object",
            "properties": {
              "eventId": {
                "type": "string",
                "minLength": 1
              },
              "journalId": {
                "type": "string",
                "minLength": 1
              },
              "timestampMs": {
                "type": "number",
                "description": "Epoch milliseconds"
              },
              "orderId": {
                "type": "string",
                "minLength": 1
              },
              "planHash": {
                "type": "string",
                "minLength": 1
              },
              "idempotencyKey": {
                "type": "string",
                "minLength": 1
              },
              "sourceId": {
                "type": "string",
                "minLength": 1
              },
              "provenance": {
                "$ref": "#/$defs/Provenance"
              },
              "eventType": {},
              "detail": {}
            },
            "additionalProperties": false,
            "required": [
              "eventId",
              "journalId",
              "timestampMs",
              "orderId",
              "planHash",
              "sourceId",
              "provenance",
              "eventType",
              "detail"
            ]
          },
          {
            "anyOf": [
              {
                "properties": {
                  "eventType": {
                    "const": "proposed",
                    "type": "string"
                  },
                  "detail": {
                    "$ref": "#/$defs/Detail"
                  }
                }
              },
              {
                "properties": {
                  "eventType": {
                    "const": "preflighted",
                    "type": "string"
                  },
                  "detail": {
                    "$ref": "#/$defs/Detail"
                  }
                }
              },
              {
                "properties": {
                  "eventType": {
                    "const": "authorized",
                    "type": "string"
                  },
                  "detail": {
                    "$ref": "#/$defs/Detail"
                  }
                }
              },
              {
                "properties": {
                  "eventType": {
                    "const": "submitted",
                    "type": "string"
                  },
                  "detail": {
                    "type": "object",
                    "properties": {
                      "quantity": {
                        "type": "number",
                        "exclusiveMinimum": 0
                      },
                      "fillId": {
                        "type": "string"
                      },
                      "pricePerUnit": {
                        "type": "number"
                      },
                      "reason": {
                        "type": "string"
                      },
                      "replacementOrderId": {
                        "type": "string"
                      },
                      "artifactHash": {
                        "type": "string"
                      },
                      "note": {
                        "type": "string"
                      },
                      "order": {
                        "allOf": [
                          {
                            "type": "object",
                            "properties": {
                              "instrumentId": {
                                "type": "string",
                                "minLength": 1
                              },
                              "side": {
                                "type": "string",
                                "enum": [
                                  "buy",
                                  "sell"
                                ]
                              },
                              "timeInForce": {
                                "type": "string",
                                "enum": [
                                  "day",
                                  "gtc"
                                ],
                                "description": "Default: the paper execution policy’s day time-in-force"
                              },
                              "comboId": {
                                "type": "string",
                                "minLength": 1,
                                "description": "The multi-leg order this is a leg of (B5)"
                              },
                              "orderId": {
                                "type": "string",
                                "minLength": 1
                              },
                              "quantity": {
                                "type": "number",
                                "exclusiveMinimum": 0,
                                "description": "Units/contracts, strictly positive; side carries direction"
                              },
                              "plannedTimestampMs": {
                                "type": "number",
                                "description": "When the plan was made — never when a broker saw the order"
                              },
                              "submittedTimestampMs": {
                                "type": "number",
                                "description": "Epoch milliseconds"
                              },
                              "type": {},
                              "limitPrice": {},
                              "stopPrice": {}
                            },
                            "additionalProperties": false,
                            "required": [
                              "instrumentId",
                              "side",
                              "orderId",
                              "quantity",
                              "plannedTimestampMs",
                              "type"
                            ]
                          },
                          {
                            "anyOf": [
                              {
                                "properties": {
                                  "type": {
                                    "const": "market",
                                    "type": "string"
                                  }
                                },
                                "not": {
                                  "anyOf": [
                                    {
                                      "required": [
                                        "limitPrice"
                                      ]
                                    },
                                    {
                                      "required": [
                                        "stopPrice"
                                      ]
                                    }
                                  ]
                                }
                              },
                              {
                                "properties": {
                                  "type": {
                                    "const": "market-on-open",
                                    "type": "string"
                                  }
                                },
                                "not": {
                                  "anyOf": [
                                    {
                                      "required": [
                                        "limitPrice"
                                      ]
                                    },
                                    {
                                      "required": [
                                        "stopPrice"
                                      ]
                                    }
                                  ]
                                }
                              },
                              {
                                "properties": {
                                  "type": {
                                    "const": "market-on-close",
                                    "type": "string"
                                  }
                                },
                                "not": {
                                  "anyOf": [
                                    {
                                      "required": [
                                        "limitPrice"
                                      ]
                                    },
                                    {
                                      "required": [
                                        "stopPrice"
                                      ]
                                    }
                                  ]
                                }
                              },
                              {
                                "properties": {
                                  "type": {
                                    "const": "limit",
                                    "type": "string"
                                  },
                                  "limitPrice": {
                                    "type": "number",
                                    "exclusiveMinimum": 0
                                  }
                                },
                                "required": [
                                  "limitPrice"
                                ],
                                "not": {
                                  "anyOf": [
                                    {
                                      "required": [
                                        "stopPrice"
                                      ]
                                    }
                                  ]
                                }
                              },
                              {
                                "properties": {
                                  "type": {
                                    "const": "stop",
                                    "type": "string"
                                  },
                                  "stopPrice": {
                                    "type": "number",
                                    "exclusiveMinimum": 0
                                  }
                                },
                                "required": [
                                  "stopPrice"
                                ],
                                "not": {
                                  "anyOf": [
                                    {
                                      "required": [
                                        "limitPrice"
                                      ]
                                    }
                                  ]
                                }
                              },
                              {
                                "properties": {
                                  "type": {
                                    "const": "stop-limit",
                                    "type": "string"
                                  },
                                  "limitPrice": {
                                    "type": "number",
                                    "exclusiveMinimum": 0
                                  },
                                  "stopPrice": {
                                    "type": "number",
                                    "exclusiveMinimum": 0
                                  }
                                },
                                "required": [
                                  "limitPrice",
                                  "stopPrice"
                                ]
                              }
                            ]
                          }
                        ]
                      },
                      "instrument": {
                        "type": "object",
                        "properties": {
                          "currency": {
                            "type": "string",
                            "pattern": "^[A-Z]{3}$"
                          },
                          "contractMultiplier": {
                            "type": "number",
                            "exclusiveMinimum": 0
                          },
                          "contract": {
                            "$ref": "#/$defs/Contract"
                          },
                          "settlementStyle": {
                            "type": "string",
                            "enum": [
                              "cash-on-trade",
                              "variation-margin"
                            ]
                          },
                          "settlementLag": {
                            "anyOf": [
                              {
                                "const": 0,
                                "type": "number"
                              },
                              {
                                "const": 1,
                                "type": "number"
                              },
                              {
                                "const": 2,
                                "type": "number"
                              }
                            ],
                            "description": "T+n 24-hour days in the paper broker; default 0"
                          }
                        },
                        "additionalProperties": false,
                        "required": [
                          "currency"
                        ]
                      },
                      "accountId": {
                        "type": "string",
                        "minLength": 1
                      },
                      "baseCurrency": {
                        "type": "string",
                        "pattern": "^[A-Z]{3}$"
                      },
                      "executionPolicyHash": {
                        "type": "string",
                        "minLength": 1
                      },
                      "comboId": {
                        "type": "string",
                        "minLength": 1
                      },
                      "netLimitPrice": {
                        "type": "number"
                      }
                    },
                    "additionalProperties": false,
                    "required": [
                      "quantity"
                    ]
                  }
                }
              },
              {
                "properties": {
                  "eventType": {
                    "const": "acknowledged",
                    "type": "string"
                  },
                  "detail": {
                    "$ref": "#/$defs/Detail"
                  }
                }
              },
              {
                "properties": {
                  "eventType": {
                    "const": "partially-filled",
                    "type": "string"
                  },
                  "detail": {
                    "$ref": "#/$defs/Detail2"
                  }
                }
              },
              {
                "properties": {
                  "eventType": {
                    "const": "filled",
                    "type": "string"
                  },
                  "detail": {
                    "$ref": "#/$defs/Detail2"
                  }
                }
              },
              {
                "properties": {
                  "eventType": {
                    "const": "rejected",
                    "type": "string"
                  },
                  "detail": {
                    "$ref": "#/$defs/Detail"
                  }
                }
              },
              {
                "properties": {
                  "eventType": {
                    "const": "cancel-requested",
                    "type": "string"
                  },
                  "detail": {
                    "$ref": "#/$defs/Detail"
                  }
                }
              },
              {
                "properties": {
                  "eventType": {
                    "const": "cancelled",
                    "type": "string"
                  },
                  "detail": {
                    "$ref": "#/$defs/Detail"
                  }
                }
              },
              {
                "properties": {
                  "eventType": {
                    "const": "replaced",
                    "type": "string"
                  },
                  "detail": {
                    "type": "object",
                    "properties": {
                      "quantity": {
                        "type": "number"
                      },
                      "fillId": {
                        "type": "string"
                      },
                      "pricePerUnit": {
                        "type": "number"
                      },
                      "reason": {
                        "type": "string"
                      },
                      "replacementOrderId": {
                        "type": "string",
                        "minLength": 1
                      },
                      "artifactHash": {
                        "type": "string"
                      },
                      "note": {
                        "type": "string"
                      }
                    },
                    "additionalProperties": false,
                    "required": [
                      "replacementOrderId"
                    ]
                  }
                }
              },
              {
                "properties": {
                  "eventType": {
                    "const": "expired",
                    "type": "string"
                  },
                  "detail": {
                    "$ref": "#/$defs/Detail"
                  }
                }
              },
              {
                "properties": {
                  "eventType": {
                    "const": "reconciled",
                    "type": "string"
                  },
                  "detail": {
                    "$ref": "#/$defs/Detail"
                  }
                }
              },
              {
                "properties": {
                  "eventType": {
                    "const": "unresolved",
                    "type": "string"
                  },
                  "detail": {
                    "$ref": "#/$defs/Detail"
                  }
                }
              }
            ]
          }
        ]
      }
    },
    "ledger": {
      "anyOf": [
        {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "kind": {
                  "const": "totalfinance.portfolio-ledger",
                  "type": "string"
                },
                "schemaVersion": {
                  "const": 1,
                  "type": "number"
                },
                "portfolioId": {
                  "type": "string",
                  "minLength": 1
                },
                "baseCurrency": {
                  "type": "string",
                  "pattern": "^[A-Z]{3}$"
                },
                "lotRelief": {
                  "type": "string",
                  "enum": [
                    "fifo",
                    "lifo",
                    "highest-cost",
                    "specific-lot"
                  ]
                },
                "events": {
                  "type": "array",
                  "items": {
                    "$ref": "#/$defs/PortfolioEventEnvelope"
                  }
                },
                "provenance": {
                  "$ref": "#/$defs/Provenance"
                }
              },
              "additionalProperties": false,
              "required": [
                "kind",
                "schemaVersion",
                "baseCurrency",
                "lotRelief",
                "events"
              ]
            },
            {
              "type": "object",
              "properties": {
                "schemaVersion": {
                  "const": 1,
                  "type": "number"
                },
                "portfolioId": {
                  "type": "string",
                  "minLength": 1
                },
                "baseCurrency": {
                  "type": "string",
                  "pattern": "^[A-Z]{3}$"
                },
                "lotRelief": {
                  "type": "string",
                  "enum": [
                    "fifo",
                    "lifo",
                    "highest-cost",
                    "specific-lot"
                  ]
                },
                "accounts": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "object",
                    "properties": {
                      "cashBalances": {
                        "type": "object",
                        "additionalProperties": {
                          "type": "object",
                          "properties": {
                            "totalAmount": {
                              "type": "number"
                            },
                            "settlementSchedule": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "eventId": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "amount": {
                                    "type": "number"
                                  },
                                  "settleTimestampMs": {
                                    "type": "number",
                                    "description": "Epoch milliseconds"
                                  }
                                },
                                "additionalProperties": false,
                                "required": [
                                  "eventId",
                                  "amount",
                                  "settleTimestampMs"
                                ]
                              }
                            }
                          },
                          "additionalProperties": false,
                          "required": [
                            "totalAmount",
                            "settlementSchedule"
                          ]
                        }
                      },
                      "positions": {
                        "type": "object",
                        "additionalProperties": {
                          "type": "object",
                          "properties": {
                            "instrumentId": {
                              "type": "string",
                              "minLength": 1
                            },
                            "currency": {
                              "type": "string",
                              "pattern": "^[A-Z]{3}$"
                            },
                            "contractMultiplier": {
                              "type": "number",
                              "exclusiveMinimum": 0
                            },
                            "settlementStyle": {
                              "type": "string",
                              "enum": [
                                "cash-on-trade",
                                "variation-margin"
                              ]
                            },
                            "contract": {
                              "$ref": "#/$defs/Contract"
                            },
                            "quantity": {
                              "type": "number"
                            },
                            "lots": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "lotId": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "openedByEventId": {
                                    "type": "string",
                                    "minLength": 1
                                  },
                                  "openedTimestampMs": {
                                    "type": "number",
                                    "description": "Epoch milliseconds"
                                  },
                                  "quantity": {
                                    "type": "number"
                                  },
                                  "costBasisPerUnit": {
                                    "type": "number"
                                  }
                                },
                                "additionalProperties": false,
                                "required": [
                                  "lotId",
                                  "openedByEventId",
                                  "openedTimestampMs",
                                  "quantity",
                                  "costBasisPerUnit"
                                ]
                              }
                            }
                          },
                          "additionalProperties": false,
                          "required": [
                            "instrumentId",
                            "currency",
                            "contractMultiplier",
                            "settlementStyle",
                            "quantity",
                            "lots"
                          ]
                        }
                      },
                      "realizedPnl": {
                        "type": "object",
                        "additionalProperties": {
                          "type": "number"
                        }
                      },
                      "incomeReceived": {
                        "type": "object",
                        "additionalProperties": {
                          "type": "number"
                        }
                      },
                      "transactionCosts": {
                        "type": "object",
                        "additionalProperties": {
                          "type": "number"
                        }
                      },
                      "financingCosts": {
                        "type": "object",
                        "additionalProperties": {
                          "type": "number"
                        }
                      },
                      "realizedPnlByInstrument": {
                        "type": "object",
                        "additionalProperties": {
                          "type": "object",
                          "additionalProperties": {
                            "type": "number"
                          }
                        }
                      },
                      "incomeByInstrument": {
                        "type": "object",
                        "additionalProperties": {
                          "type": "object",
                          "additionalProperties": {
                            "type": "number"
                          }
                        }
                      },
                      "transactionCostsByInstrument": {
                        "type": "object",
                        "additionalProperties": {
                          "type": "object",
                          "additionalProperties": {
                            "type": "number"
                          }
                        }
                      }
                    },
                    "additionalProperties": false,
                    "required": [
                      "cashBalances",
                      "positions",
                      "realizedPnl",
                      "incomeReceived",
                      "transactionCosts",
                      "financingCosts",
                      "realizedPnlByInstrument",
                      "incomeByInstrument",
                      "transactionCostsByInstrument"
                    ]
                  }
                },
                "appliedEvents": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "string"
                  }
                },
                "eventCount": {
                  "type": "integer",
                  "minimum": 0
                },
                "lastEffectiveTimestampMs": {
                  "anyOf": [
                    {
                      "type": "number",
                      "description": "Epoch milliseconds"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "lotSequence": {
                  "type": "integer",
                  "minimum": 0
                },
                "fillEffects": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "object",
                    "properties": {
                      "accountId": {
                        "type": "string",
                        "minLength": 1
                      },
                      "instrumentId": {
                        "type": "string",
                        "minLength": 1
                      },
                      "currency": {
                        "type": "string",
                        "pattern": "^[A-Z]{3}$"
                      },
                      "openedLotIds": {
                        "type": "array",
                        "items": {
                          "type": "string",
                          "minLength": 1
                        }
                      },
                      "relievedQuantity": {
                        "type": "number"
                      },
                      "realizedPnl": {
                        "type": "number"
                      },
                      "cashDelta": {
                        "type": "number"
                      },
                      "accruedInterest": {
                        "type": "number"
                      }
                    },
                    "additionalProperties": false,
                    "required": [
                      "accountId",
                      "instrumentId",
                      "currency",
                      "openedLotIds",
                      "relievedQuantity",
                      "realizedPnl",
                      "cashDelta",
                      "accruedInterest"
                    ]
                  }
                },
                "reversals": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "string"
                  }
                },
                "accountMigrations": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "eventId": {
                        "type": "string",
                        "minLength": 1
                      },
                      "fromAccountId": {
                        "type": "string",
                        "minLength": 1
                      },
                      "toAccountId": {
                        "type": "string",
                        "minLength": 1
                      },
                      "effectiveTimestampMs": {
                        "type": "number",
                        "description": "Epoch milliseconds"
                      }
                    },
                    "additionalProperties": false,
                    "required": [
                      "eventId",
                      "fromAccountId",
                      "toAccountId",
                      "effectiveTimestampMs"
                    ]
                  }
                }
              },
              "additionalProperties": false,
              "required": [
                "schemaVersion",
                "baseCurrency",
                "lotRelief",
                "accounts",
                "appliedEvents",
                "eventCount",
                "lastEffectiveTimestampMs",
                "lotSequence",
                "fillEffects",
                "reversals",
                "accountMigrations"
              ]
            }
          ]
        },
        {
          "type": "string",
          "pattern": "^totalfinance:\\/\\/portfolios\\/"
        }
      ]
    },
    "sourceId": {
      "type": "string",
      "minLength": 1
    },
    "fills": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Fill"
      }
    },
    "external": {
      "type": "object",
      "properties": {
        "asOf": {
          "anyOf": [
            {
              "type": "number",
              "description": "Epoch milliseconds"
            },
            {
              "type": "string"
            }
          ]
        },
        "accounts": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "properties": {
              "cash": {
                "type": "object",
                "additionalProperties": {
                  "type": "object",
                  "properties": {
                    "total": {
                      "type": "number"
                    },
                    "settled": {
                      "type": "number"
                    }
                  },
                  "additionalProperties": false,
                  "required": [
                    "total"
                  ]
                }
              },
              "positions": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "instrumentId": {
                      "type": "string",
                      "minLength": 1
                    },
                    "quantity": {
                      "type": "number"
                    },
                    "currency": {
                      "type": "string",
                      "pattern": "^[A-Z]{3}$"
                    },
                    "costBasis": {
                      "type": "number"
                    }
                  },
                  "additionalProperties": false,
                  "required": [
                    "instrumentId",
                    "quantity"
                  ]
                }
              }
            },
            "additionalProperties": false,
            "required": [
              "cash",
              "positions"
            ]
          }
        },
        "source": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "asOf",
        "accounts"
      ]
    },
    "asOf": {
      "type": "number"
    },
    "tolerance": {
      "type": "object",
      "properties": {
        "quantity": {
          "type": "number",
          "minimum": 0
        },
        "cashAmount": {
          "type": "number",
          "minimum": 0
        },
        "costBasis": {
          "type": "number",
          "minimum": 0
        }
      },
      "additionalProperties": false,
      "required": [
        "quantity",
        "cashAmount"
      ]
    },
    "planHash": {
      "type": "string"
    }
  },
  "additionalProperties": false,
  "required": [
    "ledger",
    "sourceId",
    "fills",
    "asOf",
    "tolerance"
  ],
  "oneOf": [
    {
      "required": [
        "journalId"
      ],
      "not": {
        "required": [
          "journal"
        ]
      }
    },
    {
      "required": [
        "journal"
      ],
      "not": {
        "required": [
          "journalId"
        ]
      }
    }
  ],
  "$id": "https://totalfinance.dev/schemas/trade.reconcile.input",
  "$defs": {
    "PortfolioEventEnvelope": {
      "allOf": [
        {
          "type": "object",
          "properties": {
            "eventId": {
              "type": "string",
              "minLength": 1
            },
            "schemaVersion": {
              "const": 1,
              "type": "number"
            },
            "sourceId": {
              "type": "string",
              "minLength": 1
            },
            "accountId": {
              "type": "string",
              "minLength": 1
            },
            "effectiveTimestampMs": {
              "type": "number",
              "description": "Epoch milliseconds"
            },
            "recordedTimestampMs": {
              "type": "number",
              "description": "Epoch milliseconds"
            },
            "correlationId": {
              "type": "string",
              "minLength": 1
            },
            "causationId": {
              "type": "string",
              "minLength": 1
            },
            "reversesEventId": {
              "type": "string",
              "minLength": 1
            },
            "provenance": {
              "$ref": "#/$defs/Provenance"
            },
            "eventType": {},
            "event": {}
          },
          "additionalProperties": false,
          "required": [
            "eventId",
            "schemaVersion",
            "sourceId",
            "accountId",
            "effectiveTimestampMs",
            "recordedTimestampMs",
            "provenance",
            "eventType",
            "event"
          ]
        },
        {
          "anyOf": [
            {
              "properties": {
                "eventType": {
                  "const": "cash.deposit",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CashDeposit"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "cash.withdrawal",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CashWithdrawal"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "cash.transfer",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CashTransfer"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "cash.conversion",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CashConversion"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "trade.fill",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/TradeFill"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "cost.charge",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CostCharge"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "income.received",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/IncomeReceived"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "financing.charge",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/FinancingCharge"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "corporate.split",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CorporateSplit"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "derivative.exercise",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/DerivativeExercise"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "derivative.assignment",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/DerivativeAssignment"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "derivative.expiration",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/DerivativeExpiration"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "derivative.multiplier-change",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/DerivativeMultiplierChange"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "derivative.variation-margin",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/DerivativeVariationMargin"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "derivative.roll",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/DerivativeRoll"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "fixed-income.redemption",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/FixedIncomeRedemption"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "corporate.symbol-change",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CorporateSymbolChange"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "corporate.merger",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CorporateMerger"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "corporate.spin-off",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CorporateSpinOff"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "corporate.return-of-capital",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CorporateReturnOfCapital"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "corporate.cash-in-lieu",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CorporateCashInLieu"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "position.transfer",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/PositionTransfer"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "admin.reversal",
                  "type": "string"
                },
                "event": {
                  "type": "object",
                  "properties": {
                    "eventType": {
                      "const": "admin.reversal",
                      "type": "string"
                    },
                    "original": {
                      "$ref": "#/$defs/PortfolioEventEnvelope"
                    },
                    "reason": {
                      "type": "string"
                    }
                  },
                  "additionalProperties": false,
                  "required": [
                    "eventType",
                    "original"
                  ]
                }
              },
              "required": [
                "reversesEventId"
              ]
            },
            {
              "properties": {
                "eventType": {
                  "const": "admin.correction",
                  "type": "string"
                },
                "event": {
                  "type": "object",
                  "properties": {
                    "eventType": {
                      "const": "admin.correction",
                      "type": "string"
                    },
                    "original": {
                      "$ref": "#/$defs/PortfolioEventEnvelope"
                    },
                    "replacement": {
                      "anyOf": [
                        {
                          "$ref": "#/$defs/CashDeposit"
                        },
                        {
                          "$ref": "#/$defs/CashWithdrawal"
                        },
                        {
                          "$ref": "#/$defs/CashTransfer"
                        },
                        {
                          "$ref": "#/$defs/CashConversion"
                        },
                        {
                          "$ref": "#/$defs/TradeFill"
                        },
                        {
                          "$ref": "#/$defs/CostCharge"
                        },
                        {
                          "$ref": "#/$defs/IncomeReceived"
                        },
                        {
                          "$ref": "#/$defs/FinancingCharge"
                        },
                        {
                          "$ref": "#/$defs/CorporateSplit"
                        },
                        {
                          "$ref": "#/$defs/DerivativeExercise"
                        },
                        {
                          "$ref": "#/$defs/DerivativeAssignment"
                        },
                        {
                          "$ref": "#/$defs/DerivativeExpiration"
                        },
                        {
                          "$ref": "#/$defs/DerivativeMultiplierChange"
                        },
                        {
                          "$ref": "#/$defs/DerivativeVariationMargin"
                        },
                        {
                          "$ref": "#/$defs/DerivativeRoll"
                        },
                        {
                          "$ref": "#/$defs/FixedIncomeRedemption"
                        },
                        {
                          "$ref": "#/$defs/CorporateSymbolChange"
                        },
                        {
                          "$ref": "#/$defs/CorporateMerger"
                        },
                        {
                          "$ref": "#/$defs/CorporateSpinOff"
                        },
                        {
                          "$ref": "#/$defs/CorporateReturnOfCapital"
                        },
                        {
                          "$ref": "#/$defs/CorporateCashInLieu"
                        },
                        {
                          "$ref": "#/$defs/PositionTransfer"
                        }
                      ]
                    },
                    "reason": {
                      "type": "string"
                    }
                  },
                  "additionalProperties": false,
                  "required": [
                    "eventType",
                    "original",
                    "replacement"
                  ]
                }
              },
              "required": [
                "reversesEventId"
              ]
            },
            {
              "properties": {
                "eventType": {
                  "const": "admin.account-migration",
                  "type": "string"
                },
                "event": {
                  "type": "object",
                  "properties": {
                    "eventType": {
                      "const": "admin.account-migration",
                      "type": "string"
                    },
                    "fromAccountId": {
                      "type": "string",
                      "minLength": 1
                    },
                    "toAccountId": {
                      "type": "string",
                      "minLength": 1
                    },
                    "reason": {
                      "type": "string"
                    }
                  },
                  "additionalProperties": false,
                  "required": [
                    "eventType",
                    "fromAccountId",
                    "toAccountId"
                  ]
                }
              }
            }
          ]
        }
      ]
    },
    "Provenance": {
      "type": "object",
      "properties": {
        "provider": {
          "type": "string"
        },
        "dataset": {
          "type": "string"
        },
        "asOf": {
          "type": "number",
          "description": "Epoch milliseconds"
        },
        "receivedAt": {
          "type": "number",
          "description": "Epoch milliseconds"
        },
        "sourceVersion": {
          "type": "string"
        },
        "requestId": {
          "type": "string"
        },
        "warnings": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "minLength": 1
              },
              "message": {
                "type": "string"
              },
              "severity": {
                "type": "string",
                "enum": [
                  "info",
                  "warn",
                  "error"
                ]
              },
              "context": {
                "type": "object",
                "additionalProperties": {}
              }
            },
            "additionalProperties": false,
            "required": [
              "code",
              "message",
              "severity"
            ]
          }
        }
      },
      "additionalProperties": false
    },
    "Detail": {
      "type": "object",
      "properties": {
        "quantity": {
          "type": "number"
        },
        "fillId": {
          "type": "string"
        },
        "pricePerUnit": {
          "type": "number"
        },
        "reason": {
          "type": "string"
        },
        "replacementOrderId": {
          "type": "string"
        },
        "artifactHash": {
          "type": "string"
        },
        "note": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "Contract": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "option",
              "type": "string"
            },
            "underlyingInstrumentId": {
              "type": "string",
              "minLength": 1
            },
            "type": {
              "type": "string",
              "enum": [
                "call",
                "put"
              ]
            },
            "strikePricePerUnit": {
              "type": "number"
            },
            "expiryTimestampMs": {
              "type": "number",
              "description": "Epoch milliseconds"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "underlyingInstrumentId",
            "type",
            "strikePricePerUnit",
            "expiryTimestampMs"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "future",
              "type": "string"
            },
            "underlyingInstrumentId": {
              "type": "string",
              "minLength": 1
            },
            "expiryTimestampMs": {
              "type": "number",
              "description": "Epoch milliseconds"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "underlyingInstrumentId",
            "expiryTimestampMs"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "perpetual",
              "type": "string"
            },
            "underlyingInstrumentId": {
              "type": "string",
              "minLength": 1
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "underlyingInstrumentId"
          ]
        }
      ]
    },
    "Detail2": {
      "type": "object",
      "properties": {
        "quantity": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "fillId": {
          "type": "string",
          "minLength": 1
        },
        "pricePerUnit": {
          "type": "number"
        },
        "reason": {
          "type": "string"
        },
        "replacementOrderId": {
          "type": "string"
        },
        "artifactHash": {
          "type": "string"
        },
        "note": {
          "type": "string"
        },
        "observationTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        },
        "fill": {
          "$ref": "#/$defs/Fill"
        }
      },
      "additionalProperties": false,
      "required": [
        "quantity",
        "fillId"
      ]
    },
    "Fill": {
      "type": "object",
      "properties": {
        "fillId": {
          "type": "string",
          "minLength": 1
        },
        "accountId": {
          "type": "string",
          "minLength": 1
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "side": {
          "type": "string",
          "enum": [
            "buy",
            "sell"
          ]
        },
        "quantity": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "pricePerUnit": {
          "type": "number"
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "filledTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        },
        "settleTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        },
        "contractMultiplier": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "settlementStyle": {
          "type": "string",
          "enum": [
            "cash-on-trade",
            "variation-margin"
          ]
        },
        "contract": {
          "$ref": "#/$defs/Contract"
        },
        "accruedInterest": {
          "type": "number"
        },
        "executionPriceAdjustment": {
          "type": "number",
          "minimum": 0
        },
        "costs": {
          "type": "object",
          "properties": {
            "commission": {
              "type": "number",
              "minimum": 0
            },
            "exchangeFees": {
              "type": "number",
              "minimum": 0
            },
            "regulatoryFees": {
              "type": "number",
              "minimum": 0
            },
            "slippageAdjustment": {
              "type": "number",
              "minimum": 0
            }
          },
          "additionalProperties": false
        },
        "orderId": {
          "type": "string",
          "minLength": 1
        },
        "venue": {
          "type": "string"
        },
        "liquidity": {
          "type": "string",
          "enum": [
            "maker",
            "taker",
            "unknown"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "fillId",
        "accountId",
        "instrumentId",
        "side",
        "quantity",
        "pricePerUnit",
        "currency",
        "filledTimestampMs"
      ]
    },
    "CashDeposit": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "cash.deposit",
          "type": "string"
        },
        "amount": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "settleTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "amount",
        "currency"
      ]
    },
    "CashWithdrawal": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "cash.withdrawal",
          "type": "string"
        },
        "amount": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "settleTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "amount",
        "currency"
      ]
    },
    "CashTransfer": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "cash.transfer",
          "type": "string"
        },
        "amount": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "fromAccountId": {
          "type": "string",
          "minLength": 1
        },
        "toAccountId": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "amount",
        "currency",
        "fromAccountId",
        "toAccountId"
      ]
    },
    "CashConversion": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "cash.conversion",
          "type": "string"
        },
        "fromCurrency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "toCurrency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "fromAmount": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "toAmount": {
          "type": "number",
          "exclusiveMinimum": 0
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "fromCurrency",
        "toCurrency",
        "fromAmount",
        "toAmount"
      ]
    },
    "TradeFill": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "trade.fill",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "side": {
          "type": "string",
          "enum": [
            "buy",
            "sell"
          ]
        },
        "quantity": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "pricePerUnit": {
          "type": "number"
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "settleTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        },
        "lotSelections": {
          "$ref": "#/$defs/LotSelections"
        },
        "contractMultiplier": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "settlementStyle": {
          "type": "string",
          "enum": [
            "cash-on-trade",
            "variation-margin"
          ]
        },
        "contract": {
          "$ref": "#/$defs/Contract"
        },
        "accruedInterest": {
          "type": "number"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "side",
        "quantity",
        "pricePerUnit",
        "currency"
      ]
    },
    "LotSelections": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "lotId": {
            "type": "string",
            "minLength": 1
          },
          "quantity": {
            "type": "number",
            "exclusiveMinimum": 0
          }
        },
        "additionalProperties": false,
        "required": [
          "lotId",
          "quantity"
        ]
      },
      "minItems": 1
    },
    "CostCharge": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "cost.charge",
          "type": "string"
        },
        "costType": {
          "type": "string",
          "enum": [
            "commission",
            "exchange-fee",
            "regulatory-fee",
            "slippage-adjustment"
          ]
        },
        "amount": {
          "type": "number"
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "relatesToEventId": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "costType",
        "amount",
        "currency"
      ]
    },
    "IncomeReceived": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "income.received",
          "type": "string"
        },
        "incomeType": {
          "type": "string",
          "enum": [
            "dividend",
            "coupon",
            "interest",
            "staking-reward",
            "funding-receipt"
          ]
        },
        "amount": {
          "type": "number"
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "settleTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "incomeType",
        "amount",
        "currency"
      ]
    },
    "FinancingCharge": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "financing.charge",
          "type": "string"
        },
        "financingType": {
          "type": "string",
          "enum": [
            "margin-interest",
            "borrow-charge",
            "funding-payment"
          ]
        },
        "amount": {
          "type": "number"
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "financingType",
        "amount",
        "currency"
      ]
    },
    "CorporateSplit": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "corporate.split",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "sharesAfterSplit": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "sharesBeforeSplit": {
          "type": "number",
          "exclusiveMinimum": 0
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "sharesAfterSplit",
        "sharesBeforeSplit"
      ]
    },
    "DerivativeExercise": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "derivative.exercise",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "quantity": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "settlement": {
          "$ref": "#/$defs/Settlement"
        },
        "premiumTreatment": {
          "type": "string",
          "enum": [
            "fold-into-underlying-basis",
            "realize"
          ]
        },
        "settleTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        },
        "lotSelections": {
          "$ref": "#/$defs/LotSelections"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "quantity",
        "settlement",
        "premiumTreatment"
      ]
    },
    "Settlement": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "physical",
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "cash",
              "type": "string"
            },
            "settlementPricePerUnit": {
              "type": "number"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "settlementPricePerUnit"
          ]
        }
      ]
    },
    "DerivativeAssignment": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "derivative.assignment",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "quantity": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "settlement": {
          "$ref": "#/$defs/Settlement"
        },
        "premiumTreatment": {
          "type": "string",
          "enum": [
            "fold-into-underlying-basis",
            "realize"
          ]
        },
        "settleTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        },
        "lotSelections": {
          "$ref": "#/$defs/LotSelections"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "quantity",
        "settlement",
        "premiumTreatment"
      ]
    },
    "DerivativeExpiration": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "derivative.expiration",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "quantity": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "lotSelections": {
          "$ref": "#/$defs/LotSelections"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "quantity"
      ]
    },
    "DerivativeMultiplierChange": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "derivative.multiplier-change",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "contractMultiplierAfter": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "strikePricePerUnitAfter": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "reason": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "contractMultiplierAfter"
      ]
    },
    "DerivativeVariationMargin": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "derivative.variation-margin",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "settlementPricePerUnit": {
          "type": "number"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "settlementPricePerUnit"
      ]
    },
    "DerivativeRoll": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "derivative.roll",
          "type": "string"
        },
        "fromInstrumentId": {
          "type": "string",
          "minLength": 1
        },
        "toInstrumentId": {
          "type": "string",
          "minLength": 1
        },
        "quantity": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "closePricePerUnit": {
          "type": "number"
        },
        "openPricePerUnit": {
          "type": "number"
        },
        "contract": {
          "$ref": "#/$defs/Contract"
        },
        "lotSelections": {
          "$ref": "#/$defs/LotSelections"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "fromInstrumentId",
        "toInstrumentId",
        "quantity",
        "closePricePerUnit",
        "openPricePerUnit"
      ]
    },
    "FixedIncomeRedemption": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "fixed-income.redemption",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "redemptionType": {
          "type": "string",
          "enum": [
            "maturity",
            "call",
            "principal-paydown",
            "sinking-fund"
          ]
        },
        "quantity": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "pricePerUnit": {
          "type": "number"
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "settleTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        },
        "lotSelections": {
          "$ref": "#/$defs/LotSelections"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "redemptionType",
        "quantity",
        "pricePerUnit",
        "currency"
      ]
    },
    "CorporateSymbolChange": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "corporate.symbol-change",
          "type": "string"
        },
        "fromInstrumentId": {
          "type": "string",
          "minLength": 1
        },
        "toInstrumentId": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "fromInstrumentId",
        "toInstrumentId"
      ]
    },
    "CorporateMerger": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "corporate.merger",
          "type": "string"
        },
        "fromInstrumentId": {
          "type": "string",
          "minLength": 1
        },
        "toInstrumentId": {
          "type": "string",
          "minLength": 1
        },
        "sharesPerShare": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "cashPerShare": {
          "type": "number"
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "settleTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "fromInstrumentId"
      ]
    },
    "CorporateSpinOff": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "corporate.spin-off",
          "type": "string"
        },
        "parentInstrumentId": {
          "type": "string",
          "minLength": 1
        },
        "childInstrumentId": {
          "type": "string",
          "minLength": 1
        },
        "sharesPerParentShare": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "basisAllocationFraction": {
          "type": "number"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "parentInstrumentId",
        "childInstrumentId",
        "sharesPerParentShare",
        "basisAllocationFraction"
      ]
    },
    "CorporateReturnOfCapital": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "corporate.return-of-capital",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "amountPerShare": {
          "type": "number"
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "settleTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "amountPerShare",
        "currency"
      ]
    },
    "CorporateCashInLieu": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "corporate.cash-in-lieu",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "quantity": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "amount": {
          "type": "number"
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "relatesToEventId": {
          "type": "string",
          "minLength": 1
        },
        "settleTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "quantity",
        "amount",
        "currency"
      ]
    },
    "PositionTransfer": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "position.transfer",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "quantity": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "fromAccountId": {
          "type": "string",
          "minLength": 1
        },
        "toAccountId": {
          "type": "string",
          "minLength": 1
        },
        "lotSelections": {
          "$ref": "#/$defs/LotSelections"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "quantity",
        "fromAccountId",
        "toAccountId"
      ]
    }
  }
}
Output schema
{
  "type": "object",
  "properties": {
    "kind": {
      "const": "totalfinance.reconciliation-report",
      "type": "string"
    },
    "schemaVersion": {
      "const": 1,
      "type": "number"
    },
    "asOf": {
      "type": "number",
      "description": "Epoch milliseconds"
    },
    "planHash": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "journalId": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "sourceId": {
      "type": "string",
      "minLength": 1
    },
    "reconciled": {
      "type": "boolean"
    },
    "orders": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "orderId": {
            "type": "string",
            "minLength": 1
          },
          "planHash": {
            "type": "string",
            "minLength": 1
          },
          "state": {
            "type": "string",
            "enum": [
              "submitted",
              "acknowledged",
              "partially-filled",
              "filled",
              "cancelled",
              "rejected",
              "expired",
              "unresolved"
            ]
          },
          "submittedQuantity": {
            "type": "number",
            "minimum": 0
          },
          "filledQuantity": {
            "type": "number",
            "minimum": 0
          },
          "remainingQuantity": {
            "type": "number",
            "minimum": 0
          },
          "averageFillPrice": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "fillIds": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "lateFillIds": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "lastEventId": {
            "type": "string",
            "minLength": 1
          },
          "lastTimestampMs": {
            "type": "number",
            "description": "Epoch milliseconds"
          },
          "terminal": {
            "type": "boolean"
          },
          "cancelRequested": {
            "type": "boolean"
          },
          "reason": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "replacedBy": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "reconciledEventId": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "additionalProperties": false,
        "required": [
          "orderId",
          "planHash",
          "state",
          "submittedQuantity",
          "filledQuantity",
          "remainingQuantity",
          "averageFillPrice",
          "fillIds",
          "lateFillIds",
          "lastEventId",
          "lastTimestampMs",
          "terminal",
          "cancelRequested",
          "reason",
          "replacedBy",
          "reconciledEventId"
        ]
      }
    },
    "orderChecks": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "orderId": {
            "type": "string",
            "minLength": 1
          },
          "state": {
            "type": "string",
            "enum": [
              "submitted",
              "acknowledged",
              "partially-filled",
              "filled",
              "cancelled",
              "rejected",
              "expired",
              "unresolved"
            ]
          },
          "journaledQuantity": {
            "type": "number"
          },
          "fillQuantity": {
            "type": "number"
          },
          "difference": {
            "type": "number"
          },
          "withinTolerance": {
            "type": "boolean"
          }
        },
        "additionalProperties": false,
        "required": [
          "orderId",
          "state",
          "journaledQuantity",
          "fillQuantity",
          "difference",
          "withinTolerance"
        ]
      }
    },
    "fills": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "fillId": {
            "type": "string",
            "minLength": 1
          },
          "orderId": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "quantity": {
            "type": "number"
          },
          "journaled": {
            "type": "boolean"
          },
          "inLedger": {
            "type": "boolean"
          },
          "ledgerKey": {
            "type": "string"
          }
        },
        "additionalProperties": false,
        "required": [
          "fillId",
          "orderId",
          "quantity",
          "journaled",
          "inLedger",
          "ledgerKey"
        ]
      }
    },
    "journaledNotInLedger": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "ledgerNotJournaled": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "unresolved": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "orderId": {
            "type": "string",
            "minLength": 1
          },
          "reason": {
            "type": "string"
          }
        },
        "additionalProperties": false,
        "required": [
          "orderId",
          "reason"
        ]
      }
    },
    "portfolio": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "asOf": {
              "type": "number",
              "description": "Epoch milliseconds"
            },
            "baseCurrency": {
              "type": "string",
              "pattern": "^[A-Z]{3}$"
            },
            "reconciled": {
              "type": "boolean"
            },
            "accounts": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "accountId": {
                    "type": "string",
                    "minLength": 1
                  },
                  "presentInLedger": {
                    "type": "boolean"
                  },
                  "presentInExternal": {
                    "type": "boolean"
                  },
                  "cash": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "currency": {
                          "type": "string",
                          "pattern": "^[A-Z]{3}$"
                        },
                        "ledgerTotal": {
                          "type": "number"
                        },
                        "ledgerSettled": {
                          "type": "number"
                        },
                        "ledgerUnsettledReceivable": {
                          "type": "number"
                        },
                        "ledgerUnsettledPayable": {
                          "type": "number"
                        },
                        "externalTotal": {
                          "type": "number"
                        },
                        "externalSettled": {
                          "anyOf": [
                            {
                              "type": "number"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "totalDifference": {
                          "type": "number"
                        },
                        "settledDifference": {
                          "anyOf": [
                            {
                              "type": "number"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "withinTolerance": {
                          "type": "boolean"
                        },
                        "explanation": {
                          "$ref": "#/$defs/Explanation"
                        }
                      },
                      "additionalProperties": false,
                      "required": [
                        "currency",
                        "ledgerTotal",
                        "ledgerSettled",
                        "ledgerUnsettledReceivable",
                        "ledgerUnsettledPayable",
                        "externalTotal",
                        "externalSettled",
                        "totalDifference",
                        "settledDifference",
                        "withinTolerance"
                      ]
                    }
                  },
                  "positions": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "instrumentId": {
                          "type": "string",
                          "minLength": 1
                        },
                        "kind": {
                          "type": "string",
                          "enum": [
                            "matched",
                            "quantity-difference",
                            "missing-in-external",
                            "extra-in-external"
                          ]
                        },
                        "ledgerQuantity": {
                          "type": "number"
                        },
                        "externalQuantity": {
                          "type": "number"
                        },
                        "quantityDifference": {
                          "type": "number"
                        },
                        "withinTolerance": {
                          "type": "boolean"
                        },
                        "currency": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "currencyMismatch": {
                          "type": "object",
                          "properties": {
                            "ledger": {
                              "type": "string"
                            },
                            "external": {
                              "type": "string"
                            }
                          },
                          "additionalProperties": false,
                          "required": [
                            "ledger",
                            "external"
                          ]
                        },
                        "costBasis": {
                          "type": "object",
                          "properties": {
                            "ledger": {
                              "type": "number"
                            },
                            "external": {
                              "type": "number"
                            },
                            "difference": {
                              "type": "number"
                            },
                            "withinTolerance": {
                              "type": "boolean"
                            }
                          },
                          "additionalProperties": false,
                          "required": [
                            "ledger",
                            "external",
                            "difference",
                            "withinTolerance"
                          ]
                        },
                        "explanation": {
                          "$ref": "#/$defs/Explanation"
                        }
                      },
                      "additionalProperties": false,
                      "required": [
                        "instrumentId",
                        "kind",
                        "ledgerQuantity",
                        "externalQuantity",
                        "quantityDifference",
                        "withinTolerance",
                        "currency"
                      ]
                    }
                  }
                },
                "additionalProperties": false,
                "required": [
                  "accountId",
                  "presentInLedger",
                  "presentInExternal",
                  "cash",
                  "positions"
                ]
              }
            },
            "differenceCount": {
              "type": "integer",
              "minimum": 0
            },
            "explainedCount": {
              "type": "integer",
              "minimum": 0
            },
            "suggestedCorrections": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/PortfolioEventEnvelope"
              }
            },
            "undraftable": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "accountId": {
                    "type": "string",
                    "minLength": 1
                  },
                  "subject": {
                    "type": "string"
                  },
                  "reason": {
                    "type": "string"
                  }
                },
                "additionalProperties": false,
                "required": [
                  "accountId",
                  "subject",
                  "reason"
                ]
              }
            },
            "assumptions": {
              "type": "object",
              "properties": {
                "conventionsVersion": {
                  "type": "string"
                },
                "lotRelief": {
                  "type": "string",
                  "enum": [
                    "fifo",
                    "lifo",
                    "highest-cost",
                    "specific-lot"
                  ]
                },
                "tolerance": {
                  "$ref": "#/$defs/Tolerance"
                },
                "comparisonConvention": {
                  "type": "string"
                }
              },
              "additionalProperties": false,
              "required": [
                "conventionsVersion",
                "lotRelief",
                "tolerance",
                "comparisonConvention"
              ]
            },
            "diagnostics": {
              "type": "object",
              "properties": {
                "warnings": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "ledgerAccountCount": {
                  "type": "integer",
                  "minimum": 0
                },
                "externalAccountCount": {
                  "type": "integer",
                  "minimum": 0
                }
              },
              "additionalProperties": false,
              "required": [
                "warnings",
                "ledgerAccountCount",
                "externalAccountCount"
              ]
            }
          },
          "additionalProperties": false,
          "required": [
            "asOf",
            "baseCurrency",
            "reconciled",
            "accounts",
            "differenceCount",
            "explainedCount",
            "suggestedCorrections",
            "undraftable",
            "assumptions",
            "diagnostics"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "assumptions": {
      "type": "object",
      "properties": {
        "conventionsVersion": {
          "type": "string"
        },
        "tolerance": {
          "$ref": "#/$defs/Tolerance"
        },
        "matchConvention": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "conventionsVersion",
        "tolerance",
        "matchConvention"
      ]
    },
    "diagnostics": {
      "type": "object",
      "properties": {
        "engine": {
          "const": "trade-reconciliation",
          "type": "string"
        },
        "warnings": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "orderCount": {
          "type": "integer",
          "minimum": 0
        },
        "openCount": {
          "type": "integer",
          "minimum": 0
        },
        "fillCount": {
          "type": "integer",
          "minimum": 0
        },
        "ledgerFillCount": {
          "type": "integer",
          "minimum": 0
        },
        "unresolvedCount": {
          "type": "integer",
          "minimum": 0
        },
        "differenceCount": {
          "type": "integer",
          "minimum": 0
        }
      },
      "additionalProperties": false,
      "required": [
        "engine",
        "warnings",
        "orderCount",
        "openCount",
        "fillCount",
        "ledgerFillCount",
        "unresolvedCount",
        "differenceCount"
      ]
    },
    "contentHash": {
      "type": "string",
      "minLength": 1
    }
  },
  "additionalProperties": false,
  "required": [
    "kind",
    "schemaVersion",
    "asOf",
    "planHash",
    "journalId",
    "sourceId",
    "reconciled",
    "orders",
    "orderChecks",
    "fills",
    "journaledNotInLedger",
    "ledgerNotJournaled",
    "unresolved",
    "portfolio",
    "assumptions",
    "diagnostics",
    "contentHash"
  ],
  "$id": "https://totalfinance.dev/schemas/trade.reconcile.output",
  "$defs": {
    "PortfolioEventEnvelope": {
      "allOf": [
        {
          "type": "object",
          "properties": {
            "eventId": {
              "type": "string",
              "minLength": 1
            },
            "schemaVersion": {
              "const": 1,
              "type": "number"
            },
            "sourceId": {
              "type": "string",
              "minLength": 1
            },
            "accountId": {
              "type": "string",
              "minLength": 1
            },
            "effectiveTimestampMs": {
              "type": "number",
              "description": "Epoch milliseconds"
            },
            "recordedTimestampMs": {
              "type": "number",
              "description": "Epoch milliseconds"
            },
            "correlationId": {
              "type": "string",
              "minLength": 1
            },
            "causationId": {
              "type": "string",
              "minLength": 1
            },
            "reversesEventId": {
              "type": "string",
              "minLength": 1
            },
            "provenance": {
              "type": "object",
              "properties": {
                "provider": {
                  "type": "string"
                },
                "dataset": {
                  "type": "string"
                },
                "asOf": {
                  "type": "number",
                  "description": "Epoch milliseconds"
                },
                "receivedAt": {
                  "type": "number",
                  "description": "Epoch milliseconds"
                },
                "sourceVersion": {
                  "type": "string"
                },
                "requestId": {
                  "type": "string"
                },
                "warnings": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "code": {
                        "type": "string",
                        "minLength": 1
                      },
                      "message": {
                        "type": "string"
                      },
                      "severity": {
                        "type": "string",
                        "enum": [
                          "info",
                          "warn",
                          "error"
                        ]
                      },
                      "context": {
                        "type": "object",
                        "additionalProperties": {}
                      }
                    },
                    "additionalProperties": false,
                    "required": [
                      "code",
                      "message",
                      "severity"
                    ]
                  }
                }
              },
              "additionalProperties": false
            },
            "eventType": {},
            "event": {}
          },
          "additionalProperties": false,
          "required": [
            "eventId",
            "schemaVersion",
            "sourceId",
            "accountId",
            "effectiveTimestampMs",
            "recordedTimestampMs",
            "provenance",
            "eventType",
            "event"
          ]
        },
        {
          "anyOf": [
            {
              "properties": {
                "eventType": {
                  "const": "cash.deposit",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CashDeposit"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "cash.withdrawal",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CashWithdrawal"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "cash.transfer",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CashTransfer"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "cash.conversion",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CashConversion"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "trade.fill",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/TradeFill"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "cost.charge",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CostCharge"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "income.received",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/IncomeReceived"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "financing.charge",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/FinancingCharge"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "corporate.split",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CorporateSplit"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "derivative.exercise",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/DerivativeExercise"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "derivative.assignment",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/DerivativeAssignment"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "derivative.expiration",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/DerivativeExpiration"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "derivative.multiplier-change",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/DerivativeMultiplierChange"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "derivative.variation-margin",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/DerivativeVariationMargin"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "derivative.roll",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/DerivativeRoll"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "fixed-income.redemption",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/FixedIncomeRedemption"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "corporate.symbol-change",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CorporateSymbolChange"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "corporate.merger",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CorporateMerger"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "corporate.spin-off",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CorporateSpinOff"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "corporate.return-of-capital",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CorporateReturnOfCapital"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "corporate.cash-in-lieu",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/CorporateCashInLieu"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "position.transfer",
                  "type": "string"
                },
                "event": {
                  "$ref": "#/$defs/PositionTransfer"
                }
              }
            },
            {
              "properties": {
                "eventType": {
                  "const": "admin.reversal",
                  "type": "string"
                },
                "event": {
                  "type": "object",
                  "properties": {
                    "eventType": {
                      "const": "admin.reversal",
                      "type": "string"
                    },
                    "original": {
                      "$ref": "#/$defs/PortfolioEventEnvelope"
                    },
                    "reason": {
                      "type": "string"
                    }
                  },
                  "additionalProperties": false,
                  "required": [
                    "eventType",
                    "original"
                  ]
                }
              },
              "required": [
                "reversesEventId"
              ]
            },
            {
              "properties": {
                "eventType": {
                  "const": "admin.correction",
                  "type": "string"
                },
                "event": {
                  "type": "object",
                  "properties": {
                    "eventType": {
                      "const": "admin.correction",
                      "type": "string"
                    },
                    "original": {
                      "$ref": "#/$defs/PortfolioEventEnvelope"
                    },
                    "replacement": {
                      "anyOf": [
                        {
                          "$ref": "#/$defs/CashDeposit"
                        },
                        {
                          "$ref": "#/$defs/CashWithdrawal"
                        },
                        {
                          "$ref": "#/$defs/CashTransfer"
                        },
                        {
                          "$ref": "#/$defs/CashConversion"
                        },
                        {
                          "$ref": "#/$defs/TradeFill"
                        },
                        {
                          "$ref": "#/$defs/CostCharge"
                        },
                        {
                          "$ref": "#/$defs/IncomeReceived"
                        },
                        {
                          "$ref": "#/$defs/FinancingCharge"
                        },
                        {
                          "$ref": "#/$defs/CorporateSplit"
                        },
                        {
                          "$ref": "#/$defs/DerivativeExercise"
                        },
                        {
                          "$ref": "#/$defs/DerivativeAssignment"
                        },
                        {
                          "$ref": "#/$defs/DerivativeExpiration"
                        },
                        {
                          "$ref": "#/$defs/DerivativeMultiplierChange"
                        },
                        {
                          "$ref": "#/$defs/DerivativeVariationMargin"
                        },
                        {
                          "$ref": "#/$defs/DerivativeRoll"
                        },
                        {
                          "$ref": "#/$defs/FixedIncomeRedemption"
                        },
                        {
                          "$ref": "#/$defs/CorporateSymbolChange"
                        },
                        {
                          "$ref": "#/$defs/CorporateMerger"
                        },
                        {
                          "$ref": "#/$defs/CorporateSpinOff"
                        },
                        {
                          "$ref": "#/$defs/CorporateReturnOfCapital"
                        },
                        {
                          "$ref": "#/$defs/CorporateCashInLieu"
                        },
                        {
                          "$ref": "#/$defs/PositionTransfer"
                        }
                      ]
                    },
                    "reason": {
                      "type": "string"
                    }
                  },
                  "additionalProperties": false,
                  "required": [
                    "eventType",
                    "original",
                    "replacement"
                  ]
                }
              },
              "required": [
                "reversesEventId"
              ]
            },
            {
              "properties": {
                "eventType": {
                  "const": "admin.account-migration",
                  "type": "string"
                },
                "event": {
                  "type": "object",
                  "properties": {
                    "eventType": {
                      "const": "admin.account-migration",
                      "type": "string"
                    },
                    "fromAccountId": {
                      "type": "string",
                      "minLength": 1
                    },
                    "toAccountId": {
                      "type": "string",
                      "minLength": 1
                    },
                    "reason": {
                      "type": "string"
                    }
                  },
                  "additionalProperties": false,
                  "required": [
                    "eventType",
                    "fromAccountId",
                    "toAccountId"
                  ]
                }
              }
            }
          ]
        }
      ]
    },
    "Explanation": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "pending-settlement",
              "type": "string"
            },
            "detail": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "detail"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "corporate-action-candidate",
              "type": "string"
            },
            "detail": {
              "type": "string"
            },
            "ratio": {
              "type": "number"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "detail",
            "ratio"
          ]
        }
      ]
    },
    "Tolerance": {
      "type": "object",
      "properties": {
        "quantity": {
          "type": "number",
          "minimum": 0
        },
        "cashAmount": {
          "type": "number",
          "minimum": 0
        },
        "costBasis": {
          "type": "number",
          "minimum": 0
        }
      },
      "additionalProperties": false,
      "required": [
        "quantity",
        "cashAmount",
        "costBasis"
      ]
    },
    "CashDeposit": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "cash.deposit",
          "type": "string"
        },
        "amount": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "settleTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "amount",
        "currency"
      ]
    },
    "CashWithdrawal": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "cash.withdrawal",
          "type": "string"
        },
        "amount": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "settleTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "amount",
        "currency"
      ]
    },
    "CashTransfer": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "cash.transfer",
          "type": "string"
        },
        "amount": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "fromAccountId": {
          "type": "string",
          "minLength": 1
        },
        "toAccountId": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "amount",
        "currency",
        "fromAccountId",
        "toAccountId"
      ]
    },
    "CashConversion": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "cash.conversion",
          "type": "string"
        },
        "fromCurrency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "toCurrency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "fromAmount": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "toAmount": {
          "type": "number",
          "exclusiveMinimum": 0
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "fromCurrency",
        "toCurrency",
        "fromAmount",
        "toAmount"
      ]
    },
    "TradeFill": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "trade.fill",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "side": {
          "type": "string",
          "enum": [
            "buy",
            "sell"
          ]
        },
        "quantity": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "pricePerUnit": {
          "type": "number"
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "settleTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        },
        "lotSelections": {
          "$ref": "#/$defs/LotSelections"
        },
        "contractMultiplier": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "settlementStyle": {
          "type": "string",
          "enum": [
            "cash-on-trade",
            "variation-margin"
          ]
        },
        "contract": {
          "$ref": "#/$defs/Contract"
        },
        "accruedInterest": {
          "type": "number"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "side",
        "quantity",
        "pricePerUnit",
        "currency"
      ]
    },
    "LotSelections": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "lotId": {
            "type": "string",
            "minLength": 1
          },
          "quantity": {
            "type": "number",
            "exclusiveMinimum": 0
          }
        },
        "additionalProperties": false,
        "required": [
          "lotId",
          "quantity"
        ]
      },
      "minItems": 1
    },
    "Contract": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "option",
              "type": "string"
            },
            "underlyingInstrumentId": {
              "type": "string",
              "minLength": 1
            },
            "type": {
              "type": "string",
              "enum": [
                "call",
                "put"
              ]
            },
            "strikePricePerUnit": {
              "type": "number"
            },
            "expiryTimestampMs": {
              "type": "number",
              "description": "Epoch milliseconds"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "underlyingInstrumentId",
            "type",
            "strikePricePerUnit",
            "expiryTimestampMs"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "future",
              "type": "string"
            },
            "underlyingInstrumentId": {
              "type": "string",
              "minLength": 1
            },
            "expiryTimestampMs": {
              "type": "number",
              "description": "Epoch milliseconds"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "underlyingInstrumentId",
            "expiryTimestampMs"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "perpetual",
              "type": "string"
            },
            "underlyingInstrumentId": {
              "type": "string",
              "minLength": 1
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "underlyingInstrumentId"
          ]
        }
      ]
    },
    "CostCharge": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "cost.charge",
          "type": "string"
        },
        "costType": {
          "type": "string",
          "enum": [
            "commission",
            "exchange-fee",
            "regulatory-fee",
            "slippage-adjustment"
          ]
        },
        "amount": {
          "type": "number"
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "relatesToEventId": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "costType",
        "amount",
        "currency"
      ]
    },
    "IncomeReceived": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "income.received",
          "type": "string"
        },
        "incomeType": {
          "type": "string",
          "enum": [
            "dividend",
            "coupon",
            "interest",
            "staking-reward",
            "funding-receipt"
          ]
        },
        "amount": {
          "type": "number"
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "settleTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "incomeType",
        "amount",
        "currency"
      ]
    },
    "FinancingCharge": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "financing.charge",
          "type": "string"
        },
        "financingType": {
          "type": "string",
          "enum": [
            "margin-interest",
            "borrow-charge",
            "funding-payment"
          ]
        },
        "amount": {
          "type": "number"
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "financingType",
        "amount",
        "currency"
      ]
    },
    "CorporateSplit": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "corporate.split",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "sharesAfterSplit": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "sharesBeforeSplit": {
          "type": "number",
          "exclusiveMinimum": 0
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "sharesAfterSplit",
        "sharesBeforeSplit"
      ]
    },
    "DerivativeExercise": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "derivative.exercise",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "quantity": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "settlement": {
          "$ref": "#/$defs/Settlement"
        },
        "premiumTreatment": {
          "type": "string",
          "enum": [
            "fold-into-underlying-basis",
            "realize"
          ]
        },
        "settleTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        },
        "lotSelections": {
          "$ref": "#/$defs/LotSelections"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "quantity",
        "settlement",
        "premiumTreatment"
      ]
    },
    "Settlement": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "physical",
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "cash",
              "type": "string"
            },
            "settlementPricePerUnit": {
              "type": "number"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "settlementPricePerUnit"
          ]
        }
      ]
    },
    "DerivativeAssignment": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "derivative.assignment",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "quantity": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "settlement": {
          "$ref": "#/$defs/Settlement"
        },
        "premiumTreatment": {
          "type": "string",
          "enum": [
            "fold-into-underlying-basis",
            "realize"
          ]
        },
        "settleTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        },
        "lotSelections": {
          "$ref": "#/$defs/LotSelections"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "quantity",
        "settlement",
        "premiumTreatment"
      ]
    },
    "DerivativeExpiration": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "derivative.expiration",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "quantity": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "lotSelections": {
          "$ref": "#/$defs/LotSelections"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "quantity"
      ]
    },
    "DerivativeMultiplierChange": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "derivative.multiplier-change",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "contractMultiplierAfter": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "strikePricePerUnitAfter": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "reason": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "contractMultiplierAfter"
      ]
    },
    "DerivativeVariationMargin": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "derivative.variation-margin",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "settlementPricePerUnit": {
          "type": "number"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "settlementPricePerUnit"
      ]
    },
    "DerivativeRoll": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "derivative.roll",
          "type": "string"
        },
        "fromInstrumentId": {
          "type": "string",
          "minLength": 1
        },
        "toInstrumentId": {
          "type": "string",
          "minLength": 1
        },
        "quantity": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "closePricePerUnit": {
          "type": "number"
        },
        "openPricePerUnit": {
          "type": "number"
        },
        "contract": {
          "$ref": "#/$defs/Contract"
        },
        "lotSelections": {
          "$ref": "#/$defs/LotSelections"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "fromInstrumentId",
        "toInstrumentId",
        "quantity",
        "closePricePerUnit",
        "openPricePerUnit"
      ]
    },
    "FixedIncomeRedemption": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "fixed-income.redemption",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "redemptionType": {
          "type": "string",
          "enum": [
            "maturity",
            "call",
            "principal-paydown",
            "sinking-fund"
          ]
        },
        "quantity": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "pricePerUnit": {
          "type": "number"
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "settleTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        },
        "lotSelections": {
          "$ref": "#/$defs/LotSelections"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "redemptionType",
        "quantity",
        "pricePerUnit",
        "currency"
      ]
    },
    "CorporateSymbolChange": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "corporate.symbol-change",
          "type": "string"
        },
        "fromInstrumentId": {
          "type": "string",
          "minLength": 1
        },
        "toInstrumentId": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "fromInstrumentId",
        "toInstrumentId"
      ]
    },
    "CorporateMerger": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "corporate.merger",
          "type": "string"
        },
        "fromInstrumentId": {
          "type": "string",
          "minLength": 1
        },
        "toInstrumentId": {
          "type": "string",
          "minLength": 1
        },
        "sharesPerShare": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "cashPerShare": {
          "type": "number"
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "settleTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "fromInstrumentId"
      ]
    },
    "CorporateSpinOff": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "corporate.spin-off",
          "type": "string"
        },
        "parentInstrumentId": {
          "type": "string",
          "minLength": 1
        },
        "childInstrumentId": {
          "type": "string",
          "minLength": 1
        },
        "sharesPerParentShare": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "basisAllocationFraction": {
          "type": "number"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "parentInstrumentId",
        "childInstrumentId",
        "sharesPerParentShare",
        "basisAllocationFraction"
      ]
    },
    "CorporateReturnOfCapital": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "corporate.return-of-capital",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "amountPerShare": {
          "type": "number"
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "settleTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "amountPerShare",
        "currency"
      ]
    },
    "CorporateCashInLieu": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "corporate.cash-in-lieu",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "quantity": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "amount": {
          "type": "number"
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "relatesToEventId": {
          "type": "string",
          "minLength": 1
        },
        "settleTimestampMs": {
          "type": "number",
          "description": "Epoch milliseconds"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "quantity",
        "amount",
        "currency"
      ]
    },
    "PositionTransfer": {
      "type": "object",
      "properties": {
        "eventType": {
          "const": "position.transfer",
          "type": "string"
        },
        "instrumentId": {
          "type": "string",
          "minLength": 1
        },
        "quantity": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "fromAccountId": {
          "type": "string",
          "minLength": 1
        },
        "toAccountId": {
          "type": "string",
          "minLength": 1
        },
        "lotSelections": {
          "$ref": "#/$defs/LotSelections"
        }
      },
      "additionalProperties": false,
      "required": [
        "eventType",
        "instrumentId",
        "quantity",
        "fromAccountId",
        "toAccountId"
      ]
    }
  }
}

All operations · Setup, handles, jobs & permissions