Options

Can someone explain to me how option open interest works? You have volume and open interest. Say I want to buy 1,000 contracts but the open interest is only 500. Does open interest change if you were to write the options vs buying them? Thanks in advance.

You buy 50 contracts: OI 50, Volume 50

You sell 50 contracts: OI 0, Volume 100

OI is just existing position in the market. (For every long there is a short so counted only once)

A fresh long / short adds up OI. A reversal of that position decreases the OI.

Volume is just additive each time a trade is executed.