erdewit / ib_insync

Python sync/async framework for Interactive Brokers API
BSD 2-Clause "Simplified" License
2.76k stars 726 forks source link

reqHistoricalTicks reports error 'Unable to parse data. java.lang.NumberFormatException' #12

Closed lysunht closed 6 years ago

lysunht commented 6 years ago

Repro Source Code:

from ib_insync import *

ib = IB()

ib.connect('127.0.0.1', 4003, clientId=1)

contract = Stock('AAPL', 'SMART', 'USD')

ticks = ib.reqHistoricalTicks(contract, startDateTime='2017-09-01', endDateTime='', numberOfTicks=100, whatToShow='TRADES', useRth=False, ignoreSize=False, miscOptions=None) print(ticks)

Output:

ERROR:ib_insync.wrapper:Error 320, reqId -1: Error reading request:Message type -1. Unable to parse data. java.lang.NumberFormatException: For input string: "AAPL" ERROR:ib_insync.client:Peer closed connection

erdewit commented 6 years ago

You'll need the latest TWS version, and datetimes are specified like '20170901 00:00:00' (or as a Python datetime).

lysunht commented 6 years ago

I'm using tws build 963.3h. I also tried to change the date format,

ticks = ib.reqHistoricalTicks(contract, startDateTime='20170901 00:00:00', endDateTime='', numberOfTicks=100, whatToShow='TRADES', useRth=False, ignoreSize=False, miscOptions=None)

Still not working, with the same error.

erdewit commented 6 years ago

Latest version TWS is 967.

lysunht commented 6 years ago

Thanks and sorry for my misunderstanding. Using the "TWS Latest" solved the problem.

morbal commented 6 years ago

Now we are at TWS 969 and I get the same error in live and paper when I try to run reqHistoricalData. Any thoughts?

morbal commented 6 years ago

from ibapi.client import EClient from ibapi.wrapper import EWrapper from ibapi.common import from ibapi.contract import class TestApp(EClient, EWrapper): def init(self): EClient.init(self, self) def error(self, reqId: TickerId, errorCode: int, errorString: str): print("Error", reqId, " ", errorCode, " ", errorString) def contractDetails(self, reqId: int, contractDetails: ContractDetails): print("Contract Details: ", reqId, " ", contractDetails) def main(): app = TestApp() app.connect("127.0.0.1", 7497, 0) contract = Contract() contract.symbol = "SIE" contract.secType = "STK" contract.exchange = "IBIS" contract.currency = "EUR" contract.primaryExchange = "IBIS"

app.reqHistoricalData(10, contract, 20180223, "3 D", "1 hour", "MIDPOINT", 0, 1, 'True', 'XYZ')

# -> Error 10   321   Error validating request:-'bm' : cause - Historical data query end date/time string [20180223] is invalid.
#    Format is 'YYYYMMDD{SPACE}hh:mm:ss[{SPACE}TMZ]'.
app.reqHistoricalData(10, contract, '20180228 14:15:00', "3 D", "1 hour", "MIDPOINT", 0, 1, 'True', 'XYZ')
app.run()

if name == "main": main()

erdewit commented 6 years ago

Not that you're using ib_insync, but the format is 'YYYYMMDD{SPACE}hh:mm:ss[{SPACE}TMZ]' (or leave it empty).

morbal commented 6 years ago

my fault - now it works

Richard-Msule commented 11 months ago

0-Aug-23 09:55:22 DEBUG findfont: score(FontEntry(fname='C:\Windows\Fonts\ebrimabd.ttf', name='Ebrima', style='normal', variant='normal', weight=700, stretch='normal', size='scalable')) = 10.335 30-Aug-23 09:55:22 DEBUG findfont: Matching sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to DejaVu Sans ('c:\users\quant\tan-quant\tqnt\env\lib\site-packages\matplotlib\mpl-data\fonts\ttf\DejaVuSans.ttf') with score of 0.050000. Javascript Error: IPython is not defined 30-Aug-23 09:55:23 DEBUG >>> 50,3,4,50,0,EUR,CASH,,0.0,,,IDEALPRO,,USD,,,5,MIDPOINT,0 30-Aug-23 09:55:23 DEBUG <<< 4,2,4,320,Error reading request. Unable to parse data. java.lang.NumberFormatException: For input string: "MIDPOINT", 30-Aug-23 09:55:23 ERROR Error 320, reqId 4: Error reading request. Unable to parse data. java.lang.NumberFormatException: For input string: "MIDPOINT", contract: 50