refactor: 프로젝트명 bithumb으로 변경 및 futures 파이프라인 제거
deepcoin 패키지를 bithumb으로 rename하고, 3단계 live 운영·사이징 튜닝·텔레그램 알림을 통합한다. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
90
scripts/3_init_live_state.py
Executable file
90
scripts/3_init_live_state.py
Executable file
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env python3
|
||||
"""paper → live 상태 전환 — 거래소 잔고 동기화."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SRC = ROOT / "src"
|
||||
if str(SRC) not in sys.path:
|
||||
sys.path.insert(0, str(SRC))
|
||||
|
||||
from bithumb.config import load_settings
|
||||
from bithumb.notifications.telegram import create_telegram_notifier
|
||||
from bithumb.operations.live_bootstrap import init_live_state
|
||||
|
||||
|
||||
def main() -> int:
|
||||
"""CLI 진입점."""
|
||||
parser = argparse.ArgumentParser(description="Bithumb live 상태 초기화")
|
||||
parser.add_argument(
|
||||
"--no-backup",
|
||||
action="store_true",
|
||||
help="기존 state JSON 백업 생략",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--reset-bar-cursor",
|
||||
action="store_true",
|
||||
help="last_processed_bar_index 를 -1 로 초기화",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--yes",
|
||||
action="store_true",
|
||||
help="확인 프롬프트 생략",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
settings = load_settings()
|
||||
if settings.ops_mode != "live":
|
||||
print(f"OPS_MODE={settings.ops_mode} — .env 에 OPS_MODE=live 설정 후 실행하세요.", file=sys.stderr)
|
||||
return 1
|
||||
if not settings.bithumb_access_key or not settings.bithumb_secret_key:
|
||||
print("BITHUMB API 키가 필요합니다.", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
if not args.yes:
|
||||
print("경고: live 상태 초기화 — 거래소 잔고가 state JSON에 반영됩니다.")
|
||||
print(f"state: {settings.ops_state_json}")
|
||||
answer = input("계속하시겠습니까? [y/N]: ").strip().lower()
|
||||
if answer not in ("y", "yes"):
|
||||
print("취소됨.")
|
||||
return 1
|
||||
|
||||
result = init_live_state(
|
||||
settings,
|
||||
backup=not args.no_backup,
|
||||
preserve_bar_cursor=not args.reset_bar_cursor,
|
||||
)
|
||||
bal = result["balances"]
|
||||
|
||||
print("=== live 상태 초기화 완료 ===")
|
||||
if result["backup_path"]:
|
||||
print(f"백업: {result['backup_path']}")
|
||||
print(f"state: {result['state_path']}")
|
||||
print(
|
||||
f"잔고: KRW {bal['cash_krw']:,.0f}원 · "
|
||||
f"{settings.symbol} {bal['coin_qty']:.8f}"
|
||||
)
|
||||
print(f"bar cursor: {result['last_processed_bar_index']}")
|
||||
|
||||
telegram = create_telegram_notifier(
|
||||
settings.telegram_bot_token,
|
||||
settings.telegram_chat_id,
|
||||
enabled=settings.ops_telegram_enabled,
|
||||
)
|
||||
if telegram.is_active:
|
||||
telegram.send_message(
|
||||
"[Bithumb] LIVE 세션 시작\n"
|
||||
f"{settings.coin_name} ({settings.symbol}) | {settings.ops_technique_id}\n"
|
||||
f"KRW {bal['cash_krw']:,.0f} · {settings.symbol} {bal['coin_qty']:.8f}\n"
|
||||
f"일 체결 상한 {settings.ops_daily_max_trades} · 슬리피지 {settings.ops_slippage_rate * 100:.2f}%"
|
||||
)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user