fxmacrodata 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fxmacrodata/__init__.py +6 -0
- fxmacrodata/async_client.py +59 -0
- fxmacrodata/client.py +48 -0
- fxmacrodata/exceptions.py +4 -0
- fxmacrodata/utils.py +3 -0
- fxmacrodata-0.1.0.dist-info/METADATA +64 -0
- fxmacrodata-0.1.0.dist-info/RECORD +10 -0
- fxmacrodata-0.1.0.dist-info/WHEEL +5 -0
- fxmacrodata-0.1.0.dist-info/licenses/LICENSE +21 -0
- fxmacrodata-0.1.0.dist-info/top_level.txt +1 -0
fxmacrodata/__init__.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import aiohttp # type: ignore
|
|
2
|
+
from typing import Optional
|
|
3
|
+
from .exceptions import FXMacroDataError
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class AsyncClient:
|
|
7
|
+
BASE_URL = "https://fxmacrodata.com/api"
|
|
8
|
+
|
|
9
|
+
def __init__(self, api_key: Optional[str] = None):
|
|
10
|
+
"""
|
|
11
|
+
Asynchronous FXMacroData Client.
|
|
12
|
+
api_key: Required for non-USD currencies. USD is public.
|
|
13
|
+
"""
|
|
14
|
+
self.api_key: Optional[str] = api_key
|
|
15
|
+
self.session: Optional[aiohttp.ClientSession] = None
|
|
16
|
+
|
|
17
|
+
async def __aenter__(self) -> "AsyncClient":
|
|
18
|
+
self.session = aiohttp.ClientSession()
|
|
19
|
+
return self
|
|
20
|
+
|
|
21
|
+
async def __aexit__(self, exc_type, exc_val, exc_tb) -> None:
|
|
22
|
+
if self.session:
|
|
23
|
+
await self.session.close()
|
|
24
|
+
self.session = None
|
|
25
|
+
|
|
26
|
+
async def get(
|
|
27
|
+
self,
|
|
28
|
+
currency: str,
|
|
29
|
+
indicator: str,
|
|
30
|
+
start_date: Optional[str] = None,
|
|
31
|
+
end_date: Optional[str] = None,
|
|
32
|
+
) -> dict:
|
|
33
|
+
currency = currency.lower()
|
|
34
|
+
url = f"{self.BASE_URL}/{currency}/{indicator}"
|
|
35
|
+
|
|
36
|
+
headers = {}
|
|
37
|
+
if currency != "usd":
|
|
38
|
+
if not self.api_key:
|
|
39
|
+
raise FXMacroDataError(
|
|
40
|
+
f"API key required for {currency.upper()} endpoints."
|
|
41
|
+
)
|
|
42
|
+
headers["X-API-Key"] = self.api_key
|
|
43
|
+
|
|
44
|
+
params = {}
|
|
45
|
+
if start_date:
|
|
46
|
+
params["start_date"] = start_date
|
|
47
|
+
if end_date:
|
|
48
|
+
params["end_date"] = end_date
|
|
49
|
+
|
|
50
|
+
if not self.session:
|
|
51
|
+
self.session = aiohttp.ClientSession()
|
|
52
|
+
|
|
53
|
+
assert self.session is not None # mypy now knows session is initialized
|
|
54
|
+
|
|
55
|
+
async with self.session.get(url, headers=headers, params=params) as resp:
|
|
56
|
+
if resp.status != 200:
|
|
57
|
+
text = await resp.text()
|
|
58
|
+
raise FXMacroDataError(f"{resp.status} - {text}")
|
|
59
|
+
return await resp.json()
|
fxmacrodata/client.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
from typing import Optional
|
|
3
|
+
from .exceptions import FXMacroDataError
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Client:
|
|
7
|
+
BASE_URL = "https://fxmacrodata.com/api"
|
|
8
|
+
|
|
9
|
+
def __init__(self, api_key: Optional[str] = None):
|
|
10
|
+
"""
|
|
11
|
+
Synchronous FXMacroData Client.
|
|
12
|
+
api_key: Required for non-USD currencies. USD is public.
|
|
13
|
+
"""
|
|
14
|
+
self.api_key = api_key
|
|
15
|
+
|
|
16
|
+
def get(
|
|
17
|
+
self,
|
|
18
|
+
currency: str,
|
|
19
|
+
indicator: str,
|
|
20
|
+
start_date: Optional[str] = None,
|
|
21
|
+
end_date: Optional[str] = None,
|
|
22
|
+
) -> dict:
|
|
23
|
+
currency = currency.lower()
|
|
24
|
+
url = f"{self.BASE_URL}/{currency}/{indicator}"
|
|
25
|
+
|
|
26
|
+
headers = {}
|
|
27
|
+
if currency != "usd":
|
|
28
|
+
if not self.api_key:
|
|
29
|
+
raise FXMacroDataError(
|
|
30
|
+
f"API key required for {currency.upper()} endpoints."
|
|
31
|
+
)
|
|
32
|
+
headers["X-API-Key"] = self.api_key
|
|
33
|
+
|
|
34
|
+
params = {}
|
|
35
|
+
if start_date:
|
|
36
|
+
params["start_date"] = start_date
|
|
37
|
+
if end_date:
|
|
38
|
+
params["end_date"] = end_date
|
|
39
|
+
|
|
40
|
+
try:
|
|
41
|
+
response = requests.get(url, headers=headers, params=params)
|
|
42
|
+
except Exception as e:
|
|
43
|
+
raise FXMacroDataError(f"Request failed: {e}")
|
|
44
|
+
|
|
45
|
+
if response.status_code != 200:
|
|
46
|
+
raise FXMacroDataError(f"{response.status_code} - {response.text}")
|
|
47
|
+
|
|
48
|
+
return response.json()
|
fxmacrodata/utils.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fxmacrodata
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python client for the FXMacroData API, providing forex macroeconomic data for traders, quants, and analysts.
|
|
5
|
+
Author-email: FXMacroData <info@fxmacrodata.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://fxmacrodata.com/?utm_source=pypi&utm_medium=package&utm_campaign=python_sdk
|
|
8
|
+
Project-URL: Documentation, https://fxmacrodata.com/api/docs?utm_source=pypi&utm_medium=package&utm_campaign=python_sdk
|
|
9
|
+
Project-URL: Source, https://github.com/fxmacrodata/fxmacrodata
|
|
10
|
+
Project-URL: Issues, https://github.com/fxmacrodata/fxmacrodata
|
|
11
|
+
Keywords: forex,macro data,macroeconomics,trading,quant,economic indicators,fxmacrodata,rapidapi
|
|
12
|
+
Requires-Python: >=3.9
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: requests>=2.28
|
|
16
|
+
Requires-Dist: aiohttp>=3.8
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
19
|
+
Requires-Dist: pytest-mock>=3.10; extra == "dev"
|
|
20
|
+
Requires-Dist: python-dotenv>=1.1; extra == "dev"
|
|
21
|
+
Requires-Dist: python-semantic-release>=7.23; extra == "dev"
|
|
22
|
+
Requires-Dist: twine>=4.0; extra == "dev"
|
|
23
|
+
Requires-Dist: build>=1.0; extra == "dev"
|
|
24
|
+
Requires-Dist: ruff>=0.0; extra == "dev"
|
|
25
|
+
Requires-Dist: mypy>=1.5; extra == "dev"
|
|
26
|
+
Requires-Dist: black>=24.0; extra == "dev"
|
|
27
|
+
Requires-Dist: types-requests>=2.28; extra == "dev"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# FXMacroData Python SDK 🐍📊
|
|
31
|
+
|
|
32
|
+

|
|
33
|
+

|
|
34
|
+

|
|
35
|
+

|
|
36
|
+
|
|
37
|
+
The **FXMacroData Python SDK** is a lightweight, easy-to-use client for fetching **forex macroeconomic data** from [FXMacroData](https://fxmacrodata.com/?utm_source=github&utm_medium=readme&utm_campaign=python_sdk).
|
|
38
|
+
|
|
39
|
+
It supports **synchronous** and **asynchronous** requests, provides ready-to-use JSON responses, and enforces API keys only for non-USD endpoints. Perfect for developers, quants, and algo traders.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## 🌟 Features
|
|
44
|
+
|
|
45
|
+
- Fetch **policy rates, CPI, inflation, GDP, unemployment**, and other macroeconomic indicators.
|
|
46
|
+
- Supports **USD (free)** and **other currencies via RapidAPI key**.
|
|
47
|
+
- **Async-first** design for bulk data fetching.
|
|
48
|
+
- Works with **Python 3.9+**.
|
|
49
|
+
- Compatible with **TradingBots, Jupyter Notebooks, Backtests**.
|
|
50
|
+
- Minimal dependencies: `requests`, `aiohttp`.
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## 📦 Installation
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install fxmacrodata
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Or install the latest version from GitHub:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install git+https://github.com/yourusername/fxmacrodata.git
|
|
64
|
+
```
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
fxmacrodata/__init__.py,sha256=H3XZGyqfS_Yx1KIVSQ62-l1oNos4udWdHZcncvuqQJA,211
|
|
2
|
+
fxmacrodata/async_client.py,sha256=o1Hp6CkY-GkGbhvG27OO1sL_A7VSpe2HK14zGwJIovk,1852
|
|
3
|
+
fxmacrodata/client.py,sha256=Pjn1ZfD8PpP-CKcvLV1UmWqYR1Nxc4eSnPeTIwFL-f0,1374
|
|
4
|
+
fxmacrodata/exceptions.py,sha256=Mv1SP0RZ-dCmKysi2l1ythhLhVc-J7zsBTJCSiGe4Xk,103
|
|
5
|
+
fxmacrodata/utils.py,sha256=B1f9vPJfVUS2wXwMBrLTYZbyHV9LYrm0B-zBUYuFi4g,195
|
|
6
|
+
fxmacrodata-0.1.0.dist-info/licenses/LICENSE,sha256=7qtf-IvAp1ZLUzJ52T3FhWhPr56stYxCnaumn3TDbBU,1068
|
|
7
|
+
fxmacrodata-0.1.0.dist-info/METADATA,sha256=UGFnhE3XEY4LBb5Uf-9Mnlgx0RwzgboHF1ucPtwX1N0,2775
|
|
8
|
+
fxmacrodata-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
+
fxmacrodata-0.1.0.dist-info/top_level.txt,sha256=g4wStAnsNrEJfApHUVU3AISpc5w-r4khkVvEPg-10S4,12
|
|
10
|
+
fxmacrodata-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 FXMacroData
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fxmacrodata
|