Advertisement
den4ik2003

Untitled

Apr 16th, 2024
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.16 KB | None | 0 0
  1. paths = [
  2. '/mnt/ico_data/PRYUSDT-2024-04-03-13-02-00_TRADES.log',
  3. '/mnt/ico_data/SCOTTYAIUSDT-2024-03-26-22-15-57_TRADES.log',
  4. '/mnt/ico_data/SPARTAUSDT-2024-03-26-22-14-32_TRADES.log',
  5. '/mnt/ico_data/MUSKUSDT-2024-04-03-08-56-27_TRADES.log',
  6. '/mnt/ico_data/HOVUSDT-2024-03-26-22-08-45_TRADES.log',
  7. '/mnt/ico_data/GGMTUSDT-2024-03-27-09-52-27_TRADES.log',
  8. '/mnt/ico_data/BXNUSDT-2024-04-02-11-58-18_TRADES.log'
  9. ]
  10. total = []
  11. before_1h = []
  12. after_1h = []
  13.  
  14. for path_to_log in paths:
  15. with open(path_to_log) as file:
  16. raws = file.readlines()
  17. trades = []
  18. for i in range(len(raws)):
  19. if raws[i][:5] == 'Trade':
  20. try:
  21. trade = json.loads(raws[i + 1])
  22. trade['time'] = int(raws[i][raws[i].find('time: ') + len('time: '):])
  23. trades.append(trade)
  24. except json.JSONDecodeError:
  25. print('Error in line ', i)
  26.  
  27. df_trades = pd.DataFrame(trades)
  28. df_trades.drop('symbol', axis=1, inplace=True)
  29. df_trades['price'] = df_trades['price'].astype(float)
  30. df_trades['quantity'] = df_trades['quantity'].astype(float)
  31. df_trades['quote_size'] = df_trades['price'] * df_trades['quantity']
  32. df_trades['time'] = pd.to_datetime(df_trades['time'] * 1e6) # делать ли groupby по 1с
  33. df_trades = df_trades.groupby(by=['time', 'side']).sum().reset_index()[['time', 'quote_size', 'side']]
  34. df_trades['time delta'] = (df_trades['time'].shift(-1) - df_trades['time']).dt.total_seconds()
  35.  
  36. trades_before_1h = df_trades[df_trades['time'] <= np.min(df_trades['time'] + datetime.timedelta(hours=1))]
  37. trades_after_1h = df_trades[df_trades['time'] > np.min(df_trades['time'] + datetime.timedelta(hours=1))]
  38.  
  39. print(path_to_log.split('/')[3].split('-')[0])
  40. print('all trades data duration (hours) = ', np.round((np.max(df_trades['time']) - np.min(df_trades['time'])).total_seconds() / 3600, 1))
  41. print('trades mean / trades sum / time delta mean')
  42.  
  43. print('total: ', np.round(df_trades['quote_size'].mean(), 3),
  44. np.round(df_trades['quote_size'].sum(), 1),
  45. np.round(df_trades['time delta'].mean(), 3))
  46.  
  47. print('1h: ', np.round(trades_before_1h['quote_size'].mean(), 3),
  48. np.round(trades_before_1h['quote_size'].sum(), 1),
  49. np.round(trades_before_1h['time delta'].mean(), 3))
  50.  
  51. print('1h+: ', np.round(trades_after_1h['quote_size'].mean(), 3),
  52. np.round(trades_after_1h['quote_size'].sum(), 1),
  53. np.round(trades_after_1h['time delta'].mean(), 3))
  54.  
  55.  
  56. total.append((np.round(df_trades['quote_size'].mean(), 3),
  57. np.round(df_trades['quote_size'].sum(), 1),
  58. np.round(df_trades['time delta'].mean(), 3)))
  59.  
  60. before_1h.append((np.round(trades_before_1h['quote_size'].mean(), 3),
  61. np.round(trades_before_1h['quote_size'].sum(), 1),
  62. np.round(trades_before_1h['time delta'].mean(), 3)))
  63.  
  64. after_1h.append((np.round(trades_after_1h['quote_size'].mean(), 3),
  65. np.round(trades_after_1h['quote_size'].sum(), 1),
  66. np.round(trades_after_1h['time delta'].mean(), 3)))
  67.  
  68. print()
  69.  
  70.  
  71. print('total mean = ', np.array([coin[0] for coin in total]).mean())
  72. print('1h mean = ', np.array([coin[0] for coin in before_1h]).mean())
  73. print('1h+ mean = ', np.array([coin[0] for coin in after_1h]).mean())
  74. print()
  75. print('1h trades sum = ', np.array([coin[1] for coin in before_1h]).mean())
  76. print()
  77. print('total time delta mean = ', np.array([coin[2] for coin in total]).mean())
  78. print('1h time delta mean = ', np.array([coin[2] for coin in before_1h]).mean())
  79. print('1h+ time delta mean = ', np.array([coin[2] for coin in after_1h]).mean())
  80.  
  81. import numpy as np
  82. import matplotlib.pyplot as plt
  83.  
  84. plt.scatter(np.array([coin[2] for coin in after_1h]), 7 * [0], alpha=0.7, color='g')
  85. plt.title('after 1h cutted mean interval between trades')
  86. plt.xlim([0, 40])
  87. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement