@flexemarkets/fm-sdk

中文文档
0.22.0发布于 2026/11/15MITTypeScriptES Module构建来源已验证近 30 天下载 3131

Flexemarkets TypeScript SDK

原始使用文档
文档目录8 节
  1. ⚠️ Alpha software — the API is not stable
  2. Requirements
  3. Install
  4. Configuration
  5. Credential file
  6. Endpoint file
  7. SDK usage
  8. Example: ticker

fm-sdk-typescript

TypeScript / JavaScript SDK for the Flexemarkets API.

⚠️ Alpha software — the API is not stable

fm-sdk is pre-1.0 and under active development. Anything public may be added, renamed, or removed in any release, including in ways that break code that compiles and runs today, and without a deprecation period first. Under semantic versioning a 0.x release carries no compatibility promise, and that is how these versions are used: treat every 0.x bump as potentially breaking.

Pin an exact version rather than a range ("@flexemarkets/fm-sdk": "0.2.0", not ^0.2.0), read the upgrade notes for the release you are moving to, and expect to change code when you move.

Not recommended for production use.

Requirements

  • Node.js 22+ (ES modules)

Install

npm install @flexemarkets/fm-sdk

Configuration

The SDK loads credentials and endpoint from these sources (highest priority first):

  1. Arguments passed to Flexemarkets.connect()
  2. Files ~/.fm/credential and ~/.fm/endpoint (Java .properties format)
  3. Environment variable FM_API_URL (defaults to https://api.flexemarkets.com)

Credential file

Create ~/.fm/credential:

account=myaccount
[email protected]
password=secret

Or use a bearer token:

token=eyJhbGciOiJIUzI1NiJ9...

Endpoint file

Create ~/.fm/endpoint:

endpoint=https://api.flexemarkets.com/api/marketplaces/123

SDK usage

import { Flexemarkets } from "@flexemarkets/fm-sdk";

// connect(null, null, ...) falls back to ~/.fm/credential and ~/.fm/endpoint
const fm = await Flexemarkets.connect(null, null, "my-bot");

// REST API
const marketplaceId = fm.endpointMarketplaceId;
const markets = await fm.markets(marketplaceId);
const session = await fm.session(marketplaceId);
const holding = await fm.holding(marketplaceId);

// Submit orders
const order = await fm.submitLimit(marketplaceId, markets[0].id, "BUY", 1, 950);
await fm.submitCancel(marketplaceId, markets[0].id, order.id);

// Live market data. A desk keeps the books and tapes for you: it seeds them
// over REST, applies deltas, and re-seeds after a sequence gap.
const desk = await fm.desk(marketplaceId);
const marketId = markets[0].id;

desk.onBookChange(marketId, (book) => console.log(book.bestPrice("BUY")));
desk.onSessionChange((s) => console.log(s.state));
desk.onHoldingChange((h) => console.log(h.cash));

const one = desk.book(marketId);          // one market
for (const book of desk.books()) {        // every market in the marketplace
  console.log(book.symbol, book.bestPrice("BUY"));
}

desk.close();

Example: ticker

The SDK includes a ticker example — a live terminal display of order book best bid/ask, spread, and recent trade prices.

npx tsx src/ticker.ts -C ~/.fm/credential -E 123

Options:

FlagDescription
-C, --credentialCredential file path or bearer token
-E, --endpointMarketplace id, endpoint file path, or URL

Output:

fm-ticker                                              OPEN

  Symbol     Bid     Ask  Spread   Last trades
  ------  ------  ------  ------   -----------
    AAPL    9.50   10.50    1.00   9.50  10.00
     IBM    4.00    5.00    1.00   4.50

The display refreshes on each order book update. Press Ctrl-C to stop.

版本与发布记录

@flexemarkets/fm-sdk 共发布 42 个版本,首次发布于 2026/02/21;过去 12 个月发布了 42 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.22.0latest2026/11/15今天
0.21.02026/11/105 天前
0.20.02026/11/087 天前
0.19.02026/11/078 天前
0.18.02026/11/0510 天前
0.17.02026/10/3017 天前

关于 @flexemarkets/fm-sdk 的常见问题

@flexemarkets/fm-sdk 是什么?

Flexemarkets TypeScript SDK

如何安装 @flexemarkets/fm-sdk?

在项目目录运行 npm install @flexemarkets/fm-sdk,或使用 pnpm add / yarn add / bun add。

@flexemarkets/fm-sdk 支持 TypeScript 吗?

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

@flexemarkets/fm-sdk 支持 ESM 还是 CommonJS?

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

@flexemarkets/fm-sdk 需要什么版本的 Node.js?

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

@flexemarkets/fm-sdk 可以商用吗?

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

@flexemarkets/fm-sdk 的下载量有多少?

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

@flexemarkets/fm-sdk 还在维护吗?

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