A bid-ask spread is the amount by which the ask price exceeds the bid. This is essentially the difference in price between the highest price that a buyer is willing to pay for an asset and the lowest price for which a seller is willing to sell it.
The following formulae have been used :
spread = bid-ask;
margin = ((ask-bid)/ask)*100%;