Request to change API collection reponses

This is more of a feedback/improvement request. Not sure where else to submit this.

I’ve noticed that many of the collection (group) queries are formatted as nested objects instead of arrays. This is pretty uncommon in my experience and more difficult to work with. Is there any change of getting and implementation that uses arrays for collection responses?

Here’s the example request to demo the reponse:
https://data.alpaca.markets/v2/stocks/quotes/latest?symbols=AAPL,TSLA,VTI

response:

{
  "quotes": {
    "TSLA": {
      "t": "2022-08-04T17:42:24.920312936Z",
      "ax": "V",
      "ap": 940,
      "as": 1,
      "bx": "V",
      "bp": 924.4,
      "bs": 1,
      "c": [
        "R"
      ],
      "z": "C"
    },
    "AAPL": {
      "t": "2022-08-04T17:42:26.629657067Z",
      "ax": "V",
      "ap": 165.45,
      "as": 1,
      "bx": "V",
      "bp": 165.43,
      "bs": 1,
      "c": [
        "R"
      ],
      "z": "C"
    },
    "VTI": {
      "t": "2022-08-04T17:42:13.343985473Z",
      "ax": "V",
      "ap": 218,
      "as": 3,
      "bx": "V",
      "bp": 191.4,
      "bs": 1,
      "c": [
        "R"
      ],
      "z": "B"
    }
  }
}

I believe the common expectation for a response like this would be:

{
  "quotes": [
    {
      "symbol": "TSLA",
      "t": "2022-08-04T17:42:24.920312936Z",
      "ax": "V",
      "ap": 940,
      "as": 1,
      "bx": "V",
      "bp": 924.4,
      "bs": 1,
      "c": [
        "R"
      ],
      "z": "C"
    },
    {
      "symbol": "AAPL",
      "t": "2022-08-04T17:42:26.629657067Z",
      "ax": "V",
      "ap": 165.45,
      "as": 1,
      "bx": "V",
      "bp": 165.43,
      "bs": 1,
      "c": [
        "R"
      ],
      "z": "C"
    },
    {
      "symbol": "VTI",
      "t": "2022-08-04T17:42:13.343985473Z",
      "ax": "V",
      "ap": 218,
      "as": 3,
      "bx": "V",
      "bp": 191.4,
      "bs": 1,
      "c": [
        "R"
      ],
      "z": "B"
    }
  ]
}

Cheers!

Hi @agentsmith, thanks for the suggestion!

Currently we don’t have any plans on changing the response on this endpoint. Can you provide any details/examples for how this is more difficult to work with?

Working in python, for example, the difference would be very minimal. Something like:

quotes = {...}

for symbol, quote in quotes.items():
    ...

# VS

for quote in quotes:
    symbol = quote["symbol"]
    ...

And most other programming languages have facilities that let you loop over the (key, value) pairs.

One advantage of having the symbols as keys is for lookups on the quotes map for specific symbols instead of iterating through the list to find the symbol you need. This is better from both a performance lens (probably minor), and in my opinion is a bit more developer-friendly.

Thanks for your input :slight_smile:,

Dylan @ Alpaca