-
Notifications
You must be signed in to change notification settings - Fork 133
Description
I got the proken price issue while getting usdt balance through mexc sdk
code is below
def get_usdt_balance(max_retries=3, retry_delay=1):
"""현물 계정의 사용 가능한 USDT 잔고 조회 (재시도 및 클라이언트 재초기화 로직 추가)"""
global mexc_client # 전역 변수 mexc_client를 수정하기 위해 global 키워드 사용
for attempt in range(max_retries):
try:
account_info = mexc_client.account_info()
for balance in account_info.get('balances', []):
if balance['asset'] == 'USDT':
return float(balance['free'])
logging.warning("계정 정보에서 USDT 잔고를 찾을 수 없습니다.")
return 0.0
except Exception as e:
logging.error(f"USDT 잔고 조회 중 에러 발생 (시도 {attempt + 1}/{max_retries}): {e}")
if attempt < max_retries - 1:
logging.info(f"MEXC 클라이언트를 재초기화하고 {retry_delay}초 후 재시도합니다.")
try:
mexc_client = Spot(api_key=API_KEY, api_secret=API_SECRET) # 클라이언트 재초기화
except Exception as client_init_e: # 모든 종류의 예외를 잡도록 변경 (JSONDecodeError 포함)
logging.error(f"MEXC 클라이언트 재초기화 중 에러 발생: {client_init_e}")
# 클라이언트 재초기화 실패 시 루프를 계속하거나, None을 반환할 수 있습니다.
time.sleep(retry_delay)
else:
logging.error("USDT 잔고 조회 최종 실패.")
return None
error:
2025-05-27 20:01:00,506 - INFO - XRPUSDT 최신 캔들 (4h / 2025-05-27 20:00:00): H=2.3373, L=2.3348, C=2.3357
2025-05-27 20:01:00,506 - INFO - XRPUSDT IBS: 0.3600
2025-05-27 20:01:00,506 - ERROR - USDT 잔고 조회 중 에러 발생 (시도 1/3): [Errno 32] Broken pipe
2025-05-27 20:01:00,506 - INFO - MEXC 클라이언트를 재초기화하고 1초 후 재시도합니다.
2025-05-27 20:01:00,506 - ERROR - MEXC 클라이언트 재초기화 중 에러 발생: [Errno 32] Broken pipe
2025-05-27 20:01:01,507 - ERROR - USDT 잔고 조회 중 에러 발생 (시도 2/3): [Errno 32] Broken pipe
2025-05-27 20:01:01,507 - INFO - MEXC 클라이언트를 재초기화하고 1초 후 재시도합니다.
2025-05-27 20:01:01,507 - ERROR - MEXC 클라이언트 재초기화 중 에러 발생: [Errno 32] Broken pipe
2025-05-27 20:01:02,507 - ERROR - USDT 잔고 조회 중 에러 발생 (시도 3/3): [Errno 32] Broken pipe
2025-05-27 20:01:02,508 - ERROR - USDT 잔고 조회 최종 실패.
2025-05-27 20:01:02,508 - ERROR - XRPUSDT: USDT 잔고를 조회할 수 없어 거래를 진행할 수 없습니다.
Sorry it's in Korean but it's erroro. 32 and says "Broken price'
At the beginning it gets usdt balance well but after a couple hours it caues some error