I have a command that calculates margin every 10 seconds
It's not recommended to poll funds API. You can alternatively fetch funds value at the start of the trading day and keep reducing the required order placed amount, which you can fetch from the order margin API.