T-Invest Node SDK Node.js

分页读取操作记录

getOperationsByCursor 分页返回账户历史。从空游标开始,当 hasNext 为 true 时,将 nextCursor 传给下一次请求。请填写令牌、账户 ID 和时间范围。

operations-pagination.ts
import { TInvestNodeSDK } from '@woodger/t-invest-node-sdk';

const sdk = new TInvestNodeSDK({
  token: 'YOUR_TOKEN',
  endpoint: 'invest-public-api.tbank.ru:443'
});
const request = {
  accountId: 'YOUR_ACCOUNT_ID',
  from: new Date('2026-01-01T00:00:00Z'),
  to: new Date('2026-02-01T00:00:00Z'),
  limit: 100
};
let cursor = '';

try {
  while (true) {
    const page = await sdk.operations.getOperationsByCursor({
      ...request,
      cursor
    });

    for (const operation of page.items) {
      console.log(operation);
    }

    if (!page.hasNext) {
      break;
    }

    cursor = page.nextCursor;
  }
}
finally {
  sdk.close();
}

翻页时只更新游标,账户、时间范围和筛选条件保持一致。以 hasNext 判断何时停止,包括 items 为空的情况。此处每页为 100 条。方法的行为见提供方文档,筛选条件见操作记录契约。在沙箱中使用 sdk.sandbox.getSandboxOperationsByCursor。

页数较多时,请使用请求限流器。如何设置时限或取消调用见一元请求指南。