Not able to get more than 100 historical orders using activities endpoint

Hi,

I’m trying to get the account order history (FILL) using the /v2/account/activities/activity_type/ endpoint but I’m not able to get the pagination to work as the result only provides a list of 100 transactions.

Instead of API key/secret, I’m using access token in the header.

This is what I’m following:

I’m using python and using the URL: api.alpaca.markets/v2/account/activities/activity_type/FILL gives me a 404 (but this is the URL in the documentation).

However, using the URL api.alpaca.markets/v2/account/activities?activity_types=FILL works
but only gives me a list of 100 most recent orders with no way to paginate.

I’m a bit confused. Am I using the wrong documentation? How can I get more historical trades or paginate historical account fills?

@CuCrest The activities can be paged using the ID of the last activity returned. If there are no activities returned after subsequent paging then that is the end. There is an explanation in the docs here

As an example, the first request would be without a page_token

https://paper-api.alpaca.markets/v2/account/activities/FILL?after=2024-01-01%2000%3A00%3A00&page_size=2

The result is this (notice there are 2 records since page_size=2 was specified)

[
    {
        "id": "20240112131913030::26001117-479d-4323-8a4a-eddcebe92ffd",
        "activity_type": "FILL",
        "transaction_time": "2024-01-12T18:19:13.030355Z",
        "type": "partial_fill",
        "price": "235.07",
        "qty": "1.534308929",
        "side": "buy",
        "symbol": "FNGU",
        "leaves_qty": "4",
        "order_id": "80557fa3-51a6-4411-b9d4-5b397d7fca2b",
        "cum_qty": "38.534308929",
        "order_status": "partially_filled"
    },
    {
        "id": "20240112131913027::64f18004-bcd7-4dca-8efb-6454597ac3fb",
        "activity_type": "FILL",
        "transaction_time": "2024-01-12T18:19:13.027857Z",
        "type": "fill",
        "price": "235.07",
        "qty": "4",
        "side": "buy",
        "symbol": "FNGU",
        "leaves_qty": "0",
        "order_id": "80557fa3-51a6-4411-b9d4-5b397d7fca2b",
        "cum_qty": "42.534308929",
        "order_status": "filled"
    }
]

The next call would be identical to the original call but with the added parameter page_token=20240112131913027::64f18004-bcd7-4dca-8efb-6454597ac3fb

https://paper-api.alpaca.markets/v2/account/activities/FILL?after=2024-01-01%2000%3A00%3A00&page_size=2&page_token=20240112131913027::64f18004-bcd7-4dca-8efb-6454597ac3fb

That will then return the next page of results. The page_size can be set to anything 1-100.

1 Like

Thank you! That helped!