atreyuxtrading / atreyu-backtrader-api

Atreyu's integration of IB Native API with backtrader
BSD 2-Clause "Simplified" License
95 stars 62 forks source link

321 Error With Simple Quote Example #5

Closed tshumay closed 2 years ago

tshumay commented 2 years ago

I'm just getting things up and running here - but it seems like maybe the example code is out of date?

After setting up the environment and testing my connections, executing a python script with the following IBData object:

data = IBData(host='127.0.0.1', port=7497, clientId=35,
               name="GOOG",     # Data name
               dataname='GOOG', # Symbol name
               secType='STK',   # SecurityType is STOCK 
               exchange='SMART',# Trading exchange IB's SMART exchange 
               currency='USD',  # Currency of SecurityType
               what='BID_ASK',  # Get data fields (see note below)
               rtbar=True,      # Request Realtime bars
               _debug=True      # Set to True to print out debug messagess from IB TWS API
              )

Results in a stream of 321 errors from the TWS API Client complaining about the 'What to show field':


Calling reqRealTimeBars(4557295888: 208813720,GOOG,STK,,0,,,SMART,NASDAQ,USD,GOOG,NMS,False,,,,combo:, what='BID_ASK')
Calling error(16780436, 321, "Error validating request.-'bY' : cause - What to show field is missing or incorrect.", '')
{'reqId': 16780436, 'errorCode': 321, 'errorString': "Error validating request.-'bY' : cause - What to show field is missing or incorrect.", 'advancedOrderRejectJson': ''}
Error: {'reqId': 16780436, 'errorCode': 321, 'errorString': "Error validating request.-'bY' : cause - What to show field is missing or incorrect.", 'advancedOrderRejectJson': ''}
Cancel data queue for 16780436

Should the 'what' field maybe be 'TRADES' instead of 'BID_ASK'?

atreyuxtrading commented 2 years ago

Looks like there is an error in the example. If you remove the what:

data = IBData(host='127.0.0.1', port=7497, clientId=35, name="AAPL", # Data name dataname='AAPL', # Symbol name secType='STK', # SecurityType is STOCK exchange='SMART',# Trading exchange IB's SMART exchange currency='USD', # Currency of SecurityType

what='BID', # Get data fields (see note below)

           rtbar=True,      # Request Realtime bars
           _debug=True      # Set to True to print out debug messagess from IB TWS API
          )

Looks like the values that work are "BID", "ASK" and "TRADES".

Ignore the "End Date/Time: The date, time, or time-zone entered is invalid." error as there is no end time for the realtime bars.

tshumay commented 2 years ago

Thanks. Will give it a shot.