Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- paths = [
- '/mnt/ico_data/PRYUSDT-2024-04-03-13-02-00_TRADES.log',
- '/mnt/ico_data/SCOTTYAIUSDT-2024-03-26-22-15-57_TRADES.log',
- '/mnt/ico_data/SPARTAUSDT-2024-03-26-22-14-32_TRADES.log',
- '/mnt/ico_data/MUSKUSDT-2024-04-03-08-56-27_TRADES.log',
- '/mnt/ico_data/HOVUSDT-2024-03-26-22-08-45_TRADES.log',
- '/mnt/ico_data/GGMTUSDT-2024-03-27-09-52-27_TRADES.log',
- '/mnt/ico_data/BXNUSDT-2024-04-02-11-58-18_TRADES.log'
- ]
- total = []
- before_1h = []
- after_1h = []
- for path_to_log in paths:
- with open(path_to_log) as file:
- raws = file.readlines()
- trades = []
- for i in range(len(raws)):
- if raws[i][:5] == 'Trade':
- try:
- trade = json.loads(raws[i + 1])
- trade['time'] = int(raws[i][raws[i].find('time: ') + len('time: '):])
- trades.append(trade)
- except json.JSONDecodeError:
- print('Error in line ', i)
- df_trades = pd.DataFrame(trades)
- df_trades.drop('symbol', axis=1, inplace=True)
- df_trades['price'] = df_trades['price'].astype(float)
- df_trades['quantity'] = df_trades['quantity'].astype(float)
- df_trades['quote_size'] = df_trades['price'] * df_trades['quantity']
- df_trades['time'] = pd.to_datetime(df_trades['time'] * 1e6) # делать ли groupby по 1с
- df_trades = df_trades.groupby(by=['time', 'side']).sum().reset_index()[['time', 'quote_size', 'side']]
- df_trades['time delta'] = (df_trades['time'].shift(-1) - df_trades['time']).dt.total_seconds()
- trades_before_1h = df_trades[df_trades['time'] <= np.min(df_trades['time'] + datetime.timedelta(hours=1))]
- trades_after_1h = df_trades[df_trades['time'] > np.min(df_trades['time'] + datetime.timedelta(hours=1))]
- print(path_to_log.split('/')[3].split('-')[0])
- print('all trades data duration (hours) = ', np.round((np.max(df_trades['time']) - np.min(df_trades['time'])).total_seconds() / 3600, 1))
- print('trades mean / trades sum / time delta mean')
- print('total: ', np.round(df_trades['quote_size'].mean(), 3),
- np.round(df_trades['quote_size'].sum(), 1),
- np.round(df_trades['time delta'].mean(), 3))
- print('1h: ', np.round(trades_before_1h['quote_size'].mean(), 3),
- np.round(trades_before_1h['quote_size'].sum(), 1),
- np.round(trades_before_1h['time delta'].mean(), 3))
- print('1h+: ', np.round(trades_after_1h['quote_size'].mean(), 3),
- np.round(trades_after_1h['quote_size'].sum(), 1),
- np.round(trades_after_1h['time delta'].mean(), 3))
- total.append((np.round(df_trades['quote_size'].mean(), 3),
- np.round(df_trades['quote_size'].sum(), 1),
- np.round(df_trades['time delta'].mean(), 3)))
- before_1h.append((np.round(trades_before_1h['quote_size'].mean(), 3),
- np.round(trades_before_1h['quote_size'].sum(), 1),
- np.round(trades_before_1h['time delta'].mean(), 3)))
- after_1h.append((np.round(trades_after_1h['quote_size'].mean(), 3),
- np.round(trades_after_1h['quote_size'].sum(), 1),
- np.round(trades_after_1h['time delta'].mean(), 3)))
- print()
- print('total mean = ', np.array([coin[0] for coin in total]).mean())
- print('1h mean = ', np.array([coin[0] for coin in before_1h]).mean())
- print('1h+ mean = ', np.array([coin[0] for coin in after_1h]).mean())
- print()
- print('1h trades sum = ', np.array([coin[1] for coin in before_1h]).mean())
- print()
- print('total time delta mean = ', np.array([coin[2] for coin in total]).mean())
- print('1h time delta mean = ', np.array([coin[2] for coin in before_1h]).mean())
- print('1h+ time delta mean = ', np.array([coin[2] for coin in after_1h]).mean())
- import numpy as np
- import matplotlib.pyplot as plt
- plt.scatter(np.array([coin[2] for coin in after_1h]), 7 * [0], alpha=0.7, color='g')
- plt.title('after 1h cutted mean interval between trades')
- plt.xlim([0, 40])
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement