Sorted historical candles sort by a couple and a period
When downloading historical candlestick data for several cripturcreren couples during different periods from Binance API, data sorting is very important to facilitate the analysis of trends and models. In this article, we will show you how to sort data by pair and time.
Conditions required
- Make sure you have a basic understanding of JSON and API interaction.
- You have access to the Binance API and you are familiar with it to download historical data.
Step 1: Set the Data Structure
Before you start sorting, make sure -your data structure is solved correctly. Assuming you work with the following object:
`Javascript
CONC DAT = [
{
Time tag: ‘2022-01-01T00: 00: 00’,
Pair: “BTC/USDT”,
Open: 1000,
Tall: 1500,
Low: 800,
Close: 1200,
Tom: 100000
},
{
Time tag: ‘2022-01-02T00: 00: 00’,
Pair: “Et/BTC”,
Open: 500,
Tall: 700,
Low: 400,
Close: 550,
Tom: 80000
}
]
`
Step 2: Sort by a couple and a period
You can sort your data using the following syntax:
Javascript
Date.Sort ((a, b) => {
IF (A.Pair == ‘BTC/USDT’ && B.Pair! == ‘BTC/USDT’) return -1;
IF (B.Pair == ‘BTC/USDT’ && A.Pair! == ‘BTC/USDT’) return 1;
Const Timeframea = moment (a.timestamp);
Const Timeframeb = moment (b.timastamp);
IF (Timeframea
Otherwise if (Timeframea> Timeframeb) returns 1;
return 0;
});
`
This will arrange the data according to the pair and then time. If the couple has changed, it will be transferred to the appropriate time.
Step 3: Filter results
After sorting, you may want to filter your results to cover only the most relevant data. For example:
Javascript
Data = date.Filter ((element) => item.pair! == ‘btc/USDT’);
`
This will eliminate all the elements in the pairs that do not match the desired couple.
Step 4: Show results
Finally, you can display your sorted and filtered data to better understand the trends and patterns on your cryptocurrency markets.
Here is an example of how you can display sorted data using console.log () feature:
Javascript
Data.Freach ((item) => {
console.log ($ {Item.pair}: $ {moment (itemstamp).
});
Example of case use
Let's say you have a large set of data with multiple pairs and periods and you want to analyze the performance of each pair in different periods. By taking these steps, you can easily sort your data by a couple during the period, then filter the results to include only the most important information.
Javascript
CONC DAT = [
{
Time tag: ‘2022-01-01T00: 00: 00’,
Pair: “BTC/USDT”,
Open: 1000,
Tall: 1500,
Low: 800,
Close: 1200,
Tom: 100000
},
{
Time tag: ‘2022-01-02T00: 00: 00’,
Pair: “Et/BTC”,
Open: 500,
Tall: 700,
Low: 400,
Close: 550,
Tom: 80000
},
{
Time tag: ‘2022-01-03T00: 00: 00’,
Pair: “BTC/USDT”,
Open: 1200,
Height: 1800,
Low: 1000,
Close: 1300,
Tom: 150000
}
]
Date.Sort ((a, b) => {
IF (A.Pair == ‘BTC/USDT’ && B.Pair! == ‘BTC/USDT’) return -1;
IF (B.Pair == ‘BTC/USDT’ && A.Pair! == ‘BTC/USDT’) return 1;
Const Timeframea = moment (a.timestamp);
Const Timeframeb = moment (b.timastamp);
IF (Timeframea
Otherwise if (Timeframea> Timeframeb) returns 1;
return 0;
});
Data.Freach ((item) => {
console.log ($ {Item.pair}: $ {moment (itemstamp).
});
`
This will sort the data according to the pair, then, over time, and show the performance of each pair over several periods.
دیدگاهها