Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

ValueError: Account not found in account list #30

Closed
3rock618 opened this issue Jun 10, 2019 · 6 comments
Closed

ValueError: Account not found in account list #30

3rock618 opened this issue Jun 10, 2019 · 6 comments

Comments

@3rock618
Copy link

3rock618 commented Jun 10, 2019

1.12.67 was working fine, error with 1.12.68:

When I place an a basic market order I get the following error:

>>> tws.placeOrder(contract, tws.createOrder(1))
1550304349
ERROR:ibpy:Exception in message dispatch.  Handler 'handleServerEvents' for 'orderStatus'
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/ib/opt/dispatcher.py", line 44, in __call__
    results.append(listener(message))
  File "/usr/local/lib/python3.7/site-packages/ezibpy/ezibpy.py", line 332, in handleServerEvents
    self.handleOrders(msg)
  File "/usr/local/lib/python3.7/site-packages/ezibpy/ezibpy.py", line 762, in handleOrders
    positions = self.getPositions(order['account'])
  File "/usr/local/lib/python3.7/site-packages/ezibpy/ezibpy.py", line 616, in getPositions
    raise ValueError("Account %s not found in account list" % account)
ValueError: Account  not found in account list
ERROR:ibpy:Exception in message dispatch.  Handler 'handleServerEvents' for 'orderStatus'
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/ib/opt/dispatcher.py", line 44, in __call__
    results.append(listener(message))
  File "/usr/local/lib/python3.7/site-packages/ezibpy/ezibpy.py", line 332, in handleServerEvents
    self.handleOrders(msg)
  File "/usr/local/lib/python3.7/site-packages/ezibpy/ezibpy.py", line 762, in handleOrders
    positions = self.getPositions(order['account'])
  File "/usr/local/lib/python3.7/site-packages/ezibpy/ezibpy.py", line 616, in getPositions
    raise ValueError("Account %s not found in account list" % account)
ValueError: Account  not found in account list

Using TWS I can see that the order completes successfully. Also when I type tws.getPositions() I get my positions back as normal.

@3rock618
Copy link
Author

3rock618 commented Jun 10, 2019

I've found the problem. The order object in handleOrders comes back where order['account'] = ''. However tws.getPositions(None) is not the same as tws.getPositions(''), hence the error.

Since I'd rather not mess with the whole order object pipeline (it's a bit hairy), I can monkeypatch getPositions with if account == '': account = None

import ezibpy

# MONKEY PATCH
def getPositions(self, account=None):
    if len(self._positions) == 0: 
        return {}
    if account == '': 
        account = None
    account = self._get_default_account_if_none(account)
    if account is None:
        if len(self._positions) > 1:
            raise ValueError("Must specify account number as multiple accounts exists.")
        return self._positions[list(self._positions.keys())[0]]
    if account in self._positions:
        return self._positions[account]
    raise ValueError("Account %s not found in account list" % account)

ezibpy.ezIBpy.getPositions = getPositions

@ranaroussi
Copy link
Owner

Hi,

Thanks for pointing that out!

I've updated the library to use a more fool-proof_get_active_account() (foremarly _get_default_account_if_none()) to handle this. I've also made sure that handleOrders uses None as the default account value instead of "". This should do the trick :)

Please update to 1.12.69 to get the changes and let me know if the problem is solved.

Thanks,
Ran

@3rock618
Copy link
Author

Problem still persists in .68, when I debug getPositions it tells me that account = ''

@ranaroussi
Copy link
Owner

ranaroussi commented Jun 15, 2019

Thanks!

When calling getPositions() - are you not getting the positions, or are you just not getting the account code?

Also - do you call getPositions() with or without specifying the account?

@ranaroussi
Copy link
Owner

?

@3rock618
Copy link
Author

3rock618 commented Jun 17, 2019

Working from the github version, this is solved now. 👍🏼🙏🏼
Thanks Ran for all your great work!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants