hummingbot / hummingbot

Open source software that helps you create and deploy high-frequency crypto trading bots
https://hummingbot.org
Apache License 2.0
8.04k stars 2.79k forks source link

Make TWAP a production strategy #3431

Closed phbrgnomo closed 3 years ago

phbrgnomo commented 3 years ago

What?

The dev_4_twap was first implemented as strategy creation demo for external developers and haven't been touched in a long time. Currently the strategy is partialy woking.

The strategy must be refactored to update the code to make proper use of the current code base, but also to work as stand-alone public strategies that are available on the master branch.

Curent state

TWAP

Why?

The code of these strategies must be updated to the most recent framework of the code base.

These strategies are also widely used by traders that need to negotiate big volumes.

Making them public available allows to demostrante different ways that hummingbot can be used by big players.

Due to it's simplicity, they are good examples for developers on how to build new strategies.

How?

TWAP

Configurations/Variables needed:

trading_pair - What is the trading pair the strategy will be executed

target_asset_amount - What is the total amount that will be bought/sold

order_step_size - What is the size of each individual order

order_delay_time - how long the bot must wait between each individual order

end_timer - for how long the bot must run. (-1 option must be enabled to disable the timed execution) # to be implemented on a follow-up issue

orders_price - The maximum/minimum price of all the individual orders

trade_side - (buy or sell) which side of the trade the orders will be executed

Note:

A proper TWAP strategy should calculate the best trade price based on last market prices, that would be used as the orders_price value. A simple script for the calculation of the TWAP value is shown here: phbrgnomo/CryptoTradingTools But this implementation would require historical price data to be accessible through hummingbot, wich is still a work in progress (issue #3250) Therefore, the current strategy refactor will not consider this calculation. Followup issues will be created to each new improvement.

Strategy prompts

What is the trading pair? User select the trading pair market -> tradig_pair

What operation will be executed? (buy/sell) User chooses if it will buy or sell the asset -> trade_side

What is the total amount of <base asset> to be traded? This option sets target_asset_amount that must limit the maximum amount the bot will be allowed to trade

At what price the orders will be created? This sets orders_price.

What is the size of each individual order (in <base asset>)? This sets order_step_size

How long must the bot wait between each order (in seconds)? This sets orders_delay_time

Execution

When the strategy start, the bot will create a LIMIT order, with the order_step_size amount, every orders_delay_time seconds, until the total amount of orders filled is equal to target_asset_amount

Performance stats

status must show:

history

First config:
1 BTC at 10k USD

= total amount spent 10k USD

0.5 at 9k USD

Const spent =4.5k USD

0.5 at 10k = Need to spend 5k

Expected total cost on the end = 4.5k + 5k = 9,5k

Impact?

A proper TWAP strategy creates an easy tool for traders to sell/buy a big amount of capital on the markets without moving prices. This expands the use of hummingbot as a professional trading tool beyond market-making and provides acessibility to this automated strategy to more people.

Alternatives?

New stories will be created as follow up to improve this strategy:

References

Research sources

TWAP

https://empirica.io/blog/twap-strategy/

https://blog.quantinsti.com/twap/

phbrgnomo commented 3 years ago

@aarmoa & @keithbaum a reminder that once the refactor is finished, we should remove the dev from the strategy name to make it available on master/docker install.

But this strategy is also still a simple example for external devs, so add/keep comments on it where you see fit to explain what each parameter part of the strategy is doing.