Keyboard Shortcuts
ctrl + shift + ? :
Show all keyboard shortcuts
ctrl + g :
Navigate to a group
ctrl + shift + f :
Find
ctrl + / :
Quick actions
esc to dismiss
Likes
Search
using reqAccountUpdates to create pandas dataframe for each new update
Is there a way of using reqAccountUpdates and updatePortfolio to create a dataframe with all positions, and then overwrite the dataframe for each refresh?
I am using reqAccountUpdates so that I can get the cash balance and the positions all in one place. My problem is that each symbol comes in separately, so if I do something like this: ``` ? ? def updatePortfolio(self, contract: Contract, position: float, marketPrice: float, marketValue: float, averageCost: float, unrealizedPNL: float, realizedPNL: float, accountName: str):
? ? ? ? df = pd.DataFrame([contract.symbol, position, marketValue])
? ? ? ? df.to_csv('positions.csv') ``` The CSV file ends up with the last position only, since its overwriting it for each symbol. |
In your class __init__, add:
? ? self.positions = pd.DataFrame() in def updatePortfolio, try this: def updatePortfolio(self, ?This may not be ideal, but it might get you on a path that works for now and can be improved upon later. BTW, I have not tried the code, but despite any errors, it will hopefully get you started. ? |
Sorry, I notice I can't see the code I posted very well. Some of the
code elements seem to show up so lightly that I can't see them. If I drag my cursor across it to select it, then I can read it. Maybe it has something to do with my PyCharm color scheme that makes cut and paste unusable.? Or, maybe there is a trick I need to learn. Anyone? ? |
Change the default PyCharm colour scheme?
I use the Intelli Light scheme in PyCharm, and just copied and pasted into a new .py document. Readibility is good. KH def updatePortfolio(self, |
def updatePortfolio(self, |
¿ªÔÆÌåÓýA quick observation tells me that certain items are faint because they are not called up later in the code.
On 28/5/21 12:39 pm,
sbtuttle@... wrote:
Sorry, I notice I can't see the code I posted very well. Some of the |
to navigate to use esc to dismiss