Komnomnomnom / swigibpy

Third party Interactive Brokers Python API generated from TWS C++ API using SWIG.
http://github.com/Komnomnomnom/swigibpy/
Other
155 stars 36 forks source link

Allow custom poll interval #5

Closed Komnomnomnom closed 12 years ago

Komnomnomnom commented 12 years ago

Email correspondance with @olafsep01

The sleep time in the Polling class I made variable: swigify_ib.i:

%pythoncode %{
import threading
import time
class TWSPoller(threading.Thread):
    '''Polls TWS every second for any outstanding messages'''

    def __init__(self, tws):
        super(TWSPoller, self).__init__()
        self.daemon = True
        self._tws = tws
        self.stop_polling = False
        self.sleep_time = 1 # <-------

    def run(self):
        '''Continually poll TWS until the stop flag is set'''
        while not self.stop_polling:
            try:
                self._tws.checkMessages()
            except:
                if self.stop_polling:
                    break
                else:
                    raise
            time.sleep(self.sleep_time) # <-------
%}

I tend to use a smaller sleep time. So now I am able to change the sleep_time after the connection with: tws.poller.sleep_time = 0.2

Komnomnomnom commented 12 years ago

eConnect now accepts a poll_interval argument.