From 1802effbdce93ead6f5e64c6a0f2988e6d4c8445 Mon Sep 17 00:00:00 2001 From: JJ-Cro Date: Wed, 15 Jan 2025 10:37:30 +0100 Subject: [PATCH 1/2] feat(): added nextPageCursor example --- examples/rest-v5-next-cursor.ts | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 examples/rest-v5-next-cursor.ts diff --git a/examples/rest-v5-next-cursor.ts b/examples/rest-v5-next-cursor.ts new file mode 100644 index 00000000..c9ec22de --- /dev/null +++ b/examples/rest-v5-next-cursor.ts @@ -0,0 +1,39 @@ +import { RestClientV5, UniversalTransferRecordV5 } from '../src/index'; + +// or +// import { RestClientV5 } from 'bybit-api'; + +const client = new RestClientV5({ + testnet: false, + key: 'insert_api_key', + secret: 'insert_api_secret', +}); + +async function getAllUniversalTransfers() { + let allTransfers: UniversalTransferRecordV5[] = []; + let nextCursor = ''; + let pages = 0; + + do { + pages++; + console.log(`Fetching data from page ${pages}`); + const response = await client.getUniversalTransferRecords({ + limit: 50, // Maximum page size per request + cursor: nextCursor || undefined, // Only send cursor if we have one + }); + + if (response.result.list && response.result.list.length > 0) { + allTransfers = [...allTransfers, ...response.result.list]; + } + + nextCursor = response.result.nextPageCursor; + + // Optional: Add a small delay to avoid rate limits + await new Promise((resolve) => setTimeout(resolve, 100)); + } while (nextCursor); + + console.log('Total transfers fetched:', allTransfers.length); + console.log('All transfers:', allTransfers); +} + +getAllUniversalTransfers().catch(console.error); From a0048880a1148129d7509f539526c22df2f16a93 Mon Sep 17 00:00:00 2001 From: JJ-Cro Date: Wed, 15 Jan 2025 11:03:15 +0100 Subject: [PATCH 2/2] chore(): updated let to const --- examples/rest-v5-next-cursor.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/rest-v5-next-cursor.ts b/examples/rest-v5-next-cursor.ts index c9ec22de..483394c0 100644 --- a/examples/rest-v5-next-cursor.ts +++ b/examples/rest-v5-next-cursor.ts @@ -10,7 +10,7 @@ const client = new RestClientV5({ }); async function getAllUniversalTransfers() { - let allTransfers: UniversalTransferRecordV5[] = []; + const allTransfers: UniversalTransferRecordV5[] = []; let nextCursor = ''; let pages = 0; @@ -23,7 +23,7 @@ async function getAllUniversalTransfers() { }); if (response.result.list && response.result.list.length > 0) { - allTransfers = [...allTransfers, ...response.result.list]; + allTransfers.push(...response.result.list); } nextCursor = response.result.nextPageCursor;