fix: _on_candle_closed async 콜백 구조 수정 — asyncio.create_task 제거
동기 콜백 내부에서 asyncio.create_task()를 호출하면 이벤트 루프 컨텍스트 밖에서 실패하여 캔들 처리가 전혀 이루어지지 않는 버그 수정. - _on_candle_closed: 동기 → async, create_task → await - handle_message (KlineStream/MultiSymbolStream): 동기 → async, on_candle await - test_callback_called_on_closed_candle: AsyncMock + await handle_message로 수정 Made-with: Cursor
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import asyncio
|
||||
import pandas as pd
|
||||
from loguru import logger
|
||||
from src.config import Config
|
||||
@@ -25,12 +24,12 @@ class TradingBot:
|
||||
on_candle=self._on_candle_closed,
|
||||
)
|
||||
|
||||
def _on_candle_closed(self, candle: dict):
|
||||
async def _on_candle_closed(self, candle: dict):
|
||||
xrp_df = self.stream.get_dataframe(self.config.symbol)
|
||||
btc_df = self.stream.get_dataframe("BTCUSDT")
|
||||
eth_df = self.stream.get_dataframe("ETHUSDT")
|
||||
if xrp_df is not None:
|
||||
asyncio.create_task(self.process_candle(xrp_df, btc_df=btc_df, eth_df=eth_df))
|
||||
await self.process_candle(xrp_df, btc_df=btc_df, eth_df=eth_df)
|
||||
|
||||
async def _recover_position(self) -> None:
|
||||
"""재시작 시 바이낸스에서 현재 포지션을 조회하여 상태 복구."""
|
||||
|
||||
Reference in New Issue
Block a user