コード例 #1
0
 def run(self) -> None:
     """Fire-up dataloding function."""
     log.debug(f'running {self.func}')
     try:
         util.run(self.func())
     except Exception as e:
         log.error(f'ignoring schedule exception: {e}')
コード例 #2
0
    def connect(self, host, port, clientId, timeout=2):
        """
        Connect to TWS/IBG at given host and port and with a clientId
        that is not in use elsewhere.

        When timeout is not zero, asyncio.TimeoutError
        is raised if the connection is not established
        within the timeout period.
        """
        util.run(self.connectAsync(host, port, clientId, timeout))
コード例 #3
0
ファイル: backtester.py プロジェクト: FinTrek/ib_tools
    def run(self) -> None:
        """Interface method, providing entry point to run simulations."""
        log.debug(f'Market initialized with reboot={self._reboot}')
        log.debug(f'commission levels for instruments: {self.commissions}')
        log.debug(f'minTicks for instruments: {self.ticks}')

        try:
            getattr(self, 'manager')
        except AttributeError:
            raise AttributeError('No manager object provided to Market')

        util.run(self._run())
        self.post_mortem()
コード例 #4
0
ファイル: wrapper.py プロジェクト: toledy/ib_insync
 def waitOnUpdate(self, timeout=0):
     self._clearPendingTickers()
     self._waitingOnUpdate = True
     coro = self._updateEv.wait()
     if timeout:
         try:
             util.run(asyncio.wait_for(coro, timeout))
         except asyncio.TimeoutError:
             pass
     else:
         util.run(coro)
     self._waitingOnUpdate = False
     self._emitPendingTickers()
     return True
コード例 #5
0
    def connect(self, host: str, port: int, clientId: int, timeout: float = 2):
        """
        Connect to a running TWS or IB gateway application.

        Args:
            host: Host name or IP address.
            port: Port number.
            clientId: ID number to use for this client; must be unique per
                connection.
            timeout: If establishing the connection takes longer than
                ``timeout`` seconds then the ``asyncio.TimeoutError`` exception
                is raised. Set to 0 to disable timeout.
        """
        util.run(self.connectAsync(host, port, clientId, timeout))
コード例 #6
0
    def reqMktData(self, contract, what=None):
        '''Creates a MarketData subscription

        Params:
          - contract: a ib.ext.Contract.Contract intance

        Returns:
          - a Queue the client can wait on to receive a RTVolume instance
        '''
        # get a ticker/queue for identification/data delivery
        q = self.getTickerQueue()
        ticks = '233'  # request RTVOLUME tick delivered over tickString

        if contract.secType in ['CASH', 'CFD']:
            #self.iscash[tickerId] = True
            ticks = ''  # cash markets do not get RTVOLUME
            if what == 'ASK':
                #self.iscash[tickerId] = 2
                pass

        # q.put(None)  # to kickstart backfilling
        # Can request 233 also for cash ... nothing will arrive
        
        md = MktData()
        q_ticks = queue.Queue()
        
        util.run(md.update_ticks(self.ib, contract, ticks, q_ticks))
                  
        while not q_ticks.empty():
            ticker = q_ticks.get()
            for tick in ticker.ticks:
                # https://interactivebrokers.github.io/tws-api/tick_types.html
                if tick != self.last_tick: #last price
                    #print(str(tick.time) +" >> " + str(tick.price))
                    self.last_tick = tick
                    q.put(tick)

        return q
コード例 #7
0
 def terminate(self):
     """Terminate TWS/IBG."""
     util.run(self.terminateAsync())
コード例 #8
0
 def stop(self):
     """Cleanly shutdown TWS/IBG."""
     util.run(self.stopAsync())
コード例 #9
0
 def start(self):
     """Launch TWS/IBG."""
     util.run(self.startAsync())
コード例 #10
0
 def onStarted(self, *args):
     log.debug(f'Starting: {args}')
     util.run(self.func())
コード例 #11
0
ファイル: blotter.py プロジェクト: t1user/ib_tools
 def save(self) -> None:
     util.run(self._save())
コード例 #12
0
ファイル: blotter.py プロジェクト: t1user/ib_tools
 def write_to_file(self, data: Dict[str, Any]) -> None:
     util.run(self._write_to_file(data))