In this tutorial we will explore the /cs/v1/audit/orderactivities/ endpoint with a fairly simple spreadsheet which pulls the latest trades from the user's accounts, loads all data into the specified area on the spreadsheet and automatically creates a table. The table is sorted by ActivityTime, which is the exact time the trade was confirmed on Saxo Bank's servers. Because this endpoint is limited in terms of the number of items it returns, we can only pull the latest 1000 trade confirmations. In addition, the endpoint contains all order activity on the user's accounts, hence filtering by Status is necessary to remove unwanted order confirmations that are not related the actual execution of trades. This tool has a couple of useful features:
- Because the /orderactivities/ endpoint will always return the latest 1000 trades, no additional instructions regarding date and timing are necessary to get the most relevant (recent) data.
- The entire flow is automated using VBA, which makes it quick to update and is especially useful when refreshing the blotter side-by-side with a trading tool (such as SaxoTraderGO).
- Filtering options in the table allow the user to quickly drill down into recent trades:
- Which asset types were traded on the client's accounts?
- Has a certain instrument been traded during the month of December?
- Which order types were used for these trades?
- Given a certain Limit/Stop order, at what price did the trade execute?
As in Tutorial 3, a dynamic pivot table is added, which is updated every time the source data is loaded. The Blotter table on the first tab serves as source for the pivot on the Stats tab. This allows the client to quickly drill down into his trades and get updated statistics every time the Update Blotter button is clicked.
To automate updates of the trade blotter, the VBA script below uses some familiar functionality to access data from the OpenAPI and loads it on the spreadsheet. In order to refresh the entire table, it is built from scratch every time the user hits the Update Blotter button. This means that all column headers, the construction of the table, and the sorting have to be repeated. The code below takes care of these tasks. Some key points here are:
- As before, the input is verified to prevent unwanted errors. Because this is a relatively basic flow, the only check required concerns the result of the API call using the TypeName() function.
- The table is created dynamically and always takes the full range of the loaded data.
- On each refresh, the table is labeled 'Blotter' and sorted automatically descending by Time.
Currently, this tool returns the first thousand trades from the activity log because this is the default behavior of the endpoint. If there are more than 1000 trades executed on the client's accounts, the more recent trades will not show.