{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/farmdash/json-schema/farmdash-reconcile-order-response-schema.json",
  "title": "ReconcileOrderResponse",
  "x-generated": "2026-10-29",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/farmdash-agent-api-openapi.yml#/components/schemas/ReconcileOrderResponse",
  "type": "object",
  "required": [
    "ok",
    "reconciliation",
    "builderFees",
    "durableEvidence",
    "evidenceSources",
    "timestamp"
  ],
  "properties": {
    "ok": {
      "type": "boolean",
      "enum": [
        true
      ]
    },
    "reconciliation": {
      "$ref": "#/$defs/FuturesOrderReconciliation"
    },
    "boundedReconciliation": {
      "type": "array",
      "description": "Optional; omitted when no durable bounded actions match. An accepted reservation is not final venue cancellation.",
      "items": {
        "$ref": "#/$defs/BoundedFuturesReconciliation"
      }
    },
    "builderFees": {
      "$ref": "#/$defs/FuturesBuilderFeeReconciliation"
    },
    "durableEvidence": {
      "$ref": "#/$defs/ReconcileOrderDurableEvidence"
    },
    "evidenceSources": {
      "type": "object",
      "required": [
        "orderStatus",
        "fills",
        "methodology",
        "balanceDeltasUsed"
      ],
      "properties": {
        "orderStatus": {
          "type": "string",
          "enum": [
            "hyperliquid_order_status"
          ]
        },
        "fills": {
          "type": "string",
          "enum": [
            "hyperliquid_user_fills"
          ]
        },
        "methodology": {
          "type": "string",
          "enum": [
            "direct_venue_evidence_only"
          ]
        },
        "balanceDeltasUsed": {
          "type": "boolean",
          "enum": [
            false
          ]
        }
      }
    },
    "timestamp": {
      "type": "integer",
      "description": "Unix milliseconds"
    }
  },
  "$defs": {
    "BoundedFuturesReconciliation": {
      "type": "object",
      "required": [
        "actionId",
        "result"
      ],
      "properties": {
        "actionId": {
          "type": "string",
          "format": "uuid"
        },
        "result": {
          "oneOf": [
            {
              "$ref": "#/$defs/BoundedFuturesReservation"
            },
            {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "bounded"
              ],
              "properties": {
                "bounded": {
                  "type": "boolean",
                  "enum": [
                    false
                  ]
                }
              }
            }
          ]
        }
      }
    },
    "BoundedFuturesReservation": {
      "type": "object",
      "description": "Durable reservation row returned by FuturesPolicyService; not proof of execution, final cancellation or revenue",
      "required": [
        "id",
        "grant_id",
        "action_id",
        "network",
        "account_address",
        "coin",
        "intent_hash",
        "signed_action_hash",
        "venue_order_id",
        "status",
        "dispatched_at"
      ],
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "grant_id": {
          "type": "string",
          "format": "uuid"
        },
        "action_id": {
          "type": "string",
          "format": "uuid"
        },
        "network": {
          "type": "string",
          "enum": [
            "mainnet",
            "testnet"
          ]
        },
        "account_address": {
          "type": "string"
        },
        "coin": {
          "type": "string"
        },
        "intent_hash": {
          "type": "string"
        },
        "signed_action_hash": {
          "type": "string"
        },
        "venue_order_id": {
          "type": [
            "integer",
            "null"
          ]
        },
        "status": {
          "type": "string",
          "enum": [
            "submitted",
            "accepted",
            "held_ambiguous",
            "reconciled",
            "released"
          ]
        },
        "dispatched_at": {
          "type": "string",
          "format": "date-time"
        },
        "scope": {
          "type": "string",
          "enum": [
            "futures.open",
            "futures.reduce",
            "futures.close",
            "futures.cancel",
            "futures.protective_order"
          ]
        },
        "venue_nonce": {
          "type": "integer"
        },
        "requested_notional_usd": {
          "oneOf": [
            {
              "type": "number"
            },
            {
              "type": "string"
            }
          ]
        },
        "new_risk_usd": {
          "oneOf": [
            {
              "type": "number"
            },
            {
              "type": "string"
            }
          ]
        },
        "risk_reducing": {
          "type": "boolean"
        },
        "expires_at": {
          "type": "string",
          "format": "date-time"
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        },
        "updated_at": {
          "type": "string",
          "format": "date-time"
        },
        "evidence": {
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": true
        },
        "cancel_target_evidence": {
          "type": "object",
          "additionalProperties": true
        }
      }
    },
    "FuturesBuilderFeeFill": {
      "type": "object",
      "required": [
        "fillId",
        "fillHash",
        "observedBuilderFee",
        "expectedBuilderFee",
        "builderFeeToken",
        "nonBuilderVenueFee",
        "state",
        "reason"
      ],
      "properties": {
        "fillId": {
          "type": "integer"
        },
        "fillHash": {
          "type": "string"
        },
        "observedBuilderFee": {
          "type": [
            "string",
            "null"
          ]
        },
        "expectedBuilderFee": {
          "type": [
            "string",
            "null"
          ]
        },
        "builderFeeToken": {
          "type": [
            "string",
            "null"
          ]
        },
        "nonBuilderVenueFee": {
          "type": [
            "string",
            "null"
          ]
        },
        "state": {
          "type": "string",
          "enum": [
            "exact",
            "absent",
            "ambiguous",
            "unavailable"
          ]
        },
        "reason": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "FuturesBuilderFeeReconciliation": {
      "type": "object",
      "required": [
        "state",
        "builderFeeTotal",
        "fillCountWithBuilderFee",
        "feeToken",
        "venueTotal",
        "nonBuilderVenueFee",
        "recipient",
        "signedTenthsBps",
        "reason",
        "fills"
      ],
      "properties": {
        "state": {
          "type": "string",
          "enum": [
            "exact",
            "absent",
            "ambiguous",
            "unavailable"
          ]
        },
        "builderFeeTotal": {
          "type": [
            "string",
            "null"
          ]
        },
        "fillCountWithBuilderFee": {
          "type": "integer"
        },
        "feeToken": {
          "type": [
            "string",
            "null"
          ]
        },
        "venueTotal": {
          "type": [
            "string",
            "null"
          ]
        },
        "nonBuilderVenueFee": {
          "type": [
            "string",
            "null"
          ]
        },
        "recipient": {
          "type": [
            "string",
            "null"
          ]
        },
        "signedTenthsBps": {
          "type": [
            "string",
            "null"
          ]
        },
        "reason": {
          "type": [
            "string",
            "null"
          ]
        },
        "fills": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/FuturesBuilderFeeFill"
          }
        }
      }
    },
    "FuturesOrderReconciliation": {
      "allOf": [
        {
          "$ref": "#/$defs/FuturesOrderReconciliationEvidence"
        },
        {
          "type": "object",
          "required": [
            "state",
            "evidence"
          ],
          "properties": {
            "state": {
              "$ref": "#/$defs/FuturesReconciliationState"
            },
            "evidence": {
              "$ref": "#/$defs/FuturesOrderReconciliationEvidence"
            }
          }
        }
      ]
    },
    "FuturesOrderReconciliationEvidence": {
      "type": "object",
      "required": [
        "accountOwner",
        "signerAddress",
        "perpDex",
        "coin",
        "orderId",
        "intentHash",
        "clientOrderId",
        "side",
        "orderSize",
        "orderPrice",
        "venueStatus",
        "venueReportedFilledSize",
        "reconciliationState",
        "filledSize",
        "filledNotional",
        "avgFillPrice",
        "venueFee",
        "venueFeeToken",
        "fillCount",
        "terminal",
        "reason",
        "fills"
      ],
      "properties": {
        "accountOwner": {
          "type": "string"
        },
        "signerAddress": {
          "type": "string"
        },
        "perpDex": {
          "type": "string"
        },
        "coin": {
          "type": "string"
        },
        "orderId": {
          "type": "integer"
        },
        "intentHash": {
          "type": [
            "string",
            "null"
          ]
        },
        "clientOrderId": {
          "type": [
            "string",
            "null"
          ]
        },
        "side": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "buy",
            "sell",
            null
          ]
        },
        "orderSize": {
          "type": [
            "number",
            "null"
          ]
        },
        "orderPrice": {
          "type": [
            "number",
            "null"
          ]
        },
        "venueStatus": {
          "type": [
            "string",
            "null"
          ]
        },
        "venueReportedFilledSize": {
          "type": [
            "number",
            "null"
          ]
        },
        "reconciliationState": {
          "$ref": "#/$defs/FuturesReconciliationState"
        },
        "filledSize": {
          "type": "number"
        },
        "filledNotional": {
          "type": "number"
        },
        "avgFillPrice": {
          "type": [
            "number",
            "null"
          ]
        },
        "venueFee": {
          "type": "number"
        },
        "venueFeeToken": {
          "type": [
            "string",
            "null"
          ]
        },
        "fillCount": {
          "type": "integer"
        },
        "terminal": {
          "type": "boolean"
        },
        "reason": {
          "type": [
            "string",
            "null"
          ]
        },
        "fills": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/FuturesReconciledFill"
          }
        }
      }
    },
    "FuturesReconciledFill": {
      "type": "object",
      "required": [
        "fillId",
        "fillHash",
        "side",
        "size",
        "price",
        "notional",
        "fee",
        "feeToken",
        "sizeRaw",
        "priceRaw",
        "feeRaw",
        "builderFeeRaw",
        "filledAt"
      ],
      "properties": {
        "fillId": {
          "type": "integer"
        },
        "fillHash": {
          "type": "string"
        },
        "side": {
          "type": "string",
          "enum": [
            "buy",
            "sell"
          ]
        },
        "size": {
          "type": "number"
        },
        "price": {
          "type": "number"
        },
        "notional": {
          "type": "number"
        },
        "fee": {
          "type": "number"
        },
        "feeToken": {
          "type": "string"
        },
        "sizeRaw": {
          "type": [
            "string",
            "null"
          ]
        },
        "priceRaw": {
          "type": [
            "string",
            "null"
          ]
        },
        "feeRaw": {
          "type": [
            "string",
            "null"
          ]
        },
        "builderFeeRaw": {
          "type": [
            "string",
            "null"
          ]
        },
        "filledAt": {
          "type": "integer",
          "description": "Unix milliseconds"
        }
      }
    },
    "FuturesReconciliationState": {
      "type": "string",
      "enum": [
        "submitted",
        "resting",
        "partially_filled",
        "fully_filled",
        "canceled",
        "venue_canceled",
        "rejected",
        "unknown",
        "ambiguous"
      ]
    },
    "ReconcileOrderDurableEvidence": {
      "type": "object",
      "required": [
        "recorded",
        "note"
      ],
      "properties": {
        "recorded": {
          "type": "boolean",
          "enum": [
            true
          ]
        },
        "record": {
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": true
        },
        "note": {
          "type": "string"
        }
      }
    }
  }
}