What does += mean in the context of event handling?

  interactive-brokers, python, python-asyncio

In Scanner data (streaming) I can find the following statement (you can find below the full code):

scanData.updateEvent += onScanData

What does the += mean?

So, I understand that onScanData() is the event handler function that should be called when the scanData.updateEvent is fired.

But why do I have a += here and not a simple =?
What get’s incremented and where can I find the incremented variable later on?

Remark: to get the code snippet below running, the Interactive-Brokers software TWS has be running.

import datetime
from ib_insync import *

ib = IB()
ib.connect('127.0.0.1', 7497, clientId=1)


def onScanData(scanData):
    print(scanData[0])
    print(len(scanData))

sub = ScannerSubscription(
    instrument='FUT.US',
    locationCode='FUT.GLOBEX',
    scanCode='TOP_PERC_GAIN')
scanData = ib.reqScannerSubscription(sub)
scanData.updateEvent += onScanData
ib.sleep(60)
ib.cancelScannerSubscription(scanData)

Source: Python Questions

LEAVE A COMMENT