get_bizmoney
Retrieve advertising balance, recent 7-day spend trend, and estimated remaining days for Kakao Moment.
Instructions
비즈머니 잔액 + 최근 7일 소진 추이 + 현재 페이스 기준 잔여 일수 예상.
이런 질문에 사용하세요: • "비즈머니 얼마 남았어?" / "잔액 얼마야?" / "광고비 얼마 남았어?" • "이대로 가면 며칠 더 쓸 수 있어?" / "비즈머니 며칠치 남았어?" • "최근 일주일 광고비 얼마 썼어?" • "비즈머니 충전해야 해?" / "잔액 부족하지 않아?"
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- Core handler: async function that fetches BizMoney balance from Kakao Moment API, calculates recent 7-day spend, and estimates days left. Returns dict with balance, free_cash, deferred_pay, spend data, and summary.
async def get_bizmoney(client: KakaoMomentClient) -> dict[str, Any]: """비즈머니 잔액 + 최근 7일 소진 추이.""" data = await client.get("/openapi/v4/adAccounts/balance") body = data.get("data") if isinstance(data, dict) and "data" in data else data if not isinstance(body, dict): return {"raw": data, "summary": "비즈머니 정보를 해석할 수 없습니다."} balance = body.get("cash") or body.get("balance") or body.get("totalAmount") # 최근 7일 소진 (오늘 제외 7일 전 ~ 어제). 광고계정 일별 리포트 사용. today = date.today() week_ago = today - timedelta(days=7) yesterday = today - timedelta(days=1) recent_spend: list[dict[str, Any]] = [] weekly_total: float = 0.0 try: report = await client.get( "/openapi/v4/adAccounts/report", params={ "dateFrom": to_yyyymmdd(week_ago), "dateTo": to_yyyymmdd(yesterday), "metricsGroups": "DAY", }, ) rows = report.get("data") if isinstance(report, dict) and "data" in report else report if isinstance(rows, list): for r in rows: flat = _unwrap_metrics(r) cost = float(flat.get("cost", 0) or 0) weekly_total += cost recent_spend.append( {"date": flat.get("start") or flat.get("date"), "cost": cost} ) except Exception: # noqa: BLE001 — 리포트 권한이 없는 경우에도 잔액은 반환 recent_spend = [] avg_daily = (weekly_total / len(recent_spend)) if recent_spend else 0.0 days_left: float | None = None if balance and avg_daily > 0: try: days_left = round(float(balance) / avg_daily, 1) except (TypeError, ValueError): days_left = None summary_parts = [f"비즈머니 잔액 {_fmt_won(balance)}"] if recent_spend: summary_parts.append(f"최근 7일 평균 일소진 {_fmt_won(avg_daily)}") if days_left is not None: summary_parts.append(f"현재 페이스로 약 {days_left}일 잔여") return { "balance": balance, "free_cash": body.get("freeCash"), "deferred_pay_amount": body.get("deferredPayAmount"), "recent_spend_7d": recent_spend, "weekly_total_cost": round(weekly_total, 2), "avg_daily_cost_7d": round(avg_daily, 2), "days_left_estimate": days_left, "summary": " · ".join(summary_parts), "raw": body, } - Helper _fmt_won: formats a numeric amount as Korean won string (e.g., '1,234,567원'). Used by get_bizmoney for the summary.
def _fmt_won(amount: float | int | None) -> str: if amount is None: return "-" try: return f"{int(round(float(amount))):,}원" except (TypeError, ValueError): return str(amount)