fix: resolve 6 warning issues from code review
5. Add daily PnL reset loop — UTC midnight auto-reset via
_daily_reset_loop in main.py, prevents stale daily_pnl accumulation
6. Fix set_base_balance race condition — call once in main.py before
spawning bots, instead of each bot calling independently
7. Remove realized_pnl != 0 from close detection — prevents entry
orders with small rp values being misclassified as closes
8. Rename xrp_btc_rs/xrp_eth_rs → primary_btc_rs/primary_eth_rs —
generic column names for multi-symbol support (dataset_builder,
ml_features, and tests updated consistently)
9. Replace asyncio.get_event_loop() → get_running_loop() — fixes
DeprecationWarning on Python 3.10+
10. Parallelize candle preload — asyncio.gather for all symbols
instead of sequential REST calls, ~3x faster startup
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -161,26 +161,31 @@ class MultiSymbolStream:
|
||||
df.set_index("timestamp", inplace=True)
|
||||
return df
|
||||
|
||||
async def _preload_one(self, client: AsyncClient, symbol: str, limit: int):
|
||||
"""단일 심볼의 과거 캔들을 버퍼에 채운다."""
|
||||
logger.info(f"{symbol.upper()} 과거 캔들 {limit}개 로드 중...")
|
||||
klines = await client.futures_klines(
|
||||
symbol=symbol.upper(),
|
||||
interval=self.interval,
|
||||
limit=limit,
|
||||
)
|
||||
for k in klines[:-1]:
|
||||
self.buffers[symbol].append({
|
||||
"timestamp": k[0],
|
||||
"open": float(k[1]),
|
||||
"high": float(k[2]),
|
||||
"low": float(k[3]),
|
||||
"close": float(k[4]),
|
||||
"volume": float(k[5]),
|
||||
"is_closed": True,
|
||||
})
|
||||
logger.info(f"{symbol.upper()} {len(self.buffers[symbol])}개 로드 완료")
|
||||
|
||||
async def _preload_history(self, client: AsyncClient, limit: int = _PRELOAD_LIMIT):
|
||||
"""REST API로 모든 심볼의 과거 캔들을 버퍼에 미리 채운다."""
|
||||
for symbol in self.symbols:
|
||||
logger.info(f"{symbol.upper()} 과거 캔들 {limit}개 로드 중...")
|
||||
klines = await client.futures_klines(
|
||||
symbol=symbol.upper(),
|
||||
interval=self.interval,
|
||||
limit=limit,
|
||||
)
|
||||
for k in klines[:-1]:
|
||||
self.buffers[symbol].append({
|
||||
"timestamp": k[0],
|
||||
"open": float(k[1]),
|
||||
"high": float(k[2]),
|
||||
"low": float(k[3]),
|
||||
"close": float(k[4]),
|
||||
"volume": float(k[5]),
|
||||
"is_closed": True,
|
||||
})
|
||||
logger.info(f"{symbol.upper()} {len(self.buffers[symbol])}개 로드 완료")
|
||||
"""REST API로 모든 심볼의 과거 캔들을 병렬로 버퍼에 미리 채운다."""
|
||||
await asyncio.gather(*[
|
||||
self._preload_one(client, symbol, limit) for symbol in self.symbols
|
||||
])
|
||||
|
||||
async def start(self, api_key: str, api_secret: str):
|
||||
client = await AsyncClient.create(
|
||||
|
||||
Reference in New Issue
Block a user