public async void ListAssetsWorks()
        {
            var assets = await _alpacaTradingClient.ListAssetsAsync(
                new AssetsRequest());

            Assert.NotNull(assets);
            Assert.NotEmpty(assets);
        }
Example #2
0
        public async Task <object> GetAssets()
        {
            try {
                IAlpacaTradingClient trading = null;

                if (!String.IsNullOrWhiteSpace(Settings.API_Alpaca_Live_Key) && !String.IsNullOrWhiteSpace(Settings.API_Alpaca_Live_Secret))
                {
                    trading = Environments.Live.GetAlpacaTradingClient(new SecretKey(Settings.API_Alpaca_Live_Key, Settings.API_Alpaca_Live_Secret));
                }
                else if (!String.IsNullOrWhiteSpace(Settings.API_Alpaca_Paper_Key) && !String.IsNullOrWhiteSpace(Settings.API_Alpaca_Paper_Secret))
                {
                    trading = Environments.Paper.GetAlpacaTradingClient(new SecretKey(Settings.API_Alpaca_Paper_Key, Settings.API_Alpaca_Paper_Secret));
                }
                else
                {
                    return(new ArgumentNullException());
                }

                var assets = await trading.ListAssetsAsync(new AssetsRequest { AssetStatus = AssetStatus.Active });

                List <Data.Asset> output = new List <Data.Asset>();
                foreach (var asset in assets)
                {
                    output.Add(new Data.Asset()
                    {
                        ID           = asset.AssetId.ToString(),
                        Class        = asset.Class.ToString(),
                        Exchange     = asset.Exchange.ToString(),
                        Symbol       = asset.Symbol,
                        Status       = asset.Status.ToString(),
                        Tradeable    = asset.IsTradable,
                        Marginable   = asset.Marginable,
                        Shortable    = asset.Shortable,
                        EasyToBorrow = asset.EasyToBorrow
                    });
                }
                return(output);
            } catch (Exception ex) {
                await Log.Error($"{MethodBase.GetCurrentMethod().DeclaringType}: {MethodBase.GetCurrentMethod().Name}", ex);

                return(ex.Message);
            }
        }
Example #3
0
        public static async Task <IEnumerable <IAsset> > GetStocks(IAlpacaTradingClient client)
        {
            var assets = await client.ListAssetsAsync(new AssetsRequest { AssetStatus = AssetStatus.Active });

            return(assets.Where(asset => asset.Exchange == Exchange.Nasdaq));
        }