/
format_status_example.py
47 lines (40 loc) · 2.49 KB
/
format_status_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from hummingbot.strategy.script_strategy_base import ScriptStrategyBase
class FormatStatusExample(ScriptStrategyBase):
"""
This example shows how to add a custom format_status to a strategy and query the order book.
Run the command status --live, once the strategy starts.
"""
markets = {
"binance_paper_trade": {"ETH-USDT", "BTC-USDT", "MATIC-USDT", "AVAX-USDT"},
"kucoin_paper_trade": {"ETH-USDT", "BTC-USDT", "MATIC-USDT", "AVAX-USDT"},
"gate_io_paper_trade": {"ETH-USDT", "BTC-USDT", "MATIC-USDT", "AVAX-USDT"},
}
def format_status(self) -> str:
"""
Returns status of the current strategy on user balances and current active orders. This function is called
when status command is issued. Override this function to create custom status display output.
"""
if not self.ready_to_trade:
return "Market connectors are not ready."
lines = []
warning_lines = []
warning_lines.extend(self.network_warning(self.get_market_trading_pair_tuples()))
balance_df = self.get_balance_df()
lines.extend(["", " Balances:"] + [" " + line for line in balance_df.to_string(index=False).split("\n")])
market_status_df = self.get_market_status_df_with_depth()
lines.extend(["", " Market Status Data Frame:"] + [" " + line for line in market_status_df.to_string(index=False).split("\n")])
warning_lines.extend(self.balance_warning(self.get_market_trading_pair_tuples()))
if len(warning_lines) > 0:
lines.extend(["", "*** WARNINGS ***"] + warning_lines)
return "\n".join(lines)
def get_market_status_df_with_depth(self):
market_status_df = self.market_status_data_frame(self.get_market_trading_pair_tuples())
market_status_df["Exchange"] = market_status_df.apply(lambda x: x["Exchange"].strip("PaperTrade") + "paper_trade", axis=1)
market_status_df["Volume (+1%)"] = market_status_df.apply(lambda x: self.get_volume_for_percentage_from_mid_price(x, 0.01), axis=1)
market_status_df["Volume (-1%)"] = market_status_df.apply(lambda x: self.get_volume_for_percentage_from_mid_price(x, -0.01), axis=1)
return market_status_df
def get_volume_for_percentage_from_mid_price(self, row, percentage):
price = row["Mid Price"] * (1 + percentage)
is_buy = percentage > 0
result = self.connectors[row["Exchange"]].get_volume_for_price(row["Market"], is_buy, price)
return result.result_volume