diff --git a/docker/dev/build.sh b/docker/dev/build.sh index 8711c2e9..e0402c59 100755 --- a/docker/dev/build.sh +++ b/docker/dev/build.sh @@ -9,6 +9,7 @@ cd ${__dir} rm -rf build mkdir build rsync -av ../.. build --exclude docker +rm -rf build/dist docker build --build-arg IB_VERSION=1016.01 -t deephaven-examples/deephaven-ib:dev -f Dockerfile . diff --git a/examples/example_all_functionality.py b/examples/example_all_functionality.py index 199ca82b..34f6bd44 100644 --- a/examples/example_all_functionality.py +++ b/examples/example_all_functionality.py @@ -341,13 +341,13 @@ def get_contracts() -> Dict[str, Contract]: contract.exchange = "PAXOS" contract.currency = "USD" -rc = client.get_registered_contract(c2) -client.request_bars_historical(rc2, duration=dhib.Duration.days(253), +rc = client.get_registered_contract(contract) +client.request_bars_historical(rc, duration=dhib.Duration.days(253), bar_size=dhib.BarSize.DAY_1, bar_type=dhib.BarDataType.AGGTRADES, keep_up_to_date = False ) -client.request_bars_realtime(rc2, bar_type=dhib.BarDataType.TRADES) +client.request_bars_realtime(rc, bar_type=dhib.BarDataType.TRADES) client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5, bar_type=dhib.BarDataType.MIDPOINT) @@ -483,8 +483,6 @@ def get_contracts() -> Dict[str, Contract]: order.orderType = "LIMIT" order.totalQuantity = 1 order.lmtPrice = 3000 -order.eTradeOnly = False -order.firmQuoteOnly = False print("Placing order: START") client.order_place(rc, order) @@ -496,8 +494,6 @@ def get_contracts() -> Dict[str, Contract]: order.orderType = "LIMIT" order.totalQuantity = 1 order.lmtPrice = 2600 -order.eTradeOnly = False -order.firmQuoteOnly = False print("Placing order: START") client.order_place(rc, order) @@ -509,8 +505,6 @@ def get_contracts() -> Dict[str, Contract]: order.orderType = "LIMIT" order.totalQuantity = 1 order.lmtPrice = 2700 -order.eTradeOnly = False -order.firmQuoteOnly = False print("Placing order: START") req = client.order_place(rc, order) diff --git a/examples/example_beta_calc.py b/examples/example_beta_calc.py index 9b7d8b1e..b7f80bdc 100644 --- a/examples/example_beta_calc.py +++ b/examples/example_beta_calc.py @@ -256,8 +256,6 @@ def check_table_size(dh_table, table_name, expected_size=1): order.orderType = "LIMIT" order.totalQuantity = hedge_qty order.lmtPrice = hedge_limit_px -order.eTradeOnly = False -order.firmQuoteOnly = False print('Order: ' + str(order)) diff --git a/examples/example_read_only_functionality.py b/examples/example_read_only_functionality.py index c9863a00..4fd31eb6 100644 --- a/examples/example_read_only_functionality.py +++ b/examples/example_read_only_functionality.py @@ -337,13 +337,13 @@ def get_contracts() -> Dict[str, Contract]: contract.exchange = "PAXOS" contract.currency = "USD" -rc = client.get_registered_contract(c2) -client.request_bars_historical(rc2, duration=dhib.Duration.days(253), +rc = client.get_registered_contract(contract) +client.request_bars_historical(rc, duration=dhib.Duration.days(253), bar_size=dhib.BarSize.DAY_1, bar_type=dhib.BarDataType.AGGTRADES, keep_up_to_date = False ) -client.request_bars_realtime(rc2, bar_type=dhib.BarDataType.TRADES) +client.request_bars_realtime(rc, bar_type=dhib.BarDataType.TRADES) client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5, bar_type=dhib.BarDataType.MIDPOINT) @@ -479,8 +479,6 @@ def get_contracts() -> Dict[str, Contract]: order.orderType = "LIMIT" order.totalQuantity = 1 order.lmtPrice = 3000 -order.eTradeOnly = False -order.firmQuoteOnly = False print("Placing order -- confirm fail: START") try: @@ -498,8 +496,6 @@ def get_contracts() -> Dict[str, Contract]: order.orderType = "LIMIT" order.totalQuantity = 1 order.lmtPrice = 2600 -order.eTradeOnly = False -order.firmQuoteOnly = False print("Placing order -- confirm fail: START") try: @@ -517,8 +513,6 @@ def get_contracts() -> Dict[str, Contract]: order.orderType = "LIMIT" order.totalQuantity = 1 order.lmtPrice = 2700 -order.eTradeOnly = False -order.firmQuoteOnly = False print("Placing order -- confirm fail: START") try: diff --git a/src/deephaven_ib/__init__.py b/src/deephaven_ib/__init__.py index 37c5590f..24e53b57 100644 --- a/src/deephaven_ib/__init__.py +++ b/src/deephaven_ib/__init__.py @@ -1,5 +1,6 @@ from enum import Enum -from typing import Dict, List, Callable +from typing import Dict, List, Callable, Optional +import json from deephaven.table import Table from deephaven.dtypes import DateTime @@ -546,7 +547,7 @@ def annotate_ticks(t): return rst - def deephaven_ib_float_value(s: str) -> Union[float, None]: + def deephaven_ib_float_value(s: str) -> Optional[float]: if not s: return NULL_DOUBLE @@ -555,7 +556,7 @@ def deephaven_ib_float_value(s: str) -> Union[float, None]: except ValueError: return NULL_DOUBLE - def deephaven_ib_parse_note(note:str, key:str) -> Union[str,None]: + def deephaven_ib_parse_note(note:str, key:str) -> Optional[str]: dict = json.loads(note) if key in dict: diff --git a/src/deephaven_ib/_internal/tablewriter.py b/src/deephaven_ib/_internal/tablewriter.py index c63ef4dc..b340df3b 100644 --- a/src/deephaven_ib/_internal/tablewriter.py +++ b/src/deephaven_ib/_internal/tablewriter.py @@ -1,7 +1,7 @@ """Functionality for creating Deephaven tables.""" import logging -from typing import List, Any, Sequence, Union, Set +from typing import List, Any, Sequence, Optional, Set import collections from deephaven.time import now @@ -114,7 +114,7 @@ def map_values(value, map, default=lambda v: f"UNKNOWN({v})") -> Any: return default(value) -def to_string_val(value) -> Union[str, None]: +def to_string_val(value) -> Optional[str]: """ Converts a value to a string. """ if value is None: @@ -123,7 +123,7 @@ def to_string_val(value) -> Union[str, None]: return str(value) -def to_string_set(value: Sequence) -> Union[ArrayStringSet, None]: +def to_string_set(value: Sequence) -> Optional[ArrayStringSet]: """ Converts an iterable to a string set. """ if value is None: diff --git a/src/deephaven_ib/_tws/ib_type_logger.py b/src/deephaven_ib/_tws/ib_type_logger.py index 40d24892..0eed72f3 100644 --- a/src/deephaven_ib/_tws/ib_type_logger.py +++ b/src/deephaven_ib/_tws/ib_type_logger.py @@ -1,7 +1,7 @@ """Functionality for logging IB types to Deephaven tables.""" import sys -from typing import Any, List, Tuple, Dict, Callable, Union +from typing import Any, List, Tuple, Dict, Callable, Optional from deephaven import dtypes @@ -73,7 +73,7 @@ def _details_family_code() -> List[Tuple]: def _details_contract() -> List[Tuple]: """ Details for logging Contract. """ - def map_right(right: str) -> Union[str, None]: + def map_right(right: str) -> Optional[str]: if right == "?": return None @@ -110,7 +110,7 @@ def map_right(right: str) -> Union[str, None]: def _details_contract_details() -> List[Tuple]: """Details for logging ContractDetails.""" - def map_null_int(value: int) -> Union[int, None]: + def map_null_int(value: int) -> Optional[int]: if value == 2147483647: return None @@ -445,9 +445,6 @@ def _details_order() -> List[Tuple]: # SMART routing only ("DiscretionaryAmt", dtypes.float64, lambda o: o.discretionaryAmt), - ("ETradeOnly", dtypes.bool_, lambda o: o.eTradeOnly), - ("FirmQuoteOnly", dtypes.bool_, lambda o: o.firmQuoteOnly), - ("NbboPriceCap", dtypes.float64, lambda o: o.nbboPriceCap), ("OptOutSmarRouting", dtypes.bool_, lambda o: o.optOutSmartRouting), # BOX exchange orders only @@ -650,7 +647,7 @@ def _details_execution() -> List[Tuple]: def _details_commission_report() -> List[Tuple]: """ Details for logging CommissionReport. """ - def format_yield_redemption_date(date: int) -> Union[str, None]: + def format_yield_redemption_date(date: int) -> Optional[str]: if date == 0: return None @@ -660,7 +657,7 @@ def format_yield_redemption_date(date: int) -> Union[str, None]: y = int(date / 10000) return f"{y:04}-{m:02}-{d:02}" - def map_null_value(value: float) -> Union[float, None]: + def map_null_value(value: float) -> Optional[float]: if value == sys.float_info.max: return None diff --git a/src/deephaven_ib/_tws/tws_client.py b/src/deephaven_ib/_tws/tws_client.py index 3d439230..e779f11c 100644 --- a/src/deephaven_ib/_tws/tws_client.py +++ b/src/deephaven_ib/_tws/tws_client.py @@ -9,7 +9,7 @@ import xml.etree.ElementTree as ET from functools import wraps from threading import Thread -from typing import Set +from typing import Set, Optional import decimal from decimal import Decimal @@ -392,8 +392,8 @@ def _subscribe(self) -> None: #################################################################################################################### #################################################################################################################### - def log_request(self, req_id: int, request_type: str, contract: Union[Contract, None], - notes: Union[Dict[str, Any], None]): + def log_request(self, req_id: int, request_type: str, contract: Optional[Contract], + notes: Optional[Dict[str, Any]]): """Log a data request.""" if notes is None: diff --git a/src/deephaven_ib/time.py b/src/deephaven_ib/time.py index c1a0ba93..037f0300 100644 --- a/src/deephaven_ib/time.py +++ b/src/deephaven_ib/time.py @@ -5,6 +5,7 @@ from deephaven.dtypes import DateTime _SimpleDateFormat = jpy.get_type("java.text.SimpleDateFormat") +_TimeZone = jpy.get_type("java.util.TimeZone") _ib_date_time_pattern_sec = "yyyyMMdd HH:mm:ss" _ib_date_time_pattern_subsec = "yyyyMMdd HH:mm:ss.S" @@ -15,9 +16,13 @@ "yyyy-MM-dd HH:mm:ss", ] _ib_date_time_formatter_sec = _SimpleDateFormat(_ib_date_time_pattern_sec) +_ib_date_time_formatter_sec.setTimeZone(_TimeZone.getTimeZone("US/Eastern")) _ib_date_time_formatter_subsec = _SimpleDateFormat(_ib_date_time_pattern_subsec) +_ib_date_time_formatter_subsec.setTimeZone(_TimeZone.getTimeZone("US/Eastern")) _ib_date_time_formatters = [_SimpleDateFormat(pattern) for pattern in _ib_date_time_patterns] +for _f in _ib_date_time_formatters: + _f.setTimeZone(_TimeZone.getTimeZone("US/Eastern")) def dh_to_ib_datetime(time: DateTime, sub_sec: bool = True) -> str: """Convert a DH DateTime to an IB timestamp string. @@ -31,9 +36,9 @@ def dh_to_ib_datetime(time: DateTime, sub_sec: bool = True) -> str: return "" if sub_sec: - return _ib_date_time_formatter_subsec.format(time.getDate()) + return _ib_date_time_formatter_subsec.format(time.getDate()) + " US/Eastern" else: - return _ib_date_time_formatter_sec.format(time.getDate()) + return _ib_date_time_formatter_sec.format(time.getDate()) + " US/Eastern" def ib_to_dh_datetime(time: str) -> DateTime: