Skip to content

Commit cc77c4d

Browse files
authored
Dh 0 16 release fixes (#94)
* Fix dev docker build. * Add timezones to IB formatted times. * Fix missing imports and Optional annotations. Remove deprecated fields from logs. Fix broken examples. * Fix broken example.
1 parent 379dedb commit cc77c4d

File tree

9 files changed

+29
-39
lines changed

9 files changed

+29
-39
lines changed

docker/dev/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ cd ${__dir}
99
rm -rf build
1010
mkdir build
1111
rsync -av ../.. build --exclude docker
12+
rm -rf build/dist
1213

1314
docker build --build-arg IB_VERSION=1016.01 -t deephaven-examples/deephaven-ib:dev -f Dockerfile .
1415

examples/example_all_functionality.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,13 @@ def get_contracts() -> Dict[str, Contract]:
341341
contract.exchange = "PAXOS"
342342
contract.currency = "USD"
343343

344-
rc = client.get_registered_contract(c2)
345-
client.request_bars_historical(rc2, duration=dhib.Duration.days(253),
344+
rc = client.get_registered_contract(contract)
345+
client.request_bars_historical(rc, duration=dhib.Duration.days(253),
346346
bar_size=dhib.BarSize.DAY_1,
347347
bar_type=dhib.BarDataType.AGGTRADES,
348348
keep_up_to_date = False
349349
)
350-
client.request_bars_realtime(rc2, bar_type=dhib.BarDataType.TRADES)
350+
client.request_bars_realtime(rc, bar_type=dhib.BarDataType.TRADES)
351351

352352
client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
353353
bar_type=dhib.BarDataType.MIDPOINT)
@@ -483,8 +483,6 @@ def get_contracts() -> Dict[str, Contract]:
483483
order.orderType = "LIMIT"
484484
order.totalQuantity = 1
485485
order.lmtPrice = 3000
486-
order.eTradeOnly = False
487-
order.firmQuoteOnly = False
488486

489487
print("Placing order: START")
490488
client.order_place(rc, order)
@@ -496,8 +494,6 @@ def get_contracts() -> Dict[str, Contract]:
496494
order.orderType = "LIMIT"
497495
order.totalQuantity = 1
498496
order.lmtPrice = 2600
499-
order.eTradeOnly = False
500-
order.firmQuoteOnly = False
501497

502498
print("Placing order: START")
503499
client.order_place(rc, order)
@@ -509,8 +505,6 @@ def get_contracts() -> Dict[str, Contract]:
509505
order.orderType = "LIMIT"
510506
order.totalQuantity = 1
511507
order.lmtPrice = 2700
512-
order.eTradeOnly = False
513-
order.firmQuoteOnly = False
514508

515509
print("Placing order: START")
516510
req = client.order_place(rc, order)

examples/example_beta_calc.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,6 @@ def check_table_size(dh_table, table_name, expected_size=1):
256256
order.orderType = "LIMIT"
257257
order.totalQuantity = hedge_qty
258258
order.lmtPrice = hedge_limit_px
259-
order.eTradeOnly = False
260-
order.firmQuoteOnly = False
261259

262260
print('Order: ' + str(order))
263261

examples/example_read_only_functionality.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,13 @@ def get_contracts() -> Dict[str, Contract]:
337337
contract.exchange = "PAXOS"
338338
contract.currency = "USD"
339339

340-
rc = client.get_registered_contract(c2)
341-
client.request_bars_historical(rc2, duration=dhib.Duration.days(253),
340+
rc = client.get_registered_contract(contract)
341+
client.request_bars_historical(rc, duration=dhib.Duration.days(253),
342342
bar_size=dhib.BarSize.DAY_1,
343343
bar_type=dhib.BarDataType.AGGTRADES,
344344
keep_up_to_date = False
345345
)
346-
client.request_bars_realtime(rc2, bar_type=dhib.BarDataType.TRADES)
346+
client.request_bars_realtime(rc, bar_type=dhib.BarDataType.TRADES)
347347

348348
client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
349349
bar_type=dhib.BarDataType.MIDPOINT)
@@ -479,8 +479,6 @@ def get_contracts() -> Dict[str, Contract]:
479479
order.orderType = "LIMIT"
480480
order.totalQuantity = 1
481481
order.lmtPrice = 3000
482-
order.eTradeOnly = False
483-
order.firmQuoteOnly = False
484482

485483
print("Placing order -- confirm fail: START")
486484
try:
@@ -498,8 +496,6 @@ def get_contracts() -> Dict[str, Contract]:
498496
order.orderType = "LIMIT"
499497
order.totalQuantity = 1
500498
order.lmtPrice = 2600
501-
order.eTradeOnly = False
502-
order.firmQuoteOnly = False
503499

504500
print("Placing order -- confirm fail: START")
505501
try:
@@ -517,8 +513,6 @@ def get_contracts() -> Dict[str, Contract]:
517513
order.orderType = "LIMIT"
518514
order.totalQuantity = 1
519515
order.lmtPrice = 2700
520-
order.eTradeOnly = False
521-
order.firmQuoteOnly = False
522516

523517
print("Placing order -- confirm fail: START")
524518
try:

src/deephaven_ib/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from enum import Enum
2-
from typing import Dict, List, Callable
2+
from typing import Dict, List, Callable, Optional
3+
import json
34

45
from deephaven.table import Table
56
from deephaven.dtypes import DateTime
@@ -546,7 +547,7 @@ def annotate_ticks(t):
546547

547548
return rst
548549

549-
def deephaven_ib_float_value(s: str) -> Union[float, None]:
550+
def deephaven_ib_float_value(s: str) -> Optional[float]:
550551
if not s:
551552
return NULL_DOUBLE
552553

@@ -555,7 +556,7 @@ def deephaven_ib_float_value(s: str) -> Union[float, None]:
555556
except ValueError:
556557
return NULL_DOUBLE
557558

558-
def deephaven_ib_parse_note(note:str, key:str) -> Union[str,None]:
559+
def deephaven_ib_parse_note(note:str, key:str) -> Optional[str]:
559560
dict = json.loads(note)
560561

561562
if key in dict:

src/deephaven_ib/_internal/tablewriter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Functionality for creating Deephaven tables."""
22

33
import logging
4-
from typing import List, Any, Sequence, Union, Set
4+
from typing import List, Any, Sequence, Optional, Set
55
import collections
66

77
from deephaven.time import now
@@ -114,7 +114,7 @@ def map_values(value, map, default=lambda v: f"UNKNOWN({v})") -> Any:
114114
return default(value)
115115

116116

117-
def to_string_val(value) -> Union[str, None]:
117+
def to_string_val(value) -> Optional[str]:
118118
""" Converts a value to a string. """
119119

120120
if value is None:
@@ -123,7 +123,7 @@ def to_string_val(value) -> Union[str, None]:
123123
return str(value)
124124

125125

126-
def to_string_set(value: Sequence) -> Union[ArrayStringSet, None]:
126+
def to_string_set(value: Sequence) -> Optional[ArrayStringSet]:
127127
""" Converts an iterable to a string set. """
128128

129129
if value is None:

src/deephaven_ib/_tws/ib_type_logger.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Functionality for logging IB types to Deephaven tables."""
22

33
import sys
4-
from typing import Any, List, Tuple, Dict, Callable, Union
4+
from typing import Any, List, Tuple, Dict, Callable, Optional
55

66
from deephaven import dtypes
77

@@ -73,7 +73,7 @@ def _details_family_code() -> List[Tuple]:
7373
def _details_contract() -> List[Tuple]:
7474
""" Details for logging Contract. """
7575

76-
def map_right(right: str) -> Union[str, None]:
76+
def map_right(right: str) -> Optional[str]:
7777
if right == "?":
7878
return None
7979

@@ -110,7 +110,7 @@ def map_right(right: str) -> Union[str, None]:
110110
def _details_contract_details() -> List[Tuple]:
111111
"""Details for logging ContractDetails."""
112112

113-
def map_null_int(value: int) -> Union[int, None]:
113+
def map_null_int(value: int) -> Optional[int]:
114114

115115
if value == 2147483647:
116116
return None
@@ -445,9 +445,6 @@ def _details_order() -> List[Tuple]:
445445

446446
# SMART routing only
447447
("DiscretionaryAmt", dtypes.float64, lambda o: o.discretionaryAmt),
448-
("ETradeOnly", dtypes.bool_, lambda o: o.eTradeOnly),
449-
("FirmQuoteOnly", dtypes.bool_, lambda o: o.firmQuoteOnly),
450-
("NbboPriceCap", dtypes.float64, lambda o: o.nbboPriceCap),
451448
("OptOutSmarRouting", dtypes.bool_, lambda o: o.optOutSmartRouting),
452449

453450
# BOX exchange orders only
@@ -650,7 +647,7 @@ def _details_execution() -> List[Tuple]:
650647
def _details_commission_report() -> List[Tuple]:
651648
""" Details for logging CommissionReport. """
652649

653-
def format_yield_redemption_date(date: int) -> Union[str, None]:
650+
def format_yield_redemption_date(date: int) -> Optional[str]:
654651
if date == 0:
655652
return None
656653

@@ -660,7 +657,7 @@ def format_yield_redemption_date(date: int) -> Union[str, None]:
660657
y = int(date / 10000)
661658
return f"{y:04}-{m:02}-{d:02}"
662659

663-
def map_null_value(value: float) -> Union[float, None]:
660+
def map_null_value(value: float) -> Optional[float]:
664661

665662
if value == sys.float_info.max:
666663
return None

src/deephaven_ib/_tws/tws_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import xml.etree.ElementTree as ET
1010
from functools import wraps
1111
from threading import Thread
12-
from typing import Set
12+
from typing import Set, Optional
1313

1414
import decimal
1515
from decimal import Decimal
@@ -392,8 +392,8 @@ def _subscribe(self) -> None:
392392
####################################################################################################################
393393
####################################################################################################################
394394

395-
def log_request(self, req_id: int, request_type: str, contract: Union[Contract, None],
396-
notes: Union[Dict[str, Any], None]):
395+
def log_request(self, req_id: int, request_type: str, contract: Optional[Contract],
396+
notes: Optional[Dict[str, Any]]):
397397
"""Log a data request."""
398398

399399
if notes is None:

src/deephaven_ib/time.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from deephaven.dtypes import DateTime
66

77
_SimpleDateFormat = jpy.get_type("java.text.SimpleDateFormat")
8+
_TimeZone = jpy.get_type("java.util.TimeZone")
89

910
_ib_date_time_pattern_sec = "yyyyMMdd HH:mm:ss"
1011
_ib_date_time_pattern_subsec = "yyyyMMdd HH:mm:ss.S"
@@ -15,9 +16,13 @@
1516
"yyyy-MM-dd HH:mm:ss",
1617
]
1718
_ib_date_time_formatter_sec = _SimpleDateFormat(_ib_date_time_pattern_sec)
19+
_ib_date_time_formatter_sec.setTimeZone(_TimeZone.getTimeZone("US/Eastern"))
1820
_ib_date_time_formatter_subsec = _SimpleDateFormat(_ib_date_time_pattern_subsec)
21+
_ib_date_time_formatter_subsec.setTimeZone(_TimeZone.getTimeZone("US/Eastern"))
1922
_ib_date_time_formatters = [_SimpleDateFormat(pattern) for pattern in _ib_date_time_patterns]
2023

24+
for _f in _ib_date_time_formatters:
25+
_f.setTimeZone(_TimeZone.getTimeZone("US/Eastern"))
2126

2227
def dh_to_ib_datetime(time: DateTime, sub_sec: bool = True) -> str:
2328
"""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:
3136
return ""
3237

3338
if sub_sec:
34-
return _ib_date_time_formatter_subsec.format(time.getDate())
39+
return _ib_date_time_formatter_subsec.format(time.getDate()) + " US/Eastern"
3540
else:
36-
return _ib_date_time_formatter_sec.format(time.getDate())
41+
return _ib_date_time_formatter_sec.format(time.getDate()) + " US/Eastern"
3742

3843

3944
def ib_to_dh_datetime(time: str) -> DateTime:

0 commit comments

Comments
 (0)