@finatic/server-node

中文文档
1.0.8发布于 2026/10/23PROPRIETARYTypeScriptESM + CJS构建来源已验证近 30 天下载 3596

Node.js SDK for Finatic Server API

原始使用文档
文档目录7 节
  1. Install
  2. Quick start
  3. Error handling
  4. Exact instrument descriptors
  5. Embed Connect
  6. Common commands
  7. Documentation

Finatic Server SDK (Node)

Node.js SDK for embedding Finatic in your backend. Keep the company API key on the server. Mint a 90-second one-time token for @finatic/client, or start a session and redirect to Connect.

Install

npm install @finatic/server-node

Quick start

import { FinaticServer } from '@finatic/server-node';

const finatic = new FinaticServer(process.env['FINATIC_API_KEY']!, {
  apiEnvironment: 'sandbox',
});

// Client iframe: 90-second token. Never send the API key to the browser.
const oneTimeToken = await finatic.v1.getToken();

// Redirect flow: start a session first (getPortalUrl requires it).
const redirectSession = await finatic.v1.startSession();
if (!redirectSession.session_id) {
  const message =
    'error' in redirectSession && redirectSession.error
      ? redirectSession.error
      : 'Session start failed';
  throw new Error(message);
}
const portalUrl = await finatic.v1.getPortalUrl({ mode: 'dark' });

// After account.grant.created, start a session for that portal user, then read.
const portalUserId = 'user-from-connect-onSuccess';
const authenticatedSession = await finatic.v1.startSession({ userId: portalUserId });
if (!authenticatedSession.authenticated) {
  const message = authenticatedSession.error
    ? authenticatedSession.error
    : `Session is ${authenticatedSession.status ?? 'not active'}`;
  throw new Error(message);
}

interface AccountSummary {
  accountId: string;
}

const accounts = await finatic.v1.listAccounts<AccountSummary[]>({
  includeSyncStatus: true,
});
const accountId = accounts.data?.[0]?.accountId;
if (!accountId) {
  throw new Error(accounts.errors[0]?.message ?? 'No granted accounts yet');
}
const orders = await finatic.v1.listOrders({ accountId });

Server v1 data methods return { traceId, data, warnings, errors }. Check errors before using data.

Error handling

Each normalized v1 error exposes two identifiers:

  • category is one of the stable generic categories, such as CONFLICT, VALIDATION, or RATE_LIMITED. Branch on this field for broad handling and retry policy.
  • code preserves the specific API-provided string, such as IDEMPOTENCY_KEY_REUSED. Codes are open-ended so SDK consumers can handle current and future API errors without losing identity.

When an API response has no usable code, the SDK falls back to the derived category. Existing FinaticV1ErrorCode imports remain valid as the public type for the open string code, while FinaticV1ErrorCategory represents the closed generic taxonomy.

fntc_sandbox_ keys use Finatic synthetic data. Broker paper/sim accounts stay live.

FinaticServer.init(apiKey, userId?) is a shortcut that calls startSession. Use the constructor + getToken() when you only need to hand a token to the browser.

Exact instrument descriptors

Order legs, fills, events, and positions use generated descriptor types by default. Exact futures remain distinct from product-root-only identities, and the SDK does not infer missing contract, expiry, venue, provenance, or identity-quality fields.

const orders = await finatic.v1.listOrders({ accountId: 'acct_123' });
const instrument = orders.data?.[0]?.legs?.[0]?.instrument;

if (instrument?.future?.identityQuality === 'EXACT') {
  console.log(instrument.future.contractCode); // e.g. MGCZ6
}

await finatic.v1.createAccountOrder({
  accountId: 'acct_123',
  idempotencyKey: crypto.randomUUID(),
  body: {
    order: {
      finaticInstrumentId: 'finatic:future:MGCZ6',
      instrumentId: 418, // provider-native identifiers remain additive
    },
  },
});

Embed Connect

  1. v1.getToken() → pass the token to FinaticConnect.init(token) in the browser (token TTL is 90 seconds).
  2. Or v1.startSession() then v1.getPortalUrl(...) → redirect. Treat the full URL as secret.

Wait for webhook account.grant.created before treating access as durable.

startSession().success means the request completed. Check authenticated before account or trading calls; status, user_id, provided_user_id_rejected, and portal_connection_management_pending explain non-active session states.

Common commands

TaskCommand
Buildnpm run build
Testnpm test
Lintnpm run lint
Type checknpm run type:check

Documentation

This README is the Node SDK contract. Fetch the rest before writing a full integration:

版本与发布记录

@finatic/server-node 共发布 35 个版本,首次发布于 2025/09/17;过去 12 个月发布了 22 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.0.8latest2026/10/2322 天前
1.0.72026/10/1630 天前
1.0.62026/10/1630 天前
1.0.52026/10/111 个月前
1.0.42026/09/191 个月前
1.0.32026/09/181 个月前

关于 @finatic/server-node 的常见问题

@finatic/server-node 是什么?

Node.js SDK for Finatic Server API

如何安装 @finatic/server-node?

在项目目录运行 npm install @finatic/server-node,或使用 pnpm add / yarn add / bun add。

@finatic/server-node 支持 TypeScript 吗?

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

@finatic/server-node 支持 ESM 还是 CommonJS?

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

@finatic/server-node 需要什么版本的 Node.js?

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

@finatic/server-node 可以商用吗?

@finatic/server-node 使用 PROPRIETARY 许可。声明的许可为 PROPRIETARY,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@finatic/server-node 的下载量有多少?

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

@finatic/server-node 还在维护吗?

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