fix: map interval to DB format and add 'No candles found' status (v1.3.2)
This commit is contained in:
@ -68,7 +68,7 @@ class DatabaseManager:
|
||||
|
||||
class PingPongBot:
|
||||
def __init__(self, config_path="config/ping_pong_config.yaml"):
|
||||
self.version = "1.3.1"
|
||||
self.version = "1.3.2"
|
||||
with open(config_path, 'r') as f:
|
||||
self.config = yaml.safe_load(f)
|
||||
|
||||
@ -89,6 +89,9 @@ class PingPongBot:
|
||||
self.symbol = self.config['symbol'].upper() # e.g. BTCUSDT
|
||||
self.db_symbol = self.symbol.replace("USDT", "") # e.g. BTC
|
||||
self.interval = str(self.config['interval'])
|
||||
# Map interval to DB format: '1' -> '1m'
|
||||
self.db_interval = self.interval + "m" if self.interval.isdigit() else self.interval
|
||||
|
||||
self.direction = self.config['direction'].lower()
|
||||
|
||||
# State
|
||||
@ -164,7 +167,13 @@ class PingPongBot:
|
||||
# 3. Balance
|
||||
wallet = self.session.get_wallet_balance(category="linear", accountType="UNIFIED", coin="USDT")
|
||||
if wallet['retCode'] == 0:
|
||||
self.wallet_balance = float(wallet['result']['list'][0].get('totalWalletBalance', 0))
|
||||
result_list = wallet_response = wallet['result']['list']
|
||||
if result_list:
|
||||
self.wallet_balance = float(result_list[0].get('totalWalletBalance', 0))
|
||||
if self.wallet_balance == 0:
|
||||
coin_info = result_list[0].get('coin', [])
|
||||
if coin_info:
|
||||
self.wallet_balance = float(coin_info[0].get('walletBalance', 0))
|
||||
except Exception as e:
|
||||
logger.error(f"Exchange Sync Error: {e}")
|
||||
|
||||
@ -257,7 +266,7 @@ class PingPongBot:
|
||||
last_exchange_update = now
|
||||
|
||||
# 2. DB Sync (5s)
|
||||
candles = await self.db.get_candles(self.db_symbol, self.interval, limit=100)
|
||||
candles = await self.db.get_candles(self.db_symbol, self.db_interval, limit=100)
|
||||
if candles:
|
||||
latest = candles[0]
|
||||
if latest['time'] != self.last_candle_time:
|
||||
@ -268,6 +277,8 @@ class PingPongBot:
|
||||
self.last_candle_time = latest['time']
|
||||
self.last_candle_price = latest['close']
|
||||
self.status_msg = f"New Candle processed: {latest['time']}"
|
||||
else:
|
||||
self.status_msg = f"No candles found for {self.db_symbol} / {self.db_interval}"
|
||||
|
||||
self.render_dashboard()
|
||||
await asyncio.sleep(5)
|
||||
|
||||
Reference in New Issue
Block a user