Live release feed
Sub-second macro releases for FX backtests
Point-in-time history
Official CPI, jobs, GDP, and central-bank events with point-in-time history.
USD 25/month 14-day free trial
Start Free Trial
迅速スタート: Node.js で FXMacroData に接続する image
Share headline card X LinkedIn Email
Download

By Language

Quick Start Guides

迅速スタート: Node.js で FXMacroData に接続する

Node.js で FXMacroData を数分で起動する.組み込みのフェッチ API,アシンクロ/待ちパターン,マルチインジケータリクエスト,そして中央銀行のデータを抽出するための実行可能なスクリプトをカバーする.

他言語版 English
Share article X LinkedIn Email

FXMacroData REST API は,HTTP GET リクエストを行うことができる言語から消費するように設計されています. Node.js は内蔵された fetch implementation from v18 onwards, so there is nothing extra to install for basic usage — just your API key and a few lines of JavaScript. This guide walks you from zero to a working multi-indicator script in under ten minutes.

あなた が 築く もの

FXMacroData REST API に認証し,複数のG10通貨の政策レートとインフレデータを並行で取得し,コンソールにクリーンな概要表をプリントします.

条件

  • Node.js 18 以降 v18 はグローバル 導入 fetch API; v20+は生産に推奨される
  • npm (Node.js とバンドル) 選択パッケージを追加する場合はのみ必要
  • FXMacroData API キーを 登録する / サブスクリプト そしてダッシュボードからあなたの鍵をコピー

Node.js のバージョンを確認してください.

node --version   # should print v18.x.x or later

ステップ 1 API キーを安全に保存する

ソースファイルにAPIキーをハードコードすることは決してない.バージョン制御にコミットできる.最も簡単な安全なアプローチは実行時に読み取れる環境変数である.

シェルプロフィールに追加します (~/.bashrc ほら ~/.zshrcについて

export FXMD_API_KEY="your_actual_api_key_here"

Windows (PowerShell) で:

$env:FXMD_API_KEY = "your_actual_api_key_here"

Node.js プロジェクトでは, .env ファイルと フォローする 設定についてはステップ6を参照してください.

Step 2 — Understand the API Shape

FXMacroDataのすべてのエンドポイントは同じパターンに従っており,一般的なフェッチヘルパーを簡単に構築できます. 基本的な構造は以下です:

GET https://fxmacrodata.com/api/v1/announcements/{currency}/{indicator}?api_key=YOUR_API_KEY

応答はJSONで,トップレベルです. data 配列です.各要素には date番号を val及び (ほとんどの指標において) announcement_datetime 値がリリースされた秒を特定します:

{
  "data": [
    { "date": "2025-03-19", "val": 4.25, "announcement_datetime": "2025-03-19T18:00:00Z" },
    { "date": "2025-01-29", "val": 4.25, "announcement_datetime": "2025-01-29T19:00:00Z" },
    { "date": "2024-12-18", "val": 4.25, "announcement_datetime": "2024-12-18T19:00:00Z" }
  ]
}

このクリーンで一貫した構造は,ビジネスロジック,データベース,またはダウンストリームAPIで使用する前にほとんど変換を必要としません.

ステップ 3 初めての電話

ファイルを作成します fxmd.js and add the following. This fetches the US Federal Reserve policy rate for the last two years using Node.js's built-in fetchありがとうございました

// fxmd.js  —  requires Node.js 18+
const API_KEY = process.env.FXMD_API_KEY;
const BASE    = "https://fxmacrodata.com/api/v1";

async function getIndicator(currency, indicator, startDate) {
  const url = new URL(`${BASE}/announcements/${currency}/${indicator}`);
  url.searchParams.set("api_key", API_KEY);
  if (startDate) url.searchParams.set("start", startDate);

  const res = await fetch(url.toString());
  if (!res.ok) {
    throw new Error(`API error ${res.status}: ${await res.text()}`);
  }
  const json = await res.json();
  return json.data ?? [];
}

// Fetch the Fed policy rate
const data = await getIndicator("usd", "policy_rate", "2023-01-01");
console.log(`Latest USD policy rate: ${data[0]?.val}% on ${data[0]?.date}`);

実行する

FXMD_API_KEY=your_key node fxmd.js

待機する 上記の例ではトップレベルを使用します. await効く .mjs ファイルやいつ "type": "module" 設定されている package.json呼び出しをカートに包む async 動作し,すぐに呼び出す (ステップ5の完全な例を参照).

ステップ4 複数の指標を並列で取得する

Promise.all 複数の通貨と指標を同時に引き出すための再利用可能なパターンです. 複数の指数と指標が同時に引き出される場合,

const CURRENCIES  = ["usd", "eur", "gbp", "aud", "jpy"];
const INDICATORS  = ["policy_rate", "inflation"];
const START       = "2024-01-01";

// Build a flat list of [currency, indicator] pairs
const pairs = CURRENCIES.flatMap(c => INDICATORS.map(i => [c, i]));

// Fire all requests in parallel
const results = await Promise.all(
  pairs.map(([currency, indicator]) =>
    getIndicator(currency, indicator, START)
      .then(data => ({ currency, indicator, latest: data[0] ?? null }))
      .catch(err => ({ currency, indicator, latest: null, error: err.message }))
  )
);

// Print a quick summary
for (const row of results) {
  if (row.error) {
    console.log(`${row.currency.toUpperCase()} ${row.indicator}: ERROR — ${row.error}`);
  } else if (row.latest) {
    console.log(
      `${row.currency.toUpperCase()} ${row.indicator}: ${row.latest.val} (${row.latest.date})`
    );
  }
}

ほら .catch 部分的なデータがまだ実行可能である夜間作業を実行する際に有用です.

ステップ5 制作準備の準備が完了

下記は,適切なエラー処理,設定可能な通貨および指標リスト,ログまたは下流処理のためにフォーマットされた出力,完全なCommonJS対応スクリプトです:

// macro-snapshot.js  —  CommonJS, Node.js 18+
"use strict";

const API_KEY = process.env.FXMD_API_KEY;
const BASE    = "https://fxmacrodata.com/api/v1";

if (!API_KEY) {
  console.error("Error: FXMD_API_KEY environment variable is not set.");
  process.exit(1);
}

// ── Configuration ──────────────────────────────────────────────────────────
const CURRENCIES = ["usd", "eur", "gbp", "cad", "jpy", "aud", "nzd", "chf"];
const INDICATORS = ["policy_rate", "inflation", "unemployment"];
const START_DATE = "2024-01-01";
// ───────────────────────────────────────────────────────────────────────────

async function getIndicator(currency, indicator, startDate) {
  const url = new URL(`${BASE}/announcements/${currency}/${indicator}`);
  url.searchParams.set("api_key", API_KEY);
  if (startDate) url.searchParams.set("start", startDate);

  const res = await fetch(url.toString());
  if (!res.ok) {
    const body = await res.text().catch(() => "");
    throw new Error(`HTTP ${res.status}${body ? ": " + body.slice(0, 120) : ""}`);
  }
  const json = await res.json();
  return Array.isArray(json.data) ? json.data : [];
}

async function main() {
  const pairs = CURRENCIES.flatMap(c => INDICATORS.map(i => [c, i]));

  const results = await Promise.all(
    pairs.map(async ([currency, indicator]) => {
      try {
        const data = await getIndicator(currency, indicator, START_DATE);
        return { currency, indicator, latest: data[0] ?? null, error: null };
      } catch (err) {
        return { currency, indicator, latest: null, error: err.message };
      }
    })
  );

  // Group by currency for readable output
  const byCurrency = {};
  for (const row of results) {
    if (!byCurrency[row.currency]) byCurrency[row.currency] = [];
    byCurrency[row.currency].push(row);
  }

  console.log("\n=== FXMacroData Macro Snapshot ===\n");
  for (const [currency, rows] of Object.entries(byCurrency)) {
    console.log(`  ${currency.toUpperCase()}`);
    for (const row of rows) {
      if (row.error) {
        console.log(`    ${row.indicator.padEnd(20)} — error: ${row.error}`);
      } else if (row.latest) {
        console.log(
          `    ${row.indicator.padEnd(20)} ${String(row.latest.val).padStart(8)}  (${row.latest.date})`
        );
      } else {
        console.log(`    ${row.indicator.padEnd(20)} — no data`);
      }
    }
    console.log();
  }
}

main().catch(err => {
  console.error("Fatal:", err.message);
  process.exit(1);
});

スクリプトを実行します.

FXMD_API_KEY=your_key node macro-snapshot.js

試料出力:

=== FXMacroData Macro Snapshot ===

  USD
    policy_rate             4.25  (2025-03-19)
    inflation               2.40  (2025-04-10)
    unemployment            4.20  (2025-04-04)

  EUR
    policy_rate             2.40  (2025-04-17)
    inflation               2.20  (2025-04-16)
    unemployment            6.10  (2025-03-31)

  GBP
    policy_rate             4.50  (2025-03-20)
    inflation               2.60  (2025-03-26)
    unemployment            4.40  (2025-04-15)
  ...

ステップ6 地方開発のためのDotenvを使用

大きくなる Node.js プロジェクトを構築する際には,API キーを .env ファイルに追加して自動的に フォローする パッケージ:

npm install dotenv

創る .env プロジェクトに追加します. .gitignore すぐさま)

FXMD_API_KEY=your_actual_api_key_here

Add one line to the top of your script:

require("dotenv").config();   // CommonJS
// or
import "dotenv/config";       // ES module

脚本の残りはこう書いてある process.env.FXMD_API_KEY 変更は必要ありません.

生産中 クラウド機能,AWS ラムダ,Vercel,レンダリングなど FXMD_API_KEY プラットフォームの秘密管理者を通して 安全な環境変数として .env ファイルからソースコントロールへ

ステップ7 完全な指標カタログを調査する

The macro snapshot above covers three indicators, but FXMacroData exposes more than 80 time series across 14 major currency blocs. The same getIndicator 外国為替トレーダーにとって価値の高い例をいくつか挙げます.

  • リアルレート 引く inflation について policy_rate 通貨の間の実質金利差を計算する. 中期為替方向性の主要な要因である. 政策金利の文書 詳細については,
  • 労働データ unemploymentほら non_farm_payrollsほら average_hourly_earnings 銀行反応機能について早期信号を与える.
  • 感情 consumer_confidenceほら pmiほら business_confidence lead hard-data indicators by one to two months and can precede currency moves before they appear in rate decisions.
  • 貿易流量 trade_balanceほら exportsほら imports 商品・通貨ペア (AUD,NZD,CAD) を取引条件の変動にリンクする.

通貨の全カタログを 閲覧 https://fxmacrodata.com/api/v1/catalogue/{currency}?api_key=YOUR_API_KEYインタラクティブなドキュメントを閲覧してください api-data-docs についてほら

概要

Node.js から FXMacroData を消費するために必要なものはすべてあります:

  • 共通語 getIndicator(currency, indicator, startDate) 認証とエラーチェックを処理するヘルパー
  • 複数の指標を並列で要求する Promise.all 要求ごとにエラーを隔離する
  • プログラムし,サーバーレス機能に展開したり,既存の Node.js バックエンドに統合したりできる 生産準備の良いスクリプト
  • 環境変数または セキュリティー 管理 dotenv

実行するタスクランナーで スナップショットスクリプトをスケジュールします n8n処理された JSON 構造は,React ダッシュボード,Express API,またはCloud Function トリガーを作成するかどうかにかかわらず,同じ方法で動作します.

言語に関するガイドについては, 速やかに 始める ガイド 分析と視覚化のためのエコシステム特有のツールで同じ指標セットをカバーします.

Blogroll

AI Answer-Ready

Key Facts

Page
Quick Start Nodejs FXmacrodata
Section
Articles
Canonical URL
https://fxmacrodata.com/ja/articles/quick-start-nodejs-fxmacrodata
Source
FXMacroData editorial and official publisher references
Last Updated
2026-06-15 11:06 UTC

Provenance And Trust

Cite the canonical URL and source field above. Where available, this page maps to official publisher releases and timestamped updates.

Quick Q&A

What is this page about? This page explains Quick Start Nodejs FXmacrodata with directly usable context for trading, research, and API workflows.

What source should be cited? Use the canonical URL and the listed source field; cite official publisher references when available.

How fresh is this content? The last updated value above reflects the page metadata or latest available data timestamp.

Can this be used in AI assistants? Yes. This section is intentionally structured for retrieval and citation in chat assistants.

Prompt Packs

Use these in ChatGPT, Claude, Gemini, Mistral, Perplexity, or Grok for consistent source-aware outputs.