ib-api-reloaded / ib_async

Python sync/async framework for Interactive Brokers API (replaces ib_insync)
BSD 2-Clause "Simplified" License
236 stars 39 forks source link

BID_ASK for Forex error #35

Closed blair-anson closed 1 week ago

blair-anson commented 1 week ago

Hi, when running the code below I get this error when type = BID_ASK however it works fine when MIDPOINT is used.

Error 321, reqId 4: Error validating request.-'bY' : cause - What to show field is missing or incorrect., contract: Forex('EURUSD', exchange='IDEALPRO')

from ib_async import IB, util, RealTimeBar
from ib_async.contract import *  # noqa

def main():

    ib = IB()
    ib.connect(host='127.0.0.1', port=7497, clientId=14)
    print("Connected to IB")

    type = 'BID_ASK'  # MIDPOINT   BID_ASK
    contract = Forex("EURUSD")
    print(ib.reqHeadTimeStamp(contract, whatToShow=type, useRTH=False))
    print(ib.reqCurrentTime())

    bars = ib.reqRealTimeBars(contract=contract,
                              barSize=5,
                              whatToShow=type,
                              useRTH=False)

    def on_bar_update(bars, hasNewBar):
        print(bars[-1])

    bars.updateEvent += on_bar_update

    ib.sleep(20)
    ib.cancelRealTimeBars(bars)
    ib.disconnect()

if __name__ == "__main__":
    util.startLoop()
    main()
baichen111 commented 1 week ago

Your 'type' should be 'BID' or 'ASK', not 'BID_ASK'

this is the document :

whatToShow: Specifies the source for constructing bars.
                Can be 'TRADES', 'MIDPOINT', 'BID' or 'ASK'.
blair-anson commented 1 week ago

Ahhh I see, thank you. I must have been looking at the reqHistoricalData() docstrings which do support BID_ASK