Replies: 3 comments 2 replies
-
There are:
The former is called at startup. The doc says "no need to call again". If you call it again, the whole program hangs. Try calling |
Beta Was this translation helpful? Give feedback.
-
I have code that gets the portfolio data from multiple accounts. It takes a list of accounts, gets the portfolio data I want from each account and adds it with the account name to a dataframe. I have it split the data by TYPE (STK, OPT, CASH) as the columns are different between those and this way I can later in the code merge the data together. |
Beta Was this translation helpful? Give feedback.
-
I'll check, but I think I have it on my GitHub.Sent from my Galaxy
-------- Original message --------From: klemenkk ***@***.***> Date: 2024-10-23 3:51 a.m. (GMT-08:00) To: ib-api-reloaded/ib_async ***@***.***> Cc: ClimberMel ***@***.***>, Comment ***@***.***> Subject: Re: [ib-api-reloaded/ib_async] How to get portfolio items for multiple accounts (Discussion #61)
Thanks. I would be very interested in your code. The format of the data should be the same as portfolio() output as is today, just that it works across multiple accounts (I want to portfolios from different accounts I have). I need at least the following columns: Account,Symbol,Position,Average Price,Market Price,Market Value,Unrealized P&L,Realized P&L. Realized and Unrealized P&L are not available for me in positions. I have a FastAPI serving IB data to other apps I use.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hello,
I have created a new linked account on IB and now have two (managed in same TWS). The problem is that I can no more use the
ib.portfolio()
function since it keeps returning[]
. If I try and callib.reqAccountUpdates(True, '')
(withawait asyncio.sleep(2)
after thereqAccountUpdates
call) beforeib.portfolio()
I get this error:IB.reqAccountUpdates() takes from 1 to 2 positional arguments but 3 were given
. If I omit the second argument and just go withib.reqAccountUpdates(True)
code gets stuck and the error is the following:Error 321, reqId 2147483647: Error validating request.-'bk' : cause - Invalid account code '1'. Exception in callback Task.task_wakeup(<Future finished result=None>) handle: <Handle Task.task_wakeup(<Future finished result=None>)> Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\asyncio\events.py", line 80, in _run self._context.run(self._callback, *self._args) RuntimeError: Cannot enter into task <Task pending name='Task-1' coro=<Server.serve() running at C:\git.venv\Lib\site-packages\uvicorn\server.py:81> wait_for=<Future finished result=None> cb=[_run_until_complete_cb() at C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py:180]> while another task <Task pending name='Task-18' coro=<RequestResponseCycle.run_asgi() running at C:\git.venv\Lib\site-packages\uvicorn\protocols\http\h11_impl.py:408> cb=[set.discard()]> is being executed.
Would it be possible to get a clean example on how to retrieve all portfolio items from all the accounts?
Thanks.
Edit:
Looks like there is discrepancy in how
portfolio()
functions in case there is only one account and when there are many. To me it looks like when there is only one accountportfolio()
works as expected. It just works and returns position items. If there are more than 1 accounts you need to explicitly call 'reqAccountUpdates('account_name')' with at least one account name as a parameter and also callib.sleep(0)
right afterwards. Then call toportfolio()
works. The issue is that if you call 'reqAccountUpdates('account_name')' the second time the whole "program" hangs... Anyway, to me it looks like an issue that would be great if it would be solved...Beta Was this translation helpful? Give feedback.
All reactions