erdewit / ib_insync

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

reqHistogramData errors on parsing period string #230

Closed drhboss closed 4 years ago

drhboss commented 4 years ago

reqHistogramData complains about the format of the time-period. I use same format string for reqHistoricalData and it works fine,

Thank you for looking into it.

here is an example:

print(ib_insync.__version__)

0.9.59

contract = Stock('SPY', 'SMART', 'USD') ib.reqHistogramData(contract, False, '3 days')

Error 320, reqId 4: Error reading request:Message id 4. Unable to parse data. java.lang.NumberFormatException: For input string: "3 days", contract: Stock(symbol='SPY', exchange='SMART', currency='USD')

erdewit commented 4 years ago

Could be a weekend thing, try it after the IB weekend maintenance.

The code looks okay.

drhboss commented 4 years ago

I don't think the issue is the weekly maintenance, just tested again using the native IBKR api and it works fine, here is the code using EWrapper/EClient., still same error as before when using ib_insync

Thank you

from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.ticktype import TickTypeEnum

import time

class TestApp(EWrapper, EClient):
    def __init__(self):
        EClient.__init__(self, self)

    def error(self, reqId, errorCode, errorString):
        print("Error: ", reqId, " ", errorCode, " ", errorString)

    def tickPrice(self, reqId, tickType, price, attrib):
        print("Tick Price. Ticker Id:", reqId, "tickType:",
TickTypeEnum.to_str(tickType), "Price:", price, end=' ')

    def histogramData(self, reqId, items):
        print("HistogramData. ReqId:", reqId, "HistogramDataList:", "[%s]" % "; ".join(map(str, items)))

    def tickSize(self, reqId, tickType, size):
        print("Tick Size. Ticker Id:", reqId, "tickType:",
TickTypeEnum.to_str(tickType), "Size:", size)

def main():
    app = TestApp()

    app.connect("127.0.0.1", 4002, 0)
    time.sleep(0.1)

    contract = Contract()
    contract.secType = "FUT"
    contract.exchange = "GLOBEX"
    contract.currency = "USD"
    contract.lastTradeDateOrContractMonth="202006"
    contract.symbol="ES"

    app.reqHistogramData(1, contract, False, '5 days')

    app.run()

if __name__ == "__main__":
    main()
erdewit commented 4 years ago

Thanks for the followup. It was indeed a bug in the ib_insync client which is now fixed in the repo. It will be released shortly in v0.9.60.

drhboss commented 4 years ago

Thank you!, great work by the way, :-)