From Trades to Agg Trades

Hi, I am recently doing research on the trades data, and I am confused about the aggTrades data. Could you plz explain how it works? I know Aggregate trade combines trades with the same price together in a period of time, but sometimes it doesn’t seems like that.

e.g. in Trades
|45|2665741|0.0591|1.006|0.059455|1655856991617|False|
|46|2665742|0.0591|3.599|0.212701|1655856991617|False|
|47|2665743|0.0591|1.006|0.059455|1655856991617|False|
and in aggTrades
|25|2333259|0.0591|1.006|2665741|2665741|1655856991617|False|
|26|2333260|0.0591|4.605|2665742|2665743|1655856991617|False|
here, you can see tradeid 2665741 and 2665742&2665743 don’t aggregate together.

And another example
|133|2665829|0.0596|0.223|0.013291|1655858015410|True|
|134|2665830|0.0596|1.359|0.080996|1655858015410|True|
|135|2665831|0.0596|0.313|0.018655|1655858015410|True|
|136|2665832|0.0596|1.269|0.075632|1655858015410|True|
|137|2665833|0.0596|1.582|0.094287|1655858015410|True|
here, tradeid 2665829 to 2665833 were separate into three records in aggTrades.
|81|2333315|0.0596|1.582|2665829|2665830|1655858015410|True|
|82|2333316|0.0596|1.582|2665831|2665832|1655858015410|True|
|83|2333317|0.0596|1.582|2665833|2665833|1655858015410|True|

So, how the agg actually works? Thank you.

Which symbol is this?

The data is AAVEETH-aggTrades-2022-06-22.csv and AAVEETH-trades-2022-06-22.csv.

And for trades, the columns are:
index id price qty quote_qty time IsBuyerMaker

for AggTrades, the columns are:
index agg_id price qty first_id last_id time IsBuyerMaker

If you go to the official documentation here: binance-spot-api-docs/rest-api.md at master · binance/binance-spot-api-docs · GitHub

You can see following:

Get compressed, aggregate trades. Trades that fill at the time, from the same taker order, with the same price will have the quantity aggregated.

The “same take order” is the clue here.
There may be many orders sitting at the same price level, a single incoming taker order may match with one or more at the same price level but it may not exhaust all of them.
If it doesn’t exhaust all of them and the price on the book won’t change before next order you would see this scenario.