Hi, When requesting auction price, volume, and imbalance data for ASX-listed securities in the pre-auction period, I'm getting the same number returned to me for both auction volume and auction imbalance, even though the tick type is different. I've put together an MWE to help anyone else look into this possible bug. I also just ran this MWE during the pre-close period today and I've pasted some of the output produced below so you can see what I mean. Anyway, the code is:
from ibapi.client import EClient from ibapi.wrapper import EWrapper from ibapi.contract import Contract from ibapi.order import Order from ibapi.order_state import OrderState
import threading import time from datetime import datetime import queue class IBapi(EWrapper, EClient): def __init__(self): EClient.__init__(self, self) def request_auction_data_single(self, idnum: int, contract1: Contract): self.reqMktData(idnum, contract1, 'mdoff,225', False, False, []) #225 is tick id for auction data of volume, price, and imbalance return None def tickPrice(self, reqId, tickType, price, attrib): # tick price data sent by TWS is received by this function attrib_as_string = str(attrib) print("tickPrice triggered. reqId=%d, tickType=%d, price=%f, attribasstr=%s" % (reqId, tickType, price, attrib_as_string)) return None def tickSize(self, reqId, tickType, size): # tick size data sent by TWS is received by this function print("tickSize triggered. reqId=%d, tickType=%d, size=%d" % (reqId, tickType, size)) return None def error(self, id, errorCode, errorString): errormessage = "TWS error. id = %d. errorcode = %d. msg = %s" % (id, errorCode, errorString) print(errormessage) def build_contract(self, mkt: str, scy: str, sectype: str, currency: str): cc1 = Contract() cc1.exchange = mkt cc1.symbol = scy cc1.secType = sectype cc1.currency = currency return cc1
def run_loop(): app.run()
app = IBapi() app.connect("127.0.0.1", 7496, 0)
# Start the app in a thread api_thread = threading.Thread(target=run_loop, daemon=True) api_thread.start()
time.sleep(1) # Sleep interval to allow time for connection to server
# Request auction data id1 = app.reqIds(-1) contract1 = app.build_contract("ASX","NAB","STK","AUD") app.request_auction_data_single(id1, contract1)
On my machine, this snippet will start printing auction price, volume, and imbalance data to the terminal for NAB (National Australian Bank) - which is one of the big banks listed on the ASX. I ran the snippet in the pre-close period today (just after 4pm Sydney time) and here is a snippet of the output produced:
tickSize? triggered. reqId=5, tickType=36, size=897951 tickPrice triggered. reqId=5, tickType=35, price=30.160000, attribasstr=CanAutoExecute: 0, PastLimit: 0, PreOpen: 0 tickSize? triggered. reqId=5, tickType=61, size=0 tickSize? triggered. reqId=5, tickType=34, size=912196 tickSize? triggered. reqId=5, tickType=36, size=912196 tickSize? triggered. reqId=5, tickType=34, size=915148 tickSize? triggered. reqId=5, tickType=36, size=915148 tickPrice triggered. reqId=5, tickType=35, price=30.290001, attribasstr=CanAutoExecute: 0, PastLimit: 0, PreOpen: 0 tickSize? triggered. reqId=5, tickType=34, size=915178 tickSize? triggered. reqId=5, tickType=36, size=915178 tickSize? triggered. reqId=5, tickType=34, size=915190 tickSize? triggered. reqId=5, tickType=36, size=915190 tickSize? triggered. reqId=5, tickType=34, size=916392 tickSize? triggered. reqId=5, tickType=36, size=916392 tickPrice triggered. reqId=5, tickType=35, price=30.250000, attribasstr=CanAutoExecute: 0, PastLimit: 0, PreOpen: 0 tickSize? triggered. reqId=5, tickType=34, size=916618 tickSize? triggered. reqId=5, tickType=36, size=916618 tickSize? triggered. reqId=5, tickType=34, size=917042 tickSize? triggered. reqId=5, tickType=36, size=917042 tickSize? triggered. reqId=5, tickType=34, size=917851 tickSize? triggered. reqId=5, tickType=36, size=917851 tickSize? triggered. reqId=5, tickType=34, size=917863 tickSize? triggered. reqId=5, tickType=36, size=917863
My understanding is that tickType 34 is supposed to be the volume, and tickType 36 is the imbalance. However, as can be seen here, they are both returning exactly the same number each time. Note, I've verified this behaviour across multiple securities on multiple days. Cheers all, any help would be most appreciated. Colin
|