$172.07 -1.51%
ETH · 40w

Bitfinex releases new Python API client + tutorial

Tutorial: Creating and managing trades with the new Python client

Jan 10

We received really good feedback with our original NodeJS client and a lot of people requested a port to Python so they can continue to create advanced strategies on the Bitfinex platform in a language that is extremely friendly to data analytics.

The team at Bitfinex have been working on the bitfinex-api-py repo which can be found here:

The client is designed to make it easy to interact with both the REST and websocket interface.

The client handles all of the nasty parts that are associated with websockets such as subscriptions, authentication, confirmation callbacks and reconnecting when the connection is intermittent. The REST interface is as easy as ever to use, it exposes function calls such as get_active_orders() and then handles all of the authentication for you.

In this tutorial we will cover three basic examples such as subscribing to the order-book, sending an order and retrieving open orders. These examples will be a good place to start since it will show how to manage a subscription and also authenticated REST + websocket calls.

Subscribing to an order-book

Firstly we have to create an instance of the Bitfinex client. Since the order-books are public, we don’t need to worry about passing in any auth keys.

Once we have done this we can use Python decorators to call a function when a certain event occurs (for a full list of events that are available please see the github repo).

from bfxapi import Client bfx = Client( logLevel='INFO', manageOrderBooks=True)'order_book_update')def log_update(data): print ("Book update: {}".format(data))'connected')async def start(): await'book', 'tBTCUSD')

Here we listen to 2 different events — the order-book update event and the ‘connected’ event which is triggered when the connection is s...

Continue on
Recent news