I've been trying to get equity from broker connected to MC.net. I use following code
Code: Select all
private double currentEquity {
get {
try {
ITradingProfile active_profile = activeProfile;
if ((active_profile != null) && (active_profile.Accounts.Length > 0)) {
string current_account = active_profile.Accounts[0];
Account[] accounts = TradeManager.TradingData.Accounts.Items ?? new Account[0];
Account active_account = accounts.FirstOrDefault(acc => acc.Name == current_account);
double? balance = active_account.Balance;
if (balance.HasValue) {
return balance.Value;
}
}
}
catch (Exception ex) {
// ignore if there's any error
}
if (this.Environment.IsAutoTradingMode) {
return 0;
}
return this.InitialCapital + this.NetProfit;
}
}
private ITradingProfile activeProfile {
get {
ITradingProfile[] trading_profiles = this.TradeManager.TradingProfiles ?? new ITradingProfile[0];
return trading_profiles.FirstOrDefault(prof => prof.Name == this.Profile);
}
}
This code works "most" of the times, except there are 2 catches. First, it never get updated at all. Second, it's returning 0 on live trading (which means there's no account loaded) intermittently during start time. My question is this, is there anything that I need to do to make it work correctly, or is this a bug? If it's a bug, is there any workaround that I can apply to fix this problem for the time being?
Thanks,
Felix