Bitget Risk Watch is a Bitget-native AI portfolio risk monitor for USDT-FUTURES.
It monitors a Bitget futures portfolio, identifies risky positions, explains exactly why they are risky, recommends protective actions, and records every scan in an audit log. The MVP runs in SIMULATION, it reads real account data in LIVE_READ, and it can also run a separate, explicit trading console when you intentionally enable execution mode LIVE_EXECUTE.
Built for the Bitget Agent Hub Skills Challenge.
It is a risk-control tool for positions on Bitget. It answers questions like:
- Which positions are risky right now?
- Why was BTC flagged?
- What should I do next?
- What changed since the last scan?
- If I decide to act, what exact Bitget command would I run?
The scan follows one simple loop:
- Fetch Bitget account and futures position data
- Normalize the responses into typed internal objects
- Classify each position as
SAFE,WARNING, orCRITICAL - Recommend protective actions
- Save a structured audit record
- Support follow-up queries from the latest scan history
Safe demo mode.
- Uses bundled mock portfolio data
- No Bitget reads
- No order placement
Live analysis mode.
- Reads real Bitget account data
- Does not place orders
- Uses read-only Bitget CLI calls in the scan path
Execution-enabled mode.
- Scans still remain read-only
- Only the separate execution console can place orders
- Destructive actions require an explicit confirmation token
It can:
- read Bitget balances and futures positions
- enrich positions with market and funding context
- detect missing stop-loss, high leverage, large unrealized loss, high margin ratio, and elevated funding pressure
- explain each flag in plain English
- recommend concrete protective actions
- store the result in
audit-log.json - generate a browser-friendly
latest-report.htmlfrom the latest scan
It can answer:
scan my portfoliowhich positions are at risk?why is BTC flagged?what actions do you recommend?what changed since last scan?show my risk summary
It can:
- preview a supported action before sending anything
- close part of a position
- reduce position size
- lower leverage
- inspect live positions
- inspect open orders
- inspect fills
- cancel one order
- cancel all orders for a symbol
The Agent supports all Bitget Skill Hub enrichments for follow-up context:
macro-analystmarket-intelnews-briefingsentiment-analysttechnical-analysis
The core scan works without them. The report and query layer suggest when to use them.
Trading actions are treated as sensitive operations. The current implementation enforces:
- scans never place live orders
- scan-time Bitget calls use
--read-only - execution is separate from scanning
- execution requires
RUNTIME_MODE=LIVE_EXECUTE - execution always previews the exact Bitget command first
- destructive actions require a symbol-and-action-specific confirmation token
- execution attempts and outcomes are logged in
execution-audit.jsonl - credentials are read from environment variables only
This repo is built around Bitget’s CLI tool surface, bgc, from bitget-client.
Relevant Bitget commands used by the project:
bgc account get_account_assetsbgc futures futures_get_positions --productType USDT-FUTURESbgc futures futures_get_ticker --productType USDT-FUTURES --symbol BTCUSDTbgc futures futures_get_funding_rate --productType USDT-FUTURES --symbol BTCUSDTbgc futures futures_place_orderbgc futures futures_set_leveragebgc futures futures_cancel_ordersbgc futures futures_get_ordersbgc futures futures_get_fills
Relevant Bitget API references:
- Futures positions: https://www.bitget.com/api-doc/contract/position/get-all-position
- Futures place order: https://www.bitget.com/api-doc/contract/trade/Place-Order
- Futures cancel order: https://www.bitget.com/api-doc/contract/trade/Cancel-Order
- Futures leverage config: https://www.bitget.com/api-doc/contract/account/Change-Leverage
- Futures modify order: https://www.bitget.com/api-doc/contract/trade/Modify-Order
Current focus:
USDT-FUTURES
The project is optimized for one futures product type so the risk rules, normalization, and execution logic remain consistent and reliable.
Default rules:
- no stop-loss ->
WARNING - leverage above
10x->WARNING - unrealized loss worse than
15%->CRITICAL - margin ratio at or above
80%->CRITICAL - funding rate at or above
0.3%in absolute terms ->WARNING
These are configurable through environment variables.
The agent currently generates recommendations such as:
- add stop-loss
- lower leverage
- reduce position size
- close partial position
- avoid new entries until margin pressure improves
- review funding exposure before the next funding window
Not every recommendation is executable automatically.
The current live execution flow supports only verified actions:
close partial positionreduce position sizelower leverage- order and fill inspection
- order cancellation
Stop-loss / TP-SL execution remains recommendation-only.
There are two audit surfaces:
Stored in audit-log.json
Contains:
- timestamp
- mode
- productType
- runtime diagnostics
- skill calls
- account summary
- positions
- flagged positions
- overall risk
- risk reasons
- recommendations
- scan status
- warnings
Stored in execution-audit.jsonl
Contains one line per execution-related event:
- preview shown
- confirmation missing
- command succeeded
- command failed
- Node.js 18+ or the bundled Node toolchain in
.tools/node - Bitget CLI (
bgc) - Bitget API credentials for
LIVE_READorLIVE_EXECUTE
npm installnpm install -g bitget-clientVerify:
bgc --helpExample .env.local:
BITGET_API_KEY=your_api_key_here
BITGET_SECRET_KEY=your_secret_here
BITGET_PASSPHRASE=your_passphrase_here
RUNTIME_MODE=LIVE_READ
LEVERAGE_THRESHOLD=10
LOSS_THRESHOLD_PCT=15
MARGIN_DANGER_PCT=80
FUNDING_WARNING_PCT=0.3Important:
RUNTIME_MODEcan beSIMULATION,LIVE_READ, orLIVE_EXECUTE
If you want Codex-side Skill Hub enrichments available:
npx bitget-hub upgrade bitget-skill
npx bitget-hub upgrade bitget-skill-hub
npx bitget-hub install --target codexOn Ubuntu, if pip install pandas numpy fails with externally-managed-environment, use a virtual environment:
sudo apt install python3-venv
python3 -m venv .venv
. .venv/bin/activate
pip install pandas numpynpx ts-node src/index.tsOr:
npm run scanEach scan updates:
audit-log.jsonlatest-report.html
Open the HTML file in a browser for a cleaner demo view than raw terminal output.
npm run reportDefault URL:
http://127.0.0.1:4173
Optional environment variables:
REPORT_PORT=8080REPORT_HOST=127.0.0.1
npx ts-node src/query.ts "which positions are at risk?"
npx ts-node src/query.ts "why is BTC flagged?"
npx ts-node src/query.ts "what actions do you recommend?"
npx ts-node src/query.ts "what changed since last scan?"
npx ts-node src/query.ts "show my risk summary"npx ts-node src/query.ts "skill hub enrichments"
npx ts-node src/query.ts "sentiment analysis"
npx ts-node src/query.ts "technical analysis"
npx ts-node src/query.ts "macro outlook"
npx ts-node src/query.ts "full market assessment"npm run demoPreview a supported action:
RUNTIME_MODE=LIVE_EXECUTE npx ts-node src/execute.ts BTCUSDT --action "close partial position"Execute it:
RUNTIME_MODE=LIVE_EXECUTE npx ts-node src/execute.ts BTCUSDT --action "close partial position" --confirm EXECUTE:BTCUSDT:CLOSE_PARTIAL_POSITION --size-pct 25Lower leverage:
RUNTIME_MODE=LIVE_EXECUTE npx ts-node src/execute.ts BTCUSDT --action "lower leverage" --confirm EXECUTE:BTCUSDT:LOWER_LEVERAGE --leverage 9Inspect live trading state:
RUNTIME_MODE=LIVE_EXECUTE npx ts-node src/execute.ts BTCUSDT --show-positions
RUNTIME_MODE=LIVE_EXECUTE npx ts-node src/execute.ts BTCUSDT --show-orders
RUNTIME_MODE=LIVE_EXECUTE npx ts-node src/execute.ts BTCUSDT --show-fillsCancel orders:
RUNTIME_MODE=LIVE_EXECUTE npx ts-node src/execute.ts BTCUSDT --cancel --order-id 123456 --confirm EXECUTE:BTCUSDT:CANCEL_ORDER
RUNTIME_MODE=LIVE_EXECUTE npx ts-node src/execute.ts BTCUSDT --cancel-all --confirm EXECUTE:BTCUSDT:CANCEL_ALL_ORDERSThe inspection commands render a simplified operator view first. If Bitget returns an unfamiliar payload shape, the console falls back to raw JSON.
Best demo sequence:
- run a
SIMULATIONscan - show flagged positions and clear explanations
- run follow-up queries
- show the execution preview and confirmation gate
- show
audit-log.json - show
execution-audit.jsonl - show Skill Hub enrichment suggestions
This demonstrates:
- Bitget-native reads
- explainable risk classification
- actionable recommendations
- execution safety
- auditability
- Skill Hub extensibility
src/index.ts: scan entry pointsrc/config.ts: runtime config and thresholdssrc/types.ts: internal modelssrc/bitget.ts: Bitget integration and normalizationsrc/fetcher.ts: simulation and live scan input assemblysrc/classifier.ts: risk classificationsrc/recommender.ts: recommendation generationsrc/reporter.ts: terminal reportingsrc/query.ts: follow-up question interfacesrc/execute.ts: explicit trading consolesrc/skillHub.ts: Skill Hub enrichment routingsrc/audit.ts: scan and execution audit helpers
Commands verified in this repo:
npm run typechecknpx ts-node src/index.tsnpx ts-node src/query.ts "which positions are at risk?"npx ts-node src/query.ts "skill hub enrichments"RUNTIME_MODE=LIVE_EXECUTE npx ts-node src/execute.ts BTCUSDT --show-positionsRUNTIME_MODE=LIVE_EXECUTE npx ts-node src/execute.ts BTCUSDT --cancel-all
- explainable risk scan
- clear read-only live analysis path
- explicit confirmation-gated execution console
- execution audit logging
- queryable scan history