tradinglookup 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.
- tradinglookup/__init__.py +58 -0
- tradinglookup/client.py +856 -0
- tradinglookup-0.1.0.dist-info/METADATA +118 -0
- tradinglookup-0.1.0.dist-info/RECORD +7 -0
- tradinglookup-0.1.0.dist-info/WHEEL +5 -0
- tradinglookup-0.1.0.dist-info/licenses/LICENSE +25 -0
- tradinglookup-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""TradingLookup zero-API-key Python SDK.
|
|
2
|
+
|
|
3
|
+
Public, read-only access to TradingLookup's CC BY 4.0 datasets, REST API
|
|
4
|
+
endpoints and Model Context Protocol (MCP) tools.
|
|
5
|
+
|
|
6
|
+
Open data hub: https://tradinglookup.com/data/
|
|
7
|
+
AI agent access: https://tradinglookup.com/for-ai-agents/
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from .client import (
|
|
13
|
+
CC_BY_4_0_LICENCE,
|
|
14
|
+
CFD_RISK_WARNING,
|
|
15
|
+
DEFAULT_BASE_URL,
|
|
16
|
+
PROP_MARKETS,
|
|
17
|
+
TradingLookupClient,
|
|
18
|
+
TradingLookupError,
|
|
19
|
+
__version__,
|
|
20
|
+
compare_prop_firms,
|
|
21
|
+
get_catalog,
|
|
22
|
+
get_cfd_loss_rates,
|
|
23
|
+
get_crypto_access,
|
|
24
|
+
get_economic_releases,
|
|
25
|
+
get_economic_releases_snapshot,
|
|
26
|
+
get_india_brokers,
|
|
27
|
+
get_market_hours,
|
|
28
|
+
get_prop_plans,
|
|
29
|
+
get_rule_changes,
|
|
30
|
+
lookup_prop_firm,
|
|
31
|
+
mcp_call,
|
|
32
|
+
read_csv,
|
|
33
|
+
to_dataframe,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
__all__ = [
|
|
37
|
+
"__version__",
|
|
38
|
+
"DEFAULT_BASE_URL",
|
|
39
|
+
"CC_BY_4_0_LICENCE",
|
|
40
|
+
"CFD_RISK_WARNING",
|
|
41
|
+
"PROP_MARKETS",
|
|
42
|
+
"TradingLookupError",
|
|
43
|
+
"TradingLookupClient",
|
|
44
|
+
"to_dataframe",
|
|
45
|
+
"get_catalog",
|
|
46
|
+
"get_prop_plans",
|
|
47
|
+
"lookup_prop_firm",
|
|
48
|
+
"compare_prop_firms",
|
|
49
|
+
"get_cfd_loss_rates",
|
|
50
|
+
"get_economic_releases",
|
|
51
|
+
"get_economic_releases_snapshot",
|
|
52
|
+
"get_market_hours",
|
|
53
|
+
"get_crypto_access",
|
|
54
|
+
"get_india_brokers",
|
|
55
|
+
"get_rule_changes",
|
|
56
|
+
"read_csv",
|
|
57
|
+
"mcp_call",
|
|
58
|
+
]
|
tradinglookup/client.py
ADDED
|
@@ -0,0 +1,856 @@
|
|
|
1
|
+
"""Zero-API-key client for TradingLookup open datasets, REST endpoints and MCP tools.
|
|
2
|
+
|
|
3
|
+
All network I/O uses Python's standard library (``urllib.request``). ``pandas`` is
|
|
4
|
+
imported lazily only when ``as_dataframe=True`` or ``to_dataframe()`` is called.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import csv
|
|
10
|
+
import inspect
|
|
11
|
+
import io
|
|
12
|
+
import json
|
|
13
|
+
import urllib.error
|
|
14
|
+
import urllib.parse
|
|
15
|
+
import urllib.request
|
|
16
|
+
from dataclasses import dataclass
|
|
17
|
+
from datetime import date, datetime
|
|
18
|
+
from typing import Any, Callable, Iterable, Mapping, Optional, Sequence
|
|
19
|
+
|
|
20
|
+
__version__ = "0.1.0"
|
|
21
|
+
|
|
22
|
+
DEFAULT_BASE_URL = "https://tradinglookup.com"
|
|
23
|
+
CC_BY_4_0_LICENCE = (
|
|
24
|
+
"CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). "
|
|
25
|
+
"Credit TradingLookup and link the source page."
|
|
26
|
+
)
|
|
27
|
+
CFD_RISK_WARNING = (
|
|
28
|
+
"CFDs are complex instruments and come with a high risk of losing money rapidly due to leverage."
|
|
29
|
+
)
|
|
30
|
+
PROP_MARKETS: tuple[str, ...] = ("futures", "forex", "crypto")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass
|
|
34
|
+
class TradingLookupError(Exception):
|
|
35
|
+
"""Raised when a TradingLookup HTTP, JSON, CSV or MCP request fails."""
|
|
36
|
+
|
|
37
|
+
message: str
|
|
38
|
+
status: Optional[int] = None
|
|
39
|
+
url: Optional[str] = None
|
|
40
|
+
body: Optional[str] = None
|
|
41
|
+
|
|
42
|
+
def __post_init__(self) -> None:
|
|
43
|
+
super().__init__(self.message)
|
|
44
|
+
|
|
45
|
+
def __str__(self) -> str:
|
|
46
|
+
return self.message
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def to_dataframe(
|
|
50
|
+
rows: Iterable[Mapping[str, Any]],
|
|
51
|
+
attrs: Optional[Mapping[str, Any]] = None,
|
|
52
|
+
) -> Any:
|
|
53
|
+
"""Convert row mappings into a ``pandas.DataFrame`` with metadata in ``df.attrs``.
|
|
54
|
+
|
|
55
|
+
Imports ``pandas`` lazily so the core package has zero required runtime
|
|
56
|
+
dependencies. Raises ``ImportError`` with installation guidance if ``pandas``
|
|
57
|
+
is not installed.
|
|
58
|
+
"""
|
|
59
|
+
try:
|
|
60
|
+
import pandas as pd
|
|
61
|
+
except ImportError as exc:
|
|
62
|
+
raise ImportError(
|
|
63
|
+
'pandas is required when as_dataframe=True. '
|
|
64
|
+
'Install it with: pip install "tradinglookup[pandas]"'
|
|
65
|
+
) from exc
|
|
66
|
+
|
|
67
|
+
df = pd.DataFrame(list(rows))
|
|
68
|
+
if attrs:
|
|
69
|
+
for key, value in attrs.items():
|
|
70
|
+
if value is not None:
|
|
71
|
+
df.attrs[key] = value
|
|
72
|
+
return df
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _validate_slug(value: str, field_name: str = "slug") -> str:
|
|
76
|
+
if not isinstance(value, str) or not value.strip():
|
|
77
|
+
raise ValueError(f"{field_name} must be a non-empty string")
|
|
78
|
+
return value.strip()
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _extract_rows(payload: Any, preferred_keys: Sequence[str]) -> list[Mapping[str, Any]]:
|
|
82
|
+
if isinstance(payload, list):
|
|
83
|
+
return [row for row in payload if isinstance(row, Mapping)]
|
|
84
|
+
if isinstance(payload, Mapping):
|
|
85
|
+
for key in preferred_keys:
|
|
86
|
+
candidate = payload.get(key)
|
|
87
|
+
if isinstance(candidate, list):
|
|
88
|
+
return [row for row in candidate if isinstance(row, Mapping)]
|
|
89
|
+
return []
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _format_param_value(value: Any) -> str:
|
|
93
|
+
if isinstance(value, bool):
|
|
94
|
+
return "true" if value else "false"
|
|
95
|
+
if isinstance(value, (datetime, date)):
|
|
96
|
+
return value.isoformat()
|
|
97
|
+
return str(value)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _filter_releases(
|
|
101
|
+
releases: Sequence[Mapping[str, Any]],
|
|
102
|
+
*,
|
|
103
|
+
currency: Optional[str] = None,
|
|
104
|
+
impact: Optional[str] = None,
|
|
105
|
+
event: Optional[str] = None,
|
|
106
|
+
from_date: Optional[str] = None,
|
|
107
|
+
limit: Optional[int] = None,
|
|
108
|
+
) -> list[Mapping[str, Any]]:
|
|
109
|
+
cur_norm = currency.strip().upper() if currency else None
|
|
110
|
+
imp_norm = impact.strip().lower() if impact else None
|
|
111
|
+
evt_norm = event.strip().lower() if event else None
|
|
112
|
+
from_norm = _format_param_value(from_date).strip() if from_date else None
|
|
113
|
+
|
|
114
|
+
filtered: list[Mapping[str, Any]] = []
|
|
115
|
+
for row in releases:
|
|
116
|
+
if cur_norm and str(row.get("currency") or "").upper() != cur_norm:
|
|
117
|
+
continue
|
|
118
|
+
if imp_norm and str(row.get("impact") or "").lower() != imp_norm:
|
|
119
|
+
continue
|
|
120
|
+
if evt_norm:
|
|
121
|
+
haystack = " ".join(
|
|
122
|
+
str(row.get(k) or "")
|
|
123
|
+
for k in ("event_slug", "event_name", "short", "agency")
|
|
124
|
+
).lower()
|
|
125
|
+
if evt_norm not in haystack:
|
|
126
|
+
continue
|
|
127
|
+
if from_norm and str(row.get("date") or "") < from_norm:
|
|
128
|
+
continue
|
|
129
|
+
filtered.append(row)
|
|
130
|
+
if limit is not None and len(filtered) >= limit:
|
|
131
|
+
break
|
|
132
|
+
return filtered
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class TradingLookupClient:
|
|
136
|
+
"""Client for TradingLookup's public open datasets, REST API and MCP server.
|
|
137
|
+
|
|
138
|
+
No API key or authentication is required. Every dataset is published under
|
|
139
|
+
CC BY 4.0 unless otherwise noted.
|
|
140
|
+
"""
|
|
141
|
+
|
|
142
|
+
def __init__(
|
|
143
|
+
self,
|
|
144
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
145
|
+
timeout: float = 20.0,
|
|
146
|
+
user_agent: Optional[str] = None,
|
|
147
|
+
opener: Optional[Any] = None,
|
|
148
|
+
) -> None:
|
|
149
|
+
self.base_url = base_url.rstrip("/")
|
|
150
|
+
self.timeout = float(timeout)
|
|
151
|
+
self.user_agent = user_agent or f"tradinglookup-python/{__version__}"
|
|
152
|
+
self.opener = opener
|
|
153
|
+
|
|
154
|
+
def _build_url(
|
|
155
|
+
self,
|
|
156
|
+
path_or_url: str,
|
|
157
|
+
params: Optional[Mapping[str, Any]] = None,
|
|
158
|
+
) -> str:
|
|
159
|
+
if path_or_url.startswith(("https://", "http://")):
|
|
160
|
+
url = path_or_url
|
|
161
|
+
else:
|
|
162
|
+
path = path_or_url if path_or_url.startswith("/") else f"/{path_or_url}"
|
|
163
|
+
url = f"{self.base_url}{path}"
|
|
164
|
+
|
|
165
|
+
if not params:
|
|
166
|
+
return url
|
|
167
|
+
|
|
168
|
+
pairs = [
|
|
169
|
+
(key, _format_param_value(val))
|
|
170
|
+
for key, val in params.items()
|
|
171
|
+
if val is not None
|
|
172
|
+
]
|
|
173
|
+
if not pairs:
|
|
174
|
+
return url
|
|
175
|
+
|
|
176
|
+
query = urllib.parse.urlencode(pairs)
|
|
177
|
+
separator = "&" if urllib.parse.urlsplit(url).query else "?"
|
|
178
|
+
return f"{url}{separator}{query}"
|
|
179
|
+
|
|
180
|
+
def _csv_url(self, path_or_url: str) -> str:
|
|
181
|
+
target = path_or_url.strip()
|
|
182
|
+
if target.startswith(("https://", "http://", "/")):
|
|
183
|
+
return self._build_url(target)
|
|
184
|
+
if target.startswith("data/"):
|
|
185
|
+
return self._build_url(f"/{target}")
|
|
186
|
+
return self._build_url(f"/data/{target}")
|
|
187
|
+
|
|
188
|
+
def _invoke_opener(self, request: urllib.request.Request) -> Any:
|
|
189
|
+
if self.opener is None:
|
|
190
|
+
return urllib.request.urlopen(request, timeout=self.timeout) # noqa: S310
|
|
191
|
+
|
|
192
|
+
open_fn: Callable[..., Any]
|
|
193
|
+
if hasattr(self.opener, "open") and callable(self.opener.open):
|
|
194
|
+
open_fn = self.opener.open
|
|
195
|
+
elif callable(self.opener):
|
|
196
|
+
open_fn = self.opener
|
|
197
|
+
else:
|
|
198
|
+
raise TypeError("opener must be callable or provide an .open() method")
|
|
199
|
+
|
|
200
|
+
try:
|
|
201
|
+
sig = inspect.signature(open_fn)
|
|
202
|
+
accepts_timeout = "timeout" in sig.parameters or any(
|
|
203
|
+
p.kind == inspect.Parameter.VAR_KEYWORD
|
|
204
|
+
for p in sig.parameters.values()
|
|
205
|
+
)
|
|
206
|
+
except (TypeError, ValueError):
|
|
207
|
+
accepts_timeout = True
|
|
208
|
+
|
|
209
|
+
if accepts_timeout:
|
|
210
|
+
return open_fn(request, timeout=self.timeout)
|
|
211
|
+
return open_fn(request)
|
|
212
|
+
|
|
213
|
+
def _request_text(
|
|
214
|
+
self,
|
|
215
|
+
url: str,
|
|
216
|
+
*,
|
|
217
|
+
method: str = "GET",
|
|
218
|
+
headers: Optional[Mapping[str, str]] = None,
|
|
219
|
+
data: Optional[bytes] = None,
|
|
220
|
+
) -> tuple[int, str]:
|
|
221
|
+
req_headers = {"User-Agent": self.user_agent}
|
|
222
|
+
if headers:
|
|
223
|
+
req_headers.update(headers)
|
|
224
|
+
request = urllib.request.Request(
|
|
225
|
+
url,
|
|
226
|
+
data=data,
|
|
227
|
+
headers=req_headers,
|
|
228
|
+
method=method,
|
|
229
|
+
)
|
|
230
|
+
try:
|
|
231
|
+
with self._invoke_opener(request) as response:
|
|
232
|
+
status = getattr(response, "status", None) or response.getcode() or 200
|
|
233
|
+
raw = response.read()
|
|
234
|
+
text = raw.decode("utf-8-sig") if isinstance(raw, (bytes, bytearray)) else str(raw)
|
|
235
|
+
return int(status), text
|
|
236
|
+
except urllib.error.HTTPError as exc:
|
|
237
|
+
body_text: Optional[str] = None
|
|
238
|
+
try:
|
|
239
|
+
raw_err = exc.read()
|
|
240
|
+
body_text = (
|
|
241
|
+
raw_err.decode("utf-8", errors="replace")
|
|
242
|
+
if isinstance(raw_err, (bytes, bytearray))
|
|
243
|
+
else str(raw_err)
|
|
244
|
+
)
|
|
245
|
+
except Exception:
|
|
246
|
+
body_text = None
|
|
247
|
+
raise TradingLookupError(
|
|
248
|
+
message=f"HTTP {exc.code} requesting {url}: {exc.reason}",
|
|
249
|
+
status=int(exc.code),
|
|
250
|
+
url=url,
|
|
251
|
+
body=body_text,
|
|
252
|
+
) from exc
|
|
253
|
+
except urllib.error.URLError as exc:
|
|
254
|
+
raise TradingLookupError(
|
|
255
|
+
message=f"Network error requesting {url}: {exc.reason}",
|
|
256
|
+
status=None,
|
|
257
|
+
url=url,
|
|
258
|
+
) from exc
|
|
259
|
+
|
|
260
|
+
def _get_json(
|
|
261
|
+
self,
|
|
262
|
+
path_or_url: str,
|
|
263
|
+
params: Optional[Mapping[str, Any]] = None,
|
|
264
|
+
) -> tuple[str, Any]:
|
|
265
|
+
url = self._build_url(path_or_url, params=params)
|
|
266
|
+
status, text = self._request_text(
|
|
267
|
+
url,
|
|
268
|
+
method="GET",
|
|
269
|
+
headers={"Accept": "application/json"},
|
|
270
|
+
)
|
|
271
|
+
try:
|
|
272
|
+
return url, json.loads(text)
|
|
273
|
+
except json.JSONDecodeError as exc:
|
|
274
|
+
raise TradingLookupError(
|
|
275
|
+
message=f"Invalid JSON response from {url}: {exc}",
|
|
276
|
+
status=status,
|
|
277
|
+
url=url,
|
|
278
|
+
body=text,
|
|
279
|
+
) from exc
|
|
280
|
+
|
|
281
|
+
def _post_json(self, path_or_url: str, payload: Mapping[str, Any]) -> tuple[str, Any]:
|
|
282
|
+
url = self._build_url(path_or_url)
|
|
283
|
+
encoded = json.dumps(payload).encode("utf-8")
|
|
284
|
+
status, text = self._request_text(
|
|
285
|
+
url,
|
|
286
|
+
method="POST",
|
|
287
|
+
headers={
|
|
288
|
+
"Accept": "application/json",
|
|
289
|
+
"Content-Type": "application/json",
|
|
290
|
+
},
|
|
291
|
+
data=encoded,
|
|
292
|
+
)
|
|
293
|
+
if not text.strip():
|
|
294
|
+
return url, {}
|
|
295
|
+
try:
|
|
296
|
+
return url, json.loads(text)
|
|
297
|
+
except json.JSONDecodeError as exc:
|
|
298
|
+
raise TradingLookupError(
|
|
299
|
+
message=f"Invalid JSON response from {url}: {exc}",
|
|
300
|
+
status=status,
|
|
301
|
+
url=url,
|
|
302
|
+
body=text,
|
|
303
|
+
) from exc
|
|
304
|
+
|
|
305
|
+
def _base_attrs(
|
|
306
|
+
self,
|
|
307
|
+
payload: Any,
|
|
308
|
+
*,
|
|
309
|
+
data_url: str,
|
|
310
|
+
default_canonical: str,
|
|
311
|
+
) -> dict[str, Any]:
|
|
312
|
+
if isinstance(payload, Mapping):
|
|
313
|
+
canonical = (
|
|
314
|
+
payload.get("canonical_url")
|
|
315
|
+
or payload.get("source_page")
|
|
316
|
+
or payload.get("facts_page")
|
|
317
|
+
or payload.get("us_page")
|
|
318
|
+
or default_canonical
|
|
319
|
+
)
|
|
320
|
+
last_checked = (
|
|
321
|
+
payload.get("last_checked")
|
|
322
|
+
or payload.get("updated")
|
|
323
|
+
or payload.get("last_read_with_change")
|
|
324
|
+
)
|
|
325
|
+
licence = payload.get("licence") or payload.get("license") or CC_BY_4_0_LICENCE
|
|
326
|
+
else:
|
|
327
|
+
canonical = default_canonical
|
|
328
|
+
last_checked = None
|
|
329
|
+
licence = CC_BY_4_0_LICENCE
|
|
330
|
+
|
|
331
|
+
return {
|
|
332
|
+
"canonical_url": canonical,
|
|
333
|
+
"last_checked": last_checked,
|
|
334
|
+
"license": licence,
|
|
335
|
+
"data_url": data_url,
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
def get_catalog(self) -> dict[str, Any]:
|
|
339
|
+
"""Fetch the master CC BY 4.0 open data catalogue from ``/data/catalog.json``."""
|
|
340
|
+
_, data = self._get_json("/data/catalog.json")
|
|
341
|
+
return data
|
|
342
|
+
|
|
343
|
+
def get_prop_plans(
|
|
344
|
+
self,
|
|
345
|
+
market: str = "futures",
|
|
346
|
+
as_dataframe: bool = False,
|
|
347
|
+
) -> Any:
|
|
348
|
+
"""Fetch priced prop firm plans and rules for ``futures``, ``forex`` or ``crypto``."""
|
|
349
|
+
norm_market = market.strip().lower() if isinstance(market, str) else ""
|
|
350
|
+
if norm_market not in PROP_MARKETS:
|
|
351
|
+
raise ValueError(
|
|
352
|
+
f"Unsupported market {market!r}; expected one of {', '.join(PROP_MARKETS)}"
|
|
353
|
+
)
|
|
354
|
+
url, data = self._get_json(f"/data/agent/prop-plans/{norm_market}.json")
|
|
355
|
+
if not as_dataframe:
|
|
356
|
+
return data
|
|
357
|
+
|
|
358
|
+
default_canonical = (
|
|
359
|
+
f"{self.base_url}/prop-firms/"
|
|
360
|
+
if norm_market == "futures"
|
|
361
|
+
else f"{self.base_url}/prop-firms/{norm_market}/"
|
|
362
|
+
)
|
|
363
|
+
attrs = self._base_attrs(data, data_url=url, default_canonical=default_canonical)
|
|
364
|
+
attrs["market"] = norm_market
|
|
365
|
+
rows = _extract_rows(data, ("plans", "rows", "data"))
|
|
366
|
+
return to_dataframe(rows, attrs=attrs)
|
|
367
|
+
|
|
368
|
+
def lookup_prop_firm(
|
|
369
|
+
self,
|
|
370
|
+
slug: str,
|
|
371
|
+
account_size: Optional[int] = None,
|
|
372
|
+
market: Optional[str] = None,
|
|
373
|
+
) -> dict[str, Any]:
|
|
374
|
+
"""Look up one prop firm's dated terms from ``/api/v1/prop-firms/{slug}``."""
|
|
375
|
+
clean_slug = _validate_slug(slug, "slug")
|
|
376
|
+
encoded_slug = urllib.parse.quote(clean_slug, safe="")
|
|
377
|
+
_, data = self._get_json(
|
|
378
|
+
f"/api/v1/prop-firms/{encoded_slug}",
|
|
379
|
+
params={"account_size": account_size, "market": market},
|
|
380
|
+
)
|
|
381
|
+
return data
|
|
382
|
+
|
|
383
|
+
def compare_prop_firms(
|
|
384
|
+
self,
|
|
385
|
+
firm_a: str,
|
|
386
|
+
firm_b: str,
|
|
387
|
+
account_size: int = 100000,
|
|
388
|
+
) -> dict[str, Any]:
|
|
389
|
+
"""Compare two prop firms side by side via ``/api/v1/prop-firms/compare``."""
|
|
390
|
+
clean_a = _validate_slug(firm_a, "firm_a")
|
|
391
|
+
clean_b = _validate_slug(firm_b, "firm_b")
|
|
392
|
+
_, data = self._get_json(
|
|
393
|
+
"/api/v1/prop-firms/compare",
|
|
394
|
+
params={
|
|
395
|
+
"firm_a": clean_a,
|
|
396
|
+
"firm_b": clean_b,
|
|
397
|
+
"account_size": account_size,
|
|
398
|
+
},
|
|
399
|
+
)
|
|
400
|
+
return data
|
|
401
|
+
|
|
402
|
+
def get_cfd_loss_rates(
|
|
403
|
+
self,
|
|
404
|
+
broker: Optional[str] = None,
|
|
405
|
+
regulator: Optional[str] = None,
|
|
406
|
+
as_dataframe: bool = False,
|
|
407
|
+
) -> Any:
|
|
408
|
+
"""Fetch retail CFD account loss rates with the mandatory FCA COBS 22.5 risk warning.
|
|
409
|
+
|
|
410
|
+
Uses ``/data/agent/cfd-loss-rates.json`` when no filters are supplied and
|
|
411
|
+
``/api/v1/cfd-loss-rates`` when ``broker`` or ``regulator`` is set.
|
|
412
|
+
"""
|
|
413
|
+
if broker is None and regulator is None:
|
|
414
|
+
url, data = self._get_json("/data/agent/cfd-loss-rates.json")
|
|
415
|
+
else:
|
|
416
|
+
url, data = self._get_json(
|
|
417
|
+
"/api/v1/cfd-loss-rates",
|
|
418
|
+
params={"broker": broker, "regulator": regulator},
|
|
419
|
+
)
|
|
420
|
+
|
|
421
|
+
if isinstance(data, dict) and not data.get("risk_warning"):
|
|
422
|
+
data["risk_warning"] = CFD_RISK_WARNING
|
|
423
|
+
|
|
424
|
+
if not as_dataframe:
|
|
425
|
+
return data
|
|
426
|
+
|
|
427
|
+
attrs = self._base_attrs(
|
|
428
|
+
data,
|
|
429
|
+
data_url=url,
|
|
430
|
+
default_canonical=f"{self.base_url}/brokers/cfd-loss-rates/",
|
|
431
|
+
)
|
|
432
|
+
attrs["risk_warning"] = (
|
|
433
|
+
data.get("risk_warning") if isinstance(data, Mapping) else None
|
|
434
|
+
) or CFD_RISK_WARNING
|
|
435
|
+
rows = _extract_rows(data, ("brokers", "rows", "data"))
|
|
436
|
+
return to_dataframe(rows, attrs=attrs)
|
|
437
|
+
|
|
438
|
+
def get_economic_releases(
|
|
439
|
+
self,
|
|
440
|
+
currency: Optional[str] = None,
|
|
441
|
+
impact: Optional[str] = None,
|
|
442
|
+
event: Optional[str] = None,
|
|
443
|
+
from_date: Optional[str] = None,
|
|
444
|
+
limit: Optional[int] = None,
|
|
445
|
+
as_dataframe: bool = False,
|
|
446
|
+
) -> Any:
|
|
447
|
+
"""Fetch scheduled central bank and macro releases from ``/api/v1/economic-calendar``."""
|
|
448
|
+
url, data = self._get_json(
|
|
449
|
+
"/api/v1/economic-calendar",
|
|
450
|
+
params={
|
|
451
|
+
"currency": currency,
|
|
452
|
+
"impact": impact,
|
|
453
|
+
"event": event,
|
|
454
|
+
"from": from_date,
|
|
455
|
+
"limit": limit,
|
|
456
|
+
},
|
|
457
|
+
)
|
|
458
|
+
if not as_dataframe:
|
|
459
|
+
return data
|
|
460
|
+
|
|
461
|
+
attrs = self._base_attrs(
|
|
462
|
+
data,
|
|
463
|
+
data_url=url,
|
|
464
|
+
default_canonical=f"{self.base_url}/economic-calendar/",
|
|
465
|
+
)
|
|
466
|
+
rows = _extract_rows(data, ("releases", "events", "rows", "data"))
|
|
467
|
+
return to_dataframe(rows, attrs=attrs)
|
|
468
|
+
|
|
469
|
+
def get_economic_releases_snapshot(
|
|
470
|
+
self,
|
|
471
|
+
currency: Optional[str] = None,
|
|
472
|
+
impact: Optional[str] = None,
|
|
473
|
+
event: Optional[str] = None,
|
|
474
|
+
from_date: Optional[str] = None,
|
|
475
|
+
limit: Optional[int] = None,
|
|
476
|
+
as_dataframe: bool = False,
|
|
477
|
+
) -> Any:
|
|
478
|
+
"""Fetch the static economic releases snapshot from ``/data/agent/economic-releases.json``."""
|
|
479
|
+
url, data = self._get_json("/data/agent/economic-releases.json")
|
|
480
|
+
releases = _extract_rows(data, ("releases", "events", "rows", "data"))
|
|
481
|
+
has_filters = any(v is not None for v in (currency, impact, event, from_date, limit))
|
|
482
|
+
if has_filters:
|
|
483
|
+
releases = _filter_releases(
|
|
484
|
+
releases,
|
|
485
|
+
currency=currency,
|
|
486
|
+
impact=impact,
|
|
487
|
+
event=event,
|
|
488
|
+
from_date=from_date,
|
|
489
|
+
limit=limit,
|
|
490
|
+
)
|
|
491
|
+
if isinstance(data, dict):
|
|
492
|
+
data = dict(data)
|
|
493
|
+
data["releases"] = releases
|
|
494
|
+
data["count"] = len(releases)
|
|
495
|
+
|
|
496
|
+
if not as_dataframe:
|
|
497
|
+
return data
|
|
498
|
+
|
|
499
|
+
attrs = self._base_attrs(
|
|
500
|
+
data,
|
|
501
|
+
data_url=url,
|
|
502
|
+
default_canonical=f"{self.base_url}/economic-calendar/",
|
|
503
|
+
)
|
|
504
|
+
return to_dataframe(releases, attrs=attrs)
|
|
505
|
+
|
|
506
|
+
def get_market_hours(
|
|
507
|
+
self,
|
|
508
|
+
exchange: Optional[str] = None,
|
|
509
|
+
at: Optional[Any] = None,
|
|
510
|
+
) -> dict[str, Any]:
|
|
511
|
+
"""Fetch live or point-in-time exchange hours from ``/api/v1/market-hours``."""
|
|
512
|
+
_, data = self._get_json(
|
|
513
|
+
"/api/v1/market-hours",
|
|
514
|
+
params={"exchange": exchange, "at": at},
|
|
515
|
+
)
|
|
516
|
+
return data
|
|
517
|
+
|
|
518
|
+
def get_crypto_access(self, as_dataframe: bool = False) -> Any:
|
|
519
|
+
"""Fetch US 50-state crypto availability and UK FCA register status."""
|
|
520
|
+
url, data = self._get_json("/data/agent/crypto-access.json")
|
|
521
|
+
if not as_dataframe:
|
|
522
|
+
return data
|
|
523
|
+
|
|
524
|
+
attrs = self._base_attrs(
|
|
525
|
+
data,
|
|
526
|
+
data_url=url,
|
|
527
|
+
default_canonical=f"{self.base_url}/crypto-exchanges/availability/",
|
|
528
|
+
)
|
|
529
|
+
if isinstance(data, Mapping) and data.get("uk_page"):
|
|
530
|
+
attrs["uk_page"] = data["uk_page"]
|
|
531
|
+
rows = _extract_rows(data, ("exchanges", "rows", "data"))
|
|
532
|
+
return to_dataframe(rows, attrs=attrs)
|
|
533
|
+
|
|
534
|
+
def get_india_brokers(self, as_dataframe: bool = False) -> Any:
|
|
535
|
+
"""Fetch Indian stockbroker fee schedules and statutory rates."""
|
|
536
|
+
url, data = self._get_json("/data/agent/india-brokers.json")
|
|
537
|
+
if not as_dataframe:
|
|
538
|
+
return data
|
|
539
|
+
|
|
540
|
+
attrs = self._base_attrs(
|
|
541
|
+
data,
|
|
542
|
+
data_url=url,
|
|
543
|
+
default_canonical=f"{self.base_url}/trading-tools/india-brokerage-calculator/",
|
|
544
|
+
)
|
|
545
|
+
if isinstance(data, Mapping) and data.get("calculator_page"):
|
|
546
|
+
attrs["calculator_page"] = data["calculator_page"]
|
|
547
|
+
rows = _extract_rows(data, ("brokers", "rows", "data"))
|
|
548
|
+
return to_dataframe(rows, attrs=attrs)
|
|
549
|
+
|
|
550
|
+
def get_rule_changes(
|
|
551
|
+
self,
|
|
552
|
+
slug: Optional[str] = None,
|
|
553
|
+
as_dataframe: bool = False,
|
|
554
|
+
) -> Any:
|
|
555
|
+
"""Fetch recorded prop firm rule and price changes (index or one firm)."""
|
|
556
|
+
if slug is None:
|
|
557
|
+
url, data = self._get_json("/data/agent/rule-changes.json")
|
|
558
|
+
row_keys: tuple[str, ...] = ("firms", "rows", "data")
|
|
559
|
+
default_canonical = f"{self.base_url}/prop-firms/changes/"
|
|
560
|
+
else:
|
|
561
|
+
clean_slug = _validate_slug(slug, "slug")
|
|
562
|
+
encoded_slug = urllib.parse.quote(clean_slug, safe="")
|
|
563
|
+
url, data = self._get_json(f"/data/agent/rule-changes/{encoded_slug}.json")
|
|
564
|
+
row_keys = ("changes", "rows", "data")
|
|
565
|
+
default_canonical = f"{self.base_url}/prop-firms/changes/{encoded_slug}/"
|
|
566
|
+
|
|
567
|
+
if not as_dataframe:
|
|
568
|
+
return data
|
|
569
|
+
|
|
570
|
+
attrs = self._base_attrs(data, data_url=url, default_canonical=default_canonical)
|
|
571
|
+
if isinstance(data, Mapping):
|
|
572
|
+
if data.get("changes_page"):
|
|
573
|
+
attrs["canonical_url"] = data["changes_page"]
|
|
574
|
+
if data.get("firm"):
|
|
575
|
+
attrs["firm"] = data["firm"]
|
|
576
|
+
if data.get("slug"):
|
|
577
|
+
attrs["slug"] = data["slug"]
|
|
578
|
+
rows = _extract_rows(data, row_keys)
|
|
579
|
+
return to_dataframe(rows, attrs=attrs)
|
|
580
|
+
|
|
581
|
+
def read_csv(
|
|
582
|
+
self,
|
|
583
|
+
path_or_url: str,
|
|
584
|
+
as_dataframe: bool = False,
|
|
585
|
+
) -> Any:
|
|
586
|
+
"""Download and parse any published TradingLookup CSV file under ``/data/``."""
|
|
587
|
+
if not isinstance(path_or_url, str) or not path_or_url.strip():
|
|
588
|
+
raise ValueError("path_or_url must be a non-empty string")
|
|
589
|
+
url = self._csv_url(path_or_url)
|
|
590
|
+
_, text = self._request_text(
|
|
591
|
+
url,
|
|
592
|
+
method="GET",
|
|
593
|
+
headers={"Accept": "text/csv, text/plain;q=0.9"},
|
|
594
|
+
)
|
|
595
|
+
reader = csv.DictReader(io.StringIO(text))
|
|
596
|
+
rows = [dict(row) for row in reader]
|
|
597
|
+
if not as_dataframe:
|
|
598
|
+
return rows
|
|
599
|
+
|
|
600
|
+
attrs: dict[str, Any] = {
|
|
601
|
+
"canonical_url": f"{self.base_url}/data/",
|
|
602
|
+
"data_url": url,
|
|
603
|
+
"license": CC_BY_4_0_LICENCE,
|
|
604
|
+
}
|
|
605
|
+
if "cfd" in url.lower():
|
|
606
|
+
attrs["risk_warning"] = CFD_RISK_WARNING
|
|
607
|
+
return to_dataframe(rows, attrs=attrs)
|
|
608
|
+
|
|
609
|
+
def mcp_call(
|
|
610
|
+
self,
|
|
611
|
+
tool_name: str,
|
|
612
|
+
arguments: Optional[Mapping[str, Any]] = None,
|
|
613
|
+
directory_mode: bool = False,
|
|
614
|
+
request_id: int | str = 1,
|
|
615
|
+
) -> Any:
|
|
616
|
+
"""Invoke a read-only MCP tool via JSON-RPC 2.0 on ``/mcp`` or ``/mcp/directory``."""
|
|
617
|
+
clean_tool = _validate_slug(tool_name, "tool_name")
|
|
618
|
+
endpoint = "/mcp/directory" if directory_mode else "/mcp"
|
|
619
|
+
rpc_request = {
|
|
620
|
+
"jsonrpc": "2.0",
|
|
621
|
+
"id": request_id,
|
|
622
|
+
"method": "tools/call",
|
|
623
|
+
"params": {
|
|
624
|
+
"name": clean_tool,
|
|
625
|
+
"arguments": dict(arguments) if arguments is not None else {},
|
|
626
|
+
},
|
|
627
|
+
}
|
|
628
|
+
url, response = self._post_json(endpoint, rpc_request)
|
|
629
|
+
if not isinstance(response, Mapping):
|
|
630
|
+
raise TradingLookupError(
|
|
631
|
+
message=f"Unexpected MCP response shape from {url}",
|
|
632
|
+
url=url,
|
|
633
|
+
)
|
|
634
|
+
if "error" in response and response["error"] is not None:
|
|
635
|
+
err = response["error"]
|
|
636
|
+
code = err.get("code") if isinstance(err, Mapping) else None
|
|
637
|
+
err_msg = err.get("message") if isinstance(err, Mapping) else str(err)
|
|
638
|
+
raise TradingLookupError(
|
|
639
|
+
message=f"MCP error ({code}): {err_msg}" if code is not None else f"MCP error: {err_msg}",
|
|
640
|
+
url=url,
|
|
641
|
+
body=json.dumps(err),
|
|
642
|
+
)
|
|
643
|
+
|
|
644
|
+
result = response.get("result")
|
|
645
|
+
if not isinstance(result, Mapping):
|
|
646
|
+
return result
|
|
647
|
+
|
|
648
|
+
structured = result.get("structuredContent")
|
|
649
|
+
if result.get("isError"):
|
|
650
|
+
detail = (
|
|
651
|
+
structured.get("error")
|
|
652
|
+
if isinstance(structured, Mapping) and structured.get("error")
|
|
653
|
+
else None
|
|
654
|
+
)
|
|
655
|
+
if not detail:
|
|
656
|
+
content = result.get("content")
|
|
657
|
+
if isinstance(content, list) and content and isinstance(content[0], Mapping):
|
|
658
|
+
detail = content[0].get("text")
|
|
659
|
+
raise TradingLookupError(
|
|
660
|
+
message=f"MCP tool {clean_tool!r} failed: {detail or 'unknown error'}",
|
|
661
|
+
url=url,
|
|
662
|
+
body=json.dumps(result),
|
|
663
|
+
)
|
|
664
|
+
|
|
665
|
+
if structured is not None:
|
|
666
|
+
return structured
|
|
667
|
+
|
|
668
|
+
content = result.get("content")
|
|
669
|
+
if isinstance(content, list) and len(content) == 1 and isinstance(content[0], Mapping):
|
|
670
|
+
text = content[0].get("text")
|
|
671
|
+
if isinstance(text, str):
|
|
672
|
+
try:
|
|
673
|
+
return json.loads(text)
|
|
674
|
+
except json.JSONDecodeError:
|
|
675
|
+
return text
|
|
676
|
+
|
|
677
|
+
return dict(result)
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
_DEFAULT_CLIENT: Optional[TradingLookupClient] = None
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
def _resolve_client(client: Optional[TradingLookupClient]) -> TradingLookupClient:
|
|
684
|
+
global _DEFAULT_CLIENT
|
|
685
|
+
if client is not None:
|
|
686
|
+
return client
|
|
687
|
+
if _DEFAULT_CLIENT is None:
|
|
688
|
+
_DEFAULT_CLIENT = TradingLookupClient()
|
|
689
|
+
return _DEFAULT_CLIENT
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
def get_catalog(*, client: Optional[TradingLookupClient] = None) -> dict[str, Any]:
|
|
693
|
+
"""Fetch the master CC BY 4.0 open data catalogue."""
|
|
694
|
+
return _resolve_client(client).get_catalog()
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+
def get_prop_plans(
|
|
698
|
+
market: str = "futures",
|
|
699
|
+
as_dataframe: bool = False,
|
|
700
|
+
*,
|
|
701
|
+
client: Optional[TradingLookupClient] = None,
|
|
702
|
+
) -> Any:
|
|
703
|
+
"""Fetch priced prop firm plans and rules for one market."""
|
|
704
|
+
return _resolve_client(client).get_prop_plans(market=market, as_dataframe=as_dataframe)
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
def lookup_prop_firm(
|
|
708
|
+
slug: str,
|
|
709
|
+
account_size: Optional[int] = None,
|
|
710
|
+
market: Optional[str] = None,
|
|
711
|
+
*,
|
|
712
|
+
client: Optional[TradingLookupClient] = None,
|
|
713
|
+
) -> dict[str, Any]:
|
|
714
|
+
"""Look up one prop firm's dated terms."""
|
|
715
|
+
return _resolve_client(client).lookup_prop_firm(
|
|
716
|
+
slug=slug,
|
|
717
|
+
account_size=account_size,
|
|
718
|
+
market=market,
|
|
719
|
+
)
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
def compare_prop_firms(
|
|
723
|
+
firm_a: str,
|
|
724
|
+
firm_b: str,
|
|
725
|
+
account_size: int = 100000,
|
|
726
|
+
*,
|
|
727
|
+
client: Optional[TradingLookupClient] = None,
|
|
728
|
+
) -> dict[str, Any]:
|
|
729
|
+
"""Compare two prop firms side by side."""
|
|
730
|
+
return _resolve_client(client).compare_prop_firms(
|
|
731
|
+
firm_a=firm_a,
|
|
732
|
+
firm_b=firm_b,
|
|
733
|
+
account_size=account_size,
|
|
734
|
+
)
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
def get_cfd_loss_rates(
|
|
738
|
+
broker: Optional[str] = None,
|
|
739
|
+
regulator: Optional[str] = None,
|
|
740
|
+
as_dataframe: bool = False,
|
|
741
|
+
*,
|
|
742
|
+
client: Optional[TradingLookupClient] = None,
|
|
743
|
+
) -> Any:
|
|
744
|
+
"""Fetch retail CFD account loss rates with the mandatory FCA COBS 22.5 risk warning."""
|
|
745
|
+
return _resolve_client(client).get_cfd_loss_rates(
|
|
746
|
+
broker=broker,
|
|
747
|
+
regulator=regulator,
|
|
748
|
+
as_dataframe=as_dataframe,
|
|
749
|
+
)
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
def get_economic_releases(
|
|
753
|
+
currency: Optional[str] = None,
|
|
754
|
+
impact: Optional[str] = None,
|
|
755
|
+
event: Optional[str] = None,
|
|
756
|
+
from_date: Optional[str] = None,
|
|
757
|
+
limit: Optional[int] = None,
|
|
758
|
+
as_dataframe: bool = False,
|
|
759
|
+
*,
|
|
760
|
+
client: Optional[TradingLookupClient] = None,
|
|
761
|
+
) -> Any:
|
|
762
|
+
"""Fetch scheduled central bank and macro economic releases."""
|
|
763
|
+
return _resolve_client(client).get_economic_releases(
|
|
764
|
+
currency=currency,
|
|
765
|
+
impact=impact,
|
|
766
|
+
event=event,
|
|
767
|
+
from_date=from_date,
|
|
768
|
+
limit=limit,
|
|
769
|
+
as_dataframe=as_dataframe,
|
|
770
|
+
)
|
|
771
|
+
|
|
772
|
+
|
|
773
|
+
def get_economic_releases_snapshot(
|
|
774
|
+
currency: Optional[str] = None,
|
|
775
|
+
impact: Optional[str] = None,
|
|
776
|
+
event: Optional[str] = None,
|
|
777
|
+
from_date: Optional[str] = None,
|
|
778
|
+
limit: Optional[int] = None,
|
|
779
|
+
as_dataframe: bool = False,
|
|
780
|
+
*,
|
|
781
|
+
client: Optional[TradingLookupClient] = None,
|
|
782
|
+
) -> Any:
|
|
783
|
+
"""Fetch the static economic releases JSON snapshot."""
|
|
784
|
+
return _resolve_client(client).get_economic_releases_snapshot(
|
|
785
|
+
currency=currency,
|
|
786
|
+
impact=impact,
|
|
787
|
+
event=event,
|
|
788
|
+
from_date=from_date,
|
|
789
|
+
limit=limit,
|
|
790
|
+
as_dataframe=as_dataframe,
|
|
791
|
+
)
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
def get_market_hours(
|
|
795
|
+
exchange: Optional[str] = None,
|
|
796
|
+
at: Optional[Any] = None,
|
|
797
|
+
*,
|
|
798
|
+
client: Optional[TradingLookupClient] = None,
|
|
799
|
+
) -> dict[str, Any]:
|
|
800
|
+
"""Fetch live or point-in-time exchange hours."""
|
|
801
|
+
return _resolve_client(client).get_market_hours(exchange=exchange, at=at)
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
def get_crypto_access(
|
|
805
|
+
as_dataframe: bool = False,
|
|
806
|
+
*,
|
|
807
|
+
client: Optional[TradingLookupClient] = None,
|
|
808
|
+
) -> Any:
|
|
809
|
+
"""Fetch US 50-state crypto availability and UK FCA register status."""
|
|
810
|
+
return _resolve_client(client).get_crypto_access(as_dataframe=as_dataframe)
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
def get_india_brokers(
|
|
814
|
+
as_dataframe: bool = False,
|
|
815
|
+
*,
|
|
816
|
+
client: Optional[TradingLookupClient] = None,
|
|
817
|
+
) -> Any:
|
|
818
|
+
"""Fetch Indian stockbroker fee schedules and statutory charges."""
|
|
819
|
+
return _resolve_client(client).get_india_brokers(as_dataframe=as_dataframe)
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
def get_rule_changes(
|
|
823
|
+
slug: Optional[str] = None,
|
|
824
|
+
as_dataframe: bool = False,
|
|
825
|
+
*,
|
|
826
|
+
client: Optional[TradingLookupClient] = None,
|
|
827
|
+
) -> Any:
|
|
828
|
+
"""Fetch recorded prop firm rule and price changes."""
|
|
829
|
+
return _resolve_client(client).get_rule_changes(slug=slug, as_dataframe=as_dataframe)
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
def read_csv(
|
|
833
|
+
path_or_url: str,
|
|
834
|
+
as_dataframe: bool = False,
|
|
835
|
+
*,
|
|
836
|
+
client: Optional[TradingLookupClient] = None,
|
|
837
|
+
) -> Any:
|
|
838
|
+
"""Download and parse any published TradingLookup CSV file."""
|
|
839
|
+
return _resolve_client(client).read_csv(path_or_url=path_or_url, as_dataframe=as_dataframe)
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
def mcp_call(
|
|
843
|
+
tool_name: str,
|
|
844
|
+
arguments: Optional[Mapping[str, Any]] = None,
|
|
845
|
+
directory_mode: bool = False,
|
|
846
|
+
request_id: int | str = 1,
|
|
847
|
+
*,
|
|
848
|
+
client: Optional[TradingLookupClient] = None,
|
|
849
|
+
) -> Any:
|
|
850
|
+
"""Invoke a read-only MCP tool via JSON-RPC 2.0 on ``/mcp`` or ``/mcp/directory``."""
|
|
851
|
+
return _resolve_client(client).mcp_call(
|
|
852
|
+
tool_name=tool_name,
|
|
853
|
+
arguments=arguments,
|
|
854
|
+
directory_mode=directory_mode,
|
|
855
|
+
request_id=request_id,
|
|
856
|
+
)
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tradinglookup
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Zero-API-key Python SDK for TradingLookup CC BY 4.0 open financial datasets, REST API endpoints and MCP tools.
|
|
5
|
+
Author: TradingLookup
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://tradinglookup.com
|
|
8
|
+
Project-URL: Documentation, https://tradinglookup.readthedocs.io/
|
|
9
|
+
Project-URL: Source, https://github.com/tradinglookup/tradinglookup
|
|
10
|
+
Project-URL: OpenAPI, https://tradinglookup.com/openapi.json
|
|
11
|
+
Project-URL: Data, https://tradinglookup.com/data/
|
|
12
|
+
Keywords: tradinglookup,prop-firms,cfd-loss-rates,economic-calendar,market-hours,crypto-exchanges,india-brokers,open-data,mcp
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Provides-Extra: pandas
|
|
25
|
+
Requires-Dist: pandas>=2.0; extra == "pandas"
|
|
26
|
+
Provides-Extra: docs
|
|
27
|
+
Requires-Dist: mkdocs>=1.6; extra == "docs"
|
|
28
|
+
Requires-Dist: mkdocs-material>=9.5; extra == "docs"
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# tradinglookup
|
|
34
|
+
|
|
35
|
+
Zero-API-key Python SDK for TradingLookup open financial data, REST endpoints and read-only MCP tools.
|
|
36
|
+
|
|
37
|
+
- **No API key, no account, no required third-party dependencies** (Python 3.9+ standard library only).
|
|
38
|
+
- **Optional pandas support** via `pip install "tradinglookup[pandas]"`.
|
|
39
|
+
- **Open data hub:** <https://tradinglookup.com/data/>
|
|
40
|
+
- **AI & machine access guide:** <https://tradinglookup.com/for-ai-agents/>
|
|
41
|
+
- **Documentation:** <https://tradinglookup.readthedocs.io/>
|
|
42
|
+
|
|
43
|
+
## Install
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install tradinglookup
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
With optional pandas `DataFrame` support:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install "tradinglookup[pandas]"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Quickstart
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
import tradinglookup as tl
|
|
59
|
+
|
|
60
|
+
# Discover all CC BY 4.0 datasets
|
|
61
|
+
catalog = tl.get_catalog()
|
|
62
|
+
|
|
63
|
+
# Compare two futures prop firms at $100,000
|
|
64
|
+
comparison = tl.compare_prop_firms("ftmo", "fundednext", account_size=100000)
|
|
65
|
+
|
|
66
|
+
# Look up one prop firm's terms
|
|
67
|
+
firm = tl.lookup_prop_firm("topstep", market="futures")
|
|
68
|
+
|
|
69
|
+
# Fetch retail CFD account loss rates (includes mandatory FCA COBS 22.5 warning)
|
|
70
|
+
cfd = tl.get_cfd_loss_rates()
|
|
71
|
+
print(cfd["risk_warning"])
|
|
72
|
+
|
|
73
|
+
# Check live market hours or scheduled central bank / macro releases
|
|
74
|
+
hours = tl.get_market_hours(exchange="nyse")
|
|
75
|
+
releases = tl.get_economic_releases(currency="USD", impact="high", limit=10)
|
|
76
|
+
|
|
77
|
+
# Call TradingLookup's read-only MCP endpoint directly
|
|
78
|
+
result = tl.mcp_call("is_market_open", {"exchange": "lse"})
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Using a reusable client instance:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from tradinglookup import TradingLookupClient
|
|
85
|
+
|
|
86
|
+
client = TradingLookupClient(timeout=15.0)
|
|
87
|
+
plans = client.get_prop_plans(market="futures")
|
|
88
|
+
changes = client.get_rule_changes("topstep")
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Pandas DataFrames
|
|
92
|
+
|
|
93
|
+
Tabular helpers accept `as_dataframe=True`, returning a `pandas.DataFrame` with `canonical_url`, `last_checked`, `license` (and `risk_warning` for CFD datasets) preserved in `df.attrs`:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
import tradinglookup as tl
|
|
97
|
+
|
|
98
|
+
df = tl.get_cfd_loss_rates(as_dataframe=True)
|
|
99
|
+
print(df[["broker", "loss_pct", "regulator"]].head())
|
|
100
|
+
print(df.attrs["risk_warning"])
|
|
101
|
+
print(df.attrs["canonical_url"])
|
|
102
|
+
|
|
103
|
+
# Or load any published CSV directly from /data/
|
|
104
|
+
csv_df = tl.read_csv("/data/cfd-loss-rates-live.csv", as_dataframe=True)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## CFD risk warning (FCA COBS 22.5)
|
|
108
|
+
|
|
109
|
+
Whenever you display or redistribute retail CFD loss-rate figures from TradingLookup, include the FCA COBS 22.5 risk warning verbatim:
|
|
110
|
+
|
|
111
|
+
> CFDs are complex instruments and come with a high risk of losing money rapidly due to leverage.
|
|
112
|
+
|
|
113
|
+
## Licence and attribution (CC BY 4.0)
|
|
114
|
+
|
|
115
|
+
- **SDK code:** MIT Licence (see [LICENSE](LICENSE)).
|
|
116
|
+
- **Data:** Creative Commons Attribution 4.0 International ([CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)). When you publish, display or redistribute figures from TradingLookup, credit **TradingLookup** and link to the canonical dataset or facts page (for example <https://tradinglookup.com/data/>).
|
|
117
|
+
|
|
118
|
+
Every figure is read from each firm's or official body's own published pages on the date shown. This is reference data, not financial or trading advice.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
tradinglookup/__init__.py,sha256=ZTHoJm7pxL-gWHoubeB6hoye1hxqe14wsi0jgAiOxAM,1308
|
|
2
|
+
tradinglookup/client.py,sha256=i59MOX1HSXo_On2ayc6E2vXX0VyB1Q5ThMMj_MjB_oM,29065
|
|
3
|
+
tradinglookup-0.1.0.dist-info/licenses/LICENSE,sha256=NleeEf_4pXfqLoRzl1fkZe9l3mEF22hgDWCfClclOsA,1301
|
|
4
|
+
tradinglookup-0.1.0.dist-info/METADATA,sha256=Tz3xfl4xJLDh05h_QPqGGi0qz8cQkQtPAMOSE4YELOw,4422
|
|
5
|
+
tradinglookup-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
6
|
+
tradinglookup-0.1.0.dist-info/top_level.txt,sha256=9ytyTUk4eqSPgirWCue6BvEE-Km4u8ZWMDckzcv3iS8,14
|
|
7
|
+
tradinglookup-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TradingLookup
|
|
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.
|
|
22
|
+
|
|
23
|
+
The TradingLookup datasets accessed by this SDK (https://tradinglookup.com/data/)
|
|
24
|
+
are published separately under the Creative Commons Attribution 4.0 International
|
|
25
|
+
Licence (CC BY 4.0): https://creativecommons.org/licenses/by/4.0/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tradinglookup
|