Hummingbot connector for Uniswap and other AMMs

Hi everyone, was wondering if you had any recommendations/guidance for building a connector for a automated reserve such as kyber (seems like uniswap is similar). I’m looking at the connector documentation, and it seems that much of it is revolved around an orderbook (e.g. OrderBookDatasource, ActiveOrderTracker, OrderBookTracker…) However, in these systems there is not really an orderbook. You can basically buy whatever amount of tokens you want at the ‘rate’ of the reserve (which dynamically adjusts). I have an api where I can enter the token amount and get a quote price for that amount. I’m having trouble implementing this in the standard connector format, and any help/guidance would be appreciated.

Since some users have asked about building a connector for Uniswap and similar venues, I wanted to provide some guidance. As mentioned in this blog post, we are big fans of decentralized exchanges that utilize automatic market makers like Uniswap, Bancor, and Kyber Network. We think that a Uniswap connector for Hummingbot makes a lot of sense, but currently our engineering bandwidth is tied up integrating with regular exchanges that support market making. You may also want to read this post about different exchange types.

Rather than an order book, Uniswap uses a constant function to determine the price for a given order amount. The function is a “constant product formula”: it solves for the price such that the value of the combined reserve is equivalent before and after the trade. I think of it as replacing a non-linear order book (assembled by aggregating a set of orders) with a synthetic order book defined by a simple linear function in which only the order quantity and the current reserve amounts are hyper-parameters.

Therefore, the order book components of a Hummingbot connector can be greatly simplified by replicating Uniswap’s constant product formula inside the connector, so that the connector can compute the price for any order quantity. Then, assuming that you know the amount and type (bid or ask) of an order, you can create a synthetic order book using the formula.

Note that Hummingbot’s market making strategies can’t be used with Uniswap, but the arbitrage strategy should be viable.

Thanks for the post @fengtality. Im looking to implement this for Kyber’s Automated Pricing Reserve. It follows a pricing curve, similar to that of uniswap.

The problem I see with trying to create a ‘fake orderbook’ is that there are infinite possibilities because the price is dependent on the quantity being bought. With that being said, I’m failing to see how this would fit into a system where the orderbook is polling/listening for new bids/asks. Could you give a high level description of what classes/methods I need to implement for this use case? and where you would call the price function within those classes? (e.g. OrderBook, OrderBookTracker, OrderBookTrackerDatasource, Market). Alot of methods in those classes do not make sense to implement for this use case, but I dont know the consequences of not implementing them. Could implementations (either classes or methods of those classes) be left out, and if so, which ones?

1 Like

I see… I agree that since the order book is dependent on quantity, a lot of what currently have in Hummingbot doesn’t apply.

I recommend starting with the arbitrage strategy rather than with a market connector, since that’s the only strategy that can be used with an AMM. The direction I would explore is to create a custom version of this strategy so that one market can be an order book exchange while the other is an AMM. Currently, the c_find_profitable_arbitrage_orders function increments through two order books and returns the profitable opportunities. Since the quantity is known in each loop of the increment step-through, you can use the AMM’s constant product formula to derive the price and then compare it with the price in the other market.

There are still a number of changes necessary to make this strategy play nicely with the rest of Hummingbot, especially if you want all the tests to pass. For this reason, we originally intended to integrate Uniswap and other AMMs with Hummingbot ourselves. Since our business model depends on it, our roadmap is filled with integrating with exchanges that support market making, so AMMs aren’t on there currently. However, we are happy to offer guidance to external developers who want to add support for AMMs like Uniswap, Bancor, and Kyber.

Interesting. I am thinking to develop connector for AMM market . It would be great if someone can just provide dummy methods which need different implementation than other exchanges .

@fengtality . Do we need to define Order book message of new connector in hummingbot.core.data_type.order_book_message . . This is being refer in OrderBookDataSource. This seems to be kind of integration part, but can we do unit test without this?