Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/amb 415 exchange from compressed files #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion marketdata/spot-trade/coalesce-daily/coalesce.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ echo " Runtime: ${runtime}"; echo "";

####################################################################################

# Fix some files format

find "$DATA_DIR" ! -name '*\.gz' -type f -exec sed -i 's/}{/}\n{/g' {} +

####################################################################################

echo " COALESCING FILES..."

start=`date +%s.%N`
Expand Down Expand Up @@ -129,4 +135,4 @@ runtime=$( echo "$end - $start" | bc -l )

echo " Runtime: ${runtime}"; echo "";

####################################################################################
####################################################################################
13 changes: 13 additions & 0 deletions marketdata/spot-trade/coalesce-daily/coalesce_trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@
import json
import gzip
import time
import re


def is_csv_gzip(_file_path):
return _file_path.endswith("csv.gz")


def add_exchange(file_path):
try:
matches = list(re.finditer(r"((?:.(?!\/))+$)", file_path))
file_name = matches[0].group()
return re.match(r"\/(.*?)(?:(?:-[0-9]+)|(?:@))", file_name).group(1)
except Exception as e:
print(f"file: {file_path}", file=sys.stderr)


def convert_line_from_csv_gz(_line, file_path):
[timestamp, timestampNanoseconds, tradeId, price, size, isBuySide] = _line.decode('UTF-8').strip().split(',')
return {
"exchange": add_exchange(file_path),
"timestamp": int(timestamp),
"timestampNanoseconds": int(timestampNanoseconds),
"tradeId": int(tradeId),
Expand Down