This script tracks the net Bitfinex margin sizes from candle to candle (longs - shorts), and divide it by the total volume from the previous candle. This should give you a ratio of net margin trading volume over total volume on Bitfinex.
Note that assuming the delay is not severe, this ratio should never exceed 1 or -1 (since margin traded volume should strictly...