package fxmacrodata

  1. Overview
  2. Docs
OCaml client for the FXMacroData forex and macroeconomic data API

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.1.0.tar.gz
sha256=d9e7ddffc396a90ed7888853f501ae86241f794b311b9cce73f7e40897867232
sha512=239fbf711b71566fb4f75f0d99e072f3ecca5eeea80efecdefffd1722bd033109d401f10689cea4d73302da1585ad7cc9ef326c8b4d297c814640d2d9bbcd8d0

Description

Client library for the FXMacroData REST API: official-source forex and macroeconomic data covering central-bank announcements, macroeconomic indicator time series, economic release calendars, CFTC Commitment of Traders positioning, commodities, and FX spot-rate history for 18 catalogue currencies. Provides a small typed wrapper with Lwt-based requests, plus a generic get_json escape hatch for any endpoint of the public API.

Tags

forex macroeconomics finance market data api-client

Added to opam-repository:

README

ocaml-fxmacrodata

OCaml client for the FXMacroData API — official-source forex and macroeconomic data: central-bank announcements, macroeconomic indicator time series, economic release calendars, CFTC Commitment of Traders positioning, commodities, and FX spot-rate history across 18 catalogue currencies (AUD, BRL, CAD, CHF, CNH, CNY, DKK, EUR, GBP, ILS, JPY, NGN, NOK, NZD, PEN, SEK, THB, USD).

Install

opam install fxmacrodata

Quickstart

let () =
  let client = Fxmacrodata.create () in
  match
    Lwt_main.run
      (Fxmacrodata.macro_indicator client ~currency:"usd"
         ~indicator:"inflation_rate" ~start_date:"2026-01-01" ())
  with
  | Ok rows -> Printf.printf "Fetched %d rows\n" (List.length rows)
  | Error e -> prerr_endline (Fxmacrodata.Error.to_string e)

Run the bundled example:

dune exec examples/latest_announcements.exe

Authentication

Free-tier endpoints work without a key. For keyed access, pass the key explicitly or set an environment variable — resolution order is ~api_key argument, then FXMACRODATA_API_KEY, then FXMD_API_KEY:

let client = Fxmacrodata.create ~api_key:"YOUR_KEY" ()

The key is sent as an X-API-Key header by default; use ~auth_mode:Fxmacrodata.Query to send it as an api_key query parameter instead.

API surface

Typed helpers (all return (_, Fxmacrodata.Error.t) result Lwt.t; dates are YYYY-MM-DD strings):

Function

Endpoint

ping

GET /v1/ping

data_catalogue ~currency

GET /v1/data_catalogue/{currency}

release_calendar ~currency

GET /v1/calendar/{currency}

macro_indicator ~currency ~indicator

GET /v1/announcements/{currency}/{indicator}

forex ~base ~quote

GET /v1/forex/{base}/{quote}

cot ~currency

GET /v1/cot/{currency}

commodity ~indicator

GET /v1/commodities/{indicator}

Any other endpoint of the public API is reachable through the generic escape hatch:

Fxmacrodata.get_json client ~path:"/v1/market_sessions" ()

get_data is the same but returns the top-level data array of the response, which is the shape most time-series endpoints use.

Start with data_catalogue to discover the exact indicator slugs available for a currency.

Development

opam install . --deps-only --with-test
dune build
dune test

Tests run fully offline against an injected stub HTTP function.

License

MIT

Dependencies (8)

  1. yojson >= "2.0"
  2. uri >= "4.0"
  3. lwt >= "5.6"
  4. cohttp-lwt >= "5.0"
  5. cohttp >= "5.0"
  6. cohttp-lwt-unix >= "5.0"
  7. ocaml >= "4.14"
  8. dune >= "3.7"

Dev Dependencies (2)

  1. odoc with-doc
  2. alcotest >= "1.7" & with-test

Used by

None

Conflicts

None