Author: fengtality 0x352
Original Post Date: 12 Jan 2022
In addition, CoinAlpha engineering lead @nullably has created a few related exploratory issues:
- Introduce new Lite strategies. · Issue #4715 · hummingbot/hummingbot · GitHub (epic)
- New lite strategy base class · Issue #4716 · hummingbot/hummingbot · GitHub
- New lite argument on start command · Issue #4717 · hummingbot/hummingbot · GitHub
- New lite strategy examples · Issue #4718 · hummingbot/hummingbot · GitHub
Note that there may be some architectural / refactoring work needed to support these cases, and this is still very preliminary. Nonetheless, we’d like to open up the discussion to everyone in the community.
Thanks for kicking off the discussion @klpanagi! I think an important first step is to define the level of abstraction. Since strategies can be quite different and achieve different purposes, especially user generated ones, I think it’d be simpler to start at a lower abstraction level and define a framework that simplifies the creation of a strategy itself. This should be easier to scope because a strategy is simply a looping process that performs the following actions each tick:
- Fetch data from an array of markets (exchange-pair combinations)
- Cancel orders on those markets
- Create orders on those markets
I feel like an interface should let the user to specify the list of the markets, expose helper functions to help the user retrieve data each tick (outstanding orders, top bid/ask, bid and ask orders, etc), and have cancel_order and create_order higher order functions that users can control more precisely. Everything else in between is just pure logic and can be performed in normal Python.
I will definitely agree for the initial definition of the abstraction level and build it in layers.
Ok, I see that you are talking about a DSL for **Creating Strategies” , not for customizing currently supported.
In this case, yes we should initially split down and implement (reuse from codebase) basic operations needed to create strategies, in the form of a framework in Python.
Another solution is Refactoring the current implementation to allow using different entities, such as for example MarketDataFeeder and OrderExecutor, for easily creating custom bots in Python, which can use custom / community-driven indicators.
Similar to what I was thinking there. Thanks for pointing out the common market actions on each tick.
So, if I understand correctly, you suggest to initially implement a framework in Python for easily creating strategies. This means we will implement a new way of creating and executing hummingbot bots.
Can you provide an example of how you imagine writing custom strategies? (you act as an end-user here )
Sure, this is totally off the cuff but here’s an example or a simple arbitrage strategy in pseudo-code:
markets = Markets( ["binance", "BTC-USD"], ["kucoin", "BTC-USDT"] binance_px = markets.top_bid kucoin_px = markets.top_ask # create orders if (binance_px <= kucoin_px) markets,create_order("limit", "buy", 1000) markets,create_order("limit", "sell", 1000) # cancel orders if (markets.outstanding_orders.length > 0) markets.cancel_all_orders() if (markets.outstanding_orders.length > 0) markets.cancel_all_orders()
IMO, it’s similar to how Keras offers a simpler entry point into creating a Tensorflow model. It’s limited in scope, but advanced users can always create their ML model in native Tensorflow
@klpanagi welcome! Really good to see someone developing this idea, because it’s something we discussed internally a few times but the team never had the proper time to work on it.
I can’t help much with the coding part, but as someone that have been playing around for some time creating trading bots even on TradFi platforms, I am really interested in helping with this side project. We can schedule a call to exchanges some ideas, but as a starting point, my opinion is that we should aim to having something similar to MQL5 (Metatrader) and Pinescript (Tradingview).
I think the simplification of strategy creation shouldn’t remove the potential power of writing it directly in python, but allow must used functions on trading (like “creat buy order, with x volume at y price”) to be added to the strategy by a simple function call.
Thanks @fengtality! Hello @phgnomo!
This approach of developing strategies in Python language is actually what I was searching for when I initially started searching for crypto amm bot frameworks. Though, hummingbot client does not currently support this approach due to the actual implementation. We must develop a more abstract implementation of
Strategy and refactor (atleast) the
HummingApplication class to support the execution, or implement a new
I will agree that this approach will enable building custom AMM bots, using more abstract textual and graphical languages in the future.
At this point, I would like us to talk about the future intentions, in order to build it correctly from scratch. @phgnomo pointed some example platforms which provide easy scripting of their strategies. I will go one step forward… I have discussed the idea of creating strategies via a graphical language with experience traders and the feedback was very positive. Imagine having a canvas where you can drag&drop indicators, oscillators, algorithms, market_operations etc, connect them in graph, parameterize the blocks and auto-generate and execute the bot via a single click.
In any case, to go there, we must have a high-level framework (Hummingbot Strategy DSL in Python) to easily create and deploy custom strategies. Injecting source code or performing partial or complete code-generation won’t be a problem in the future, If you want to follow that path. Secondly, I would implement an L2 textual DSL for traders with high-level semantics, similar to what you mentioned (“create buy order, with x volume at y price”). Finally, I would build a graphical DSL for traders on top of the textual one.
I will have a look at MQL5 (Metatrader) later one today, just to have an idea of their approach… I know Pinescript , it could be better…
Sure, lets schedule a call to exchange ideas and craft some initial implementation thoughts.
MQL5 is a modified C++ language.
By visual drag&drop, i am guessing you are thinking in something like this:
Yeah, i think it would be a really awesome tool to have, but my guess is that it would need some time to make it work properly.
My suggestion is that we start with the L2 textual DSL, in a way that would make it similar to writing Python (The same way MQL5 is a modified C++ language), but leave the door open on the architecture design for a future implementation of a graphic strategy builder. Here is MQL5 documentation: MQL5 Reference - How to use algorithmic/automated trading language for MetaTrader 5
Exactly! And yeah, It will need time and a lot of effort to build it. That is why I also think of a three phase schedule. 1) High-level Python framework (aka DSL in python), 2) Trader-oriented Textual DSL, 3) Graphical DSL. By utilizing model-driven development techniques, we will be able to transform models from 3 to 2 to 1 and able to perform code-generation or model interpretation at the level of Python. You can also have a look at the NodeRED and NoFlo low-code platforms for the visual paradigm of DSLs. Though these DSLs are specialized for the domain of IoT, but the concept is similar.