newbie here! I'm trying to make a basic ping to the Binance crypto exchange using its exposed REST API and node.js. Instead of coding everything from 0, I'm planning to use a wrapper package in https://github.com/binance-exchange/binance-api-node that facilities interaction. I've downloaded the binance-api-node code from github into my node.js project.
After installing the package, when trying to run the included basic getting-started code to get the time from the server:
import Binance from 'binance-api-node';
const client = Binance();
client.time().then(time => console.log(time));
I’m getting this error:
Uncaught TypeError: Binance is not a function
I also tried:
const client = new Binance();
but I get another error saying Binance is not a constructor.
This is the function declaration in the index.d.ts of binance-api-node
declare module 'binance-api-node' {
export default function(options?: {
apiKey?: string
apiSecret?: string
getTime?: () => number | Promise<number>
httpBase?: string
httpFutures?: string
wsBase?: string
wsFutures?: string
proxy?: string
}): Binance
...
Any help will be appreciated.
Thanks!
CodePudding user response:
As stated in documentation:
If you do not have an appropriate babel config, you will need to use the basic commonjs requires:
const Binance = require('binance-api-node').default
const client = Binance();
Or like this, it worked for me:
import Binance from 'binance-api-node';
const client = Binance.default();