When I do this It works
import React, { useState, useEffect } from 'react'
// Node Binance API
// https://github.com/binance-exchange/node-binance-api
const Binance = require('node-binance-api')
const binance = new Binance().options({
APIKEY: 'xxxxxxxxxx',
APISECRET: 'xxxxxxxxxx'
})
// BTCUSDT - price
const FuturesPrices = () => {
const [btcPrice, setBtcPrice] = useState([])
useEffect(() => {
async function fetchMyAPI() {
let response = await binance.futuresPrices()
response = response.BTCUSDT
setBtcPrice(response)
//console.log(response)
}
fetchMyAPI()
}, [btcPrice])
return <div>{btcPrice}</div>
}
export default FuturesPrices
But when I try example down below It doesn't work. Gives "error Unhandled Rejection (Error): ws does not work in the browser. Browser clients must use the native WebSocket object"
import React, { useState, useEffect } from 'react'
// Node Binance API
// https://github.com/binance-exchange/node-binance-api
const Binance = require('node-binance-api')
const binance = new Binance().options({
APIKEY: 'xxxxxxxxxx',
APISECRET: 'xxxxxxxxxx'
})
// BTCUSDT - price
const BtcPriceTicker = () => {
const [btcPriceTicker, setBtcPriceTicker] = useState([])
useEffect(() => {
async function fetchMyAPI() {
let response = await binance.futuresMiniTickerStream( 'BTCUSDT' )
response = response.close
setBtcPriceTicker(response)
//console.log(response)
}
fetchMyAPI()
}, [btcPriceTicker])
return <div>{btcPriceTicker}</div>
}
export default BtcPriceTicker;
My GitHub https://github.com/React-Binance/react-binance-api Contribute to React-Binance/functional components development