Export trading activity

Is there a way to export trading activity to excel or other formats? Thanks

There’s an API for that! Look at get account activities. One can download specific activity types and specify the date range. Something like this in Python

# First fetch the desired activities
# Default is to fetch the most recent 100 activities
activities = api.get_activities()

# Turn the activities list into a dataframe
activities_df = pd.DataFrame([activity._raw for activity in activities])

# Use Pandas handy `to_csv` method to write the dataframe to a file
activities_df.to_csv('my_activites_file')

There isn’t a direct method to export the activities via the web portal, however there are some browser extensions which can help. One extension is Table Capture. There are others, and I don’t necessarily recommend this particular one, but I have used it and it works.

Once installed, navigate to the Alpaca Account Activities page in your browser. Select, the activities table, right mouse click, select ‘Table Capture’ from the pop-up menu, and after a couple more steps, voila! One gets a CSV file of activities.

The information provided by the API is more extensive than that in the web table, which may be one reason to use the API. However, clicking in the web portal is perhaps easier and may have enough info.

Hope that helps.

1 Like

Thanks Dan. I appreciate the details.

Can we add ‘start’ and 'end arguments to this method so we can obtain end-point inclusive data retrieval? It’s the difference between open interval (after, until) and closed interval (start, end).

Otherwise you need to start playing games with after and until like this:
after = some_start_date - pandas.offsets.BDay()
until = some_end_date + pandas.offsets.BDay()

I am using this method but I think it does not return all activities but it hold only few months back, for instance now it is April 2022 and I can see back to only November 2021, but I have been trading for more than that. Could someone explain the real behaviour of this API?

the max of the api call is to only pull 500 orders. If you have more than that you need to use pagination with your programing. For python this would look something like this:
image

2 Likes