using System.Collections.Generic; using System.ComponentModel; using TradeIdeas.TIProGUI; using TradeIdeas.MiscSupport; namespace TIProAutoTradeExtension { public class Account : IRowDataCapable, INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public string Name { get; set; } = ""; [Browsable(false)] public string Firm { get; set; } /// /// Currently only used in paper trading - this comes from the server /// [Browsable(false)] public int UserAccountId { get; set; } [Browsable(false)] public IBroker Broker { get; set; } private double _accountValue; [ColumnInfoAttribute(DisplayName = "Account Value", Format = "2")] public double AccountValue { get => _accountValue; set { double previousValue = _accountValue; _accountValue = value; // ReSharper disable once CompareOfFloatsByEqualityOperator if (null != PropertyChanged && previousValue != value) PropertyChanged(this, new PropertyChangedEventArgs("AccountValue")); } } [ColumnInfoAttribute(DisplayName = "Buying Power", Format = "2")] public double BuyingPower { get; set; } [ColumnInfoAttribute(DisplayName = "Available Funds", Format = "2")] public double AvailableFunds { get; set; } = 0; [ColumnInfoAttribute(DisplayName = "Buying Power in Use", Format = "2")] public double BuyingPowerInUse { get; set; } = 0; [ColumnInfoAttribute(DisplayName = "Unrealized Profit", Format = "2")] public double UnrealizedProfit { get; set; } = 0; [ColumnInfoAttribute(DisplayName = "Realized Profit", Format = "2")] public double RealizedProfit { get; set; } = 0; [Browsable(false)] public string DisplayName { get { string strName = Name; if (EnablePrivacy) strName = PrivacyName; if (null == Broker) return strName; else if (Broker.InternalCode() == "PAP") return strName + " (Trade-Ideas)"; else return strName + " (" + Broker.Name() + ")"; } } public bool EnablePrivacy { get; set; } = false; public string PrivacyName { get { return EnablePrivacy ? PrivateName : Name; } } public string PrivateName { get { string strName = Name; if (null != Broker && Broker.InternalCode() != "PAP" ) { try { int length = strName.Length; string last3Digits = strName.Substring(length - 3, 3); strName = Broker.InternalCode() + "_" + last3Digits; } catch { // ignored } } return strName; } } public override bool Equals(object obj) { if (!(obj is Account c)) return false; // Return true if the fields match: bool matches = Name == c.Name; return matches; } public bool Equals(Account c) { // If parameter is null return false: if (c == null) return false; // Return true if the fields match: bool matches = Name == c.Name; return matches; } public override int GetHashCode() { // ReSharper disable once NonReadonlyMemberInGetHashCode return Name.GetHashCode(); } public override string ToString() { return PrivacyName; } /// /// List of properties where we do not want to display data when privacy mode is enabled. /// private readonly List _privateProperties = new List() { "AccountValue", "BuyingPower" }; public RowData ToRowData() { if (EnablePrivacy) { // Currently we just want to substitute the value of the Name property to the value of the PrivateName // displayed in rowData. var replacePropertyValueDictionary = new Dictionary {{"Name", PrivacyName}}; return RowDataHelper.GetRowDataFromObjectPrivately(this, _privateProperties, replacePropertyValueDictionary); } return RowDataHelper.GetRowDataFromObject(this); } public FractionalTrading FractionalTrading { get; set; } = new FractionalTrading() { Enabled = false }; } public class FractionalTrading { public bool Enabled { get; set; } public decimal MinimumShares { get; set; } public int Decimals { get; set; } } }