Profile Picture

Account info of Interactive Broker plugin question

Posted By felixtjung 7 Years Ago
Message
Posted Friday November 26 2010
Hi,

I'm just wondering how do I get the value of "Net Liquidation Value" and "RegT Margin" of InteractiveBroker from RightEdge?


P.S: From other post, I learned that I need to use switch "this.SystemData.UseBrokerBuyingPower". But After I enable that option, all I could get is only "buying power".

Thanks,
Felix
Posted Sunday November 28 2010
You will need to modify the TWS broker plugin to do this. Look at the client_UpdateAccountValue method in TWSPlugin.cs. You can change it so that calling GetBuyingPower will return the net liquidation by changing the "BuyingPower" key to "NetLiquidation", as explained in the source code comments. TWS probably sends the RegT Margin also, just enable the code to trace what TWS sends to this method to find out how the information is sent.

Thanks,
Daniel
Posted Friday April 29 2011
When is client_UpdateAccountValue entered? I've placed breakpoints in the handler but the breakpoints are never hit when running live.

Thanks, Duane
phg
Supreme Being (44,909 reputation)Supreme Being (44,909 reputation)Supreme Being (44,909 reputation)Supreme Being (44,909 reputation)Supreme Being (44,909 reputation)Supreme Being (44,909 reputation)Supreme Being (44,909 reputation)Supreme Being (44,909 reputation)Supreme Being (44,909 reputation)
Posted Saturday April 30 2011
Margin info is provided through the API but you have to know implicitly whether the computation was by Reg T or portfolio. That is, the method of computation is a 'known/fixed' attribute of the account.

-Pete

See also Yahoo group about applying RE.

Posted Saturday April 30 2011
Pete,

   Thanks for the reply; however, I’m currently modifying the TWSPlugin and need to know when client_UpdateAccountValue is entered. Both RequestAccountUpdates is called and the (IBClient)client.UpdateAccountValue event is subscribed to in Connect(). I do not see breakpoints hit in client_UpdateAccountValue (which obtains buying power).

When is client_UpdateAccountValue entered?

Thanks, Duane
phg
Supreme Being (44,909 reputation)Supreme Being (44,909 reputation)Supreme Being (44,909 reputation)Supreme Being (44,909 reputation)Supreme Being (44,909 reputation)Supreme Being (44,909 reputation)Supreme Being (44,909 reputation)Supreme Being (44,909 reputation)Supreme Being (44,909 reputation)
Posted Sunday May 01 2011

Hi Duane,

I have not had a reason to track that down through the TWSPlugin. A call to reqAccountUpdates returns information through 3 events: updateAccountTime, updateAccountValue and updatePortfolio. Are the first and last events working?



-Pete

See also Yahoo group about applying RE.

Posted Sunday May 01 2011
The client_UpdateAccountValue method should be called after the live broker plugin connects. If the breakpoint isn't being hit it's probably a debugging information issue- ie the DLL that's loaded doesn't match the code you're trying to set the breakpoint on. Do other breakpoints in the TWS plugin work?

Thanks,
Daniel
Posted Monday May 02 2011
The modules are loading correctly. The issue appears to be that RequestAccountUpdates() needs to be called each time a request is needed. The tws api seemed to imply that updates are on a regular basis.

That brings up new questions. The first: when SystemData.Broker.GetBuyingPower is called, does this return the buying power at the time the connection to tws is initially made or is this an updated value at the time of the call?

Additionally, I’m trying to adapt the tws plugin to return account information (other kvps in UpdateAccountValueEventArgs) for specific accounts traded in an FA account. However, the accountCode needs to be passed to the plugin. The only way I currently see to accomplish this is to create a new method in the plugin. This though requires a reference to the plugin in the scripts (the account info needs to be updated in the scripts). I added the ISimBroker interface implementation to the plugin and attempted to cast to type TWSPlugin:

   ((TWSPlugin)SystemData.Broker).NewMethodToRequenstAccountInfo(string account)

However, RE threw an invalid cast exception: “Unable to cast object of type 'RightEdge.Shared.BrokerWrapper' to type 'RightEdge.TWSCSharpPlugin.TWSPlugin'.”

Is there an easier way to accomplish the account information request than referencing the TWSPlugin from the script? If no, how do I get around the casting issue mentioned above? If the plugin must be referenced, any other thoughts on implementation?

Thanks, Duane
Posted Monday May 02 2011
As an update, IB confirmed that UpdateAccountValue is triggered every 3 minutes or when positions change.

Also, after thinking about it further, it would not be possible to obtain other kvps without a) referencing the TWSPlugin as mentioned above; b) using the other methods already available, e.g., using GetMargin() to return a different double (this is not an ideal solution for obvious reasons), or c) adding a method directly to broker, e.g., GetUpdatedAccountValue() that would return a List which then can be parsed in the system or script. UpdateAccountValueEventArgs would be the wrong type to use because a reference to Krs.Ats.IBNet would be needed. Instead, a struct which included corresponding string properties, or alternatively allow the return type to be an object, would work well.

Is it possible to add the suggestion in c) above to eliminate the casting and referencing issues mentioned in the previous post and enable expanded access to IB account data?

Thanks, Duane

Edited: Monday May 02 2011 by alpha23
Posted Thursday May 05 2011
As a further update, I resolved the issue above via a separate dll that includes a singleton. Kvps from UpdateAccountValueEventArgs in the TWSPlugin are saved in the singleton and retrieved in the strategy.

For those interested, there are numerous kvps available: http://www.interactivebrokers.com/php/apiUsersGuide/apiguide/activex/updateaccountvalue.htm#HT_updateAccountValue

A few minor issues are still outstanding such as:

1.   the fact that the IB account values are not updated until after positions change in the account (causing values to be missing upon startup), and
2.   not being able to update account values for each account in an FA account (the IB api is only sending updates for the last account requested).

If any has a solution for these two issues, please let me know.

Thanks, Duane


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems