开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育

IB-insync library - how to invoke the priceSizeTick() function


 

Hello,

IB-insync is a python library developed to make it easier to work with the TWS api.


https://ib-insync.readthedocs.io/_modules/ib_insync/client.html#

I would like to know how to invoke the method 'priceSizeTick' in the??ib_insync.wrapper class.?
or alternatively how to invoke the 'priceTick' and 'sizeTick' functions. (which are combined in the?'priceSizeTick' function)
Please attach a code script if you can.

Thank you!

Itay


 

Just wondering why do you need this? What are you trying to do? Maybe I can help you if I know what you are trying to do.?

I think what you are trying to do has been removed. Maybe you can get what you need by this below??

contract = Stock(symbol='TSLA', exchange='SMART', currency='USD')
ib.qualifyContracts(contract)
ticker = ib.reqMktData(contract=contract,genericTickList="",snapshot=False,regulatorySnapshot=False)

def onUpdateEvent(ticker):
? ? print(ticker)

ticker.updateEvent+=onUpdateEvent


 

Hey Adi/Dror

Thank you for your reply.
I'm trying to invoke events that only relates to price change - meaning a trade as been completed.
For example, I want to collect ticker data (timestamp, price, volume, etc') only when a trade in TSLA actually occurred.
ib.reqMktData() returns aggregated ticker data every 250 ms, which includes any tick type event within this time frame (for example, bid or ask change, volume change etc').
According to the docs, priceSizeTick() is suppose to be invoked only when there is a price change (same as 'priceTick' and 'sizeTick' functions in the TWS api).
So who can i do that?

By the way, I'm not sure i can use reqTickByTickData("Last") because it doesn't return the size of the trade in the callback, am i wrong?

Thank you,
Itay


 

From what you wrote, reqTickByTickData("Last"). It does return "size", but only for "Last". Finally you subscribe to the pendingTickersEvent event to get event on each packets of ticks.


 
Edited

Hey you can use ib.reqTickByTickData and calculate your logic with it... It does return the size of the trade... Try this in Jupyter notebook. I display the last few trades every time a new tick comes...

from IPython.display import display, clear_output

contract = Stock(symbol='TSLA', exchange='SMART', currency='USD')
ib.qualifyContracts(contract)
ticker = ib.reqTickByTickData(contract=contract, tickType='Last', numberOfTicks=0)

all_ticks = []

def onUpdateEvent(ticker):
global all_ticks
all_ticks += [tick for tick in ticker.tickByTicks]
df = util.df(all_ticks)
clear_output()
display(df.tail())

ticker.updateEvent += onUpdateEvent


See at 01:08:00 (1 hour and 8 minutes) I have an example.