@bitget-ai/bitget-agent-sdk

中文文档
3.3.1发布于 2026/09/20MITTypeScriptES Module零依赖近 30 天下载 4320

Spec-driven foundation SDK for the Bitget Unified Trading Account (UTA / v3) API. Generated from openapi.yaml — exposes all v3 endpoints as AI-callable tools, with a built-in catalog-driven mock server for hermetic regression testing.

原始使用文档
文档目录28 节
  1. Overview
  2. Quick Start
  3. Install
  4. Basic Usage
  5. Set Credentials
  6. Features
  7. What It Does for You
  8. Key Exports
  9. Usage
  10. Control Tool Scope & Safety
  11. Explore at Runtime
  12. Intent Verbs (Default Surface)
  13. Modules
  14. Testing
  15. Error Handling
  16. Security
  17. Compatibility
  18. Documentation
  19. Related Projects
  20. FAQ
  21. What is bitget-agent-sdk?
  22. What developer use cases is this SDK designed for?
  23. How is this different from calling the Bitget REST API dire…
  24. Does this SDK support CommonJS?
  25. How do I load only specific modules?
  26. I'm on a classic Bitget account — can I use this?
  27. Is it officially from Bitget and free to use?
  28. License

Bitget Agent SDK — TypeScript foundation library for Bitget UTA v3 API trading bot development

bitget-agent-sdk — Official Bitget AI Trading TypeScript SDK

The foundation TypeScript SDK for the Bitget Unified Trading Account (UTA / v3) REST API — exposed as AI-callable Intent tools, with HMAC-SHA256 signing and client-side rate limiting.

Bitget Agent SDK continuous integration build status Bitget Agent SDK npm package version Bitget Agent SDK monthly downloads TypeScript type definitions included Requires Node.js 20 or higher Zero runtime dependencies MIT open source license

Quick Start · Features · Usage · Modules · Testing · Error Handling · FAQ


Overview

@bitget-ai/bitget-agent-sdk is the foundation TypeScript SDK of the Bitget Agent Hub ecosystem. It provides:

  • 89 UTA operations with full JSON Schema
  • 14 curated Intent verbs for AI tool-use frameworks, plus raw and discover meta tools
  • HMAC-SHA256 request signing and client-side rate limiting
  • Zero runtime dependencies — lightweight and tree-shakeable ("sideEffects": false)

Both bitget-agent-cli and bitget-agent-mcp are built on top of this SDK.

For developers: Building quant strategies, custom MCP servers, LLM tool-use pipelines, or automated trading bots. Not a developer? Use the higher-level surfaces: bitget-agent-cli + bitget-agent-skill for terminal AI, bitget-agent-mcp for desktop AI, bitget-signal for market analysis with no account needed. None of them require this SDK directly.


Quick Start

Install

npm install @bitget-ai/bitget-agent-sdk

Basic Usage

import {
  loadConfig,
  buildTools,
  BitgetRestClient,
  safeInvoke,
} from "@bitget-ai/bitget-agent-sdk";

// Default surface is "intent" (curated verbs + raw + discover).
// Starting with readOnly is a safe default — every write tool is dropped.
const config = loadConfig({ modules: "all", readOnly: true });
const client = new BitgetRestClient(config);
const tools = buildTools(config);
const ctx = { config, client };

console.log(`Loaded ${tools.length} tools`); // intent verbs + raw + discover

// Public market data — no credentials required.
const market = tools.find((t) => t.name === "market")!;
const res = await safeInvoke(
  market,
  { action: "tickers", category: "SPOT", symbol: "BTCUSDT" },
  ctx,
);

if (res.ok) console.log(res.data);
else console.error(res.error);

Set Credentials

Credentials are read from environment variables — the SDK does not parse .env files and never writes credentials to disk:

export BITGET_API_KEY="your-api-key"
export BITGET_SECRET_KEY="your-secret-key"
export BITGET_PASSPHRASE="your-passphrase"

Or pass them inline to loadConfig({ apiKey, secretKey, passphrase, ... }).


Features

What It Does for You

FeatureWhat It Replaces
89 UTA operations with 14 curated Intent verbs, mountable to any LLM framework in one callHand-rolling endpoint wrappers and keeping them in sync
safeInvoke — every call resolves to { ok, … }, never throwsWrapping every tool call in your own try/catch
discover — the surface describes itself to your model, drill in on demandMaintaining a separate tool catalog just for prompts
Request signing (HMAC-SHA256) + client-side rate limiting + typed errorsRe-implementing Bitget's auth spec yourself
Safety modes: readOnly + paperTrading, high-risk ops require explicit confirmWriting your own guardrails against accidental live orders

Key Exports

// Client + tool primitives
import {
  BitgetRestClient,
  buildTools,
  toToolSpec,
  loadConfig,
  safeInvoke,
  toMcpTool,
} from "@bitget-ai/bitget-agent-sdk";

// Curated verbs, discovery, raw
import {
  COMPOSITE_TOOL_NAMES,
  buildDiscoverTool,
  DISCOVER_TOOL_NAME,
  RAW_TOOL_NAME,
} from "@bitget-ai/bitget-agent-sdk";

// The generated catalog (single source of truth)
import {
  CATALOG,
  CATALOG_SPEC_VERSION,
  CATALOG_OPERATION_COUNT,
  getOperation,
} from "@bitget-ai/bitget-agent-sdk";

// Types
import type {
  BitgetConfig,
  CliOptions,
  Surface,
  ToolSpec,
  ToolContext,
  ToolResult,
  SafeResult,
  ModuleId,
} from "@bitget-ai/bitget-agent-sdk";

// Metadata
import {
  SERVER_NAME,
  SERVER_VERSION,
  API_VARIANT,
  MODULES,
  DEFAULT_MODULES,
} from "@bitget-ai/bitget-agent-sdk";

// Errors — all subclasses of BitgetMcpError
import {
  BitgetMcpError,
  BitgetApiError,
  ConfigError,
  ValidationError,
  RateLimitError,
  AuthenticationError,
  NetworkError,
  toToolErrorPayload,
} from "@bitget-ai/bitget-agent-sdk";

Everything exported from the package root or the @bitget-ai/bitget-agent-sdk/testing subpath follows semver. Anything not exported from those paths is internal and may change without notice.


Usage

Control Tool Scope & Safety

loadConfig accepts these commonly-used options:

OptionDefaultEffect
surface"intent""intent" (default) exposes the curated verbs + raw + discover. "full" additionally emits one 1:1 tool per operation.
modules"account,trade,market"Comma-separated module list, or "all". Gates which tools are surfaced.
readOnlyfalseDrop every write tool; reads only. Mutually exclusive with paperTrading.
paperTradingfalseSend orders to Bitget paper trading. Mutually exclusive with readOnly.
baseUrlhttps://api.bitget.comAPI base URL (or BITGET_API_BASE_URL).
timeoutMs15000Per-request timeout in ms (or BITGET_TIMEOUT_MS).

Every tool carries a riskLevel of read < write < high. High-risk operations self-gate: they return a { confirmationRequired: true } preview until you pass confirm, so an agent can't fire a destructive call on its first turn. This holds on every path — the curated verbs, the 1:1 operation tools, and the raw escape hatch all flow through one safety chokepoint.

Explore at Runtime

discover lets a model learn the surface progressively, without you shipping a separate tool catalog in the prompt:

const discover = tools.find((t) => t.name === "discover")!;

await safeInvoke(discover, {}, ctx);                                    // domains + tool counts
await safeInvoke(discover, { domain: "trade" }, ctx);                   // tools in a domain
await safeInvoke(discover, { tool: "market" }, ctx);                    // one tool's full schema
await safeInvoke(discover, { tool: "market", action: "tickers" }, ctx); // one action's exact contract
await safeInvoke(discover, { search: "funding" }, ctx);                 // keyword search

Intent Verbs (Default Surface)

The default intent surface exposes 14 curated verbs, each gated on its module being enabled. These 14 cover the generally-available modules:

VerbModuleReaches
marketmarkettickers, order book, candles, funding rate, open interest, reference reads
ordertradeplace / amend / cancel orders, current & historical orders, fills
positiontradeopen positions, leverage & margin mode, position history
strategy_ordertradetrigger / TP-SL / plan orders
account_overviewaccountbalances, assets, bills
account_configaccountaccount mode, margin & leverage settings
transfer_fundsaccountinternal & sub-account transfers
depositaccountdeposit address & records
withdrawaccountwithdrawals & records
funds_recordsaccountdeposit / withdraw / transfer history
repaymentaccountliability repayment
subaccountaccountsub-account create / list / manage
loancryptoloansborrow, repay, collateral, loan records
taxtaxtransaction tax records

Plus two always-present meta tools:

  • raw — the escape hatch. Call any operation directly by operationId when you want the exact 1:1 contract. It routes through the same safety gate as the curated verbs — readOnly, dryRun, and the high-risk confirm requirement all still apply, so raw widens reach without ever skipping a destructive-action confirmation.
  • discover — introspect the active surface (see above). Both are available in every surface and every mode.

Modules

The default profile loads account + trade + market, covering everyday trading. Load everything with loadConfig({ modules: "all" }), or pick a named subset:

ModuleOperationsDefaultDescription
account39✅Balances & assets, account settings, transfers, deposit/withdraw, funding records, sub-accounts
trade17✅Order placement & management (spot + futures), positions, fills
market16✅Public market data — tickers, order book, candles, funding rate, open interest
strategy5—Strategy orders — trigger, TP/SL, plan orders
cryptoloans11—Crypto-backed loans — borrow, repay, collateral, records
tax1—Transaction tax records
Total (visible)8972

Classic account users: If you are on a Bitget classic account, you need to create an Agent sub-account via the API first, then use that sub-account's API key to call MCP / CLI / Skill tools. Create Agent Sub-Account →


Testing

Import an in-memory Bitget API simulator from the @bitget-ai/bitget-agent-sdk/testing subpath for integration tests — no real API key required:

import { MockServer, seedState } from "@bitget-ai/bitget-agent-sdk/testing";
import { loadConfig, BitgetRestClient } from "@bitget-ai/bitget-agent-sdk";

const mock = new MockServer();
await mock.start(); // ephemeral port

const config = loadConfig({
  modules: "market",
  baseUrl: mock.baseUrl,
  apiKey: "test",
  secretKey: "test",
  passphrase: "test",
});
const client = new BitgetRestClient(config);

// ... drive your tests against `client` ...

await mock.stop();

Error Handling

Two complementary layers:

1. safeInvoke — the recommended path. It never throws. Branch on .ok:

const res = await safeInvoke(tool, args, ctx);
if (res.ok) {
  // res.data, res.endpoint, res.requestTime
} else {
  // res.error — a JSON-serialisable payload, ready for an LLM tool-use reply
}

2. Typed errors — when you call a handler directly. Every API failure and config problem surfaces as a typed Error subclass you can instanceof-narrow:

import { BitgetApiError, ConfigError, RateLimitError } from "@bitget-ai/bitget-agent-sdk";

try {
  await tool.handler(args, ctx);
} catch (err) {
  if (err instanceof RateLimitError) {
    // SDK applies client-side rate limiting, but Bitget can still 429 under load — back off and retry
  } else if (err instanceof BitgetApiError) {
    console.error(err.code, err.message);
  } else if (err instanceof ConfigError) {
    // Missing or invalid credentials — surface to the user
  }
}

Use toToolErrorPayload(err) to convert any caught error into the same { ok: false, error: { … } } payload safeInvoke produces.


Security

  • Credentials from environment variables only: API keys are read via export BITGET_API_KEY=... — the SDK does not parse .env files and never writes credentials to disk.
  • Signed locally: all authenticated requests are signed in-process with HMAC-SHA256 before reaching Bitget's API — no third-party server is involved.
  • Client-side rate limiting: built-in throttling prevents loops from hitting Bitget's API limits.

Compatibility

Node.js≥ 20.0.0
Module formatESM only ("type": "module"). Tree-shaking enabled ("sideEffects": false).
TypeScriptTypes ship in the package; no @types/... install needed. Module resolution is NodeNext.
DependenciesZero runtime dependencies.
Bitget APIBitget Unified Trading Account (UTA / v3).

Documentation

  • In-core discovery. The discover tool returns the live, config-aware tool surface and each operation's contract; no external catalog to keep in sync.
  • Bitget API reference. bitget.com/api-doc

PackagePurpose
bitget-agent-cliTerminal AI tool (built on SDK)
bitget-agent-mcpDesktop AI MCP server (built on SDK)
bitget-agent-skillAI reasoning guide
bitget-signalMarket analysis skills
agent-hubEcosystem entry point

FAQ

What is bitget-agent-sdk?

bitget-agent-sdk is the official Bitget foundation TypeScript SDK — covering 89 UTA operations, with HMAC-SHA256 signing, client-side rate limiting, and a 14-verb Intent surface mountable into any LLM tool-use framework. Both bitget-agent-cli and bitget-agent-mcp are built on top of it, making it the foundational layer of the entire Bitget Agent Hub ecosystem.

What developer use cases is this SDK designed for?

Building quantitative trading strategies, custom MCP servers, LLM tool-use pipelines, automated trading bots, and any TypeScript or JavaScript project that needs programmatic access to Bitget's UTA API.

How is this different from calling the Bitget REST API directly?

The SDK handles HMAC-SHA256 request signing, client-side rate limiting, and typed error classes. It provides 14 curated Intent verbs plus the raw escape hatch, all mountable into any LLM tool-use framework. safeInvoke gives every call a uniform { ok, … } shape — no need to wrap each handler in try/catch yourself.

Does this SDK support CommonJS?

No, it is ESM-only ("type": "module"). Requires Node.js ≥ 20 and NodeNext module resolution.

How do I load only specific modules?

Pass a comma-separated list, e.g. loadConfig({ modules: "account,trade" }), or loadConfig({ modules: "all" }) for every module.

I'm on a classic Bitget account — can I use this?

Yes, but classic accounts need to create an Agent sub-account first via the API, then use that sub-account's API key for MCP / CLI / Skill tools. View the Create Agent Sub-Account API →

Is it officially from Bitget and free to use?

Yes. It is an official open-source SDK published by Bitget under the MIT license, free to use.


License

MIT — Bitget Agent SDK

Official Bitget Agent Hub tool · Trading Stack · Foundation layer. Surfaces built on this SDK: agent-cli · agent-mcp · agent-skill

版本与发布记录

@bitget-ai/bitget-agent-sdk 共发布 6 个版本,首次发布于 2026/06/09;过去 12 个月发布了 6 个版本。

版本发布日期距今
3.3.1latest2026/09/201 个月前
3.3.02026/09/042 个月前
3.2.02026/09/042 个月前
3.1.02026/09/022 个月前
3.0.02026/06/224 个月前
1.2.02026/06/094 个月前

关于 @bitget-ai/bitget-agent-sdk 的常见问题

@bitget-ai/bitget-agent-sdk 是什么?

Spec-driven foundation SDK for the Bitget Unified Trading Account (UTA / v3) API. Generated from openapi.yaml — exposes all v3 endpoints as AI-callable tools, with a built-in catalog-driven mock server for hermetic regression testing.

如何安装 @bitget-ai/bitget-agent-sdk?

在项目目录运行 npm install @bitget-ai/bitget-agent-sdk,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 bitget-mock-server,可以用 npx bitget-mock-server 直接运行。

@bitget-ai/bitget-agent-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bitget-ai/bitget-agent-sdk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@bitget-ai/bitget-agent-sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bitget-ai/bitget-agent-sdk 可以商用吗?

@bitget-ai/bitget-agent-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bitget-ai/bitget-agent-sdk 的下载量有多少?

根据 npm 官方下载统计,@bitget-ai/bitget-agent-sdk 在 2026/10/08 – 2026/11/06 这 30 天内被下载 4,320 次,日均约 144 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bitget-ai/bitget-agent-sdk 还在维护吗?

最新版本 3.3.1 发布于 2026/09/20(1 个月前);至今共发布 6 个版本,其中过去 12 个月发布了 6 个;首次发布于 2026/06/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。