Get Trade Balance
comtrade_get_trade_balanceCompute the trade balance for a country over one or more periods — total exports minus total imports — with an optional HS or SITC commodity filter whose codes must not overlap. Keyless preview makes two requests per served period, at least 4 seconds apart; authenticated calls batch periods. Returns the export and import values per period and, when both flows have data, the signed balance (USD) and coverage ratio (exports / imports). Note: mirror asymmetry is common — balance reflects values as reported by this country; the same flow may be recorded differently by the partner. Uses comtrade_lookup_countries to resolve reporter codes.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"reporter_code": "<reporter_code>",
"period": "<period>"
},
"name": "comtrade_get_trade_balance"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| freq | No | Frequency for both flows: A=annual YYYY, M=monthly YYYYMM (01–12). Omit to infer it from the periods; an explicit value must match them. | |
| period | Yes | Periods, all annual (YYYY) or all monthly (YYYYMM); mixed lengths are rejected. Serves the first 4 distinct periods keyless (12 with authenticated access); the rest, and any period whose export or import request is rate limited, hits a UN Comtrade server error or network failure, or runs out of time, are listed in unservedPeriods. Input ceiling 120. | |
| cmd_code | No | HS or SITC commodity codes whose values the balance sums; omit for the overall balance across all commodities. Exact duplicates count once. Overlapping codes are rejected because their shared trade would be summed twice: a code beside one of its sub-codes (27 and 2709), TOTAL beside any other entry, or AG<n> beside another AG selector or a code whose length is not n. Serves the first 20 and discloses the remainder; input ceiling 200. | |
| partner_code | No | M49 partner code (0–999); defaults to World (0). The balance uses the reporter’s values. A partner code with a reporter-valid counterpart (840 → 842, 158 → 490) that returns no data fails with no_data naming that counterpart. | |
| reporter_code | Yes | M49 numeric code of the reporting country (0–999). A partner-only code (0 World, 250 Metropolitan France, 158 Taiwan, Province of China) with no data fails with partner_only_reporter, naming the code to query instead when one exists: 251 shares the ISO-3 identity of 250, and UN Comtrade publishes the trade of 158 under 490 (Other Asia, nes). | |
| classification | No | Goods classification: HS/H0–H6 or SITC S1–S4/SS. | HS |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| error | No | Present when the call failed. Absent on success. | |
| notice | No | Period failures, periods without export or import data, possible incompleteness at the preview cap, and commodity edition guidance for missing selectors. | |
| periods | No | Balance computation per period. | |
| cmdCodes | No | Commodity codes used in the query (absent when querying all commodities). | |
| partnerCode | No | M49 partner code used. | |
| partnerDesc | No | Partner name supplied by the returned records, or its numeric code when unavailable. | |
| mirrorCaveat | No | Standard caveat about mirror asymmetry — balance reflects this country's reported values. | |
| reporterCode | No | M49 reporter code used. | |
| reporterDesc | No | Reporter country name. | |
| referenceNotice | No | Reference descriptions unavailable; codes and trade values retained. | |
| unservedPeriods | No | Periods not served: past the period cap (4 keyless, 12 authenticated) or whose export or import request was rate limited, hit a UN Comtrade server error or network failure, or ran out of time; query them separately. | |
| unservedCmdCodes | No | Commodity codes beyond the 20-code work cap; query them separately. | |
| cmdCodesWithoutRecords | No | Served commodity selectors without records in any completed period. Omitted when the result is truncated. |