Skip to content

Commit

Permalink
Fix request tickdata realtime exception (#96)
Browse files Browse the repository at this point in the history
* Fix broken example.

* Change bid ask sizes in bid ask ticks to floats.
  • Loading branch information
chipkent authored Sep 27, 2022
1 parent cc77c4d commit b5c547f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
17 changes: 9 additions & 8 deletions examples/example_all_functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,23 @@ def get_contracts() -> Dict[str, Contract]:
contract.secType = "FUT"
contract.exchange = "GLOBEX"
contract.currency = "USD"
contract.lastTradeDateOrContractMonth = "202209"
contract.lastTradeDateOrContractMonth = "202212"
rst["future_1"] = contract

# find more contracts at https://www.cmegroup.com/markets/equities/sp/e-mini-sandp500.quotes.html
contract = Contract()
contract.secType = "FUT"
contract.exchange = "GLOBEX"
contract.currency = "USD"
contract.localSymbol = "MESU2"
contract.localSymbol = "ESZ2"
rst["future_2"] = contract

contract = Contract()
contract.symbol = "DAX"
contract.secType = "FUT"
contract.exchange = "EUREX"
contract.currency = "EUR"
contract.lastTradeDateOrContractMonth = "202209"
contract.lastTradeDateOrContractMonth = "202212"
contract.multiplier = "1"
rst["future_3"] = contract

Expand Down Expand Up @@ -357,8 +358,8 @@ def get_contracts() -> Dict[str, Contract]:
bar_type=dhib.BarDataType.ASK)
client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
bar_type=dhib.BarDataType.BID_ASK, keep_up_to_date=False)
client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
bar_type=dhib.BarDataType.AGGTRADES)
# client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
# bar_type=dhib.BarDataType.AGGTRADES)
client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
bar_type=dhib.BarDataType.ADJUSTED_LAST, keep_up_to_date=False)

Expand Down Expand Up @@ -482,7 +483,7 @@ def get_contracts() -> Dict[str, Contract]:
order.action = "BUY"
order.orderType = "LIMIT"
order.totalQuantity = 1
order.lmtPrice = 3000
order.lmtPrice = 100

print("Placing order: START")
client.order_place(rc, order)
Expand All @@ -493,7 +494,7 @@ def get_contracts() -> Dict[str, Contract]:
order.action = "BUY"
order.orderType = "LIMIT"
order.totalQuantity = 1
order.lmtPrice = 2600
order.lmtPrice = 90

print("Placing order: START")
client.order_place(rc, order)
Expand All @@ -504,7 +505,7 @@ def get_contracts() -> Dict[str, Contract]:
order.action = "BUY"
order.orderType = "LIMIT"
order.totalQuantity = 1
order.lmtPrice = 2700
order.lmtPrice = 91

print("Placing order: START")
req = client.order_place(rc, order)
Expand Down
17 changes: 9 additions & 8 deletions examples/example_read_only_functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,23 @@ def get_contracts() -> Dict[str, Contract]:
contract.secType = "FUT"
contract.exchange = "GLOBEX"
contract.currency = "USD"
contract.lastTradeDateOrContractMonth = "202209"
contract.lastTradeDateOrContractMonth = "202212"
rst["future_1"] = contract

# find more contracts at https://www.cmegroup.com/markets/equities/sp/e-mini-sandp500.quotes.html
contract = Contract()
contract.secType = "FUT"
contract.exchange = "GLOBEX"
contract.currency = "USD"
contract.localSymbol = "MESU2"
contract.localSymbol = "ESZ2"
rst["future_2"] = contract

contract = Contract()
contract.symbol = "DAX"
contract.secType = "FUT"
contract.exchange = "EUREX"
contract.currency = "EUR"
contract.lastTradeDateOrContractMonth = "202209"
contract.lastTradeDateOrContractMonth = "202212"
contract.multiplier = "1"
rst["future_3"] = contract

Expand Down Expand Up @@ -353,8 +354,8 @@ def get_contracts() -> Dict[str, Contract]:
bar_type=dhib.BarDataType.ASK)
client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
bar_type=dhib.BarDataType.BID_ASK, keep_up_to_date=False)
client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
bar_type=dhib.BarDataType.AGGTRADES)
# client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
# bar_type=dhib.BarDataType.AGGTRADES)
client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
bar_type=dhib.BarDataType.ADJUSTED_LAST, keep_up_to_date=False)

Expand Down Expand Up @@ -478,7 +479,7 @@ def get_contracts() -> Dict[str, Contract]:
order.action = "BUY"
order.orderType = "LIMIT"
order.totalQuantity = 1
order.lmtPrice = 3000
order.lmtPrice = 100

print("Placing order -- confirm fail: START")
try:
Expand All @@ -495,7 +496,7 @@ def get_contracts() -> Dict[str, Contract]:
order.action = "BUY"
order.orderType = "LIMIT"
order.totalQuantity = 1
order.lmtPrice = 2600
order.lmtPrice = 90

print("Placing order -- confirm fail: START")
try:
Expand All @@ -512,7 +513,7 @@ def get_contracts() -> Dict[str, Contract]:
order.action = "BUY"
order.orderType = "LIMIT"
order.totalQuantity = 1
order.lmtPrice = 2700
order.lmtPrice = 91

print("Placing order -- confirm fail: START")
try:
Expand Down
4 changes: 2 additions & 2 deletions src/deephaven_ib/_tws/ib_type_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ def _details_historical_tick_bid_ask() -> List[Tuple]:
("Timestamp", dtypes.DateTime, lambda t: unix_sec_to_dh_datetime(t.time)),
("BidPrice", dtypes.float64, lambda t: t.priceBid),
("AskPrice", dtypes.float64, lambda t: t.priceAsk),
("BidSize", dtypes.int64, lambda t: t.sizeBid),
("AskSize", dtypes.int64, lambda t: t.sizeAsk),
("BidSize", dtypes.float64, lambda t: t.sizeBid),
("AskSize", dtypes.float64, lambda t: t.sizeAsk),
*_include_details(_details_tick_attrib_bid_ask(), lambda t: t.tickAttribBidAsk),
]

Expand Down

0 comments on commit b5c547f

Please sign in to comment.