# @evedex/exchange-bot-sdk 中文文档

规范地址：https://npmcn.com/package/%40evedex/exchange-bot-sdk/

版本：1\.2\.12
npm 元数据更新时间：2026-11-11T09:30:04.703Z
中文译文更新时间：2026-11-14T00:58:16.184Z
软件包许可：ISC

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

原始 npm 页面：https://www.npmjs.com/package/%40evedex/exchange-bot-sdk
原文对照：https://npmcn.com/package/%40evedex/exchange-bot-sdk/?lang=original

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

- 包体积（解压后）：245 kB，44 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：15 个
- 首次发布：2025-04-23T20:09:55.195Z
- 最新版本发布：2026-11-11T09:30:04.293Z
- 近 30 天下载量：3254（2026-10-14 至 2026-11-12，npm 官方下载统计）
- 已发布版本数：68（近 12 个月 22 个）

## 中文简介

\[技选

## 安装

```sh
npm install @evedex/exchange-bot-sdk
```

也可以使用：`pnpm add @evedex/exchange-bot-sdk`、`yarn add @evedex/exchange-bot-sdk`、`bun add @evedex/exchange-bot-sdk`

## README

# 用于 Evedex REST APIS 和 WebSockets 的节点.js & JavaScript SDK

\[技选

此 SDK 允许程序访问 [Evedex 交换](https://exchange.evedex.com/) 服务,包括市场数据流、账户计量和订单管理.

-   整合 sdk 与 Evedex REST API 和 WebSockets 合并.
-   TypeScript 支持(大多数API请求和回复都有类型声明).
-   带有钱包私钥或 API 密钥的认证
-   实时余额,位置,订单簿,以及带有缓存管理的订单状态更新.
-   通过钱包账户处理命令的方法:创建替换取消命令.
-   包括订单、位置和取出方法的内部签名请求有效载荷

## 安装

1.  输入 npm 项目
    
2.  安装交换- 机器人- sdk 依赖性
    

```
pnpm add @evedex/exchange-bot-sdk
```

## 使用量

### 初始化容器

可以使用演示(用于测试目的)或生产环境. 要初始化容器, 您需要通过 Websocket 实例 .

如果您使用节点环境, 您需要安装 `ws` 此外:

```
pnpm add ws
```

在初始化容器方法时使用

```ts
import { WebSocket } from "ws";
```

#### 德莫·特拉迪环 环境

```ts
const isDebugMode = true; // optional parameter false by default, true for debugging mode 
const container = new evedexSdk.DemoContainer({
  centrifugeWebSocket: WebSocket,
  wallets: {
    baseAccount: {
      privateKey: "0x...",
    },
  },
  apiKeys: {},
}, isDebugMode);
```

#### 生产环境

```ts
const container = new evedexSdk.ProdContainer({
  centrifugeWebSocket: WebSocket,
  wallets: {
    baseAccount: {
      privateKey: "0x...",
    },
  },
  apiKeys: {},
});
```

### 初始化账户

#### Api 密钥账户

ApiKeyAccount旨在读取用户账户状态,包括:余额,位置,订单.

如果您已经登录到 evedex 交换, 可以创建 api 密钥 .

点击右上角的avatar, 进入配置菜单。 请访问设置 API 创建 API 密钥

输入示例

```ts
import * as evedexSdk from "@evedex/exchange-bot-sdk";

const container = evedexSdk.initContainer(evedexSdk.Environment.DEMO, {
  centrifugeWebSocket: WebSocket,
  wallets: {},
  apiKeys: {
    mainApiKey: {
      apiKey: "cUxD***uOUQ=",
    },
  },
});

// or
const demoContainer = new evedexSdk.DemoContainer({
  centrifugeWebSocket: WebSocket,
  wallets: {},
  apiKeys: {
    mainApiKey: {
      apiKey: "cUxD***uOUQ=",
    },
  },
});

const apiKeyAccount = await container.apiKeyAccount('mainApiKey');
const accountInfo = await apiKeyAccount.fetchMe();
console.log('👤 Account info:', accountInfo);
```

#### 钱包账户

钱包Accout 拥有读取用户账户状态的所有可能性,还包括:

-   命令( 创建、 替换、 取消、 质量取消 ) 用内部签名的方法
    
-   职务工作方法
    
-   平衡的工作方法
    

输入示例

```ts
import * as evedexSdk from "@evedex/exchange-bot-sdk";

const container = new evedexSdk.DemoContainer({
  centrifugeWebSocket: WebSocket,
  wallets: {
    baseAccount: {
      privateKey: "0x...",
    },
  },
});
```

#### 使用一击交易钱包和 api 密钥的钱包账户

钱包账户可以使用一击交易的钱包私钥和API密钥账户进行即时处理

输入示例

```ts
import * as evedexSdk from "@evedex/exchange-bot-sdk";

const container = new evedexSdk.DemoContainer({
  centrifugeWebSocket: WebSocket,
  wallets: {
    oneClickTradingAccount: {
      privateKey: "0x...",
    },
  },
    apiKeys: {
    mainApiKey: {
      apiKey: "cUxD***uOUQ=",
    },
  },
});
// Create api key account
const apiKeyAccount = await container.apiKeyAccount('mainApiKey');
// Receive account info
const accountInfo = await apiKeyAccount.fetchMe();
// Initialize one-click-trading wallet account
const walletAccount = new evedexSdk.WalletAccount({
  gateway: apiKey.gateway,
  wallet: container.wallet('oneClickTradingAccount'),
  exchangeAccount: accountInfo,
});

await walletAccount.createLimitOrderV2({
  instrument: 'BTCUSD:DEV',
  quantity: 0.001,
  side: evedexSdk.Side.Buy,
  limitPrice: 107625,
  leverage: 1,
  postOnly: false,
});
```

#### 余额

余额实例旨在计算可用的用户余额并处理交换事件.

获取前缀返回缓存状态的方法如下:

-   数量(货币) -
-   获取 postitionList () -
-   获得(文书) -
-   获得命令列表( ) -
-   获取 TpSlList () -
-   获得AvailableBalance() -
-   获得权力(文书) -

获取前缀的方法用于从 REST API 检索数据:

-   获取 TpSlList( query) - 获取 TP/ SL 列表
-   获取Me( ) - 获取用户信息
-   获取 Postitions () - 获取位置
-   获取命令( 命令列表查询) — 获取命令
-   获取 AvailableBalance () — 获取可用余额
-   获取 OpenOrders () - 获取打开的命令

余额 `listen` 交换活动的方法订阅:更新位置,订单,资金,tpsl.

信号会因处理事件而解析:

-   帐号更新
-   供资最新情况
-   状态更新
-   命令更新
-   tpSl 更新
-   命令填报更新

样本

```ts
import * as evedexSdk from "@evedex/exchange-bot-sdk";

const container = new evedexSdk.DemoContainer({
  centrifugeWebSocket: WebSocket,
  wallets: {
    baseAccount: {
      privateKey: "0x...",
    },
  },
    
});

const account = await container.account("baseAccount");

const balance = account.getBalance();

balance.listen();

console.log(balance.getPower("BTCUSDT:DEMO"));

console.log(await balance.fetchOrders({ instrument: "BTCUSDT:DEMO" }));

balance.onAccountUpdate((a) => console.info(a));
```

### 实例

Sdk 使用的完整示例 :

```ts
import * as evedexSdk from "@evedex/exchange-bot-sdk";
import { AxiosError } from "axios";
import WebSocket from "ws";

const cfg = {
  centrifugeWebSocket: WebSocket,
  // your wallet private key
  wallets: { myWallet: { privateKey: "5b7..." } },
  // your api key
  apiKeys: { myApiKey: { apiKey: "GNL+Y/VgRj..." } },
};

const container = new evedexSdk.DemoContainer(cfg); // or ProdContainer
const gateway = container.gateway(); // for public api methods

const sampleMarketData = async () => {
  //let's subscribe to the order book update and print 1st value
  console.log("Subscribing to order book update");
  gateway.onOrderBookUpdate((o) => {
    console.log(o);
    gateway.unListenOrderBook("BTCUSDT:DEMO");
  });
  gateway.listenOrderBook("BTCUSDT:DEMO");

  //let's subscribe to the order book best update and print 1st value
  console.log("Subscribing to order book best update");
  gateway.onOrderBookBestUpdate((o) => {
    console.log(o);
    gateway.unListenOrderBookBest("BTCUSDT:DEMO");
  });
  
  const wsTimeout = 2000;
  // wsTimeout ms optional arg - by default 1000 ms
  gateway.listenOrderBookBest("BTCUSDT:DEMO", wsTimeout);

  //let's fetch orderbook directly
  console.log(await gateway.fetchMarketDepth({ instrument: "BTCUSDT:DEMO", maxLevel: 10 }));

  //let's fetch instruments
  console.log(
    (await container.gateway().fetchInstrumentsWithMetrics()).find(
      (i) => i.name === "BTCUSDT:DEMO",
    ),
  );
  console.log(
    (await container.gateway().fetchInstruments()).find((i) => i.name === "BTCUSDT:DEMO"),
  );

  //lets fetch coins
  console.log((await gateway.fetchCoins()).find((c: any) => c.name === "BTC"));
  console.log(await gateway.fetchTrades({ instrument: "BTCUSDT:DEMO" }));
};

const sampleAccountData = async (account: evedexSdk.WalletAccount | evedexSdk.ApiKeyAccount) => {
  //show account info
  console.log(await account.fetchMe());
  const accountState = account.getBalance(); // for account ws callbacks and state
  // let's subscribe to account state metrics
  await accountState.listen(); //await is important here as it will wait till cache is populated
  console.log("Account metrics subscription done, getting state now:");

  // log current state from cache
  console.log(accountState.getOrderList().filter((o) => o.status === evedexSdk.OrderStatus.New));
  console.log(accountState.getFundingQuantity(evedexSdk.CollateralCurrency.USDT));
  console.log(accountState.getAvailableBalance());
  console.log(accountState.getPositionList());
  console.log(accountState.getTpSlList());
  console.log(accountState.getPower("BTCUSDT:DEMO"));

  //also we can fetch the same data from gateway directly
  console.log(await account.fetchOrders({ instrument: "BTCUSDT:DEMO" }));
  console.log(await account.fetchPositions());
  console.log(await account.fetchAvailableBalance());
  console.log(await account.fetchTpSlList({ instrument: "BTCUSDT:DEMO" }));

  //now let's attach callbacks to account updates to print new values
  console.log("Subscribing to account updates");
  accountState.onAccountUpdate((a) => console.info(a));
  accountState.onFundingUpdate((f) => console.info(f));
  accountState.onPositionUpdate((p) => console.info(p));
  accountState.onOrderUpdate((o) => console.info(o));
  accountState.onTpSlUpdate((t) => console.info(t));
};

const sampleOrders = async (account: evedexSdk.WalletAccount) => {
  // //this is how leverage is managed
  await account.updatePosition({ instrument: "BTCUSDT:DEMO", leverage: 20 });

  console.log("Placing limit order");
  const md = await gateway.fetchMarketDepth({ instrument: "BTCUSDT:DEMO", maxLevel: 1 });

  const limitOrder = {
    instrument: "BTCUSDT:DEMO",
    side: evedexSdk.Side.Buy,
    quantity: 0.001,
    limitPrice: md.bids[0].price - 500,
    leverage: 20,
  };
  const order = await account.createLimitOrderV2(limitOrder);
  console.info(`Order created: ${order.id}`);
  console.log("Cancelling limit order...");

  await account.cancelOrder({ orderId: order.id });
  try {
    //both queries will fail with 400 as order is already cancelled
    await account.massCancelUserOrders({ instrument: "BTCUSDT:DEMO" });
    await account.massCancelUserOrdersById({ orderIds: [order.id] });
  } catch (e: any) {
    if (e instanceof AxiosError) console.log(e.response?.data.error);
  }
};

const main = async () => {
  const account = await container.account("myWallet"); // for account methods
  const apiKeyAccount = await container.apiKeyAccount("myApiKey"); // for readonly account methods via api key
  console.log("Init done");

  await sampleMarketData();
  await sampleAccountData(apiKeyAccount); // or apiKeyAccount
  await sampleOrders(account); //order placements only for wallet account

  console.log("Done");
};

main().catch((e) => console.error(e));
```

### 如何在开发环境中测试USDT

为了方便,有一个测试水龙头 立即将1000美元 存入你的智能账户 开发环境.

1.  第一次运行在您注册时自动发生 [https://exchange.evedex.com (中文(简体) )](https://exchange.evedex.com/)
2.  之后,您可以偶尔使用交易所屏幕下方右侧的按钮"Request Demo Funds"请求测试资金.

## 方法树

### 集装箱

-   `constructor(config: ContainerConfig)` ——集装箱实例初始化.

输入容器使用实例

```typescript
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
```

-   `wallet(walletName: string)` 返回钱包类实例.

钱包方法使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const wallet = devContainer.wallet("myWallet");
```

钱包类提供了使用醚类库与Ethereum钱包交互的方法.

方法解释:

-   `getChainId()`: 返回 Ethereum 网络的链式ID, 要么从提供的选项返回 。 链字符串或查询签名人的提供者.
-   `getAddress()`: 返回与钱包相关的Ethereum地址.
-   `solidityPackedKeccak256(types, values)`: 计算所提供的类型和值的固态包装克恰克-256散列.
-   `getBytes(value)`: 返回所提供值字符串的字节表示.
-   `serializeSignature(signature)`:将提供的签名字符串序列化为适合传输的格式.
-   `signMessage(message)`: 使用钱包的私密密钥签名提供的消息字符串或 Uint8Array .
-   `signTypedData(domain, types, value)`:根据EIP-712打出的数据规格,使用钱包的私人密钥,在所提供的域名,类型和值上签名.

-   帐号( wallet Name: string) — 返回 [钱包账户实例](https://npmcn.com/package/%40evedex/exchange-bot-sdk/#readme-wallet-account)。 。 。 .

账户方法使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
```

-   apiKey( apiKeyName: string) – 通过配置名返回用户 api 密钥 .

apiKey 方法使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const userApiKey = devContainer.apiKey("mainApiKey"); // returns 'your-api-key'
```

-   apiKey Account( apiKey) —— 返回 [ApiKey 账户实例](https://npmcn.com/package/%40evedex/exchange-bot-sdk/#readme-api-key-account)。 。 。 .

apiKeycount 方法使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const apiKeyAccount = devContainer.apiKeyAccount("mainApiKey");
```

-   网关() — 返回网关实例( 已过期, 不建议使用) 。 回返a `Gateway` 类案例.
-   关闭WsConnection()——关闭离心机网锁连接.

### 密钥账户

ApiKeyAccount类代表了API密钥账户,该密钥账户提供了与交换网关互动的方法.

要初始化 `ApiKeyAccount` 您需要将您的 API 密钥传递到容器配置 .

分类方法

计数器 :

-   `gateway`: 返回网关实例(已过期,不建议使用).
-   `authGateway`: 返回认证网关(已过期,不建议使用).
-   `exchangeGateway`: 返回交换网关(过期,不建议使用).
-   `wsGateway`: 返回WebSocket网关(过期,不建议使用).
-   `exchangeAccount`: 返回与 API 密钥相关的交换账户.

交换账户方法使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const apiKeyAccount = devContainer.apiKeyAccount("mainApiKey");
const exchangeAccountData = apiKeyAccount.exchangeAccount();
```

交换账户结果实例

```json
{
  "id": "8f0f1f6e-4a6d-4f6a-8e6f-0f6a4f6a8ev",
  "authId": "b6b3a4c6-5a6d-43e6-b6b3-a4c65a6d43e6",
  "exchangeId": 1,
  "name": "John Doe",
  "email": "john.doe@example.com",
  "wallet": "0x1234567890abcdef",
  "social": [
    {
      "type": "twitter",
      "value": "@johndoe"
    },
    {
      "type": "github",
      "value": "johndoe"
    }
  ],
  "avatar": "https://example.com/avatar.jpg",
  "level": 2,
  "locale": "en-US",
  "dateTimeFormat": "MM/DD/YYYY",
  "favoriteInstruments": ["BTCUSDT"],
  "marginCall": false,
  "createdAt": "2022-01-01T12:00:00.000Z",
  "updatedAt": "2022-01-15T14:30:00.000Z"
}
```

-   `session`: 返回与 API 密钥账户相关的会话。 如果 api ey 账户返回 api 密钥 .

方法:

-   `getBalance`: 为 API 密钥账户返回一个新的平衡类实例.
    
-   `fetchTpSlList`: 获取基于所提供的查询参数的Take Profit and Stop Loss(TpSl)命令列表.
    

获取 TpSlList 方法使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container, TpSlType } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const apiKeyAccount = devContainer.apiKeyAccount("mainApiKey");
const query = {
  instrument: ["BTCUSDT", "ETHUSDT"],
  status: ["active", "pending"],
  type: TpSlType.TakeProfit,
  offset: 0,
  limit: 10,
};
const tpslList = await apiKeyAccount.fetchTpSlList(query);
```

tpsl 列表结果示例

```json
{
  "list": [
    {
      "id": "f47ac10b-58cc-4752-9f6a-8e3f9e7a6c11",
      "instrument": "BTCUSDT",
      "type": "take-profit",
      "side": "BUY",
      "quantity": "0.1",
      "price": "50000.00",
      "status": "active",
      "triggerOrder": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b9d4c22",
      "triggeredQuantity": "0.05",
      "cancelledReason": "",
      "createdAt": "2022-01-01T12:00:00.000Z",
      "updatedAt": "2022-01-15T14:30:00.000Z"
    }
  ]
}
```

-   `fetchMe`: 获取当前用户信息.

获取 Me 方法使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const apiKeyAccount = devContainer.apiKeyAccount("mainApiKey");
const userData = await apiKeyAccount.fetchMe();
```

获取我的结果示例

```json
{
  "id": "8f0f1f6e-4a6d-4f6a-8e6f-0f6a4f6a8ev",
  "authId": "b6b3a4c6-5a6d-43e6-b6b3-a4c65a6d43e6",
  "exchangeId": 1,
  "name": "John Doe",
  "email": "john.doe@example.com",
  "wallet": "0x1234567890abcdef",
  "social": [
    {
      "type": "twitter",
      "value": "@johndoe"
    },
    {
      "type": "github",
      "value": "johndoe"
    }
  ],
  "avatar": "https://example.com/avatar.jpg",
  "level": 2,
  "locale": "en-US",
  "dateTimeFormat": "MM/DD/YYYY",
  "favoriteInstruments": ["BTCUSDT"],
  "marginCall": false,
  "createdAt": "2022-01-01T12:00:00.000Z",
  "updatedAt": "2022-01-15T14:30:00.000Z"
}
```

-   `fetchPositions`:获取当前用户位置列表.

获取 Postitions 方法使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const apiKeyAccount = devContainer.apiKeyAccount("mainApiKey");
const positions = await apiKeyAccount.fetchPositions();
```

获取结果示例

```json
[
  {
    "id": "1-BTCUSDT",
    "user": "1",
    "instrument": "BTCUSDT",
    "side": "buy",
    "quantity": 0.1,
    "avgPrice": 50000.0,
    "fundingRate": 0.01,
    "leverage": 10,
    "maintenanceMargin": 0.05,
    "createdAt": "2022-01-01T12:00:00.000Z",
    "updatedAt": "2022-01-15T14:30:00.000Z",
    "unRealizedPnL": 1000.0,
    "adlLevel": 2
  }
]
```

-   `fetchOrders`:根据提供的查询参数获取用户命令列表.

获取命令方法使用示例

```typescript
import { WebSocket } from "ws";
import {
  Environment,
  Container,
  Side,
  OrderType,
  OrderGroup,
  OrderStatus,
} from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const apiKeyAccount = devContainer.apiKeyAccount("mainApiKey");
const orderListQueryParams = {
  instrument: "BTCUSDT",
  status: [OrderStatus.New, OrderStatus.PartiallyFilled],
  group: [OrderGroup.Manually, OrderGroup.TpSl],
  type: [OrderType.Limit, OrderType.Market],
  side: Side.Buy,
  version: 2,
  limit: 10,
  offset: 0,
};

const orderList = await apiKeyAccount.fetchOrders(orderListQueryParams);
```

获取命令结果示例

```json
{
  "list": [
    {
      "id": "a6f1c4e5-3b7d-42e6-b6b3-a4c65a6d43e6",
      "user": "67890",
      "instrument": "BTCUSDT",
      "side": "BUY",
      "type": "LIMIT",
      "quantity": 0.1,
      "cashQuantity": 5000.0,
      "limitPrice": 50000.0,
      "stopPrice": null,
      "status": "PARTIALLY_FILLED",
      "unFilledQuantity": 0.05,
      "filledAvgPrice": 50050.0,
      "realizedPnL": 100.0,
      "fee": [
        {
          "coin": "USDT",
          "quantity": 10.0
        }
      ],
      "createdAt": "2022-01-01T12:00:00.000Z",
      "updatedAt": "2022-01-15T14:30:00.000Z",
      "triggeredAt": null,
      "group": "manually"
    }
  ],
  "count": 1
}
```

-   `fetchAvailableBalance`:获取当前用户可用的余额.

获取 AvailableBalance 方法使用示例

```typescript
import { WebSocket } from "ws";
import {
  Environment,
  Container,
  Side,
  OrderType,
  OrderGroup,
  OrderStatus,
} from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const apiKeyAccount = devContainer.apiKeyAccount("mainApiKey");
const availableBalance = await apiKeyAccount.fetchAvailableBalance();
```

获取 AvailableBalance 结果示例

```json
{
  "funding": {
    "currency": "USDT",
    "balance": "10000.00"
  },
  "positions": [
    {
      "instrument": "BTCUSDT",
      "side": "buy",
      "volume": "0.1",
      "initialMargin": "500.00"
    },
    {
      "instrument": "ETHUSDT",
      "side": "sell",
      "volume": "1.0",
      "initialMargin": "1000.00"
    }
  ],
  "openOrders": [
    {
      "instrument": "BTCUSDT",
      "side": "buy",
      "unFilledVolume": "0.05",
      "unFilledInitialMargin": "250.00"
    },
    {
      "instrument": "ETHUSDT",
      "side": "sell",
      "unFilledVolume": "0.5",
      "unFilledInitialMargin": "500.00"
    }
  ],
  "availableBalance": "5000.00"
}
```

-   `fetchPower`:获取用户电源以出售并购买侧.

获取Power 方法使用示例

```typescript
import { WebSocket } from "ws";
import {
  Environment,
  Container,
  Side,
  OrderType,
  OrderGroup,
  OrderStatus,
} from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const apiKeyAccount = devContainer.apiKeyAccount("mainApiKey");
const powerQueryParams = {
  instrument: "BTCUSDT",
};
const power = await apiKeyAccount.fetchPower(powerQueryParams);
```

获取Power 结果示例

```json
{
  "buy": {
    "power": 1000
  },
  "sell": {
    "power": 2000
  }
}
```

-   `fetchOpenOrders`:为当前用户获取打开命令列表.

获取 OpenOrders 方法使用示例

```typescript
import { WebSocket } from "ws";
import {
  Environment,
  Container,
  Side,
  OrderType,
  OrderGroup,
  OrderStatus,
} from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const apiKeyAccount = devContainer.apiKeyAccount("mainApiKey");
const openOrders = await apiKeyAccount.fetchOpenOrders();
```

获取 OpenOrders 结果示例

```json
[
  {
    "id": "a6f1c4e5-3b7d-42e6-b6b3-a4c65a6d43e6",
    "user": "67890",
    "instrument": "BTCUSDT",
    "side": "BUY",
    "type": "LIMIT",
    "status": "PARTIALLY_FILLED",
    "quantity": 0.1,
    "limitPrice": 50000.0,
    "unFilledQuantity": 0.05,
    "fee": [
      {
        "coin": "USDT",
        "quantity": 10.0
      }
    ],
    "updatedAt": "2022-01-15T14:30:00.000Z",
    "cashQuantity": 5000.0
  }
]
```

### 钱包账户( 扩展会话账户)

此类扩展了会话账户类, 它扩展了 ApiKey Account .

`WalletAccount` 包含 `ApiKeyAccount` • 提供执行各种贸易行动的方法和方法.

要初始化 `WalletAccount` 您需要将您的钱包私钥传递到容器配置.

分类方法

-   `createWithdraw(withdraw)` ——用于创建已签名的退出请求并发送到交换网关的方法.

创建Wordraw 方法使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container, type TradingBalanceWithdraw } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const withdrawQueryParams: TradingBalanceWithdraw = {
  recipient: "0x1234567890abcdef",
  amount: 100.5,
};
const withdrawResult = await walletAccount.createWithdraw(withdrawQueryParams);
```

创建( W)

```json
{
  "id": "123e4567-e89b-12d3-a456-426655440000",
  "user": "f47ac10b-58cc-4372-a567-0e02bdc8d47d",
  "type": "withdraw",
  "coin": "USDT",
  "amount": 100.5,
  "fee": 0.1,
  "status": "pending",
  "createdAt": "2023-02-20T14:30:00.000Z",
  "updatedAt": "2023-02-20T14:30:00.000Z"
}
```

-   `createClosePositionOrderV2(order)` – 用于创建已签名的近位置命令并发送到交换网关的方法

创建 ClosePostion OrderV2 方法使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container, type PositionCloseOrderPayload } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const positionCloseOrderPayload: PositionCloseOrderPayload = {
  instrument: "BTCUSDT",
  leverage: 10,
  quantity: 0.1,
};
const closePositionResult = await walletAccount.createClosePositionOrderV2(positionCloseOrderPayload);
```

创建 ClosePostion OrderV2 结果示例

```json
{
  "id": "a6f1c4e5-3b7d-42e6-b6b3-a4c65a6d43e6",
  "user": "67890",
  "instrument": "BTCUSDT",
  "side": "BUY",
  "type": "MARKET",
  "quantity": 0.1,
  "cashQuantity": 5000.0,
  "limitPrice": null,
  "stopPrice": null,
  "status": "FILLED",
  "unFilledQuantity": 0,
  "filledAvgPrice": 50050.0,
  "realizedPnL": 100.0,
  "fee": [
    {
      "coin": "USDT",
      "quantity": 10.0
    }
  ],
  "createdAt": "2022-01-01T12:00:00.000Z",
  "updatedAt": "2022-01-15T14:30:00.000Z",
  "triggeredAt": null,
  "group": "manually"
}
```

-   `updatePosition(query)` ——用于更新开放位置杠杆的方法.

创建Wordraw 方法使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container, type PositionUpdateQuery } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const positionUpdatePayload: PositionUpdateQuery = {
  instrument: "BTCUSDT",
  leverage: 20,
};

const updatePositionResult = await walletAccount.updatePosition(positionCloseOrderPayload);
```

更新结果实例

```json
{
  "instrument": "BTCUSDT",
  "side": "BUY",
  "quantity": 10,
  "avgPrice": 100.0,
  "leverage": 20,
  "maintenanceMargin": 1000.0,
}
```

-   `createLimitOrderV2(order)` ——用于创建已签名的限制令并发送到交换网关的方法.

创建 LimitOrderV2( order) 方法使用示例

```typescript
import { WebSocket } from "ws";
import {
  Environment,
  Container,
  type LimitOrderPayload,
  Side,
  TpSlType,
} from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const limitOrderPayload: LimitOrderPayload = {
  instrument: "BTCUSDT",
  side: Side.Buy,
  leverage: 10,
  quantity: 0.01,
  limitPrice: 100000,
  tpsl: [
    {
      type: TpSlType.TakeProfit,
      side: Side.Buy,
      quantity: 0.01,
      price: 120000,
    },
    {
      type: TpSlType.StopLoss,
      side: Side.Buy,
      quantity: 0.01,
      price: 80000,
    },
  ],
  // Optional flag to use for POST only limit orders
  postOnly: true
};
const createLimitOrderResult = await walletAccount.createLimitOrderV2(limitOrderPayload);
```

创建LimitV2 顺序结果示例

```json
{
  "id": "a6f1c4e5-3b7d-42e6-b6b3-a4c65a6d43e6",
  "user": "67890",
  "instrument": "BTCUSDT",
  "side": "BUY",
  "type": "LIMIT",
  "quantity": 0.01,
  "cashQuantity": 0,
  "limitPrice": 100000,
  "stopPrice": null,
  "status": "NEW",
  "unFilledQuantity": 0.01,
  "filledAvgPrice": 0,
  "realizedPnL": 0,
  "fee": [
    {
      "coin": "USDT",
      "quantity": 10.0
    }
  ],
  "createdAt": "2022-01-01T12:00:00.000Z",
  "updatedAt": "2022-01-15T14:30:00.000Z",
  "triggeredAt": null,
  "group": "manually",
  "exchangeRequestId": "1"
}
```

-   `batchCreateLimitOrderV2(orders)` ——用于创建已签名的限制令并发送到交换网关的方法.

批量创建LimitOrderV2(顺序)方法使用示例

```typescript
import { WebSocket } from "ws";
import {
  Environment,
  Container,
  type LimitOrderPayload,
  Side,
  TpSlType,
} from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const instrument = "BTCUSDT";
const limitOrderPayloads: LimitOrderPayload[] = [
  {
    instrument,
    side: Side.Buy,
    leverage: 10,
    quantity: 0.01,
    limitPrice: 100000,
    postOnly: true
  },
  {
    instrument,
    side: Side.Buy,
    leverage: 10,
    quantity: 0.02,
    limitPrice: 101000,
  },
];
const batchCreateLimitOrderResult = await walletAccount.batchCreateLimitOrderV2(
  instrument,
  limitOrderPayloads,
);
```

批量创建LimitOrderV2 结果示例

```json
[
  {
    "orderId": "a6f1c4e5-3b7d-42e6-b6b3-a4c65a6d43e7",
    "success": true
  },
  {
    "orderId": "a6f1c4e5-3b7d-42e6-b6b3-a4c65a6d43e8",
    "success": false,
    "failReason": "Insufficient funds"
  }
]
```

-   `replaceLimitOrder(order)` ——用于更新(替换)开放限制令的方法.

替换 LimitOrder( 顺序) 方法使用示例

```typescript
import { WebSocket } from "ws";
import {
  Environment,
  Container,
  type ReplaceLimitOrder,
  Side,
  TpSlType,
} from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const replaceLimitOrderPayload: ReplaceLimitOrder = {
  orderId: "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
  quantity: 0.02,
  limitPrice: 105000,
  // Optional flag to use for POST only limit orders
  postOnly: true
};
const replaceLimitOrderResult = await walletAccount.replaceLimitOrder(replaceLimitOrderPayload);
```

替换 LimitOrder 结果示例

```json
{
  "id": "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
  "user": "67890",
  "instrument": "BTCUSDT",
  "side": "BUY",
  "type": "LIMIT",
  "quantity": 0.02,
  "cashQuantity": 0,
  "limitPrice": 105000,
  "stopPrice": null,
  "status": "REPLACED",
  "unFilledQuantity": 0.02,
  "filledAvgPrice": 0,
  "realizedPnL": 0,
  "fee": [
    {
      "coin": "USDT",
      "quantity": 10.0
    }
  ],
  "createdAt": "2022-01-01T12:00:00.000Z",
  "updatedAt": "2022-01-15T14:30:00.000Z",
  "triggeredAt": null,
  "group": "manually",
  "exchangeRequestId": "1"
}
```

-   `batchReplaceLimitOrder(orderList)` ——用于批量替换开放限制令的方法. **已去已去已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已. 代之以批量重置仪器命令方法**
    
-   `batchReplaceInstrumentLimitOrder(instrument, orderList)` ——用于批量替换开放限制令的方法.
    

重置仪器Limit Order( 仪器, 订单) 方法使用示例

```typescript
import { WebSocket } from "ws";
import {
  Environment,
  Container,
  type ReplaceLimitOrder,
  Side,
  TpSlType,
} from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const replaceLimitOrderPayloads: ReplaceLimitOrder[] = [
  {
    orderId: "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
    quantity: 0.02,
    limitPrice: 105000,
    // Optional flag to use for POST only limit orders
    postOnly: true
  },
  {
    orderId: "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1n",
    quantity: 0.01,
    limitPrice: 95000,
  },
];
const batchReplaceInstrumentLimitOrderResult = await walletAccount.batchReplaceInstrumentLimitOrder(
  "BTCUSDT",
  replaceLimitOrderPayloads,
);
```

更换仪器命令结果实例

```json
{}
```

-   `createMarketOrderV2(order)` ——用于创建签字市场秩序的方法.

创建 MarketOrderV2( 顺序) 方法使用示例

```typescript
import { WebSocket } from "ws";
import {
  Environment,
  Container,
  type MarketOrderPayload,
  TimeInForce,
  Side,
  TpSlType,
} from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const marketOrderPayload: MarketOrderPayload = {
  instrument: "BTCUSDT",
  side: Side.Buy,
  leverage: 10,
  timeInForce: TimeInForce.IOC,
  cashQuantity: 1000,
  tpsl: [
    {
      type: TpSlType.TakeProfit,
      side: Side.Buy,
      quantity: 0.01,
      price: 120000,
    },
    {
      type: TpSlType.StopLoss,
      side: Side.Buy,
      quantity: 0.01,
      price: 80000,
    },
  ],
};
const createMarketOrderResult = await walletAccount.createMarketOrderV2(marketOrderPayload);
```

创建 MarketOrderV2 结果示例

```json
{
  "id": "a6f1c4e5-3b7d-42e6-b6b3-a4c65a6d43e6",
  "user": "67890",
  "instrument": "BTCUSDT",
  "side": "BUY",
  "type": "MARKET",
  "quantity": 0,
  "cashQuantity": 1000,
  "limitPrice": 0,
  "stopPrice": null,
  "status": "NEW",
  "unFilledQuantity": 0.01,
  "filledAvgPrice": 0,
  "realizedPnL": 0,
  "fee": [
    {
      "coin": "USDT",
      "quantity": 10.0
    }
  ],
  "createdAt": "2022-01-01T12:00:00.000Z",
  "updatedAt": "2022-01-15T14:30:00.000Z",
  "triggeredAt": null,
  "group": "manually",
  "exchangeRequestId": "1"
}
```

-   `createStopLimitOrderV2(order)` ——用于创建止止限令的方法.

创建StopLimitOrderV2(order)方法使用示例

```typescript
import { WebSocket } from "ws";
import {
  Environment,
  Container,
  type StopLimitOrderPayload,
  Side,
  TpSlType,
} from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const limitOrderPayload: StopLimitOrderPayload = {
  instrument: "BTCUSDT",
  side: Side.Buy,
  leverage: 10,
  quantity: 0.01,
  limitPrice: 100000,
  stopPrice: 100500,
  tpsl: [
    {
      type: TpSlType.TakeProfit,
      side: Side.Buy,
      quantity: 0.01,
      price: 120000,
    },
    {
      type: TpSlType.StopLoss,
      side: Side.Buy,
      quantity: 0.01,
      price: 80000,
    },
  ],
};
const createStopLimitOrderResult = await walletAccount.createStopLimitOrderV2(limitOrderPayload);
```

创建StopLimitOrderV2 结果示例

```json
{
  "id": "a6f1c4e5-3b7d-42e6-b6b3-a4c65a6d43e6",
  "user": "67890",
  "instrument": "BTCUSDT",
  "side": "BUY",
  "type": "STOP_LIMIT",
  "quantity": 0.01,
  "cashQuantity": 0,
  "limitPrice": 100000,
  "stopPrice": 100500,
  "status": "NEW",
  "unFilledQuantity": 0.01,
  "filledAvgPrice": 0,
  "realizedPnL": 0,
  "fee": [
    {
      "coin": "USDT",
      "quantity": 10.0
    }
  ],
  "createdAt": "2022-01-01T12:00:00.000Z",
  "updatedAt": "2022-01-15T14:30:00.000Z",
  "triggeredAt": null,
  "group": "manually",
  "exchangeRequestId": "1"
}
```

-   `replaceStopLimitOrder(order)` ——用于替换停放限制令的方法.

替换 StopLimit Order( 顺序) 方法使用示例

```typescript
import { WebSocket } from "ws";
import {
  Environment,
  Container,
  type ReplaceStopLimitOrder,
  Side,
  TpSlType,
} from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const replaceLimitOrderPayload: ReplaceStopLimitOrder = {
  orderId: "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
  quantity: 0.02,
  limitPrice: 105000,
  stopPrice: 105500,
};
const replaceLimitOrderResult = await walletAccount.replaceStopLimitOrder(replaceLimitOrderPayload);
```

替换“停止命令”结果示例

```json
{
  "id": "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
  "user": "67890",
  "instrument": "BTCUSDT",
  "side": "BUY",
  "type": "LIMIT",
  "quantity": 0.02,
  "cashQuantity": 0,
  "limitPrice": 105000,
  "stopPrice": 105500,
  "status": "REPLACED",
  "unFilledQuantity": 0.02,
  "filledAvgPrice": 0,
  "realizedPnL": 0,
  "fee": [
    {
      "coin": "USDT",
      "quantity": 10.0
    }
  ],
  "createdAt": "2022-01-01T12:00:00.000Z",
  "updatedAt": "2022-01-15T14:30:00.000Z",
  "triggeredAt": null,
  "group": "manually",
  "exchangeRequestId": "1"
}
```

-   `cancelOrder(query)` ——取消订单的方法.

取消命令( query) 方法使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container, type OrderCancelQuery } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const cancelOrderPayload: OrderCancelQuery = {
  orderId: "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
};
const cancelOrderResult = await walletAccount.cancelOrder(cancelOrderPayload);
```

取消命令结果示例

```json
{}
```

-   `massCancelUserOrdersById(query)` ——由ids取消用户订单的方法.

质量终止用户命令ById( 清) 方法使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container, type OrderMassCancelByIdQuery } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const massCancelUserOrdersByIdParams: OrderMassCancelByIdQuery = {
  orderIds: ["4f6c21a4-3c4f-4f2e-8f6d-5b4c7a9d2e1f", "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f"],
};
const massCancelUserOrdersResult = await walletAccount.massCancelUserOrdersById(
  massCancelUserOrdersByIdParams,
);
```

质量取消用户命令ById 结果实例

```json
{}
```

-   `massCancelUserOrders(query)` ——通过仪器取消用户订单的方法.

质量取消用户命令( query) 方法使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container, type OrderMassCancelQuery } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const massCancelUserOrdersParams: OrderMassCancelQuery = {
  instrument: "BTCUSDT",
};
const massCancelUserOrdersResult = await walletAccount.massCancelUserOrders(
  massCancelUserOrdersParams,
);
```

质量取消用户命令结果示例

```json
{}
```

-   `createTpSl(tpsl)` ——用于创建Take Profit/Stop Loss订单的方法.

创建 TpSl(tpsl) 方法使用示例

```typescript
import { WebSocket } from "ws";
import {
  Environment,
  Container,
  type TpSlCreatePayload,
  Side,
  TpSlType,
} from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const tpslPayload: TpSlCreatePayload = {
  type: TpSlType.TakeProfit,
  side: Side.Buy,
  quantity: 0.01,
  price: 120000,
  order: "4f6c21a4-3c4f-4f2e-8f6d-5b4c7a9d2e1f",
  instrument: "BTCUSDT",
};
const createTpSlResult = await walletAccount.createTpSl(tpslPayload);
```

创建 TpSl 结果示例

```json
{
  "id": "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
  "instrument": "BTCUSD",
  "type": "take-profit",
  "side": "BUY",
  "quantity": "0.01",
  "price": "120000",
  "status": "waitOrder",
  "triggerOrder": null,
  "triggeredQuantity": "0",
  "cancelledReason": "",
  "createdAt": "2023-02-20T14:30:00.000Z",
  "updatedAt": "2023-02-20T14:30:00.000Z"
}
```

-   `updateTpSl(query)` ——用于更新Take Profit/Stop Loss订单的方法.

更新 TpSl( query) 方法使用示例

```typescript
import { WebSocket } from "ws";
import {
  Environment,
  Container,
  type TpSlUpdateQuery,
  Side,
  TpSlType,
} from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const tpslUpdatePayload: TpSlUpdateQuery = {
  type: TpSlType.TakeProfit,
  side: Side.Buy,
  quantity: 0.01,
  price: 121000,
  order: "4f6c21a4-3c4f-4f2e-8f6d-5b4c7a9d2e1f",
  instrument: "BTCUSDT",
  id: "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
};
const updateTpSlResult = await walletAccount.updateTpSl(tpslUpdatePayload);
```

更新 TpSl 结果示例

```json
{
  "id": "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
  "instrument": "BTCUSD",
  "type": "take-profit",
  "side": "BUY",
  "quantity": "0.01",
  "price": "121000",
  "status": "waitOrder",
  "triggerOrder": null,
  "triggeredQuantity": "0",
  "cancelledReason": "",
  "createdAt": "2023-02-20T14:30:00.000Z",
  "updatedAt": "2023-02-20T14:30:00.000Z"
}
```

-   `cancelTpSl(query)` - 取消利润/停止损失订单的方法.

取消 TpSl( query) 方法使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container, type TpSlCancelQuery } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const tpslCancelPayload: TpSlCancelQuery = {
  instrument: "BTCUSDT",
  id: "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
};
const cancelTpSlResult = await walletAccount.cancelTpSl(tpslCancelPayload);
```

取消 TpSl 结果示例

```json
{
  "id": "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
  "instrument": "BTCUSD",
  "type": "take-profit",
  "side": "BUY",
  "quantity": "0.01",
  "price": "121000",
  "status": "cancelled",
  "triggerOrder": null,
  "triggeredQuantity": "0",
  "cancelledReason": "",
  "createdAt": "2023-02-20T14:30:00.000Z",
  "updatedAt": "2023-02-20T14:30:00.000Z"
}
```

### 余额

这个班级用来获取实时可用的平衡和动力数据并处理交换事件.

-   `constructor(options: BalanceOptions)` ——用于创建 `Balance` 举个例子.

Init 平衡使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

// using wallet account

const devContainer = new Container(config);

const walletAccount = await devContainer.account("myWallet");

const balance = walletAccount.getBalance();

// or using api key account

const apiKeyAccount = await devContainer.apiKeyAccount("mainApiKey");

const balanceFromApiKeyAccount = apiKeyAccount.getBalance();
```

-   `listen()` - 用于订阅交换事件和填充平衡状态的方法。 返回平衡类实例

声音( ) 使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);

const walletAccount = await devContainer.account("myWallet");

const balance = walletAccount.getBalance();

await balance.listen();
```

-   `unListen()` - 用于不订阅交换事件并重置平衡状态的方法。 返回平衡类实例

未倾听( ) 使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);

const walletAccount = await devContainer.account("myWallet");

const balance = walletAccount.getBalance();

await balance.listen();

await balance.unListen();
```

-   `getFundingQuantity(currency)` ——用于获取余额当前资金的方法.

获得资金数量()使用实例

```typescript
import { WebSocket } from "ws";
import { Environment, Container, CollateralCurrency } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);

const walletAccount = await devContainer.account("myWallet");

const balance = walletAccount.getBalance();

await balance.listen();

const funding = balance.getFundingQuantity(CollateralCurrency.USDT); // Example: returns "1000"
```

-   `getWithdrawTransferPendingQuantity()` 退还待收回的转移款总额的方法.

获取Wordraw TransferPending 数量

```typescript
import { WebSocket } from "ws";
import { Environment, Container, CollateralCurrency } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);

const walletAccount = await devContainer.account("myWallet");

const balance = walletAccount.getBalance();

await balance.listen();

const withdrawPendingTrasferAmount = balance.getWithdrawTransferPendingQuantity(
  CollateralCurrency.USDT,
); // Example: returns Big instance
```

-   `getPositionList()` 返回平衡的所有位置的方法.

获取 PositionList () 使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container, CollateralCurrency } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);

const walletAccount = await devContainer.account("myWallet");

const balance = walletAccount.getBalance();

await balance.listen();

const positions = balance.getPositionList();
```

获取选项 列表结果示例

```json
[
  {
    "id": "1-BTCUSDT",
    "user": "johnDoe",
    "instrument": "BTCUSDT",
    "side": "BUY",
    "quantity": 0.1,
    "avgPrice": 50000,
    "fundingRate": 0.01,
    "leverage": 5,
    "maintenanceMargin": 100,
    "createdAt": "2022-01-01T12:00:00.000Z",
    "updatedAt": "2022-01-01T12:00:00.000Z"
  }
]
```

-   `getPosition(instrument)` ——按仪器返回用户位置的方法.

获取设备( 仪器) 使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);

const walletAccount = await devContainer.account("myWallet");

const balance = walletAccount.getBalance();

await balance.listen();

const position = balance.getPosition("BTCUSDT");
```

获取结果示例

```json
{
  "id": "1-BTCUSDT",
  "user": "johnDoe",
  "instrument": "BTCUSDT",
  "side": "BUY",
  "quantity": 0.1,
  "avgPrice": 50000,
  "fundingRate": 0.01,
  "leverage": 5,
  "maintenanceMargin": 100,
  "createdAt": "2022-01-01T12:00:00.000Z",
  "updatedAt": "2022-01-01T12:00:00.000Z"
}
```

-   `getOrderList()` ——返回现有订单列表的方法.

获取命令列表 () 使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);

const walletAccount = await devContainer.account("myWallet");

const balance = walletAccount.getBalance();

await balance.listen();

const orderList = balance.getOrderList();
```

获得命令列表 () 结果示例

```json
[
  {
    "id": "9fcbf9d3-4a3d-4a6b-8a6f-5f4c9d3a1b2c",
    "user": "1",
    "instrument": "BTCUSDT",
    "side": "BUY",
    "type": "LIMIT",
    "status": "NEW",
    "quantity": 0.1,
    "limitPrice": 50000,
    "unFilledQuantity": 0.1,
    "fee": [
      {
        "coin": "USDT",
        "quantity": 10.0
      }
    ],
    "updatedAt": "2022-01-01T12:00:00.000Z",
    "cashQuantity": 0
  }
]
```

-   `getTpSlList()` ——返回已有的Take Profit/Stop Loss订单的方法.

获取 TpSlList () 使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);

const walletAccount = await devContainer.account("myWallet");

const balance = walletAccount.getBalance();

await balance.listen();

const tpSlList = balance.getTpSlList();
```

获得 TpSlList () 结果示例

```json
[
  {
    "id": "f47ac10b-58cc-4752-9f6a-8e3f9e7a6c11",
    "instrument": "BTCUSDT",
    "type": "take-profit",
    "side": "BUY",
    "quantity": "0.1",
    "price": "50000.00",
    "status": "active",
    "triggerOrder": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b9d4c22",
    "triggeredQuantity": "0.05",
    "cancelledReason": "",
    "createdAt": "2022-01-01T12:00:00.000Z",
    "updatedAt": "2022-01-15T14:30:00.000Z"
  }
]
```

-   `getAvailableBalance()` ——返回账户现有余额、现有位置和未结订单的方法.

获得 AvailableBalance () 使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);

const walletAccount = await devContainer.account("myWallet");

const balance = walletAccount.getBalance();

await balance.listen();

const availableBalance = balance.getAvailableBalance();
```

获得AvailableBalance () 结果实例

```json
{
  "funding": {
    "currency": "USDT",
    "balance": "10000.00"
  },
  "positions": [
    {
      "instrument": "BTCUSDT",
      "side": "buy",
      "volume": "0.1",
      "initialMargin": "500.00"
    },
    {
      "instrument": "ETHUSDT",
      "side": "sell",
      "volume": "1.0",
      "initialMargin": "1000.00"
    }
  ],
  "openOrders": [
    {
      "instrument": "BTCUSDT",
      "side": "buy",
      "unFilledVolume": "0.05",
      "unFilledInitialMargin": "250.00"
    },
    {
      "instrument": "ETHUSDT",
      "side": "sell",
      "unFilledVolume": "0.5",
      "unFilledInitialMargin": "500.00"
    }
  ],
  "availableBalance": "5000.00"
}
```

-   `getPower(instrument)` ——返回当前买卖力的方法(最大可用订单价值).

获取Power( 仪器) 使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);

const walletAccount = await devContainer.account("myWallet");

const balance = walletAccount.getBalance();

await balance.listen();

const power = balance.getPower("BTCUSDT");
```

获取Power( 工具) 结果示例

```json
{
  "buy": 1000,
  "sell": 1500
}
```

信号 :

平衡类实例可以处理由使用信号被websocket取回的交换产生的实时事件.

-   `onAccountUpdate()` - 更新用户数据的信号

账户更新( ) 使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);

const walletAccount = await devContainer.account("myWallet");

const balance = walletAccount.getBalance();

await balance.listen();

balance.onAccountUpdate((accountState) => console.log(accountState));
```

() 事件有效载荷实例

```json
{
  "id": "8f0f1f6e-4a6d-4f6a-8e6f-0f6a4f6a8ev",
  "authId": "b6b3a4c6-5a6d-43e6-b6b3-a4c65a6d43e6",
  "exchangeId": 1,
  "name": "John Doe",
  "email": "john.doe@example.com",
  "wallet": "0x1234567890abcdef",
  "social": [
    {
      "type": "twitter",
      "value": "@johndoe"
    },
    {
      "type": "github",
      "value": "johndoe"
    }
  ],
  "avatar": "https://example.com/avatar.jpg",
  "level": 2,
  "locale": "en-US",
  "dateTimeFormat": "MM/DD/YYYY",
  "favoriteInstruments": ["BTCUSDT"],
  "marginCall": false,
  "createdAt": "2022-01-01T12:00:00.000Z",
  "updatedAt": "2022-01-15T14:30:00.000Z"
}
```

-   `onFundingUpdate()` - 更新用户数据的信号

() 使用实例

```typescript
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);

const walletAccount = await devContainer.account("myWallet");

const balance = walletAccount.getBalance();

await balance.listen();

balance.onFundingUpdate((fundingState) => console.log(fundingState));
```

事件有效载荷实例

```json
{
  "coin": "BTC",
  "quantity": 0.5,
  "updatedAt": "2022-01-01T12:00:00.000Z"
}
```

-   `onTransferUpdate()` ——更新用户传输数据的信号

在 TransferUpdate () 使用示例上

```typescript
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);

const walletAccount = await devContainer.account("myWallet");

const balance = walletAccount.getBalance();

await balance.listen();

balance.onTransferUpdate((transferState) => console.log(transferState));
```

() 事件有效载荷实例

```json
{
  "id": "8b6e9f4c-4a3d-4f6b-8a6f-5f4c9d3a1b2c",
  "user": "1",
  "type": "withdraw",
  "coin": "BTC",
  "amount": 0.5,
  "fee": 0.001,
  "status": "pending",
  "createdAt": "2022-01-01T12:00:00.000Z",
  "updatedAt": "2022-01-01T12:00:00.000Z"
}
```

-   `onPositionUpdate()` - 用户位置数据更新信号

使用实例

```typescript
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);

const walletAccount = await devContainer.account("myWallet");

const balance = walletAccount.getBalance();

await balance.listen();

balance.onPositionUpdate((positionState) => console.log(positionState));
```

事件有效载荷实例

```json
{
  "id": "1-BTCUSDT",
  "user": "1",
  "instrument": "BTCUSDT",
  "side": "buy",
  "quantity": 0.1,
  "avgPrice": 50000.0,
  "fundingRate": 0.01,
  "leverage": 10,
  "maintenanceMargin": 0.05,
  "createdAt": "2022-01-01T12:00:00.000Z",
  "updatedAt": "2022-01-15T14:30:00.000Z",
  "unRealizedPnL": 1000.0,
  "adlLevel": 2
}
```

-   `onOrderUpdate()` ——更新用户订单数据信号

命令更新( ) 使用示例

```typescript
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";

const config = {
  environment: Environment.DEV,
  centrifugeWebSocket: WebSocket,
  wallets: {
    myWallet: {
      privateKey: "your-private-key",
    },
  },
  apiKeys: {
    mainApiKey: {
      apiKey: "your-api-key",
    },
  },
};

const devContainer = new Container(config);

const walletAccount = await devContainer.account("myWallet");

const balance = walletAccount.g
```

## 常见问题

### @evedex/exchange-bot-sdk 是什么？

\[技选

### 如何安装 @evedex/exchange-bot-sdk？

在项目目录运行 npm install @evedex/exchange-bot-sdk，或使用 pnpm add / yarn add / bun add。

### @evedex/exchange-bot-sdk 支持 TypeScript 吗？

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

### @evedex/exchange-bot-sdk 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @evedex/exchange-bot-sdk 可以商用吗？

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

### @evedex/exchange-bot-sdk 的下载量有多少？

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

### @evedex/exchange-bot-sdk 还在维护吗？

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

