I know its not legal to have open long and short position on specific security (on two stock exchanges - NSE/BSE)
There is nothing illegal about it. There are prescribed ways on how this is addressed.
In Cash Segment / Intra Day trades:
One can short sell a security. If by end of day he does not buy the security; it goes into Auction. The said security is purchased on your behalf. Any profit or loss arising out of this is charged to you.
Similarly one can buy a security; if one does not pay the amount by end of day; it would go into auction and sold. Any profit or loss arising out of this is charged to you.
If you short sell a security on one exchange; you have to buy it on same exchange. If you buy on other exchange; it will not be adjusted against this short position.
Also is it legal to have long position on stock and short its derivative (future/option)?
There are no restrictions.
Edit:
@yety Party A shorts 10 shares of HDFC today in Intra-Day Cash Segment purchased by Party B. Rather than buying back 10 shares or allowing it to go into auction... Party A borrows 10 HDFC Shares from "X" via SLB for a period of say 6 months [1 month to 1 year]. This is recorded as Party A obligation to "X". These 10 borrowed shares are transferred to Party B. So Party "X" doesn't have any HDFC shares at this point in time. However in exchange, Party X receives fees for borrowing from Party A. If there is dividend, are declared, Company pays Party B. However SLB recovers identical amount from Party A and pays Party X. If there is 1:1 split, now party A owes Party X 20 HDFC Shares. On maturity [after 6 months], Party A has to buy these from market and given back the borrowed shares to Party X.
If there are some other corporate actions, i.e. mergers / amalgamations ... the obligation of Party A to Party X is closed immediately and position settled.
Of course there are provisions whereby party A can pay back the shares earlier or party X can ask for shares earlier and there are rules/trades/mechanisms to facilitate this.