/// <summary> /// Removes a TradbaleAsset from this class. /// </summary> /// <param name="address"> The address of the asset to remove. </param> public void RemoveTradableAsset(string address) { if (!TradableAssets.ContainsKey(address)) { return; } var tradableAsset = TradableAssets[address]; TradableAssets.Remove(address); tradableAsset.OnAssetBalanceChanged -= _ => OnBalancesUpdated?.Invoke(); OnTradableAssetRemoved?.Invoke(tradableAsset); }
/// <summary> /// Adds a new asset to the collection of TradableAssets to manage. /// </summary> /// <param name="tradableAsset"> The TradableAsset to add to the manager. </param> public void AddTradableAsset(TradableAsset tradableAsset) { var address = tradableAsset.AssetAddress; if (TradableAssets.ContainsKey(address)) { return; } if (tradableAsset is EtherAsset) { EtherAsset = tradableAsset as EtherAsset; SetNewActiveAsset(tradableAsset); } TradableAssets.Add(address, tradableAsset); tradableAsset.OnAssetBalanceChanged += _ => OnBalancesUpdated?.Invoke(); OnTradableAssetAdded?.Invoke(tradableAsset); }
/// <summary> /// Gets a TradableAsset given its address. /// </summary> /// <param name="address"> The address of the asset to receive. </param> /// <returns> The TradableAsset located at the address. </returns> public TradableAsset GetTradableAsset(string address) => TradableAssets.ContainsKey(address) ? TradableAssets[address] : null;