Margin by itself is not additive as it is calculated under the maximum norm. The closest thing that works in real-time is CME's SPAN mechanism. There's some documentation on the client systems wiki if you want to implement something similar, although it would require simulating all scenarios (up, down, sideways, high vol, low vol).
?
Margin(A) + Margin(B) != Margin (A+B)
?
With the SPAN methodology, the risk vectors are additive:
Risk(A+B)[k] = Risk(A)[k] + Risk(B)[k]
?
So margin can always be deduced:
Margin(A+B) = max ( Risk(A+B)[k] for k in [1..16] ) = max ( Risk(A)[k]+Risk(B)[k] for k=1..16 )
?
IB is doing something similar on their side.