rterp / SumZeroTrading

A Java API for Developing Automated Trading Applications for the Equity, Futures, and Currency Markets
http://rterp.github.io/SumZeroTrading/
Other
145 stars 47 forks source link

how to get open positions #32

Open aries1998 opened 7 years ago

aries1998 commented 7 years ago
i'm trying to get open positions from ib with getOpenPositions but find out that it only returns an empty array from InteractiveBrokersBroker.getAllPositions() .  
Then in EClientSocket.reqPositions() method , it just do nothing but print some version numbers. I'm a liitle confused how to do it .
rterp commented 7 years ago

I'll need to double check on this one. I've only been implementing the functionality as I have needed it, and it could be that the getAllPositions() method is currently stubbed out right now. I'll let you know.

aries1998 commented 7 years ago

thanks for your replay. It seems the simplest way to do is assemble the Posistion in InteractiveBrokerBroker.position() method and filter the closed position (don't know why ib return closed positions here ........)

And i think maybe Position need a avgCost as its element. Ticker + size + avgCost can make a complete position structure.

rterp commented 7 years ago

I started to implement this and then remember why I had not fully implemented it yet. There are builder classes to take a Ticker object and convert it into a Contract object which the IB API uses. However there are not yet any builders which will take an IB Contract object and convert it into a Ticker object. The IB position() callback method returns an IB Contract object, so I'll need to create a builder to translate this to a Ticker object.