Struggling
HawkridgeV opened this issue · comments
Hello,
I have jsut started using Python and am new to programming. I am struggling to make use of this project. Could anyone explain how to get started/set up this thing? I have the. token + an xml, however I have no idea what to do with makefile, setup, etc.
I have tried: pythong ibflex build and install but the sample code does not work for me (its in Jypiter format and I am using pycharm.
Sorry for the beginer questions!
Thanks a lot in advance.
Hey! The project README is intended to function as documentation. As it says there under the section entitled "Installation", you should be able just to type
pip install ibflex
assuming you have a recent version of Python and/or you've already installed pip.
If you don't want to use pip, or it doesn't work for you, ibflex
has got all your old-school installation needs covered. Download & unzip the library (or git clone
it if you're one of the cool kids), open a shell inside that directory, and type:
python setup.py install
If there are no errors with this process, you can verify the installation by opening a Python interpreter and typing:
import ibflex
print(ibflex.__file__)
That will report where the library got installed. Inside the directory, you'll find client.py
, which can be run as a script, e.g. python client.py --help
. For your convenience, this script actually should have been installed to your $PATH
under the name flexget
, so you can try just typing flexget --help
and take it from there.
HTH
I was simply not aware that I could ignore the build/makefile if pip
worked.
If you open the Makefile in a text editor, I think you'll find it very easy to understand... it's mostly there as a convenience for developers (i.e. me) working on the library code. Users of the library don't need to bother with it; they can just stick to the usual Python installation practices (PyPI, pip, etc.)
I figured out that the
parser puts the data in this structure and i can access it by:
print(response.FlexStatements)
print(response.type)
print(response.queryName)
Sound like it is working then, no? That's good!
It's possible that my example from the README docs is out of date; IBKR changes the data model quite frequently. The other main possibility is that you haven't configured your Flex Query to include the data that you want to look at.
Have a look at your XML file... I'd just open it up in a text editor and examine it closely. Does the output of ibflex.parser.parse()
directly map to what's contained in your XML file?
As part of this process, I'd also recommend opening up ibflex.parser.Types
in a text editor and looking at the source code. I have gone to quite a bit of trouble to make these data structures very easy to understand, modify, and extend by people who have no special experience.
At the top of the file, you'll see this:
class FlexQueryResponse(FlexElement):
""" Root element """
queryName: str
type: str
FlexStatements: Tuple["FlexStatement", ...]
So you should be able to do print(len(response.FlexStatements))
and stmt = response.FlexStatements[0]
. Moving on to that class definition, you'll see this:
class FlexStatement(FlexElement):
""" Wrapped in <FlexStatements> """
accountId: str
fromDate: datetime.date
toDate: datetime.date
period: str
whenGenerated: datetime.datetime
<snip>
Trades: Tuple["Trade", ...] = ()
So you should be able to say print(len(stmt.Trades))
and trade = stmt.Trades[0]
(if it's not empty). Then you can go look at the class definition for Trade, and keep on going. But again, if you haven't configured the Flex Query builder on IB's website to download trade data, it won't be there in the XML file for the parser to find.
If you get data in your XML file that is not showing up in the parser output, that is a bug!
You've got it. You should be good to go.
BTW those fields listed inside <angle brackets>
are enums; you'll find them in ibflex.enums.py
if you need to handle different cases in your code.
Have fun!