Getting your order book data in CCXT

Getting Started

First, we have to do the essentials, importing ccxt, along with a config file that holds your keys. You can also insert your keys directly but we prefer to use a file. Next, we need to establish a few things, firstly the ticker which in this case will be uBTCUSD.

Finding our Order Book

Using the fetch command we’ve used in previous tutorials, we are going to enter the commands: “def ob():”, followed by “ob = phemex.fetch_order_book(symbol)”, then lastly “return ob”. Then as you have likely learned from previous tutorials, we need to print the function. Entering “print (ob())” in this case. This will bring up our order book when we run the code.

What can you use the order book for?

There are a few useful parts here, such as:

  • Timestamps. These are useful for showing you see exactly when trades were made
  • Bids and asks. Which let you see exactly what prices were in play on any certain order. This is super important as you won’t always get the latest data when an order is made.

Now using the order book, we first need to establish that “ob = ob()”. Then deleting the previous print, we only need to use the command “print(ob)” to print the order book. If you want to pull the specific bids and asks up, we have another tutorial that you can check out to bring them up more effectively and specifically, as they take a bit of time to look through without tailoring.

In Conclusion

The order book is a very important tool in an algorithm trader’s arsenal, without it, you can be left feeling seriously uninformed about your decisions and methods of making a profit. It is one of the many essential things to learn when it comes to being a successful algo trader.

want to learn how to algo trade so you can remove all emotions from trading and automate it 100%? click below to join the free discord and then join the bootcamp to get started today.

Leave a Reply

Your email address will not be published. Required fields are marked *