I have been working on my order book code and I am struggling to figure out how to summarize objects. Below is the current code that I have:
const orderbook = [
{
"ClientID": "31135d2c-a5f0-11ed-b07a-10e7c6f7c62e",
"Side": "BID",
"Pair": "BTC/USDT",
"Quantity": "20",
"OriginalQuantity": "20",
"Price": "23700",
"Status": "pending",
"Updated": 0,
"time": 1677680878610,
"id": 1
},
{
"ClientID": "31135d2c-a5f0-11ed-b07a-10e7c6f7c62e",
"Side": "BID",
"Pair": "BTC/USDT",
"Quantity": "50",
"OriginalQuantity": "50",
"Price": "23674.52",
"Status": "pending",
"Updated": 0,
"time": 1677681421267,
"id": 2
},
{
"ClientID": "31135d2c-a5f0-11ed-b07a-10e7c6f7c62e",
"Side": "BID",
"Pair": "BTC/USDT",
"Quantity": "50",
"OriginalQuantity": "50",
"Price": "23714.99",
"Status": "pending",
"Updated": 0,
"time": 1677681888376,
"id": 3
},
{
"ClientID": "31135d2c-a5f0-11ed-b07a-10e7c6f7c62e",
"Side": "BID",
"Pair": "BTC/USDT",
"Quantity": "50",
"OriginalQuantity": "50",
"Price": "23674.52",
"Status": "pending",
"Updated": 0,
"time": 1677681421267,
"id": 2
}
];
I am trying to merge objects with the same price. I need to write a function that takes one argument (the array above) and runs the following code:
Expected results:
const bidsOrders =
[
{Price: "23714.99", "Quantity": "50", orders: 1},
{Price: "23700", "Quantity": "20", orders: 1},
{Price: "23674.52", "Quantity": "100", orders: 2}
];