コード例 #1
0
ファイル: wrapper.py プロジェクト: rickgghuang/ib_insync
 def execDetails(self, reqId, contract, execution):
     """
     This wrapper handles both live fills and responses to reqExecutions.
     """
     if execution.orderId == UNSET_INTEGER:
         # bug in TWS: executions of manual orders have unset value
         execution.orderId = 0
     key = self.orderKey(execution.clientId, execution.orderId,
                         execution.permId)
     trade = self.trades.get(key) or self.permId2Trade.get(execution.permId)
     if trade and contract == trade.contract:
         contract = trade.contract
     else:
         contract = Contract.create(**contract.dict())
     execId = execution.execId
     execution.time = util.parseIBDatetime(execution.time). \
         astimezone(datetime.timezone.utc)
     isLive = reqId not in self._futures
     time = self.lastTime if isLive else execution.time
     fill = Fill(contract, execution, CommissionReport(), time)
     if execId not in self.fills:
         # first time we see this execution so add it
         self.fills[execId] = fill
         if trade:
             trade.fills.append(fill)
             logEntry = TradeLogEntry(
                 time, trade.orderStatus.status,
                 f'Fill {execution.shares}@{execution.price}')
             trade.log.append(logEntry)
             if isLive:
                 self._logger.info(f'execDetails: {fill}')
                 self.ib.execDetailsEvent.emit(trade, fill)
                 trade.fillEvent(trade, fill)
     if not isLive:
         self._results[reqId].append(fill)
コード例 #2
0
ファイル: wrapper.py プロジェクト: xia-natsu/ib_insync
 def execDetails(self, reqId, contract, execution):
     """
     This wrapper handles both live fills and responses to reqExecutions.
     """
     if execution.orderId == 2147483647:
         # bug in TWS: executions of manual orders have orderId=2**31 - 1
         execution.orderId = 0
     key = self.orderKey(execution.clientId, execution.orderId,
                         execution.permId)
     trade = self.trades.get(key)
     if trade and contract.conId == trade.contract.conId:
         contract = trade.contract
     else:
         contract = self._getContract(contract)
     execId = execution.execId
     execution = Execution(**execution.__dict__)
     execution.time = util.parseIBDatetime(execution.time). \
         astimezone(datetime.timezone.utc)
     isLive = reqId not in self._futures
     time = self.lastTime if isLive else execution.time
     fill = Fill(contract, execution, CommissionReport(), time)
     if execId not in self.fills:
         # first time we see this execution so add it
         self.fills[execId] = fill
         if trade:
             trade.fills.append(fill)
             logEntry = TradeLogEntry(
                 self.lastTime, trade.orderStatus.status,
                 f'Fill {execution.shares}@{execution.price}')
             trade.log.append(logEntry)
             if isLive:
                 self.handleEvent('execDetailsEvent', trade, fill)
                 self._logger.info(f'execDetails: {fill}')
                 trade.fillEvent(trade, fill)
     if not isLive:
         self._results[reqId].append(fill)