@imbingox/acex 0.1.0-beta.2 → 0.1.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @imbingox/acex
2
2
 
3
- `acex` 是一个面向交易场景的状态型 SDK。调用方只需要持有一个 `AcexClient`,就可以通过统一的 `market`、`account`、`order` manager 读取最新快照、订阅增量事件、观察健康状态,而不需要自己维护本地缓存、ready barrier 或 websocket 生命周期。
3
+ `acex` 是一个面向交易场景的状态型 SDK。调用方只需要持有一个 `AcexClient`,就可以通过统一的 `market`、`account`、`order` manager 读取最新快照、订阅增量事件、观察健康状态,并在当前 Binance MVP 范围内执行第一版下单/撤单命令,而不需要自己维护本地缓存、ready barrier 或 websocket 生命周期。
4
4
 
5
5
  ## 安装
6
6
 
@@ -262,7 +262,7 @@ await client.market.unsubscribeL1Book({
262
262
 
263
263
  ### 5. Account(账户余额和仓位)
264
264
 
265
- > 当前 account 是占位实现,contract 已稳定但不是完整真实私有流。
265
+ > 当前 account 已接通 Binance PAPI UM 私有链路,可读取余额、仓位、风险和账户状态。
266
266
 
267
267
  ```ts
268
268
  // ① 注册账户(start 之前或之后均可)
@@ -270,8 +270,8 @@ await client.registerAccount({
270
270
  accountId: "main-binance",
271
271
  exchange: "binance",
272
272
  credentials: {
273
- apiKey: process.env.BINANCE_API_KEY,
274
- secret: process.env.BINANCE_API_SECRET,
273
+ apiKey: process.env.BINANCE_PAPI_API_KEY,
274
+ secret: process.env.BINANCE_PAPI_SECRET,
275
275
  },
276
276
  });
277
277
 
@@ -333,7 +333,7 @@ await client.removeAccount("main-binance");
333
333
 
334
334
  ### 6. Order(订单)
335
335
 
336
- > 当前 order 是占位实现,contract 已稳定但不是完整真实私有流。
336
+ > 当前 order 已接通 Binance PAPI UM 订单私有链路,并支持第一版交易命令:`createOrder()`、`cancelOrder()`、`cancelAllOrders()`。
337
337
 
338
338
  ```ts
339
339
  // 订阅订单流(需要先 registerAccount)
@@ -354,6 +354,40 @@ const order = client.order.getOrder({
354
354
  // → OrderSnapshot | undefined
355
355
  // { symbol, side, type, status, price, amount, filled, remaining, ... }
356
356
 
357
+ // 下单:第一版只支持 limit / market
358
+ const created = await client.order.createOrder({
359
+ accountId: "main-binance",
360
+ symbol: "BTC/USDT:USDT",
361
+ side: "buy",
362
+ type: "limit",
363
+ price: "71830.6",
364
+ amount: "0.001",
365
+ });
366
+
367
+ // 如果账户是双向持仓模式(hedge mode),必须显式传 positionSide
368
+ const hedgeCreated = await client.order.createOrder({
369
+ accountId: "main-binance",
370
+ symbol: "BTC/USDT:USDT",
371
+ side: "buy",
372
+ type: "limit",
373
+ price: "71900.9",
374
+ amount: "0.001",
375
+ positionSide: "long",
376
+ });
377
+
378
+ // 撤单:需要 accountId + symbol,并提供 orderId / clientOrderId 其一
379
+ const canceled = await client.order.cancelOrder({
380
+ accountId: "main-binance",
381
+ symbol: "BTC/USDT:USDT",
382
+ orderId: created.orderId,
383
+ });
384
+
385
+ // 某个 symbol 下全撤
386
+ const canceledAll = await client.order.cancelAllOrders({
387
+ accountId: "main-binance",
388
+ symbol: "BTC/USDT:USDT",
389
+ });
390
+
357
391
  // 消费订单事件
358
392
  for await (const event of client.order.events.updates({
359
393
  accountId: "main-binance",
@@ -378,6 +412,8 @@ for await (const event of client.order.events.updates({
378
412
  await client.order.unsubscribeOrders({ accountId: "main-binance" });
379
413
  ```
380
414
 
415
+ `createOrder()` / `cancelOrder()` resolve 的是 REST 成功后标准化的 `OrderSnapshot`;`events.updates()` 是后续生命周期变化流,不是唯一 ack 来源。
416
+
381
417
  ### 7. 健康监控
382
418
 
383
419
  #### 全局健康快照
@@ -581,9 +617,13 @@ client.stop()
581
617
  ## 当前限制
582
618
 
583
619
  - 运行时真正支持的市场数据交易所只有 **Binance**(`okx`、`bybit`、`gate` 仅类型定义)
584
- - 真实落地的数据链路只有 Binance **L1 Book**
620
+ - 真实落地的 market 数据链路当前是 Binance **L1 Book**
621
+ - 私有账户与订单链路当前只支持 **Binance PAPI UM**
585
622
  - `fundingRate` 接口已暴露,但当前是占位快照
586
- - `account` / `order` 当前是占位实现,不是完整真实私有流
623
+ - 第一版交易命令只支持 `createOrder()` / `cancelOrder()` / `cancelAllOrders()`
624
+ - `createOrder()` 当前只支持 `limit` / `market`
625
+ - 双向持仓模式账户下单时必须显式传 `positionSide`
626
+ - 条件单、改单、账户级全撤当前还不支持
587
627
  - `CreateClientOptions` 中 `sandbox`、`logger`、`logLevel` 仍是预留位
588
628
 
589
629
  ## 仓库内开发
@@ -595,4 +635,46 @@ bun run type-check
595
635
  bun test
596
636
  ```
597
637
 
638
+ ### 发布流程
639
+
640
+ 当前仓库使用 **Changesets + GitHub Actions + npm Trusted Publishing**:
641
+
642
+ 1. 开发 PR 时,如果改动会影响用户,执行 `bun run changeset`
643
+ 2. 按提示选择 `patch` / `minor` / `major`,并写一段对外 release note
644
+ 3. PR merge 到 `main` 后,[release.yml](/projects/acex-feat-order_account/.github/workflows/release.yml) 会自动:
645
+ - 安装依赖
646
+ - 执行 `bun run lint`
647
+ - 执行 `bun run type-check`
648
+ - 执行 `bun run test`
649
+ - 若存在未消费的 changeset,则创建或更新 release PR
650
+ 4. merge release PR 后,同一条 workflow 会自动发布到 npm
651
+
652
+ 当前仓库处于 Changesets 的 `beta` prerelease 模式,自动发布默认走 npm `beta` dist-tag。
653
+
654
+ npm 侧配置 Trusted Publisher 时,需要确保:
655
+
656
+ - workflow 文件名是 `release.yml`
657
+ - `package.json.repository.url` 必须直接写仓库地址,例如 `https://github.com/imbingox/acex`
658
+ - npm 包 settings 里绑定的是 GitHub Actions trusted publisher,而不是长期 `NPM_TOKEN`
659
+
660
+ 真实 Binance 公网 smoke test 单独执行,不放进默认 `bun test`:
661
+
662
+ ```bash
663
+ bun run test:live:market:smoke
664
+ bun run test:live:market:soak
665
+ bun run test:live:account:smoke
666
+ bun run test:live:account:soak
667
+ bun run test:live:order:smoke
668
+ bun run test:live:order:soak
669
+ ```
670
+
671
+ 这些脚本会验证:
672
+ - `market`:`loadMarkets()`、`subscribeL1Book()`、`getL1Book()` / `events.l1BookUpdates()`,以及可选的主动断线后自动重连
673
+ - `account`:Binance PAPI UM 账户 bootstrap、余额/仓位/风险投影、private stream 更新和可选重连
674
+ - `order`:open orders bootstrap、`subscribeOrders()`、订单事件投影和可选重连
675
+
676
+ 约定:
677
+ - `smoke` 是快速连通性检查,默认跑 10 秒,不主动断线
678
+ - `soak` 是短时稳定性检查,默认跑 60 秒,并做一次主动断线重连验证
679
+
598
680
  更完整的公开接口设计说明见 [docs/sdk-public-api.md](./docs/sdk-public-api.md)。
package/package.json CHANGED
@@ -1,24 +1,44 @@
1
1
  {
2
2
  "name": "@imbingox/acex",
3
- "version": "0.1.0-beta.2",
3
+ "version": "0.1.0-beta.3",
4
4
  "description": "Multi-exchange trading SDK for market data, account, and order management",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/imbingox/acex"
8
+ },
5
9
  "module": "index.ts",
6
10
  "type": "module",
7
11
  "exports": {
8
12
  ".": "./index.ts"
9
13
  },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
10
17
  "files": [
11
18
  "index.ts",
12
19
  "src/"
13
20
  ],
14
21
  "scripts": {
22
+ "changeset": "changeset",
15
23
  "lint": "biome check .",
16
24
  "lint:fix": "biome check --write .",
25
+ "release": "changeset publish",
17
26
  "type-check": "tsc --noEmit",
18
- "test": "bun test"
27
+ "test": "bun test --max-concurrency=1",
28
+ "test:live:account": "bun run scripts/live-account-smoke.ts",
29
+ "test:live:account:smoke": "bun run scripts/live-account-smoke.ts --duration 10",
30
+ "test:live:account:soak": "bun run scripts/live-account-smoke.ts --duration 60 --disconnect-after 5",
31
+ "test:live:market": "bun run scripts/live-market-smoke.ts",
32
+ "test:live:market:smoke": "bun run scripts/live-market-smoke.ts --duration 10",
33
+ "test:live:market:soak": "bun run scripts/live-market-smoke.ts --duration 60 --disconnect-after 5 --disconnect-target perp",
34
+ "test:live:order": "bun run scripts/live-order-smoke.ts",
35
+ "test:live:order:smoke": "bun run scripts/live-order-smoke.ts --duration 10",
36
+ "test:live:order:soak": "bun run scripts/live-order-smoke.ts --duration 60 --disconnect-after 5",
37
+ "version-packages": "changeset version"
19
38
  },
20
39
  "devDependencies": {
21
40
  "@biomejs/biome": "^2.4.10",
41
+ "@changesets/cli": "^2.31.0",
22
42
  "@types/bun": "latest",
23
43
  "typescript": "^6.0.2"
24
44
  },