The terminology can be confusing.
Initial margin can be up to 50% of the purchase. (2:1)
Intraday margin can be 25%. (4:1)
Say you have $20,000 cash in your account. Regulation T ( a quasi-government regulation - set by the Federal Reserve) allows the broker to loan you another $20,000 to buy stocks. (2:1)
You buy $40,000 worth of stock. You are now at 50% (1/2 your money - 1/2 your broker's loan). That is the maximum the broker may lend you on a stock purchase.
Once you are into the stock you must maintain a maintenance margin. It must be a minimum of 25%. But the normal percentage is generally greater, is set by the broker and can change at their whim. What this means is that once you are in a position its value can decrease to some degree without the need to sell it or add more money to the account. Do not confuse with the 25% intraday margin. Any intraday purchase that uses 25% margin must be closed or reduced to the 50% level by the end of the day.
In the case of IB, they generally, especially during periods of high volatility, raise the maintenance margin and the initial margin higher than many other brokers do. IB is very risk averse.
Unlike many brokers IB does not issue what I think of as a margin call. Many brokers give you two or three days to get more money into the account. IB does not. If your IB account becomes under-margined there will be a pop-up message on your TWS advising that you are getting close to limits and then a subsequent message saying, in effect, do something to get this under control or we will do it for you. Shortly thereafter, how long has always been a mystery, IB will sell stuff to get your account back with their margin parameters. Also, if you are using intraday margin, be aware that IB does not let you go to the market close. They will close you out about 10 minutes before the close to ensure you can meet margin requirements at the close. This is not good for you as they seem to use market orders, not limit orders.
IB has some of the absolute lowest margin interest charges in the retail business.
If you are going to write program parameters for different brokers you'll have to check with each. Futures, by the way, do not work on margin, they use performance bonds. So look them up if you ever get interested in that area.
If you are new to this stuff, especially if you are going to be doing system trading, be sure to read about Pattern Day Traders (PDT). Although margin can be involved, the frequency of trading drives PDT rules.
Jack