# @blockworks-foundation/mango-client 中文文档

规范地址：https://npmcn.com/package/%40blockworks-foundation/mango-client/

版本：2\.3\.0
npm 元数据更新时间：2026-11-04T11:47:21.701Z
中文译文更新时间：2026-11-08T07:41:01.138Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40blockworks-foundation/mango-client
原文对照：https://npmcn.com/package/%40blockworks-foundation/mango-client/?lang=original
源码仓库：https://github.com/blockworks-foundation/mango-client-ts

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：274 kB，33 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=10
- 运行依赖：8 个
- 首次发布：2021-02-21T18:24:49.859Z
- 最新版本发布：2023-11-14T14:29:47.152Z
- 近 30 天下载量：4079（2026-10-09 至 2026-11-07，npm 官方下载统计）
- 已发布版本数：154（近 12 个月 0 个）

## 中文简介

与芒果市场Solana智能合约互动的图书馆.

## 安装

```sh
npm install @blockworks-foundation/mango-client
```

也可以使用：`pnpm add @blockworks-foundation/mango-client`、`yarn add @blockworks-foundation/mango-client`、`bun add @blockworks-foundation/mango-client`

## README

# 芒果客户端

一个与芒果程序接触的客户端

## 版本数

2.0.0 释放了June 9, 2021

-   支持 Mango 的 5 个符号版本
-   [页:1](https://trade.mango.markets/)

0.1.19 联合国

-   支持芒果的3个符号版本
-   [https://usdt.mango. 市场](https://usdt.mango.markets/)

## 测试

**所有测试都要在devnet上进行** 全面测试运行,需要很长时间才能进行,有时由于连通性问题或其他工作人而失败 _脱网_因此,建议进行这样的孤立试验:

```
yarn test -g "<test description>"
```

例如,以下测试:

```
it('should log lotSizes', async() => {...});
```

就会像这样跑

```
yarn test -g "should log lotSizes"
```

您还可以指定一个测试组, 可以运行多个测试, 例如下面的组 -

```
describe('log stuff', async() => {...});
```

可以这样运行..

```
yarn test -g "should log lotSizes"
```

如果你真的想运行 全套测试只是运行 -

```
yarn test
```

### 所需资源

诸如伐木和订单匹配等一些测试将没有任何要求进行,但所有清算测试都期望有一个 `AGGREGATOR_PATH` 变量集 _.env 数据_。 。 。 .

这个 `AGGREGATOR_PATH` 变量应该是 _solana-flux-聚合剂_ 可获取的路径 [这里](https://github.com/blockworks-foundation/solana-flux-aggregator)。 。 。 .

示例 _.env 数据_ 文件 -

```
AGGREGATOR_PATH=~/solana-flux-aggregator
```

### 测试清算

套房中最能动的测试之一是清算测试,这可以在 `stress testing partial liquidation` 组只需在您的 IDE 中搜索它.

所有测试都有变异 `stressTestLiquidation` 函数.

这个函数大致由 -

1.  创建和资金a _丽琪_ 待清算的账户
2.  将预告价格改为订单价格 _丽琪_ 是关于提交
3.  代表缔约方提交长或短命令 _丽琪_
4.  将甲骨文价格改为强制 _丽琪_低于维护门槛值的附带比率
5.  创建和资金a _里科尔_ 将进行清算的账户
6.  _里科尔_ 进行清算

以下列出可以产生许多不同清算假设的参数:

```
mangoGroupSpotMarket: Market,
orderQuantity?: number, // Default = 1
customLiqeeOwner?: Account, // Default = null
shouldPartialLiquidate?: boolean, // Default = false
shouldCreateNewLiqor?: boolean, // Default = true
shouldFinishLiquidationInTest?: boolean, // Default = true
customOrderPrice?: number, // Default = 0
customOrderSize?: number, // Default = 0
leverageCoefficient?: number, // Default = 15
matchLeveragedOrder?: boolean, // Default = false
side?: 'buy' | 'sell' // Default = 'buy'
```

-   _芒果组点市场_ 应当创造清算机会的现货市场
-   _数量_ 指定多少命令 _丽琪_ 账户应该创建, 它不影响命令Size
-   _自定义Liqee-Owner_ 如果您想要重新使用现有账户,则可以指定 `liqee`。如果您想要将清算情况连锁起来,则这样做是有用的。 如果空出, 将创建新账户
-   _应 PartialLiquidate (应参加)_ 指明应当定期清算还是部分清算
-   _应创建新地址_ 将建立一个新的liqor账户,为清算提供资金。 如果你把清算方案连在一起 不需要在每一个方案上建立一个清算人 这样你就可以设定它 `false`
-   _应完成定量 测试_ - 和上面一样,您应该将这个参数设置为 `false` 或希望手工完成清算.
-   _自定义命令_ - 如果不设定,它将使用 `minPrice` 市场
-   _自定义命令大小_ - 如果不设定,它将使用 `minSize` 市场
-   _杠杆_ - 此参数指定了当前 _丽琪_例如,15个系数将生效 _丽琪_ 改为 15x
-   _匹配已调整的顺序_ 指定长或短是否应当相匹配,否则清算方案将与借款一起进行,以便始终保持与开放订单相同的货币。 如果设置为 `true` 它会把杠杆提高一倍.
-   _边_ 指定是长还是短才被清算

### 示例

```
async function main() {
  const client = new MangoClient()
  const cluster = 'mainnet-beta'
  const clusterUrl = process.env.CLUSTER_URL || IDS.cluster_urls[cluster]
  const connection = new Connection(clusterUrl, 'singleGossip')
  const programId = new PublicKey(IDS[cluster].mango_program_id)
  const dexProgramId = new PublicKey(IDS[cluster].dex_program_id)
  const mangoGroupPk = new PublicKey(IDS[cluster].mango_groups['BTC_ETH_USDT'].mango_group_pk)

  const keyPairPath = process.env.KEYPAIR || homedir() + '/.config/solana/id.json'

  const payer = new Account(JSON.parse(fs.readFileSync(keyPairPath, 'utf-8')))
  const mangoGroup = await client.getMangoGroup(connection, mangoGroupPk)
  const prices = await mangoGroup.getPrices(connection)
  const marginAccounts = (await client.getMarginAccountsForOwner(connection, programId, mangoGroup, payer))
  marginAccounts.sort(
    (a, b) => (a.computeValue(mangoGroup, prices) > b.computeValue(mangoGroup, prices) ? -1 : 1)
  )
  let marginAccount = marginAccounts[0]

  const market = await Market.load(connection, mangoGroup.spotMarkets[0], { skipPreflight: true, commitment: 'singleGossip'}, mangoGroup.dexProgramId)
  console.log('placing order')
  const txid = await client.placeOrder(connection, programId, mangoGroup, marginAccount, market, payer, 'buy', 48000, 0.0001)
  console.log('order placed')

  await sleep(5000)
  marginAccount = await client.getMarginAccount(connection, marginAccount.publicKey, mangoGroup.dexProgramId)
  const bids = await market.loadBids(connection)
  const asks = await market.loadAsks(connection)
  console.log('canceling orders')
  await marginAccount.cancelAllOrdersByMarket(connection, client, programId, mangoGroup, market, bids, asks, payer)
  console.log('orders canceled')
}
```

## 常见问题

### @blockworks-foundation/mango-client 是什么？

与芒果市场Solana智能合约互动的图书馆\.

### 如何安装 @blockworks-foundation/mango-client？

在项目目录运行 npm install @blockworks-foundation/mango-client，或使用 pnpm add / yarn add / bun add。

### @blockworks-foundation/mango-client 支持 TypeScript 吗？

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

### @blockworks-foundation/mango-client 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @blockworks-foundation/mango-client 需要什么版本的 Node\.js？

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

### @blockworks-foundation/mango-client 可以商用吗？

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

### @blockworks-foundation/mango-client 的下载量有多少？

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

### @blockworks-foundation/mango-client 还在维护吗？

最新版本 2\.3\.0 发布于 2023/11/14（2 年前）；至今共发布 154 个版本，其中过去 12 个月发布了 0 个；首次发布于 2021/02/22。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

