API BINANCE FUTURES: Avoiding overloaded data
As a developer who works with the Binance Futures API, you may have encountered a problem in which the candlestick data is printed as a list instead of being displayed in a formatted graph. This can be frustrating and can remove your general experience.
The problem lies in the way in which the Binance Futures API manages the data taking. When making a request to take the candlestick data using get/candles/{symbol}/{interval}/{Start time}/{end time} endpoint, the answer is a number of objects containing all the available data points. However, this painting is printed as a list instead of being displayed in a graph.
This problem can be avoided by customizing how you recover and display the candlestick data using the Binance Futures API.
problem:

When get/candles/{symbol}/{interval}/{Start time}/{end time} endpoint returns a number of objects, it is simply returned as it is. This means that if you try to display this data in a graph, all individual points will be displayed on top of each other.
Solution:
One way to avoid printing the candlesticks as a list when using the Binance Futures API is to use the JSON () `Method. You can specify that you want the answer to be analyzed as JSON instead of a painting.
To achieve this, you must make two separate requests:
- One for taking over the entire set of data and displaying it in a graph (for example,get/candles/{symbol}/{interval}/{Start time}/{End Time}/All
).
- Another. Another for taking over the individual data points (for example,get/candles/{symbol}/{interval}/{Start time}/{end time}/{date} .json
).
Here is an example of how you can change your code to use theJSONJSON () Fetchmethod:
Javascript
// Recover all of the Says Simultaneously
fetch (‘ {symbol}/{interval}/{Start time}/{end time}/all’)
.Then ((answer) => reply.json ())
.Then ((data) => {
// Display data in a graph using chart.js or other library
CONT CTX = Document.Getementbyid (‘Sandlestick-Chart’). Getcontext (‘2D’);
Chart.ctx.canvas = ctx;
New graphic (CTX, {
Type: ‘line’,
Data: {
Tags: date.map ((point) => point.date),
Data sets: [{
Label: « Sayable data »,
Data: Data.map ((point) => point.close),
Backgroundcolor: ‘RGBA (255, 99, 132, 0.2)’,
Bordecolor: ‘RGBA (255, 99, 132, 1)’,
Border width: 1,
}],
},
});
})
.catch ((error) => console.error (error));
`
Similarly, you can change your code to take over the individual sandlestick data points usingget/candles/{symbol}/{interval}/{Start time}/{end time}/{date} .json.
Javascript
// recover a data point of the individual candlestick at a specific date
fetch ({symbol}/$ {interval}/$ {Start time}/$ {End Time}/$ {Data} .Json)
.Then ((answer) => reply.json ())
.Then ((data) => {
// Display data in a graph using chart.js or other library
CONT CTX = Document.Getementbyid (‘Sandlestick-Chart’). Getcontext (‘2D’);
Chart.ctx.canvas = ctx;
New graphic (CTX, {
Type: ‘line’,
Data: {
Tags: date.map ((point) => point.date),
Data sets: [{
Label: « Sayable data »,
Data: Data.map ((point) => point.close),
Backgroundcolor: ‘RGBA (255, 99, 132, 0.2)’,
Bordecolor: ‘RGBA (255, 99, 132, 1)’,
Border width: 1,
}],
},
});
})
.catch ((error) => console.error (error));
`
Using theJSON ()` Fetch ‘option and taking data in a single call, you can avoid printing data as a list when using the Binance Futures API. Instead, you will be able to display it in a graph with more control over the look.