'Invalid symbol error with binance api request
I'm currently working on react app which compare crypto buy price from wallet and actual price and return profit/loss. I created a backend server to call the binance endpoint and here is the code:
import fetch from 'node-fetch';
import crypto from 'crypto';
import { HttpError } from 'http-errors';
import express from 'express';
const app = express();
const port = 9000;
app.use(express.json());
const process_env_API_URL = 'https://api.binance.com';
const process_env_API_SKEY =
'';
const process_env_API_PKEY =
'';
app.get('/', async (req, res) => {
const endPoint2 = '/api/v3/allOrders';
const dataQueryString = 'timestamp=' + Date.now();
const signature = crypto
.createHmac('sha256', process_env_API_SKEY)
.update(dataQueryString)
.digest('hex');
const symbol = 'BTCUSDT';
const url = process_env_API_URL + endPoint2 + '?' + 'symbol='+ 'symbol' + '&';
dataQueryString + '&signature=' + signature;
console.log(url);
let currentBalances;
try {
currentBalances = await fetch(url, {
headers: { 'X-MBX-APIKEY': process_env_API_PKEY },
})
.then((res) => res.json())
.then((data) => console.log(data));
} catch (err) {
return next(new HttpError('API Error...', 500));
}
app.listen(port, () => {
console.log(`app listening on port ${port}`);
});
The problem is with symbol param. I don't know where put it (in header or where in query).I always get error about invalid symbol, or not allowed characters when I use '=' in query. I tried all options and I don't know how to fix it. On this website when I put params I get correct response : https://syncwith.com/api/binance/get/api-v3-myTrades. Thank you for all help!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
