Slightly improve memory-usage of kraken-convert

This commit is contained in:
Matthias 2024-02-10 09:37:59 +01:00
parent a83b5abb51
commit 3aa2d0c30a

View File

@ -41,7 +41,7 @@ def import_kraken_trades_from_csv(config: Config, convert_to: str):
if pairs_raw := config.get('pairs'):
pairs = expand_pairlist(pairs_raw, [m[0] for m in markets])
markets = [m for m in markets if m[0] in pairs]
markets = {m for m in markets if m[0] in pairs}
if not markets:
logger.info(f"No data found for pairs {', '.join(pairs_raw)}.")
return
@ -61,17 +61,18 @@ def import_kraken_trades_from_csv(config: Config, convert_to: str):
continue
trades = pd.concat(dfs, ignore_index=True)
del dfs
trades.loc[:, 'timestamp'] = trades['timestamp'] * 1e3
trades.loc[:, 'cost'] = trades['price'] * trades['amount']
for col in DEFAULT_TRADES_COLUMNS:
if col not in trades.columns:
trades[col] = ''
trades.loc[:, col] = ''
trades = trades[DEFAULT_TRADES_COLUMNS]
trades = trades_convert_types(trades)
trades_df = trades_df_remove_duplicates(trades)
del trades
logger.info(f"{pair}: {len(trades_df)} trades, from "
f"{trades_df['date'].min():{DATETIME_PRINT_FORMAT}} to "
f"{trades_df['date'].max():{DATETIME_PRINT_FORMAT}}")