Acquire Binance account balances through NextJS, ccxt library, and TypeScript integration

Currently, I am attempting to retrieve balances from Binance within my NextJS 13 application, utilizing the /src/app directory along with TypeScript.

async function fetchData() {   
  const exchange = new ccxt.binance ({
    "apiKey": "mykey",
    "secret": "mysecret",
  })
  return exchange.fetchTotalBalance()
}
 
export default async function Page() {
  const info = await getData()
  return <main>{info. Total}</main>
}

Unfortunately, an error keeps appearing:

Error [ERR_MODULE_NOT_FOUND]: Cannot locate module 'D:\myapp\.next\server\static_dependencies\node-fetch\index.js' that is being imported from D:\myapp\.next\server\app\page.js

I have tried installing and importing the node-fetch package but it did not resolve the issue. Information on using ccxt with React/NextJS is limited, so any assistance would be greatly appreciated.

Answer №1

NextJS GitHub was where I turned to for help with my question, and @bludnic provided a solution that worked like a charm:

The issue was resolved by swapping out the fetch implementation of CCXT with NextJS's fetch.

import ccxt from 'ccxt'

const fetcher = (...args: Parameters<typeof fetch>) => fetch(...args);

export default async function Page() {
  const exchange = new ccxt.binance()
  exchange.fetchImplementation = fetcher // <-

  const price = await exchange.fetchTicker('BTC/USDT')

  return <div>{JSON.stringify(price)}</div>
}

You can find the full discussion here: https://github.com/vercel/next.js/discussions/53200

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

An easy way to create an input field after clicking a button

When I try to add a field on Button Click, the default field is not showing and does not get added upon button click I have put in my best effort but I cannot figure out what the problem is. I have added functions and used Math to generate a unique id. Th ...

Limit the elements in an array within a specified range of dates

Currently, I am working on implementing a filter functionality for a data array used in a LineChart within my Angular application using TypeScript. The structure of the data array is as follows: var multi = [ { "name": "test1", "series": [ ...

Selecting a filter for an array of objects

I'm struggling to implement a search feature in my mat-select DropDown. The existing options I've found online aren't quite working for me due to the object array I am passing to the Dropdown. Any assistance or guidance on this matter would ...

Avoiding repetitive logic in both parent and child components in Angular 8

In my parent controller, I have common requests and I also read router params for those requests. However, for the child components, I have different requests but still need to extract the same parameters from the router - resulting in duplicate code. For ...

What causes the return value type in a functional interface to be loosely implemented in Typescript?

In an attempt to explain a specific partial type of return value for a functional interface, I have encountered an issue. Within my IStore interface, there is only one property called test. When assigning this interface to the function foo, which returns ...

When inner pages in Next.js reload, they display the same content as the home page upon page refresh

During the development of our website using Next Js, we encountered an issue where the home page and inner pages load correctly locally and in the deployed build on AWS S3. However, when refreshing an inner page or opening it in a new tab, the content of ...

I am looking to conceal the y-axis labels and tooltip within the react chart

I am currently working with react-chart-2. I have a line graph that displays a tooltip when hovered over, but I would like to hide this tooltip feature. Additionally, I want to remove the numbers 0, 0.1, 0.2 up to 1 on the left side (y-axis) of the gra ...

When utilizing Typescript to develop a form, it is essential to ensure that the operand of a 'delete' operator is optional, as indicated by error code ts(279

Can someone help me understand why I am encountering this error? I am currently working on a form for users to submit their email address. export const register = createAsyncThunk< User, RegisterProps, { rejectValue: ValidationErrors; } > ...

Enhance the express request to include the user parameter for the passport

I am currently utilizing Passport for authentication in an Express application. This authenticates the user and sets it on the Express response. As I am using TypeScript, trying to set the request type to Request in the route definitions results in an erro ...

In development, Next.js dynamic routes function correctly, but in production they are displaying a 404 error page

I am currently working on implementing dynamic routes in my Next.js project to render pages based on user input. I have set up a route that should display the page content along with the id extracted from the URL using the useRouter() hook. Everything is f ...

Is there a method to establish a connection between my NextJS app on my phone through the local network during development similar to the way Create React App does

When using Create-React-App, I am able to access a URL through my local area network (LAN) like this: Is it possible to make the NextJS URL accessible over the LAN network as well? ...

Creating Dynamic Navigation with Framer Motion

I'm struggling with the animation of my navigation bar in React and Framer Motion. The result is almost perfect, but I need some tweaking to make it pixel-perfect. The issue lies with the animation of the links; they should be fixed on the left, but c ...

The recent update from Angular version 5.2 to 7 has caused issues with Post methods

An issue has occurred with the type mismatch in the error handling function. It seems that the argument provided is not compatible with the expected parameter type within the Observable structure. GetFullAddress(addressModel: FullAddr ...

Using NextJS to navigate user journey by mapping an array of values from Formik to

I really appreciate all the help I've received so far, but I'm facing an issue trying to map an object with an array within it to the router. Here is my current code: const initialValues = { region: query.region || 'all', campt ...

I am unable to access the properties of an undefined element, specifically the 'size' property in Next.js 13

I encountered a problem today while working with Next.js version 13.4 and backend integration. When using searchParams on the server side, I received an error message: "Cannot read properties of undefined (reading 'size')" while destructuring siz ...

Operator in RxJS that maps the elements within an array composed of multiple arrays

disclaimer: I have a creative solution and would like to share it here. While exploring the RxJS documentation for map methods that meet this specific requirement - let's call it mapArray - I haven't been able to find one. of([1, 2, 3]).pipe( ...

How does the Paginate Pipe effectively retrieve the array length in an Angular 2 application?

I find myself in an interesting situation where I have a piece of code that is functioning within my Angular 2 application - it's generating the correct value, but the method behind its success is unclear to me. Specifically, I am using ng2-paginatio ...

A step-by-step guide on executing a callback function once the animation has finished with frame-motion

I'm facing an issue with my component called AnimatedText. After the animation is complete, I want the words filled in the underlineLines prop to be underlined. How can I achieve this? I attempted using the onAnimationEnd function, but it didn't ...

Production environment is unable to display images - NextJS React application

After following a tutorial using NextJS to create a ReactJS project, I encountered an issue with the logo image not rendering properly in production when deploying to Netlify or Vercel. Despite researching and identifying that there is a problem related t ...

Guide to Injecting Services with Dependencies in Angular 2 (Using Ionic 2/Angular 2/Typescript)

As part of my project, I am developing a sample application that connects to a websocket server in Ionic 2 using Typescript. You can find the repository here. The main requirement is to establish the websocket connection when the application starts up. T ...