{
  "openapi": "3.1.0",
  "info": {
    "title": "Dinar API",
    "version": "2.1",
    "description": "Use your subscription to read two Libyan exchange-rate feeds. Choose the market that matches the transaction.\n\n| Feed | Endpoint | Pricing basis |\n| --- | --- | --- |\n| Mushir Tripoli | `GET /api/rates` | Parallel market by instrument, including cash, transfers and bank cheques |\n| Central Bank of Libya | `GET /api/central-bank` | Official bulletin with its effective date and published unit |\n\n**Both feeds in one request.** Send `GET /api/rates?market_type=all` with the same bearer key. The complete Mushir Tripoli feed is in `markets.parallel` and the official bulletin is in `markets.official`. A successful call counts once.\n\n**Quick start**\n\n1. [Register or sign in](/account). Your dashboard opens immediately. Transfer 50 LYD using the LYPay or IBAN details in your dashboard and upload your receipt.\n2. Open the [connection dashboard](/dashboard) after your payment is approved and create your personal key. Keep it on your application server.\n3. Send the key as `Authorization: Bearer YOUR_KEY` to the endpoint for your market. One response contains all the available currencies in that feed.\n\n**Subscription** — 50 LYD per month includes unlimited feed requests while active. The dashboard shows the expiry date and successful request counts.\n\n**Prices and dates** — Price fields use decimal strings with four decimal places. A successful collection can contain an earlier quote. Use each parallel instrument’s observation time or the official bulletin’s effective date to identify the price you used.\n\nCheck [feed health](/health) for collection times and coverage. For strict price-age limits, see `max_age_seconds` on `GET /api/rates`.\n\n[Download the OpenAPI specification](/openapi.json)"
  },
  "servers": [
    {
      "url": "/",
      "description": "This Dinar API host"
    },
    {
      "url": "https://dinarapi.ly",
      "description": "Dinar API"
    }
  ],
  "tags": [
    {
      "name": "Market data"
    },
    {
      "name": "Accounts"
    }
  ],
  "paths": {
    "/api/rates": {
      "get": {
        "tags": [
          "Market data"
        ],
        "operationId": "getRates",
        "summary": "Get parallel rates or both markets",
        "description": "Returns the latest available instruments from Mushir Tripoli. Use `market_type=cash`, `transfer` or `bank_cheque` to select the settlement method. Transfers and bank cheques also identify the destination or bank in `description`.\n\n**Both markets.** Use `market_type=all` for the full parallel and official snapshots in one response. Read `markets.parallel.rates` or `markets.official.rates` for the desired prices. Each snapshot retains its source, timestamp and prices. If either snapshot is unavailable, the request returns HTTP 503. A successful call counts as one request on your dashboard.\n\n**Conversion.** For a single-unit quote, `rate` gives quote units per base unit. With USD/LYD, multiply USD by `rate` to get LYD. With LYD/EGP, multiply LYD by `rate` to get EGP. `per_lyd` gives foreign units per dinar where the unit size is known. For forex rows with `rate_basis=source_lot` the provider has published a price for a lot of unspecified size. Those rows return the published `rate`, `unit_size=null` and `per_lyd=null`. Skip them for per-unit conversions.\n\n**Timing and source.** A snapshot read directly from the provider's list has `collection_method=source_list` and `mode=mushir_tripoli_direct`. A chart snapshot has `collection_method=chart` and `mode=mushir_tripoli_screen`. `last_sync_at` is the collection time, and `observed_at` is when the service read the individual price. Retained rows keep their observation time. Direct rows include `source_price_at` when the provider publishes a price-update time. This can precede the latest observation by days. Examples are illustrative.\n\n**Freshness.** At response time, the service checks each parallel observation against a 120-second window. Read `freshness_status` for the selected rows and `fresh` for each instrument. A fresh observation means the service recently read the source; an unchanged price may have an older provider timestamp. By default the response includes retained quotes and marks their age. Set `max_age_seconds=120` to require a recent successful sync and a recent observation for every selected parallel instrument. A failed requirement returns HTTP 503 and does not increment usage. In a combined call this option applies only to `markets.parallel`. The official bulletin follows its own effective date.",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Parallel-market snapshot, or both complete snapshots for market_type=all.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/Rates"
                    },
                    {
                      "$ref": "#/components/schemas/BothMarkets"
                    }
                  ]
                },
                "examples": {
                  "parallel": {
                    "summary": "Default parallel-market response",
                    "value": {
                      "source": "Mushir Tripoli",
                      "mode": "mushir_tripoli_direct",
                      "last_sync_at": "2026-01-01T10:00:00Z",
                      "count": 1,
                      "with_price": 1,
                      "read_this_cycle": 1,
                      "rates": [
                        {
                          "base": "USD",
                          "quote": "LYD",
                          "currency": "USD",
                          "market": "نقدي",
                          "description": "دولار أمريكي",
                          "rate": "10.0000",
                          "per_lyd": "0.1000",
                          "observed_at": "2026-01-01T10:00:00Z",
                          "market_type": "cash",
                          "age_seconds": 1,
                          "fresh": true,
                          "rate_basis": "single_unit",
                          "unit_size": 1,
                          "source_price_at": "2026-01-01T09:45:00Z"
                        }
                      ],
                      "fresh_count": 1,
                      "max_age_seconds": 120,
                      "freshness_status": "fresh",
                      "stale": false,
                      "collection_method": "source_list",
                      "collection_origin": "hosted_worker"
                    }
                  },
                  "both": {
                    "summary": "Both feeds (market_type=all)",
                    "value": {
                      "markets": {
                        "parallel": {
                          "source": "Mushir Tripoli",
                          "mode": "mushir_tripoli_direct",
                          "last_sync_at": "2026-01-01T10:00:00Z",
                          "count": 1,
                          "with_price": 1,
                          "read_this_cycle": 1,
                          "rates": [
                            {
                              "base": "USD",
                              "quote": "LYD",
                              "currency": "USD",
                              "market": "نقدي",
                              "description": "دولار أمريكي",
                              "rate": "10.0000",
                              "per_lyd": "0.1000",
                              "observed_at": "2026-01-01T10:00:00Z",
                              "market_type": "cash",
                              "age_seconds": 1,
                              "fresh": true,
                              "rate_basis": "single_unit",
                              "unit_size": 1,
                              "source_price_at": "2026-01-01T09:45:00Z"
                            }
                          ],
                          "fresh_count": 1,
                          "max_age_seconds": 120,
                          "freshness_status": "fresh",
                          "stale": false,
                          "collection_method": "source_list",
                          "collection_origin": "hosted_worker"
                        },
                        "official": {
                          "source": "Central Bank of Libya",
                          "source_url": "https://cbl.gov.ly/currency-exchange-rates/",
                          "last_sync_at": "2026-11-29T10:00:00Z",
                          "effective_date": "2026-11-29",
                          "stale": false,
                          "count": 1,
                          "rates": [
                            {
                              "currency": "JPY",
                              "base": "JPY",
                              "quote": "LYD",
                              "description": "الين الياباني",
                              "market_type": "official",
                              "effective_date": "2026-11-29",
                              "unit": "100 ين",
                              "unit_size": 100,
                              "rate": "0.0406",
                              "buy": "0.0405",
                              "sell": "0.0407",
                              "inverse_rate": "24.6305",
                              "per_lyd": "24.6305",
                              "published": {
                                "average": "4.0600",
                                "buy": "4.0500",
                                "sell": "4.0700"
                              }
                            }
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing bearer key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "api_key_required"
                }
              }
            }
          },
          "403": {
            "description": "Invalid key, disabled account or expired subscription.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid_or_disabled_key"
                }
              }
            }
          },
          "503": {
            "description": "A requested feed is missing or invalid, the service is unavailable, or the strict parallel freshness requirement failed. Unsuccessful requests do not count toward usage.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/Error"
                        },
                        {
                          "not": {
                            "properties": {
                              "error": {
                                "const": "stale_parallel_feed"
                              }
                            }
                          }
                        }
                      ]
                    },
                    {
                      "$ref": "#/components/schemas/StaleParallelFeed"
                    }
                  ]
                },
                "examples": {
                  "waiting": {
                    "value": {
                      "error": "waiting_for_feed"
                    }
                  },
                  "partial": {
                    "value": {
                      "error": "stale_parallel_feed",
                      "last_sync_at": "2026-01-01T10:00:00Z",
                      "freshness_status": "partial",
                      "fresh_count": 3,
                      "count": 4,
                      "max_age_seconds": 120
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Unsupported market type or invalid max_age_seconds."
          }
        },
        "parameters": [
          {
            "in": "query",
            "name": "market_type",
            "schema": {
              "type": "string",
              "enum": [
                "cash",
                "transfer",
                "bank_cheque",
                "forex",
                "crypto",
                "all"
              ]
            },
            "description": "Select one parallel-market segment, or use all for a response containing both complete feeds. Omit to return the complete parallel-market feed."
          },
          {
            "in": "query",
            "name": "max_age_seconds",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 86400
            },
            "description": "Optional whole seconds, 1 through 86400. When supplied, empty results, missing prices, an old collection or any selected parallel quote without a valid observation within this age cause HTTP 503. Omit to allow retained prices with freshness indicators. Supply the parameter at most once."
          }
        ]
      }
    },
    "/api/central-bank": {
      "get": {
        "tags": [
          "Market data"
        ],
        "operationId": "getCentralBankRates",
        "summary": "Get official Central Bank of Libya rates",
        "description": "Returns the latest collected [official bulletin](https://cbl.gov.ly/currency-exchange-rates/). `effective_date` identifies the quotation date. `last_sync_at` identifies when the collector checked it. The bank can keep the same rates across several checks or non-publication days.\n\n**Published units.** The bank quotes some currencies in lots of 10 or 100. `published` preserves the buying, selling and average prices for the full lot. `rate`, `buy` and `sell` express LYD per single foreign unit. For example, on 29 November 2026 the published average for 100 Japanese yen was 4.0600 LYD. One yen cost 0.0406 LYD at that average, and one dinar bought about 24.6305 yen.\n\n**Conversion.** Multiply the LYD amount by `per_lyd` for an indicative conversion at the official average. For a specific side, use `buy` or `sell` according to your transaction and its stated units. If `currency` is null, use the published description to identify the row.",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "in": "query",
            "name": "market_type",
            "schema": {
              "type": "string",
              "enum": [
                "official"
              ]
            },
            "description": "Optional explicit selection of the official market."
          }
        ],
        "responses": {
          "200": {
            "description": "Latest stored official bulletin available to the subscription.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CentralBankRates"
                },
                "example": {
                  "source": "Central Bank of Libya",
                  "source_url": "https://cbl.gov.ly/currency-exchange-rates/",
                  "last_sync_at": "2026-11-29T10:00:00Z",
                  "effective_date": "2026-11-29",
                  "stale": false,
                  "count": 1,
                  "rates": [
                    {
                      "currency": "JPY",
                      "base": "JPY",
                      "quote": "LYD",
                      "description": "الين الياباني",
                      "market_type": "official",
                      "effective_date": "2026-11-29",
                      "unit": "100 ين",
                      "unit_size": 100,
                      "rate": "0.0406",
                      "buy": "0.0405",
                      "sell": "0.0407",
                      "inverse_rate": "24.6305",
                      "per_lyd": "24.6305",
                      "published": {
                        "average": "4.0600",
                        "buy": "4.0500",
                        "sell": "4.0700"
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Missing bearer key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "api_key_required"
                }
              }
            }
          },
          "403": {
            "description": "Invalid key, disabled account or expired subscription.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid_or_disabled_key"
                }
              }
            }
          },
          "503": {
            "description": "Snapshot or service temporarily unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "waiting_for_feed"
                }
              }
            }
          },
          "400": {
            "description": "Unsupported market type or a parallel-only max_age_seconds parameter."
          }
        }
      }
    },
    "/account/register": {
      "post": {
        "tags": [
          "Accounts"
        ],
        "operationId": "register",
        "summary": "Request an account",
        "description": "Create a dashboard account. Sign in on the website to submit a transfer receipt and request a subscription. A repeat registration returns the same acknowledgment.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Credentials"
              },
              "example": {
                "email": "developer@example.com",
                "password": "EXAMPLE-password-only"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Request an account",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "description": "message"
                    }
                  },
                  "required": [
                    "message"
                  ]
                },
                "example": {
                  "message": "Registration received. Sign in to submit your subscription payment."
                }
              }
            }
          },
          "400": {
            "description": "Invalid credentials format, JSON or request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid_email_or_password_length"
                }
              }
            }
          },
          "413": {
            "description": "Request body too large.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid_request"
                }
              }
            }
          },
          "429": {
            "description": "Account request rate limit reached. Try later.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "try_again_later"
                }
              }
            }
          },
          "503": {
            "description": "Temporary service error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "service_unavailable"
                }
              }
            }
          }
        }
      }
    },
    "/account/login": {
      "post": {
        "tags": [
          "Accounts"
        ],
        "operationId": "login",
        "summary": "Check subscription",
        "description": "Returns the current subscription for an approved account.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Credentials"
              },
              "example": {
                "email": "developer@example.com",
                "password": "EXAMPLE-password-only"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Active subscription",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string"
                    },
                    "requests": {
                      "const": "unlimited"
                    },
                    "monthly_price_lyd": {
                      "const": 50
                    },
                    "expires_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                },
                "example": {
                  "status": "active",
                  "requests": "unlimited",
                  "monthly_price_lyd": 50,
                  "expires_at": "2027-01-01T10:00:00Z"
                }
              }
            }
          },
          "400": {
            "description": "Invalid credentials format, JSON or request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid_email_or_password_length"
                }
              }
            }
          },
          "413": {
            "description": "Request body too large.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid_request"
                }
              }
            }
          },
          "429": {
            "description": "Account request rate limit reached. Try later.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "try_again_later"
                }
              }
            }
          },
          "503": {
            "description": "Temporary service error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "service_unavailable"
                }
              }
            }
          },
          "401": {
            "description": "Incorrect credentials.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid_credentials"
                }
              }
            }
          },
          "403": {
            "description": "Account pending approval or disabled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "awaiting_owner_approval"
                }
              }
            }
          }
        }
      }
    },
    "/account/key": {
      "post": {
        "tags": [
          "Accounts"
        ],
        "operationId": "key",
        "summary": "Issue or replace your key",
        "description": "Immediately invalidates any previous key. Save the returned key securely on your server.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Credentials"
              },
              "example": {
                "email": "developer@example.com",
                "password": "EXAMPLE-password-only"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Issue or replace your key",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "api_key": {
                      "type": "string",
                      "description": "api_key"
                    }
                  },
                  "required": [
                    "api_key"
                  ]
                },
                "example": {
                  "api_key": "lyd_EXAMPLE_ONLY"
                }
              }
            }
          },
          "400": {
            "description": "Invalid credentials format, JSON or request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid_email_or_password_length"
                }
              }
            }
          },
          "413": {
            "description": "Request body too large.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid_request"
                }
              }
            }
          },
          "429": {
            "description": "Account request rate limit reached. Try later.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "try_again_later"
                }
              }
            }
          },
          "503": {
            "description": "Temporary service error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "service_unavailable"
                }
              }
            }
          },
          "401": {
            "description": "Incorrect credentials.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid_credentials"
                }
              }
            }
          },
          "403": {
            "description": "Account pending approval or disabled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "awaiting_owner_approval"
                }
              }
            }
          }
        }
      }
    },
    "/coverage": {
      "get": {
        "tags": ["Market data"],
        "operationId": "getInstrumentCoverage",
        "summary": "List instruments by source and market",
        "description": "Public, unmetered catalog from the latest stored feeds. Each entry identifies one instrument. The same currency can appear in several markets, at different banks or for different transfer destinations. Price fields are available through the subscription feeds. Successful responses may be cached for 60 seconds.",
        "security": [],
        "responses": {
          "200": {
            "description": "At least one catalog is available. An unavailable source is null. Empty groups are empty arrays.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["parallel", "official"],
                  "additionalProperties": false,
                  "not": {"const": {"parallel": null, "official": null}},
                  "properties": {
                    "parallel": {
                      "$ref": "#/components/schemas/CoverageFeed",
                      "description": "Mushir Tripoli groups: cash, transfer, bank_cheque, forex, crypto and other."
                    },
                    "official": {
                      "$ref": "#/components/schemas/CoverageFeed",
                      "description": "Central Bank of Libya instruments are in the official group."
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Both catalogs are unavailable, or the service could not read its storage.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {"const": {"parallel": null, "official": null}},
                    {"$ref": "#/components/schemas/Error"}
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/health": {
      "get": {
        "tags": [
          "Market data"
        ],
        "operationId": "getFeedHealth",
        "summary": "Check feed freshness and market coverage",
        "description": "Public read-only health check. Its response contains feed timestamps, counts and the recorded collection_origin of the latest parallel snapshot. HTTP 200 requires a successful official-source check within 120 seconds and fresh parallel coverage during market hours. Outside market hours, a priced parallel snapshot less than 24 hours old may report closed. HTTP 503 indicates a partial, stale, or unavailable feed, or an underlying service failure. Official collection health measures the last successful fetch. older_bulletin separately reports whether the effective date precedes today in Tripoli. Unavailable feeds expose only their status. Health checks are unmetered and can be cached for 15 seconds.",
        "security": [],
        "responses": {
          "200": {
            "description": "Both collectors meet the freshness criteria.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FeedHealth"
                }
              }
            }
          },
          "503": {
            "description": "Degraded data or unavailable service.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/FeedHealth"
                    },
                    {
                      "$ref": "#/components/schemas/Error"
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "Key issued to an approved account."
      }
    },
    "schemas": {
      "CoverageFeed": {
        "type": ["object", "null"],
        "required": ["count", "groups"],
        "additionalProperties": false,
        "properties": {
          "count": {"type": "integer", "minimum": 1, "description": "Number of instruments across this source's groups."},
          "groups": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "object",
                "required": ["description", "currency", "base", "quote"],
                "additionalProperties": false,
                "properties": {
                  "description": {"type": "string", "description": "Source label for the instrument."},
                  "currency": {"type": ["string", "null"], "description": "Foreign currency code when identified."},
                  "base": {"type": ["string", "null"], "description": "Base currency code when identified."},
                  "quote": {"type": ["string", "null"], "description": "Quote currency code when identified."}
                }
              }
            }
          }
        }
      },
      "Credentials": {
        "type": "object",
        "properties": {
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 254
          },
          "password": {
            "type": "string",
            "format": "password",
            "minLength": 12,
            "maxLength": 256,
            "writeOnly": true
          }
        },
        "required": [
          "email",
          "password"
        ]
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Machine-readable error code."
          }
        },
        "required": [
          "error"
        ]
      },
      "Quote": {
        "type": "object",
        "properties": {
          "base": {
            "type": "string",
            "description": "First currency in the original pair."
          },
          "quote": {
            "type": "string",
            "description": "Currency used to price one base unit."
          },
          "currency": {
            "type": "string",
            "description": "Non-LYD currency."
          },
          "market": {
            "type": "string",
            "description": "Market segment, for example نقدي (cash)."
          },
          "description": {
            "type": "string",
            "description": "Instrument label; distinguishes banks and transfer routes."
          },
          "rate": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[0-9]+\\.[0-9]{4}$",
            "description": "Quote per base unit for single-unit prices. Rows marked source_lot preserve the published lot quotation."
          },
          "per_lyd": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[0-9]+\\.[0-9]{4}$",
            "description": "Foreign currency for one LYD. Null for a missing price or a forex quotation with an unverified lot size."
          },
          "observed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "When the collector read this individual instrument."
          },
          "market_type": {
            "type": "string",
            "description": "Normalized instrument category. Bank and destination details remain in description."
          },
          "source_price_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Provider price-update timestamp when supplied. Separate from the time our collector observed the value."
          },
          "age_seconds": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "description": "Age of the source observation, rounded up to whole seconds at delivery. Null when the observation is missing, invalid or in the future."
          },
          "fresh": {
            "type": "boolean",
            "description": "A priced observation within the parallel age window."
          },
          "unit_size": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "description": "Number of base units in the published quotation. Null for an unspecified forex lot. Historical single-unit chart rows may omit this field."
          },
          "rate_basis": {
            "type": "string",
            "enum": [
              "single_unit",
              "source_lot"
            ],
            "description": "single_unit for an instrument quoted per unit, source_lot for a provider lot with unverified size. Historical single-unit chart rows may omit this field."
          }
        },
        "required": [
          "base",
          "quote",
          "currency",
          "market",
          "description",
          "rate",
          "per_lyd",
          "observed_at",
          "market_type",
          "age_seconds",
          "fresh"
        ]
      },
      "Rates": {
        "type": "object",
        "properties": {
          "source": {
            "type": "string",
            "description": "Primary feed label."
          },
          "mode": {
            "type": "string",
            "description": "Collection mode.",
            "enum": [
              "mushir_tripoli_direct",
              "mushir_tripoli_screen"
            ]
          },
          "last_sync_at": {
            "type": "string",
            "format": "date-time",
            "description": "When the collector completed the snapshot."
          },
          "count": {
            "type": "integer",
            "minimum": 0,
            "description": "Total instruments."
          },
          "with_price": {
            "type": "integer",
            "minimum": 0,
            "description": "Instruments with a usable price, including retained readings."
          },
          "read_this_cycle": {
            "type": "integer",
            "minimum": 0,
            "description": "Instruments read across the collection cycle, before filtering."
          },
          "rates": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Quote"
            }
          },
          "fresh_count": {
            "type": "integer",
            "minimum": 0,
            "description": "Selected rows with a priced observation within the age window."
          },
          "max_age_seconds": {
            "type": "integer",
            "minimum": 1,
            "maximum": 86400,
            "description": "Age window applied to parallel observations. Defaults to 120."
          },
          "freshness_status": {
            "type": "string",
            "enum": [
              "fresh",
              "partial",
              "stale",
              "unavailable"
            ],
            "description": "fresh: recent collection and every selected row fresh. partial: recent collection and some rows fresh. stale: old collection or zero recent observations among priced rows. unavailable: no selected rows or no prices."
          },
          "stale": {
            "type": "boolean",
            "description": "True when the selected parallel snapshot is partial, stale or unavailable."
          },
          "collection_method": {
            "type": "string",
            "enum": [
              "source_list",
              "chart"
            ],
            "description": "Whether this snapshot was read from the source market list or its chart."
          },
          "collection_origin": {
            "$ref": "#/components/schemas/CollectionOrigin"
          }
        },
        "required": [
          "source",
          "mode",
          "last_sync_at",
          "count",
          "with_price",
          "rates",
          "fresh_count",
          "max_age_seconds",
          "freshness_status",
          "stale",
          "collection_method",
          "collection_origin"
        ]
      },
      "OfficialPublished": {
        "type": "object",
        "properties": {
          "average": {
            "type": "string",
            "pattern": "^[0-9]+\\.[0-9]{4}$",
            "description": "Official average in LYD for the entire published unit."
          },
          "buy": {
            "type": "string",
            "pattern": "^[0-9]+\\.[0-9]{4}$",
            "description": "Official buying price in LYD for the entire published unit."
          },
          "sell": {
            "type": "string",
            "pattern": "^[0-9]+\\.[0-9]{4}$",
            "description": "Official selling price in LYD for the entire published unit."
          }
        },
        "required": [
          "average",
          "buy",
          "sell"
        ]
      },
      "OfficialQuote": {
        "type": "object",
        "properties": {
          "currency": {
            "type": [
              "string",
              "null"
            ],
            "description": "Currency code when the published description identifies it unambiguously."
          },
          "base": {
            "type": [
              "string",
              "null"
            ],
            "description": "Currency code when the published description identifies it unambiguously."
          },
          "quote": {
            "type": "string",
            "const": "LYD"
          },
          "description": {
            "type": "string",
            "description": "Currency name as printed in the Arabic bulletin."
          },
          "market_type": {
            "type": "string",
            "const": "official"
          },
          "effective_date": {
            "type": "string",
            "format": "date",
            "description": "Effective date printed on the official bulletin."
          },
          "unit": {
            "type": "string",
            "description": "Unit or lot label as printed in Arabic."
          },
          "unit_size": {
            "type": "integer",
            "minimum": 1,
            "description": "Number of foreign units in one published lot."
          },
          "rate": {
            "type": "string",
            "pattern": "^[0-9]+\\.[0-9]{4}$",
            "description": "Official average in LYD per ONE foreign unit."
          },
          "buy": {
            "type": "string",
            "pattern": "^[0-9]+\\.[0-9]{4}$",
            "description": "Official buying price in LYD per ONE foreign unit."
          },
          "sell": {
            "type": "string",
            "pattern": "^[0-9]+\\.[0-9]{4}$",
            "description": "Official selling price in LYD per ONE foreign unit."
          },
          "inverse_rate": {
            "type": "string",
            "pattern": "^[0-9]+\\.[0-9]{4}$",
            "description": "Foreign units for one LYD at the official average."
          },
          "per_lyd": {
            "type": "string",
            "pattern": "^[0-9]+\\.[0-9]{4}$",
            "description": "Alias for inverse_rate."
          },
          "published": {
            "$ref": "#/components/schemas/OfficialPublished"
          }
        },
        "required": [
          "currency",
          "base",
          "quote",
          "description",
          "market_type",
          "effective_date",
          "unit",
          "unit_size",
          "rate",
          "buy",
          "sell",
          "inverse_rate",
          "per_lyd",
          "published"
        ]
      },
      "CentralBankRates": {
        "type": "object",
        "properties": {
          "source": {
            "type": "string",
            "const": "Central Bank of Libya"
          },
          "source_url": {
            "type": "string",
            "format": "uri",
            "description": "Official publication URL."
          },
          "last_sync_at": {
            "type": "string",
            "format": "date-time",
            "description": "Time of the successful source check, in UTC."
          },
          "effective_date": {
            "type": "string",
            "format": "date",
            "description": "Effective date printed on the official bulletin."
          },
          "stale": {
            "type": "boolean",
            "description": "True when the effective date is earlier than today in Tripoli, including weekends."
          },
          "count": {
            "type": "integer",
            "minimum": 0,
            "description": "Number of official currencies returned."
          },
          "rates": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OfficialQuote"
            }
          }
        },
        "required": [
          "source",
          "source_url",
          "last_sync_at",
          "effective_date",
          "stale",
          "count",
          "rates"
        ]
      },
      "BothMarkets": {
        "type": "object",
        "required": [
          "markets"
        ],
        "properties": {
          "markets": {
            "type": "object",
            "required": [
              "parallel",
              "official"
            ],
            "properties": {
              "parallel": {
                "$ref": "#/components/schemas/Rates"
              },
              "official": {
                "$ref": "#/components/schemas/CentralBankRates"
              }
            }
          }
        }
      },
      "StaleParallelFeed": {
        "type": "object",
        "properties": {
          "error": {
            "const": "stale_parallel_feed"
          },
          "last_sync_at": {
            "type": "string",
            "format": "date-time"
          },
          "freshness_status": {
            "type": "string",
            "enum": [
              "fresh",
              "partial",
              "stale",
              "unavailable"
            ]
          },
          "fresh_count": {
            "type": "integer",
            "minimum": 0
          },
          "count": {
            "type": "integer",
            "minimum": 0
          },
          "max_age_seconds": {
            "type": "integer",
            "minimum": 1,
            "maximum": 86400
          }
        },
        "required": [
          "error",
          "last_sync_at",
          "freshness_status",
          "fresh_count",
          "count",
          "max_age_seconds"
        ]
      },
      "FeedHealth": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "ok",
              "degraded"
            ]
          },
          "checked_at": {
            "type": "string",
            "format": "date-time"
          },
          "max_age_seconds": {
            "const": 120
          },
          "feeds": {
            "type": "object",
            "properties": {
              "parallel": {
                "type": "object",
                "properties": {
                  "status": {
                    "type": "string",
                    "enum": [
                      "fresh",
                      "partial",
                      "stale",
                      "unavailable",
                      "closed"
                    ]
                  },
                  "last_sync_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "count": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "fresh_count": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "collection_origin": {
                    "$ref": "#/components/schemas/CollectionOrigin"
                  }
                },
                "required": [
                  "status"
                ]
              },
              "official": {
                "type": "object",
                "properties": {
                  "status": {
                    "type": "string",
                    "enum": [
                      "fresh",
                      "stale",
                      "unavailable"
                    ]
                  },
                  "last_sync_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "effective_date": {
                    "type": "string",
                    "format": "date"
                  },
                  "older_bulletin": {
                    "type": "boolean"
                  },
                  "count": {
                    "type": "integer",
                    "minimum": 0
                  }
                },
                "required": [
                  "status"
                ]
              }
            },
            "required": [
              "parallel",
              "official"
            ]
          }
        },
        "required": [
          "status",
          "checked_at",
          "max_age_seconds",
          "feeds"
        ]
      },
      "CollectionOrigin": {
        "type": "string",
        "enum": [
          "hosted_worker",
          "external_publisher",
          "unknown"
        ],
        "description": "Server-recorded writer of the stored parallel snapshot. hosted_worker means the scheduled Worker itself fetched the source. external_publisher means a collector uploaded it. Older unmarked records are unknown."
      }
    }
  }
}
