deephaven-examples / deephaven-ib

An Interactive Brokers integration for Deephaven
Apache License 2.0
64 stars 27 forks source link

Exception when canceling orders #97

Closed chipkent closed 2 years ago

chipkent commented 2 years ago

IB broke their API and did not document the change.

from typing import Dict

from deephaven.time import to_datetime
from ibapi.contract import Contract
from ibapi.order import Order

import deephaven_ib as dhib
from deephaven.updateby import ema_time_decay
from deephaven import time_table
from deephaven.plot import Figure

###########################################################################
# WARNING: THIS SCRIPT EXECUTES TRADES!! ONLY USE ON PAPER TRADING ACCOUNTS
###########################################################################

print("==============================================================================================================")
print("==== Create a client and connect.")
print("==== ** Accept the connection in TWS **")
print("==============================================================================================================")

client = dhib.IbSessionTws(host="host.docker.internal", port=7497, client_id=0, download_short_rates=False, read_only=False)
print(f"IsConnected: {client.is_connected()}")

client.connect()
print(f"IsConnected: {client.is_connected()}")

## Setup

account = "DU4943848"
ticks_bid_ask = client.tables["ticks_bid_ask"]
orders_submitted = client.tables["orders_submitted"]
orders_status = client.tables["orders_status"]
positions = client.tables["accounts_positions"].where("Account = account")

print("==============================================================================================================")
print("==== Request data.")
print("==============================================================================================================")

contract = Contract()
contract.symbol = "GOOG"
contract.secType = "STK"
contract.currency = "USD"
contract.exchange = "SMART"

rc = client.get_registered_contract(contract)
id = rc.contract_details[0].contract.conId
print(f"Registered contract: id={id} rc={rc}")

order_sell = Order()
order_sell.account = account
order_sell.action = "SELL"
order_sell.orderType = "LIMIT"
order_sell.totalQuantity = 100
order_sell.lmtPrice = 101

order = client.order_place(rc, order_sell)
order.cancel()
r-Scheduler-Serial-1 | i.d.s.s.SessionState      | Internal Error 'ffda8bbd-3f96-4c13-bc7d-825605890ce5' java.lang.RuntimeException: Error in Python interpreter:
Type: <class 'TypeError'>
Value: cancelOrder() missing 1 required positional argument: 'manualCancelOrderTime'
Line: 1169
Namespace: order_cancel
File: /opt/deephaven-venv/lib/python3.7/site-packages/deephaven_ib/__init__.py
Traceback (most recent call last):
  File "<string>", line 59, in <module>
  File "/opt/deephaven-venv/lib/python3.7/site-packages/deephaven_ib/__init__.py", line 307, in cancel
  File "/opt/deephaven-venv/lib/python3.7/site-packages/deephaven_ib/__init__.py", line 1169, in order_cancel

        at org.jpy.PyLib.executeCode(PyLib.java:-2)
        at org.jpy.PyObject.executeCode(PyObject.java:138)
        at io.deephaven.engine.util.PythonEvaluatorJpy.evalScript(PythonEvaluatorJpy.java:73)
        at io.deephaven.integrations.python.PythonDeephavenSession.lambda$evaluate$1(PythonDeephavenSession.java:185)
        at io.deephaven.util.locks.FunctionalLock.doLockedInterruptibly(FunctionalLock.java:49)
        at io.deephaven.integrations.python.PythonDeephavenSession.evaluate(PythonDeephavenSession.java:184)
        at io.deephaven.engine.util.AbstractScriptSession.lambda$evaluateScript$1(AbstractScriptSession.java:146)
        at io.deephaven.engine.context.ExecutionContext.lambda$apply$0(ExecutionContext.java:117)
        at io.deephaven.engine.context.ExecutionContext.apply(ExecutionContext.java:128)
        at io.deephaven.engine.context.ExecutionContext.apply(ExecutionContext.java:116)
        at io.deephaven.engine.util.AbstractScriptSession.evaluateScript(AbstractScriptSession.java:146)
        at io.deephaven.engine.util.DelegatingScriptSession.evaluateScript(DelegatingScriptSession.java:87)
        at io.deephaven.engine.util.ScriptSession.evaluateScript(ScriptSession.java:113)
        at io.deephaven.server.console.ConsoleServiceGrpcImpl.lambda$executeCommand$8(ConsoleServiceGrpcImpl.java:170)
        at io.deephaven.server.session.SessionState$ExportBuilder.lambda$submit$2(SessionState.java:1308)
        at io.deephaven.server.session.SessionState$ExportObject.doExport(SessionState.java:856)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at io.deephaven.server.runner.DeephavenApiServerModule$ThreadFactory.lambda$newThread$0(DeephavenApiServerModule.java:156)
        at java.lang.Thread.run(Thread.java:829)