OpenParable
Skip to content
← Back to skills

Comtrade Trade

Research
comtrade-trade

Comtrade Trade is an Agent Skill for research published in the lamm-mit/scienceclaw repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

Query UN Comtrade bilateral trade flows (USD, kg) for critical minerals by HS code, country, and year

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/lamm-mit/scienceclaw/blob/HEAD/skills/comtrade-trade/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/comtrade-trade, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

UN Comtrade Trade Data

Query UN Comtrade for bilateral trade flows of critical minerals. Returns trade values (USD), net weight (kg), and flow direction (imports/exports) by HS commodity code, reporter country, partner country, and year.

Usage

Search by mineral name:

python3 {baseDir}/scripts/comtrade_query.py --mineral lithium

Search by HS code:

python3 {baseDir}/scripts/comtrade_query.py --hs-code 282520 --reporter 842

Filter by country and flow:

python3 {baseDir}/scripts/comtrade_query.py --mineral cobalt --reporter 842 --flow X --year 2022

JSON output:

python3 {baseDir}/scripts/comtrade_query.py --mineral rare_earth --format json --year 2023

Parameters

ParameterDescriptionDefault
--mineralCritical mineral name (lithium, cobalt, rare_earth, graphite, nickel, manganese, gallium, germanium, copper, hree, lree)-
--hs-codeHS commodity code (alternative to --mineral)-
--reporterReporter country code (e.g., 842 for USA, 156 for China)0 (all)
--partnerPartner country code0 (world)
--flowTrade flow: M (imports), X (exports), M,X (both)M,X
--yearYear(s), comma-separated2023
--limitMaximum records to return500
--formatOutput format: summary, detailed, jsonsummary

Available Minerals

NameHS CodesDescription
lithium253090, 282520, 283691, 850650Ores, oxide/hydroxide, carbonate, batteries
cobalt2605, 282200, 810520, 810590Ores, oxides, unwrought, articles
rare_earth2846, 280530REE compounds, REE metals
hree284690Heavy REE compounds
lree284610Light REE compounds
graphite250410, 250490, 380110Natural (amorphous, crystalline), artificial
nickel2604, 7501, 750210, 750220, 281122Ores, matte, unwrought, alloys, oxides
manganese2602, 811100Ores, unwrought
gallium811292Unwrought
germanium811299Other base metals
copper7402, 7403Refined, unrefined

Examples

# US lithium imports
python3 {baseDir}/scripts/comtrade_query.py --mineral lithium --reporter 842 --flow M --year 2023

# Global cobalt trade flows
python3 {baseDir}/scripts/comtrade_query.py --mineral cobalt --format detailed

# China rare earth exports
python3 {baseDir}/scripts/comtrade_query.py --mineral rare_earth --reporter 156 --flow X --year 2022

# Nickel trade by specific HS code
python3 {baseDir}/scripts/comtrade_query.py --hs-code 2604 --format json

Notes

  • Requires UNCOMTRADE_API_KEY environment variable
  • Country codes follow UN M49 standard (842=USA, 156=China, 276=Germany, etc.)
  • Use 0 for "all countries" or "world"
  • HS codes follow Harmonized System classification
  • API has rate limits; be conservative with large queries