{
  "openapi": "3.1.0",
  "info": {
    "title": "ListingQuery API",
    "version": "1.3.0"
  },
  "servers": [
    {
      "url": "/",
      "description": "This ListingQuery instance"
    }
  ],
  "security": [],
  "tags": [
    {
      "name": "Listings"
    },
    {
      "name": "Health"
    }
  ],
  "paths": {
    "/listings": {
      "get": {
        "operationId": "listListings",
        "tags": [
          "Listings"
        ],
        "summary": "Get listings",
        "description": "Returns all matches, including deleted listings.",
        "parameters": [
          {
            "$ref": "#/components/parameters/MarketHashName"
          }
        ],
        "responses": {
          "200": {
            "description": "All matching listings.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListingResults"
                },
                "examples": {
                  "key": {
                    "summary": "Mann Co. Supply Crate Key",
                    "value": {
                      "listings": [
                        {
                          "id": 11910,
                          "side": "sell",
                          "steam64": "76561198274895819",
                          "listing_id": "2508245",
                          "asset_id": "17697420422",
                          "listing": {
                            "hat_id": 4,
                            "hat": "Z^Mann_Co._Supply_Crate_Key;TMC;Unique",
                            "image_url": "https://crit.tf/optimized-images/2",
                            "created_at": 1793191013,
                            "updated_at": 1793191013,
                            "amount": 1,
                            "price": {
                              "keys": 0,
                              "half_scrap": 1162
                            }
                          },
                          "deleted": true,
                          "first_seen_at": 1793189963,
                          "last_seen_at": 1793191070,
                          "last_event": "listing-deleted",
                          "event_id": "GFS2JUMOWPFG7GTP2OJCKPC2NM:2885899"
                        },
                        {
                          "id": 11911,
                          "side": "sell",
                          "steam64": "76561198274895819",
                          "listing_id": "2508246",
                          "asset_id": "17697438793",
                          "listing": {
                            "hat_id": 4,
                            "hat": "Z^Mann_Co._Supply_Crate_Key;TMC;Unique",
                            "image_url": "https://crit.tf/optimized-images/2",
                            "created_at": 1793190873,
                            "updated_at": 1793190873,
                            "amount": 1,
                            "price": {
                              "keys": 0,
                              "half_scrap": 1162
                            }
                          },
                          "deleted": true,
                          "first_seen_at": 1793189963,
                          "last_seen_at": 1793190902,
                          "last_event": "listing-deleted",
                          "event_id": "GFS2JUMOWPFG7GTP2OJCKPC2NM:2873079"
                        }
                      ]
                    }
                  },
                  "dellDynamic": {
                    "summary": "Dell Dynamic",
                    "value": {
                      "listings": [
                        {
                          "id": 32,
                          "side": "sell",
                          "steam64": "76561199118229984",
                          "listing_id": "1878046",
                          "asset_id": "17724095028",
                          "listing": {
                            "hat_id": 19175,
                            "hat": "Z^Dell_Dynamic;TMC;Unique",
                            "image_url": "https://crit.tf/optimized-images/5793",
                            "created_at": 1793045763,
                            "updated_at": 1793189425,
                            "amount": 1,
                            "price": {
                              "keys": 0,
                              "half_scrap": 172
                            }
                          },
                          "deleted": false,
                          "first_seen_at": 1793189425,
                          "last_seen_at": 1793189425,
                          "last_event": "listing-updated",
                          "event_id": "GFS2JUMOWPFG7GTP2OJCKPC2NM:2784486"
                        }
                      ]
                    }
                  },
                  "empty": {
                    "summary": "No matches",
                    "value": {
                      "listings": []
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidQuery"
          },
          "500": {
            "$ref": "#/components/responses/ReadFailure"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/status": {
      "get": {
        "operationId": "getStreamStatus",
        "tags": [
          "Health"
        ],
        "summary": "Stream status",
        "responses": {
          "200": {
            "description": "Stream status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StreamStatus"
                },
                "example": {
                  "cursor": "GFS2JUMOWPFG7GTP2OJCKPC2NM:2922533",
                  "resync_count": 1,
                  "last_resync_at": 1793189424,
                  "last_message_at": 1793191755,
                  "connected": true
                }
              }
            }
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/healthz": {
      "get": {
        "operationId": "getHealth",
        "tags": [
          "Health"
        ],
        "summary": "Database health",
        "responses": {
          "200": {
            "$ref": "#/components/responses/Healthy"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/readyz": {
      "get": {
        "operationId": "getReadiness",
        "tags": [
          "Health"
        ],
        "summary": "Stream readiness",
        "responses": {
          "200": {
            "$ref": "#/components/responses/Healthy"
          },
          "503": {
            "description": "Upstream disconnected.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "upstream disconnected; stored listings remain queryable"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "parameters": {
      "MarketHashName": {
        "name": "market_hash_name",
        "in": "query",
        "schema": {
          "type": "string",
          "minLength": 1,
          "maxLength": 4096
        },
        "required": true,
        "examples": {
          "key": {
            "summary": "Mann Co. Supply Crate Key",
            "value": "Mann Co. Supply Crate Key"
          },
          "dellDynamic": {
            "summary": "Dell Dynamic",
            "value": "Dell Dynamic"
          }
        }
      }
    },
    "schemas": {
      "DecimalID": {
        "type": "string",
        "pattern": "^[1-9][0-9]{0,19}$",
        "description": "Unsigned 64-bit decimal string."
      },
      "Price": {
        "type": "object",
        "description": "Keys and half-scrap.",
        "properties": {
          "keys": {
            "type": "integer",
            "minimum": 0,
            "maximum": 65535
          },
          "half_scrap": {
            "type": "integer",
            "minimum": 0,
            "maximum": 65535,
            "description": "Metal in half-scrap units."
          }
        },
        "required": [
          "keys",
          "half_scrap"
        ],
        "additionalProperties": true
      },
      "Snapshot": {
        "type": "object",
        "description": "Original crit.tf snapshot.",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "description": "Upstream buy ID."
          },
          "hat_id": {
            "type": "integer",
            "format": "int64",
            "description": "crit.tf item ID."
          },
          "hat": {
            "type": "string",
            "description": "Hat Version Z."
          },
          "image_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "amount": {
            "type": "integer",
            "description": "Quantity."
          },
          "ignored_fields": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Buy fields allowed to vary."
          },
          "price": {
            "$ref": "#/components/schemas/Price"
          },
          "created_at": {
            "anyOf": [
              {
                "type": "integer",
                "format": "int64"
              },
              {
                "type": "string",
                "format": "date-time"
              }
            ],
            "description": "Unix seconds or ISO 8601."
          },
          "updated_at": {
            "anyOf": [
              {
                "type": "integer",
                "format": "int64"
              },
              {
                "type": "string",
                "format": "date-time"
              }
            ],
            "description": "Unix seconds or ISO 8601."
          }
        },
        "additionalProperties": true,
        "examples": [
          {
            "hat_id": 4,
            "hat": "Z^Mann_Co._Supply_Crate_Key;TMC;Unique",
            "image_url": "https://crit.tf/optimized-images/2",
            "created_at": 1793191013,
            "updated_at": 1793191013,
            "amount": 1,
            "price": {
              "keys": 0,
              "half_scrap": 1162
            }
          },
          {
            "hat_id": 19175,
            "hat": "Z^Dell_Dynamic;TMC;Unique",
            "image_url": "https://crit.tf/optimized-images/5793",
            "created_at": 1793045763,
            "updated_at": 1793189425,
            "amount": 1,
            "price": {
              "keys": 0,
              "half_scrap": 172
            }
          }
        ]
      },
      "Listing": {
        "type": "object",
        "required": [
          "id",
          "side",
          "steam64",
          "listing",
          "deleted",
          "first_seen_at",
          "last_seen_at",
          "last_event",
          "event_id"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "Local row ID."
          },
          "side": {
            "type": "string",
            "enum": [
              "buy",
              "sell"
            ]
          },
          "steam64": {
            "allOf": [
              {
                "$ref": "#/components/schemas/DecimalID"
              }
            ],
            "minLength": 17,
            "maxLength": 17
          },
          "listing_id": {
            "$ref": "#/components/schemas/DecimalID",
            "description": "Upstream listing ID."
          },
          "asset_id": {
            "$ref": "#/components/schemas/DecimalID",
            "description": "Sell asset ID."
          },
          "listing": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/Snapshot"
              },
              {
                "type": "null"
              }
            ],
            "description": "Last snapshot; null if only a deletion was observed."
          },
          "deleted": {
            "type": "boolean",
            "description": "Last event was a deletion."
          },
          "first_seen_at": {
            "type": "integer",
            "format": "int64",
            "description": "Unix seconds."
          },
          "last_seen_at": {
            "type": "integer",
            "format": "int64",
            "description": "Unix seconds."
          },
          "last_event": {
            "type": "string",
            "enum": [
              "listing-created",
              "listing-updated",
              "listing-deleted"
            ]
          },
          "event_id": {
            "type": "string",
            "description": "Upstream SSE cursor."
          }
        },
        "examples": [
          {
            "id": 11910,
            "side": "sell",
            "steam64": "76561198274895819",
            "listing_id": "2508245",
            "asset_id": "17697420422",
            "listing": {
              "hat_id": 4,
              "hat": "Z^Mann_Co._Supply_Crate_Key;TMC;Unique",
              "image_url": "https://crit.tf/optimized-images/2",
              "created_at": 1793191013,
              "updated_at": 1793191013,
              "amount": 1,
              "price": {
                "keys": 0,
                "half_scrap": 1162
              }
            },
            "deleted": true,
            "first_seen_at": 1793189963,
            "last_seen_at": 1793191070,
            "last_event": "listing-deleted",
            "event_id": "GFS2JUMOWPFG7GTP2OJCKPC2NM:2885899"
          },
          {
            "id": 32,
            "side": "sell",
            "steam64": "76561199118229984",
            "listing_id": "1878046",
            "asset_id": "17724095028",
            "listing": {
              "hat_id": 19175,
              "hat": "Z^Dell_Dynamic;TMC;Unique",
              "image_url": "https://crit.tf/optimized-images/5793",
              "created_at": 1793045763,
              "updated_at": 1793189425,
              "amount": 1,
              "price": {
                "keys": 0,
                "half_scrap": 172
              }
            },
            "deleted": false,
            "first_seen_at": 1793189425,
            "last_seen_at": 1793189425,
            "last_event": "listing-updated",
            "event_id": "GFS2JUMOWPFG7GTP2OJCKPC2NM:2784486"
          }
        ]
      },
      "StreamStatus": {
        "type": "object",
        "required": [
          "cursor",
          "resync_count",
          "last_resync_at",
          "last_message_at",
          "connected"
        ],
        "properties": {
          "cursor": {
            "type": "string",
            "description": "Last committed SSE cursor."
          },
          "resync_count": {
            "type": "integer",
            "format": "int64",
            "minimum": 0,
            "description": "Replay gaps, including the initial connection."
          },
          "last_resync_at": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64",
            "description": "Last replay gap, Unix seconds."
          },
          "last_message_at": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64",
            "description": "Last stored event, Unix seconds."
          },
          "connected": {
            "type": "boolean"
          }
        }
      },
      "Health": {
        "type": "object",
        "required": [
          "status"
        ],
        "properties": {
          "status": {
            "type": "string",
            "const": "ok"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          }
        }
      },
      "ListingResults": {
        "type": "object",
        "required": [
          "listings"
        ],
        "properties": {
          "listings": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Listing"
            }
          }
        }
      }
    },
    "responses": {
      "Healthy": {
        "description": "OK.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Health"
            },
            "example": {
              "status": "ok"
            }
          }
        }
      },
      "InvalidQuery": {
        "description": "Invalid market hash name or unsupported parameter.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "supply one nonempty market_hash_name"
            }
          }
        }
      },
      "ReadFailure": {
        "description": "Stored row could not be read.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "could not read listing"
            }
          }
        }
      },
      "Unavailable": {
        "description": "Database unavailable.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "database unavailable"
            }
          }
        }
      }
    }
  }
}
