Detailed instructions for maintaining a valid order book from a WebSocket API v1 order book feed are available in our How to maintain a valid order book support page.
Example code (in Python) that illustrates the WebSocket API v1 order book logic is provided below and is also available for download as krakenwsorderbook.py.
The example code implements a command line client that subscribes to the specified order book feed, then creates and maintains a valid order book from the feed messages, while outputting the current order book once per second.
The usage of the command line client is ./krakenwsbook.py symbol depth such as the following example commands: