Initial commit
This commit is contained in:
95
backend/test/wind_data_probe.py
Normal file
95
backend/test/wind_data_probe.py
Normal file
@ -0,0 +1,95 @@
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
API_ENDPOINTS = [
|
||||
{
|
||||
"name": "institutions",
|
||||
"description": "Main/Institution vs retail capital flow summary.",
|
||||
"path": "/data/v1/api/moneyflow/getMoneyFlow.json",
|
||||
"params": {
|
||||
"tradeDate": None,
|
||||
"field": "tradeDate,secID,instNetFlow,retailNetFlow,instBuyCash,instSellCash",
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "blocks",
|
||||
"description": "Block/sector capital inflows and outflows.",
|
||||
"path": "/data/v1/api/moneyflow/getBlockMoneyFlow.json",
|
||||
"params": {
|
||||
"tradeDate": None,
|
||||
"field": "tradeDate,industryName,blockNetFlow,blockBuyCash,blockSellCash",
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "indices",
|
||||
"description": "Broad index capital flow overview.",
|
||||
"path": "/data/v1/api/moneyflow/getIndexMoneyFlow.json",
|
||||
"params": {
|
||||
"tradeDate": None,
|
||||
"field": "tradeDate,indexName,indexNetFlow,indexBuyCash,indexSellCash",
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def probe_endpoint(
|
||||
base_url: str, token: str | None, endpoint: dict[str, Any], default_trade_date: str
|
||||
) -> dict[str, Any]:
|
||||
params = {**endpoint["params"]}
|
||||
params["tradeDate"] = params["tradeDate"] or default_trade_date
|
||||
url = f"{base_url}{endpoint['path']}"
|
||||
headers = {}
|
||||
if token:
|
||||
headers["Authorization"] = f"Bearer {token}"
|
||||
response = requests.get(url, headers=headers, params=params, timeout=20)
|
||||
try:
|
||||
body = response.json()
|
||||
except ValueError:
|
||||
body = response.text
|
||||
|
||||
return {
|
||||
"name": endpoint["name"],
|
||||
"url": url,
|
||||
"params": params,
|
||||
"status_code": response.status_code,
|
||||
"headers": dict(response.headers),
|
||||
"body": body,
|
||||
"description": endpoint["description"],
|
||||
}
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description="Probe Wind/WMCloud capital flow endpoints.")
|
||||
parser.add_argument("--trade-date", default="2026-03-19")
|
||||
parser.add_argument("--out", default="probe_results.json")
|
||||
parser.add_argument("--base-url", default="https://api.wmcloud.com")
|
||||
args = parser.parse_args()
|
||||
|
||||
token = os.environ.get("WIND_API_TOKEN")
|
||||
results: list[dict[str, Any]] = []
|
||||
|
||||
for endpoint in API_ENDPOINTS:
|
||||
try:
|
||||
result = probe_endpoint(args.base_url, token, endpoint, args.trade_date)
|
||||
except requests.RequestException as exc:
|
||||
result = {
|
||||
"name": endpoint["name"],
|
||||
"description": endpoint["description"],
|
||||
"error": str(exc),
|
||||
"url": f"{args.base_url}{endpoint['path']}",
|
||||
}
|
||||
results.append(result)
|
||||
|
||||
out_path = Path(__file__).resolve().parent / args.out
|
||||
out_path.write_text(json.dumps(results, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
print(out_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user