Finatic 服务器 SDK (节点)
嵌入 Finatic 的节点.js SDK 您的后端在服务器上保留公司的API密钥. 薄荷 90秒 一次性代币 @finatic/client,或启动会话并重定向到连接.
安装
npm install @finatic/server-node
快开始
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 });
服务器 v1 数据方法返回 { traceId, data, warnings, errors }检查 errors 在使用前 data。 。 。 .
处理错误
每个归正的v1出错都暴露出两个识别符:
category是稳定的通用类别之一,例如:CONFLICT, (中文(简体) ),VALIDATION,或RATE_LIMITED这一领域的部门负责广泛的处理和重新研究政策.code保存特定的 API 提供的字符串,例如IDEMPOTENCY_KEY_REUSED代码为 开放式,这样SDK的消费者可以处理当前和未来API出错而不会失去身份.
当API 响应无法使用时 code,SDK 回归到衍生 category现有
FinaticV1ErrorCode 导入作为打开字符串代码的公用类型仍然有效,而
FinaticV1ErrorCategory 代表封闭的通用分类.
fntc_sandbox_ 键使用 Finatic 合成数据。 中间商票据/债券账户暂存 live。 。 。 .
FinaticServer.init(apiKey, userId?) 是一个可调用的快捷键 startSession组合键 getToken() 您只需向浏览器递交一个符号.
精确的仪器描述符
顺序腿,填充,事件和位置默认使用生成的描述符类型. 准确的未来 仍然有别于仅以产品为主的特性,SDK并不推断缺少合同, 过期,地点,出处,或身份质量的字段.
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
},
},
});
嵌入连接
v1.getToken()将信使传递给FinaticConnect.init(token)在浏览器中(token TTL为90秒).- 或者说
v1.startSession()接下来v1.getPortalUrl(...)- 调整方向。 将完整 URL 视为秘密 .
等待网钩 account.grant.created 在将准入视为持久之前.
startSession().success 表示请求已完成. 检查 authenticated 账户前或
交易电话; status, (中文(简体) ), user_id, (中文(简体) ), provided_user_id_rejected,以及
portal_connection_management_pending 解释非活性会话状态.
常见命令
| 任务 | 命令 |
|---|---|
| 构建 | npm run build |
| 测试 | npm test |
| 林特 | npm run lint |
| 类型检查 | npm run type:check |
文档
这个README是节点SDK合同. 在写完整集成之前获取其余部分 :
- 快速开始 : https://finatic.dev/docs/快克-起步/快克-起步
- 客户端 SDK 阅读器 : https://github.com/FinaticORG/FinaticClientSDK/blob/develop/README.md 互联网档案馆的存檔,存档日期2013-12-20
- Python SDK 读取: https://github.com/FinaticORG/FinaticServerSDK-Python/blob/develop/README.md 互联网档案馆的存檔,存档日期2013-12-21
- 嵌入连接 : https://github.com/FinaticORG/FinaticConnect/blob/develop/docs/embedding.md. 互联网档案馆的存檔,存档日期2013-12-22
- 演示应用 : https://github.com/FinaticORG/FinaticDemoApps/blob/develop/README.md 互联网档案馆的存檔,存档日期2014-12-21
- API 参考 : https://finatic.dev/docs/api-参考资料
- 打开API : https://finatic.dev/openapi.json 页面存档备份,存于互联网档案馆
- 代理索引 : https://finatic.dev/llms.txt
- 代理笔记 : https://finatic.dev/AGENTS.md (英语)