How to calculate trading fees ahead of time? I'd like to determine what trading fees to expect before placing an order.

According to https://www.bitstamp.net/fee_schedule/ Bitstamp's trading fees depend upon the USD total of a customer’s last 30 days worth of transactions.

How can one calculate this amount using the Bitstamp API? It doesn't seem to be possible.
Those are Bitstamp trading fees, not Bitcoin transaction fees. Trading fees are automatically calculated and deducted by Bitstamp when executing a trade.

For choosing the right Bitcoin fee, use bitcoin-cli estimatesmartfee or one of the many web services.