def test_to_pandas(self): # Fix the timestamp here so that we can test order age accurately created = 1625835199511442 now_ts = created + 100 * 1e6 self.maxDiff = None orders = [ LimitOrder("HBOT_1", "A-B", True, "A", "B", Decimal("1"), Decimal("1.5")), LimitOrder(f"HBOT_{str(created)}", "C-D", True, "C", "D", Decimal("1"), Decimal("1")), LimitOrder("HBOT_2", "A-B ", False, "A", "B", Decimal("2.5"), Decimal("1"), Decimal("0"), created, LimitOrderStatus.OPEN), LimitOrder(f"HBOT_{str(created)}", "A-B ", False, "A", "B", Decimal("2"), Decimal("1"), Decimal(0), created, LimitOrderStatus.CANCELED), ] df = LimitOrder.to_pandas(orders, 1.5, end_time_order_age=now_ts) # Except df output is as below # Order ID Type Price Spread Amount Age Hang # HBOT_2 sell 2.5 66.67% 1.0 00:01:40 n/a # ...1442 sell 2.0 33.33% 1.0 00:01:40 n/a # HBOT_1 buy 1.0 33.33% 1.5 n/a n/a # ...1442 buy 1.0 33.33% 1.0 00:01:40 n/a # we can't compare the text output directly as for some weird reason the test file passes when run individually # but will fail under coverage run -m nose test.hummingbot # self.assertEqual(expect_txt, df.to_string(index=False, max_colwidth=50)) self.assertEqual("HBOT_2", df["Order ID"][0]) self.assertEqual("sell", df["Type"][0]) self.assertAlmostEqual(2.5, df["Price"][0]) self.assertEqual("66.67%", df["Spread"][0]) self.assertAlmostEqual(1., df["Amount"][0]) self.assertEqual("00:01:40", df["Age"][0]) self.assertEqual("n/a", df["Hang"][0]) # Test to see if hanging orders are displayed correctly df = LimitOrder.to_pandas(orders, 1.5, ["HBOT_1", "HBOT_2"], end_time_order_age=now_ts) # Except df output is as below # Order ID Type Price Spread Amount Age Hang # HBOT_2 sell 2.5 66.67% 1.0 00:01:40 yes # ...1442 sell 2.0 33.33% 1.0 00:01:40 no # HBOT_1 buy 1.0 33.33% 1.5 n/a yes # ...1442 buy 1.0 33.33% 1.0 00:01:40 no self.assertEqual("HBOT_2", df["Order ID"][0]) self.assertEqual("sell", df["Type"][0]) self.assertAlmostEqual(2.5, df["Price"][0]) self.assertEqual("66.67%", df["Spread"][0]) self.assertAlmostEqual(1., df["Amount"][0]) self.assertEqual("00:01:40", df["Age"][0]) self.assertEqual("yes", df["Hang"][0]) # Test to see if df is created and order age is calculated df = LimitOrder.to_pandas(orders, 1.5, []) self.assertAlmostEqual(2.5, df["Price"][0]) self.assertTrue(":" in df["Age"][0])
def format_status(self) -> str: lines = [] warning_lines = [] for market_info in self._market_infos.values(): active_orders = self.market_info_to_active_orders.get( market_info, []) warning_lines.extend(self.network_warning([market_info])) markets_df = self.market_status_data_frame([market_info]) lines.extend( ["", " Markets:"] + [" " + line for line in str(markets_df).split("\n")]) assets_df = self.wallet_balance_data_frame([market_info]) lines.extend( ["", " Assets:"] + [" " + line for line in str(assets_df).split("\n")]) # See if there're any open orders. if active_orders: df = LimitOrder.to_pandas(active_orders) df_lines = str(df).split("\n") lines.extend(["", " Active orders:"] + [" " + line for line in df_lines]) else: lines.extend(["", " No active maker orders."]) warning_lines.extend(self.balance_warning([market_info])) if warning_lines: lines.extend(["", "*** WARNINGS ***"] + warning_lines) return "\n".join(lines)
def format_status(self) -> str: lines: list = [] warning_lines: list = [] lines.extend(self.configuration_status_lines()) for market_info in self._market_infos.values(): active_orders = self.market_info_to_active_orders.get( market_info, []) warning_lines.extend(self.network_warning([market_info])) markets_df = self.market_status_data_frame([market_info]) lines.extend( ["", " Markets:"] + [" " + line for line in str(markets_df).split("\n")]) assets_df = self.wallet_balance_data_frame([market_info]) lines.extend( ["", " Assets:"] + [" " + line for line in str(assets_df).split("\n")]) # See if there're any open orders. if len(active_orders) > 0: df = LimitOrder.to_pandas(active_orders) df_lines = str(df).split("\n") lines.extend(["", " Active orders:"] + [" " + line for line in df_lines]) else: lines.extend(["", " No active maker orders."]) filled_trades = self.filled_trades() average_price = (statistics.mean( [trade.price for trade in filled_trades]) if filled_trades else Decimal(0)) lines.extend([ "", f" Average filled orders price: " f"{PerformanceMetrics.smart_round(average_price)} " f"{market_info.quote_asset}" ]) lines.extend([ f" Pending amount: {PerformanceMetrics.smart_round(self._quantity_remaining)} " f"{market_info.base_asset}" ]) warning_lines.extend(self.balance_warning([market_info])) if warning_lines: lines.extend(["", "*** WARNINGS ***"] + warning_lines) return "\n".join(lines)
def format_status(self) -> str: lines: list = [] warning_lines: list = [] lines.extend(self.configuration_status_lines()) for market_info in self._market_infos.values(): active_orders = self.market_info_to_active_orders.get( market_info, []) warning_lines.extend(self.network_warning([market_info])) markets_df = self.market_status_data_frame([market_info]) lines.extend( ["", " Markets:"] + [" " + line for line in markets_df.to_string().split("\n")]) assets_df = self.wallet_balance_data_frame([market_info]) lines.extend( ["", " Assets:"] + [" " + line for line in assets_df.to_string().split("\n")]) # See if there're any open orders. if len(active_orders) > 0: price_provider = None for market_info in self._market_infos.values(): price_provider = market_info if price_provider is not None: df = LimitOrder.to_pandas( active_orders, mid_price=price_provider.get_mid_price()) if self._is_buy: # Descend from the price closest to the mid price df = df.sort_values(by=['Price'], ascending=False) else: # Ascend from the price closest to the mid price df = df.sort_values(by=['Price'], ascending=True) df = df.reset_index(drop=True) df_lines = df.to_string().split("\n") lines.extend(["", " Active orders:"] + [" " + line for line in df_lines]) else: lines.extend(["", " No active maker orders."]) filled_trades = self.filled_trades() average_price = (statistics.mean( [trade.price for trade in filled_trades]) if filled_trades else Decimal(0)) lines.extend([ "", f" Average filled orders price: " f"{PerformanceMetrics.smart_round(average_price)} " f"{market_info.quote_asset}" ]) lines.extend([ f" Pending amount: {PerformanceMetrics.smart_round(self._quantity_remaining)} " f"{market_info.base_asset}" ]) warning_lines.extend(self.balance_warning([market_info])) if warning_lines: lines.extend(["", "*** WARNINGS ***"] + warning_lines) return "\n".join(lines)