Advertisement
den4ik2003

Untitled

Apr 16th, 2024
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. paths = [
  2. '/mnt/ico_data/gateio/CHAT-USDT-2024-04-10-09-08-38_DEPTH.log',
  3. '/mnt/ico_data/gateio/EVERY-USDT-2024-04-05-10-01-48_DEPTH.log',
  4. '/mnt/ico_data/gateio/MP-USDT-2024-04-08-09-23-26_DEPTH.log',
  5. '/mnt/ico_data/gateio/XAR-USDT-2024-04-03-09-59-44_DEPTH.log',
  6. '/mnt/ico_data/gateio/FAKEAI-USDT-2024-04-03-13-07-42_DEPTH.log'
  7. '/mnt/ico_data/gateio/ESE-USDT-2024-04-11-09-59-36_DEPTH.log',
  8. '/mnt/ico_data/gateio/MASA-USDT-2024-04-11-08-05-17_DEPTH.log',
  9. ]
  10.  
  11. total = []
  12. before_1h = []
  13. after_1h = []
  14.  
  15. for path_to_log in paths:
  16. with open(path_to_log) as file:
  17. orderbook_asks, orderbook_bids = [], []
  18.  
  19. row = file.readline()
  20. while row:
  21. d = json.loads(row)
  22. for ask in d['asks']:
  23. ask_lvl = {}
  24. ask_lvl['price'], ask_lvl['size'] = float(ask[0]), float(ask[1])
  25. ask_lvl['quote_size'] = ask_lvl['price'] * ask_lvl['size']
  26. ask_lvl['type'] = 'ask'
  27. ask_lvl['time'] = d['t']
  28. orderbook_asks.append(ask_lvl)
  29.  
  30. for bid in d['bids']:
  31. bid_lvl = {}
  32. bid_lvl['price'], bid_lvl['size'] = float(bid[0]), float(bid[1])
  33. bid_lvl['quote_size'] = bid_lvl['price'] * bid_lvl['size']
  34. bid_lvl['type'] = 'bid'
  35. bid_lvl['time'] = d['t']
  36. orderbook_bids.append(bid_lvl)
  37.  
  38. row = file.readline()
  39.  
  40. df_asks = pd.DataFrame(orderbook_asks)
  41. df_bids = pd.DataFrame(orderbook_bids)
  42.  
  43. df_asks['time'] = pd.to_datetime(df_asks['time']*1e6)
  44. df_bids['time'] = pd.to_datetime(df_bids['time']*1e6)
  45.  
  46. df_asks = df_asks.groupby(by='time').sum().reset_index()[['time', 'quote_size']]
  47. df_bids = df_bids.groupby(by='time').sum().reset_index()[['time', 'quote_size']]
  48.  
  49. df = pd.DataFrame()
  50. df['time'] = df_asks['time']
  51. df['quote_size'] = df_asks['quote_size'] + df_bids['quote_size']
  52. df['delta'] = (df['time'].shift(-1) - df['time']).dt.total_seconds()
  53.  
  54.  
  55. print(path_to_log.split('/')[4].split('-')[0] + path_to_log.split('/')[4].split('-')[1])
  56. print('-------------------------')
  57. print('depths data time (hours) = ', np.round((np.max(df['time']) - np.min(df['time'])).total_seconds() / 3600, 1))
  58.  
  59. ob_before_1h = df[df['time'] <= np.min(df['time']) + datetime.timedelta(hours=1)]
  60. ob_after_1h = df[df['time'] > np.min(df['time']) + datetime.timedelta(hours=1)]
  61.  
  62. size_mean = np.round((df['quote_size']).mean(), 2)
  63. total.append(size_mean)
  64. print('all time orderbook size mean', size_mean)
  65.  
  66. size_mean = np.round((ob_before_1h['quote_size']).mean(), 2)
  67. time_mean = np.round(ob_before_1h['delta'].mean(), 3)
  68. before_1h.append((size_mean, time_mean))
  69. print('1 hour orderbook size mean', size_mean)
  70. print('1h order book change time mean', time_mean)
  71.  
  72. size_mean = np.round((ob_after_1h['quote_size']).mean(), 2)
  73. time_mean = np.round(ob_after_1h['delta'].mean(), 3)
  74. after_1h.append((size_mean, time_mean))
  75. print('after 1 hour orderbook size mean', size_mean)
  76. print('after 1h order book change time mean', time_mean)
  77.  
  78. print()
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement