# 市場統計を取得する

Source: https://won.dev/ja/docs/trade/stats-query

`POST https://api.won.dev/v1/trade/stats/query`

ある商品または1社について、市場の規模、その分布、動きを示します。合計値、輸出入それぞれの側の国、月ごとの推移です。答えの中では2種類の数字を分けています。`records` は当社の通関記録の件数を数え、申告された金額を合計したものです。傾向や1社の発注サイクルを見るのに向いていますが、市場全体の数字ではありません。国によってカバー範囲が違い、米国の船荷証券には金額がないためです。`official` は統計機関が公表する数字で、市場規模や国別シェアにはこちらを使ってください。`hs_code` を指定し、輸入国か輸出国を指定したときに返り、200以上の国と地域をカバーします。自国の統計がある国はその数字を、ない国は取引相手国がその国との貿易について報告した数字を使い、`mirror` と示します。米国、EU、英国では当月から約2か月遅れ、ほかの国ではたいていもっと遅れます。`coverage.recorded_value_share` で、記録された金額が公式の金額のどれだけにあたるかがわかります。結果のある照会は $0.10、`official` だけを求めたかそれしか見つからなかった場合は $0.02 です。結果がなければ無料です。`partial` と示された月はまだデータがそろっていない途中の月なので、減少と読み違えないでください。期間は最大36か月です。

- **課金：** `trade_stats` $0.10：結果のある市場統計の照会1回。`trade_official_stats` $0.02：公式統計だけ、または金額のない通関件数だけで答えた市場統計の照会1回。
- **モード：** `merge` ([各モードの意味](/ja/docs/trade#modes))

テストキー（`won_test_...`）でこのリクエストを送ると、同じサンプル企業が無料で返ります。

## パラメーター [#parameters]

パラメーターはJSONのリクエストボディで渡します。`POST` リクエストでは `Idempotency-Key` ヘッダーも使えます。[冪等性](/ja/docs/idempotency)を参照してください。

| パラメーター | 型 | 必須 | 説明（APIの原文） |
| --- | --- | --- | --- |
| `hs_code` | string | いいえ | HS code, digits only. 6 to 10 digits for shipment records. Official statistics alone (`basis: ["official"]`) also take a 2-digit chapter or a 4-digit heading, such as `9401`. |
| `product` | string | いいえ | Product keywords in English, such as `office chair`. A fuzzy match on the goods description. Use it when you do not know the HS code; an `hs_code` is more precise. |
| `company` | string | いいえ | Only the records of this company: its `co_` ID, or its name. Shows what one buyer or seller trades over time. Needs `role`. An ID with no `hs_code`, `product` or country, over the last 12 months (the default range), counts the company itself by its ID. Otherwise it is matched by its name as it stands in the records, so companies that share the name count together. `records.company_match` says which. Official statistics do not exist by company. |
| `role` | `importer` \| `exporter` | いいえ | With `company`: count what it imports, or what it exports. |
| `importer_country` | string | いいえ | Country the goods are imported into: an ISO code such as `US`, or an English name such as `United States`. `EU` is the European Union as a whole, in official statistics only. |
| `exporter_country` | string | いいえ | Country the goods are exported from: an ISO code such as `VN`, or an English name such as `Vietnam`. `EU` is the European Union as a whole, in official statistics only. |
| `since` | string | いいえ | First day of the date range, `YYYY-MM-DD`. Default: the first day of the month 12 months before `until`. |
| `until` | string | いいえ | Last day of the date range, `YYYY-MM-DD`. Default: up to the latest records. |
| `basis` | (`records` \| `official`)[] | いいえ | Which numbers to return. Default: both. `official` alone is cheaper and answers from official statistics only. Default: `records,official`. |
| `top` | integer | いいえ | How many countries each breakdown lists, 1 to 50. Default: `20`. |
| `max_cost` | number | いいえ | Spending cap for this call in US dollars. If the call could cost more, it fails with `budget_exceeded` before anything is charged. |
| `dry_run` | boolean | いいえ | If true, only return the maximum cost of this call. Nothing runs, nothing is charged. Default: `false`. |

## レスポンス [#response]

`dry_run: true` を指定すると何も実行されず、`data` にはその呼び出しの最大費用だけが入ります。[ドライラン](/ja/docs/responses#dry-run)を参照してください。エラーについては[エラーコード](/ja/docs/errors)を参照してください。

| フィールド | 型 | 説明（APIの原文） |
| --- | --- | --- |
| `data` | object | The statistics, one part for each kind of number. |
| `data.records` | object \| null | Counts and declared values of our shipment records. Not official trade totals. |
| `data.records.shipments` | integer | Number of shipment records. A count of records, not a market share: countries that publish every declaration are over-represented. |
| `data.records.recorded_value_usd` | number \| null | Sum of the declared values of the records that have one, in US dollars. A lower bound: US bills of lading carry no value. |
| `data.records.by_importer_country` | object[] \| null | Records by importing country, largest first. Null when it could not be loaded. |
| `data.records.by_importer_country[].country` | string | ISO 3166-1 alpha-2 country code, such as `US`. |
| `data.records.by_importer_country[].shipments` | integer | Number of shipment records. A count of records, not a market share: countries that publish every declaration are over-represented. |
| `data.records.by_exporter_country` | object[] \| null | Records by exporting country, largest first. Null when it could not be loaded. |
| `data.records.by_exporter_country[].country` | string | ISO 3166-1 alpha-2 country code, such as `US`. |
| `data.records.by_exporter_country[].shipments` | integer | Number of shipment records. A count of records, not a market share: countries that publish every declaration are over-represented. |
| `data.records.by_month` | object[] | One entry for each month of the range, oldest first. |
| `data.records.by_month[].month` | string | `YYYY-MM` |
| `data.records.by_month[].shipments` | integer | Shipment records of the month. |
| `data.records.by_month[].recorded_value_usd` | number \| null | Declared value of the month's records that have one, in US dollars. |
| `data.records.by_month[].partial` | boolean | True when the month is not complete yet. Do not read it as a drop. |
| `data.records.company_match` | `id` \| `name` | With `company`: how its records were found. `id` counts the company itself, by its ID, over the last 12 months. `name` matches its name as it stands in the records, so companies that share the name count together. |
| `data.official` | object \| null | Official trade statistics. Use these for market size and country shares. |
| `data.official.reporter` | string | Country whose statistics these are, or `EU`. |
| `data.official.flow` | `import` \| `export` | Whether these are the reporter's imports or its exports. |
| `data.official.period` | object | The first and the last month the numbers cover. |
| `data.official.period.since` | string | `YYYY-MM` |
| `data.official.period.until` | string | `YYYY-MM` |
| `data.official.value_usd` | number | Trade value of the period, in US dollars. |
| `data.official.value_basis` | `customs` \| `cif` \| `fob` | How `value_usd` is valued: customs value, cost-insurance-freight or free on board. |
| `data.official.cif_value_usd` | number \| null | For US imports: the value including insurance and freight. |
| `data.official.quantity` | number \| null | Quantity of the period, where the office measures one in a single unit for every partner and month. Left out otherwise. |
| `data.official.quantity_unit` | string \| null | Unit of `quantity`: `u` items, `kg`, `l`, `m2`, `pairs` and so on. |
| `data.official.unit_value_usd` | number \| null | `value_usd` divided by `quantity`: the average price of one unit. |
| `data.official.by_partner_country` | object[] | The partner countries, largest first. |
| `data.official.by_partner_country[].country` | string | ISO 3166-1 alpha-2 country code, such as `US`. |
| `data.official.by_partner_country[].value_usd` | number | Trade value with this country, in US dollars. |
| `data.official.by_partner_country[].share` | number | This country's part of everything the reporter imports or exports of the product in the period, from 0 to 1. |
| `data.official.by_month` | object[] | One entry for each published month, oldest first. |
| `data.official.by_month[].month` | string | `YYYY-MM` |
| `data.official.by_month[].value_usd` | number | Trade value of the month, in US dollars. |
| `data.official.by_month[].partial` | boolean | True while more partners can still add their numbers for the month. Do not read it as a drop. |
| `data.official.missing_months` | string[] | Months inside `period` the office published nothing for, of any product: they are missing from `by_month` and from `value_usd`, not months without trade. Left out when none are. |
| `data.official.stopped_reporting` | object[] | With `mirror`: partners whose numbers stop for six months or more while the others go on, most likely because they have published nothing since, or publish late. The months after their `last_month` look lower than the trade was. Left out when none did. |
| `data.official.stopped_reporting[].country` | string | ISO 3166-1 alpha-2 country code, such as `US`. |
| `data.official.stopped_reporting[].last_month` | string | The last month with its numbers, `YYYY-MM`. |
| `data.official.stopped_reporting[].share` | number | Its part of `value_usd`, from 0 to 1, all of it from before it stopped. |
| `data.official.mirror` | boolean | True when the reporter publishes no recent statistics of its own and these numbers add up what its partners report about their trade with it: their imports from it at CIF for its exports, their exports to it at FOB for its imports. Partners that publish nothing are missing, so it is a lower bound. |
| `data.official.source` | `official_statistics` | Marks these numbers as official statistics. |
| `data.coverage` | object | How the two kinds of numbers compare. |
| `data.coverage.recorded_value_share` | number \| null | Recorded value divided by the official value for the same months. Shows how much of real trade the recorded values stand for. |
| `query` | object | The request as it was understood: country names as codes, the default dates filled in. `data_through` says how recent the records behind the answer are. |
| `query.data_through` | string \| null | Date of the latest record this query can see, `YYYY-MM-DD`. Records arrive weeks after a shipment, so recent months are incomplete. |
| `notice` | string \| null | A plain sentence when there is something to know about this result: why a part is missing, or what to try next. Null otherwise. |
| `usage` | object | What this call was charged, and the balance left. |
| `usage.unit` | `trade_record` \| `trade_company` \| `trade_company_profile` \| `trade_lookup` \| `person_email` \| `company_channels` \| `trade_stats` \| `trade_official_stats` \| `market_search` \| `market_listings` \| `market_estimates` | What is counted. |
| `usage.records` | integer | How many were returned and charged. |
| `usage.already_paid` | integer | How many more were returned for free, because this organization paid for them in the last 30 days. |
| `usage.cost` | number | What this call cost, in US dollars. |
| `usage.balance` | number | The balance left after this call, in US dollars. |
| `usage.replayed` | boolean | True when this is a repeat of a request from the last 24 hours. Repeats are free. |

## 例 [#example]

```bash
curl https://api.won.dev/v1/trade/stats/query \
  -H "Authorization: Bearer $WON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "hs_code": "940161",
  "importer_country": "US"
}'
```

```json
{
  "data": {
    "records": {
      "shipments": 1165783,
      "recorded_value_usd": 2620186000,
      "by_importer_country": [
        {
          "country": "US",
          "shipments": 1021440
        }
      ],
      "by_exporter_country": [
        {
          "country": "VN",
          "shipments": 932019
        },
        {
          "country": "MY",
          "shipments": 104871
        },
        {
          "country": "MX",
          "shipments": 58330
        }
      ],
      "by_month": [
        {
          "month": "2026-07",
          "shipments": 118420,
          "recorded_value_usd": 251340118.2,
          "partial": false
        },
        {
          "month": "2026-08",
          "shipments": 121077,
          "recorded_value_usd": 259871402.75,
          "partial": false
        },
        {
          "month": "2026-09",
          "shipments": 126295,
          "recorded_value_usd": 270019576.35,
          "partial": false
        },
        {
          "month": "2026-10",
          "shipments": 98114,
          "recorded_value_usd": 204118330.1,
          "partial": true
        },
        {
          "month": "2026-11",
          "shipments": 5526,
          "recorded_value_usd": 3393700.19,
          "partial": true
        }
      ]
    },
    "official": {
      "reporter": "US",
      "flow": "import",
      "period": {
        "since": "2025-11",
        "until": "2026-09"
      },
      "value_usd": 4813000000,
      "value_basis": "customs",
      "cif_value_usd": 5102000000,
      "by_partner_country": [
        {
          "country": "VN",
          "value_usd": 2888000000,
          "share": 0.6
        },
        {
          "country": "MX",
          "value_usd": 722000000,
          "share": 0.15
        },
        {
          "country": "CN",
          "value_usd": 481000000,
          "share": 0.1
        }
      ],
      "by_month": [
        {
          "month": "2026-07",
          "value_usd": 428000000
        },
        {
          "month": "2026-08",
          "value_usd": 417000000
        },
        {
          "month": "2026-09",
          "value_usd": 401000000
        }
      ],
      "source": "official_statistics"
    },
    "coverage": {
      "recorded_value_share": 0.6321
    }
  },
  "query": {
    "hs_code": "940161",
    "importer_country": "US",
    "since": "2025-11-01",
    "until": "2026-11-20",
    "basis": [
      "records",
      "official"
    ],
    "top": 20,
    "data_through": "2026-11-11"
  },
  "notice": null,
  "usage": {
    "unit": "trade_stats",
    "records": 1,
    "already_paid": 0,
    "cost": 0.1,
    "balance": 47.98,
    "replayed": false
  }
}
```