Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- paths = [
- '/mnt/ico_data/gateio/CHAT-USDT-2024-04-10-09-08-38_DEPTH.log',
- '/mnt/ico_data/gateio/EVERY-USDT-2024-04-05-10-01-48_DEPTH.log',
- '/mnt/ico_data/gateio/MP-USDT-2024-04-08-09-23-26_DEPTH.log',
- '/mnt/ico_data/gateio/XAR-USDT-2024-04-03-09-59-44_DEPTH.log',
- '/mnt/ico_data/gateio/FAKEAI-USDT-2024-04-03-13-07-42_DEPTH.log'
- '/mnt/ico_data/gateio/ESE-USDT-2024-04-11-09-59-36_DEPTH.log',
- '/mnt/ico_data/gateio/MASA-USDT-2024-04-11-08-05-17_DEPTH.log',
- ]
- total = []
- before_1h = []
- after_1h = []
- for path_to_log in paths:
- with open(path_to_log) as file:
- orderbook_asks, orderbook_bids = [], []
- row = file.readline()
- while row:
- d = json.loads(row)
- for ask in d['asks']:
- ask_lvl = {}
- ask_lvl['price'], ask_lvl['size'] = float(ask[0]), float(ask[1])
- ask_lvl['quote_size'] = ask_lvl['price'] * ask_lvl['size']
- ask_lvl['type'] = 'ask'
- ask_lvl['time'] = d['t']
- orderbook_asks.append(ask_lvl)
- for bid in d['bids']:
- bid_lvl = {}
- bid_lvl['price'], bid_lvl['size'] = float(bid[0]), float(bid[1])
- bid_lvl['quote_size'] = bid_lvl['price'] * bid_lvl['size']
- bid_lvl['type'] = 'bid'
- bid_lvl['time'] = d['t']
- orderbook_bids.append(bid_lvl)
- row = file.readline()
- df_asks = pd.DataFrame(orderbook_asks)
- df_bids = pd.DataFrame(orderbook_bids)
- df_asks['time'] = pd.to_datetime(df_asks['time']*1e6)
- df_bids['time'] = pd.to_datetime(df_bids['time']*1e6)
- df_asks = df_asks.groupby(by='time').sum().reset_index()[['time', 'quote_size']]
- df_bids = df_bids.groupby(by='time').sum().reset_index()[['time', 'quote_size']]
- df = pd.DataFrame()
- df['time'] = df_asks['time']
- df['quote_size'] = df_asks['quote_size'] + df_bids['quote_size']
- df['delta'] = (df['time'].shift(-1) - df['time']).dt.total_seconds()
- print(path_to_log.split('/')[4].split('-')[0] + path_to_log.split('/')[4].split('-')[1])
- print('-------------------------')
- print('depths data time (hours) = ', np.round((np.max(df['time']) - np.min(df['time'])).total_seconds() / 3600, 1))
- ob_before_1h = df[df['time'] <= np.min(df['time']) + datetime.timedelta(hours=1)]
- ob_after_1h = df[df['time'] > np.min(df['time']) + datetime.timedelta(hours=1)]
- size_mean = np.round((df['quote_size']).mean(), 2)
- total.append(size_mean)
- print('all time orderbook size mean', size_mean)
- size_mean = np.round((ob_before_1h['quote_size']).mean(), 2)
- time_mean = np.round(ob_before_1h['delta'].mean(), 3)
- before_1h.append((size_mean, time_mean))
- print('1 hour orderbook size mean', size_mean)
- print('1h order book change time mean', time_mean)
- size_mean = np.round((ob_after_1h['quote_size']).mean(), 2)
- time_mean = np.round(ob_after_1h['delta'].mean(), 3)
- after_1h.append((size_mean, time_mean))
- print('after 1 hour orderbook size mean', size_mean)
- print('after 1h order book change time mean', time_mean)
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement