Skip to content

Commit

Permalink
Fix historical bar timestamp parsing (#57)
Browse files Browse the repository at this point in the history
* Add a docker command to build images and then launch the system.
* Parse multiple timestamp formats for bars.
* Support new bar sizes.
  • Loading branch information
chipkent authored May 11, 2022
1 parent 74d56eb commit d94df01
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docker/deephaven_ib_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function help() {
echo "------"
echo "build - build Docker images for the system"
echo "up - launch the system"
echo "build_up - build the Docker images for the system and launch the system"
echo "down - shut down the system"
echo "help - print a help message"
echo ""
Expand Down Expand Up @@ -89,6 +90,10 @@ case "$ACTION" in
"up")
up
;;
"build_up")
build
up
;;
"down")
down
;;
Expand Down
18 changes: 18 additions & 0 deletions src/deephaven_ib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ class BarSize(Enum):
"""1 second bar."""
SEC_5 = "5 secs"
"""5 second bar."""
SEC_10 = "10 secs"
"""10 second bar."""
SEC_15 = "15 secs"
"""15 second bar."""
SEC_30 = "30 secs"
Expand All @@ -161,14 +163,30 @@ class BarSize(Enum):
"""3 minute bar."""
MIN_5 = "5 mins"
"5 minute bar."
MIN_10 = "10 mins"
"10 minute bar."
MIN_15 = "15 mins"
"""15 minute bar."""
MIN_20 = "20 mins"
"20 minute bar."
MIN_30 = "30 mins"
"""30 minute bar."""
HOUR_1 = "1 hour"
"""1 hour bar."""
HOUR_2 = "2 hour"
"""2 hour bar."""
HOUR_3 = "3 hour"
"""3 hour bar."""
HOUR_4 = "4 hour"
"""4 hour bar."""
HOUR_8 = "8 hour"
"""8 hour bar."""
DAY_1 = "1 day"
"""1 day bar."""
WEEK_1 = "1W"
"""1 week bar."""
MONTH_1 = "1M"
"""1 month bar."""


class Duration:
Expand Down
14 changes: 13 additions & 1 deletion src/deephaven_ib/_tws/ib_type_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,20 @@ def map_null(val):

return val

def parse_timestamp(bd):
if len(bd.date) is 8:
# bd.date is a date string
year = bd.date[0:4]
month = bd.date[4:6]
day = bd.date[6:]
time_string = f"{year}{month}{day} 23:59:59"
return ib_to_dh_datetime(time_string)
else:
# bd.date is unix sec
return unix_sec_to_dh_datetime(int(bd.date))

return [
("Timestamp", dtypes.DateTime, lambda bd: unix_sec_to_dh_datetime(int(bd.date))),
("Timestamp", dtypes.DateTime, parse_timestamp),
("Open", dtypes.float64, lambda bd: bd.open),
("High", dtypes.float64, lambda bd: bd.high),
("Low", dtypes.float64, lambda bd: bd.low),
Expand Down

0 comments on commit d94df01

Please sign in to comment.