def list_trades( self, # type: HummingbotApplication start_time: float): if threading.current_thread() != threading.main_thread(): self.ev_loop.call_soon_threadsafe(self.list_trades, start_time) return lines = [] queried_trades: List[TradeFill] = self._get_trades_from_session( int(start_time * 1e3), MAXIMUM_TRADE_FILLS_DISPLAY_OUTPUT + 1, self.strategy_file_name) if self.strategy_name == "celo_arb": celo_trades = self.strategy.celo_orders_to_trade_fills() queried_trades = queried_trades + celo_trades df: pd.DataFrame = TradeFill.to_pandas(queried_trades) if len(df) > 0: # Check if number of trades exceed maximum number of trades to display if len(df) > MAXIMUM_TRADE_FILLS_DISPLAY_OUTPUT: df_lines = str( df[:MAXIMUM_TRADE_FILLS_DISPLAY_OUTPUT]).split("\n") self._notify( f"\n Showing last {MAXIMUM_TRADE_FILLS_DISPLAY_OUTPUT} trades in the current session." ) else: df_lines = str(df).split("\n") lines.extend(["", " Recent trades:"] + [" " + line for line in df_lines]) else: lines.extend(["\n No past trades in this session."]) self._notify("\n".join(lines))
async def export_trades(self, # type: HummingbotApplication ): with self.trade_fill_db.get_new_session() as session: trades: List[TradeFill] = self._get_trades_from_session( int(self.init_time * 1e3), session=session) if len(trades) == 0: self.notify("No past trades to export.") return self.placeholder_mode = True self.app.hide_input = True path = self.client_config_map.log_file_path if path is None: path = str(DEFAULT_LOG_FILE_PATH) file_name = await self.prompt_new_export_file_name(path) file_path = os.path.join(path, file_name) try: df: pd.DataFrame = TradeFill.to_pandas(trades) df.to_csv(file_path, header=True) self.notify(f"Successfully exported trades to {file_path}") except Exception as e: self.notify(f"Error exporting trades to {path}: {e}") self.app.change_prompt(prompt=">>> ") self.placeholder_mode = False self.app.hide_input = False
def list_trades( self, # type: HummingbotApplication ): if threading.current_thread() != threading.main_thread(): self.ev_loop.call_soon_threadsafe(self.list_trades) return lines = [] if self.strategy is None: self._notify("Bot not started. No past trades.") else: # Query for maximum number of trades to display + 1 queried_trades: List[TradeFill] = self._get_trades_from_session( self.init_time, MAXIMUM_TRADE_FILLS_DISPLAY_OUTPUT + 1) df: pd.DataFrame = TradeFill.to_pandas(queried_trades) if len(df) > 0: # Check if number of trades exceed maximum number of trades to display if len(df) > MAXIMUM_TRADE_FILLS_DISPLAY_OUTPUT: df_lines = str( df[:MAXIMUM_TRADE_FILLS_DISPLAY_OUTPUT]).split("\n") self._notify( f"\n Showing last {MAXIMUM_TRADE_FILLS_DISPLAY_OUTPUT} trades in the current session." ) else: df_lines = str(df).split("\n") lines.extend(["", " Recent trades:"] + [" " + line for line in df_lines]) else: lines.extend(["\n No past trades in this session."]) self._notify("\n".join(lines))
def list_trades( self, # type: HummingbotApplication ): if threading.current_thread() != threading.main_thread(): self.ev_loop.call_soon_threadsafe(self.list_trades) return lines = [] # To access the trades from Markets Recorder you need the file path and strategy name if in_memory_config_map.get("strategy_file_path").value is None or \ in_memory_config_map.get("strategy").value is None: self._notify("Bot not started. No past trades.") else: # Query for maximum number of trades to display + 1 queried_trades: List[TradeFill] = self._get_trades_from_session( self.init_time, MAXIMUM_TRADE_FILLS_DISPLAY_OUTPUT + 1) df: pd.DataFrame = TradeFill.to_pandas(queried_trades) if len(df) > 0: # Check if number of trades exceed maximum number of trades to display if len(df) > MAXIMUM_TRADE_FILLS_DISPLAY_OUTPUT: df_lines = str( df[:MAXIMUM_TRADE_FILLS_DISPLAY_OUTPUT]).split("\n") self._notify( f"Number of Trades exceeds the maximum display limit " f"of:{MAXIMUM_TRADE_FILLS_DISPLAY_OUTPUT} trades. " f"Please change limit in client settings to display the required number of trades " ) else: df_lines = str(df).split("\n") lines.extend(["", " Past trades:"] + [" " + line for line in df_lines]) else: lines.extend([" No past trades in this session."]) self._notify("\n".join(lines))
def export_trades( self, # type: HummingbotApplication path: str = ""): if threading.current_thread() != threading.main_thread(): self.ev_loop.call_soon_threadsafe(self.export_trades, path) return if not path: fname = f"trades_{pd.Timestamp.now().strftime('%Y-%m-%d-%H-%M-%S')}.csv" path = join(dirname(__file__), f"../../../logs/{fname}") trades: List[TradeFill] = self._get_trades_from_session(self.init_time) if len(trades) > 0: try: df: pd.DataFrame = TradeFill.to_pandas(trades) df.to_csv(path, header=True) self._notify(f"Successfully saved trades to {path}") except Exception as e: self._notify(f"Error saving trades to {path}: {e}") else: self._notify("No past trades to export.")