diff --git a/backend/market_data_collector.py b/backend/market_data_collector.py index 0c6af9c..d808cd7 100644 --- a/backend/market_data_collector.py +++ b/backend/market_data_collector.py @@ -135,12 +135,22 @@ class MarketDataCollector: } self.save_indicator(symbol, "coinbase_premium", ts, payload) + async def collect_funding_rate(self, session: aiohttp.ClientSession, symbol: str) -> None: + endpoint = "https://fapi.binance.com/fapi/v1/fundingRate" + data = await self.fetch_json(session, endpoint, {"symbol": symbol, "limit": 1}) + if not data: + raise RuntimeError("empty response") + item = data[0] + ts = int(item.get("fundingTime") or int(time.time() * 1000)) + self.save_indicator(symbol, "funding_rate", ts, item) + async def collect_symbol(self, session: aiohttp.ClientSession, symbol: str) -> None: tasks = [ ("long_short_ratio", self.collect_long_short_ratio(session, symbol)), ("top_trader_position", self.collect_top_trader_position(session, symbol)), ("open_interest_hist", self.collect_open_interest_hist(session, symbol)), ("coinbase_premium", self.collect_coinbase_premium(session, symbol)), + ("funding_rate", self.collect_funding_rate(session, symbol)), ] results = await asyncio.gather(*(t[1] for t in tasks), return_exceptions=True)