Is it legal to use bots according to the rules of the exchange?

Yes, cryptocurrency exchanges allow trading through bots. Especially for this purpose, they provide an API (Application Programming Interface), through which trading applications can more effectively interact with the exchange.