Getting Data

Learn how to retrieve accounts, orders, positions, and other data from connected brokerages.

Once the session is initialized and the user has approved read permission on a broker connection, you can retrieve account data. Here are the most common methods:

Get Accounts

Retrieve all accounts from connected brokerages:

1const result = await finatic.getAccounts(); 2 3if (result.success) { 4 const accounts = result.success.data; // PaginatedData - use directly as array 5 console.log(`Found ${accounts.length} account(s)`); 6} else { 7 console.error('Failed to get accounts:', result.error); 8}

Get Orders

Retrieve orders from connected brokerages:

1const result = await finatic.getOrders(); 2 3if (result.success) { 4 const orders = result.success.data; // PaginatedData - use directly as array 5 console.log(`Found ${orders.length} order(s)`); 6} else { 7 console.error('Failed to get orders:', result.error); 8}

Get Positions

Retrieve positions from connected brokerages:

1const result = await finatic.getPositions(); 2 3if (result.success) { 4 const positions = result.success.data; // PaginatedData - use directly as array 5 console.log(`Found ${positions.length} position(s)`); 6} else { 7 console.error('Failed to get positions:', result.error); 8}

Pagination

The regular methods (getAccounts(), getOrders(), getPositions()) support pagination. The response data is a PaginatedData object that behaves like an array and includes navigation methods:

  • result.success.data: The paginated data (use directly as an array - result.success.data[0], result.success.data.length, etc.)
  • result.success.data.hasMore: Boolean indicating if there are more pages available
  • result.success.data.nextPage(): Fetches and returns the next page (e.g., if currently on page 1 with 50 results, this fetches results 51-100)
  • result.success.data.prevPage(): Fetches and returns the previous page (e.g., if currently on page 2, this fetches the previous 50 results)
  • result.success.data.firstPage(): Fetches and returns the first page of results
  • result.success.data.lastPage(): Fetches and returns the last page of results

You can also use limit and offset parameters to control pagination manually.

Example with pagination navigation methods:

1// Get first page (results 1-50) 2const result = await finatic.getOrders({ limit: 50 }); 3 4if (result.success) { 5 const firstPage = result.success.data; // PaginatedData - use as array 6 console.log(`First page: ${firstPage.length} orders`); 7 8 // Check if there are more pages 9 if (firstPage.hasMore) { 10 // Get next page (results 51-100) 11 const secondPage = await firstPage.nextPage(); 12 console.log(`Next page: ${secondPage.length} orders`); // Go back to previous page (results 1-50) const prevPage = await secondPage.prevPage(); console.log(`Previous page: ${prevPage.length} orders`); // Jump to last page const lastPage = await firstPage.lastPage(); console.log(`Last page: ${lastPage.length} orders`); // Jump back to first page const firstPageAgain = await lastPage.firstPage(); console.log(`First page: ${firstPageAgain.length} orders`); } } 13 const secondPage = nextResult.success.data; 14 console.log(`Next page: ${secondPage.length} orders`); 15 16 // Go back to previous page (results 1-50) 17 const prevResult = await nextResult.prevPage(); 18 if (prevResult.success) { 19 console.log(`Previous page: ${prevResult.success.data.length} orders`); 20 } 21 22 // Jump to last page 23 const lastResult = await nextResult.lastPage(); 24 if (lastResult.success) { 25 console.log(`Last page: ${lastResult.success.data.length} orders`); 26 } 27 28 // Jump back to first page 29 const firstResult = await lastResult.firstPage(); 30 if (firstResult.success) { 31 console.log(`First page: ${firstResult.success.data.length}orders`); 32 } 33 } 34 } 35}

Example with manual pagination:

1// Get first page (50 results) 2const page1 = await finatic.getOrders({ limit: 50, offset: 0 }); 3 4// Get second page (next 50 results) 5const page2 = await finatic.getOrders({ limit: 50, offset: 50 });

Note: Each method also has a "get all" version (getAllAccounts(), getAllOrders(), getAllPositions()) that automatically handles pagination for you by fetching all pages and returning a single array with all results. Use these methods when you need all data without managing pagination manually.


Response Format

All methods in this guide return a standard response format. Always check for result.success or result.error before accessing data:

1const result = await finatic.getAccounts(); 2 3if (result.success) { 4 const accounts = result.success.data; 5 // Process accounts 6} else if (result.error) { 7 console.error('Error:', result.error.message); 8 // Handle error 9} 10

For detailed information on response structure and error handling, see:


Next Steps

Now that you've retrieved your data:

  1. Standard Response Object - Understand the response format used by all methods
  2. Connecting Brokers - Learn how to connect brokerages to access real data
  3. Error Handling - Review error handling patterns for robust applications
  4. Explore the API Reference - See all available methods in the API Reference
  5. Try the Interactive Playground - Test the SDK in your browser with our Interactive Playground