def _init_req_queue(self, req_id: int): """Initials a new `FinishableQueue` if there's no object at `self.__req_queue[req_id]`; Resets the queue status to its' initial status. Raises: ibpy_native.error.IBError: If a `FinishableQueue` already exists at `self.__req_queue[req_id]` and it's not finished. """ if req_id in self._req_queue: if (self._req_queue[req_id].finished or (req_id == _global.IDX_NEXT_ORDER_ID and (self._req_queue[_global.IDX_NEXT_ORDER_ID].status is fq.Status.INIT)) or (req_id == _global.IDX_OPEN_ORDERS and (self._req_queue[_global.IDX_OPEN_ORDERS].status is fq.Status.INIT))): self._req_queue[req_id].reset() else: raise error.IBError( rid=req_id, err_code=error.IBErrorCode.QUEUE_IN_USE, err_str=f"Requested queue with ID {str(req_id)} is " "currently in use") else: self._req_queue[req_id] = fq.FinishableQueue(queue.Queue())
def __init__( self, accounts_manager: delegates.AccountsManagementDelegate, orders_manager: delegates.OrdersManagementDelegate, connection_listener: Optional[listeners.ConnectionListener] = None, notification_listener: Optional[ listeners.NotificationListener] = None): self._lock = threading.Lock() self._req_queue: Dict[int, fq.FinishableQueue] = {} self._accounts_manager = accounts_manager self._orders_manager = orders_manager self._connection_listener = connection_listener self._notification_listener = notification_listener # Queue with ID -1 is always reserved for next order ID self._req_queue[_global.IDX_NEXT_ORDER_ID] = fq.FinishableQueue( queue_to_finish=queue.Queue()) # -2 is reserved for open orders requests self._req_queue[_global.IDX_OPEN_ORDERS] = fq.FinishableQueue( queue_to_finish=queue.Queue()) super().__init__()
def on_order_submission(self, order_id: int): """INTERNAL FUNCTION! Creates a new `FinishableQueue` with `order_id` as key in `_pending_queues` for order submission task completeion status monitoring. Args: order_id (int): The order's identifier on TWS/Gateway. Raises: ibpy_native.error.IBError: If existing `FinishableQueue` assigned for the `order_id` specificed is found. """ if order_id not in self._pending_queues: self._pending_queues[order_id] = fq.FinishableQueue( queue_to_finish=queue.Queue()) else: raise error.IBError( rid=order_id, err_code=error.IBErrorCode.DUPLICATE_ORDER_ID.value, err_str=f"Existing queue assigned for order ID {order_id} " "found. Possiblely duplicate order ID is being used.")
def __init__(self, accounts: Optional[Dict[str, models.Account]] = None): self._accounts: Dict[str, models.Account] = ({} if accounts is None else accounts) self._account_updates_queue: fq.FinishableQueue = fq.FinishableQueue( queue_to_finish=queue.Queue())
def __init__(self): self._account_list: Dict[str, models.Account] = {} self._account_updates_queue: fq.FinishableQueue = fq.FinishableQueue( queue_to_finish=queue.Queue() )
def _reset(self): self._req_queue.clear() self._req_queue[_global.IDX_NEXT_ORDER_ID] = fq.FinishableQueue( queue_to_finish=queue.Queue()) self._req_queue[_global.IDX_OPEN_ORDERS] = fq.FinishableQueue( queue_to_finish=queue.Queue())