Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def parse_events(path_to_logs):
- list_of_events_dicts = []
- count_of_decode_errors = 0
- with open(path_to_logs, 'r') as logs:
- rows = logs.readlines()
- for i in range(len(rows)):
- if re.search('Account order event', rows[i]):
- if i + 1 < len(rows):
- try:
- event = json.loads(re.sub(r'(LIMIT_MAKER")', r'\1,', rows[i+1][1:].strip()))
- if type(event) is dict:
- list_of_events_dicts.append(event)
- except json.JSONDecodeError:
- count_of_decode_errors += 1
- return (list_of_events_dicts, count_of_decode_errors)
- def create_events_csv(path_to_logs, name='mm_events.csv'):
- events, errors_count = parse_events(path_to_logs)
- print(f'events rows = {len(events)}; errors count = {errors_count}')
- df = pd.DataFrame(events)
- df.drop(['symbol', 'type', 'is_maker', 'average_price', 'filled_quantity'], axis=1, inplace=True)
- for float_column in ['amount', 'price', 'quantity']:
- df[float_column] = df[float_column].astype(float)
- for str_column in ['status', 'side']:
- df[str_column] = df[str_column].astype('string')
- df['create_time'] = pd.to_datetime(df['create_time'] * 1e6).dt.round('1s')
- df['update_time'] = pd.to_datetime(df['update_time'] * 1e6).dt.round('1s')
- df = df.sort_values('update_time')
- df.to_csv(name, index=False)
- return df
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement